|
|
Message-ID: <Z_LqUgildoq33vI-@cloudsdale.the-delta.net.eu.org>
Date: Sun, 6 Apr 2025 22:55:46 +0200
From: "Haelwenn (lanodan) Monnier" <contact@...ktivis.me>
To: musl@...ts.openwall.com
Cc: Rich Felker <dalias@...c.org>, ipedrosa@...hat.com,
~hallyn/shadow@...ts.sr.ht, libc-alpha@...rceware.org
Subject: Re: strptime("UTC", "%Z", &tm) in musl
[2025-04-06 21:57:35+0200] Alejandro Colomar:
>I was trying to develop a function that parses a UTC date in the shadow
>project, and I came up with this:
><https://github.com/shadow-maint/shadow/pull/1217/>
>
> $ grepc -htfd get_date .
> static long
> get_date(const char *s)
> {
> struct tm tm;
> const char *p;
>
> bzero(&tm, sizeof(tm));
>
> p = strptime("UTC", "%Z", &tm);
> if (p == NULL || !streq(p, ""))
> return -1;
That bzero seems like a bit of a bad idea, `struct tm` can have some extra
fields where 0 isn't the correct value.
Quite like how `tm_isdst` uses -1 for unknown state, 0 for no-DST, 1 for DST.
Could probably use `if(!gmtime_r(0, &tm)) { /* handle err */ }` instead
which also has the nice effect of initializing tm for UTC,
allowing to skip the problematic strptime %Z.
Best regards
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.