PR/34238: Aleksey Cheusov: add wcsdup, wcscasecmp and wcsncasecmp functions

This commit is contained in:
christos 2006-08-22 20:50:46 +00:00
parent c10a5d302a
commit 54097ce7af
6 changed files with 120 additions and 5 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: wchar.h,v 1.25 2006/04/15 12:17:22 tnozaki Exp $ */
/* $NetBSD: wchar.h,v 1.26 2006/08/22 20:50:46 christos Exp $ */
/*-
* Copyright (c)1999 Citrus Project,
@ -191,6 +191,9 @@ int vwscanf(const wchar_t * __restrict, _BSD_VA_LIST_);
struct tinfo;
int t_putws(struct tinfo *, const wchar_t *, int, void (*)(wchar_t, void *),
void *);
wchar_t *wcsdup (const wchar_t *);
int wcsncasecmp (const wchar_t *, const wchar_t *, size_t);
int wcscasecmp(const wchar_t *, const wchar_t *);
#endif
__END_DECLS

View File

@ -1,4 +1,4 @@
# $NetBSD: shlib_version,v 1.181 2006/08/12 23:49:53 christos Exp $
# $NetBSD: shlib_version,v 1.182 2006/08/22 20:50:46 christos Exp $
# Remember to update distrib/sets/lists/base/shl.* when changing
#
# things we wish to do on next major version bump:
@ -17,4 +17,4 @@
# - libc/net/getnet{ent,namadr}.c, netdb.h: remove __n_pad0
#
major=12
minor=146
minor=147

View File

@ -1,5 +1,5 @@
# from: @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
# $NetBSD: Makefile.inc,v 1.61 2006/08/12 23:49:54 christos Exp $
# $NetBSD: Makefile.inc,v 1.62 2006/08/22 20:50:46 christos Exp $
# string sources
.PATH: ${ARCHDIR}/string ${.CURDIR}/string
@ -11,7 +11,7 @@ SRCS+= bm.c strcasecmp.c strncasecmp.c strcasestr.c strcoll.c strdup.c \
# wide char
SRCS+= wcscat.c wcschr.c wcscmp.c wcscpy.c wcscspn.c wcslcat.c wcslcpy.c \
wcslen.c wcsncat.c \
wcslen.c wcsncat.c wcscasecmp.c wcsdup.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

View File

@ -0,0 +1,39 @@
/* $NetBSD: wcscasecmp.c,v 1.1 2006/08/22 20:50:46 christos Exp $ */
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: wcscasecmp.c,v 1.1 2006/08/22 20:50:46 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <assert.h>
#include <wchar.h>
#include <wctype.h>
__weak_alias(wcscasecmp,_wcscasecmp)
int
wcscasecmp(const wchar_t *s1, const wchar_t *s2)
{
int lc1 = 0;
int lc2 = 0;
int diff = 0;
_DIAGASSERT(s1);
_DIAGASSERT(s2);
for (;;) {
lc1 = towlower(*s1);
lc2 = towlower(*s2);
diff = lc1 - lc2;
if (diff)
return diff;
if (!lc1)
return 0;
++s1;
++s2;
}
}

32
lib/libc/string/wcsdup.c Normal file
View File

@ -0,0 +1,32 @@
/* $NetBSD: wcsdup.c,v 1.1 2006/08/22 20:50:46 christos Exp $ */
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: wcsdup.c,v 1.1 2006/08/22 20:50:46 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <wchar.h>
__weak_alias(wcsdup,_wcsdup)
wchar_t *
wcsdup(const wchar_t *str)
{
wchar_t *copy;
size_t len;
_DIAGASSERT(str != NULL);
len = wcslen(str) + 1;
copy = malloc(len * sizeof (wchar_t));
if (!copy)
return NULL;
return wmemcpy(copy, str, len);
}

View File

@ -0,0 +1,41 @@
/* $NetBSD: wcsncasecmp.c,v 1.1 2006/08/22 20:50:46 christos Exp $ */
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: wcsncasecmp.c,v 1.1 2006/08/22 20:50:46 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <assert.h>
#include <wchar.h>
#include <wctype.h>
__weak_alias(wcsncasecmp,_wcsncasecmp)
int
wcsncasecmp(const wchar_t *s1, const wchar_t *s2, size_t n)
{
int lc1 = 0;
int lc2 = 0;
int diff = 0;
_DIAGASSERT(s1);
_DIAGASSERT(s2);
while (n--) {
lc1 = towlower (*s1);
lc2 = towlower (*s2);
diff = lc1 - lc2;
if (diff)
return diff;
if (!lc1)
return 0;
++s1;
++s2;
}
return 0;
}