summaryrefslogtreecommitdiff
path: root/lib/hard-locale.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2002-04-30 09:17:50 +0000
committerJim Meyering <jim@meyering.net>2002-04-30 09:17:50 +0000
commit9c46845348cf19366e62eaad668d1a86fc77fe1c (patch)
treef508da329669f859d401c0434c7bd0cdd6d140a6 /lib/hard-locale.c
parent2cc5a65c0fb2a49dd83529302b4e5d73d947ac0d (diff)
downloadcoreutils-9c46845348cf19366e62eaad668d1a86fc77fe1c.tar.xz
Upgrade to version used in GNU Diffutils 2.8.1.
Diffstat (limited to 'lib/hard-locale.c')
-rw-r--r--lib/hard-locale.c62
1 files changed, 27 insertions, 35 deletions
diff --git a/lib/hard-locale.c b/lib/hard-locale.c
index 01e0ebdd7..0070542e0 100644
--- a/lib/hard-locale.c
+++ b/lib/hard-locale.c
@@ -1,5 +1,6 @@
/* hard-locale.c -- Determine whether a locale is hard.
- Copyright 1997, 1998, 1999 Free Software Foundation, Inc.
+
+ Copyright (C) 1997, 1998, 1999, 2002 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -19,41 +20,26 @@
# include <config.h>
#endif
-#if __GNUC__
-# define alloca __builtin_alloca
-#else
-# ifdef HAVE_ALLOCA_H
-# include <alloca.h>
-# else
-# ifdef _AIX
- # pragma alloca
-# else
-# ifdef _WIN32
-# include <malloc.h>
-# include <io.h>
-# else
-# ifndef alloca
-char *alloca ();
-# endif
-# endif
-# endif
-# endif
-#endif
-
#if HAVE_LOCALE_H
# include <locale.h>
#endif
+#if HAVE_STDLIB_H
+# include <stdlib.h>
+#endif
+
#if HAVE_STRING_H
# include <string.h>
#endif
+#include "hard-locale.h"
+
/* Return nonzero if the current CATEGORY locale is hard, i.e. if you
can't get away with assuming traditional C or POSIX behavior. */
int
hard_locale (int category)
{
-#if ! (defined ENABLE_NLS && HAVE_SETLOCALE)
+#if ! HAVE_SETLOCALE
return 0;
#else
@@ -62,22 +48,28 @@ hard_locale (int category)
if (p)
{
-# if defined __GLIBC__ && __GLIBC__ >= 2
+# if defined __GLIBC__ && 2 <= __GLIBC__
if (strcmp (p, "C") == 0 || strcmp (p, "POSIX") == 0)
hard = 0;
# else
- char *locale = alloca (strlen (p) + 1);
- 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))
- hard = 0;
+ char *locale = malloc (strlen (p) + 1);
+ if (locale)
+ {
+ 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))
+ hard = 0;
- /* Restore the caller's locale. */
- setlocale (category, locale);
+ /* Restore the caller's locale. */
+ setlocale (category, locale);
+ free (locale);
+ }
# endif
}