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 #include <wchar.h>
37 #include <wctype.h>
38 
39 int
wcscasecmp(const wchar_t * s1,const wchar_t * s2)40 wcscasecmp (const wchar_t *s1,
41 	const wchar_t *s2)
42 {
43   int d = 0;
44   for ( ; ; )
45     {
46       const int c1 = towlower (*s1++);
47       const int c2 = towlower (*s2++);
48       if (((d = c1 - c2) != 0) || (c2 == '\0'))
49         break;
50     }
51   return d;
52 }
53