[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: `nstrftime ()' prototype
From: |
Ludovic Courtès |
Subject: |
Re: `nstrftime ()' prototype |
Date: |
Tue, 26 Aug 2008 13:57:59 +0200 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) |
Hi Bruno,
Bruno Haible <address@hidden> writes:
> Ludovic Courtès wrote:
>> In addition, it doesn't mention any portability problem, but AIX and
>> Solaris (at least) have a non-C99-compliant behavior (let alone GNU
>> extensions): https://savannah.gnu.org/bugs/index.php?24130 .
>
> Can you explain what the portability problem is, preferably with a testcase
> in C? It's not clear to me, from looking at the cited URLs, what you consider
> to be a problem, except that it's something related to "%z".
Yes, `%z' is not honored on all platforms: some don't support it at all
(in which case either "%z" or "" appears in the output), on some
platforms (e.g., AIX) it has different semantics, and on others it seems
to be broken (Solaris?). Attached is a simple test program (I don't
have access to Solaris and AIX boxes myself so I can't say what the
result's like).
Another portability issue is `%Z', which is apparently not supported on
NetBSD.
Another one is this:
/* POSIX says strftime returns 0 on buffer overrun, but old
systems (i.e. libc 4 on GNU/Linux) might return `size' in that
case. */
while ((len = strftime (tbuf, size, myfmt, &t)) == 0 || len == size)
I'm sorry I don't have much more information about the "faulty" systems.
All this is gathered from $GUILE/test-suite/tests/time.test and
$GUILE/libguile/stime.c.
Anyway, I think it motivates the need for a portable `strftime'. :-)
Thanks,
Ludo'.
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
int
main (int argc, char *argv[])
{
char buf[123];
size_t size;
time_t now;
struct tm *local_now;
now = time (NULL);
setenv ("TZ", "GMT", 1);
local_now = localtime (&now);
size = strftime (buf, sizeof (buf), "%z", local_now);
if (strcmp ("+0000", buf))
{
/* On AIX, we get "GMT".
On Solaris, we get "+0000" (?). */
printf ("FAIL: GMT: got `%s'\n", buf);
return 1;
}
setenv ("TZ", "EST+5", 1);
local_now = localtime (&now);
size = strftime (buf, sizeof (buf), "%z", local_now);
if (strcmp ("-0500", buf))
{
/* On AIX, we get "EST".
On Solaris, we get "+0000" (?). */
printf ("FAIL: EST: got `%s'\n", buf);
return 2;
}
return 0;
}
Re: `nstrftime ()' prototype, Ludovic Courtès, 2008/08/30