File: strstr.c

package info (click to toggle)
fetchmail 6.3.26-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 8,980 kB
  • ctags: 4,235
  • sloc: ansic: 29,508; sh: 5,796; perl: 3,181; python: 1,955; yacc: 458; makefile: 350; lex: 265; awk: 124; lisp: 84; exp: 43; sed: 16
file content (36 lines) | stat: -rw-r--r-- 710 bytes parent folder | download | duplicates (14)
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;
}