Adds chaninfo()
[akaros.git] / kern / src / strstr.c
1 //INFERNO
2 #include <string.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;
12         int f, n;
13
14         f = s2[0];
15         if(f == 0)
16                 return s1;
17         n = strlen(s2);
18         for(p=strchr(s1, f); p; p=strchr(p+1, f))
19                 if(strncmp(p, s2, n) == 0)
20                         return p;
21         return 0;
22 }
23
24 /* Case insensitive strcmp */
25 int
26 cistrcmp(char *s1, char *s2)
27 {
28         int c1, c2;
29
30         while(*s1){
31                 c1 = *( uint8_t *)s1++;
32                 c2 = *( uint8_t *)s2++;
33
34                 if(c1 == c2)
35                         continue;
36
37                 if(c1 >= 'A' && c1 <= 'Z')
38                         c1 -= 'A' - 'a';
39
40                 if(c2 >= 'A' && c2 <= 'Z')
41                         c2 -= 'A' - 'a';
42
43                 if(c1 != c2)
44                         return c1 - c2;
45         }
46         return -*s2;
47 }