commit 0b4fa1949cf1763cf901c63caf7062df66bc5a07
parent 365bccde0e11442a9006138605c1f61c9e3fd624
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Thu, 25 Apr 2019 09:50:32 +0100
[libc] Initiliaze tz before use in localtime()
Tz was used before being initialized. The more generic solution is to
call _tzone with the timep received, and let to the implementation of
_tzone to decide how to use that parameter or to ignore it.
Diffstat:
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/libc/time/asctime.c b/src/libc/time/asctime.c
@@ -1,7 +1,6 @@
#include <time.h>
#undef asctime
-#include <stdio.h> // TODO: remove me!
char *
asctime(const struct tm *tm)
{
diff --git a/src/libc/time/localtime.c b/src/libc/time/localtime.c
@@ -10,10 +10,10 @@ localtime(const time_t *timep)
struct tm *tm;
time_t t = *timep;
+ tz = _tzone(gmtime(timep));
t += tz->gmtoff * 60;
t += tz->isdst * 60;
tm = gmtime(&t);
- tz = _tzone(tm);
tm->tm_zone = tz->name;
tm->tm_isdst = tz->isdst;
tm->tm_gmtoff = tz->gmtoff;