/* hard-locale.c -- Determine whether a locale is hard.12Copyright (C) 1997, 1998, 1999, 2002, 2003 Free Software Foundation, Inc.34This program is free software; you can redistribute it and/or modify5it under the terms of the GNU General Public License as published by6the Free Software Foundation; either version 2, or (at your option)7any later version.89This program is distributed in the hope that it will be useful,10but WITHOUT ANY WARRANTY; without even the implied warranty of11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12GNU General Public License for more details.1314You should have received a copy of the GNU General Public License15along with this program; if not, write to the Free Software Foundation,16Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */1718#if HAVE_CONFIG_H19# include <config.h>20#endif2122#include "hard-locale.h"2324#if HAVE_LOCALE_H25# include <locale.h>26#endif2728#include <stdlib.h>29#include <string.h>3031/* Return nonzero if the current CATEGORY locale is hard, i.e. if you32can't get away with assuming traditional C or POSIX behavior. */33int34hard_locale (int category)35{36#if ! HAVE_SETLOCALE37return 0;38#else3940int hard = 1;41char const *p = setlocale (category, 0);4243if (p)44{45# if defined __GLIBC__ && 2 <= __GLIBC__46if (strcmp (p, "C") == 0 || strcmp (p, "POSIX") == 0)47hard = 0;48# else49char *locale = malloc (strlen (p) + 1);50if (locale)51{52strcpy (locale, p);5354/* Temporarily set the locale to the "C" and "POSIX" locales55to find their names, so that we can determine whether one56or the other is the caller's locale. */57if (((p = setlocale (category, "C"))58&& strcmp (p, locale) == 0)59|| ((p = setlocale (category, "POSIX"))60&& strcmp (p, locale) == 0))61hard = 0;6263/* Restore the caller's locale. */64setlocale (category, locale);65free (locale);66}67# endif68}6970return hard;7172#endif73}747576