summaryrefslogtreecommitdiff
path: root/missing/strchr.c
diff options
context:
space:
mode:
Diffstat (limited to 'missing/strchr.c')
-rw-r--r--missing/strchr.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/missing/strchr.c b/missing/strchr.c
index 82f3cc96b0..465f07b61e 100644
--- a/missing/strchr.c
+++ b/missing/strchr.c
@@ -1,30 +1,32 @@
/* public domain rewrite of strchr(3) and strrchr(3) */
+#include "ruby/missing.h"
+
+size_t strlen(const char*);
+
char *
-strchr(s, c)
- char *s;
- int c;
+strchr(const char *s, int c)
{
- if (c == 0) return s + strlen(s);
+ if (c == 0) return (char *)s + strlen(s);
while (*s) {
if (*s == c)
- return s;
+ return (char *)s;
s++;
}
return 0;
}
char *
-strrchr(s, c)
- char *s;
- int c;
+strrchr(const char *s, int c)
{
- char *save = 0;
+ const char *save;
+ if (c == 0) return (char *)s + strlen(s);
+ save = 0;
while (*s) {
if (*s == c)
save = s;
s++;
}
- return save;
+ return (char *)save;
}