]> git.saurik.com Git - apple/libc.git/blob - string/FreeBSD/strcasecmp.c.patch
Libc-763.12.tar.gz
[apple/libc.git] / string / FreeBSD / strcasecmp.c.patch
1 --- strcasecmp.c.bsdnew 2009-11-18 18:24:33.000000000 -0800
2 +++ strcasecmp.c 2009-11-18 18:24:33.000000000 -0800
3 @@ -33,38 +33,59 @@ static char sccsid[] = "@(#)strcasecmp.c
4 #include <sys/cdefs.h>
5 __FBSDID("$FreeBSD: src/lib/libc/string/strcasecmp.c,v 1.8 2009/02/03 17:58:20 danger Exp $");
6
7 +#include "xlocale_private.h"
8 +
9 #include <strings.h>
10 #include <ctype.h>
11
12 typedef unsigned char u_char;
13
14 int
15 -strcasecmp(const char *s1, const char *s2)
16 +strcasecmp_l(s1, s2, loc)
17 + const char *s1, *s2;
18 + locale_t loc;
19 {
20 const u_char
21 *us1 = (const u_char *)s1,
22 *us2 = (const u_char *)s2;
23
24 - while (tolower(*us1) == tolower(*us2++))
25 + NORMALIZE_LOCALE(loc);
26 + while (tolower_l(*us1, loc) == tolower_l(*us2++, loc))
27 if (*us1++ == '\0')
28 return (0);
29 - return (tolower(*us1) - tolower(*--us2));
30 + return (tolower_l(*us1, loc) - tolower_l(*--us2, loc));
31 }
32
33 int
34 -strncasecmp(const char *s1, const char *s2, size_t n)
35 +strcasecmp(const char *s1, const char *s2)
36 {
37 + return strcasecmp_l(s1, s2, __current_locale());
38 +}
39 +
40 +int
41 +strncasecmp_l(s1, s2, n, loc)
42 + const char *s1, *s2;
43 + size_t n;
44 + locale_t loc;
45 +{
46 + NORMALIZE_LOCALE(loc);
47 if (n != 0) {
48 const u_char
49 *us1 = (const u_char *)s1,
50 *us2 = (const u_char *)s2;
51
52 do {
53 - if (tolower(*us1) != tolower(*us2++))
54 - return (tolower(*us1) - tolower(*--us2));
55 + if (tolower_l(*us1, loc) != tolower_l(*us2++, loc))
56 + return (tolower_l(*us1, loc) - tolower_l(*--us2, loc));
57 if (*us1++ == '\0')
58 break;
59 } while (--n != 0);
60 }
61 return (0);
62 }
63 +
64 +int
65 +strncasecmp(const char *s1, const char *s2, size_t n)
66 +{
67 + return strncasecmp_l(s1, s2, n, __current_locale());
68 +}