Bug 350 and Bug 456449: Upgraded NSPR to NSPR_HEAD_20090209.
authorWan-Teh Chang <wtc@google.com>
Mon, 09 Feb 2009 12:24:50 -0800
changeset 24797 b21b71e9b0b1db05db6b047a158cffe0484245c4
parent 24796 a419ff2cf0c5eafa232420ec286f559528dd15be
child 24798 dcb3845d3134ae93f4e5cc5d7bb9f7396eafc3c7
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs350, 456449
milestone1.9.2a1pre
Bug 350 and Bug 456449: Upgraded NSPR to NSPR_HEAD_20090209.
nsprpub/pr/src/md/windows/w95io.c
nsprpub/pr/src/misc/prtime.c
--- a/nsprpub/pr/src/md/windows/w95io.c
+++ b/nsprpub/pr/src/md/windows/w95io.c
@@ -62,45 +62,42 @@ static HANDLE CreateFileA(LPCSTR lpFileN
     PRUnichar wFileName[MAX_PATH];
     MultiByteToWideChar(CP_ACP, 0, lpFileName, -1, wFileName, MAX_PATH);
     return CreateFileW(wFileName, dwDesiredAccess, dwShareMode,
                        lpSecurityAttributes, dwCreationDisposition,
                        dwFlagsAndAttributes, hTemplateFile);
 }
 
 /*
- * We seem to call FindFirstFileA and FindNextFileA just to
- * get the file names in a directory listing.  If so, the
- * WIN32_FIND_DATAA structure could be defined to contain
- * just the cFileName field, and the CopyFindFileDataW2A
- * function could just copy/convert the cFileName field.
+ * We seem to call FindFirstFileA and FindNextFileA just to get
+ * the file names in a directory listing.  If so, we could define
+ * a custom WIN32_FIND_DATAA structure with just the cFileName
+ * member, and the CopyFindFileDataW2A function could just
+ * copy/convert the cFileName member.
  */
-typedef struct _WIN32_FIND_DATAA {
-    DWORD dwFileAttributes;
-    FILETIME ftCreationTime;
-    FILETIME ftLastAccessTime;
-    FILETIME ftLastWriteTime;
-    DWORD nFileSizeHigh;
-    DWORD nFileSizeLow;
-    DWORD dwOID;
-    CHAR  cFileName[MAX_PATH];
-} WIN32_FIND_DATAA, *LPWIN32_FIND_DATAA;
-
 static void CopyFindFileDataW2A(LPWIN32_FIND_DATAW from,
                                 LPWIN32_FIND_DATAA to)
 {
+    /*
+     * WIN32_FIND_DATAA and WIN32_FIND_DATAW are slightly different.
+     * The dwReserved0, dwReserved1, and cAlternateFileName members
+     * exist only in WIN32_FIND_DATAA.  The dwOID member exists only
+     * in WIN32_FIND_DATAW.
+     */
     to->dwFileAttributes = from->dwFileAttributes;
     to->ftCreationTime = from->ftCreationTime;
     to->ftLastAccessTime = from->ftLastAccessTime;
     to->ftLastWriteTime = from->ftLastWriteTime;
     to->nFileSizeHigh = from->nFileSizeHigh;
     to->nFileSizeLow = from->nFileSizeLow;
-    to->dwOID = from->dwOID;
+    to->dwReserved0 = 0;
+    to->dwReserved1 = 0;
     WideCharToMultiByte(CP_ACP, 0, from->cFileName, -1,
                         to->cFileName, MAX_PATH, NULL, NULL);
+    to->cAlternateFileName[0] = '\0';
 }
 
 static HANDLE FindFirstFileA(LPCSTR lpFileName,
                              LPWIN32_FIND_DATAA lpFindFileData)
 {
     PRUnichar wFileName[MAX_PATH];
     HANDLE hFindFile;
     WIN32_FIND_DATAW wFindFileData;
--- a/nsprpub/pr/src/misc/prtime.c
+++ b/nsprpub/pr/src/misc/prtime.c
@@ -69,19 +69,16 @@
  * (which is ((2)-1) * 365) and so on. The reference point is 01/01/01
  * midnight 00:00:00.
  */
 
 #define COUNT_LEAPS(Y)   ( ((Y)-1)/4 - ((Y)-1)/100 + ((Y)-1)/400 )
 #define COUNT_DAYS(Y)  ( ((Y)-1)*365 + COUNT_LEAPS(Y) )
 #define DAYS_BETWEEN_YEARS(A, B)  (COUNT_DAYS(B) - COUNT_DAYS(A))
 
-
-
-
 /*
  * Static variables used by functions in this file
  */
 
 /*
  * The following array contains the day of year for the last day of
  * each month, where index 1 is January, and day 0 is January 1.
  */
@@ -100,27 +97,26 @@ static const PRInt8 nDays[2][12] = {
     {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
 };
 
 /*
  * Declarations for internal functions defined later in this file.
  */
 
 static void        ComputeGMT(PRTime time, PRExplodedTime *gmt);
-static int        IsLeapYear(PRInt16 year);
+static int         IsLeapYear(PRInt16 year);
 static void        ApplySecOffset(PRExplodedTime *time, PRInt32 secOffset);
 
 /*
  *------------------------------------------------------------------------
  *
  * ComputeGMT --
  *
  *     Caveats:
  *     - we ignore leap seconds
- *     - our leap-year calculation is only correct for years 1901-2099
  *
  *------------------------------------------------------------------------
  */
 
 static void
 ComputeGMT(PRTime time, PRExplodedTime *gmt)
 {
     PRInt32 tmp, rem;
@@ -170,59 +166,57 @@ ComputeGMT(PRTime time, PRExplodedTime *
 
     /* Compute the time of day. */
     
     gmt->tm_hour = rem / 3600;
     rem %= 3600;
     gmt->tm_min = rem / 60;
     gmt->tm_sec = rem % 60;
 
-    /* Compute the four-year span containing the specified time */
-
-    tmp = numDays / (4 * 365 + 1);
-    rem = numDays % (4 * 365 + 1);
-
-    if (rem < 0) {
-        tmp--;
-        rem += (4 * 365 + 1);
-    }
-
     /*
-     * Compute the year after 1900 by taking the four-year span and
-     * adjusting for the remainder.  This works because 2000 is a 
-     * leap year, and 1900 and 2100 are out of the range.
+     * Compute the year by finding the 400 year period, then working
+     * down from there.
+     *
+     * Since numDays is originally the number of days since January 1, 1970,
+     * we must change it to be the number of days from January 1, 0001.
      */
     
-    tmp = (tmp * 4) + 1970;
-    isLeap = 0;
+    numDays += 719162;       /* 719162 = days from year 1 up to 1970 */
+    tmp = numDays / 146097;  /* 146097 = days in 400 years */
+    rem = numDays % 146097;
+    gmt->tm_year = tmp * 400 + 1;
 
-    /*
-     * 1970 has 365 days
-     * 1971 has 365 days
-     * 1972 has 366 days (leap year)
-     * 1973 has 365 days
-     */
+    /* Compute the 100 year period. */
 
-    if (rem >= 365) {                                /* 1971, etc. */
-        tmp++;
-        rem -= 365;
-        if (rem >= 365) {                        /* 1972, etc. */
-            tmp++;
-            rem -= 365;
-            if (rem >= 366) {                        /* 1973, etc. */
-                tmp++;
-                rem -= 366;
-            } else {
-                isLeap = 1;
-            }
-        }
+    tmp = rem / 36524;    /* 36524 = days in 100 years */
+    rem %= 36524;
+    if (tmp == 4) {       /* the 400th year is a leap year */
+        tmp = 3;
+        rem = 36524;
+    }
+    gmt->tm_year += tmp * 100;
+
+    /* Compute the 4 year period. */
+
+    tmp = rem / 1461;     /* 1461 = days in 4 years */
+    rem %= 1461;
+    gmt->tm_year += tmp * 4;
+    
+    /* Compute which year in the 4. */
+
+    tmp = rem / 365;
+    rem %= 365;
+    if (tmp == 4) {       /* the 4th year is a leap year */
+        tmp = 3;
+        rem = 365;
     }
 
-    gmt->tm_year = tmp;
+    gmt->tm_year += tmp;
     gmt->tm_yday = rem;
+    isLeap = IsLeapYear(gmt->tm_year);
 
     /* Compute the month and day of month. */
 
     for (tmp = 1; lastDayOfMonth[isLeap][tmp] < gmt->tm_yday; tmp++) {
     }
     gmt->tm_month = --tmp;
     gmt->tm_mday = gmt->tm_yday - lastDayOfMonth[isLeap][tmp];