Deleted Added
sdiff udiff text old ( 101366 ) new ( 101498 )
full compact
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 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"
58#include "ldpart.h"
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);
96static int wrap_setrunelocale(const char *);
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]);
210 if (loadlocale(j) == NULL) {
211 (void)strcpy(new_categories[j], "C");
212 (void)loadlocale(j);
213 }
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
242wrap_setrunelocale(const char *locale)
243{
244 int ret = setrunelocale((char *)locale);
245
246 if (ret != 0) {
247 errno = ret;
248 return (_LDP_ERROR);
249 }
250 return (_LDP_LOADED);
251}
252
253static char *
254loadlocale(category)
255 int category;
256{
257 char *new = new_categories[category];
258 char *old = current_categories[category];
259 int (*func)(const char *);
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);
282 if (_PathLocale == NULL) {
283 errno = ENOMEM;
284 return (NULL);
285 }
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
317 if (func(new) != _LDP_ERROR) {
318 (void)strcpy(old, new);
319 return (old);
320 }
321
322 return (NULL);
323}
324