1/* |
2 * Copyright (c) 1996 - 2001 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 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions --- 18 unchanged lines hidden (view full) --- 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 * SUCH DAMAGE. 36 * |
37 * $FreeBSD: head/lib/libc/locale/setlocale.c 72165 2001-02-08 16:58:53Z phantom $ |
38 */ 39 40#ifdef LIBC_RCS 41static const char rcsid[] = |
42 "$FreeBSD: head/lib/libc/locale/setlocale.c 72165 2001-02-08 16:58:53Z phantom $"; |
43#endif 44 45#if defined(LIBC_SCCS) && !defined(lint) 46static char sccsid[] = "@(#)setlocale.c 8.1 (Berkeley) 7/4/93"; 47#endif /* LIBC_SCCS and not lint */ 48 49#include <sys/types.h> 50#include <sys/stat.h> 51#include <limits.h> 52#include <locale.h> 53#include <rune.h> 54#include <stdlib.h> 55#include <string.h> 56#include <unistd.h> 57#include "collate.h" |
58#include "lmonetary.h" /* for __monetary_load_locale() */ 59#include "lnumeric.h" /* for __numeric_load_locale() */ 60#include "lmessages.h" /* for __messages_load_locale() */ |
61#include "setlocale.h" 62 63/* 64 * Category names for getenv() 65 */ 66static char *categories[_LC_LAST] = { 67 "LC_ALL", 68 "LC_COLLATE", --- 22 unchanged lines hidden (view full) --- 91 */ 92static char new_categories[_LC_LAST][ENCODING_LEN + 1]; 93static char saved_categories[_LC_LAST][ENCODING_LEN + 1]; 94 95static char current_locale_string[_LC_LAST * (ENCODING_LEN + 1/*"/"*/ + 1)]; 96 97static char *currentlocale __P((void)); 98static char *loadlocale __P((int)); |
99 100extern int __time_load_locale __P((const char *)); /* strftime.c */ 101 102char * 103setlocale(category, locale) 104 int category; 105 const char *locale; 106{ --- 138 unchanged lines hidden (view full) --- 245 ret = setrunelocale(new) ? NULL : new; 246 if (!ret) 247 (void)setrunelocale(old); 248 else 249 (void)strcpy(old, new); 250 return (ret); 251 } 252 |
253#define LOAD_CATEGORY(CAT, FUNC) \ 254 if (category == CAT) { \ 255 ret = (FUNC(new) < 0) ? NULL : new; \ 256 if (!ret) \ 257 (void)FUNC(old); \ 258 else \ 259 (void)strcpy(old, new); \ 260 return (ret); \ |
261 } 262 |
263 LOAD_CATEGORY(LC_COLLATE, __collate_load_tables); 264 LOAD_CATEGORY(LC_TIME, __time_load_locale); 265 LOAD_CATEGORY(LC_NUMERIC, __numeric_load_locale); 266 LOAD_CATEGORY(LC_MONETARY, __monetary_load_locale); 267 LOAD_CATEGORY(LC_MESSAGES, __messages_load_locale); |
268 |
269 /* Just in case...*/ 270 return (NULL); 271} 272 |