On Mon, Aug 18, 2014 at 10:21:50PM +0100, Stuart Henderson wrote:
| On 2014/08/18 16:08, Daurnimator wrote:
| > On 18 August 2014 16:01, Stuart Henderson <[email protected]> wrote:
| > >
| > > That said, given that you have just found 3 implementations which have
| > > the same (frankly IMHO sensible) behaviour, musl seems to be the odd one
| > > out.
| > >
| > 
| > It is correctly documented as always returning UTC (see
| > 
http://anoncvs.estpak.ee/cgi-bin/cgit/openbsd-src/tree/lib/libc/time/strftime.3#n145
| > )
| > No-where in libc do you deal with a timezone-adjusted epoch.
| > 
| > I'd say the documentation is correct; and the code is not.
| > 
| 
| So you have a fairly old API which works the same way in libc used in
| BSDs, common Linux distributions, solaris derivatives (I checked smartos)
| and probably others (haven't walked downstairs to check the mac), and
| it is already used by various existing software. This isn't something
| you can really change just because it doesn't work how you expect...

Something does seem to be off:

[weerd@despair] $ cat strptime.c 
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int
main(int argc, char *argv[]) {
        char *buf;
        struct tm time;
        size_t size;

        strptime(argv[1], "%a %b %d %T %Y %z", &time);
        buf = malloc(1024);
        size = strftime(buf, 1023, "%s", &time);
        printf("%s\n", buf);

        return 0;
}
[weerd@despair] $ make strptime   
cc -O2 -pipe    -o strptime strptime.c 
[weerd@despair] $ ./strptime "`date \"+%a %b %d %T %Y %z\"`"; date +%s
1411743728
1411740128

Why is this affected by my TZ?

Behaviour on MacOSX (10.9.5):
$ ./strptime "`date \"+%a %b %d %T %Y %z\"`"; date +%s
1411740382
1411740382

Behaviour on Linux (CentOS 6.5):
$ ./strptime "`date \"+%a %b %d %T %Y %z\"`"; date +%s
1411740349
1411740349

Behaviour on FreeBSD (9.1):
$ ./strptime "`date \"+%a %b %d %T %Y %z\"`"; date +%s
1411740498
1411740498

(In all cases, TZ is CEST)

It very much looks like OpenBSD is the odd one out here.  Can someone
confirm and/or explain?

Cheers,

Paul 'WEiRD' de Weerd

-- 
>++++++++[<++++++++++>-]<+++++++.>+++[<------>-]<.>+++[<+
+++++++++++>-]<.>++[<------------>-]<+.--------------.[-]
                 http://www.weirdnet.nl/                 

Reply via email to