/*
 * |-----------------------------------------------------------|
 * | Copyright (c) 1991, 1990 MIPS Computer Systems, Inc.      |
 * | All Rights Reserved                                       |
 * |-----------------------------------------------------------|
 * |          Restricted Rights Legend                         |
 * | Use, duplication, or disclosure by the Government is      |
 * | subject to restrictions as set forth in                   |
 * | subparagraph (c)(1)(ii) of the Rights in Technical        |
 * | Data and Computer Software Clause of DFARS 252.227-7013.  |
 * |         MIPS Computer Systems, Inc.                       |
 * |         950 DeGuigne Avenue                               |
 * |         Sunnyvale, California 94088-3650, USA             |
 * |-----------------------------------------------------------|
 */
#ident	"$Header: strstr.c,v 1.6.2.1 92/06/24 14:00:44 marker Exp $"

/*LINTLIBRARY*/
/*
 *  strstr() locates the first occurrence in the string pointed to by s1
 *  of the sequence of characters (excluding the null terminating byte)
 *  in the string pointed to by s2.
 * 
 *  if no matching string is located, or s1 is null, strstr() returns NULL
 *  if s2 is NULL, then s1 is returned.
 */

#ifndef	NULL
#define	NULL	(char *)0
#endif

#if defined(__STDC__)

char * strstr(const char *s1, const char *s2)

#else

char *
strstr(s1, s2)
register char *s1, *s2;

#endif
{
	char *str1, *str2;
	char c, initial;
	char *tstr;

	str1 = s1;
	str2 = s2;

	if (str1 == NULL || str2 == NULL || *str2 == '\0')
		return(str1);

	initial = *str2;
	while (*str1) {
		if (*str1++ == initial) {	/* possible match? */
			tstr = str1;		/* yes, remember where we are */
			while((c = *++str2) == *tstr++ && c)
				;
			if (c == 0)		/* exhaust sub-string? */
				return(str1 - 1); /* yes, success */
			str2 = s2;		/* start over again */
		} 
	}
	return(NULL);
}
