|
Packit Service |
a2489d |
/* hard-locale.c -- Determine whether a locale is hard.
|
|
Packit Service |
a2489d |
|
|
Packit Service |
a2489d |
Copyright (C) 1997-1999, 2002-2004, 2006-2007, 2009-2018 Free Software
|
|
Packit Service |
a2489d |
Foundation, Inc.
|
|
Packit Service |
a2489d |
|
|
Packit Service |
a2489d |
This program is free software: you can redistribute it and/or modify
|
|
Packit Service |
a2489d |
it under the terms of the GNU General Public License as published by
|
|
Packit Service |
a2489d |
the Free Software Foundation; either version 3 of the License, or
|
|
Packit Service |
a2489d |
(at your option) any later version.
|
|
Packit Service |
a2489d |
|
|
Packit Service |
a2489d |
This program is distributed in the hope that it will be useful,
|
|
Packit Service |
a2489d |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
a2489d |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
a2489d |
GNU General Public License for more details.
|
|
Packit Service |
a2489d |
|
|
Packit Service |
a2489d |
You should have received a copy of the GNU General Public License
|
|
Packit Service |
a2489d |
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
|
Packit Service |
a2489d |
|
|
Packit Service |
a2489d |
#include <config.h>
|
|
Packit Service |
a2489d |
|
|
Packit Service |
a2489d |
#include "hard-locale.h"
|
|
Packit Service |
a2489d |
|
|
Packit Service |
a2489d |
#include <locale.h>
|
|
Packit Service |
a2489d |
#include <stdlib.h>
|
|
Packit Service |
a2489d |
#include <string.h>
|
|
Packit Service |
a2489d |
|
|
Packit Service |
a2489d |
#ifdef __GLIBC__
|
|
Packit Service |
a2489d |
# define GLIBC_VERSION __GLIBC__
|
|
Packit Service |
a2489d |
#elif defined __UCLIBC__
|
|
Packit Service |
a2489d |
# define GLIBC_VERSION 2
|
|
Packit Service |
a2489d |
#else
|
|
Packit Service |
a2489d |
# define GLIBC_VERSION 0
|
|
Packit Service |
a2489d |
#endif
|
|
Packit Service |
a2489d |
|
|
Packit Service |
a2489d |
/* Return true if the current CATEGORY locale is hard, i.e. if you
|
|
Packit Service |
a2489d |
can't get away with assuming traditional C or POSIX behavior. */
|
|
Packit Service |
a2489d |
bool
|
|
Packit Service |
a2489d |
hard_locale (int category)
|
|
Packit Service |
a2489d |
{
|
|
Packit Service |
a2489d |
bool hard = true;
|
|
Packit Service |
a2489d |
char const *p = setlocale (category, NULL);
|
|
Packit Service |
a2489d |
|
|
Packit Service |
a2489d |
if (p)
|
|
Packit Service |
a2489d |
{
|
|
Packit Service |
a2489d |
if (2 <= GLIBC_VERSION)
|
|
Packit Service |
a2489d |
{
|
|
Packit Service |
a2489d |
if (strcmp (p, "C") == 0 || strcmp (p, "POSIX") == 0)
|
|
Packit Service |
a2489d |
hard = false;
|
|
Packit Service |
a2489d |
}
|
|
Packit Service |
a2489d |
else
|
|
Packit Service |
a2489d |
{
|
|
Packit Service |
a2489d |
char *locale = strdup (p);
|
|
Packit Service |
a2489d |
if (locale)
|
|
Packit Service |
a2489d |
{
|
|
Packit Service |
a2489d |
/* Temporarily set the locale to the "C" and "POSIX" locales
|
|
Packit Service |
a2489d |
to find their names, so that we can determine whether one
|
|
Packit Service |
a2489d |
or the other is the caller's locale. */
|
|
Packit Service |
a2489d |
if (((p = setlocale (category, "C"))
|
|
Packit Service |
a2489d |
&& strcmp (p, locale) == 0)
|
|
Packit Service |
a2489d |
|| ((p = setlocale (category, "POSIX"))
|
|
Packit Service |
a2489d |
&& strcmp (p, locale) == 0))
|
|
Packit Service |
a2489d |
hard = false;
|
|
Packit Service |
a2489d |
|
|
Packit Service |
a2489d |
/* Restore the caller's locale. */
|
|
Packit Service |
a2489d |
setlocale (category, locale);
|
|
Packit Service |
a2489d |
free (locale);
|
|
Packit Service |
a2489d |
}
|
|
Packit Service |
a2489d |
}
|
|
Packit Service |
a2489d |
}
|
|
Packit Service |
a2489d |
|
|
Packit Service |
a2489d |
return hard;
|
|
Packit Service |
a2489d |
}
|