diff options
Diffstat (limited to 'lib/libc/string')
-rw-r--r-- | lib/libc/string/Makefile.inc | 6 | ||||
-rw-r--r-- | lib/libc/string/wcscasecmp.c | 61 | ||||
-rw-r--r-- | lib/libc/string/wmemchr.3 | 20 |
3 files changed, 82 insertions, 5 deletions
diff --git a/lib/libc/string/Makefile.inc b/lib/libc/string/Makefile.inc index 679ba1b2131..44e011e3c19 100644 --- a/lib/libc/string/Makefile.inc +++ b/lib/libc/string/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.24 2011/04/04 18:16:24 stsp Exp $ +# $OpenBSD: Makefile.inc,v 1.25 2011/05/28 15:16:46 espie Exp $ # string sources .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 \ wcslen.c wcsncat.c wcsncmp.c wcsncpy.c wcspbrk.c wcsrchr.c wcsspn.c \ wcsstr.c wcstok.c wcswcs.c wcswidth.c wmemchr.c wmemcmp.c wmemcpy.c \ wmemmove.c wmemset.c \ - timingsafe_bcmp.c + timingsafe_bcmp.c wcscasecmp.c # machine-dependent net sources # m-d Makefile.inc must include sources for: @@ -167,6 +167,7 @@ MLINKS+=wmemchr.3 wmemset.3 MLINKS+=wmemchr.3 wcscat.3 MLINKS+=wmemchr.3 wcschr.3 MLINKS+=wmemchr.3 wcscmp.3 +MLINKS+=wmemchr.3 wcscasecmp.3 MLINKS+=wmemchr.3 wcscpy.3 MLINKS+=wmemchr.3 wcscspn.3 MLINKS+=wmemchr.3 wcslcat.3 @@ -174,6 +175,7 @@ MLINKS+=wmemchr.3 wcslcpy.3 MLINKS+=wmemchr.3 wcslen.3 MLINKS+=wmemchr.3 wcsncat.3 MLINKS+=wmemchr.3 wcsncmp.3 +MLINKS+=wmemchr.3 wcsncasecmp.3 MLINKS+=wmemchr.3 wcsncpy.3 MLINKS+=wmemchr.3 wcspbrk.3 MLINKS+=wmemchr.3 wcsrchr.3 diff --git a/lib/libc/string/wcscasecmp.c b/lib/libc/string/wcscasecmp.c new file mode 100644 index 00000000000..d4085ad3e87 --- /dev/null +++ b/lib/libc/string/wcscasecmp.c @@ -0,0 +1,61 @@ +/* $OpenBSD: wcscasecmp.c,v 1.1 2011/05/28 15:16:46 espie Exp $ */ + +/* + * Copyright (c) 2011 Marc Espie + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD + * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <wchar.h> +#include <wctype.h> +#include "locale/runetype.h" + +int +wcscasecmp(const wchar_t *s1, const char *s2) +{ + wchar_t l1, l2; + + while ((l1 = towlower(*s1++)) == (l2 = towlower(*s2++))) { + if (l1 == 0) + return (0); + } + /* XXX assumes wchar_t = int */ + return ((rune_t)l1 - (rune_t)l2); +} + +int +wcsncasecmp(const wchar_t *s1, const wchar_t *s2, size_t n) +{ + wchar_t l1, l2; + + if (n == 0) + return (0); + do { + if (((l1 = towlower(*s1++))) != (l2 = towlower(*s2++))) { + /* XXX assumes wchar_t = int */ + return ((rune_t)l1 - (rune_t)l2); + } + if (l1 == 0) + break; + } while (--n != 0); + return (0); +} diff --git a/lib/libc/string/wmemchr.3 b/lib/libc/string/wmemchr.3 index ff82c7b5309..7c0740a03ef 100644 --- a/lib/libc/string/wmemchr.3 +++ b/lib/libc/string/wmemchr.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: wmemchr.3,v 1.4 2010/09/10 18:38:20 jmc Exp $ +.\" $OpenBSD: wmemchr.3,v 1.5 2011/05/28 15:16:46 espie Exp $ .\" .\" $NetBSD: wmemchr.3,v 1.9 2003/09/08 17:54:33 wiz Exp $ .\" @@ -35,7 +35,7 @@ .\" .\" from: @(#)strcpy.3 8.1 (Berkeley) 6/4/93 .\" -.Dd $Mdocdate: September 10 2010 $ +.Dd $Mdocdate: May 28 2011 $ .Dt WMEMCHR 3 .Os .Sh NAME @@ -47,6 +47,7 @@ .Nm wcscat , .Nm wcschr , .Nm wcscmp , +.Nm wcscasecmp , .Nm wcscpy , .Nm wcscspn , .Nm wcslcat , @@ -54,6 +55,7 @@ .Nm wcslen , .Nm wcsncat , .Nm wcsncmp , +.Nm wcsncasecmp , .Nm wcsncpy , .Nm wcspbrk , .Nm wcsrchr , @@ -78,6 +80,8 @@ .Fn wcschr "const wchar_t *s" "wchar_t c" .Ft int .Fn wcscmp "const wchar_t *s1" "const wchar_t *s2" +.Ft int +.Fn wcscasecmp "const wchar_t *s1" "const wchar_t *s2" .Ft wchar_t * .Fn wcscpy "wchar_t * restrict s1" "const wchar_t * restrict s2" .Ft size_t @@ -92,6 +96,8 @@ .Fn wcsncat "wchar_t * restrict s1" "const wchar_t * restrict s2" "size_t n" .Ft int .Fn wcsncmp "const wchar_t *s1" "const wchar_t * s2" "size_t n" +.Ft int +.Fn wcsncasecmp "const wchar_t *s1" "const wchar_t * s2" "size_t n" .Ft wchar_t * .Fn wcsncpy "wchar_t * restrict s1" "const wchar_t * restrict s2" "size_t n" .Ft wchar_t * @@ -117,6 +123,7 @@ counterpart, such as .Xr strcat 3 , .Xr strchr 3 , .Xr strcmp 3 , +.Xr strcasecmp 3 , .Xr strcpy 3 , .Xr strcspn 3 , .Xr strlcat 3 , @@ -124,6 +131,7 @@ counterpart, such as .Xr strlen 3 , .Xr strncat 3 , .Xr strncmp 3 , +.Xr strncasecmp 3 , .Xr strncpy 3 , .Xr strpbrk 3 , .Xr strrchr 3 , @@ -134,7 +142,13 @@ These functions conform to .St -isoC-99 and were first introduced in .St -isoC-amd1 , -with the exception of +except for +.Fn wcscasecmp +and +.Fn wcsncasecmp , +which conform to +.St -p1003.1-2008 , +and for .Fn wcslcat and .Fn wcslcpy , |