/* $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred.
*/

#ident	"$Header: strstr.c 1.2 89/08/07 $"

/* $Log:	strstr.c,v $
*/

/*______________________________________________________________________*
 * This file forms part of the POSIX requirement described in section   *
 * 8.1 of 1003.1-1988 which should be referred to before making any     *
 * changes.							        *
 *______________________________________________________________________*/


#include <unistd.h>	/* for the definition of NULL */

/*
 * strstr(s1, s2) -- 
 * Returns a pointer to the location of the first occurence in the
 * string pointed to by s1 of the sequence of characters (excluding
 * the terminating null character) in the string pointed to by s2.
 */

char *
strstr(s1, s2)
char *s1;
char *s2;
{
	register char *p1;
	register char *p2;
	register char *origin;
	register int found;	/* required to avoid a recursive algorithm*/

	origin = p1 = s1;
	p2 = s2;
	found = 0;
	while( (*p1 != (char)NULL) && (*p2 != (char)NULL) ) {
		if( *p1 ==  *p2 ) {
			found = 1;
			p1++;
			p2++;
		} else {
			if( found ) {
				origin = p1;
				p2 = s2;
				found = 0;
			} else {
				origin = ++p1;
				found = 0;
			}
		}
	}
	if( *p2 == (char)NULL )
		return( origin );
	else
		return( (char *)NULL );
}
