xref: /onnv-gate/usr/src/lib/libast/common/comp/strstr.c (revision 12068:08a39a083754)
14887Schin /***********************************************************************
24887Schin *                                                                      *
34887Schin *               This software is part of the ast package               *
4*12068SRoger.Faulkner@Oracle.COM *          Copyright (c) 1985-2010 AT&T Intellectual Property          *
54887Schin *                      and is licensed under the                       *
64887Schin *                  Common Public License, Version 1.0                  *
78462SApril.Chin@Sun.COM *                    by AT&T Intellectual Property                     *
84887Schin *                                                                      *
94887Schin *                A copy of the License is available at                 *
104887Schin *            http://www.opensource.org/licenses/cpl1.0.txt             *
114887Schin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
124887Schin *                                                                      *
134887Schin *              Information and Software Systems Research               *
144887Schin *                            AT&T Research                             *
154887Schin *                           Florham Park NJ                            *
164887Schin *                                                                      *
174887Schin *                 Glenn Fowler <gsf@research.att.com>                  *
184887Schin *                  David Korn <dgk@research.att.com>                   *
194887Schin *                   Phong Vo <kpv@research.att.com>                    *
204887Schin *                                                                      *
214887Schin ***********************************************************************/
224887Schin #pragma prototyped
234887Schin 
244887Schin #if defined(__STDPP__directive) && defined(__STDPP__hide)
254887Schin __STDPP__directive pragma pp:hide strstr
264887Schin #else
274887Schin #define strstr		______strstr
284887Schin #endif
294887Schin 
304887Schin #include <ast.h>
314887Schin 
324887Schin #if defined(__STDPP__directive) && defined(__STDPP__hide)
334887Schin __STDPP__directive pragma pp:nohide strstr
344887Schin #else
354887Schin #undef	strstr
364887Schin #endif
374887Schin 
384887Schin #if _lib_strstr
394887Schin 
404887Schin NoN(strstr)
414887Schin 
424887Schin #else
434887Schin 
444887Schin #if defined(__EXPORT__)
454887Schin #define extern	__EXPORT__
464887Schin #endif
474887Schin 
484887Schin extern char*
494887Schin strstr(register const char* s1, register const char* s2)
504887Schin {
514887Schin 	register int		c1;
524887Schin 	register int		c2;
534887Schin 	register const char*	t1;
544887Schin 	register const char*	t2;
554887Schin 
564887Schin 	if (s2)
574887Schin 	{
584887Schin 		if (!*s2)
594887Schin 			return (char*)s1;
604887Schin 		c2 = *s2++;
614887Schin 		while (c1 = *s1++)
624887Schin 			if (c1 == c2)
634887Schin 			{
644887Schin 				t1 = s1;
654887Schin 				t2 = s2;
664887Schin 				do
674887Schin 				{
684887Schin 					if (!*t2)
694887Schin 						return (char*)s1 - 1;
704887Schin 				} while (*t1++ == *t2++);
714887Schin 			}
724887Schin 	}
734887Schin 	return 0;
744887Schin }
754887Schin 
764887Schin #endif
77