xref: /titanic_44/usr/src/lib/libast/common/comp/strstr.c (revision f80ce222af313ec87dc070b2219b29c81c5e5d8c)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2010 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                  David Korn <dgk@research.att.com>                   *
19 *                   Phong Vo <kpv@research.att.com>                    *
20 *                                                                      *
21 ***********************************************************************/
22 #pragma prototyped
23 
24 #if defined(__STDPP__directive) && defined(__STDPP__hide)
25 __STDPP__directive pragma pp:hide strstr
26 #else
27 #define strstr		______strstr
28 #endif
29 
30 #include <ast.h>
31 
32 #if defined(__STDPP__directive) && defined(__STDPP__hide)
33 __STDPP__directive pragma pp:nohide strstr
34 #else
35 #undef	strstr
36 #endif
37 
38 #if _lib_strstr
39 
40 NoN(strstr)
41 
42 #else
43 
44 #if defined(__EXPORT__)
45 #define extern	__EXPORT__
46 #endif
47 
48 extern char*
49 strstr(register const char* s1, register const char* s2)
50 {
51 	register int		c1;
52 	register int		c2;
53 	register const char*	t1;
54 	register const char*	t2;
55 
56 	if (s2)
57 	{
58 		if (!*s2)
59 			return (char*)s1;
60 		c2 = *s2++;
61 		while (c1 = *s1++)
62 			if (c1 == c2)
63 			{
64 				t1 = s1;
65 				t2 = s2;
66 				do
67 				{
68 					if (!*t2)
69 						return (char*)s1 - 1;
70 				} while (*t1++ == *t2++);
71 			}
72 	}
73 	return 0;
74 }
75 
76 #endif
77