1 d2c4ee9e 2003-11-24 devnull #include <stdlib.h> /* setenv etc. */
3 fd04aace 2003-11-23 devnull #include <u.h>
4 64bcfff3 2003-11-25 devnull #define NOPLAN9DEFINES
5 fd04aace 2003-11-23 devnull #include <libc.h>
6 64bcfff3 2003-11-25 devnull #include <time.h>
8 64bcfff3 2003-11-25 devnull #define _HAVETIMEGM 1
9 64bcfff3 2003-11-25 devnull #define _HAVETMZONE 1
10 64bcfff3 2003-11-25 devnull #define _HAVETMTZOFF 1
12 64bcfff3 2003-11-25 devnull #if defined(__linux__)
13 64bcfff3 2003-11-25 devnull # undef _HAVETMZONE
14 64bcfff3 2003-11-25 devnull # undef _HAVETMTZOFF
16 64bcfff3 2003-11-25 devnull #elif defined(__sun__)
17 64bcfff3 2003-11-25 devnull # undef _HAVETIMEGM
18 64bcfff3 2003-11-25 devnull # undef _HAVETMZONE
19 64bcfff3 2003-11-25 devnull # undef _HAVETMTZOFF
23 fd04aace 2003-11-23 devnull static Tm bigtm;
25 fd04aace 2003-11-23 devnull static void
26 fd04aace 2003-11-23 devnull tm2Tm(struct tm *tm, Tm *bigtm)
28 fd04aace 2003-11-23 devnull memset(bigtm, 0, sizeof *bigtm);
29 fd04aace 2003-11-23 devnull bigtm->sec = tm->tm_sec;
30 fd04aace 2003-11-23 devnull bigtm->min = tm->tm_min;
31 fd04aace 2003-11-23 devnull bigtm->hour = tm->tm_hour;
32 fd04aace 2003-11-23 devnull bigtm->mday = tm->tm_mday;
33 fd04aace 2003-11-23 devnull bigtm->mon = tm->tm_mon;
34 fd04aace 2003-11-23 devnull bigtm->year = tm->tm_year;
35 fd04aace 2003-11-23 devnull bigtm->wday = tm->tm_wday;
36 1c253ceb 2003-11-23 devnull #ifdef _HAVETMZONE
37 fd04aace 2003-11-23 devnull strecpy(bigtm->zone, bigtm->zone+4, tm->tm_zone);
39 1c253ceb 2003-11-23 devnull #ifdef _HAVETZOFF
40 fd04aace 2003-11-23 devnull bigtm->tzoff = tm->tm_gmtoff;
44 fd04aace 2003-11-23 devnull static void
45 fd04aace 2003-11-23 devnull Tm2tm(Tm *bigtm, struct tm *tm)
47 fd04aace 2003-11-23 devnull memset(tm, 0, sizeof *tm);
48 fd04aace 2003-11-23 devnull tm->tm_sec = bigtm->sec;
49 fd04aace 2003-11-23 devnull tm->tm_min = bigtm->min;
50 fd04aace 2003-11-23 devnull tm->tm_hour = bigtm->hour;
51 fd04aace 2003-11-23 devnull tm->tm_mday = bigtm->mday;
52 fd04aace 2003-11-23 devnull tm->tm_mon = bigtm->mon;
53 fd04aace 2003-11-23 devnull tm->tm_year = bigtm->year;
54 fd04aace 2003-11-23 devnull tm->tm_wday = bigtm->wday;
55 1c253ceb 2003-11-23 devnull #ifdef _HAVETMZONE
56 fd04aace 2003-11-23 devnull tm->tm_zone = bigtm->zone;
58 1c253ceb 2003-11-23 devnull #ifdef _HAVETZOFF
59 fd04aace 2003-11-23 devnull tm->tm_gmtoff = bigtm->tzoff;
64 fd04aace 2003-11-23 devnull p9gmtime(long t)
66 fd04aace 2003-11-23 devnull struct tm tm;
68 fd04aace 2003-11-23 devnull tm = *gmtime(&t);
69 fd04aace 2003-11-23 devnull tm2Tm(&tm, &bigtm);
70 fd04aace 2003-11-23 devnull return &bigtm;
74 fd04aace 2003-11-23 devnull p9localtime(long t)
76 fd04aace 2003-11-23 devnull struct tm tm;
78 fd04aace 2003-11-23 devnull tm = *localtime(&t);
79 fd04aace 2003-11-23 devnull tm2Tm(&tm, &bigtm);
80 fd04aace 2003-11-23 devnull return &bigtm;
83 d2c4ee9e 2003-11-24 devnull #if !defined(_HAVETIMEGM)
84 d2c4ee9e 2003-11-24 devnull static time_t
85 1c253ceb 2003-11-23 devnull timegm(struct tm *tm)
87 d2c4ee9e 2003-11-24 devnull time_t ret;
88 d2c4ee9e 2003-11-24 devnull char *tz;
91 d2c4ee9e 2003-11-24 devnull tz = getenv("TZ");
92 64bcfff3 2003-11-25 devnull putenv("TZ=");
94 d2c4ee9e 2003-11-24 devnull ret = mktime(tm);
96 64bcfff3 2003-11-25 devnull s = smprint("TZ=%s", tz);
98 64bcfff3 2003-11-25 devnull putenv(s);
100 d2c4ee9e 2003-11-24 devnull return ret;
105 fd04aace 2003-11-23 devnull p9tm2sec(Tm *bigtm)
107 fd04aace 2003-11-23 devnull struct tm tm;
109 fd04aace 2003-11-23 devnull Tm2tm(bigtm, &tm);
110 fd04aace 2003-11-23 devnull if(strcmp(bigtm->zone, "GMT") == 0 || strcmp(bigtm->zone, "UCT") == 0)
111 fd04aace 2003-11-23 devnull return timegm(&tm);
112 fd04aace 2003-11-23 devnull return mktime(&tm); /* local time zone */