libc: Implement strrchr()
This commit is contained in:
parent
f13c48b562
commit
6953a28ce8
@ -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. */
|
/* 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);
|
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. */
|
/* 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,
|
__lc_deprecated("strcat is unsafe and should not be used; use strncat instead") char* strcat(char* dest,
|
||||||
const char* src);
|
const char* src);
|
||||||
|
@ -133,6 +133,14 @@ extern "C"
|
|||||||
return NULL;
|
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)
|
void* bzero(void* buf, size_t n)
|
||||||
{
|
{
|
||||||
return memset(buf, 0, n);
|
return memset(buf, 0, n);
|
||||||
|
Loading…
Reference in New Issue
Block a user