#include <ncbi.h>
#include <gishlib.h>

/*
	str_str(s1, s2)

		Find the start of substring s2 within the string s1.
		Return the address within s1 of the start of s2.
		Return NULL if s2 is not a substring of s1.
*/

CharPtr _cdecl
str_str(s1, s2)
	register CharPtr s1, s2;
{
	register char	ch;
	register CharPtr s1s, s2s;
	register size_t	ns;
	size_t	n;

	/* An empty string matches right away */
	if ((ch = *s2++) == NULLB)
		return s1;
	n = strlen(s2);
	for (;;) {
		while (*s1 != ch)
			if (*s1++ == NULLB)
				return NULL;
		s1s = ++s1; s2s = s2; ns = n;
		while (ns > 0 && *s1s == *s2s++) {
			--ns;
			if (*s1s++ == NULLB)
				return --s1;
		}
		if (ns == 0)
			return --s1;
	}
	/*NOTREACHED*/
}
