libc: Add strchrnul()

Another GNU extension, it's ok.
This commit is contained in:
apio 2022-10-22 18:37:02 +02:00
parent bfbe8e847b
commit 8908faf6e2
2 changed files with 10 additions and 0 deletions

View File

@ -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);

View File

@ -208,6 +208,12 @@ extern "C"
return NULL;
}
char* strchrnul(const char* str, int c)
{
while (*str && *str != (char)c) str++;
return const_cast<char*>(str);
}
char* strrchr(const char* str, int c)
{
const char* s = str + strlen(str);