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