diff options
| author | christos <christos@NetBSD.org> | 2006-08-22 20:50:46 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2006-08-22 20:50:46 +0000 |
| commit | 54097ce7af2a6f6914ccd016c860ec1acb60f40b (patch) | |
| tree | c6770f61457e66d780b762e59764e5699d66f91b /lib/libc/string | |
| parent | c10a5d302a8996596c63f3ed2ad334c86ede2bb8 (diff) | |
PR/34238: Aleksey Cheusov: add wcsdup, wcscasecmp and wcsncasecmp functions
Diffstat (limited to 'lib/libc/string')
| -rw-r--r-- | lib/libc/string/Makefile.inc | 4 | ||||
| -rw-r--r-- | lib/libc/string/wcscasecmp.c | 39 | ||||
| -rw-r--r-- | lib/libc/string/wcsdup.c | 32 | ||||
| -rw-r--r-- | lib/libc/string/wcsncasecmp.c | 41 |
4 files changed, 114 insertions, 2 deletions
diff --git a/lib/libc/string/Makefile.inc b/lib/libc/string/Makefile.inc index 201386088bf..dba75874bc1 100644 --- a/lib/libc/string/Makefile.inc +++ b/lib/libc/string/Makefile.inc @@ -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 diff --git a/lib/libc/string/wcscasecmp.c b/lib/libc/string/wcscasecmp.c new file mode 100644 index 00000000000..023c97f54e1 --- /dev/null +++ b/lib/libc/string/wcscasecmp.c @@ -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; + } +} diff --git a/lib/libc/string/wcsdup.c b/lib/libc/string/wcsdup.c new file mode 100644 index 00000000000..6d2c73b9fbf --- /dev/null +++ b/lib/libc/string/wcsdup.c @@ -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); +} diff --git a/lib/libc/string/wcsncasecmp.c b/lib/libc/string/wcsncasecmp.c new file mode 100644 index 00000000000..3dfbadc5e51 --- /dev/null +++ b/lib/libc/string/wcsncasecmp.c @@ -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; +} |
