diff options
| author | espie <> | 2011-05-28 15:16:46 +0000 |
|---|---|---|
| committer | espie <> | 2011-05-28 15:16:46 +0000 |
| commit | 86ea12f62d74f2495d376276da8d40e06c80996f (patch) | |
| tree | ab656b594c1b784500e488a856da2be9fb492783 /src/lib/libc/string | |
| parent | 94a2b023585264ca9ba0531daaafcd082f14e0c0 (diff) | |
| download | openbsd-86ea12f62d74f2495d376276da8d40e06c80996f.tar.gz openbsd-86ea12f62d74f2495d376276da8d40e06c80996f.tar.bz2 openbsd-86ea12f62d74f2495d376276da8d40e06c80996f.zip | |
wcs(n)casecmp support, manpage comments from jmc@, okay deraadt@
Diffstat (limited to 'src/lib/libc/string')
| -rw-r--r-- | src/lib/libc/string/Makefile.inc | 6 | ||||
| -rw-r--r-- | src/lib/libc/string/wcscasecmp.c | 61 | ||||
| -rw-r--r-- | src/lib/libc/string/wmemchr.3 | 20 |
3 files changed, 82 insertions, 5 deletions
diff --git a/src/lib/libc/string/Makefile.inc b/src/lib/libc/string/Makefile.inc index 679ba1b213..44e011e3c1 100644 --- a/src/lib/libc/string/Makefile.inc +++ b/src/lib/libc/string/Makefile.inc | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # $OpenBSD: Makefile.inc,v 1.24 2011/04/04 18:16:24 stsp Exp $ | 1 | # $OpenBSD: Makefile.inc,v 1.25 2011/05/28 15:16:46 espie Exp $ |
| 2 | 2 | ||
| 3 | # string sources | 3 | # string sources |
| 4 | .PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/string ${LIBCSRCDIR}/string | 4 | .PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/string ${LIBCSRCDIR}/string |
| @@ -10,7 +10,7 @@ SRCS+= bm.c memccpy.c memrchr.c strcasecmp.c strcasestr.c strcoll.c strdup.c \ | |||
| 10 | wcslen.c wcsncat.c wcsncmp.c wcsncpy.c wcspbrk.c wcsrchr.c wcsspn.c \ | 10 | wcslen.c wcsncat.c wcsncmp.c wcsncpy.c wcspbrk.c wcsrchr.c wcsspn.c \ |
| 11 | wcsstr.c wcstok.c wcswcs.c wcswidth.c wmemchr.c wmemcmp.c wmemcpy.c \ | 11 | wcsstr.c wcstok.c wcswcs.c wcswidth.c wmemchr.c wmemcmp.c wmemcpy.c \ |
| 12 | wmemmove.c wmemset.c \ | 12 | wmemmove.c wmemset.c \ |
| 13 | timingsafe_bcmp.c | 13 | timingsafe_bcmp.c wcscasecmp.c |
| 14 | 14 | ||
| 15 | # machine-dependent net sources | 15 | # machine-dependent net sources |
| 16 | # m-d Makefile.inc must include sources for: | 16 | # m-d Makefile.inc must include sources for: |
| @@ -167,6 +167,7 @@ MLINKS+=wmemchr.3 wmemset.3 | |||
| 167 | MLINKS+=wmemchr.3 wcscat.3 | 167 | MLINKS+=wmemchr.3 wcscat.3 |
| 168 | MLINKS+=wmemchr.3 wcschr.3 | 168 | MLINKS+=wmemchr.3 wcschr.3 |
| 169 | MLINKS+=wmemchr.3 wcscmp.3 | 169 | MLINKS+=wmemchr.3 wcscmp.3 |
| 170 | MLINKS+=wmemchr.3 wcscasecmp.3 | ||
| 170 | MLINKS+=wmemchr.3 wcscpy.3 | 171 | MLINKS+=wmemchr.3 wcscpy.3 |
| 171 | MLINKS+=wmemchr.3 wcscspn.3 | 172 | MLINKS+=wmemchr.3 wcscspn.3 |
| 172 | MLINKS+=wmemchr.3 wcslcat.3 | 173 | MLINKS+=wmemchr.3 wcslcat.3 |
| @@ -174,6 +175,7 @@ MLINKS+=wmemchr.3 wcslcpy.3 | |||
| 174 | MLINKS+=wmemchr.3 wcslen.3 | 175 | MLINKS+=wmemchr.3 wcslen.3 |
| 175 | MLINKS+=wmemchr.3 wcsncat.3 | 176 | MLINKS+=wmemchr.3 wcsncat.3 |
| 176 | MLINKS+=wmemchr.3 wcsncmp.3 | 177 | MLINKS+=wmemchr.3 wcsncmp.3 |
| 178 | MLINKS+=wmemchr.3 wcsncasecmp.3 | ||
| 177 | MLINKS+=wmemchr.3 wcsncpy.3 | 179 | MLINKS+=wmemchr.3 wcsncpy.3 |
| 178 | MLINKS+=wmemchr.3 wcspbrk.3 | 180 | MLINKS+=wmemchr.3 wcspbrk.3 |
| 179 | MLINKS+=wmemchr.3 wcsrchr.3 | 181 | MLINKS+=wmemchr.3 wcsrchr.3 |
diff --git a/src/lib/libc/string/wcscasecmp.c b/src/lib/libc/string/wcscasecmp.c new file mode 100644 index 0000000000..d4085ad3e8 --- /dev/null +++ b/src/lib/libc/string/wcscasecmp.c | |||
| @@ -0,0 +1,61 @@ | |||
| 1 | /* $OpenBSD: wcscasecmp.c,v 1.1 2011/05/28 15:16:46 espie Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2011 Marc Espie | ||
| 5 | * | ||
| 6 | * Redistribution and use in source and binary forms, with or without | ||
| 7 | * modification, are permitted provided that the following conditions | ||
| 8 | * are met: | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer in the | ||
| 13 | * documentation and/or other materials provided with the distribution. | ||
| 14 | * | ||
| 15 | * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS | ||
| 16 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| 18 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD | ||
| 19 | * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| 21 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| 25 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 26 | */ | ||
| 27 | |||
| 28 | #include <wchar.h> | ||
| 29 | #include <wctype.h> | ||
| 30 | #include "locale/runetype.h" | ||
| 31 | |||
| 32 | int | ||
| 33 | wcscasecmp(const wchar_t *s1, const char *s2) | ||
| 34 | { | ||
| 35 | wchar_t l1, l2; | ||
| 36 | |||
| 37 | while ((l1 = towlower(*s1++)) == (l2 = towlower(*s2++))) { | ||
| 38 | if (l1 == 0) | ||
| 39 | return (0); | ||
| 40 | } | ||
| 41 | /* XXX assumes wchar_t = int */ | ||
| 42 | return ((rune_t)l1 - (rune_t)l2); | ||
| 43 | } | ||
| 44 | |||
| 45 | int | ||
| 46 | wcsncasecmp(const wchar_t *s1, const wchar_t *s2, size_t n) | ||
| 47 | { | ||
| 48 | wchar_t l1, l2; | ||
| 49 | |||
| 50 | if (n == 0) | ||
| 51 | return (0); | ||
| 52 | do { | ||
| 53 | if (((l1 = towlower(*s1++))) != (l2 = towlower(*s2++))) { | ||
| 54 | /* XXX assumes wchar_t = int */ | ||
| 55 | return ((rune_t)l1 - (rune_t)l2); | ||
| 56 | } | ||
| 57 | if (l1 == 0) | ||
| 58 | break; | ||
| 59 | } while (--n != 0); | ||
| 60 | return (0); | ||
| 61 | } | ||
diff --git a/src/lib/libc/string/wmemchr.3 b/src/lib/libc/string/wmemchr.3 index ff82c7b530..7c0740a03e 100644 --- a/src/lib/libc/string/wmemchr.3 +++ b/src/lib/libc/string/wmemchr.3 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | .\" $OpenBSD: wmemchr.3,v 1.4 2010/09/10 18:38:20 jmc Exp $ | 1 | .\" $OpenBSD: wmemchr.3,v 1.5 2011/05/28 15:16:46 espie Exp $ |
| 2 | .\" | 2 | .\" |
| 3 | .\" $NetBSD: wmemchr.3,v 1.9 2003/09/08 17:54:33 wiz Exp $ | 3 | .\" $NetBSD: wmemchr.3,v 1.9 2003/09/08 17:54:33 wiz Exp $ |
| 4 | .\" | 4 | .\" |
| @@ -35,7 +35,7 @@ | |||
| 35 | .\" | 35 | .\" |
| 36 | .\" from: @(#)strcpy.3 8.1 (Berkeley) 6/4/93 | 36 | .\" from: @(#)strcpy.3 8.1 (Berkeley) 6/4/93 |
| 37 | .\" | 37 | .\" |
| 38 | .Dd $Mdocdate: September 10 2010 $ | 38 | .Dd $Mdocdate: May 28 2011 $ |
| 39 | .Dt WMEMCHR 3 | 39 | .Dt WMEMCHR 3 |
| 40 | .Os | 40 | .Os |
| 41 | .Sh NAME | 41 | .Sh NAME |
| @@ -47,6 +47,7 @@ | |||
| 47 | .Nm wcscat , | 47 | .Nm wcscat , |
| 48 | .Nm wcschr , | 48 | .Nm wcschr , |
| 49 | .Nm wcscmp , | 49 | .Nm wcscmp , |
| 50 | .Nm wcscasecmp , | ||
| 50 | .Nm wcscpy , | 51 | .Nm wcscpy , |
| 51 | .Nm wcscspn , | 52 | .Nm wcscspn , |
| 52 | .Nm wcslcat , | 53 | .Nm wcslcat , |
| @@ -54,6 +55,7 @@ | |||
| 54 | .Nm wcslen , | 55 | .Nm wcslen , |
| 55 | .Nm wcsncat , | 56 | .Nm wcsncat , |
| 56 | .Nm wcsncmp , | 57 | .Nm wcsncmp , |
| 58 | .Nm wcsncasecmp , | ||
| 57 | .Nm wcsncpy , | 59 | .Nm wcsncpy , |
| 58 | .Nm wcspbrk , | 60 | .Nm wcspbrk , |
| 59 | .Nm wcsrchr , | 61 | .Nm wcsrchr , |
| @@ -78,6 +80,8 @@ | |||
| 78 | .Fn wcschr "const wchar_t *s" "wchar_t c" | 80 | .Fn wcschr "const wchar_t *s" "wchar_t c" |
| 79 | .Ft int | 81 | .Ft int |
| 80 | .Fn wcscmp "const wchar_t *s1" "const wchar_t *s2" | 82 | .Fn wcscmp "const wchar_t *s1" "const wchar_t *s2" |
| 83 | .Ft int | ||
| 84 | .Fn wcscasecmp "const wchar_t *s1" "const wchar_t *s2" | ||
| 81 | .Ft wchar_t * | 85 | .Ft wchar_t * |
| 82 | .Fn wcscpy "wchar_t * restrict s1" "const wchar_t * restrict s2" | 86 | .Fn wcscpy "wchar_t * restrict s1" "const wchar_t * restrict s2" |
| 83 | .Ft size_t | 87 | .Ft size_t |
| @@ -92,6 +96,8 @@ | |||
| 92 | .Fn wcsncat "wchar_t * restrict s1" "const wchar_t * restrict s2" "size_t n" | 96 | .Fn wcsncat "wchar_t * restrict s1" "const wchar_t * restrict s2" "size_t n" |
| 93 | .Ft int | 97 | .Ft int |
| 94 | .Fn wcsncmp "const wchar_t *s1" "const wchar_t * s2" "size_t n" | 98 | .Fn wcsncmp "const wchar_t *s1" "const wchar_t * s2" "size_t n" |
| 99 | .Ft int | ||
| 100 | .Fn wcsncasecmp "const wchar_t *s1" "const wchar_t * s2" "size_t n" | ||
| 95 | .Ft wchar_t * | 101 | .Ft wchar_t * |
| 96 | .Fn wcsncpy "wchar_t * restrict s1" "const wchar_t * restrict s2" "size_t n" | 102 | .Fn wcsncpy "wchar_t * restrict s1" "const wchar_t * restrict s2" "size_t n" |
| 97 | .Ft wchar_t * | 103 | .Ft wchar_t * |
| @@ -117,6 +123,7 @@ counterpart, such as | |||
| 117 | .Xr strcat 3 , | 123 | .Xr strcat 3 , |
| 118 | .Xr strchr 3 , | 124 | .Xr strchr 3 , |
| 119 | .Xr strcmp 3 , | 125 | .Xr strcmp 3 , |
| 126 | .Xr strcasecmp 3 , | ||
| 120 | .Xr strcpy 3 , | 127 | .Xr strcpy 3 , |
| 121 | .Xr strcspn 3 , | 128 | .Xr strcspn 3 , |
| 122 | .Xr strlcat 3 , | 129 | .Xr strlcat 3 , |
| @@ -124,6 +131,7 @@ counterpart, such as | |||
| 124 | .Xr strlen 3 , | 131 | .Xr strlen 3 , |
| 125 | .Xr strncat 3 , | 132 | .Xr strncat 3 , |
| 126 | .Xr strncmp 3 , | 133 | .Xr strncmp 3 , |
| 134 | .Xr strncasecmp 3 , | ||
| 127 | .Xr strncpy 3 , | 135 | .Xr strncpy 3 , |
| 128 | .Xr strpbrk 3 , | 136 | .Xr strpbrk 3 , |
| 129 | .Xr strrchr 3 , | 137 | .Xr strrchr 3 , |
| @@ -134,7 +142,13 @@ These functions conform to | |||
| 134 | .St -isoC-99 | 142 | .St -isoC-99 |
| 135 | and were first introduced in | 143 | and were first introduced in |
| 136 | .St -isoC-amd1 , | 144 | .St -isoC-amd1 , |
| 137 | with the exception of | 145 | except for |
| 146 | .Fn wcscasecmp | ||
| 147 | and | ||
| 148 | .Fn wcsncasecmp , | ||
| 149 | which conform to | ||
| 150 | .St -p1003.1-2008 , | ||
| 151 | and for | ||
| 138 | .Fn wcslcat | 152 | .Fn wcslcat |
| 139 | and | 153 | and |
| 140 | .Fn wcslcpy , | 154 | .Fn wcslcpy , |
