blob: e9c2fe663db198b0b8e91a52357f19a467af61f0 [file] [log] [blame] [raw]
/* A part of the Native C Library for Windows NT
Copyright 2007-2015 PC GO Ld.
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 2 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.
*/
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <windows.h>
#include <nt.h>
#ifndef TZDEFAULT
#define TZDEFAULT "localtime"
#endif
char *tzname[2];
long int timezone;
int daylight;
static void tzset_utc() {
tzname[0] = tzname[1] = (char *)"UTC";
timezone = 0;
daylight = 0;
}
void tzset() {
//static int initialized = 0;
//if(initialized) return;
//initialized = 1;
//const char *tz = getenv("TZ");
const char *tz = NULL; // TODO: implement the getenv
if(tz && !*tz) tz = "Universal";
else if(tz && *tz == ':') tz++;
else if(!tz) tz = TZDEFAULT;
//free(old_tz);
//old_tz = tz ? strdup(tz) : NULL;
if(!tz || strcmp(tz, "localtime") == 0) {
static char _tzname[64];
TIME_ZONE_INFORMATION tzi;
long int status = RtlQueryTimeZoneInformation(&tzi);
if(status < 0) {
tzset_utc();
return;
}
wcstombs(_tzname, tzi.StandardName, sizeof _tzname);
tzname[0] = _tzname;
timezone = tzi.Bias * 60;
daylight = tzi.DaylightBias;
} else tzset_utc();
}