blob: 67a367d61a8a662dd3790b59671eeb44120026d7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#include <stdlib.h>
#include <sys/types.h>
#include <fcntl.h>
#include <time.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>
static char std[32] = "GMT0";
static char dst[32];
char *tzname[2] = {
std, dst
};
long timezone;
long altzone;
int daylight;
void
tzset(void)
{
char *env, *p, *q;
env = NULL;
if((p = getenv("timezone")) == 0)
goto error;
if((env = malloc(strlen(p) + 1)) == 0)
goto error;
strcpy(env, p);
if((p = strchr(env, ' ')) == 0)
goto error;
*p = 0;
strncpy(std, env, sizeof std);
q = p + 1;
if((p = strchr(q, ' ')) == 0)
goto error;
timezone = - atoi(q);
q = p + 1;
if((p = strchr(q, ' ')) == 0)
goto nodst;
*p = 0;
strncpy(dst, q, sizeof dst);
q = p + 1;
altzone = - atoi(q);
daylight = 1;
free(env);
return;
error:
strcpy(std, "GMT0");
dst[0] = '\0';
timezone = 0;
altzone = 0;
daylight = 0;
if(env != 0)
free(env);
return;
nodst:
dst[0] = '\0';
daylight = 0;
altzone = timezone;
free(env);
return;
}
|