]>
Commit | Line | Data |
---|---|---|
fecd2382 | 1 | /* strstr - find first occurrence of wanted in s |
01170860 RP |
2 | |
3 | Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation. | |
6efd877d | 4 | |
a39116f1 | 5 | This file is part of GAS, the GNU Assembler. |
6efd877d | 6 | |
a39116f1 RP |
7 | GAS is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
6efd877d | 11 | |
a39116f1 RP |
12 | GAS is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
6efd877d | 16 | |
a39116f1 RP |
17 | You should have received a copy of the GNU General Public License |
18 | along with GAS; see the file COPYING. If not, write to | |
19 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
20 | ||
21 | /* If your compiler is really ansi, then you don't need this. */ | |
01170860 | 22 | |
3340f7e5 | 23 | #if __STDC__ != 1 |
fecd2382 RP |
24 | |
25 | #define SIZET int | |
26 | ||
27 | #define NULL 0 | |
28 | ||
29 | #include <string.h> | |
30 | ||
31 | char * /* found string, or NULL if none */ | |
6efd877d KR |
32 | strstr (s, wanted) |
33 | char *s; | |
34 | char *wanted; | |
fecd2382 | 35 | { |
6efd877d KR |
36 | register char *scan; |
37 | register SIZET len; | |
38 | register char firstc; | |
39 | ||
40 | /* | |
fecd2382 RP |
41 | * The odd placement of the two tests is so "" is findable. |
42 | * Also, we inline the first char for speed. | |
43 | * The ++ on scan has been moved down for optimization. | |
44 | */ | |
6efd877d KR |
45 | firstc = *wanted; |
46 | len = strlen (wanted); | |
47 | for (scan = s; *scan != firstc || strncmp (scan, wanted, len) != 0;) | |
48 | if (*scan++ == '\0') | |
49 | return (NULL); | |
50 | return (scan); | |
51 | } /* strstr() */ | |
fecd2382 | 52 | |
3340f7e5 | 53 | #endif /* not __STDC__ */ |
fecd2382 RP |
54 | |
55 | /* end of strstr.c */ |