[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gnulib] Re: nit in strftime.c
From: |
Paul Eggert |
Subject: |
Re: [bug-gnulib] Re: nit in strftime.c |
Date: |
Tue, 15 Mar 2005 17:08:41 -0800 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux) |
Eric Blake <address@hidden> writes:
> Why not prime the buffer?
Thanks. (I thought of exactly the same thing while driving home last night.)
I installed this patch in both gnulib and coreutils. Similar fixes
would be useful in coreutils date.c and pr.c; I'll look at those separately.
Come to think of it, perhas the "return 0" below should be an abort()?
2005-03-15 Paul Eggert <address@hidden>
* strftime.c (my_strftime): Prepend space to format so that we can
reliably distinguish strftime failure from empty output on POSIX
hosts.
--- strftime.c 14 Mar 2005 23:23:25 -0000 1.81
+++ strftime.c 16 Mar 2005 01:01:23 -0000 1.82
@@ -386,7 +386,7 @@ static CHAR_T const month_name[][10] =
(including the terminating '\0') and returning number of
characters written. If S is NULL, nothing will be written
anywhere, so to determine how many characters would be
- written, use NULL for S and (size_t) UINT_MAX for MAXSIZE. */
+ written, use NULL for S and (size_t) -1 for MAXSIZE. */
size_t
my_strftime (CHAR_T *s, size_t maxsize, const CHAR_T *format,
const struct tm *tp extra_args_spec LOCALE_PARAM_PROTO)
@@ -759,7 +759,7 @@ my_strftime (CHAR_T *s, size_t maxsize,
{
/* The relevant information is available only via the
underlying strftime implementation, so use that. */
- char ufmt[4];
+ char ufmt[5];
char *u = ufmt;
char ubuf[1024]; /* enough for any single format in practice */
size_t len;
@@ -771,16 +771,18 @@ my_strftime (CHAR_T *s, size_t maxsize,
size_t strftime ();
# endif
+ /* The space helps distinguish strftime failure from empty
+ output. */
+ *u++ = ' ';
*u++ = '%';
if (modifier != 0)
*u++ = modifier;
*u++ = format_char;
*u = '\0';
- ubuf[0] = '\1';
len = strftime (ubuf, sizeof ubuf, ufmt, tp);
- if (len == 0 && ubuf[0] != '\0')
+ if (len == 0)
return 0;
- cpy (len, ubuf);
+ cpy (len - 1, ubuf + 1);
}
break;
#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [bug-gnulib] Re: nit in strftime.c,
Paul Eggert <=