3 /* hard-locale.c -- Determine whether a locale is hard.
5 Copyright (C) 1997, 1998, 1999, 2002 Free Software Foundation, Inc.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
37 #include "hard-locale.h"
39 /* Return nonzero if the current CATEGORY locale is hard, i.e. if you
40 can't get away with assuming traditional C or POSIX behavior. */
42 hard_locale (int category
)
49 char const *p
= setlocale (category
, 0);
53 # if defined __GLIBC__ && 2 <= __GLIBC__
54 if (strcmp (p
, "C") == 0 || strcmp (p
, "POSIX") == 0)
57 char *locale
= malloc (strlen (p
) + 1);
62 /* Temporarily set the locale to the "C" and "POSIX" locales
63 to find their names, so that we can determine whether one
64 or the other is the caller's locale. */
65 if (((p
= setlocale (category
, "C"))
66 && strcmp (p
, locale
) == 0)
67 || ((p
= setlocale (category
, "POSIX"))
68 && strcmp (p
, locale
) == 0))
71 /* Restore the caller's locale. */
72 setlocale (category
, locale
);