1 extern int inside_main;
2 extern const char *p;
3
4 char *
my_strstr(const char * s1,const char * s2)5 my_strstr (const char *s1, const char *s2)
6 {
7 __SIZE_TYPE__ len = strlen (s2);
8
9 #ifdef __OPTIMIZE__
10 /* If optimizing, we should be called only in the strstr (foo + 2, p)
11 case. All other cases should be optimized. */
12 if (inside_main)
13 if (s2 != p || strcmp (s1, "hello world" + 2) != 0)
14 abort ();
15 #endif
16 if (len == 0)
17 return (char *) s1;
18 for (s1 = strchr (s1, *s2); s1; s1 = strchr (s1 + 1, *s2))
19 if (strncmp (s1, s2, len) == 0)
20 return (char *) s1;
21 return (char *) 0;
22 }
23
24 char *
strstr(const char * s1,const char * s2)25 strstr (const char *s1, const char *s2)
26 {
27 if (inside_main)
28 abort ();
29
30 return my_strstr (s1, s2);
31 }
32