Print this page
Thread safety fixes.
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libc/port/locale/setrunelocale.c
+++ new/usr/src/lib/libc/port/locale/setrunelocale.c
1 1 /*
2 2 * Copyright 2013 Garrett D'Amore <garrett@damore.org>
3 3 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
4 4 * Copyright (c) 1993
5 5 * The Regents of the University of California. All rights reserved.
6 6 *
7 7 * This code is derived from software contributed to Berkeley by
8 8 * Paul Borman at Krystal Technologies.
9 9 *
10 10 * Redistribution and use in source and binary forms, with or without
11 11 * modification, are permitted provided that the following conditions
12 12 * are met:
13 13 * 1. Redistributions of source code must retain the above copyright
14 14 * notice, this list of conditions and the following disclaimer.
15 15 * 2. Redistributions in binary form must reproduce the above copyright
16 16 * notice, this list of conditions and the following disclaimer in the
17 17 * documentation and/or other materials provided with the distribution.
18 18 * 4. Neither the name of the University nor the names of its contributors
19 19 * may be used to endorse or promote products derived from this software
20 20 * without specific prior written permission.
21 21 *
22 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 32 * SUCH DAMAGE.
33 33 */
34 34
35 35 #include "lint.h"
36 36 #include "file64.h"
37 37 #include <errno.h>
38 38 #include <limits.h>
39 39 #include <string.h>
40 40 #include <stdio.h>
41 41 #include <stdlib.h>
42 42 #include <unistd.h>
43 43 #include <wchar.h>
44 44 #include "runetype.h"
45 45 #include "ldpart.h"
46 46 #include "mblocal.h"
47 47 #include "setlocale.h"
48 48 #include "_ctype.h"
49 49 #include "lctype.h"
50 50 #include "localeimpl.h"
51 51
52 52 extern _RuneLocale *_Read_RuneMagi(const char *);
53 53
54 54 struct lc_ctype lc_ctype_posix = {
55 55 .lc_mbrtowc = __mbrtowc_ascii,
56 56 .lc_mbsinit = __mbsinit_ascii,
57 57 .lc_mbsnrtowcs = __mbsnrtowcs_ascii,
58 58 .lc_wcrtomb = __wcrtomb_ascii,
↓ open down ↓ |
58 lines elided |
↑ open up ↑ |
59 59 .lc_wcsnrtombs = __wcsnrtombs_ascii,
60 60 .lc_is_ascii = 1,
61 61 .lc_max_mblen = 1,
62 62 .lc_trans_upper = _DefaultRuneLocale.__mapupper,
63 63 .lc_trans_lower = _DefaultRuneLocale.__maplower,
64 64 .lc_ctype_mask = _DefaultRuneLocale.__runetype,
65 65 };
66 66
67 67 struct locdata __posix_ctype_locdata = {
68 68 .l_lname = "C",
69 - .l_refcnt = (uint32_t)-1,
70 69 .l_data = { &lc_ctype_posix, &_DefaultRuneLocale }
71 70 };
72 71
73 72
74 73 /*
75 74 * Table of initializers for encodings. When you add a new encoding type,
76 75 * this table should be updated.
77 76 */
78 77 static struct {
79 78 const char *e_name;
80 79 void (*e_init)(struct lc_ctype *);
81 80 } encodings[] = {
82 81 { "NONE", _none_init },
83 82 { "UTF-8", _UTF8_init },
84 83 { "EUC-CN", _EUC_CN_init },
85 84 { "EUC-JP", _EUC_JP_init },
86 85 { "EUC-KR", _EUC_KR_init },
87 86 { "EUC-TW", _EUC_TW_init },
88 87 { "GB18030", _GB18030_init },
89 88 { "GB2312", _GB2312_init },
90 89 { "GBK", _GBK_init },
91 90 { "BIG5", _BIG5_init },
92 91 { "MSKanji", _MSKanji_init },
93 92 { NULL, NULL }
94 93 };
95 94
96 95
97 96 struct locdata *
98 97 __lc_ctype_load(const char *name)
99 98 {
100 99 struct locdata *ldata;
101 100 struct lc_ctype *lct;
102 101 _RuneLocale *rl;
103 102 int i;
104 103 char path[PATH_MAX];
105 104
106 105 if ((ldata = __locdata_alloc(name, sizeof (*lct))) == NULL)
↓ open down ↓ |
27 lines elided |
↑ open up ↑ |
107 106 return (NULL);
108 107 lct = ldata->l_data[0];
109 108 /*
110 109 * Slurp the locale file into the cache.
111 110 */
112 111
113 112 (void) snprintf(path, sizeof (path), "%s/%s/LC_CTYPE/LCL_DATA",
114 113 _PathLocale, name);
115 114
116 115 if ((rl = _Read_RuneMagi(path)) == NULL) {
117 - __locdata_release(ldata);
116 + __locdata_free(ldata);
118 117 errno = EINVAL;
119 118 return (NULL);
120 119 }
121 120 ldata->l_data[1] = rl;
122 121
123 122 lct->lc_mbrtowc = NULL;
124 123 lct->lc_mbsinit = NULL;
125 124 lct->lc_mbsnrtowcs = NULL;
126 125 lct->lc_wcrtomb = NULL;
127 126 lct->lc_wcsnrtombs = NULL;
128 127 lct->lc_ctype_mask = rl->__runetype;
129 128 lct->lc_trans_upper = rl->__mapupper;
130 129 lct->lc_trans_lower = rl->__maplower;
131 130
↓ open down ↓ |
4 lines elided |
↑ open up ↑ |
132 131 /* set up the function pointers */
133 132 for (i = 0; encodings[i].e_name != NULL; i++) {
134 133 int l = strlen(encodings[i].e_name);
135 134 if ((strncmp(rl->__encoding, encodings[i].e_name, l) == 0) &&
136 135 (rl->__encoding[l] == '\0' || rl->__encoding[l] == '@')) {
137 136 encodings[i].e_init(lct);
138 137 break;
139 138 }
140 139 }
141 140 if (encodings[i].e_name == NULL) {
142 - __locdata_release(ldata);
141 + __locdata_free(ldata);
143 142 errno = EINVAL;
144 143 return (NULL);
145 144 }
146 145
147 146
148 147 return (ldata);
149 148 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX