/* Copyright (C) 2008 Emmanuel Varoquaux This file is part of XOS. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "time.h" #include #include 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 */ {"UTC", 0, NULL}, /* GMT */ {"GMT", 0, NULL}, /* CET */ {"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")));