delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1997/10/05/12:54:00

Date: Sun, 5 Oct 1997 18:52:39 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: djgpp-workers AT delorie DOT com
cc: DJ Delorie <dj AT delorie DOT com>
Subject: difftime won't go negative
Message-ID: <Pine.SUN.3.91.971005185009.20227A-100000@is>
MIME-Version: 1.0

I had a pleasant hour debugging what appears to be a problem in
`difftime':  it doesn't want to report negative time diffs.  That's
because time_t is unsigned in DJGPP.  Here's the patch (and a test
program to go with it): 

*** src/libc/ansi/time/difftime.c~0	Fri Oct  3 11:04:10 1997
--- src/libc/ansi/time/difftime.c	Fri Oct  3 12:01:56 1997
***************
*** 4,8 ****
  double
  difftime(time_t time1, time_t time0)
  {
!   return time1-time0;
  }
--- 4,25 ----
  double
  difftime(time_t time1, time_t time0)
  {
!   return (double)time1 - (double)time0;
  }
+ 
+ #ifdef TEST
+ 
+ #include <stdio.h>
+ #include <sys/stat.h>
+ 
+ int main (void)
+ {
+   struct stat stat1, stat2;
+ 
+   stat2.st_mtime = 861959338U;
+   stat1.st_mtime = 861926938U;
+   printf ("Res: %f\n", difftime (stat1.st_mtime, stat2.st_mtime));
+   return 0;
+ }
+ 
+ #endif

- Raw text -


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