[tz] [PROPOSED 2/2] strftime: conform better to POSIX+

Robert Elz kre at munnari.OZ.AU
Sun Aug 9 16:32:04 UTC 2020


    Date:        Sun, 9 Aug 2020 00:03:55 -0700
    From:        Paul Eggert <eggert at cs.ucla.edu>
    Message-ID:  <b07884cb-f690-54db-4127-459b9ad8c502 at cs.ucla.edu>

  | The tzdb's date.c program,

This is for handling date +fmt ? right

What we do is simply pass the "+fmt" arg to strftime, unaltered.
The '+' that we know must be there, or we wouldn't be calling
strftime() from date at all, serves as the extra dummy padding
character.  It doesn't matter what that char is, as long as it
isn't '\0' or '%', so the '+' is fine.

		if (*argv && **argv == '+')
			format = *argv; 
[...]
		while (strftime(buf, bufsiz, format, tm) == 0)
			/* make buffer bigger, etc, if we can */

The '+' then gets dropped from the result.

	        (void)printf("%s\n", buf + 1);

  | One can work around the problem by allocating memory for a larger format
  | (take the original format and prepend a space, then strip a leading space
  | from the output),

One certainly could, but as the format already has that '+' in it,
one doesn't really need that complication, it all just works.

There might be some cases where something like that is actually needed,
but those seem rare, I don't think I have encountered one.

  | I submitted a bug report to POSIX about this, here:
  | https://www.austingroupbugs.net/view.php?id=1386

Yes, I saw, I added a note to it similar to my e-mail here.

  | which proposes that errno should be preserved on successful returns
  | of 0 from strftime.

I have no problem with that part of it.   We just don't need the ERANGE
stuff added.

kre





More information about the tz mailing list