summaryrefslogtreecommitdiff
path: root/lib/libc/time/tzset.c
diff options
context:
space:
mode:
authorKacper <kacper@mail.openlinux.dev>2025-12-07 20:10:31 +0100
committerKacper <kacper@mail.openlinux.dev>2025-12-07 20:10:31 +0100
commitfc00c656c96528112d05cf0edf8631bd5eaea446 (patch)
treea6e0e6c588191a8bd1c64afc3b7a258e3e66c236 /lib/libc/time/tzset.c
Add build system scaffolding and libc headers
Diffstat (limited to 'lib/libc/time/tzset.c')
-rw-r--r--lib/libc/time/tzset.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/libc/time/tzset.c b/lib/libc/time/tzset.c
new file mode 100644
index 00000000..96f33702
--- /dev/null
+++ b/lib/libc/time/tzset.c
@@ -0,0 +1,58 @@
+#include <time.h>
+#include <ctype.h>
+
+int daylight = 0;
+long timezone = 0;
+char *tzname[2] = { "UTC", "UTC" };
+
+void tzset(void)
+{
+ const char *tz = NULL; // getenv("TZ");
+
+ if (tz == NULL || *tz == '\0') {
+ timezone = 0;
+ daylight = 0;
+ tzname[0] = tzname[1] = "UTC";
+ return;
+ }
+
+ const char *p = tz;
+ char sign = 0;
+ int hours = 0, mins = 0;
+
+ static char stdname[8];
+ int i = 0;
+ while (*p && !isdigit((unsigned char)*p) && *p != '+' && *p != '-' &&
+ i < 7) {
+ stdname[i++] = *p++;
+ }
+
+ stdname[i] = '\0';
+ if (stdname[0])
+ tzname[0] = stdname;
+ else
+ tzname[0] = "LCL";
+
+ if (*p == '+' || *p == '-')
+ sign = *p++;
+
+ while (isdigit((unsigned char)*p))
+ hours = hours * 10 + (*p++ - '0');
+
+ if (*p == ':') {
+ p++;
+ while (isdigit((unsigned char)*p))
+ mins = mins * 10 + (*p++ - '0');
+ }
+
+ int total = hours * 3600 + mins * 60;
+ if (sign == '+')
+ timezone = -total;
+ else if (sign == '-')
+ timezone = total;
+ else
+ timezone = 0;
+
+ daylight = 0;
+ tzname[1] = tzname[0];
+}