Ruby 1.9.3p327(2012-11-10revision37606)
missing/strchr.c
Go to the documentation of this file.
00001 /* public domain rewrite of strchr(3) and strrchr(3) */
00002 
00003 #include "ruby/missing.h"
00004 
00005 size_t strlen(const char*);
00006 
00007 char *
00008 strchr(const char *s, int c)
00009 {
00010     if (c == 0) return (char *)s + strlen(s);
00011     while (*s) {
00012         if (*s == c)
00013             return (char *)s;
00014         s++;
00015     }
00016     return 0;
00017 }
00018 
00019 char *
00020 strrchr(const char *s, int c)
00021 {
00022     const char *save;
00023 
00024     if (c == 0) return (char *)s + strlen(s);
00025     save = 0;
00026     while (*s) {
00027         if (*s == c)
00028             save = s;
00029         s++;
00030     }
00031     return (char *)save;
00032 }
00033