ReactOS  0.4.15-dev-1197-g8081ba9
timezone.c File Reference
#include "precomp.h"
Include dependency graph for timezone.c:

Go to the source code of this file.

Functions

void__p__daylight (void)
 
long__p__timezone (void)
 
long__p__dstbias (void)
 
char ** __p__tzname (void)
 
void _tzset (void)
 
int CDECL _get_tzname (size_t *ret, char *buf, size_t bufsize, int index)
 

Variables

char _tz_is_set = 0
 
static char tz_name [64] = "PST"
 
static char tz_dst_name [64] = "PDT"
 
long dst_begin = 0
 
long dst_end = 0
 
char_tzname [2]
 
int _daylight = 0
 
long _timezone = 28800
 
long _dstbias = 0
 

Function Documentation

◆ __p__daylight()

void* __p__daylight ( void  )

Definition at line 37 of file timezone.c.

38 {
39  return &_daylight;
40 }
int _daylight
Definition: timezone.c:30

◆ __p__dstbias()

long* __p__dstbias ( void  )

Definition at line 69 of file timezone.c.

70 {
71  return &_dstbias;
72 }
long _dstbias
Definition: timezone.c:62

◆ __p__timezone()

long* __p__timezone ( void  )

Definition at line 53 of file timezone.c.

54 {
55  return &_timezone;
56 }
long _timezone
Definition: timezone.c:46

◆ __p__tzname()

char** __p__tzname ( void  )

Definition at line 79 of file timezone.c.

80 {
81  return _tzname;
82 }
char * _tzname[2]
Definition: timezone.c:22

◆ _get_tzname()

int CDECL _get_tzname ( size_t ret,
char buf,
size_t  bufsize,
int  index 
)

Definition at line 220 of file timezone.c.

221 {
222  char *str_timezone;
223 
224  switch (index)
225  {
226  case 0:
227  str_timezone = tz_name;
228  break;
229 
230  case 1:
231  str_timezone = tz_dst_name;
232  break;
233 
234  default:
235  *_errno() = EINVAL;
236  return EINVAL;
237  }
238 
239  if (!ret || (!buf && (bufsize > 0)) || (buf && !bufsize))
240  {
241  *_errno() = EINVAL;
242  return EINVAL;
243  }
244 
245  *ret = strlen(str_timezone) + 1;
246  if(!buf && !bufsize)
247  return 0;
248 
249  strncpy(buf, str_timezone, bufsize);
250  return 0;
251 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
Definition: arc.h:39
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
GLenum GLuint GLsizei bufsize
Definition: glext.h:7473
static char tz_name[64]
Definition: timezone.c:13
GLuint index
Definition: glext.h:6031
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
int ret
static char tz_dst_name[64]
Definition: timezone.c:14

◆ _tzset()

void _tzset ( void  )

Definition at line 92 of file timezone.c.

93 {
94  const char * str;
95 
96  if (_tz_is_set)
97  {
98  return;
99  }
100 
101  /* Try to read the timezone from environment */
102  str = getenv("TZ");
103  if (str && str[0] != 0)
104  {
105  long hour = 0, min = 0, sec = 0;
106  size_t len = strnlen(str, 16);
107  int sign = 1;
108 
109  dst_begin = 0;
110 
111  for (;;)
112  {
113  /* Copy timezone name */
114  strncpy(tz_name, str, 3);
115  str += 3;
116  len -= 3;
117 
118  if (len < 1) break;
119 
120  if (*str == '+' || *str == '-')
121  {
122  sign = *str == '-' ? -1 : 1;
123  str++;
124  len--;
125  }
126 
127  if (len < 1) break;
128 
129  hour = atol(str);
130 
131  while (*str != 0 && *str != ':') str++;
132  if (*str == 0) break;
133 
134  min = atol(++str);
135 
136  while (*str != 0 && *str != ':') str++;
137  if (*str == 0) break;
138 
139  sec = atol(++str);
140 
141  while (*str != 0 && *str <= '9') str++;
142  if (*str == 0) break;
143 
144  /* Copy DST name */
145  strncpy(tz_dst_name, str, 3);
146 
147  // FIXME: set dst_begin etc
148 
149  /* We are finished */
150  break;
151  }
152 
153  _timezone = sign * (((hour * 60) + min) * 60 + sec);
154 
155  }
156  else
157  {
159  DWORD ret;
160 
161  ret = GetTimeZoneInformation(&tzi);
162  if (ret == TIME_ZONE_ID_INVALID)
163  {
164  return;
165  }
166 
168  0,
169  tzi.StandardName,
170  -1,
171  tz_name,
172  sizeof(tz_name),
173  NULL,
174  NULL);
175 
177  0,
178  tzi.DaylightName,
179  -1,
180  tz_dst_name,
181  sizeof(tz_dst_name),
182  NULL,
183  NULL);
184 
185  _timezone = tzi.Bias * 60;
186 
187  if (tzi.DaylightDate.wMonth)
188  {
189  struct tm _tm;
190 
191  _daylight = 1;
192  _dstbias = (tzi.DaylightBias - tzi.StandardBias) * 60;
193  _tm.tm_year = 70;
194  _tm.tm_mon = tzi.DaylightDate.wMonth - 1;
195  _tm.tm_mday = tzi.DaylightDate.wDay;
196  _tm.tm_hour = tzi.DaylightDate.wHour;
197  _tm.tm_min = tzi.DaylightDate.wMinute;
198  _tm.tm_sec = tzi.DaylightDate.wSecond;
199  dst_begin = (long)_mkgmtime(&_tm);
200  _tm.tm_mon = tzi.StandardDate.wMonth - 1;
201  _tm.tm_mday = tzi.StandardDate.wDay;
202  _tm.tm_hour = tzi.StandardDate.wHour;
203  _tm.tm_min = tzi.StandardDate.wMinute;
204  _tm.tm_sec = tzi.StandardDate.wSecond;
205  dst_end = (long)_mkgmtime(&_tm);
206  }
207  else
208  {
209  _daylight = 0;
210  _dstbias = 0;
211  }
212 
213  }
214  _tz_is_set = 1;
215 }
static size_t double int int int * sign
Definition: printf.c:69
DWORD WINAPI GetTimeZoneInformation(LPTIME_ZONE_INFORMATION lpTimeZoneInformation)
Definition: timezone.c:262
#define WideCharToMultiByte
Definition: compat.h:111
WORD wMonth
Definition: winbase.h:884
#define CP_ACP
Definition: compat.h:109
char _tz_is_set
Definition: timezone.c:10
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
#define TIME_ZONE_ID_INVALID
Definition: winbase.h:283
static char tz_name[64]
Definition: timezone.c:13
const WCHAR * str
WORD wMinute
Definition: winbase.h:888
smooth NULL
Definition: ftsmooth.c:416
_CRTIMP time_t __cdecl _mkgmtime(struct tm *_Tm)
Definition: time.h:427
long _dstbias
Definition: timezone.c:62
long dst_begin
Definition: timezone.c:16
unsigned long DWORD
Definition: ntddk_ex.h:95
_Check_return_ long __cdecl atol(_In_z_ const char *_Str)
WORD wSecond
Definition: winbase.h:889
int ret
int _daylight
Definition: timezone.c:30
GLenum GLsizei len
Definition: glext.h:6722
SYSTEMTIME StandardDate
Definition: winbase.h:1174
Definition: time.h:76
long dst_end
Definition: timezone.c:17
long _timezone
Definition: timezone.c:46
static char tz_dst_name[64]
Definition: timezone.c:14
WORD wDay
Definition: winbase.h:886
_Check_return_ char *__cdecl getenv(_In_z_ const char *_VarName)
WCHAR DaylightName[32]
Definition: winbase.h:1176
#define long
Definition: qsort.c:33
WORD wHour
Definition: winbase.h:887
#define min(a, b)
Definition: monoChain.cc:55
WCHAR StandardName[32]
Definition: winbase.h:1173
SYSTEMTIME DaylightDate
Definition: winbase.h:1177

Referenced by _Strftime(), gettimeofday(), localtime(), and test__tzset().

Variable Documentation

◆ _daylight

int _daylight = 0

Definition at line 30 of file timezone.c.

Referenced by __p__daylight(), _tzset(), and gettimeofday().

◆ _dstbias

long _dstbias = 0

Definition at line 62 of file timezone.c.

Referenced by __p__dstbias(), _gmtime_worker(), _tzset(), and localtime().

◆ _timezone

long _timezone = 28800

Definition at line 46 of file timezone.c.

Referenced by __p__timezone(), _tzset(), gettimeofday(), and localtime().

◆ _tz_is_set

char _tz_is_set = 0

Definition at line 10 of file timezone.c.

Referenced by _tzset(), and localtime().

◆ _tzname

char* _tzname[2]
Initial value:
= {
}
static char tz_name[64]
Definition: timezone.c:13
static char tz_dst_name[64]
Definition: timezone.c:14

Definition at line 22 of file timezone.c.

Referenced by __p__tzname().

◆ dst_begin

long dst_begin = 0

Definition at line 16 of file timezone.c.

Referenced by _gmtime_worker(), and _tzset().

◆ dst_end

◆ tz_dst_name

char tz_dst_name[64] = "PDT"
static

Definition at line 14 of file timezone.c.

Referenced by _get_tzname(), and _tzset().

◆ tz_name

char tz_name[64] = "PST"
static

Definition at line 13 of file timezone.c.

Referenced by _get_tzname(), and _tzset().