[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-gnulib] human, hard-locale changes to assume <locale.h>
From: |
Paul Eggert |
Subject: |
[bug-gnulib] human, hard-locale changes to assume <locale.h> |
Date: |
Sat, 04 Dec 2004 22:52:35 -0800 |
coreutils had been assuming <locale.h> for some time (since coreutils
5.0, anyway, and probably earlier) without anybody noticing or caring,
so I took the liberty of simplifying human and hard-locale to assume
<locale.h>. If this turns into a real problem on older or
freestanding hosts we can supply a substitute <locale.h> that does
nothing. I installed this patch:
+2004-12-04 Paul Eggert <address@hidden>
Changes imported from coreutils.
* lib/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.
* lib/human.c: Assume <locale.h> exists.
(human_readable): Assume localeconv exists.
* m4/hard-locale.m4 (gl_HARD_LOCALE): Assume locale.h and setlocale
exist.
* m4/human.m4 (gl_HUMAN): Assume locale.h and localeconv exist.
* modules/hard-locale (Depends-on): Add strdup.
Index: lib/hard-locale.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/hard-locale.c,v
retrieving revision 1.9
diff -p -u -r1.9 hard-locale.c
--- lib/hard-locale.c 7 Aug 2004 00:09:39 -0000 1.9
+++ lib/hard-locale.c 5 Dec 2004 06:48:46 -0000
@@ -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)
{
- 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;
-
- /* Restore the caller's locale. */
- setlocale (category, locale);
- free (locale);
}
-# endif
+ 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);
+ }
+ }
}
return hard;
-
-#endif
}
Index: lib/human.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/human.c,v
retrieving revision 1.26
diff -p -u -r1.26 human.c
--- lib/human.c 17 Nov 2004 07:18:27 -0000 1.26
+++ lib/human.c 5 Dec 2004 06:48:46 -0000
@@ -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 @@ human_readable (uintmax_t n, char *buf,
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,
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: m4/hard-locale.m4
===================================================================
RCS file: /cvsroot/gnulib/gnulib/m4/hard-locale.m4,v
retrieving revision 1.2
diff -p -u -r1.2 hard-locale.m4
--- m4/hard-locale.m4 9 Sep 2003 19:37:26 -0000 1.2
+++ m4/hard-locale.m4 5 Dec 2004 06:48:47 -0000
@@ -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: m4/human.m4
===================================================================
RCS file: /cvsroot/gnulib/gnulib/m4/human.m4,v
retrieving revision 1.6
diff -p -u -r1.6 human.m4
--- m4/human.m4 1 Jun 2004 20:27:22 -0000 1.6
+++ m4/human.m4 5 Dec 2004 06:48:47 -0000
@@ -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)
+ :
])
Index: modules/hard-locale
===================================================================
RCS file: /cvsroot/gnulib/gnulib/modules/hard-locale,v
retrieving revision 1.4
diff -p -u -r1.4 hard-locale
--- modules/hard-locale 22 Sep 2004 15:11:04 -0000 1.4
+++ modules/hard-locale 5 Dec 2004 06:48:47 -0000
@@ -7,6 +7,7 @@ lib/hard-locale.c
m4/hard-locale.m4
Depends-on:
+strdup
configure.ac:
gl_HARD_LOCALE
@@ -22,4 +23,3 @@ GPL
Maintainer:
Paul Eggert
-
- [bug-gnulib] human, hard-locale changes to assume <locale.h>,
Paul Eggert <=