summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2005-03-16 01:01:23 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2005-03-16 01:01:23 +0000
commit23f7577282edd2f5b73f523bc859ee4c53d65d8c (patch)
tree849b5e697456a74aafc74dd00b031757f39298cf /lib
parent331efbd2db03754c817c85d64b08cbb422f6b62d (diff)
downloadcoreutils-23f7577282edd2f5b73f523bc859ee4c53d65d8c.tar.xz
(my_strftime): Prepend space to format so that we can
reliably distinguish strftime failure from empty output on POSIX hosts.
Diffstat (limited to 'lib')
-rw-r--r--lib/strftime.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/strftime.c b/lib/strftime.c
index 78a963b42..3be18a2b6 100644
--- a/lib/strftime.c
+++ b/lib/strftime.c
@@ -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, const CHAR_T *format,
{
/* 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, const CHAR_T *format,
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