bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sleep with LANG="address@hidden"


From: Jim Meyering
Subject: Re: sleep with LANG="address@hidden"
Date: Thu, 27 Nov 2003 09:39:24 +0100

Paul Eggert <address@hidden> wrote:
> Jim Meyering <address@hidden> writes:
>> Sleep should accept numbers in the locale specified by the user.
>
> I'm dubious about this.  I searched POSIX for examples of standard
> programs accepting command-line options or operands containing
> floating-point values, and both examples that I found (namely, awk and
> printf) require that the values must be parsed in the C locale, not in
> the user-specified locale.

Knowing that about printf puts it all in a different light.
Thanks for doing that research.

> Clearly coreutils printf is nonconforming now, since it doesn't do
> that.  I vote that other utilities be consistent with POSIX.  Here's a
> proposed patch.
>
> 2003-11-24  Paul Eggert  <address@hidden>
>
>       Parse floating-point operands and options in the C locale.
>       POSIX requires this for printf, and we might as well be
>       consistent elsewhere.
>
>       * doc/coreutils.texi (tail invocation, printf invocation,
>       sleep invocation, seq invocation): Document this.
>       * lib/Makefile.am (libfetish_a_SOURCES): Add c-strtod.c, c-strtod.h.
>       * lib/c-strtod.c, lib/c-strtod.h: New files.
>       * lib/xstrtod.h (xstrtod): Accept an extra arg, specifying the
>       conversion function.
>       * lib/xstrtod.c (xstrtod): Likewise.  All callers changed to
>       include c-strtod.h and use c_strtod.  Don't include stdlib.h; no
>       longer needed.
>       * src/printf.c: Remove decls of strtod, strtol, strtoul; no longer
>       needed now that we assume C89.  Include "c-strtod.h".
>       (xstrtod): Call c_strtod, not strtod.
>
>       * lib/xnanosleep.c: Don't include xstrtod.h; it's not needed.

I've applied this patch.
Wouldn't it be better (in case xstrtod is called with a
modified LC_NUMERIC locale) if c_strtod restored the original
setting for LC_NUMERIC, rather than the environment-derived one?
I know it doesn't matter for the coreutils, but it might for some
other application that uses xstrtod+c_strtod.

Here's an additional patch:

Index: lib/c-strtod.c
===================================================================
RCS file: /fetish/cu/lib/c-strtod.c,v
retrieving revision 1.1
diff -u -p -u -p -r1.1 c-strtod.c
--- lib/c-strtod.c      27 Nov 2003 07:46:01 -0000      1.1
+++ lib/c-strtod.c      27 Nov 2003 08:31:30 -0000
@@ -27,8 +27,9 @@ double
 c_strtod (char const *nptr, char **endptr)
 {
   double r;
+  char const *saved_locale = setlocale (LC_NUMERIC, NULL);
   setlocale (LC_NUMERIC, "C");
   r = strtod (nptr, endptr);
-  setlocale (LC_NUMERIC, "");
+  setlocale (LC_NUMERIC, saved_locale);
   return r;
 }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]