]> git.saurik.com Git - apple/libc.git/blob - string/FreeBSD/strcoll.c.patch
Libc-763.11.tar.gz
[apple/libc.git] / string / FreeBSD / strcoll.c.patch
1 --- strcoll.c.bsdnew 2009-11-18 18:24:34.000000000 -0800
2 +++ strcoll.c 2009-11-18 18:26:43.000000000 -0800
3 @@ -28,58 +28,41 @@
4 #include <sys/cdefs.h>
5 __FBSDID("$FreeBSD: src/lib/libc/string/strcoll.c,v 1.14 2009/02/03 17:58:20 danger Exp $");
6
7 +#include "xlocale_private.h"
8 +
9 #include <stdlib.h>
10 #include <string.h>
11 +#include <wchar.h>
12 +#include <errno.h>
13 #include "collate.h"
14
15 int
16 -strcoll(const char *s, const char *s2)
17 +strcoll_l(const char *s, const char *s2, locale_t loc)
18 {
19 - int len, len2, prim, prim2, sec, sec2, ret, ret2;
20 - const char *t, *t2;
21 - char *tt, *tt2;
22 + int ret;
23 + const wchar_t *t = NULL, *t2 = NULL;
24 + int sverrno;
25
26 - if (__collate_load_error)
27 + NORMALIZE_LOCALE(loc);
28 + if (loc->__collate_load_error || (t = __collate_mbstowcs(s, loc)) == NULL || (t2 = __collate_mbstowcs(s2, loc)) == NULL) {
29 + sverrno = errno;
30 + free((void *)t);
31 + free((void *)t2);
32 + errno = sverrno;
33 return strcmp(s, s2);
34 -
35 - len = len2 = 1;
36 - ret = ret2 = 0;
37 - if (__collate_substitute_nontrivial) {
38 - t = tt = __collate_substitute(s);
39 - t2 = tt2 = __collate_substitute(s2);
40 - } else {
41 - tt = tt2 = NULL;
42 - t = s;
43 - t2 = s2;
44 }
45 - while(*t && *t2) {
46 - prim = prim2 = 0;
47 - while(*t && !prim) {
48 - __collate_lookup(t, &len, &prim, &sec);
49 - t += len;
50 - }
51 - while(*t2 && !prim2) {
52 - __collate_lookup(t2, &len2, &prim2, &sec2);
53 - t2 += len2;
54 - }
55 - if(!prim || !prim2)
56 - break;
57 - if(prim != prim2) {
58 - ret = prim - prim2;
59 - goto end;
60 - }
61 - if(!ret2)
62 - ret2 = sec - sec2;
63 - }
64 - if(!*t && *t2)
65 - ret = -(int)((u_char)*t2);
66 - else if(*t && !*t2)
67 - ret = (u_char)*t;
68 - else if(!*t && !*t2)
69 - ret = ret2;
70 - end:
71 - free(tt);
72 - free(tt2);
73 +
74 + ret = wcscoll_l(t, t2, loc);
75 + sverrno = errno;
76 + free((void *)t);
77 + free((void *)t2);
78 + errno = sverrno;
79
80 return ret;
81 }
82 +
83 +int
84 +strcoll(const char *s, const char *s2)
85 +{
86 + return strcoll_l(s, s2, __current_locale());
87 +}