1 /* $NetBSD: setlocale.c,v 1.60 2012/03/04 21:14:56 tnozaki Exp $ */
4 * Copyright (c)2008 Citrus Project,
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 #if defined(LIBC_SCCS) && !defined(lint)
31 __RCSID("$NetBSD: setlocale.c,v 1.60 2012/03/04 21:14:56 tnozaki Exp $");
32 #endif /* LIBC_SCCS and not lint */
34 #include <sys/types.h>
42 #include "setlocale_local.h"
44 const char *_PathLocale
= NULL
;
46 static _locale_set_t all_categories
[_LC_LAST
] = {
47 [LC_ALL
] = &_generic_LC_ALL_setlocale
,
48 [LC_COLLATE
] = &_dummy_LC_COLLATE_setlocale
,
49 [LC_CTYPE
] = &_citrus_LC_CTYPE_setlocale
,
50 [LC_MONETARY
] = &_citrus_LC_MONETARY_setlocale
,
51 [LC_NUMERIC
] = &_citrus_LC_NUMERIC_setlocale
,
52 [LC_TIME
] = &_citrus_LC_TIME_setlocale
,
53 [LC_MESSAGES
] = &_citrus_LC_MESSAGES_setlocale
,
57 _find_category(int category
)
59 if (category
>= LC_ALL
&& category
< _LC_LAST
)
60 return all_categories
[category
];
65 _get_locale_env(const char *category
)
70 name
= (const char *)getenv("LC_ALL");
71 if (name
== NULL
|| *name
== '\0') {
73 name
= (const char *)getenv(category
);
74 if (name
== NULL
|| *name
== '\0') {
76 name
= getenv("LANG");
79 if (name
== NULL
|| *name
== '\0' || strchr(name
, '/'))
80 /* 4. if none is set, fall to "C" */
86 __setlocale(int category
, const char *name
)
89 struct _locale_impl_t
*impl
;
91 sl
= _find_category(category
);
94 if (issetugid() || ((_PathLocale
== NULL
&&
95 (_PathLocale
= getenv("PATH_LOCALE")) == NULL
) ||
96 *_PathLocale
== '\0'))
97 _PathLocale
= _PATH_LOCALE
;
98 impl
= *_current_locale();
99 return __UNCONST((*sl
)(name
, impl
));
103 setlocale(int category
, const char *locale
)
106 /* locale may be NULL */
108 __mb_len_max_runtime
= MB_LEN_MAX
;
109 return __setlocale(category
, locale
);
112 #if defined(__minix) && defined(__weak_alias)
113 __weak_alias(setlocale
, __setlocale50
)