1 | /* hard-locale.h -- Same as hard-locale.c.
|
---|
2 | *
|
---|
3 | * For gawk, put this in a header file, provides source code
|
---|
4 | * compatibility with GNU grep for dfa.c, so that dfa.c need
|
---|
5 | * not be continually modified by hand.
|
---|
6 | */
|
---|
7 | /* hard-locale.c -- Determine whether a locale is hard.
|
---|
8 | Copyright 1997, 1998, 1999 Free Software Foundation, Inc.
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify
|
---|
11 | it under the terms of the GNU General Public License as published by
|
---|
12 | the Free Software Foundation; either version 2, or (at your option)
|
---|
13 | any later version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful,
|
---|
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | GNU General Public License for more details.
|
---|
19 |
|
---|
20 | You should have received a copy of the GNU General Public License
|
---|
21 | along with this program; if not, write to the Free Software Foundation,
|
---|
22 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
|
---|
23 |
|
---|
24 |
|
---|
25 | /* Return nonzero if the current CATEGORY locale is hard, i.e. if you
|
---|
26 | can't get away with assuming traditional C or POSIX behavior. */
|
---|
27 | static int
|
---|
28 | hard_locale (int category)
|
---|
29 | {
|
---|
30 | #if ! (defined ENABLE_NLS && HAVE_SETLOCALE)
|
---|
31 | return 0;
|
---|
32 | #else
|
---|
33 |
|
---|
34 | int hard = 1;
|
---|
35 | char const *p = setlocale (category, 0);
|
---|
36 |
|
---|
37 | if (p)
|
---|
38 | {
|
---|
39 | # if defined __GLIBC__ && __GLIBC__ >= 2
|
---|
40 | if (strcmp (p, "C") == 0 || strcmp (p, "POSIX") == 0)
|
---|
41 | hard = 0;
|
---|
42 | # else
|
---|
43 | static ptr_t xmalloc PARAMS ((size_t n));
|
---|
44 |
|
---|
45 | char *locale = xmalloc (strlen (p) + 1);
|
---|
46 | strcpy (locale, p);
|
---|
47 |
|
---|
48 | /* Temporarily set the locale to the "C" and "POSIX" locales to
|
---|
49 | find their names, so that we can determine whether one or the
|
---|
50 | other is the caller's locale. */
|
---|
51 | if (((p = setlocale (category, "C")) && strcmp (p, locale) == 0)
|
---|
52 | || ((p = setlocale (category, "POSIX")) && strcmp (p, locale) == 0))
|
---|
53 | hard = 0;
|
---|
54 |
|
---|
55 | /* Restore the caller's locale. */
|
---|
56 | setlocale (category, locale);
|
---|
57 | free(locale);
|
---|
58 | # endif
|
---|
59 | }
|
---|
60 |
|
---|
61 | return hard;
|
---|
62 |
|
---|
63 | #endif
|
---|
64 | }
|
---|