Browse Source

wcs(n)casecmp support, manpage comments from jmc@, okay deraadt@

OPENBSD_5_0
espie 13 years ago
parent
commit
7b1036f191
4 changed files with 88 additions and 6 deletions
  1. +6
    -1
      src/include/wchar.h
  2. +4
    -2
      src/lib/libc/string/Makefile.inc
  3. +61
    -0
      src/lib/libc/string/wcscasecmp.c
  4. +17
    -3
      src/lib/libc/string/wmemchr.3

+ 6
- 1
src/include/wchar.h View File

@ -1,4 +1,4 @@
/* $OpenBSD: wchar.h,v 1.15 2011/04/28 17:38:46 stsp Exp $ */
/* $OpenBSD: wchar.h,v 1.16 2011/05/28 15:16:46 espie Exp $ */
/* $NetBSD: wchar.h,v 1.16 2003/03/07 07:11:35 tshiozak Exp $ */ /* $NetBSD: wchar.h,v 1.16 2003/03/07 07:11:35 tshiozak Exp $ */
/*- /*-
@ -145,6 +145,11 @@ long int wcstol(const wchar_t * __restrict, wchar_t ** __restrict, int base);
unsigned long int wcstoul(const wchar_t * __restrict, wchar_t ** __restrict, unsigned long int wcstoul(const wchar_t * __restrict, wchar_t ** __restrict,
int base); int base);
#if __POSIX_C_SOURCE >= 200809L
int wcscasecmp(const wchar_t *, const wchar_t *);
int wcsncasecmp(const wchar_t *, const wchar_t *, size_t);
#endif
#if __ISO_C_VISIBLE >= 1999 #if __ISO_C_VISIBLE >= 1999
float wcstof(const wchar_t * __restrict, wchar_t ** __restrict); float wcstof(const wchar_t * __restrict, wchar_t ** __restrict);
long double wcstold(const wchar_t * __restrict, wchar_t ** __restrict); long double wcstold(const wchar_t * __restrict, wchar_t ** __restrict);


+ 4
- 2
src/lib/libc/string/Makefile.inc View File

@ -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 # string sources
.PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/string ${LIBCSRCDIR}/string .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 \ 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 \ wcsstr.c wcstok.c wcswcs.c wcswidth.c wmemchr.c wmemcmp.c wmemcpy.c \
wmemmove.c wmemset.c \ wmemmove.c wmemset.c \
timingsafe_bcmp.c
timingsafe_bcmp.c wcscasecmp.c
# machine-dependent net sources # machine-dependent net sources
# m-d Makefile.inc must include sources for: # 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 wcscat.3
MLINKS+=wmemchr.3 wcschr.3 MLINKS+=wmemchr.3 wcschr.3
MLINKS+=wmemchr.3 wcscmp.3 MLINKS+=wmemchr.3 wcscmp.3
MLINKS+=wmemchr.3 wcscasecmp.3
MLINKS+=wmemchr.3 wcscpy.3 MLINKS+=wmemchr.3 wcscpy.3
MLINKS+=wmemchr.3 wcscspn.3 MLINKS+=wmemchr.3 wcscspn.3
MLINKS+=wmemchr.3 wcslcat.3 MLINKS+=wmemchr.3 wcslcat.3
@ -174,6 +175,7 @@ MLINKS+=wmemchr.3 wcslcpy.3
MLINKS+=wmemchr.3 wcslen.3 MLINKS+=wmemchr.3 wcslen.3
MLINKS+=wmemchr.3 wcsncat.3 MLINKS+=wmemchr.3 wcsncat.3
MLINKS+=wmemchr.3 wcsncmp.3 MLINKS+=wmemchr.3 wcsncmp.3
MLINKS+=wmemchr.3 wcsncasecmp.3
MLINKS+=wmemchr.3 wcsncpy.3 MLINKS+=wmemchr.3 wcsncpy.3
MLINKS+=wmemchr.3 wcspbrk.3 MLINKS+=wmemchr.3 wcspbrk.3
MLINKS+=wmemchr.3 wcsrchr.3 MLINKS+=wmemchr.3 wcsrchr.3


+ 61
- 0
src/lib/libc/string/wcscasecmp.c View File

@ -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);
}

+ 17
- 3
src/lib/libc/string/wmemchr.3 View File

@ -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 $ .\" $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 .\" from: @(#)strcpy.3 8.1 (Berkeley) 6/4/93
.\" .\"
.Dd $Mdocdate: September 10 2010 $
.Dd $Mdocdate: May 28 2011 $
.Dt WMEMCHR 3 .Dt WMEMCHR 3
.Os .Os
.Sh NAME .Sh NAME
@ -47,6 +47,7 @@
.Nm wcscat , .Nm wcscat ,
.Nm wcschr , .Nm wcschr ,
.Nm wcscmp , .Nm wcscmp ,
.Nm wcscasecmp ,
.Nm wcscpy , .Nm wcscpy ,
.Nm wcscspn , .Nm wcscspn ,
.Nm wcslcat , .Nm wcslcat ,
@ -54,6 +55,7 @@
.Nm wcslen , .Nm wcslen ,
.Nm wcsncat , .Nm wcsncat ,
.Nm wcsncmp , .Nm wcsncmp ,
.Nm wcsncasecmp ,
.Nm wcsncpy , .Nm wcsncpy ,
.Nm wcspbrk , .Nm wcspbrk ,
.Nm wcsrchr , .Nm wcsrchr ,
@ -78,6 +80,8 @@
.Fn wcschr "const wchar_t *s" "wchar_t c" .Fn wcschr "const wchar_t *s" "wchar_t c"
.Ft int .Ft int
.Fn wcscmp "const wchar_t *s1" "const wchar_t *s2" .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 * .Ft wchar_t *
.Fn wcscpy "wchar_t * restrict s1" "const wchar_t * restrict s2" .Fn wcscpy "wchar_t * restrict s1" "const wchar_t * restrict s2"
.Ft size_t .Ft size_t
@ -92,6 +96,8 @@
.Fn wcsncat "wchar_t * restrict s1" "const wchar_t * restrict s2" "size_t n" .Fn wcsncat "wchar_t * restrict s1" "const wchar_t * restrict s2" "size_t n"
.Ft int .Ft int
.Fn wcsncmp "const wchar_t *s1" "const wchar_t * s2" "size_t n" .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 * .Ft wchar_t *
.Fn wcsncpy "wchar_t * restrict s1" "const wchar_t * restrict s2" "size_t n" .Fn wcsncpy "wchar_t * restrict s1" "const wchar_t * restrict s2" "size_t n"
.Ft wchar_t * .Ft wchar_t *
@ -117,6 +123,7 @@ counterpart, such as
.Xr strcat 3 , .Xr strcat 3 ,
.Xr strchr 3 , .Xr strchr 3 ,
.Xr strcmp 3 , .Xr strcmp 3 ,
.Xr strcasecmp 3 ,
.Xr strcpy 3 , .Xr strcpy 3 ,
.Xr strcspn 3 , .Xr strcspn 3 ,
.Xr strlcat 3 , .Xr strlcat 3 ,
@ -124,6 +131,7 @@ counterpart, such as
.Xr strlen 3 , .Xr strlen 3 ,
.Xr strncat 3 , .Xr strncat 3 ,
.Xr strncmp 3 , .Xr strncmp 3 ,
.Xr strncasecmp 3 ,
.Xr strncpy 3 , .Xr strncpy 3 ,
.Xr strpbrk 3 , .Xr strpbrk 3 ,
.Xr strrchr 3 , .Xr strrchr 3 ,
@ -134,7 +142,13 @@ These functions conform to
.St -isoC-99 .St -isoC-99
and were first introduced in and were first introduced in
.St -isoC-amd1 , .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 .Fn wcslcat
and and
.Fn wcslcpy , .Fn wcslcpy ,


Loading…
Cancel
Save