]> git.zerfleddert.de Git - micropolis/blob - src/tcl/compat/strstr.c
Makefile: Micropolis build fixes for recent macOS
[micropolis] / src / tcl / compat / strstr.c
1 /*
2 * strstr.c --
3 *
4 * Source code for the "strstr" library routine.
5 *
6 * Copyright 1988-1991 Regents of the University of California
7 * Permission to use, copy, modify, and distribute this
8 * software and its documentation for any purpose and without
9 * fee is hereby granted, provided that the above copyright
10 * notice appears in all copies. The University of California
11 * makes no representations about the suitability of this
12 * software for any purpose. It is provided "as is" without
13 * express or implied warranty.
14 */
15
16 #ifndef lint
17 static char rcsid[] = "$Header: /sprite/src/lib/tcl/compat/RCS/strstr.c,v 1.1 91/09/19 16:22:12 ouster Exp $ SPRITE (Berkeley)";
18 #endif /* not lint */
19
20 /*
21 *----------------------------------------------------------------------
22 *
23 * strstr --
24 *
25 * Locate the first instance of a substring in a string.
26 *
27 * Results:
28 * If string contains substring, the return value is the
29 * location of the first matching instance of substring
30 * in string. If string doesn't contain substring, the
31 * return value is 0. Matching is done on an exact
32 * character-for-character basis with no wildcards or special
33 * characters.
34 *
35 * Side effects:
36 * None.
37 *
38 *----------------------------------------------------------------------
39 */
40
41 char *
42 strstr(string, substring)
43 register char *string; /* String to search. */
44 char *substring; /* Substring to try to find in string. */
45 {
46 register char *a, *b;
47
48 /* First scan quickly through the two strings looking for a
49 * single-character match. When it's found, then compare the
50 * rest of the substring.
51 */
52
53 b = substring;
54 if (*b == 0) {
55 return string;
56 }
57 for ( ; *string != 0; string += 1) {
58 if (*string != *b) {
59 continue;
60 }
61 a = string;
62 while (1) {
63 if (*b == 0) {
64 return string;
65 }
66 if (*a++ != *b++) {
67 break;
68 }
69 }
70 b = substring;
71 }
72 return (char *) 0;
73 }
Impressum, Datenschutz