From 0d58e759107ed8cea0a0b8b761c66df372ca73b8 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Mon, 18 Jan 2021 18:09:30 +0100 Subject: [PATCH] LibC: Make tzset() set tzname to { "UTC", "UTC" } Since tzset() itself pretends to succeed (it just sets timezone = 0 for now), it seems unwise to leave tzname uninitialized. Since Serenity already assumes UTC pretty much everywhere time is used, let's continue that trend here. Quoting POSIX: https://pubs.opengroup.org/onlinepubs/009695399/functions/tzset.html The tzset() function shall use the value of the environment variable TZ to set time conversion information used by ctime(), localtime(), mktime(), and strftime(). If TZ is absent from the environment, implementation-defined default timezone information shall be used. So we still don't care about TZ at all, but the program doesn't need to know! :^) This matches what musl libc ("UTC") and glibc ("GMT") do, see: - https://sourceware.org/git/?p=glibc.git;a=blob;f=time/tzset.c - https://git.musl-libc.org/cgit/musl/tree/src/time/__tz.c --- Userland/Libraries/LibC/time.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibC/time.cpp b/Userland/Libraries/LibC/time.cpp index d9f4778d05..72b80e1d55 100644 --- a/Userland/Libraries/LibC/time.cpp +++ b/Userland/Libraries/LibC/time.cpp @@ -322,15 +322,19 @@ size_t strftime(char* destination, size_t max_size, const char* format, const st return fits ? str.length() : 0; } -long timezone = 0; +long timezone; long altzone; char* tzname[2]; int daylight; +constexpr const char* __utc = "UTC"; + void tzset() { - //FIXME: Here we prepend we are in UTC+0. + // FIXME: Here we pretend we are in UTC+0. timezone = 0; + tzname[0] = const_cast(__utc); + tzname[1] = const_cast(__utc); } clock_t clock()