diff --git a/libs/libc/include/string.h b/libs/libc/include/string.h index 9f891ff6..64d0eaf2 100644 --- a/libs/libc/include/string.h +++ b/libs/libc/include/string.h @@ -43,6 +43,9 @@ extern "C" /* Returns a pointer to the first occurrence of the character c in str, or NULL if it is not found. */ char* strchr(const char* str, int 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); + /* Concatenates the string src into dest. This function is unsafe, use strncat instead. */ __lc_deprecated("strcat is unsafe and should not be used; use strncat instead") char* strcat(char* dest, const char* src); diff --git a/libs/libc/src/string.cpp b/libs/libc/src/string.cpp index f9a398c1..dff7c8e2 100644 --- a/libs/libc/src/string.cpp +++ b/libs/libc/src/string.cpp @@ -133,6 +133,14 @@ extern "C" return NULL; } + char* strrchr(const char* str, int c) + { + const char* s = str + strlen(str); + while (s != str && *str != (char)c) str--; + if (s != str) return const_cast(s); + return NULL; + } + void* bzero(void* buf, size_t n) { return memset(buf, 0, n);