#include "time.h"
#include <string.h>
#include <stdlib.h>
static const struct dst_struct cet_dst = {"CEST", -7200, {2, 5, 0, 7200}, {9, 5, 0, 10800}};
static const struct tz_struct tz_table[] = {
{"UTC", 0, NULL},
{"GMT", 0, NULL},
{"CET", -3600, &cet_dst}
};
static const size_t tz_table_size = sizeof tz_table / sizeof tz_table[0];
const struct tz_struct *const __utc_tz = &tz_table[0];
static const struct tz_struct *const gmt_tz = &tz_table[1];
const struct tz_struct *__current_tz;
static char __tzname[TZNAME_MAX + 1][2];
char *tzname[2] __attribute__ ((weak, visibility ("default")));
long timezone __attribute__ ((weak, visibility ("default")));
int daylight __attribute__ ((weak, visibility ("default")));
static void set_vars()
{
strcpy(__tzname[0], __current_tz->name);
strcpy(__tzname[1], __current_tz->dst ? __current_tz->dst->name : __current_tz->name);
tzname[0] = __tzname[0];
tzname[1] = __tzname[1];
timezone = __current_tz->offset;
daylight = __current_tz->dst ? 1 : 0;
}
static void set_current_tz(const char *s)
{
__current_tz = tz_table;
while (__current_tz < tz_table + tz_table_size) {
if (!strcmp(__current_tz->name, s))
goto set_vars;
__current_tz++;
}
__current_tz = __utc_tz;
set_vars:
set_vars();
}
void __tz_init()
{
__current_tz = gmt_tz;
set_vars();
}
void __attribute__ ((weak, visibility ("default"))) tzset()
{
const char *_timezone;
if ((_timezone = getenv("TZ")))
set_current_tz(_timezone);
else
set_current_tz("UTC");
}
typeof (tzset) __tzset __attribute__ ((alias ("tzset")));