From 9e5fe7fe46a160efa36ac90e12029ee685642087 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 5 Dec 2004 06:50:15 +0000 Subject: [PATCH] Import chamges from coreutils, so that the code now assumes that and its functions exist. --- lib/ChangeLog | 12 ++++++++++++ lib/hard-locale.c | 58 +++++++++++++++++++++++++++---------------------------- lib/human.c | 7 +------ m4/ChangeLog | 7 +++++++ m4/hard-locale.m4 | 12 ++++-------- m4/human.m4 | 5 ++--- 6 files changed, 55 insertions(+), 46 deletions(-) diff --git a/lib/ChangeLog b/lib/ChangeLog index f4d8d6ec4..05f13df9d 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,15 @@ +2004-12-04 Paul Eggert + + Changes imported from coreutils. + * hard-locale.c: Assume 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 exists. + (human_readable): Assume localeconv exists. + 2004-12-01 Jakub Jelinek * mktime.c (__mktime_internal): If SEC_REQUESTED != SEC, 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 -#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 } diff --git a/lib/human.c b/lib/human.c index 4960876dd..295e6de3c 100644 --- 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 -#endif - +#include #include #include #include @@ -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; diff --git a/m4/ChangeLog b/m4/ChangeLog index afba8c3ef..3ffb42385 100644 --- a/m4/ChangeLog +++ b/m4/ChangeLog @@ -1,3 +1,10 @@ +2004-12-04 Paul Eggert + + 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 * getcwd-path-max.m4 (gl_FUNC_GETCWD_PATH_MAX): diff --git a/m4/hard-locale.m4 b/m4/hard-locale.m4 index 3e2a08ccb..6ce7cc1e5 100644 --- 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], [:]) diff --git a/m4/human.m4 b/m4/human.m4 index d70b219a5..e800d7407 100644 --- 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_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) + : ]) -- 2.11.0