rs don't follow rfc recommendations
aboutsummaryrefslogtreecommitdiffstats
path: root/strstr.c
blob: b2deeae5c3b1ad0719d5d8ecfd89a8b8958495b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
 * strstr -- locate first occurence of a substring 
 *
 * Locates the first occurrence in the string pointed to by S1 of the string
 * pointed to by S2.  Returns a pointer to the substring found, or a NULL
 * pointer if not found.  If S2 points to a string with zero length, the
 * function returns S1. 
 *
 * For license terms, see the file COPYING in this directory.
 */

char *strstr(register char *buf, register char *sub)
{
    register char *bp;

    if (!*sub)
	return buf;
    for (;;)
    {
	if (!*buf)
	    break;
	bp = buf;
	for (;;)
	{
	    if (!*sub)
		return buf;
	    if (*bp++ != *sub++)
		break;
	}
	sub -= (unsigned long) bp;
	sub += (unsigned long) buf;
	buf += 1;
    }
    return 0;
}