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