ctime doesn't handle negative times in 4.2
Jay Lepreau
lepreau at utah-cs.UUCP
Fri Jan 6 21:05:25 AEST 1984
Index: lib/libc/gen/ctime.c 4.2BSD Fix
Description:
For negative GMT times, which in the USA can be positive local
times, ctime prints out garbage. Matter of fact it is so garbaged
that the year has a ^A in it! In particular, this is a problem
with local times of 0. gmtime() turns out to be the culprit.
Repeat-By:
main() /* in timezones west of greenwich */
{ int zero = 0;
printf("%s", ctime(&zero));
}
Fix:
This happened cause the types of all the "time" variables in ctime.c
have been changed from long in 4.1 to unsigned long in 4.2. Note that
sys/types.h says that time_t is long, as do all the man pages. Plus I
seem to remember seeing somewhere in the Unix docco that negative
times are supposed to "work." And finally, 7fffffff is year 2038, and
I expect Unix will be long dead by then, even if the world isn't.
All you really have to change are the types in gmtime() itself:
206c206
< unsigned long *tim;
---
> long *tim;
209c209
< unsigned long hms, day;
---
> long hms, day;
More information about the Comp.bugs.4bsd.ucb-fixes
mailing list