add strrchr()
This commit is contained in:
@ -23,6 +23,7 @@ int strcmp(const char *s1, const char *s2);
|
||||
int strncmp(const char *s1, const char *s2, size_t n);
|
||||
char *strstr(const char *haystack, const char *needle);
|
||||
char *strchr(const char *s, int n);
|
||||
char *strrchr(const char *s, int n);
|
||||
void *memcpy(void *dest, const void *src, size_t n);
|
||||
void *memcpy_long(void *dest, const void *src, size_t n);
|
||||
int memcmp(const void *s1, const void *s2, size_t n);
|
||||
|
||||
15
lib/string.c
15
lib/string.c
@ -95,7 +95,20 @@ char *strchr(const char *s, int n) {
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
strrchr(const char *s, int c)
|
||||
{
|
||||
const char *last = NULL;
|
||||
|
||||
do {
|
||||
if (*s == c) {
|
||||
last = s;
|
||||
}
|
||||
} while (*(s++));
|
||||
|
||||
return (char *)last;
|
||||
} /* strrchr() */
|
||||
|
||||
char *strstr(const char *haystack, const char *needle)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user