This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Patch: FYI: fastjar dostime.c rewrite


>>>>> "Paolo" == Paolo Bonzini <bonzini@gnu.org> writes:

Tom> +  ltime.tm_sec = (dostime & 0x0f) << 1;

Paolo> should be 0x1f for bits 0-4 (0-31*2 seconds)

Thanks.  I found a couple other bugs in my rewrite.  I'm checking in
the appended patch.  I'm putting it on the 3.2 branch as well.

Tom

Index: ChangeLog
from  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.

Index: dostime.c
===================================================================
RCS file: /cvs/gcc/gcc/fastjar/dostime.c,v
retrieving revision 1.3
diff -u -r1.3 dostime.c
--- dostime.c 7 Nov 2002 14:07:19 -0000 1.3
+++ dostime.c 11 Nov 2002 22:17:45 -0000
@@ -49,11 +49,11 @@
   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 @@
 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);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]