summaryrefslogtreecommitdiff
path: root/sys/src/ape
diff options
context:
space:
mode:
authoraiju <aiju@phicode.de>2011-06-04 12:02:42 +0200
committeraiju <aiju@phicode.de>2011-06-04 12:02:42 +0200
commit67daf453a755bb6fc15a69e49784f1bdd66eaa61 (patch)
treea4eb5862bc93ab643e86a176cde699e9c14b3aa0 /sys/src/ape
parent13ae620a451fc0941810b7617e6efaeceb8473c6 (diff)
fixed tzset(), hopefully hg timezone bug should be fixed now
Diffstat (limited to 'sys/src/ape')
-rw-r--r--sys/src/ape/lib/ap/posix/tzset.c160
1 files changed, 39 insertions, 121 deletions
diff --git a/sys/src/ape/lib/ap/posix/tzset.c b/sys/src/ape/lib/ap/posix/tzset.c
index 8502c6d66..bcbe59dc7 100644
--- a/sys/src/ape/lib/ap/posix/tzset.c
+++ b/sys/src/ape/lib/ap/posix/tzset.c
@@ -6,136 +6,54 @@
#include <string.h>
#include <unistd.h>
-#define TZFILE "/etc/TZ"
-
-static char TZ[128];
static char std[32] = "GMT0";
static char dst[32];
char *tzname[2] = {
std, dst
};
-time_t tzoffset, tzdstoffset;
-int tzdst = 0;
-
-static int
-offset(char *env, time_t *off)
-{
- int n, sign;
- size_t len, retlen;
-
- retlen = 0;
- sign = 1;
- /*
- * strictly, no sign is allowed in the 'time' part of the
- * dst start/stop rules, but who cares?
- */
- if (*env == '-' || *env == '+') {
- if (*env++ == '-')
- sign = -1;
- retlen++;
- }
- if ((len = strspn(env, ":0123456789")) == 0)
- return 0;
- retlen += len;
- for (*off = 0; len && isdigit(*env); len--) /* hours */
- *off = *off*10 + (*env++ - '0')*60*60;
- if (len) {
- if (*env++ != ':')
- return 0;
- len--;
- }
- for (n = 0; len && isdigit(*env); len--) /* minutes */
- n = n*10 + (*env++ - '0')*60;
- *off += n;
- if (len) {
- if (*env++ != ':')
- return 0;
- len--;
- }
- for (n = 0; len && isdigit(*env); len--) /* seconds */
- n = n*10 + (*env++ - '0');
- *off = (*off + n)*sign;
- return retlen;
-}
+long timezone;
+int daylight;
-/*
- * TZ=stdoffset[dst[offset][,start[/time],end[/time]]]
- */
void
tzset(void)
{
- char *env, *p, envbuf[128];
- int fd, i;
- size_t len, retlen;
- time_t off;
-
- /*
- * get the TZ environment variable and check for validity.
- * the implementation-defined manner for dealing with the
- * leading ':' format is to reject it.
- * if it's ok, stash a copy away for quick comparison next time.
- */
- if ((env = getenv("TZ")) == 0) {
- if ((fd = open(TZFILE, O_RDONLY)) == -1)
- return;
- if (read(fd, envbuf, sizeof(envbuf)-1) == -1) {
- close(fd);
- return;
- }
- close(fd);
- for (i = 0; i < sizeof(envbuf); i++) {
- if (envbuf[i] != '\n')
- continue;
- envbuf[i] = '\0';
- break;
- }
- env = envbuf;
- }
- if (strcmp(env, TZ) == 0)
- return;
- if (*env == 0 || *env == ':')
- return;
- strncpy(TZ, env, sizeof(TZ)-1);
- TZ[sizeof(TZ)-1] = 0;
- /*
- * get the 'std' string.
- * before committing, check there is a valid offset.
- */
- if ((len = strcspn(env, ":0123456789,-+")) == 0)
- return;
- if ((retlen = offset(env+len, &off)) == 0)
- return;
- for (p = std, i = len+retlen; i; i--)
- *p++ = *env++;
+ char *env, *p, *q;
+
+ 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;
- tzoffset = -off;
- /*
- * get the 'dst' string (if any).
- */
- if (*env == 0 || (len = strcspn(env, ":0123456789,-+")) == 0)
- return;
- for (p = dst; len; len--)
- *p++ = *env++;
+ 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;
- /*
- * optional dst offset.
- * default is one hour.
- */
- tzdst = 1;
- if (retlen = offset(env+len, &off)) {
- tzdstoffset = -off;
- env += retlen;
- }
- else
- tzdstoffset = tzoffset + 60*60;
- /*
- * optional rule(s) for start/end of dst.
- */
- if (*env == 0 || *env != ',' || *(env+1) == 0)
- return;
- env++;
- /*
- * we could go on...
- * but why bother?
- */
+ strncpy(dst, q, sizeof dst);
+ q = p + 1;
+ daylight = 1;
+ free(env);
+ return;
+
+error:
+ strcpy(std, "GMT0");
+ dst[0] = '\0';
+ timezone = 0;
+ daylight = 0;
+ if(env != 0)
+ free(env);
+ return;
+
+nodst:
+ dst[0] = '\0';
+ daylight = 0;
+ free(env);
+ return;
}