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 |
|
|
|
32 |
|
|
int |
33 |
|
|
wcscasecmp_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 |
|
|
|
46 |
|
|
int |
47 |
|
|
wcsncasecmp_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 |
|
|
} |