summaryrefslogtreecommitdiff
path: root/src/lib/libc/string/wcscasecmp_l.c
diff options
context:
space:
mode:
authorschwarze <>2017-09-05 03:16:14 +0000
committerschwarze <>2017-09-05 03:16:14 +0000
commitf63c4fd91b8483c7d4364046fd6ef2d2679dd63a (patch)
treed7f851bfa426cf869a3a3aec05ffba386b6f2ce5 /src/lib/libc/string/wcscasecmp_l.c
parentc1d0fec9b838e4df93e396d54f1e4b9a41f7401a (diff)
downloadopenbsd-f63c4fd91b8483c7d4364046fd6ef2d2679dd63a.tar.gz
openbsd-f63c4fd91b8483c7d4364046fd6ef2d2679dd63a.tar.bz2
openbsd-f63c4fd91b8483c7d4364046fd6ef2d2679dd63a.zip
New POSIX xlocale implementation written from scratch.libressl-v2.6.1
Complete in the sense that all POSIX *locale(3) and *_l(3) functions are included, but in OpenBSD, we of course only really care about LC_CTYPE and we only support ASCII and UTF-8. With important help from kettenis@, guenther@, and jca@. Repeated testing in ports bulk builds by naddy@. Additional testing by jca@, sebastia@, dcoppa@, and others. OK kettenis@ dcoppa@, and guenther@ on an earlier version. Riding guenther@'s libc/librthread major bump.
Diffstat (limited to 'src/lib/libc/string/wcscasecmp_l.c')
-rw-r--r--src/lib/libc/string/wcscasecmp_l.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/lib/libc/string/wcscasecmp_l.c b/src/lib/libc/string/wcscasecmp_l.c
new file mode 100644
index 0000000000..35b99225c1
--- /dev/null
+++ b/src/lib/libc/string/wcscasecmp_l.c
@@ -0,0 +1,63 @@
1/* $OpenBSD: wcscasecmp_l.c,v 1.1 2017/09/05 03:16:14 schwarze 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
32int
33wcscasecmp_l(const wchar_t *s1, const wchar_t *s2, locale_t locale)
34{
35 wchar_t l1, l2;
36
37 while ((l1 = towlower_l(*s1++, locale)) ==
38 (l2 = towlower_l(*s2++, locale))) {
39 if (l1 == 0)
40 return (0);
41 }
42 /* XXX assumes wchar_t = int */
43 return ((rune_t)l1 - (rune_t)l2);
44}
45
46int
47wcsncasecmp_l(const wchar_t *s1, const wchar_t *s2, size_t n, locale_t locale)
48{
49 wchar_t l1, l2;
50
51 if (n == 0)
52 return (0);
53 do {
54 if (((l1 = towlower_l(*s1++, locale))) !=
55 (l2 = towlower_l(*s2++, locale))) {
56 /* XXX assumes wchar_t = int */
57 return ((rune_t)l1 - (rune_t)l2);
58 }
59 if (l1 == 0)
60 break;
61 } while (--n != 0);
62 return (0);
63}