]> git.saurik.com Git - apple/libc.git/blob - locale/FreeBSD/setlocale.c.patch
Libc-498.tar.gz
[apple/libc.git] / locale / FreeBSD / setlocale.c.patch
1 --- setlocale.c.orig 2004-11-25 11:38:19.000000000 -0800
2 +++ setlocale.c 2005-04-27 13:37:01.000000000 -0700
3 @@ -41,6 +41,8 @@
4 #include <sys/cdefs.h>
5 __FBSDID("$FreeBSD: src/lib/libc/locale/setlocale.c,v 1.50 2004/01/31 19:15:32 ache Exp $");
6
7 +#include "xlocale_private.h"
8 +
9 #include <sys/types.h>
10 #include <sys/stat.h>
11 #include <errno.h>
12 @@ -56,7 +58,7 @@
13 #include "lmessages.h" /* for __messages_load_locale() */
14 #include "setlocale.h"
15 #include "ldpart.h"
16 -#include "../stdtime/timelocal.h" /* for __time_load_locale() */
17 +#include "timelocal.h" /* for __time_load_locale() */
18
19 /*
20 * Category names for getenv()
21 @@ -99,15 +101,16 @@
22
23 static char *currentlocale(void);
24 static char *loadlocale(int);
25 -static const char *__get_locale_env(int);
26 +__private_extern__ const char *__get_locale_env(int);
27
28 char *
29 setlocale(category, locale)
30 int category;
31 const char *locale;
32 {
33 - int i, j, len, saverr;
34 + int i, j, len, saverr, save__numeric_fp_cvt;
35 const char *env, *r;
36 + locale_t save__lc_numeric_loc;
37
38 if (category < LC_ALL || category >= _LC_LAST) {
39 errno = EINVAL;
40 @@ -193,6 +196,9 @@
41 if (category != LC_ALL)
42 return (loadlocale(category));
43
44 + save__numeric_fp_cvt = __global_locale.__numeric_fp_cvt;
45 + save__lc_numeric_loc = __global_locale.__lc_numeric_loc;
46 + XL_RETAIN(save__lc_numeric_loc);
47 for (i = 1; i < _LC_LAST; ++i) {
48 (void)strcpy(saved_categories[i], current_categories[i]);
49 if (loadlocale(i) == NULL) {
50 @@ -205,10 +211,14 @@
51 (void)loadlocale(j);
52 }
53 }
54 + __global_locale.__numeric_fp_cvt = save__numeric_fp_cvt;
55 + __global_locale.__lc_numeric_loc = save__lc_numeric_loc;
56 + XL_RELEASE(save__lc_numeric_loc);
57 errno = saverr;
58 return (NULL);
59 }
60 }
61 + XL_RELEASE(save__lc_numeric_loc);
62 return (currentlocale());
63 }
64
65 @@ -237,7 +247,7 @@
66 {
67 char *new = new_categories[category];
68 char *old = current_categories[category];
69 - int (*func)(const char *);
70 + int (*func)(const char *, locale_t);
71 int saved_errno;
72
73 if ((new[0] == '.' &&
74 @@ -280,15 +290,26 @@
75 if (strcmp(new, old) == 0)
76 return (old);
77
78 - if (func(new) != _LDP_ERROR) {
79 + if (func(new, &__global_locale) != _LDP_ERROR) {
80 (void)strcpy(old, new);
81 + switch (category) {
82 + case LC_CTYPE:
83 + if (__global_locale.__numeric_fp_cvt == LC_NUMERIC_FP_SAME_LOCALE)
84 + __global_locale.__numeric_fp_cvt = LC_NUMERIC_FP_UNINITIALIZED;
85 + break;
86 + case LC_NUMERIC:
87 + __global_locale.__numeric_fp_cvt = LC_NUMERIC_FP_UNINITIALIZED;
88 + XL_RELEASE(__global_locale.__lc_numeric_loc);
89 + __global_locale.__lc_numeric_loc = NULL;
90 + break;
91 + }
92 return (old);
93 }
94
95 return (NULL);
96 }
97
98 -static const char *
99 +__private_extern__ const char *
100 __get_locale_env(category)
101 int category;
102 {
103 @@ -315,7 +336,7 @@
104 /*
105 * Detect locale storage location and store its value to _PathLocale variable
106 */
107 -int
108 +__private_extern__ int
109 __detect_path_locale(void)
110 {
111 if (_PathLocale == NULL) {