Commit 9e5fe7fe authored by Paul Eggert's avatar Paul Eggert

Import chamges from coreutils, so that the code now assumes

that <locale.h> and its functions exist.
parent bec31f6c
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,
......
......@@ -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;
}
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
}
......@@ -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, 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;
......
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):
......
# 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], [:])
# 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)
:
])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment