diff --git a/sys/include/libc.h b/sys/include/libc.h index ffacc848a..95ad56bae 100644 --- a/sys/include/libc.h +++ b/sys/include/libc.h @@ -416,7 +416,7 @@ extern void sysfatal(char*, ...); #pragma varargck argpos sysfatal 1 extern void syslog(int, char*, char*, ...); #pragma varargck argpos syslog 3 -extern long time(long*); +extern ulong time(long*); extern int tolower(int); extern int toupper(int); diff --git a/sys/man/2/ctime b/sys/man/2/ctime index a4e074343..814dc7631 100644 --- a/sys/man/2/ctime +++ b/sys/man/2/ctime @@ -121,9 +121,15 @@ GMT 0 .SH BUGS The return values point to static data whose content is overwritten by each call. -.br +.PP Daylight Savings Time is ``normal'' in the Southern hemisphere. -.br +.PP These routines are not equipped to handle non-\c .SM ASCII text, and are provincial anyway. +.PP +These interfaces are fixed, but all occurrences of +.B long +in the above should be manipulated as +.BR ulong ; +this extends the range of valid times into the year 2106. diff --git a/sys/man/2/time b/sys/man/2/time index 9e1054c68..3448b2f26 100644 --- a/sys/man/2/time +++ b/sys/man/2/time @@ -8,7 +8,7 @@ time, nsec \- time in seconds and nanoseconds since epoch .PP .nf .B -long time(long *tp) +ulong time(long *tp) .PP .B vlong nsec(void) @@ -27,11 +27,16 @@ is not zero then .BI * tp is also set to the answer. .PP -Times from -.I time -should be stored in and treated as -.BR ulong s; +Times should be stored in and treated as +.BR ulong s, +or cast to +.B ulong +then stored in +.BR vlong s; this extends the range of valid times into the year 2106. +Before subtraction, +times should be cast to +.BR vlong . .PP .I Time simply calls @@ -53,7 +58,13 @@ of process forks is overly complex and prone to error. .B /sys/src/libc/9syscall .SH SEE ALSO .IR cputime (2), +.IR ctime (2), .IR cons (3) .SH DIAGNOSTICS Sets .IR errstr . +Programs should test for the exact +.I time +value +.B (ulong)-1 +as a failure indication, not just for any negative value. diff --git a/sys/src/ape/lib/ap/plan9/ctime.c b/sys/src/ape/lib/ap/plan9/ctime.c index d1d651f12..72126a50c 100644 --- a/sys/src/ape/lib/ap/plan9/ctime.c +++ b/sys/src/ape/lib/ap/plan9/ctime.c @@ -54,7 +54,7 @@ static void readtimezone(void); static int rd_name(char**, char*); static int rd_long(char**, long*); -#define TZSIZE 150 +#define TZSIZE ((136*2)+10) /* 1970-2106 */ static struct @@ -63,7 +63,7 @@ struct char dlname[4]; long stdiff; long dldiff; - long dlpairs[TZSIZE]; + unsigned long dlpairs[TZSIZE]; } timezone; char* @@ -77,7 +77,7 @@ gmtime_r(const time_t *timp, struct tm *result) { int d0, d1; long hms, day; - time_t tim; + unsigned long tim; tim = *timp; /* @@ -146,8 +146,8 @@ struct tm* localtime_r(const time_t *timp, struct tm *result) { struct tm *ct; - time_t t, tim; - long *p; + unsigned long t, tim; + unsigned long *p; int dlflag; tim = *timp; @@ -162,7 +162,7 @@ localtime_r(const time_t *timp, struct tm *result) dlflag++; break; } - ct = gmtime_r(&t, result); + ct = gmtime_r((time_t *)&t, result); ct->tm_isdst = dlflag; return ct; } @@ -251,7 +251,7 @@ readtimezone(void) if(rd_long(&p, &timezone.dldiff)) goto error; for(i=0; ihdr.name, 0); /* blank pad on right */ cp < bp->hdr.name+sizeof(bp->hdr.name); cp++) *cp = ' '; - sprint(bp->hdr.date, "%-12ld", d->mtime); + sprint(bp->hdr.date, "%-12lud", d->mtime); sprint(bp->hdr.uid, "%-6d", 0); sprint(bp->hdr.gid, "%-6d", 0); sprint(bp->hdr.mode, "%-8lo", d->mode); - sprint(bp->hdr.size, "%-10lld", d->length); + sprint(bp->hdr.size, "%-10llud", d->length); strncpy(bp->hdr.fmag, ARFMAG, 2); bp->size = d->length; arread(b, bp, bp->size); @@ -829,11 +829,11 @@ rl(int fd) len = symdefsize; if(len&01) len++; - sprint(a.date, "%-12ld", time(0)); + sprint(a.date, "%-12lud", time(0)); sprint(a.uid, "%-6d", 0); sprint(a.gid, "%-6d", 0); sprint(a.mode, "%-8lo", 0644L); - sprint(a.size, "%-10ld", len); + sprint(a.size, "%-10lud", len); strncpy(a.fmag, ARFMAG, 2); strcpy(a.name, symdef); for (cp = strchr(a.name, 0); /* blank pad on right */ @@ -988,7 +988,7 @@ longt(Armember *bp) pmode(strtoul(bp->hdr.mode, 0, 8)); Bprint(&bout, "%3ld/%1ld", strtol(bp->hdr.uid, 0, 0), strtol(bp->hdr.gid, 0, 0)); - Bprint(&bout, "%7ld", bp->size); + Bprint(&bout, "%7lud", bp->size); cp = ctime(bp->date); Bprint(&bout, " %-12.12s %-4.4s ", cp+4, cp+24); } diff --git a/sys/src/cmd/cwfs/main.c b/sys/src/cmd/cwfs/main.c index d1422a1f9..96bf25715 100644 --- a/sys/src/cmd/cwfs/main.c +++ b/sys/src/cmd/cwfs/main.c @@ -489,7 +489,8 @@ void wormcopy(void *) { int f, dorecalc = 1; - Timet dt, t = 0, nddate = 0, ntoytime = 0; + Timet t = 0, nddate = 0, ntoytime = 0; + vlong dt; Filsys *fs; for (;;) { diff --git a/sys/src/cmd/cwfs/portdat.h b/sys/src/cmd/cwfs/portdat.h index d01be6fea..e32b92e94 100644 --- a/sys/src/cmd/cwfs/portdat.h +++ b/sys/src/cmd/cwfs/portdat.h @@ -10,7 +10,7 @@ enum { /* more fundamental types */ typedef vlong Wideoff; /* type to widen Off to for printing; ≥ as wide as Off */ typedef short Userid; /* signed internal representation of user-id */ -typedef long Timet; /* in seconds since epoch */ +typedef ulong Timet; /* in seconds since epoch */ typedef vlong Devsize; /* in bytes */ diff --git a/sys/src/cmd/history.c b/sys/src/cmd/history.c index 283da04df..d2be9e300 100644 --- a/sys/src/cmd/history.c +++ b/sys/src/cmd/history.c @@ -1,7 +1,7 @@ #include #include -#define MINUTE(x) ((long)(x)*60L) +#define MINUTE(x) ((x)*60L) #define HOUR(x) (MINUTE(x)*60L) #define YEAR(x) (HOUR(x)*24L*360L) @@ -17,7 +17,7 @@ int ndargv = 1; void usage(void); void ysearch(char*, char*); -long starttime(char*); +ulong starttime(char*); void lastbefore(ulong, char*, char*, char*); char* prtime(ulong); void darg(char*); @@ -304,11 +304,11 @@ prtime(ulong t) return buf; } -long +ulong starttime(char *s) { Tm *tm; - long t, dt; + ulong t, dt; int i, yr, mo, da; t = time(0); diff --git a/sys/src/cmd/mk/archive.c b/sys/src/cmd/mk/archive.c index 8c4c0c81e..8d73ca7af 100644 --- a/sys/src/cmd/mk/archive.c +++ b/sys/src/cmd/mk/archive.c @@ -67,7 +67,7 @@ atouch(char *name) if(strcmp(member, h.name) == 0){ t = SARNAME-sizeof(h); /* ughgghh */ LSEEK(fd, t, 1); - fprint(fd, "%-12ld", time(0)); + fprint(fd, "%-12lud", time(0)); break; } t = atol(h.size); diff --git a/sys/src/cmd/upas/smtp/greylist.c b/sys/src/cmd/upas/smtp/greylist.c index b5cee5a6e..460423a57 100644 --- a/sys/src/cmd/upas/smtp/greylist.c +++ b/sys/src/cmd/upas/smtp/greylist.c @@ -30,7 +30,7 @@ typedef struct { int existed; /* these two are distinct to cope with errors */ int created; int noperm; - long mtime; /* mod time, iff it already existed */ + ulong mtime; /* mod time, iff it already existed */ } Greysts; static char whitelist[] = "/mail/grey/whitelist"; @@ -218,7 +218,7 @@ addgreylist(char *file, Greysts *gsp) static int recentcall(Greysts *gsp) { - long delay = time(0) - gsp->mtime; + ulong delay = (ulong)time(0) - gsp->mtime; if (!gsp->existed) return 0; diff --git a/sys/src/libc/9sys/ctime.c b/sys/src/libc/9sys/ctime.c index 0137d6fff..7ebdef233 100644 --- a/sys/src/libc/9sys/ctime.c +++ b/sys/src/libc/9sys/ctime.c @@ -47,7 +47,8 @@ static char dmsize[12] = static int dysize(int); static void ct_numb(char*, int); -#define TZSIZE 150 +#define TZSIZE ((136*2)+10) /* 1970-2106; match tm2sec.c */ + static void readtimezone(void); static int rd_name(char**, char*); static int rd_long(char**, long*); @@ -58,7 +59,7 @@ struct char dlname[4]; long stdiff; long dldiff; - long dlpairs[TZSIZE]; + ulong dlpairs[TZSIZE]; } timezone; char* @@ -68,12 +69,13 @@ ctime(long t) } Tm* -localtime(long tim) +localtime(long atim) /* should be ulong, but it's too late */ { Tm *ct; - long t, *p; + ulong tim, t, *p; int dlflag; + tim = atim; if(timezone.stname[0] == 0) readtimezone(); t = tim + timezone.stdiff; @@ -97,17 +99,19 @@ localtime(long tim) } Tm* -gmtime(long tim) +gmtime(long atim) /* should be ulong, but it's too late */ { int d0, d1; long hms, day; + ulong tim; static Tm xtime; /* * break initial number into days */ - hms = (ulong)tim % 86400L; - day = (ulong)tim / 86400L; + tim = atim; + hms = tim % 86400L; + day = tim / 86400L; if(hms < 0) { hms += 86400L; day -= 1; @@ -234,12 +238,12 @@ readtimezone(void) if(rd_long(&p, &timezone.dldiff)) goto error; for(i=0; i #include -long +ulong time(long *tp) { vlong t; diff --git a/sys/src/libc/9sys/tm2sec.c b/sys/src/libc/9sys/tm2sec.c index 223d3f1d9..403cb13fe 100644 --- a/sys/src/libc/9sys/tm2sec.c +++ b/sys/src/libc/9sys/tm2sec.c @@ -1,10 +1,12 @@ #include #include -#define TZSIZE 150 +#define TZSIZE ((136*2)+10) /* 1970-2106; match tm2sec.c */ + static void readtimezone(void); static int rd_name(char**, char*); static int rd_long(char**, long*); + static struct { @@ -12,12 +14,12 @@ struct char dlname[4]; long stdiff; long dldiff; - long dlpairs[TZSIZE]; + ulong dlpairs[TZSIZE]; } timezone; -#define SEC2MIN 60L -#define SEC2HOUR (60L*SEC2MIN) -#define SEC2DAY (24L*SEC2HOUR) +#define SEC2MIN 60UL +#define SEC2HOUR (60UL*SEC2MIN) +#define SEC2DAY (24UL*SEC2HOUR) /* * days per month plus days/year @@ -50,7 +52,7 @@ yrsize(int y) long tm2sec(Tm *tm) { - long secs; + ulong secs; int i, yday, year, *d2m; if(strcmp(tm->zone, "GMT") != 0 && timezone.stname[0] == 0) @@ -95,8 +97,6 @@ tm2sec(Tm *tm) secs -= timezone.stdiff; else if(strcmp(tm->zone, timezone.dlname) == 0) secs -= timezone.dldiff; - if(secs < 0) - secs = 0; return secs; } @@ -124,12 +124,12 @@ readtimezone(void) if(rd_long(&p, &timezone.dldiff)) goto error; for(i=0; i