diff options
Diffstat (limited to 'src/lib/libc')
| -rw-r--r-- | src/lib/libc/string/Makefile.inc | 9 | ||||
| -rw-r--r-- | src/lib/libc/string/strcasestr.c | 64 | ||||
| -rw-r--r-- | src/lib/libc/string/strstr.3 | 32 |
3 files changed, 88 insertions, 17 deletions
diff --git a/src/lib/libc/string/Makefile.inc b/src/lib/libc/string/Makefile.inc index 902cf83cef..81be9cea0a 100644 --- a/src/lib/libc/string/Makefile.inc +++ b/src/lib/libc/string/Makefile.inc | |||
| @@ -1,11 +1,11 @@ | |||
| 1 | # $OpenBSD: Makefile.inc,v 1.13 2004/05/03 19:56:08 millert Exp $ | 1 | # $OpenBSD: Makefile.inc,v 1.14 2005/03/30 03:04:19 deraadt Exp $ |
| 2 | 2 | ||
| 3 | # string sources | 3 | # string sources |
| 4 | .PATH: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/string ${LIBCSRCDIR}/string | 4 | .PATH: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/string ${LIBCSRCDIR}/string |
| 5 | 5 | ||
| 6 | SRCS+= bm.c memccpy.c strcasecmp.c strcoll.c strdup.c strerror.c \ | 6 | SRCS+= bm.c memccpy.c strcasecmp.c strcasestr.c strcoll.c strdup.c \ |
| 7 | strerror_r.c strlcat.c strmode.c strsignal.c strtok.c strxfrm.c \ | 7 | strerror.c strerror_r.c strlcat.c strmode.c strsignal.c strtok.c \ |
| 8 | __strsignal.c | 8 | strxfrm.c __strsignal.c |
| 9 | 9 | ||
| 10 | # machine-dependent net sources | 10 | # machine-dependent net sources |
| 11 | # m-d Makefile.inc must include sources for: | 11 | # m-d Makefile.inc must include sources for: |
| @@ -148,5 +148,6 @@ MLINKS+=strcat.3 strncat.3 | |||
| 148 | MLINKS+=strcmp.3 strncmp.3 | 148 | MLINKS+=strcmp.3 strncmp.3 |
| 149 | MLINKS+=strcpy.3 strncpy.3 | 149 | MLINKS+=strcpy.3 strncpy.3 |
| 150 | MLINKS+=strlcpy.3 strlcat.3 | 150 | MLINKS+=strlcpy.3 strlcat.3 |
| 151 | MLINKS+=strstr.3 strcasestr.3 | ||
| 151 | MLINKS+=strtok.3 strtok_r.3 | 152 | MLINKS+=strtok.3 strtok_r.3 |
| 152 | MLINKS+=strerror.3 strerror_r.3 | 153 | MLINKS+=strerror.3 strerror_r.3 |
diff --git a/src/lib/libc/string/strcasestr.c b/src/lib/libc/string/strcasestr.c new file mode 100644 index 0000000000..075e6f1987 --- /dev/null +++ b/src/lib/libc/string/strcasestr.c | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | /* $OpenBSD: strcasestr.c,v 1.1 2005/03/30 03:04:19 deraadt Exp $ */ | ||
| 2 | /* $NetBSD: strcasestr.c,v 1.2 2005/02/09 21:35:47 kleink Exp $ */ | ||
| 3 | |||
| 4 | /*- | ||
| 5 | * Copyright (c) 1990, 1993 | ||
| 6 | * The Regents of the University of California. All rights reserved. | ||
| 7 | * | ||
| 8 | * This code is derived from software contributed to Berkeley by | ||
| 9 | * Chris Torek. | ||
| 10 | * | ||
| 11 | * Redistribution and use in source and binary forms, with or without | ||
| 12 | * modification, are permitted provided that the following conditions | ||
| 13 | * are met: | ||
| 14 | * 1. Redistributions of source code must retain the above copyright | ||
| 15 | * notice, this list of conditions and the following disclaimer. | ||
| 16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 17 | * notice, this list of conditions and the following disclaimer in the | ||
| 18 | * documentation and/or other materials provided with the distribution. | ||
| 19 | * 3. Neither the name of the University nor the names of its contributors | ||
| 20 | * may be used to endorse or promote products derived from this software | ||
| 21 | * without specific prior written permission. | ||
| 22 | * | ||
| 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
| 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
| 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 33 | * SUCH DAMAGE. | ||
| 34 | */ | ||
| 35 | |||
| 36 | #if defined(LIBC_SCCS) && !defined(lint) | ||
| 37 | static char *rcsid = "$OpenBSD: strcasestr.c,v 1.1 2005/03/30 03:04:19 deraadt Exp $"; | ||
| 38 | #endif /* LIBC_SCCS and not lint */ | ||
| 39 | |||
| 40 | #include <ctype.h> | ||
| 41 | #include <string.h> | ||
| 42 | |||
| 43 | /* | ||
| 44 | * Find the first occurrence of find in s, ignore case. | ||
| 45 | */ | ||
| 46 | char * | ||
| 47 | strcasestr(const char *s, const char *find) | ||
| 48 | { | ||
| 49 | char c, sc; | ||
| 50 | size_t len; | ||
| 51 | |||
| 52 | if ((c = *find++) != 0) { | ||
| 53 | c = tolower((unsigned char)c); | ||
| 54 | len = strlen(find); | ||
| 55 | do { | ||
| 56 | do { | ||
| 57 | if ((sc = *s++) == 0) | ||
| 58 | return (NULL); | ||
| 59 | } while ((char)tolower((unsigned char)sc) != c); | ||
| 60 | } while (strncasecmp(s, find, len) != 0); | ||
| 61 | s--; | ||
| 62 | } | ||
| 63 | return ((char *)s); | ||
| 64 | } | ||
diff --git a/src/lib/libc/string/strstr.3 b/src/lib/libc/string/strstr.3 index 64396e7885..2c8fa1888f 100644 --- a/src/lib/libc/string/strstr.3 +++ b/src/lib/libc/string/strstr.3 | |||
| @@ -29,18 +29,20 @@ | |||
| 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 30 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
| 31 | .\" | 31 | .\" |
| 32 | .\" $OpenBSD: strstr.3,v 1.7 2005/02/25 03:12:44 cloder Exp $ | 32 | .\" $OpenBSD: strstr.3,v 1.8 2005/03/30 03:04:19 deraadt Exp $ |
| 33 | .\" | 33 | .\" |
| 34 | .Dd June 29, 1991 | 34 | .Dd June 29, 1991 |
| 35 | .Dt STRSTR 3 | 35 | .Dt STRSTR 3 |
| 36 | .Os | 36 | .Os |
| 37 | .Sh NAME | 37 | .Sh NAME |
| 38 | .Nm strstr | 38 | .Nm strstr , strcasestr |
| 39 | .Nd locate a substring in a string | 39 | .Nd locate a substring in a string |
| 40 | .Sh SYNOPSIS | 40 | .Sh SYNOPSIS |
| 41 | .Fd #include <string.h> | 41 | .Fd #include <string.h> |
| 42 | .Ft char * | 42 | .Ft char * |
| 43 | .Fn strstr "const char *big" "const char *little" | 43 | .Fn strstr "const char *big" "const char *little" |
| 44 | .Ft char * | ||
| 45 | .Fn strcasestr "const char *big" "const char *little" | ||
| 44 | .Sh DESCRIPTION | 46 | .Sh DESCRIPTION |
| 45 | The | 47 | The |
| 46 | .Fn strstr | 48 | .Fn strstr |
| @@ -48,23 +50,27 @@ function locates the first occurrence of the NUL-terminated string | |||
| 48 | .Fa little | 50 | .Fa little |
| 49 | in the NUL-terminated string | 51 | in the NUL-terminated string |
| 50 | .Fa big . | 52 | .Fa big . |
| 53 | .Pp | ||
| 54 | The | ||
| 55 | .Fn strcasestr | ||
| 56 | function is similar to | ||
| 57 | .Fn strstr | ||
| 58 | but ignores the case of both strings. | ||
| 59 | .Pp | ||
| 51 | If | 60 | If |
| 52 | .Fa little | 61 | .Fa little |
| 53 | is the empty string, | 62 | is an empty string, |
| 54 | .Fn strstr | 63 | .Fa big |
| 55 | returns | 64 | is returned; |
| 56 | .Fa big ; | ||
| 57 | if | 65 | if |
| 58 | .Fa little | 66 | .Fa little |
| 59 | occurs nowhere in | 67 | occurs nowhere in |
| 60 | .Fa big , | 68 | .Fa big , |
| 61 | .Fn strstr | 69 | .Dv NULL |
| 62 | returns | 70 | is returned; |
| 63 | .Dv NULL ; | 71 | otherwise a pointer to the first character of the first occurrence of |
| 64 | otherwise | 72 | .Fa little |
| 65 | .Fn strstr | 73 | is returned. |
| 66 | returns a pointer to the first character of the first occurrence of | ||
| 67 | .Fa little . | ||
| 68 | .Sh SEE ALSO | 74 | .Sh SEE ALSO |
| 69 | .Xr memchr 3 , | 75 | .Xr memchr 3 , |
| 70 | .Xr strchr 3 , | 76 | .Xr strchr 3 , |
