libc: core: implement strrchr

This commit is contained in:
2026-07-19 13:29:14 +01:00
parent 67b460e4e1
commit 8aa76b5b7f
2 changed files with 15 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
#include <string.h>
char *strrchr(const char *str, int c)
{
size_t len = strlen(str);
for (int i = len - 1; i > 0; i--) {
if (str[i] == c) {
return (char *)&str[i];
}
}
return NULL;
}
+1
View File
@@ -11,6 +11,7 @@ extern size_t strlen(const char *s);
extern size_t strcspn(const char *dest, const char *src); extern size_t strcspn(const char *dest, const char *src);
extern char *strchr(const char *str, int c); extern char *strchr(const char *str, int c);
extern char *strrchr(const char *str, int ch);
extern int strcmp(const char *s1, const char *s2); extern int strcmp(const char *s1, const char *s2);
extern int strncmp(const char *s1, const char *s2, unsigned long n); extern int strncmp(const char *s1, const char *s2, unsigned long n);