Deleted Added
sdiff udiff text old ( 65603 ) new ( 72165 )
full compact
1/*
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Paul Borman at Krystal Technologies.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions

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

28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * $FreeBSD: head/lib/libc/locale/setlocale.c 65603 2000-09-08 07:29:48Z kris $
37 */
38
39#ifdef LIBC_RCS
40static const char rcsid[] =
41 "$FreeBSD: head/lib/libc/locale/setlocale.c 65603 2000-09-08 07:29:48Z kris $";
42#endif
43
44#if defined(LIBC_SCCS) && !defined(lint)
45static char sccsid[] = "@(#)setlocale.c 8.1 (Berkeley) 7/4/93";
46#endif /* LIBC_SCCS and not lint */
47
48#include <sys/types.h>
49#include <sys/stat.h>
50#include <limits.h>
51#include <locale.h>
52#include <rune.h>
53#include <stdlib.h>
54#include <string.h>
55#include <unistd.h>
56#include "collate.h"
57#include "setlocale.h"
58
59/*
60 * Category names for getenv()
61 */
62static char *categories[_LC_LAST] = {
63 "LC_ALL",
64 "LC_COLLATE",

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

87 */
88static char new_categories[_LC_LAST][ENCODING_LEN + 1];
89static char saved_categories[_LC_LAST][ENCODING_LEN + 1];
90
91static char current_locale_string[_LC_LAST * (ENCODING_LEN + 1/*"/"*/ + 1)];
92
93static char *currentlocale __P((void));
94static char *loadlocale __P((int));
95static int stub_load_locale __P((const char *));
96
97extern int __time_load_locale __P((const char *)); /* strftime.c */
98
99char *
100setlocale(category, locale)
101 int category;
102 const char *locale;
103{

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

242 ret = setrunelocale(new) ? NULL : new;
243 if (!ret)
244 (void)setrunelocale(old);
245 else
246 (void)strcpy(old, new);
247 return (ret);
248 }
249
250 if (category == LC_COLLATE) {
251 ret = (__collate_load_tables(new) < 0) ? NULL : new;
252 if (!ret)
253 (void)__collate_load_tables(old);
254 else
255 (void)strcpy(old, new);
256 return (ret);
257 }
258
259 if (category == LC_TIME) {
260 ret = (__time_load_locale(new) < 0) ? NULL : new;
261 if (!ret)
262 (void)__time_load_locale(old);
263 else
264 (void)strcpy(old, new);
265 return (ret);
266 }
267
268 if (category == LC_MONETARY ||
269 category == LC_MESSAGES ||
270 category == LC_NUMERIC) {
271 ret = stub_load_locale(new) ? NULL : new;
272 if (!ret)
273 (void)stub_load_locale(old);
274 else
275 (void)strcpy(old, new);
276 return (ret);
277 }
278
279 /* Just in case...*/
280 return (NULL);
281}
282
283static int
284stub_load_locale(encoding)
285const char *encoding;
286{
287 char name[PATH_MAX];
288 struct stat st;
289
290 if (!encoding)
291 return(1);
292 /*
293 * The "C" and "POSIX" locale are always here.
294 */
295 if (!strcmp(encoding, "C") || !strcmp(encoding, "POSIX"))
296 return(0);
297 if (!_PathLocale)
298 return(1);
299 /* Range checking not needed, encoding has fixed size */
300 strcpy(name, _PathLocale);
301 strcat(name, "/");
302 strcat(name, encoding);
303#if 0
304 /*
305 * Some day we will actually look at this file.
306 */
307#endif
308 return (stat(name, &st) != 0 || !S_ISDIR(st.st_mode));
309}