1
2 static char rcsid[] = "@(#)$Id: strstr.c,v 1.2 1995/09/29 17:41:44 wfp5p Exp $";
3
4 /*******************************************************************************
5 * The Elm Mail System - $Revision: 1.2 $ $State: Exp $
6 *
7 * Copyright (c) 1988-1995 USENET Community Trust
8 * Copyright (c) 1986,1987 Dave Taylor
9 *******************************************************************************
10 * Bug reports, patches, comments, suggestions should be sent to:
11 *
12 * Bill Pemberton, Elm Coordinator
13 * flash@virginia.edu
14 *
15 *******************************************************************************
16 * $Log: strstr.c,v $
17 * Revision 1.2 1995/09/29 17:41:44 wfp5p
18 * Alpha 8 (Chip's big changes)
19 *
20 * Revision 1.1.1.1 1995/04/19 20:38:33 wfp5p
21 * Initial import of elm 2.4 PL0 as base for elm 2.5.
22 *
23 ******************************************************************************/
24
25 /** look for substring in string
26 **/
27
28 #include "elm_defs.h"
29
30 /*
31 * strstr() -- Locates a substring.
32 *
33 * This is a replacement for the POSIX function which does not
34 * appear on all systems.
35 *
36 * Synopsis:
37 * #include <string.h>
38 * char *strstr(const char *s1, const char *s2);
39 *
40 * Arguments:
41 * s1 Pointer to the subject string.
42 * s2 Pointer to the substring to locate.
43 *
44 * Returns:
45 * A pointer to the located string or NULL
46 *
47 * Description:
48 * The strstr() function locates the first occurence in s1 of
49 * the string s2. The terminating null characters are not
50 * compared.
51 */
52
53 #ifndef STRSTR
54
strstr(s1,s2)55 char *strstr(s1, s2)
56 const char *s1, *s2;
57 {
58 int len;
59 const char *ptr;
60 const char *tmpptr;
61
62 ptr = NULL;
63 len = strlen(s2);
64
65 if ( len <= strlen(s1)) {
66 tmpptr = s1;
67 while ((ptr = index(tmpptr, (int)*s2)) != NULL) {
68 if (strncmp(ptr, s2, len) == 0) {
69 break;
70 }
71 tmpptr = ptr+1;
72 }
73 }
74 return (char *)ptr;
75 }
76
77 #endif /* !STRSTR */
78