Import chamges from coreutils, so that the code now assumes
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 5 Dec 2004 06:50:15 +0000 (06:50 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 5 Dec 2004 06:50:15 +0000 (06:50 +0000)
that <locale.h> and its functions exist.

lib/ChangeLog
lib/hard-locale.c
lib/human.c
m4/ChangeLog
m4/hard-locale.m4
m4/human.m4

index f4d8d6e..05f13df 100644 (file)
@@ -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,
index 67a4144..cc2c9be 100644 (file)
 
 #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
 }
index 4960876..295e6de 100644 (file)
 # 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 @@ human_readable (uintmax_t n, char *buf, int opts,
   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 @@ human_readable (uintmax_t n, char *buf, int opts,
   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;
index afba8c3..3ffb423 100644 (file)
@@ -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):
index 3e2a08c..6ce7cc1 100644 (file)
@@ -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], [:])
index d70b219..e800d74 100644 (file)
@@ -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_DEFUN([gl_HUMAN],
   AC_REQUIRE([gl_AC_TYPE_UINTMAX_T])
 
   dnl Prerequisites of lib/human.c.
-  AC_CHECK_HEADERS_ONCE(locale.h)
-  AC_CHECK_FUNCS_ONCE(localeconv)
+  :
 ])