]> git.ipfire.org Git - thirdparty/shadow.git/commit
lib/getdate.c: Use strptime(3) to simplify
authorAlejandro Colomar <alx@kernel.org>
Tue, 18 Feb 2025 22:25:29 +0000 (23:25 +0100)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Mon, 2 Jun 2025 07:59:51 +0000 (09:59 +0200)
commitb8abe4e9d721b63538ad145c13aa4c13a7b30304
treeda66af38aa9d8eee8ad3675e48a6f8d2e752ebb0
parent4be6e92f5bb54b4a724f058c62b593e2bda1d2de
lib/getdate.c: Use strptime(3) to simplify

The following trick:

t = 0;
gmtime_r(&t, &tm);

is a clever way to clear the tm(3type) structure, and set it to use UTC.

We need to set it to set UTC with this trick, because strptime(3)
doesn't set the timezone.  I (Alex) tried previously using

bzero(&tm, sizeof(tm));
strptime("UTC", "%Z", &tm);

but glibc ignores the timezone, and musl (at least I tried in an Alpine
container) seems to report an error.

The idea to use gmtime_r(3) was from lanodan.

Link: <https://inbox.sourceware.org/libc-alpha/Z_LqUgildoq33vI-@cloudsdale.the-delta.net.eu.org/T/#u>
Cc: Iker Pedrosa <ipedrosa@redhat.com>
Cc: Serge Hallyn <serge@hallyn.com>
Cc: Rich Felker <dalias@libc.org>
Co-authored-by: "Haelwenn (lanodan) Monnier" <contact@hacktivis.me>
Signed-off-by: "Haelwenn (lanodan) Monnier" <contact@hacktivis.me>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/getdate.c