diff options
Diffstat (limited to 'lib/libc/time/tzset.c')
| -rw-r--r-- | lib/libc/time/tzset.c | 58 |
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]; +} |
