Deleted Added
full compact
setlocale.c (101366) setlocale.c (101498)
1/*
2 * Copyright (c) 1996 - 2002 FreeBSD Project
3 * Copyright (c) 1991, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Paul Borman at Krystal Technologies.
8 *

--- 25 unchanged lines hidden (view full) ---

34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 */
37
38#if defined(LIBC_SCCS) && !defined(lint)
39static char sccsid[] = "@(#)setlocale.c 8.1 (Berkeley) 7/4/93";
40#endif /* LIBC_SCCS and not lint */
41#include <sys/cdefs.h>
1/*
2 * Copyright (c) 1996 - 2002 FreeBSD Project
3 * Copyright (c) 1991, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Paul Borman at Krystal Technologies.
8 *

--- 25 unchanged lines hidden (view full) ---

34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 */
37
38#if defined(LIBC_SCCS) && !defined(lint)
39static char sccsid[] = "@(#)setlocale.c 8.1 (Berkeley) 7/4/93";
40#endif /* LIBC_SCCS and not lint */
41#include <sys/cdefs.h>
42__FBSDID("$FreeBSD: head/lib/libc/locale/setlocale.c 101366 2002-08-05 09:58:45Z ache $");
42__FBSDID("$FreeBSD: head/lib/libc/locale/setlocale.c 101498 2002-08-08 05:51:54Z ache $");
43
44#include <sys/types.h>
45#include <sys/stat.h>
46#include <errno.h>
47#include <limits.h>
48#include <locale.h>
49#include <rune.h>
50#include <stdlib.h>
51#include <string.h>
52#include <unistd.h>
53#include "collate.h"
54#include "lmonetary.h" /* for __monetary_load_locale() */
55#include "lnumeric.h" /* for __numeric_load_locale() */
56#include "lmessages.h" /* for __messages_load_locale() */
57#include "setlocale.h"
43
44#include <sys/types.h>
45#include <sys/stat.h>
46#include <errno.h>
47#include <limits.h>
48#include <locale.h>
49#include <rune.h>
50#include <stdlib.h>
51#include <string.h>
52#include <unistd.h>
53#include "collate.h"
54#include "lmonetary.h" /* for __monetary_load_locale() */
55#include "lnumeric.h" /* for __numeric_load_locale() */
56#include "lmessages.h" /* for __messages_load_locale() */
57#include "setlocale.h"
58#include "ldpart.h"
58#include "../stdtime/timelocal.h" /* for __time_load_locale() */
59
60/*
61 * Category names for getenv()
62 */
63static char *categories[_LC_LAST] = {
64 "LC_ALL",
65 "LC_COLLATE",

--- 21 unchanged lines hidden (view full) ---

87 * The locales we are going to try and load
88 */
89static char new_categories[_LC_LAST][ENCODING_LEN + 1];
90static char saved_categories[_LC_LAST][ENCODING_LEN + 1];
91
92static char current_locale_string[_LC_LAST * (ENCODING_LEN + 1/*"/"*/ + 1)];
93
94static char *currentlocale(void);
59#include "../stdtime/timelocal.h" /* for __time_load_locale() */
60
61/*
62 * Category names for getenv()
63 */
64static char *categories[_LC_LAST] = {
65 "LC_ALL",
66 "LC_COLLATE",

--- 21 unchanged lines hidden (view full) ---

88 * The locales we are going to try and load
89 */
90static char new_categories[_LC_LAST][ENCODING_LEN + 1];
91static char saved_categories[_LC_LAST][ENCODING_LEN + 1];
92
93static char current_locale_string[_LC_LAST * (ENCODING_LEN + 1/*"/"*/ + 1)];
94
95static char *currentlocale(void);
95static int wrap_setrunelocale(char *);
96static int wrap_setrunelocale(const char *);
96static char *loadlocale(int);
97
98char *
99setlocale(category, locale)
100 int category;
101 const char *locale;
102{
103 int i, j, len, saverr;

--- 97 unchanged lines hidden (view full) ---

201
202 for (i = 1; i < _LC_LAST; ++i) {
203 (void)strcpy(saved_categories[i], current_categories[i]);
204 if (loadlocale(i) == NULL) {
205 saverr = errno;
206 for (j = 1; j < i; j++) {
207 (void)strcpy(new_categories[j],
208 saved_categories[j]);
97static char *loadlocale(int);
98
99char *
100setlocale(category, locale)
101 int category;
102 const char *locale;
103{
104 int i, j, len, saverr;

--- 97 unchanged lines hidden (view full) ---

202
203 for (i = 1; i < _LC_LAST; ++i) {
204 (void)strcpy(saved_categories[i], current_categories[i]);
205 if (loadlocale(i) == NULL) {
206 saverr = errno;
207 for (j = 1; j < i; j++) {
208 (void)strcpy(new_categories[j],
209 saved_categories[j]);
209 (void)loadlocale(j);
210 if (loadlocale(j) == NULL) {
211 (void)strcpy(new_categories[j], "C");
212 (void)loadlocale(j);
213 }
210 }
211 errno = saverr;
212 return (NULL);
213 }
214 }
215 return (currentlocale());
216}
217

--- 12 unchanged lines hidden (view full) ---

230 current_categories[i]);
231 }
232 break;
233 }
234 return (current_locale_string);
235}
236
237static int
214 }
215 errno = saverr;
216 return (NULL);
217 }
218 }
219 return (currentlocale());
220}
221

--- 12 unchanged lines hidden (view full) ---

234 current_categories[i]);
235 }
236 break;
237 }
238 return (current_locale_string);
239}
240
241static int
238wrap_setrunelocale(locale)
239 char *locale;
242wrap_setrunelocale(const char *locale)
240{
243{
241 int ret = setrunelocale(locale);
244 int ret = setrunelocale((char *)locale);
242
243 if (ret != 0) {
244 errno = ret;
245
246 if (ret != 0) {
247 errno = ret;
245 return (-1);
248 return (_LDP_ERROR);
246 }
249 }
247 return (0);
250 return (_LDP_LOADED);
248}
249
250static char *
251loadlocale(category)
252 int category;
253{
251}
252
253static char *
254loadlocale(category)
255 int category;
256{
254 char *ret;
255 char *new = new_categories[category];
256 char *old = current_categories[category];
257 char *new = new_categories[category];
258 char *old = current_categories[category];
257 int (*func)();
258 int saverr;
259 int (*func)(const char *);
259
260 if ((new[0] == '.' &&
261 (new[1] == '\0' || (new[1] == '.' && new[2] == '\0'))) ||
262 strchr(new, '/') != NULL) {
263 errno = EINVAL;
264 return (NULL);
265 }
266

--- 6 unchanged lines hidden (view full) ---

273#endif
274 ) {
275 if (strlen(p) + 1/*"/"*/ + ENCODING_LEN +
276 1/*"/"*/ + CATEGORY_LEN >= PATH_MAX) {
277 errno = ENAMETOOLONG;
278 return (NULL);
279 }
280 _PathLocale = strdup(p);
260
261 if ((new[0] == '.' &&
262 (new[1] == '\0' || (new[1] == '.' && new[2] == '\0'))) ||
263 strchr(new, '/') != NULL) {
264 errno = EINVAL;
265 return (NULL);
266 }
267

--- 6 unchanged lines hidden (view full) ---

274#endif
275 ) {
276 if (strlen(p) + 1/*"/"*/ + ENCODING_LEN +
277 1/*"/"*/ + CATEGORY_LEN >= PATH_MAX) {
278 errno = ENAMETOOLONG;
279 return (NULL);
280 }
281 _PathLocale = strdup(p);
281 if (_PathLocale == NULL)
282 if (_PathLocale == NULL) {
283 errno = ENOMEM;
282 return (NULL);
284 return (NULL);
285 }
283 } else
284 _PathLocale = _PATH_LOCALE;
285 }
286
287 switch (category) {
288 case LC_CTYPE:
289 func = wrap_setrunelocale;
290 break;

--- 15 unchanged lines hidden (view full) ---

306 default:
307 errno = EINVAL;
308 return (NULL);
309 }
310
311 if (strcmp(new, old) == 0)
312 return (old);
313
286 } else
287 _PathLocale = _PATH_LOCALE;
288 }
289
290 switch (category) {
291 case LC_CTYPE:
292 func = wrap_setrunelocale;
293 break;

--- 15 unchanged lines hidden (view full) ---

309 default:
310 errno = EINVAL;
311 return (NULL);
312 }
313
314 if (strcmp(new, old) == 0)
315 return (old);
316
314 ret = func(new) != 0 ? NULL : new;
315 if (ret == NULL) {
316 saverr = errno;
317 if (func(old) != 0 && func("C") == 0)
318 (void)strcpy(old, "C");
319 errno = saverr;
320 } else
317 if (func(new) != _LDP_ERROR) {
321 (void)strcpy(old, new);
318 (void)strcpy(old, new);
319 return (old);
320 }
322
321
323 return (ret);
322 return (NULL);
324}
325
323}
324