Print this page
Thread safety fixes.
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libc/port/locale/lmonetary.c
+++ new/usr/src/lib/libc/port/locale/lmonetary.c
1 1 /*
2 2 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
3 3 * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
4 4 * Copyright (c) 2000, 2001 Alexey Zelkin <phantom@FreeBSD.org>
5 5 * All rights reserved.
6 6 *
7 7 * Redistribution and use in source and binary forms, with or without
8 8 * modification, are permitted provided that the following conditions
9 9 * are met:
10 10 * 1. Redistributions of source code must retain the above copyright
11 11 * notice, this list of conditions and the following disclaimer.
12 12 * 2. Redistributions in binary form must reproduce the above copyright
13 13 * notice, this list of conditions and the following disclaimer in the
14 14 * documentation and/or other materials provided with the distribution.
15 15 *
16 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 26 * SUCH DAMAGE.
27 27 */
28 28
29 29 #include "lint.h"
30 30 #include <limits.h>
31 31 #include <stddef.h>
32 32 #include <stdlib.h>
33 33 #include <stdio.h>
34 34 #include <string.h>
35 35 #include <errno.h>
36 36 #include "ldpart.h"
37 37 #include "lmonetary.h"
38 38 #include "localeimpl.h"
39 39
40 40 extern const char *__fix_locale_grouping_str(const char *);
41 41
42 42 #define LCMONETARY_SIZE_FULL (sizeof (struct lc_monetary) / sizeof (char *))
43 43 #define LCMONETARY_SIZE_MIN \
44 44 (offsetof(struct lc_monetary, int_p_cs_precedes) / sizeof (char *))
45 45
46 46 static char empty[] = "";
47 47 static char numempty[] = { CHAR_MAX, '\0' };
48 48
49 49 struct lc_monetary lc_monetary_posix = {
50 50 empty, /* int_curr_symbol */
51 51 empty, /* currency_symbol */
52 52 empty, /* mon_decimal_point */
53 53 empty, /* mon_thousands_sep */
54 54 numempty, /* mon_grouping */
55 55 empty, /* positive_sign */
56 56 empty, /* negative_sign */
57 57 numempty, /* int_frac_digits */
58 58 numempty, /* frac_digits */
59 59 numempty, /* p_cs_precedes */
60 60 numempty, /* p_sep_by_space */
61 61 numempty, /* n_cs_precedes */
62 62 numempty, /* n_sep_by_space */
63 63 numempty, /* p_sign_posn */
64 64 numempty, /* n_sign_posn */
65 65 numempty, /* int_p_cs_precedes */
↓ open down ↓ |
65 lines elided |
↑ open up ↑ |
66 66 numempty, /* int_n_cs_precedes */
67 67 numempty, /* int_p_sep_by_space */
68 68 numempty, /* int_n_sep_by_space */
69 69 numempty, /* int_p_sign_posn */
70 70 numempty, /* int_n_sign_posn */
71 71 empty /* crncystr */
72 72 };
73 73
74 74 struct locdata __posix_monetary_locdata = {
75 75 .l_lname = "C",
76 - .l_refcnt = (uint32_t)-1,
77 76 .l_data = { &lc_monetary_posix }
78 77 };
79 78
80 79 static char
81 80 cnv(const char *str)
82 81 {
83 82 int i = strtol(str, NULL, 10);
84 83
85 84 if (i == -1)
86 85 i = CHAR_MAX;
87 86 return ((char)i);
88 87 }
89 88
90 89 struct locdata *
91 90 __lc_monetary_load(const char *name)
92 91 {
93 92 int ret;
94 93 int clen;
95 94 struct lc_monetary *lmon;
96 95 struct locdata *ldata;
97 96
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
98 97 if ((ldata = __locdata_alloc(name, sizeof (*lmon))) == NULL) {
99 98 return (NULL);
100 99 }
101 100 lmon = ldata->l_data[0];
102 101
103 102 ret = __part_load_locale(name, (char **)&ldata->l_data[1],
104 103 "LC_MONETARY", LCMONETARY_SIZE_FULL, LCMONETARY_SIZE_MIN,
105 104 (const char **)lmon);
106 105
107 106 if (ret != _LDP_LOADED) {
108 - __locdata_release(ldata);
107 + __locdata_free(ldata);
109 108 errno = EINVAL;
110 109 return (NULL);
111 110 }
112 111
113 112 /* special storage for currency string */
114 113 clen = strlen(lmon->currency_symbol) + 2;
115 114 ldata->l_data[2] = malloc(clen);
116 115 lmon->crncystr = ldata->l_data[2];
117 116 lmon->crncystr[0] = '\0';
118 117
119 118 lmon->mon_grouping = __fix_locale_grouping_str(lmon->mon_grouping);
120 119
121 120 #define M_ASSIGN_CHAR(NAME) \
122 121 (((char *)lmon->NAME)[0] = cnv(lmon->NAME))
123 122
124 123 M_ASSIGN_CHAR(int_frac_digits);
125 124 M_ASSIGN_CHAR(frac_digits);
126 125 M_ASSIGN_CHAR(p_cs_precedes);
127 126 M_ASSIGN_CHAR(p_sep_by_space);
128 127 M_ASSIGN_CHAR(n_cs_precedes);
129 128 M_ASSIGN_CHAR(n_sep_by_space);
130 129 M_ASSIGN_CHAR(p_sign_posn);
131 130 M_ASSIGN_CHAR(n_sign_posn);
132 131
133 132 /*
134 133 * The six additional C99 international monetary formatting
135 134 * parameters default to the national parameters when
136 135 * reading FreeBSD LC_MONETARY data files.
137 136 */
138 137 #define M_ASSIGN_ICHAR(NAME) \
139 138 if (lmon->int_##NAME == NULL) \
140 139 lmon->int_##NAME = lmon->NAME; \
141 140 else \
142 141 M_ASSIGN_CHAR(int_##NAME);
143 142
144 143 M_ASSIGN_ICHAR(p_cs_precedes);
145 144 M_ASSIGN_ICHAR(n_cs_precedes);
146 145 M_ASSIGN_ICHAR(p_sep_by_space);
147 146 M_ASSIGN_ICHAR(n_sep_by_space);
148 147 M_ASSIGN_ICHAR(p_sign_posn);
149 148 M_ASSIGN_ICHAR(n_sign_posn);
150 149
151 150 /*
152 151 * Now calculate the currency string (CRNCYSTR) for nl_langinfo.
153 152 * This is a legacy SUSv2 interface.
154 153 */
155 154 if ((lmon->p_cs_precedes[0] == lmon->n_cs_precedes[0]) &&
156 155 (lmon->currency_symbol[0] != '\0')) {
157 156 char sign = '\0';
158 157 switch (lmon->p_cs_precedes[0]) {
159 158 case 0:
160 159 sign = '-';
161 160 break;
162 161 case 1:
163 162 sign = '+';
164 163 break;
165 164 case CHAR_MAX:
166 165 /*
167 166 * Substitute currency string for radix character.
168 167 * To the best of my knowledge, no locale uses this.
169 168 */
170 169 if (strcmp(lmon->mon_decimal_point,
171 170 lmon->currency_symbol) == 0)
172 171 sign = '.';
173 172 break;
174 173 }
175 174 (void) snprintf(lmon->crncystr, clen, "%c%s", sign,
176 175 lmon->currency_symbol);
177 176 }
178 177
179 178 return (ldata);
180 179 }
↓ open down ↓ |
62 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX