1
/* hard-locale.h -- Same as hard-locale.c.
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.
7
/* hard-locale.c -- Determine whether a locale is hard.
8
Copyright 1997, 1998, 1999 Free Software Foundation, Inc.
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)
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.
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. */
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. */
28
hard_locale (int category)
30
#if ! (defined ENABLE_NLS && HAVE_SETLOCALE)
35
char const *p = setlocale (category, 0);
39
# if defined __GLIBC__ && __GLIBC__ >= 2
40
if (strcmp (p, "C") == 0 || strcmp (p, "POSIX") == 0)
43
static ptr_t xmalloc PARAMS ((size_t n));
45
char *locale = xmalloc (strlen (p) + 1);
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))
55
/* Restore the caller's locale. */
56
setlocale (category, locale);