changeset 7523:8994727ff976

(gettimeofday): New function substituting the library function of the same name. (init_gettimeofday): New function. (init_environment): Call init_gettimeofday after possibly setting TZ environment variable.
author Richard M. Stallman <rms@gnu.org>
date Tue, 17 May 1994 07:24:12 +0000
parents 3049e726a161
children 66d8171f3d42
files src/msdos.c
diffstat 1 files changed, 53 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/msdos.c	Tue May 17 05:14:10 1994 +0000
+++ b/src/msdos.c	Tue May 17 07:24:12 1994 +0000
@@ -739,6 +739,7 @@
       break;
     }
   tzset ();
+  init_gettimeofday ();
 }
 
 /* Flash the screen as a substitute for BEEPs.  */
@@ -889,7 +890,59 @@
   internal_terminal
     = (!noninteractive) && term && !strcmp (term, "internal");
 }
+
+/* When time zones are set from Ms-Dos too may C-libraries are playing
+   tricks with time values.  We solve this by defining our own version
+   of `gettimeofday' bypassing GO32.  Our version needs to be initialized
+   once and after each call to `tzset' with TZ changed.  */
 
+static int daylight, gmtoffset;
+
+int
+gettimeofday (struct timeval *tp, struct timezone *tzp)
+{
+  if (tp)
+    {
+      struct time t;
+      struct date d;
+      struct tm tmrec;
+
+      gettime (&t);
+      getdate (&d);
+      tmrec.tm_year = d.da_year - 1900;
+      tmrec.tm_mon = d.da_mon - 1;
+      tmrec.tm_mday = d.da_day;
+      tmrec.tm_hour = t.ti_hour;
+      tmrec.tm_min = t.ti_min;
+      tmrec.tm_sec = t.ti_sec;
+      tmrec.tm_gmtoff = gmtoffset;
+      tmrec.tm_isdst = daylight;
+      tp->tv_sec = mktime (&tmrec);
+      tp->tv_usec = t.ti_hund * (1000000 / 100);
+    }
+  if (tzp)
+    {
+      tzp->tz_minuteswest = gmtoffset;
+      tzp->tz_dsttime = daylight;
+    }
+  return 0;
+}
+
+void
+init_gettimeofday ()
+{
+  time_t ltm, gtm;
+  struct tm *lstm;
+
+  daylight = 0;
+  gmtoffset = 0;
+  ltm = gtm = time (NULL);
+  ltm = mktime (lstm = localtime (&ltm));
+  gtm = mktime (gmtime (&gtm));
+  daylight = lstm->tm_isdst;
+  gmtoffset = (int)(gtm - ltm) / 60;
+}
+
 /* These must be global.  */
 static _go32_dpmi_seginfo ctrl_break_vector;
 static _go32_dpmi_registers ctrl_break_regs;