libc: Implement strrchr()

This commit is contained in:
apio 2022-10-15 15:16:19 +02:00
parent f13c48b562
commit 6953a28ce8
2 changed files with 11 additions and 0 deletions

View File

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

View File

@ -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<char*>(s);
return NULL;
}
void* bzero(void* buf, size_t n)
{
return memset(buf, 0, n);