]>
Commit | Line | Data |
---|---|---|
3d9156a7 A |
1 | --- wcscoll.c.orig 2004-11-25 11:38:47.000000000 -0800 |
2 | +++ wcscoll.c 2005-02-18 18:17:11.000000000 -0800 | |
3 | @@ -27,13 +27,15 @@ | |
4 | #include <sys/cdefs.h> | |
5 | __FBSDID("$FreeBSD: src/lib/libc/string/wcscoll.c,v 1.3 2004/04/07 09:47:56 tjr Exp $"); | |
6 | ||
7 | +#include "xlocale_private.h" | |
8 | + | |
9 | #include <errno.h> | |
10 | #include <stdlib.h> | |
11 | #include <string.h> | |
12 | #include <wchar.h> | |
13 | #include "collate.h" | |
14 | ||
15 | -static char *__mbsdup(const wchar_t *); | |
16 | +static char *__mbsdup(const wchar_t *, locale_t); | |
17 | ||
18 | /* | |
19 | * Placeholder implementation of wcscoll(). Attempts to use the single-byte | |
20 | @@ -41,12 +43,13 @@ | |
21 | * with extended character sets. | |
22 | */ | |
23 | int | |
24 | -wcscoll(const wchar_t *ws1, const wchar_t *ws2) | |
25 | +wcscoll_l(const wchar_t *ws1, const wchar_t *ws2, locale_t loc) | |
26 | { | |
27 | char *mbs1, *mbs2; | |
28 | int diff, sverrno; | |
29 | ||
30 | - if (__collate_load_error || MB_CUR_MAX > 1) | |
31 | + NORMALIZE_LOCALE(loc); | |
32 | + if (loc->__collate_load_error || MB_CUR_MAX_L(loc) > 1) | |
33 | /* | |
34 | * Locale has no special collating order, could not be | |
35 | * loaded, or has an extended character set; do a fast binary | |
36 | @@ -54,7 +57,7 @@ | |
37 | */ | |
38 | return (wcscmp(ws1, ws2)); | |
39 | ||
40 | - if ((mbs1 = __mbsdup(ws1)) == NULL || (mbs2 = __mbsdup(ws2)) == NULL) { | |
41 | + if ((mbs1 = __mbsdup(ws1, loc)) == NULL || (mbs2 = __mbsdup(ws2, loc)) == NULL) { | |
42 | /* | |
43 | * Out of memory or illegal wide chars; fall back to wcscmp() | |
44 | * but leave errno indicating the error. Callers that don't | |
45 | @@ -67,7 +70,7 @@ | |
46 | return (wcscmp(ws1, ws2)); | |
47 | } | |
48 | ||
49 | - diff = strcoll(mbs1, mbs2); | |
50 | + diff = strcoll_l(mbs1, mbs2, loc); | |
51 | sverrno = errno; | |
52 | free(mbs1); | |
53 | free(mbs2); | |
54 | @@ -76,8 +79,14 @@ | |
55 | return (diff); | |
56 | } | |
57 | ||
58 | +int | |
59 | +wcscoll(const wchar_t *ws1, const wchar_t *ws2) | |
60 | +{ | |
61 | + return wcscoll_l(ws1, ws2, __current_locale()); | |
62 | +} | |
63 | + | |
64 | static char * | |
65 | -__mbsdup(const wchar_t *ws) | |
66 | +__mbsdup(const wchar_t *ws, locale_t loc) | |
67 | { | |
68 | static const mbstate_t initial; | |
69 | mbstate_t st; | |
70 | @@ -87,12 +96,12 @@ | |
71 | ||
72 | wcp = ws; | |
73 | st = initial; | |
74 | - if ((len = wcsrtombs(NULL, &wcp, 0, &st)) == (size_t)-1) | |
75 | + if ((len = wcsrtombs_l(NULL, &wcp, 0, &st, loc)) == (size_t)-1) | |
76 | return (NULL); | |
77 | if ((mbs = malloc(len + 1)) == NULL) | |
78 | return (NULL); | |
79 | st = initial; | |
80 | - wcsrtombs(mbs, &ws, len + 1, &st); | |
81 | + wcsrtombs_l(mbs, &ws, len + 1, &st, loc); | |
82 | ||
83 | return (mbs); | |
84 | } |