[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Patches against sh-utils 2.0.11
From: |
Jim Meyering |
Subject: |
Re: Patches against sh-utils 2.0.11 |
Date: |
Sat, 18 Aug 2001 13:20:46 +0200 |
User-agent: |
Gnus/5.090004 (Oort Gnus v0.04) Emacs/21.0.105 |
Ulrich Drepper <address@hidden> wrote:
> Jim Meyering <address@hidden> writes:
>> >
>> > ii) Change LC_TIME instead of LC_ALL. LC_ALL is overkill, and would
>> > have unwanted side effects if there is an error message.
>>
>> Thanks! I've applied that patch.
>
> No, this is completely wrong. The LC_TIME catagory contains data
> which is encoded in the charset of the locale. The charset
> information comes from the LC_CTYPE category. The very least is to
> set LC_CTYPE as well but this is also normally a bad idea. It is best
> to always set LC_ALL.
Hi Ulrich,
Thanks for pointing that out.
For my edification, why is it a bad idea to set both LC_TIME and LC_CTYPE?
Peter's point is still valid. I don't want the setting of LC_ALL=C
for strftime to force all diagnostics into that locale.
What do you think of this alternative?
Index: date.c
===================================================================
RCS file: /fetish/shellutils/src/date.c,v
retrieving revision 1.103
diff -u -p -u -p -u -4 -r1.103 date.c
--- date.c 2001/08/18 10:54:56 1.103
+++ date.c 2001/08/18 11:17:49
@@ -487,23 +487,31 @@ show_date (const char *format, time_t wh
printf ("\n");
return;
}
- if (rfc_format)
- setlocale (LC_TIME, "C");
-
- do
+ while (1)
{
+ int done;
out_length += 200;
out = (char *) xrealloc (out, out_length);
/* Mark the first byte of the buffer so we can detect the case
of strftime producing an empty string. Otherwise, this loop
would not terminate when date was invoked like this
`LANG=de date +%p' on a system with good language support. */
out[0] = '\1';
+
+ if (rfc_format)
+ setlocale (LC_ALL, "C");
+
+ done = (strftime (out, out_length, format, tm) || out[0] == '\0');
+
+ if (rfc_format)
+ setlocale (LC_ALL, "");
+
+ if (done)
+ break;
}
- while (strftime (out, out_length, format, tm) == 0 && out[0] != '\0');
printf ("%s\n", out);
free (out);
}