|
Last change
on this file since 108 was 10, checked in by bird, 23 years ago |
|
Initial revision
|
-
Property cvs2svn:cvs-rev
set to
1.1
-
Property svn:eol-style
set to
native
-
Property svn:executable
set to
*
|
|
File size:
959 bytes
|
| Line | |
|---|
| 1 | /* Simple implementation of strstr for systems without it.
|
|---|
| 2 | This function is in the public domain. */
|
|---|
| 3 |
|
|---|
| 4 | /*
|
|---|
| 5 |
|
|---|
| 6 | NAME
|
|---|
| 7 |
|
|---|
| 8 | strstr -- locate first occurance of a substring
|
|---|
| 9 |
|
|---|
| 10 | SYNOPSIS
|
|---|
| 11 |
|
|---|
| 12 | #include <string.h>
|
|---|
| 13 |
|
|---|
| 14 | char *strstr (char *s1, char *s2)
|
|---|
| 15 |
|
|---|
| 16 | DESCRIPTION
|
|---|
| 17 |
|
|---|
| 18 | Locates the first occurance in the string pointed to by S1 of
|
|---|
| 19 | the string pointed to by S2. Returns a pointer to the substring
|
|---|
| 20 | found, or a NULL pointer if not found. If S2 points to a string
|
|---|
| 21 | with zero length, the function returns S1.
|
|---|
| 22 |
|
|---|
| 23 | BUGS
|
|---|
| 24 |
|
|---|
| 25 | */
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 | /* FIXME: The above description is ANSI compiliant. This routine has not
|
|---|
| 29 | been validated to comply with it. -fnf */
|
|---|
| 30 |
|
|---|
| 31 | char *
|
|---|
| 32 | strstr (s1, s2)
|
|---|
| 33 | char *s1, *s2;
|
|---|
| 34 | {
|
|---|
| 35 | register char *p = s1;
|
|---|
| 36 | extern char *strchr ();
|
|---|
| 37 | extern int strncmp ();
|
|---|
| 38 | #if __GNUC__==2
|
|---|
| 39 | extern __SIZE_TYPE__ strlen ();
|
|---|
| 40 | #endif
|
|---|
| 41 | register int len = strlen (s2);
|
|---|
| 42 |
|
|---|
| 43 | for (; (p = strchr (p, *s2)) != 0; p++)
|
|---|
| 44 | {
|
|---|
| 45 | if (strncmp (p, s2, len) == 0)
|
|---|
| 46 | {
|
|---|
| 47 | return (p);
|
|---|
| 48 | }
|
|---|
| 49 | }
|
|---|
| 50 | return (0);
|
|---|
| 51 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.