]> git.lizzy.rs Git - plan9front.git/blob - sys/src/libc/port/strstr.c
libregexp: improve the transition to next available thread, instruction, and generation
[plan9front.git] / sys / src / libc / port / strstr.c
1 #include <u.h>
2 #include <libc.h>
3
4 /*
5  * Return pointer to first occurrence of s2 in s1,
6  * 0 if none
7  */
8 char*
9 strstr(char *s1, char *s2)
10 {
11         char *p, *pa, *pb;
12         int c0, c;
13
14         c0 = *s2;
15         if(c0 == 0)
16                 return s1;
17         s2++;
18         for(p=strchr(s1, c0); p; p=strchr(p+1, c0)) {
19                 pa = p;
20                 for(pb=s2;; pb++) {
21                         c = *pb;
22                         if(c == 0)
23                                 return p;
24                         if(c != *++pa)
25                                 break;
26                 }
27         }
28         return 0;
29 }