www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/08/26/05:22:13

Subject: Re: 1.12.maint1, second beta
To: dj AT ctron DOT com
Date: Fri, 26 Aug 1994 10:16:50 +0200 (MET DST)
From: Henrik Storner <storner AT olicom DOT dk>
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu

I wrote:

> 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:
> 
> [patch deleted]

I hate to admit this, but - it was a little trickier than that: DST
didn't work. Not bad for a first attempt, though.

This one ought to do the trick:

*** libsrc/c/sys/stat.org	Tue Jul 19 03:35:22 1994
--- libsrc/c/sys/stat.c	Fri Aug 26 16:07:22 1994
***************
*** 14,17 ****
--- 14,19 ----
  #include <stdio.h>
  
+ #include <sys/timeb.h>
+ 
  extern int	stat_assist(const char *, struct stat *);
  extern void	_fixpath(const char *, char *);
***************
*** 80,83 ****
--- 82,86 ----
  {
      static int	stat_called_before = 0;
+     static int  stat_gmtfix = 0;
      char	p[900];	/* Should be p[PATH_MAX+1] */
      int		status;
***************
*** 89,94 ****
--- 92,108 ----
      if (!stat_called_before)
      {
+         /* Initialize the first time called */
+         struct timeb fbuf;
+ 
  	stat_called_before = 1;
  	(void) time((time_t *) 0);
+ 
+ 	/* stat_assist gives localtime, but believes it is EST5 */
+ 	/* Compute # of seconds this is really offset from GMT  */
+ 	ftime(&fbuf);
+         stat_gmtfix = fbuf.timezone*60 - 14400;
+ 	if (fbuf.dstflag)
+ 		/* Correct for DST in effect */
+ 		stat_gmtfix -= 3600;
      }
  
***************
*** 138,141 ****
--- 152,160 ----
  	   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;
      }


It still isn't perfect; for instance, setting TZ to EST5EDT breaks _all_
of the time related functions, including ftime() which is used by this
patch. But at least, the results are consistent throughout all of the
compiler library functions.

It works for all of the basic TZ settings (EST5, GMT0 etc), and for the
POSIX type settings.
-- 
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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019