Project import
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..b1ee29e
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,111 @@
+#
+#    Copyright (c) 2010-2011 Nest, Inc.
+#    All rights reserved.
+#
+#    This document is the property of Nest. It is considered
+#    confidential and proprietary information.
+#
+#    This document may not be reproduced or transmitted in any form,
+#    in whole or in part, without the express written permission of
+#    Nest.
+#
+#    Description:
+#      This file is the make file for the Netscape Portable Runtime,
+#      (NSPR), providing a platform-neutral API for system level and
+#      libc like functions.
+#
+
+BuildConfigSpecialized	:= No
+BuildProductSpecialized	:= No
+
+include pre.mak
+
+PackageName		:= nspr
+
+PackageExtension	:= tar.gz
+PackageSeparator	:= -
+
+PackagePatchArgs	:= -p1
+
+PackageArchive		:= $(PackageName).$(PackageExtension)
+PackageSourceDir	:= $(PackageName)$(PackageSeparator)$(PackageVersion)
+
+PackageBuildMakefile	= $(call GenerateBuildPaths,Makefile)
+
+LicenseSourceFile	:= $(PackageSourceDir)/mozilla/nsprpub/pr/include/nspr.h
+
+CleanPaths		+= $(PackageLicenseFile)
+
+ifeq ($(BUILD_FEATURE_SIMULATOR), 1)
+	ENABLE_64BIT_NSPR = --enable-64bit
+endif
+
+all: $(PackageDefaultGoal)
+
+# Generate the package license contents.
+
+$(LicenseSourceFile): source
+
+$(PackageLicenseFile): $(LicenseSourceFile)
+	$(Verbose)$(SED) -n -e '/^\/\* \*\*\*\*\* BEGIN LICENSE BLOCK \*\*\*\*\*$$/,/\*\/$$/{;p;/\*\/$$/q;}' < $< > $@
+
+# Extract the source from the archive and apply patches, if any.
+
+$(PackageSourceDir): $(PackageArchive) $(PackagePatchPaths)
+	$(expand-and-patch-package)
+
+# Prepare the sources.
+
+.PHONY: source
+source: | $(PackageSourceDir)
+
+# Patch the sources, if necessary.
+
+.PHONY: patch
+patch: source
+
+# Generate the package build makefile.
+
+$(PackageBuildMakefile): | $(PackageSourceDir) $(BuildDirectory)
+	$(Verbose)cd $(BuildDirectory) && \
+	CC="$(CC)" CXX="$(CXX)" AR=$(AR) RANLIB=$(RANLIB) STRIP=$(STRIP) \
+	INSTALL="$(INSTALL) $(INSTALLFLAGS)" \
+	$(CURDIR)/$(PackageSourceDir)/mozilla/nsprpub/configure \
+	--build=$(HostTuple) \
+	--target=$(TargetTuple) \
+	$(NsprPackageOptions) \
+	--prefix=/usr \
+	--sysconfdir=/etc \
+	--localstatedir=/var \
+	$(ENABLE_64BIT_NSPR) \
+	--disable-static
+
+# Configure the source for building.
+
+.PHONY: configure
+configure: source $(PackageBuildMakefile)
+
+# Build the source.
+#
+# We have to unset MAKEFLAGS since they confuse the package build otherwise.
+
+.PHONY: build
+build: configure
+	$(Verbose)unset MAKEFLAGS && \
+	$(MAKE) $(JOBSFLAG) -C $(BuildDirectory) all
+
+# Stage the build to a temporary installation area.
+#
+# We have to unset MAKEFLAGS since they confuse the package build otherwise.
+
+.PHONY: stage
+stage: build | $(ResultDirectory)
+	$(Verbose)unset MAKEFLAGS && \
+	$(MAKE) $(JOBSFLAG) -C $(BuildDirectory) DESTDIR=$(ResultDirectory) install
+
+clean:
+	$(Verbose)$(RM) $(RMFLAGS) -r $(PackageSourceDir)
+	$(Verbose)$(RM) $(RMFLAGS) -r $(BuildDirectory)
+	$(Verbose)$(RM) $(RMFLAGS) -r $(ResultDirectory)
+
+include post.mak
diff --git a/nspr.patches/nspr-50.description b/nspr.patches/nspr-50.description
new file mode 100644
index 0000000..934ce44
--- /dev/null
+++ b/nspr.patches/nspr-50.description
@@ -0,0 +1,2 @@
+Use the CLOCK_MONOTONIC clock instead of GETTIMEOFDAY for the implementation of PR_IntervalNow().
+This fixes bug #468: "When NTP changes the time on the board, a RESET message is sent to the backplate"
diff --git a/nspr.patches/nspr-50.patch b/nspr.patches/nspr-50.patch
new file mode 100644
index 0000000..164cce3
--- /dev/null
+++ b/nspr.patches/nspr-50.patch
@@ -0,0 +1,25 @@
+diff -aruN nspr-4.8.6/mozilla/nsprpub/pr/src/md/unix/unix.c nspr-4.8.6.N/mozilla/nsprpub/pr/src/md/unix/unix.c
+--- nspr-4.8.6/mozilla/nsprpub/pr/src/md/unix/unix.c	2010-02-09 19:03:35.000000000 -0800
++++ nspr-4.8.6.N/mozilla/nsprpub/pr/src/md/unix/unix.c	2011-04-15 11:10:27.000000000 -0700
+@@ -3026,12 +3026,21 @@
+ 
+ PRIntervalTime _PR_UNIX_GetInterval()
+ {
++#if defined(XP_MACOSX)
+     struct timeval time;
+     PRIntervalTime ticks;
+ 
+     (void)GETTIMEOFDAY(&time);  /* fallicy of course */
+     ticks = (PRUint32)time.tv_sec * PR_MSEC_PER_SEC;  /* that's in milliseconds */
+     ticks += (PRUint32)time.tv_usec / PR_USEC_PER_MSEC;  /* so's that */
++#else
++    struct timespec time;
++    PRIntervalTime ticks;
++
++    (void)clock_gettime(CLOCK_MONOTONIC, &time);
++    ticks = (PRUint32)time.tv_sec * PR_MSEC_PER_SEC;  /* that's in milliseconds */
++    ticks += (PRUint32)((PRUint64)time.tv_nsec / PR_NSEC_PER_MSEC);  /* so's that */
++#endif
+     return ticks;
+ }  /* _PR_SUNOS_GetInterval */
+ 
diff --git a/nspr.patches/nspr-51.description b/nspr.patches/nspr-51.description
new file mode 100644
index 0000000..6e7357c
--- /dev/null
+++ b/nspr.patches/nspr-51.description
@@ -0,0 +1 @@
+Fix for SAPPHIRE-6143:  relies on PR_LocalTimeParameters() to get all time information but tweaks the gmt/dst parameters based on the diff from GMT and using tm_isdst from struct tm. This fix assumes DST is always 1 hour.
diff --git a/nspr.patches/nspr-51.patch b/nspr.patches/nspr-51.patch
new file mode 100644
index 0000000..14b5503
--- /dev/null
+++ b/nspr.patches/nspr-51.patch
@@ -0,0 +1,233 @@
+--- nspr-4.8.6/mozilla/nsprpub/pr/src/misc/prtime.c	2010-03-30 12:15:26.000000000 -0700
++++ nspr-4.8.6.N/mozilla/nsprpub/pr/src/misc/prtime.c	2013-10-21 13:55:53.000000000 -0700
+@@ -102,6 +102,7 @@
+ static void        ComputeGMT(PRTime time, PRExplodedTime *gmt);
+ static int         IsLeapYear(PRInt16 year);
+ static void        ApplySecOffset(PRExplodedTime *time, PRInt32 secOffset);
++static void        AdjustDSTGMTOffsets(PRTime time, PRExplodedTime *exploded);
+ 
+ /*
+  *------------------------------------------------------------------------
+@@ -244,6 +245,7 @@
+     exploded->tm_params = params(exploded);
+     ApplySecOffset(exploded, exploded->tm_params.tp_gmt_offset
+             + exploded->tm_params.tp_dst_offset);
++    AdjustDSTGMTOffsets(usecs, exploded);
+ }
+ 
+ 
+@@ -581,11 +583,68 @@
+ 
+ #endif  /* definition of MT_safe_localtime() */
+ 
++static PRBool ComputeLocalTime(time_t local, struct tm *ptm)
++{
++#ifdef HAVE_LOCALTIME_R
++    return localtime_r(&local, ptm);
++
++#elif HAVE_LOCALTIME_MONITOR
++
++    if (MT_safe_localtime(&local, ptm) != NULL)
++        return PR_TRUE;
++    else
++        return PR_FALSE;
++#else
++
++    #error no ComputeLocalTime()
++
++#endif /* definition of ComputeLocalTime() */
++}
++
++#ifndef HAVE_GMTIME_R
++
++#define HAVE_GMT_MONITOR 1  /* We use 'monitorgmt' to serialize our calls
++                             * to gmtime(). */
++
++static PRLock *monitorgmt = NULL;
++#endif
++
++static PRBool ComputeUTCTime(time_t t, struct tm *ptm)
++{
++#ifdef HAVE_GMTIME_R
++    return gmtime_r(&t, ptm);
++#else
++    PRBool retval = PR_TRUE;
++    struct tm *otm = NULL;
++    int needLock = PR_Initialized();  /* We need to use a lock to protect
++                                       * against NSPR threads only when the
++                                       * NSPR thread system is activated. */
++    if (needLock) PR_Lock(monitorgmt);
++
++    otm = gmtime(&t);
++
++    if (!otm)
++        retval = PR_FALSE;
++    else
++    {
++        *ptm = *otm;
++        retval = PR_TRUE;
++    }
++
++    if (needLock) PR_Unlock(monitorgmt);
++
++    return retval;
++#endif /* definition of ComputeUTCTime() */
++}
++
+ void _PR_InitTime(void)
+ {
+ #ifdef HAVE_LOCALTIME_MONITOR
+     monitor = PR_NewLock();
+ #endif
++#ifdef HAVE_GMT_MONITOR
++    monitorgmt = PR_NewLock();
++#endif
+ #ifdef WINCE
+     _MD_InitTime();
+ #endif
+@@ -599,11 +658,118 @@
+         monitor = NULL;
+     }
+ #endif
++#ifdef HAVE_GMT_MONITOR
++    if (monitorgmt) {
++        PR_DestroyLock(monitorgmt);
++        monitorgmt = NULL;
++    }
++#endif
+ #ifdef WINCE
+     _MD_CleanupTime();
+ #endif
+ }
+ 
++/*
++ * from https://mxr.mozilla.org/mozilla-central/source/js/src/vm/DateTime.cpp?rev=699228670afb
++ * but slightly adjusted as the modzilla has an issue during the hours close to the dst-std change
++ * Compute the offset in seconds from the current UTC time to the current local
++ * time
++ *
++ * Examples:
++ *
++ * Suppose we are in California, USA on January 1, 2013 at 04:00 PST (UTC-8, no
++ * DST in effect), corresponding to 12:00 UTC.  This function would then return
++ * -8 * SecondsPerHour, or -28800.
++ *
++ * Or suppose we are in Berlin, Germany on July 1, 2013 at 17:00 CEST (UTC+2,
++ * DST in effect), corresponding to 15:00 UTC.  This function would then return
++ * +2 * SecondsPerHour, or +7200.
++ */
++static PRInt32
++UTCToLocalTimeOffsetSeconds(time_t time)
++{
++    PRInt32 SecondsPerDay = 86400;
++    PRInt32 SecondsPerHour = 3600;
++    PRInt32 SecondsPerMinute = 60;
++    struct tm local;
++    struct tm utc;
++
++    memset(&local, 0, sizeof(local));
++    memset(&utc, 0, sizeof(utc));
++
++
++#if defined(XP_WIN)
++    // Windows doesn't follow POSIX: updates to the TZ environment variable are
++    // not reflected immediately on that platform as they are on other systems
++    // without this call.
++    _tzset();
++#endif
++
++    // Break down the current time into its components.
++    if (!ComputeLocalTime(time, &local))
++        return 0;
++
++    // Break down the local time into UTC-based components.
++    memset(&utc, 0, sizeof(utc));
++    if (!ComputeUTCTime(time, &utc))
++        return 0;
++
++    // Finally, compare the seconds-based components of the local
++    // representation and the UTC representation to determine the actual
++    // difference.
++    PRInt32 utc_secs = utc.tm_hour * SecondsPerHour + utc.tm_min * SecondsPerMinute;
++    PRInt32 local_secs = local.tm_hour * SecondsPerHour + local.tm_min * SecondsPerMinute;
++
++    // Same-day?  Just subtract the seconds counts.
++    if (utc.tm_mday == local.tm_mday)
++        return local_secs - utc_secs;
++
++    // If we have more UTC seconds, move local seconds into the UTC seconds'
++    // frame of reference and then subtract.
++    if (utc_secs > local_secs)
++        return (SecondsPerDay + local_secs) - utc_secs;
++
++    // Otherwise we have more local seconds, so move the UTC seconds into the
++    // local seconds' frame of reference and then subtract.
++    return local_secs - (utc_secs + SecondsPerDay);
++}
++
++static void
++AdjustDSTGMTOffsets(PRTime time, PRExplodedTime *exploded)
++{
++    PRInt64 sec64;
++    PRInt64 usecPerSec;
++    PRInt32 overallOffsetFromUTC;
++    PRInt32 dstoffset = 3600;
++    struct tm localTime;
++    time_t timetsecs;
++
++    LL_I2L(usecPerSec, 1000000L);
++    LL_DIV(sec64, time, usecPerSec);
++
++    timetsecs = sec64;
++
++    /*
++     *  overall_offset = gmt_offset + dst_offset
++     */
++    overallOffsetFromUTC = UTCToLocalTimeOffsetSeconds(timetsecs);
++
++    /*
++     *  used the passed time to calculate the right offsets based on
++     *  linux call to localtime
++     */
++    (void) MT_safe_localtime(&timetsecs, &localTime);
++
++    if (localTime.tm_isdst <= 0) {
++        /* DST is not in effect */
++        exploded->tm_params.tp_gmt_offset = overallOffsetFromUTC;
++        exploded->tm_params.tp_dst_offset = 0;
++    } else {
++        exploded->tm_params.tp_gmt_offset = overallOffsetFromUTC - dstoffset;
++        exploded->tm_params.tp_dst_offset = dstoffset;
++    }
++}
++
+ #if defined(XP_UNIX) || defined(XP_PC) || defined(XP_BEOS)
+ 
+ PR_IMPLEMENT(PRTimeParameters)
+@@ -642,7 +808,7 @@
+ 
+     /* GMT is 00:00:00, 2nd of Jan. */
+ 
+-    offset2Jan1970 = (PRInt32)localTime.tm_sec 
++    offset2Jan1970 = (PRInt32)localTime.tm_sec
+             + 60L * (PRInt32)localTime.tm_min
+             + 3600L * (PRInt32)localTime.tm_hour
+             + 86400L * (PRInt32)((PRInt32)localTime.tm_mday - 2L);
+@@ -696,7 +862,7 @@
+     }
+ 
+     /*
+-     * dayOffset is the offset between local time and GMT in 
++     * dayOffset is the offset between local time and GMT in
+      * the day component, which can only be -1, 0, or 1.  We
+      * use the day of the week to compute dayOffset.
+      */
+@@ -745,7 +911,7 @@
+             retVal.tp_dst_offset = 3600;
+         }
+     }
+-    
++
+     return retVal;
+ }
+ 
diff --git a/nspr.patches/nspr-52.description b/nspr.patches/nspr-52.description
new file mode 100644
index 0000000..17254e8
--- /dev/null
+++ b/nspr.patches/nspr-52.description
@@ -0,0 +1,4 @@
+Fix for SAPPHIRE-10152: updates PR_NormalizeTime() to correctly resolve DST
+time values using the Olsen database to avoid the issue seen in SAPPHIRE-10133.
+The existing PR_NormalizeTime has been renamed to PR_NormalizeTime_NoDSTAdjust,
+and is now used only internally within prtime.c.
diff --git a/nspr.patches/nspr-52.patch b/nspr.patches/nspr-52.patch
new file mode 100644
index 0000000..294a929
--- /dev/null
+++ b/nspr.patches/nspr-52.patch
@@ -0,0 +1,67 @@
+diff -aruN nspr-4.8.6/mozilla/nsprpub/pr/include/prtime.h nspr-4.8.6.N/mozilla/nsprpub/pr/include/prtime.h
+--- nspr-4.8.6/mozilla/nsprpub/pr/include/prtime.h	2009-03-03 08:17:48.000000000 -0800
++++ nspr-4.8.6.N/mozilla/nsprpub/pr/include/prtime.h	2015-04-29 16:32:24.000000000 -0700
+@@ -206,7 +206,10 @@
+  *     should treat them as "read-only".
+  */
+ 
+-NSPR_API(void) PR_NormalizeTime(
++NSPR_API(PRTime) PR_NormalizeTime(
++    PRExplodedTime *exploded, PRTimeParamFn params);
++
++NSPR_API(void) PR_NormalizeTime_NoDSTAdjust(
+     PRExplodedTime *exploded, PRTimeParamFn params);
+ 
+ /**********************************************************************/
+diff -aruN nspr-4.8.6/mozilla/nsprpub/pr/src/misc/prtime.c nspr-4.8.6.N/mozilla/nsprpub/pr/src/misc/prtime.c
+--- nspr-4.8.6/mozilla/nsprpub/pr/src/misc/prtime.c	2015-04-29 16:33:57.000000000 -0700
++++ nspr-4.8.6.N/mozilla/nsprpub/pr/src/misc/prtime.c	2015-04-29 16:33:10.000000000 -0700
+@@ -272,7 +272,7 @@
+ 
+     /* Normalize first.  Do this on our copy */
+     copy = *exploded;
+-    PR_NormalizeTime(&copy, PR_GMTParameters);
++    PR_NormalizeTime_NoDSTAdjust(&copy, PR_GMTParameters);
+ 
+     numDays = DAYS_BETWEEN_YEARS(1970, copy.tm_year);
+     
+@@ -387,9 +387,29 @@
+     }
+ }
+ 
+-PR_IMPLEMENT(void)
++NSPR_API(PRTime)
+ PR_NormalizeTime(PRExplodedTime *time, PRTimeParamFn params)
+ {
++    PRTime resolvedtime;
++    PR_NormalizeTime_NoDSTAdjust(time, PR_LocalTimeParameters);
++
++    // Resolve DST shifts explicitly. Note that this will also update *time
++    // with the corrected time.
++    resolvedtime = PR_ImplodeTime(time);
++    PR_ExplodeTime(resolvedtime, params, time);
++
++    // Return the DST-resolved PRTime.
++    return resolvedtime;
++}
++
++// This function normalizes time, but does not always resolve Daylight Savings
++// Time correctly (see SAPPHIRE-10133 for an example). It is the original
++// built-in PR_NormalizeTime function in NSPR, but should not be used outside
++// of the functions in this file - users should continue to utilize the newer
++// PR_NormalizeTime function below (see SAPPHIRE-10152).
++PR_IMPLEMENT(void)
++PR_NormalizeTime_NoDSTAdjust(PRExplodedTime *time, PRTimeParamFn params)
++{
+     int daysInMonth;
+     PRInt32 numDays;
+ 
+@@ -1723,7 +1743,7 @@
+    * Mainly to compute wday and yday, but normalized time is also required
+    * by the check below that works around a Visual C++ 2005 mktime problem.
+    */
+-  PR_NormalizeTime(result, PR_GMTParameters);
++  PR_NormalizeTime_NoDSTAdjust(result, PR_GMTParameters);
+   /* The remaining work is to set the gmt and dst offsets in tm_params. */
+ 
+   if (zone == TT_UNKNOWN && default_to_gmt)
diff --git a/nspr.patches/nspr-53.description b/nspr.patches/nspr-53.description
new file mode 100644
index 0000000..c0073f2
--- /dev/null
+++ b/nspr.patches/nspr-53.description
@@ -0,0 +1 @@
+String formatter for z and t length option.  Represents size of size_t and size of ptrdiff_t respectively
diff --git a/nspr.patches/nspr-53.patch b/nspr.patches/nspr-53.patch
new file mode 100644
index 0000000..2eeee82
--- /dev/null
+++ b/nspr.patches/nspr-53.patch
@@ -0,0 +1,44 @@
+diff -aruN nspr-4.8.6/mozilla/nsprpub/pr/include/prprf.h nspr-4.8.6.N/mozilla/nsprpub/pr/include/prprf.h
+--- nspr-4.8.6/mozilla/nsprpub/pr/include/prprf.h	2004-04-25 08:00:47.000000000 -0700
++++ nspr-4.8.6.N/mozilla/nsprpub/pr/include/prprf.h	2015-05-08 11:15:40.200961412 -0700
+@@ -48,6 +48,8 @@
+ **	%hd, %hu, %hx, %hX, %ho - 16-bit versions of above
+ **	%ld, %lu, %lx, %lX, %lo - 32-bit versions of above
+ **	%lld, %llu, %llx, %llX, %llo - 64 bit versions of above
++**	%td, %tu, %tx, %tX, %to - PRPtrdiff versions of the above (deals with machine dependent PRPtrdiff size)
++**	%zd, %zu, %zx, %zX, %zo - PRSize versions of above (deals with machine dependent PRSize size)
+ **	%s - string
+ **	%c - character
+ **	%p - pointer (deals with machine dependent pointer size)
+diff -aruN nspr-4.8.6/mozilla/nsprpub/pr/src/io/prprf.c nspr-4.8.6.N/mozilla/nsprpub/pr/src/io/prprf.c
+--- nspr-4.8.6/mozilla/nsprpub/pr/src/io/prprf.c	2008-05-31 08:10:17.000000000 -0700
++++ nspr-4.8.6.N/mozilla/nsprpub/pr/src/io/prprf.c	2015-05-08 11:12:46.305410769 -0700
+@@ -820,6 +820,28 @@
+ 		type = TYPE_INT64;
+ 		c = *fmt++;
+ 	    }
++	} else if (c == 't') {
++		if (sizeof(PRPtrdiff) == sizeof(PRInt32)) {
++		    type = TYPE_UINT32;
++		} else if (sizeof(PRPtrdiff) == sizeof(PRInt64)) {
++		    type = TYPE_UINT64;
++		} else if (sizeof(PRPtrdiff) == sizeof(PRIntn)) {
++		    type = TYPE_UINTN;
++		} else {
++		    PR_ASSERT(0);
++		}
++		c = *fmt++;
++	} else if (c == 'z') {
++		if (sizeof(PRSize) == sizeof(PRInt32)) {
++		    type = TYPE_UINT32;
++		} else if (sizeof(PRSize) == sizeof(PRInt64)) {
++		    type = TYPE_UINT64;
++		} else if (sizeof(PRSize) == sizeof(PRIntn)) {
++		    type = TYPE_UINTN;
++		} else {
++		    PR_ASSERT(0);
++		}
++		c = *fmt++;
+ 	}
+ 
+ 	/* format */
diff --git a/nspr.tar.gz b/nspr.tar.gz
new file mode 100644
index 0000000..dbd90bb
--- /dev/null
+++ b/nspr.tar.gz
Binary files differ
diff --git a/nspr.url b/nspr.url
new file mode 100644
index 0000000..d485106
--- /dev/null
+++ b/nspr.url
@@ -0,0 +1 @@
+ftp://ftp.mozilla.org/pub/nspr/releases/v4.8.6/src/nspr-4.8.6.tar.gz
diff --git a/nspr.version b/nspr.version
new file mode 100644
index 0000000..7ea5948
--- /dev/null
+++ b/nspr.version
@@ -0,0 +1 @@
+4.8.6