diff options
-rw-r--r-- | lib/hard-locale.c | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/lib/hard-locale.c b/lib/hard-locale.c index 67a4144a6..cc2c9becf 100644 --- a/lib/hard-locale.c +++ b/lib/hard-locale.c @@ -23,53 +23,53 @@ #include "hard-locale.h" -#if HAVE_LOCALE_H -# include <locale.h> -#endif - +#include <locale.h> #include <stdlib.h> #include <string.h> +#include "strdup.h" + +#ifdef __GLIBC__ +# define GLIBC_VERSION __GLIBC__ +#else +# define GLIBC_VERSION 0 +#endif + /* Return true if the current CATEGORY locale is hard, i.e. if you can't get away with assuming traditional C or POSIX behavior. */ bool hard_locale (int category) { -#if ! HAVE_SETLOCALE - return false; -#else - bool hard = true; char const *p = setlocale (category, NULL); if (p) { -# if defined __GLIBC__ && 2 <= __GLIBC__ - if (strcmp (p, "C") == 0 || strcmp (p, "POSIX") == 0) - hard = false; -# else - char *locale = malloc (strlen (p) + 1); - if (locale) + if (2 <= GLIBC_VERSION) { - strcpy (locale, p); - - /* Temporarily set the locale to the "C" and "POSIX" locales - to find their names, so that we can determine whether one - or the other is the caller's locale. */ - if (((p = setlocale (category, "C")) - && strcmp (p, locale) == 0) - || ((p = setlocale (category, "POSIX")) - && strcmp (p, locale) == 0)) + if (strcmp (p, "C") == 0 || strcmp (p, "POSIX") == 0) hard = false; + } + else + { + char *locale = strdup (p); + if (locale) + { + /* Temporarily set the locale to the "C" and "POSIX" locales + to find their names, so that we can determine whether one + or the other is the caller's locale. */ + if (((p = setlocale (category, "C")) + && strcmp (p, locale) == 0) + || ((p = setlocale (category, "POSIX")) + && strcmp (p, locale) == 0)) + hard = false; - /* Restore the caller's locale. */ - setlocale (category, locale); - free (locale); + /* Restore the caller's locale. */ + setlocale (category, locale); + free (locale); + } } -# endif } return hard; - -#endif } |