commit f889a73ce27f0b716d5af38f20a799fff4ec2e6c
parent 080c51bdf15fd5a2466189742b922fcf0a7e3a5e
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date: Wed, 15 Apr 2026 09:36:08 +0200
libc/time: Remove _systime()
The unix time assumption is everywhere in the code of the time functions
so it does not make sense to hide that because any time representation
that doesn't fit with the unix semantics would fail in other places. For
platforms where the time does not follow the unix time then the time()
function should do the translation and everything would work as expected.
Diffstat:
8 files changed, 12 insertions(+), 29 deletions(-)
diff --git a/src/libc/arch/posix/Makefile b/src/libc/arch/posix/Makefile
@@ -7,7 +7,6 @@ include $(SRCDIR)/libc/rules.mk
OBJS=\
_getheap.$O\
_open.$O\
- _systime.$O\
_tzone.$O\
clock.$O\
getenv.$O\
diff --git a/src/libc/arch/posix/_systime.c b/src/libc/arch/posix/_systime.c
@@ -1,22 +0,0 @@
-#include <time.h>
-
-#include "../../libc.h"
-
-time_t
-_systime(struct tm *tm)
-{
- int i;
- time_t t = 0;
- int year = tm->tm_year + MINYEAR;
-
- for (i = EPOCH; i < year; ++i)
- t += _daysyear(i) * SECDAY;
- for (i = 0; i < tm->tm_mon; ++i)
- t += _daysmon[i] * SECDAY;
-
- t += tm->tm_sec;
- t += tm->tm_min * SECMIN;
- t += tm->tm_hour * SECHOUR;
- t += (tm->tm_mday-1) * SECDAY;
- return t;
-}
diff --git a/src/libc/libc.h b/src/libc/libc.h
@@ -41,7 +41,6 @@ extern int _tzjulian;
extern int _daysmon[12];
-time_t _systime(struct tm *);
void _tzset(void);
int _daysyear(int);
int _newyear(int);
diff --git a/src/libc/objs/amd64-freebsd.mk b/src/libc/objs/amd64-freebsd.mk
@@ -15,7 +15,6 @@ OBJS =\
arch/amd64/strcmp.$O\
arch/amd64/strcpy.$O\
arch/posix/_open.$O\
- arch/posix/_systime.$O\
arch/posix/_tzone.$O\
arch/posix/clock.$O\
arch/posix/getenv.$O\
diff --git a/src/libc/objs/amd64-linux.mk b/src/libc/objs/amd64-linux.mk
@@ -39,7 +39,6 @@ OBJS =\
arch/linux/_sigaction.$O\
arch/linux/_waitpid.$O\
arch/posix/_open.$O\
- arch/posix/_systime.$O\
arch/posix/_tzone.$O\
arch/posix/clock.$O\
arch/posix/getenv.$O\
diff --git a/src/libc/objs/amd64-netbsd.mk b/src/libc/objs/amd64-netbsd.mk
@@ -31,7 +31,6 @@ OBJS =\
arch/netbsd/_sigaction.$O\
arch/posix/_getheap.$O\
arch/posix/_open.$O\
- arch/posix/_systime.$O\
arch/posix/_tzone.$O\
arch/posix/clock.$O\
arch/posix/getenv.$O\
diff --git a/src/libc/objs/amd64-openbsd.mk b/src/libc/objs/amd64-openbsd.mk
@@ -35,7 +35,6 @@ OBJS =\
arch/bsd/_waitpid.$O\
arch/posix/_getheap.$O\
arch/posix/_open.$O\
- arch/posix/_systime.$O\
arch/posix/_tzone.$O\
arch/posix/clock.$O\
arch/posix/getenv.$O\
diff --git a/src/libc/time/mktime.c b/src/libc/time/mktime.c
@@ -101,12 +101,23 @@ time_t
mktime(struct tm *tm)
{
time_t t;
+ int i, year;
struct tm *aux;
if (!normalize(tm))
return -1;
- t = _systime(tm);
+ year = tm->tm_year + MINYEAR;
+
+ for (i = EPOCH; i < year; ++i)
+ t += _daysyear(i) * SECDAY;
+ for (i = 0; i < tm->tm_mon; ++i)
+ t += _daysmon[i] * SECDAY;
+
+ t += tm->tm_sec;
+ t += tm->tm_min * SECMIN;
+ t += tm->tm_hour * SECHOUR;
+ t += (tm->tm_mday-1) * SECDAY;
aux = localtime(&t);
if (tm->tm_isdst == -1)