scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

strstr.c (357B)


      1 #include <string.h>
      2 #undef strstr
      3 
      4 char *
      5 strstr(const char *s1, const char *s2)
      6 {
      7 	const char *p, *q;
      8 	int c;
      9 
     10 	c = *s2++;
     11 	if (c == '\0')
     12 		return (char *) s1;
     13 
     14 	while (*s1) {
     15 		if (*s1 != c) {
     16 			++s1;
     17 		} else {
     18 			p = s1++;
     19 			for (q = s2; *q && *s1 == *q; ++s1, ++q)
     20 				/* nothing */;
     21 			if (*q == '\0')
     22 				return (char *) p;
     23 		}
     24 	}
     25 	return NULL;
     26 }