diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2004-12-02 06:51:46 +0000 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2004-12-02 06:51:46 +0000 |
commit | 2dea4ec8b08df6b15c4ee19bd27a544a0aa9af53 (patch) | |
tree | 4d059c724e6998954f6fba5990d10e54e9220add | |
parent | c98d52c34a9a5c984283639c6c5a451ec278f7aa (diff) | |
download | coreutils-2dea4ec8b08df6b15c4ee19bd27a544a0aa9af53.tar.xz |
Assume <locale.h> exists.
Include "strdup.h".
(GLIBC_VERSION): New macro.
(hard_locale): Assume setlocale exists.
Rewrite to avoid #ifdef.
Use strdup rather than malloc + strcpy.
-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 } |