changeset 5510:fd10cf72c81b

Import chamges from coreutils, so that the code now assumes that <locale.h> and its functions exist.
author Paul Eggert <eggert@cs.ucla.edu>
date Sun, 05 Dec 2004 06:50:15 +0000
parents 5fd1d2c43cd0
children 1513a260e187
files lib/ChangeLog lib/hard-locale.c lib/human.c m4/ChangeLog m4/hard-locale.m4 m4/human.m4
diffstat 6 files changed, 56 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,15 @@
+2004-12-04  Paul Eggert  <eggert@cs.ucla.edu>
+
+	Changes imported from coreutils.
+	* hard-locale.c: 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.
+	* human.c: Assume <locale.h> exists.
+	(human_readable): Assume localeconv exists.
+
 2004-12-01  Jakub Jelinek  <jakub@redhat.com>
 
 	* mktime.c (__mktime_internal): If SEC_REQUESTED != SEC,
--- 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)
+	{
+	  if (strcmp (p, "C") == 0 || strcmp (p, "POSIX") == 0)
+	    hard = false;
+	}
+      else
 	{
-	  strcpy (locale, p);
+	  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;
 
-	  /* 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
 }
--- a/lib/human.c
+++ b/lib/human.c
@@ -32,10 +32,7 @@
 # define UINTMAX_MAX ((uintmax_t) -1)
 #endif
 
-#if HAVE_LOCALE_H && HAVE_LOCALECONV
-# include <locale.h>
-#endif
-
+#include <locale.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -193,7 +190,6 @@
   size_t decimal_pointlen = 1;
   char const *grouping = "";
   char const *thousands_sep = "";
-#if HAVE_LOCALE_H && HAVE_LOCALECONV
   struct lconv const *l = localeconv ();
   size_t pointlen = strlen (l->decimal_point);
   if (0 < pointlen && pointlen <= MB_LEN_MAX)
@@ -204,7 +200,6 @@
   grouping = l->grouping;
   if (strlen (l->thousands_sep) <= MB_LEN_MAX)
     thousands_sep = l->thousands_sep;
-#endif
 
   psuffix = buf + LONGEST_HUMAN_READABLE - HUMAN_READABLE_SUFFIX_LENGTH_MAX;
   p = psuffix;
--- a/m4/ChangeLog
+++ b/m4/ChangeLog
@@ -1,3 +1,10 @@
+2004-12-04  Paul Eggert  <eggert@cs.ucla.edu>
+
+	Changes imported from coreutils.
+	* hard-locale.m4 (gl_HARD_LOCALE): Assume locale.h and setlocale
+	exist.
+	* human.m4 (gl_HUMAN): Assume locale.h and localeconv exist.
+
 2004-11-30  Paul Eggert  <eggert@cs.ucla.edu>
 
 	* getcwd-path-max.m4 (gl_FUNC_GETCWD_PATH_MAX):
--- a/m4/hard-locale.m4
+++ b/m4/hard-locale.m4
@@ -1,14 +1,10 @@
-# hard-locale.m4 serial 2
-dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+# hard-locale.m4 serial 4
+dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
 dnl This file is free software, distributed under the terms of the GNU
 dnl General Public License.  As a special exception to the GNU General
 dnl Public License, this file may be distributed as part of a program
 dnl that contains a configuration script generated by Autoconf, under
 dnl the same distribution terms as the rest of that program.
 
-AC_DEFUN([gl_HARD_LOCALE],
-[
-  dnl Prerequisites of lib/hard-locale.c.
-  AC_CHECK_HEADERS_ONCE(locale.h)
-  AC_CHECK_FUNCS_ONCE(setlocale)
-])
+dnl No prerequisites of lib/hard-locale.c.
+AC_DEFUN([gl_HARD_LOCALE], [:])
--- a/m4/human.m4
+++ b/m4/human.m4
@@ -1,4 +1,4 @@
-# human.m4 serial 5
+# human.m4 serial 6
 dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
 dnl This file is free software, distributed under the terms of the GNU
 dnl General Public License.  As a special exception to the GNU General
@@ -13,6 +13,5 @@
   AC_REQUIRE([gl_AC_TYPE_UINTMAX_T])
 
   dnl Prerequisites of lib/human.c.
-  AC_CHECK_HEADERS_ONCE(locale.h)
-  AC_CHECK_FUNCS_ONCE(localeconv)
+  :
 ])