1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21: #include <locale.h>
22: #include <bits/libc-lock.h>
23: #include <stdlib.h>
24: #include <string.h>
25:
26: #include <localeinfo.h>
27:
28:
29:
30: __libc_lock_define (extern , __libc_setlocale_lock attribute_hidden)
31:
32:
33: __locale_t
34: __duplocale (__locale_t dataset)
35: {
36:
37: if (dataset == _nl_C_locobj_ptr)
38: return dataset;
39:
40: __locale_t result;
41: int cnt;
42: size_t names_len = 0;
43:
44:
45: for (cnt = 0; cnt < __LC_LAST; ++cnt)
46: if (cnt != LC_ALL && dataset->__names[cnt] != _nl_C_name)
47: names_len += strlen (dataset->__names[cnt]) + 1;
48:
49:
50: result = malloc (sizeof (struct __locale_struct) + names_len);
51:
52: if (result != NULL)
53: {
54: char *namep = (char *) (result + 1);
55:
56:
57: __libc_lock_lock (__libc_setlocale_lock);
58:
59: for (cnt = 0; cnt < __LC_LAST; ++cnt)
60: if (cnt != LC_ALL)
61: {
62: result->__locales[cnt] = dataset->__locales[cnt];
63: if (result->__locales[cnt]->usage_count < MAX_USAGE_COUNT)
64: ++result->__locales[cnt]->usage_count;
65:
66: if (dataset->__names[cnt] == _nl_C_name)
67: result->__names[cnt] = _nl_C_name;
68: else
69: {
70: result->__names[cnt] = namep;
71: namep = __stpcpy (namep, dataset->__names[cnt]) + 1;
72: }
73: }
74:
75:
76: result->__ctype_b = dataset->__ctype_b;
77: result->__ctype_tolower = dataset->__ctype_tolower;
78: result->__ctype_toupper = dataset->__ctype_toupper;
79:
80:
81: __libc_lock_unlock (__libc_setlocale_lock);
82: }
83:
84: return result;
85: }
86: weak_alias (__duplocale, duplocale)