]> Pileus Git - ~andy/fetchmail/blob - strstr.c
Complete Dominik's name.
[~andy/fetchmail] / strstr.c
1 /*
2  * strstr -- locate first occurence of a substring 
3  *
4  * Locates the first occurrence in the string pointed to by S1 of the string
5  * pointed to by S2.  Returns a pointer to the substring found, or a NULL
6  * pointer if not found.  If S2 points to a string with zero length, the
7  * function returns S1. 
8  *
9  * For license terms, see the file COPYING in this directory.
10  */
11
12 char *strstr(register char *buf, register char *sub)
13 {
14     register char *bp;
15
16     if (!*sub)
17         return buf;
18     for (;;)
19     {
20         if (!*buf)
21             break;
22         bp = buf;
23         for (;;)
24         {
25             if (!*sub)
26                 return buf;
27             if (*bp++ != *sub++)
28                 break;
29         }
30         sub -= (unsigned long) bp;
31         sub += (unsigned long) buf;
32         buf += 1;
33     }
34     return 0;
35 }
36