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:
Ingo Weinhold
2013-08-13 21:30:30 +02:00
parent 37cfff1f04
commit ce76b7e202
+9 -10
View File
@@ -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;