diff --git a/libs/libc/string/lib_strchrnul.c b/libs/libc/string/lib_strchrnul.c index ab15fb96004..d338efcc580 100644 --- a/libs/libc/string/lib_strchrnul.c +++ b/libs/libc/string/lib_strchrnul.c @@ -39,7 +39,7 @@ * considered to be part of the string. * * Returned Value: - * Upon completion, strchrnull() returns a pointer to the byte, or a + * Upon completion, strchrnul() returns a pointer to the byte, or a * pointer to null if the byte was not found. * ****************************************************************************/ diff --git a/libs/libc/string/lib_strrchr.c b/libs/libc/string/lib_strrchr.c index 2a04b06c719..6c6b5d961e6 100644 --- a/libs/libc/string/lib_strrchr.c +++ b/libs/libc/string/lib_strrchr.c @@ -37,15 +37,16 @@ #undef strrchr /* See mm/README.txt */ FAR char *strrchr(FAR const char *s, int c) { - FAR const char *p = &s[strlen(s)]; + FAR const char *r = NULL; - for (; p >= s; p--) + do { - if (*p == c) + if (*s == c) { - return (FAR char *)p; + r = s; } } + while (*s++ != '\0'); - return NULL; + return (FAR char *)r; }