Fix strrchr()
* For the comparison cast the character parameter to char as required by the spec. * Fix broken handling of strrchr(..., 0). It is supposed to return a pointer to the end of the string. It did return a pointer to the start.
This commit is contained in:
parent
37cfff1f04
commit
ce76b7e202
@ -1,7 +1,7 @@
|
||||
/*
|
||||
** Copyright 2001, Manuel J. Petit. All rights reserved.
|
||||
** Distributed under the terms of the NewOS License.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2001, Manuel J. Petit. All rights reserved.
|
||||
* Distributed under the terms of the NewOS License.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
@ -10,14 +10,13 @@
|
||||
char *
|
||||
strrchr(char const *s, int c)
|
||||
{
|
||||
char const *last = c ? 0 : s;
|
||||
char const *last = NULL;
|
||||
|
||||
|
||||
while (*s) {
|
||||
if (*s == c)
|
||||
for (;; s++) {
|
||||
if (*s == (char)c)
|
||||
last = s;
|
||||
|
||||
s += 1;
|
||||
if (*s == '\0')
|
||||
break;
|
||||
}
|
||||
|
||||
return (char *)last;
|
||||
|
Loading…
Reference in New Issue
Block a user