X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fhard-locale.c;h=b0566ec2186ab5b17a7f831b811e5cf8deb6d001;hb=5131be5b019b1110cd597012b63e48886aaaafc7;hp=67a4144a6fec74d12a3addac772c0eb20c2c70e7;hpb=a62be9f4039b4499cfbb76e394cad2259d03fa84;p=gnulib.git diff --git a/lib/hard-locale.c b/lib/hard-locale.c index 67a4144a6..b0566ec21 100644 --- a/lib/hard-locale.c +++ b/lib/hard-locale.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #if HAVE_CONFIG_H # include @@ -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 }