Subject: Re: 1.12.maint1, second beta To: dj AT ctron DOT com (DJ Delorie) Date: Fri, 26 Aug 1994 09:35:56 +0200 (MET DST) From: Henrik Storner Cc: djgpp AT sun DOT soe DOT clarkson DOT edu DJ writes: > > > And while on this point, does anyone know where can I found the definition > > of how stat() should use TZ? Some POSIX paper, maybe? Any site which > > POSIX.1 states that for the time-related fields, "Times are given in > seconds since the Epoch." Epoch is defined as "00:00:00 Jan 1 1970 > Coordinated Universal Time." > > I interpret CUT to be the same as GMT+0, so TZ would (or should) have > no affect, except that DOS stores times as local time instead of CUT > time. Meaning ... what, exactly ? That the current DJGPP-stat() behaviour is wrong, I suppose ? Surely, the values presently returned by stat() do not fit in anywhere with the POSIX definition you mention; the value that stat() gives is GMT-time+4 hours, presumably du to some hardwired setting if EST5 as the timezone. Note that the values does _not_ change with the TZ setting! A simple fix would be to use the current stat() value, subtract 4 hours and then convert from localtime to GMT. Cannot be all that hard, eh ? Like this: *** libsrc/c/sys/stat.org Tue Jul 19 03:35:22 1994 --- libsrc/c/sys/stat.c Fri Aug 26 15:33:20 1994 *************** *** 80,83 **** --- 80,84 ---- { static int stat_called_before = 0; + static int stat_gmtfix = 0; char p[900]; /* Should be p[PATH_MAX+1] */ int status; *************** *** 89,94 **** --- 90,104 ---- if (!stat_called_before) { + /* Initialize the first time called */ + time_t ltm, gtm; + stat_called_before = 1; (void) time((time_t *) 0); + + ltm = gtm = time (NULL); + ltm = mktime (localtime (<m)); + gtm = mktime (gmtime (>m)); + /* # of seconds GMT is offset from local */ + stat_gmtfix = (int)(gtm - ltm) - 14400; } *************** *** 138,141 **** --- 148,156 ---- stat_assist doesn't think so. */ if (S_ISDIR(buf->st_mode)) buf->st_mode |= S_IWRITE; + + /* Fixup times returned by stat() from being EST5-based */ + buf->st_ctime += stat_gmtfix; + buf->st_mtime += stat_gmtfix; + buf->st_atime += stat_gmtfix; } -- Henrik Storner | "Man is the best computer we can put aboard a space- (storner AT olicom DOT dk) | craft ... and the only one that can be mass produced System Engineering | with unskilled labor." Olicom Denmark | Wernher von Braun