From 2dea4ec8b08df6b15c4ee19bd27a544a0aa9af53 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 2 Dec 2004 06:51:46 +0000 Subject: Assume exists. Include "strdup.h". (GLIBC_VERSION): New macro. (hard_locale): Assume setlocale exists. Rewrite to avoid #ifdef. Use strdup rather than malloc + strcpy. --- lib/hard-locale.c | 58 +++++++++++++++++++++++++++---------------------------- 1 file 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 -#endif - +#include #include #include +#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 } -- cgit v1.2.3-70-g09d2