Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libc/string: simplify strrchr #6229

Merged
merged 1 commit into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/libc/string/lib_strchrnul.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
****************************************************************************/
Expand Down
11 changes: 6 additions & 5 deletions libs/libc/string/lib_strrchr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}