]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
dostime.c (dos2unixtime): Mask for seconds is 0x1f.
authorTom Tromey <tromey@redhat.com>
Mon, 11 Nov 2002 22:22:31 +0000 (22:22 +0000)
committerTom Tromey <tromey@gcc.gnu.org>
Mon, 11 Nov 2002 22:22:31 +0000 (22:22 +0000)
* dostime.c (dos2unixtime): Mask for seconds is 0x1f.  Correctly
compute month.
(unix2dostime): Handle years before 1980.  Correctly compute month
and day of month.

From-SVN: r59029

fastjar/ChangeLog
fastjar/dostime.c

index 4c2d85cfc3db9522f21cddff7250439bd6e40372..58ebb1b5161cf65f66456d74a4e5753517095b3b 100644 (file)
@@ -1,3 +1,10 @@
+2002-11-11  Tom Tromey  <tromey@redhat.com>
+
+       * dostime.c (dos2unixtime): Mask for seconds is 0x1f.  Correctly
+       compute month.
+       (unix2dostime): Handle years before 1980.  Correctly compute month
+       and day of month.
+
 2002-11-07  Tom Tromey  <tromey@redhat.com>
 
        * dostime.c: Rewrote from scratch.
index b3c76e5220253419a2999b472c15951c758eb4de..5117a82014ecc48747521789846481283e8e674e 100644 (file)
@@ -49,11 +49,11 @@ dos2unixtime (unsigned long dostime)
   ltime = *localtime (&now);
 
   ltime.tm_year = (dostime >> 25) + 80;
-  ltime.tm_mon = 1 + ((dostime >> 21) & 0x0f);
+  ltime.tm_mon = ((dostime >> 21) & 0x0f) - 1;
   ltime.tm_mday = (dostime >> 16) & 0x1f;
   ltime.tm_hour = (dostime >> 11) & 0x0f;
   ltime.tm_min = (dostime >> 5) & 0x3f;
-  ltime.tm_sec = (dostime & 0x0f) << 1;
+  ltime.tm_sec = (dostime & 0x1f) << 1;
 
   ltime.tm_wday = -1;
   ltime.tm_yday = -1;
@@ -66,10 +66,13 @@ unsigned long
 unix2dostime (time_t *time)
 {
   struct tm *ltime = localtime (time);
+  int year = ltime->tm_year - 80;
+  if (year < 0)
+    year = 0;
 
-  return ((ltime->tm_year - 80) << 25
-         | ltime->tm_mon << 21
-         | (ltime->tm_mday - 1) << 16
+  return (year << 25
+         | (ltime->tm_mon + 1) << 21
+         | ltime->tm_mday << 16
          | ltime->tm_hour << 11
          | ltime->tm_min << 5
          | ltime->tm_sec >> 1);