Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!decvax!harpo!utah-cs!lepreau From: lepreau@utah-cs.UUCP (Jay Lepreau) Newsgroups: net.bugs.4bsd Subject: ctime doesn't handle negative times in 4.2 Message-ID: <2372@utah-cs.UUCP> Date: Fri, 6-Jan-84 06:05:25 EST Article-I.D.: utah-cs.2372 Posted: Fri Jan 6 06:05:25 1984 Date-Received: Sat, 7-Jan-84 01:48:21 EST Lines: 30 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;