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