diff --git a/libs/libc/include/string.h b/libs/libc/include/string.h index 2d79f1a2..7dd597c5 100644 --- a/libs/libc/include/string.h +++ b/libs/libc/include/string.h @@ -49,6 +49,10 @@ extern "C" /* Returns a pointer to the last occurrence of the character c in str, or NULL if it is not found. */ char* strrchr(const char* str, int c); + /* Returns a pointer to the first occurrence of the character c in str, or a pointer to the terminating null byte of + * str if it is not found. */ + char* strchrnul(const char* str, int c); + /* Concatenates at most max bytes of the string src into dest. */ char* strncat(char* dest, const char* src, size_t max); diff --git a/libs/libc/src/string.cpp b/libs/libc/src/string.cpp index e4e1d235..265f0c73 100644 --- a/libs/libc/src/string.cpp +++ b/libs/libc/src/string.cpp @@ -208,6 +208,12 @@ extern "C" return NULL; } + char* strchrnul(const char* str, int c) + { + while (*str && *str != (char)c) str++; + return const_cast(str); + } + char* strrchr(const char* str, int c) { const char* s = str + strlen(str);