1 /*
2 Copyright (c) 2016 Corinna Vinschen <corinna@vinschen.de>
3 */
4 /*
5 FUNCTION
6 <<wcscasecmp_l>>---case-insensitive wide character string compare
7
8 INDEX
9 wcscasecmp_l
10
11 SYNOPSIS
12 #include <wchar.h>
13 int wcscasecmp_l(const wchar_t *<[a]>, const wchar_t *<[b]>,
14 locale_t <[locale]>);
15
16 DESCRIPTION
17 <<wcscasecmp_l>> compares the wide character string at <[a]> to
18 the wide character string at <[b]> in a case-insensitive manner.
19
20 if <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object,
21 the behaviour is undefined.
22
23 RETURNS
24
25 If <<*<[a]>>> sorts lexicographically after <<*<[b]>>> (after
26 both are converted to uppercase), <<wcscasecmp_l>> returns a
27 number greater than zero. If the two strings match,
28 <<wcscasecmp_l>> returns zero. If <<*<[a]>>> sorts
29 lexicographically before <<*<[b]>>>, <<wcscasecmp_l>> returns a
30 number less than zero.
31
32 PORTABILITY
33 <<wcscasecmp_l>> is POSIX-1.2008
34
35 <<wcscasecmp_l>> requires no supporting OS subroutines. It uses
36 tolower() from elsewhere in this library.
37
38 QUICKREF
39 wcscasecmp_l
40 */
41
42 #define _DEFAULT_SOURCE
43 #include <wchar.h>
44 #include <wctype.h>
45
46 int
wcscasecmp_l(const wchar_t * s1,const wchar_t * s2,struct __locale_t * locale)47 wcscasecmp_l (const wchar_t *s1, const wchar_t *s2, struct __locale_t *locale)
48 {
49 int d = 0;
50 for ( ; ; )
51 {
52 const int c1 = towlower_l (*s1++, locale);
53 const int c2 = towlower_l (*s2++, locale);
54 if (((d = c1 - c2) != 0) || (c2 == '\0'))
55 break;
56 }
57 return d;
58 }
59