From 071da18fa3994ebc543b13f177fbc2a3ec410b3a Mon Sep 17 00:00:00 2001 From: Bananymous Date: Sun, 11 Jun 2023 20:18:03 +0300 Subject: [PATCH] LibC: add strchrnul() this is a gnu libc extension --- libc/include/string.h | 1 + libc/string.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/libc/include/string.h b/libc/include/string.h index b9c386cb18..46946a3642 100644 --- a/libc/include/string.h +++ b/libc/include/string.h @@ -20,6 +20,7 @@ char* stpcpy(char* __restrict s1, const char* __restrict s2); char* stpncpy(char* __restrict s1, const char* __restrict s2, size_t n); char* strcat(char* __restrict s1, const char* __restrict s2); char* strchr(const char* s, int c); +char* strchrnul(const char* s, int c); int strcmp(const char* s1, const char* s2); int strcoll(const char* s1, const char* s2); int strcoll_l(const char* s1, const char* s2, locale_t locale); diff --git a/libc/string.cpp b/libc/string.cpp index 4b20be8453..c85a000f98 100644 --- a/libc/string.cpp +++ b/libc/string.cpp @@ -303,6 +303,17 @@ char* strchr(const char* str, int c) return (*str == c) ? (char*)str : nullptr; } +char* strchrnul(const char* str, int c) +{ + while (*str) + { + if (*str == c) + return (char*)str; + str++; + } + return (char*)str; +} + char* strncpy(char* __restrict__ dest, const char* __restrict__ src, size_t n) { size_t i;