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:
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
** Copyright 2001, Manuel J. Petit. All rights reserved.
|
* Copyright 2001, Manuel J. Petit. All rights reserved.
|
||||||
** Distributed under the terms of the NewOS License.
|
* Distributed under the terms of the NewOS License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -10,14 +10,13 @@
|
|||||||
char *
|
char *
|
||||||
strrchr(char const *s, int c)
|
strrchr(char const *s, int c)
|
||||||
{
|
{
|
||||||
char const *last = c ? 0 : s;
|
char const *last = NULL;
|
||||||
|
|
||||||
|
for (;; s++) {
|
||||||
while (*s) {
|
if (*s == (char)c)
|
||||||
if (*s == c)
|
|
||||||
last = s;
|
last = s;
|
||||||
|
if (*s == '\0')
|
||||||
s += 1;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (char *)last;
|
return (char *)last;
|
||||||
|
|||||||
Reference in New Issue
Block a user