This source file includes following definitions.
- rpl_duplocale
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21
22 #include <locale.h>
23
24 #include <errno.h>
25 #include <string.h>
26
27 #define SIZEOF(a) (sizeof(a) / sizeof(a[0]))
28
29 #undef duplocale
30
31 locale_t
32 rpl_duplocale (locale_t locale)
33 {
34
35
36
37
38
39
40 if (locale == LC_GLOBAL_LOCALE)
41 {
42
43
44 static struct { int cat; int mask; } const categories[] =
45 {
46 { LC_NUMERIC, LC_NUMERIC_MASK },
47 { LC_TIME, LC_TIME_MASK },
48 { LC_COLLATE, LC_COLLATE_MASK },
49 { LC_MONETARY, LC_MONETARY_MASK },
50 { LC_MESSAGES, LC_MESSAGES_MASK }
51 #ifdef LC_PAPER
52 , { LC_PAPER, LC_PAPER_MASK }
53 #endif
54 #ifdef LC_NAME
55 , { LC_NAME, LC_NAME_MASK }
56 #endif
57 #ifdef LC_ADDRESS
58 , { LC_ADDRESS, LC_ADDRESS_MASK }
59 #endif
60 #ifdef LC_TELEPHONE
61 , { LC_TELEPHONE, LC_TELEPHONE_MASK }
62 #endif
63 #ifdef LC_MEASUREMENT
64 , { LC_MEASUREMENT, LC_MEASUREMENT_MASK }
65 #endif
66 #ifdef LC_IDENTIFICATION
67 , { LC_IDENTIFICATION, LC_IDENTIFICATION_MASK }
68 #endif
69 };
70 char base_name[SETLOCALE_NULL_MAX];
71 int err;
72 locale_t base_copy;
73 unsigned int i;
74
75 err = setlocale_null_r (LC_CTYPE, base_name, sizeof (base_name));
76 if (err)
77 {
78 errno = err;
79 return NULL;
80 }
81 base_copy = newlocale (LC_ALL_MASK, base_name, NULL);
82 if (base_copy == NULL)
83 return NULL;
84
85 for (i = 0; i < SIZEOF (categories); i++)
86 {
87 int category = categories[i].cat;
88 int category_mask = categories[i].mask;
89 char name[SETLOCALE_NULL_MAX];
90
91 err = setlocale_null_r (category, name, sizeof (name));
92 if (err)
93 {
94 errno = err;
95 return NULL;
96 }
97 if (strcmp (name, base_name) != 0)
98 {
99 locale_t copy = newlocale (category_mask, name, base_copy);
100 if (copy == NULL)
101 {
102 int saved_errno = errno;
103 freelocale (base_copy);
104 errno = saved_errno;
105 return NULL;
106 }
107
108
109 base_copy = copy;
110 }
111 }
112
113 return base_copy;
114 }
115
116 return duplocale (locale);
117 }