![]() |
|
Message-ID: <x7jw3s7fwpkxxzdn3ns6zmp2ed7n2euzrp54hiucravpux3ng4@atesk76cmq2n>
Date: Sun, 6 Apr 2025 22:05:15 +0200
From: Alejandro Colomar <alx@...nel.org>
To: Rich Felker <dalias@...c.org>, libc-alpha@...rceware.org
Cc: ipedrosa@...hat.com, musl@...ts.openwall.com,
~hallyn/shadow@...ts.sr.ht
Subject: Re: strptime("UTC", "%Z", &tm) in musl
[Add libc-alpha@]
On Sun, Apr 06, 2025 at 09:57:39PM +0200, Alejandro Colomar wrote:
> Hi Rich,
>
> 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;
>
> p = strptime(s, "%F", &tm);
> if (p == NULL || !streq(p, ""))
> return -1;
>
> return dategm(&tm);
> }
>
> Which works fine in glibc, but fails in musl.
Actually, I've now read the glibc sources, and it seems even worse in
glibc. glibc ignores the parsed timezone at all.
So, both glibc and musl have a bug here, I think.
Is there any way to parse a UTC date? That is, parse a "YYYY-MM-DD"
date that is not in local time, but in UTC time.
Have a lovely night!
Alex
>
> $ grepc -tfd strptime . | sed -n '/case .Z.:/,/break/p'
> case 'Z':
> if (!strncmp(s, tzname[0], len = strlen(tzname[0]))) {
> tm->tm_isdst = 0;
> s += len;
> } else if (!strncmp(s, tzname[1], len=strlen(tzname[1]))) {
> tm->tm_isdst = 1;
> s += len;
> } else {
> /* FIXME: is this supposed to be an error? */
> while ((*s|32)-'a' <= 'z'-'a') s++;
> }
> break;
>
> It seems "%Z" only accepts the timezone specified in the current locale
> (via tzname), but doesn't accept parsing a different timezone (in this
> case, I want specifically UTC, regardless of the locale). I'd say this
> is a bug, and an important limitation, BTW.
>
> Is there any way I can workaround this for musl?
>
>
> Have a lovely day!
> Alex
>
> --
> <https://www.alejandro-colomar.es/>
> <https://www.alejandro-colomar.es:8443/>
> <http://www.alejandro-colomar.es:8080/>
--
<https://www.alejandro-colomar.es/>
<https://www.alejandro-colomar.es:8443/>
<http://www.alejandro-colomar.es:8080/>
Download attachment "signature.asc" of type "application/pgp-signature" (834 bytes)
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.