Mercurial > gnulib
annotate lib/c-strstr.c @ 40057:b06060465f09
maint: Run 'make update-copyright'
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Tue, 01 Jan 2019 00:25:11 +0100 |
parents | 10eb9086bea0 |
children |
rev | line source |
---|---|
8119
f2eb2edc65c3
Rewrite c-strstr.c for maintainability.
Bruno Haible <bruno@clisp.org>
parents:
7532
diff
changeset
|
1 /* c-strstr.c -- substring search in C locale |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
2 Copyright (C) 2005-2019 Free Software Foundation, Inc. |
8119
f2eb2edc65c3
Rewrite c-strstr.c for maintainability.
Bruno Haible <bruno@clisp.org>
parents:
7532
diff
changeset
|
3 Written by Bruno Haible <bruno@clisp.org>, 2005, 2007. |
7209 | 4 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8948
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify |
8119
f2eb2edc65c3
Rewrite c-strstr.c for maintainability.
Bruno Haible <bruno@clisp.org>
parents:
7532
diff
changeset
|
6 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8948
diff
changeset
|
7 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8948
diff
changeset
|
8 (at your option) any later version. |
7209 | 9 |
8119
f2eb2edc65c3
Rewrite c-strstr.c for maintainability.
Bruno Haible <bruno@clisp.org>
parents:
7532
diff
changeset
|
10 This program is distributed in the hope that it will be useful, |
f2eb2edc65c3
Rewrite c-strstr.c for maintainability.
Bruno Haible <bruno@clisp.org>
parents:
7532
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
f2eb2edc65c3
Rewrite c-strstr.c for maintainability.
Bruno Haible <bruno@clisp.org>
parents:
7532
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f2eb2edc65c3
Rewrite c-strstr.c for maintainability.
Bruno Haible <bruno@clisp.org>
parents:
7532
diff
changeset
|
13 GNU General Public License for more details. |
7209 | 14 |
8119
f2eb2edc65c3
Rewrite c-strstr.c for maintainability.
Bruno Haible <bruno@clisp.org>
parents:
7532
diff
changeset
|
15 You should have received a copy of the GNU General Public License |
19190 | 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
7209 | 17 |
7304
1c4ed7637c24
Include <config.h> unconditionally.
Bruno Haible <bruno@clisp.org>
parents:
7209
diff
changeset
|
18 #include <config.h> |
7209 | 19 |
7532
c24b9100f102
Include the specification header.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
20 /* Specification. */ |
c24b9100f102
Include the specification header.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
21 #include "c-strstr.h" |
c24b9100f102
Include the specification header.
Bruno Haible <bruno@clisp.org>
parents:
7304
diff
changeset
|
22 |
8120
03da4921af94
Ensure O(n) worst-case complexity.
Bruno Haible <bruno@clisp.org>
parents:
8119
diff
changeset
|
23 #include <string.h> |
03da4921af94
Ensure O(n) worst-case complexity.
Bruno Haible <bruno@clisp.org>
parents:
8119
diff
changeset
|
24 |
8119
f2eb2edc65c3
Rewrite c-strstr.c for maintainability.
Bruno Haible <bruno@clisp.org>
parents:
7532
diff
changeset
|
25 /* Find the first occurrence of NEEDLE in HAYSTACK. */ |
7209 | 26 char * |
8119
f2eb2edc65c3
Rewrite c-strstr.c for maintainability.
Bruno Haible <bruno@clisp.org>
parents:
7532
diff
changeset
|
27 c_strstr (const char *haystack, const char *needle) |
7209 | 28 { |
9604
cbf06de5646d
Make c-strstr rely on strstr.
Bruno Haible <bruno@clisp.org>
parents:
9561
diff
changeset
|
29 /* POSIX says that strstr() interprets the strings as byte sequences, not |
cbf06de5646d
Make c-strstr rely on strstr.
Bruno Haible <bruno@clisp.org>
parents:
9561
diff
changeset
|
30 as character sequences in the current locale. */ |
cbf06de5646d
Make c-strstr rely on strstr.
Bruno Haible <bruno@clisp.org>
parents:
9561
diff
changeset
|
31 return strstr (haystack, needle); |
7209 | 32 } |