Project import generated by Copybara.

NOKEYCHECK=True
GitOrigin-RevId: f3be00015bca34d72208c1e3b94b4fc50ef5f2aa
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..14e2f77
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,373 @@
+Mozilla Public License Version 2.0
+==================================
+
+1. Definitions
+--------------
+
+1.1. "Contributor"
+    means each individual or legal entity that creates, contributes to
+    the creation of, or owns Covered Software.
+
+1.2. "Contributor Version"
+    means the combination of the Contributions of others (if any) used
+    by a Contributor and that particular Contributor's Contribution.
+
+1.3. "Contribution"
+    means Covered Software of a particular Contributor.
+
+1.4. "Covered Software"
+    means Source Code Form to which the initial Contributor has attached
+    the notice in Exhibit A, the Executable Form of such Source Code
+    Form, and Modifications of such Source Code Form, in each case
+    including portions thereof.
+
+1.5. "Incompatible With Secondary Licenses"
+    means
+
+    (a) that the initial Contributor has attached the notice described
+        in Exhibit B to the Covered Software; or
+
+    (b) that the Covered Software was made available under the terms of
+        version 1.1 or earlier of the License, but not also under the
+        terms of a Secondary License.
+
+1.6. "Executable Form"
+    means any form of the work other than Source Code Form.
+
+1.7. "Larger Work"
+    means a work that combines Covered Software with other material, in 
+    a separate file or files, that is not Covered Software.
+
+1.8. "License"
+    means this document.
+
+1.9. "Licensable"
+    means having the right to grant, to the maximum extent possible,
+    whether at the time of the initial grant or subsequently, any and
+    all of the rights conveyed by this License.
+
+1.10. "Modifications"
+    means any of the following:
+
+    (a) any file in Source Code Form that results from an addition to,
+        deletion from, or modification of the contents of Covered
+        Software; or
+
+    (b) any new file in Source Code Form that contains any Covered
+        Software.
+
+1.11. "Patent Claims" of a Contributor
+    means any patent claim(s), including without limitation, method,
+    process, and apparatus claims, in any patent Licensable by such
+    Contributor that would be infringed, but for the grant of the
+    License, by the making, using, selling, offering for sale, having
+    made, import, or transfer of either its Contributions or its
+    Contributor Version.
+
+1.12. "Secondary License"
+    means either the GNU General Public License, Version 2.0, the GNU
+    Lesser General Public License, Version 2.1, the GNU Affero General
+    Public License, Version 3.0, or any later versions of those
+    licenses.
+
+1.13. "Source Code Form"
+    means the form of the work preferred for making modifications.
+
+1.14. "You" (or "Your")
+    means an individual or a legal entity exercising rights under this
+    License. For legal entities, "You" includes any entity that
+    controls, is controlled by, or is under common control with You. For
+    purposes of this definition, "control" means (a) the power, direct
+    or indirect, to cause the direction or management of such entity,
+    whether by contract or otherwise, or (b) ownership of more than
+    fifty percent (50%) of the outstanding shares or beneficial
+    ownership of such entity.
+
+2. License Grants and Conditions
+--------------------------------
+
+2.1. Grants
+
+Each Contributor hereby grants You a world-wide, royalty-free,
+non-exclusive license:
+
+(a) under intellectual property rights (other than patent or trademark)
+    Licensable by such Contributor to use, reproduce, make available,
+    modify, display, perform, distribute, and otherwise exploit its
+    Contributions, either on an unmodified basis, with Modifications, or
+    as part of a Larger Work; and
+
+(b) under Patent Claims of such Contributor to make, use, sell, offer
+    for sale, have made, import, and otherwise transfer either its
+    Contributions or its Contributor Version.
+
+2.2. Effective Date
+
+The licenses granted in Section 2.1 with respect to any Contribution
+become effective for each Contribution on the date the Contributor first
+distributes such Contribution.
+
+2.3. Limitations on Grant Scope
+
+The licenses granted in this Section 2 are the only rights granted under
+this License. No additional rights or licenses will be implied from the
+distribution or licensing of Covered Software under this License.
+Notwithstanding Section 2.1(b) above, no patent license is granted by a
+Contributor:
+
+(a) for any code that a Contributor has removed from Covered Software;
+    or
+
+(b) for infringements caused by: (i) Your and any other third party's
+    modifications of Covered Software, or (ii) the combination of its
+    Contributions with other software (except as part of its Contributor
+    Version); or
+
+(c) under Patent Claims infringed by Covered Software in the absence of
+    its Contributions.
+
+This License does not grant any rights in the trademarks, service marks,
+or logos of any Contributor (except as may be necessary to comply with
+the notice requirements in Section 3.4).
+
+2.4. Subsequent Licenses
+
+No Contributor makes additional grants as a result of Your choice to
+distribute the Covered Software under a subsequent version of this
+License (see Section 10.2) or under the terms of a Secondary License (if
+permitted under the terms of Section 3.3).
+
+2.5. Representation
+
+Each Contributor represents that the Contributor believes its
+Contributions are its original creation(s) or it has sufficient rights
+to grant the rights to its Contributions conveyed by this License.
+
+2.6. Fair Use
+
+This License is not intended to limit any rights You have under
+applicable copyright doctrines of fair use, fair dealing, or other
+equivalents.
+
+2.7. Conditions
+
+Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
+in Section 2.1.
+
+3. Responsibilities
+-------------------
+
+3.1. Distribution of Source Form
+
+All distribution of Covered Software in Source Code Form, including any
+Modifications that You create or to which You contribute, must be under
+the terms of this License. You must inform recipients that the Source
+Code Form of the Covered Software is governed by the terms of this
+License, and how they can obtain a copy of this License. You may not
+attempt to alter or restrict the recipients' rights in the Source Code
+Form.
+
+3.2. Distribution of Executable Form
+
+If You distribute Covered Software in Executable Form then:
+
+(a) such Covered Software must also be made available in Source Code
+    Form, as described in Section 3.1, and You must inform recipients of
+    the Executable Form how they can obtain a copy of such Source Code
+    Form by reasonable means in a timely manner, at a charge no more
+    than the cost of distribution to the recipient; and
+
+(b) You may distribute such Executable Form under the terms of this
+    License, or sublicense it under different terms, provided that the
+    license for the Executable Form does not attempt to limit or alter
+    the recipients' rights in the Source Code Form under this License.
+
+3.3. Distribution of a Larger Work
+
+You may create and distribute a Larger Work under terms of Your choice,
+provided that You also comply with the requirements of this License for
+the Covered Software. If the Larger Work is a combination of Covered
+Software with a work governed by one or more Secondary Licenses, and the
+Covered Software is not Incompatible With Secondary Licenses, this
+License permits You to additionally distribute such Covered Software
+under the terms of such Secondary License(s), so that the recipient of
+the Larger Work may, at their option, further distribute the Covered
+Software under the terms of either this License or such Secondary
+License(s).
+
+3.4. Notices
+
+You may not remove or alter the substance of any license notices
+(including copyright notices, patent notices, disclaimers of warranty,
+or limitations of liability) contained within the Source Code Form of
+the Covered Software, except that You may alter any license notices to
+the extent required to remedy known factual inaccuracies.
+
+3.5. Application of Additional Terms
+
+You may choose to offer, and to charge a fee for, warranty, support,
+indemnity or liability obligations to one or more recipients of Covered
+Software. However, You may do so only on Your own behalf, and not on
+behalf of any Contributor. You must make it absolutely clear that any
+such warranty, support, indemnity, or liability obligation is offered by
+You alone, and You hereby agree to indemnify every Contributor for any
+liability incurred by such Contributor as a result of warranty, support,
+indemnity or liability terms You offer. You may include additional
+disclaimers of warranty and limitations of liability specific to any
+jurisdiction.
+
+4. Inability to Comply Due to Statute or Regulation
+---------------------------------------------------
+
+If it is impossible for You to comply with any of the terms of this
+License with respect to some or all of the Covered Software due to
+statute, judicial order, or regulation then You must: (a) comply with
+the terms of this License to the maximum extent possible; and (b)
+describe the limitations and the code they affect. Such description must
+be placed in a text file included with all distributions of the Covered
+Software under this License. Except to the extent prohibited by statute
+or regulation, such description must be sufficiently detailed for a
+recipient of ordinary skill to be able to understand it.
+
+5. Termination
+--------------
+
+5.1. The rights granted under this License will terminate automatically
+if You fail to comply with any of its terms. However, if You become
+compliant, then the rights granted under this License from a particular
+Contributor are reinstated (a) provisionally, unless and until such
+Contributor explicitly and finally terminates Your grants, and (b) on an
+ongoing basis, if such Contributor fails to notify You of the
+non-compliance by some reasonable means prior to 60 days after You have
+come back into compliance. Moreover, Your grants from a particular
+Contributor are reinstated on an ongoing basis if such Contributor
+notifies You of the non-compliance by some reasonable means, this is the
+first time You have received notice of non-compliance with this License
+from such Contributor, and You become compliant prior to 30 days after
+Your receipt of the notice.
+
+5.2. If You initiate litigation against any entity by asserting a patent
+infringement claim (excluding declaratory judgment actions,
+counter-claims, and cross-claims) alleging that a Contributor Version
+directly or indirectly infringes any patent, then the rights granted to
+You by any and all Contributors for the Covered Software under Section
+2.1 of this License shall terminate.
+
+5.3. In the event of termination under Sections 5.1 or 5.2 above, all
+end user license agreements (excluding distributors and resellers) which
+have been validly granted by You or Your distributors under this License
+prior to termination shall survive termination.
+
+************************************************************************
+*                                                                      *
+*  6. Disclaimer of Warranty                                           *
+*  -------------------------                                           *
+*                                                                      *
+*  Covered Software is provided under this License on an "as is"       *
+*  basis, without warranty of any kind, either expressed, implied, or  *
+*  statutory, including, without limitation, warranties that the       *
+*  Covered Software is free of defects, merchantable, fit for a        *
+*  particular purpose or non-infringing. The entire risk as to the     *
+*  quality and performance of the Covered Software is with You.        *
+*  Should any Covered Software prove defective in any respect, You     *
+*  (not any Contributor) assume the cost of any necessary servicing,   *
+*  repair, or correction. This disclaimer of warranty constitutes an   *
+*  essential part of this License. No use of any Covered Software is   *
+*  authorized under this License except under this disclaimer.         *
+*                                                                      *
+************************************************************************
+
+************************************************************************
+*                                                                      *
+*  7. Limitation of Liability                                          *
+*  --------------------------                                          *
+*                                                                      *
+*  Under no circumstances and under no legal theory, whether tort      *
+*  (including negligence), contract, or otherwise, shall any           *
+*  Contributor, or anyone who distributes Covered Software as          *
+*  permitted above, be liable to You for any direct, indirect,         *
+*  special, incidental, or consequential damages of any character      *
+*  including, without limitation, damages for lost profits, loss of    *
+*  goodwill, work stoppage, computer failure or malfunction, or any    *
+*  and all other commercial damages or losses, even if such party      *
+*  shall have been informed of the possibility of such damages. This   *
+*  limitation of liability shall not apply to liability for death or   *
+*  personal injury resulting from such party's negligence to the       *
+*  extent applicable law prohibits such limitation. Some               *
+*  jurisdictions do not allow the exclusion or limitation of           *
+*  incidental or consequential damages, so this exclusion and          *
+*  limitation may not apply to You.                                    *
+*                                                                      *
+************************************************************************
+
+8. Litigation
+-------------
+
+Any litigation relating to this License may be brought only in the
+courts of a jurisdiction where the defendant maintains its principal
+place of business and such litigation shall be governed by laws of that
+jurisdiction, without reference to its conflict-of-law provisions.
+Nothing in this Section shall prevent a party's ability to bring
+cross-claims or counter-claims.
+
+9. Miscellaneous
+----------------
+
+This License represents the complete agreement concerning the subject
+matter hereof. If any provision of this License is held to be
+unenforceable, such provision shall be reformed only to the extent
+necessary to make it enforceable. Any law or regulation which provides
+that the language of a contract shall be construed against the drafter
+shall not be used to construe this License against a Contributor.
+
+10. Versions of the License
+---------------------------
+
+10.1. New Versions
+
+Mozilla Foundation is the license steward. Except as provided in Section
+10.3, no one other than the license steward has the right to modify or
+publish new versions of this License. Each version will be given a
+distinguishing version number.
+
+10.2. Effect of New Versions
+
+You may distribute the Covered Software under the terms of the version
+of the License under which You originally received the Covered Software,
+or under the terms of any subsequent version published by the license
+steward.
+
+10.3. Modified Versions
+
+If you create software not governed by this License, and you want to
+create a new license for such software, you may create and use a
+modified version of this License if you rename the license and remove
+any references to the name of the license steward (except to note that
+such modified license differs from this License).
+
+10.4. Distributing Source Code Form that is Incompatible With Secondary
+Licenses
+
+If You choose to distribute Source Code Form that is Incompatible With
+Secondary Licenses under the terms of this version of the License, the
+notice described in Exhibit B of this License must be attached.
+
+Exhibit A - Source Code Form License Notice
+-------------------------------------------
+
+  This Source Code Form is subject to the terms of the Mozilla Public
+  License, v. 2.0. If a copy of the MPL was not distributed with this
+  file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+If it is not possible or desirable to put the notice in a particular
+file, then You may include the notice in a location (such as a LICENSE
+file in a relevant directory) where a recipient would be likely to look
+for such a notice.
+
+You may add additional accurate notices of copyright ownership.
+
+Exhibit B - "Incompatible With Secondary Licenses" Notice
+---------------------------------------------------------
+
+  This Source Code Form is "Incompatible With Secondary Licenses", as
+  defined by the Mozilla Public License, v. 2.0.
diff --git a/Makefile.in b/Makefile.in
new file mode 100644
index 0000000..dfb06f9
--- /dev/null
+++ b/Makefile.in
@@ -0,0 +1,118 @@
+#! gmake
+
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+MOD_DEPTH	= .
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+
+include $(MOD_DEPTH)/config/autoconf.mk
+
+DIRS = config pr lib
+
+ifdef MOZILLA_CLIENT
+# Make nsinstall use absolute symlinks by default for Mozilla OSX builds
+# http://bugzilla.mozilla.org/show_bug.cgi?id=193164
+ifeq ($(OS_ARCH),Darwin)
+ifndef NSDISTMODE
+NSDISTMODE=absolute_symlink
+export NSDISTMODE
+endif
+endif
+endif
+
+DIST_GARBAGE = config.cache config.log config.status
+
+all:: config.status export
+
+include $(topsrcdir)/config/rules.mk
+
+config.status:: configure
+ifeq ($(OS_ARCH),WINNT)
+	sh $(srcdir)/configure --no-create --no-recursion
+else
+	./config.status --recheck && ./config.status
+endif
+
+#
+# The -ll option of zip converts CR LF to LF.
+#
+ifeq ($(OS_ARCH),WINNT)
+ZIP_ASCII_OPT = -ll
+endif
+
+# Delete config/autoconf.mk last because it is included by every makefile.
+distclean::
+	@echo "cd pr/tests; $(MAKE) $@"
+	@$(MAKE) -C pr/tests $@
+	rm -f config/autoconf.mk
+	rm -f `cat unallmakefiles` unallmakefiles
+
+release::
+	echo $(BUILD_NUMBER) > $(RELEASE_DIR)/$(BUILD_NUMBER)/version.df
+	@if test -f imports.df; then \
+	    echo "cp -f imports.df $(RELEASE_DIR)/$(BUILD_NUMBER)/imports.df"; \
+	    cp -f imports.df $(RELEASE_DIR)/$(BUILD_NUMBER)/imports.df; \
+	else \
+	    echo "echo > $(RELEASE_DIR)/$(BUILD_NUMBER)/imports.df"; \
+	    echo > $(RELEASE_DIR)/$(BUILD_NUMBER)/imports.df; \
+	fi
+	cd $(RELEASE_DIR)/$(BUILD_NUMBER)/$(OBJDIR_NAME); \
+	rm -rf META-INF; mkdir META-INF; cd META-INF; \
+	echo "Manifest-Version: 1.0" > MANIFEST.MF; \
+	echo "" >> MANIFEST.MF; \
+	cd ..; rm -f mdbinary.jar; zip -r mdbinary.jar META-INF bin lib; \
+	rm -rf META-INF; \
+	cd include; \
+	rm -rf META-INF; mkdir META-INF; cd META-INF; \
+	echo "Manifest-Version: 1.0" > MANIFEST.MF; \
+	echo "" >> MANIFEST.MF; \
+	cd ..; rm -f mdheader.jar; zip $(ZIP_ASCII_OPT) -r mdheader.jar *; \
+	rm -rf META-INF
+ifeq ($(OS_ARCH),WINNT)
+	@if test ! -d $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER); then \
+		rm -rf $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER); \
+		echo "making directory $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER)"; \
+		mkdir -p $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER); \
+	fi
+	@if test ! -d $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER)/$(RELEASE_OBJDIR_NAME); then \
+		rm -rf $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER)/$(RELEASE_OBJDIR_NAME); \
+		echo "making directory $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER)/$(RELEASE_OBJDIR_NAME)"; \
+		mkdir -p $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER)/$(RELEASE_OBJDIR_NAME); \
+	fi
+else
+	@if test ! -d $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER); then \
+		rm -rf $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER); \
+		echo "making directory $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER)"; \
+		$(NSINSTALL) -D $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER); \
+		chmod 775 $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER); \
+	fi
+	@if test ! -d $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER)/$(RELEASE_OBJDIR_NAME); then \
+		rm -rf $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER)/$(RELEASE_OBJDIR_NAME); \
+		echo "making directory $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER)/$(RELEASE_OBJDIR_NAME)"; \
+		$(NSINSTALL) -D $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER)/$(RELEASE_OBJDIR_NAME); \
+		chmod 775 $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER)/$(RELEASE_OBJDIR_NAME); \
+	fi
+endif
+	cd $(RELEASE_DIR)/$(BUILD_NUMBER); \
+	cp -f version.df imports.df $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER); \
+	chmod 664 $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER)/version.df; \
+	chmod 664 $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER)/imports.df; \
+	cd $(OBJDIR_NAME); \
+	cp -f mdbinary.jar $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER)/$(RELEASE_OBJDIR_NAME); \
+	chmod 664 $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER)/$(RELEASE_OBJDIR_NAME)/mdbinary.jar; \
+	cd include; \
+	cp -f mdheader.jar $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER)/$(RELEASE_OBJDIR_NAME); \
+	chmod 664 $(MDIST)/$(MOD_NAME)/$(BUILD_NUMBER)/$(RELEASE_OBJDIR_NAME)/mdheader.jar
+
+package:
+	@echo "cd pkg; $(MAKE) publish"
+	$(MAKE) -C pkg publish
+
+depend:
+	@echo "NSPR20 has no dependencies.  Skipped."
diff --git a/README.google b/README.google
new file mode 100644
index 0000000..c94e3f8
--- /dev/null
+++ b/README.google
@@ -0,0 +1,10 @@
+URL:		https://ftp.mozilla.org/pub/nspr/releases/v4.13.1/src/nspr-4.13.1.tar.gz
+Version:	4.13.1
+License:	Mozilla Public License v2.0
+License File:	LICENSE
+
+Description:
+"Netscape Portable Runtime (NSPR) provides a platform-neutral API for system level and libc-like functions."
+
+Local Modifications:
+None
diff --git a/admin/explode.pl b/admin/explode.pl
new file mode 100644
index 0000000..4869597
--- /dev/null
+++ b/admin/explode.pl
@@ -0,0 +1,43 @@
+#!/bin/perl
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# -----------------------------------------------------------------
+#
+# explode.pl -- Unpack .jar files into bin, lib, include directories
+#
+# syntax: perl explode.pl
+#
+# Description:
+# explode.pl unpacks the .jar files created by the NSPR build   
+# procedure. 
+#
+# Suggested use: After copying the platform directories to
+# /s/b/c/nspr20/<release>. CD to /s/b/c/nspr20/<release> and
+# run explode.pl. This will unpack the jar files into bin, lib,
+# include directories.
+#
+# -----------------------------------------------------------------
+
+@dirs = `ls -d *.OBJ*`;
+
+foreach $dir (@dirs) {
+    chop($dir);
+    if (-l $dir) {
+        print "Skipping symbolic link $dir\n";
+        next;
+    }
+    print "Unzipping $dir/mdbinary.jar\n";
+    system ("unzip", "-o", "$dir/mdbinary.jar",
+            "-d", "$dir");
+    system ("rm", "-rf", "$dir/META-INF");
+    mkdir "$dir/include", 0755;
+    print "Unzipping $dir/mdheader.jar\n";
+    system ("unzip", "-o", "-aa",
+            "$dir/mdheader.jar",
+            "-d", "$dir/include");
+    system ("rm", "-rf", "$dir/include/META-INF");
+}
+# --- end explode.pl ----------------------------------------------
diff --git a/admin/makeTargetDirs.sh b/admin/makeTargetDirs.sh
new file mode 100644
index 0000000..46ad894
--- /dev/null
+++ b/admin/makeTargetDirs.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# -----------------------------------------------------------------
+# makeTargetDirs.sh -- Create target directories for building NSPR
+#
+# syntax: makeTargetDirs.sh
+#
+# Description:
+# makeTargetDirs.sh creates a set of directories intended for use
+# with NSPR's autoconf based build system.
+#     
+# The enumerated directories are the same as those built for NSPR
+# 4.1.1. Adjust as needed.
+#
+# -----------------------------------------------------------------
+
+mkdir  AIX4.3_64_DBG.OBJ
+mkdir  AIX4.3_64_OPT.OBJ
+mkdir  AIX4.3_DBG.OBJ
+mkdir  AIX4.3_OPT.OBJ
+mkdir  HP-UXB.11.00_64_DBG.OBJ
+mkdir  HP-UXB.11.00_64_OPT.OBJ
+mkdir  HP-UXB.11.00_DBG.OBJ
+mkdir  HP-UXB.11.00_OPT.OBJ
+mkdir  IRIX6.5_n32_PTH_DBG.OBJ
+mkdir  IRIX6.5_n32_PTH_OPT.OBJ
+mkdir  Linux2.2_x86_glibc_PTH_DBG.OBJ
+mkdir  Linux2.2_x86_glibc_PTH_OPT.OBJ
+mkdir  Linux2.4_x86_glibc_PTH_DBG.OBJ
+mkdir  Linux2.4_x86_glibc_PTH_OPT.OBJ
+mkdir  OSF1V4.0D_DBG.OBJ
+mkdir  OSF1V4.0D_OPT.OBJ
+mkdir  SunOS5.6_DBG.OBJ
+mkdir  SunOS5.6_OPT.OBJ
+mkdir  SunOS5.7_64_DBG.OBJ
+mkdir  SunOS5.7_64_OPT.OBJ
+mkdir  WIN954.0_DBG.OBJ
+mkdir  WIN954.0_DBG.OBJD
+mkdir  WIN954.0_OPT.OBJ
+mkdir  WINNT4.0_DBG.OBJ
+mkdir  WINNT4.0_DBG.OBJD
+mkdir  WINNT4.0_OPT.OBJ
+# --- end makeTargetDirs.sh ---------------------------------------
diff --git a/admin/symlinks.sh b/admin/symlinks.sh
new file mode 100644
index 0000000..8cd6a80
--- /dev/null
+++ b/admin/symlinks.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# -----------------------------------------------------------------
+# symlinks.sh -- create links from NSPR builds
+#
+# syntax: symlinks.sh
+# 
+# Description:
+# symlinks.sh creates some symbolic links for NSPR build targets
+# that are not actually build, but for which there are NSPR
+# binaries suitable for running on the intended target. ... got
+# that?
+# 
+# Suggested use: After copying NSPR binaries to
+# /s/b/c/nspr20/<platform> run symlinks.sh to create the links
+# for all supported platforms.
+#
+# The symlinks in this script correspond to the NSPR 4.1.1
+# release. Adjust as necessary.
+#
+# -----------------------------------------------------------------
+
+ln -s SunOS5.6_DBG.OBJ SunOS5.7_DBG.OBJ
+ln -s SunOS5.6_OPT.OBJ SunOS5.7_OPT.OBJ
+
+ln -s SunOS5.6_DBG.OBJ SunOS5.8_DBG.OBJ
+ln -s SunOS5.6_OPT.OBJ SunOS5.8_OPT.OBJ
+
+ln -s SunOS5.7_64_DBG.OBJ SunOS5.8_64_DBG.OBJ
+ln -s SunOS5.7_64_OPT.OBJ SunOS5.8_64_OPT.OBJ
+
+ln -s OSF1V4.0D_DBG.OBJ OSF1V5.0_DBG.OBJ
+ln -s OSF1V4.0D_OPT.OBJ OSF1V5.0_OPT.OBJ
+
+ln -s WINNT4.0_DBG.OBJ WINNT5.0_DBG.OBJ
+ln -s WINNT4.0_DBG.OBJD WINNT5.0_DBG.OBJD
+ln -s WINNT4.0_OPT.OBJ WINNT5.0_OPT.OBJ
+# --- end symlinks.sh ---------------------------------------------
+
diff --git a/automation/release/nspr-release-helper.py b/automation/release/nspr-release-helper.py
new file mode 100644
index 0000000..f526618
--- /dev/null
+++ b/automation/release/nspr-release-helper.py
@@ -0,0 +1,179 @@
+#!/usr/bin/python
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+import os
+import sys
+import datetime
+import shutil
+import glob
+from optparse import OptionParser
+from subprocess import check_call
+
+prinit_h = "pr/include/prinit.h"
+f_conf = "configure"
+f_conf_in = "configure.in"
+
+def check_call_noisy(cmd, *args, **kwargs):
+    print "Executing command:", cmd
+    check_call(cmd, *args, **kwargs)
+
+o = OptionParser(usage="client.py [options] remove_beta | set_beta | print_library_versions | set_version_to_minor_release | set_version_to_patch_release | create_nspr_release_archive")
+
+try:
+    options, args = o.parse_args()
+    action = args[0]
+except IndexError:
+    o.print_help()
+    sys.exit(2)
+
+def exit_with_failure(what):
+    print "failure: ", what
+    sys.exit(2)
+
+def check_files_exist():
+    if (not os.path.exists(prinit_h)):
+        exit_with_failure("cannot find expected header files, must run from inside NSPR hg directory")
+
+def sed_inplace(sed_expression, filename):
+    backup_file = filename + '.tmp'
+    check_call_noisy(["sed", "-i.tmp", sed_expression, filename])
+    os.remove(backup_file)
+
+def toggle_beta_status(is_beta):
+    check_files_exist()
+    if (is_beta):
+        print "adding Beta status to version numbers"
+        sed_inplace('s/^\(#define *PR_VERSION *\"[0-9.]\+\)\" *$/\\1 Beta\"/', prinit_h)
+        sed_inplace('s/^\(#define *PR_BETA *\)PR_FALSE *$/\\1PR_TRUE/', prinit_h)
+
+    else:
+        print "removing Beta status from version numbers"
+        sed_inplace('s/^\(#define *PR_VERSION *\"[0-9.]\+\) *Beta\" *$/\\1\"/', prinit_h)
+        sed_inplace('s/^\(#define *PR_BETA *\)PR_TRUE *$/\\1PR_FALSE/', prinit_h)
+    print "please run 'hg stat' and 'hg diff' to verify the files have been verified correctly"
+
+def print_beta_versions():
+    check_call_noisy(["egrep", "#define *PR_VERSION|#define *PR_BETA", prinit_h])
+
+def remove_beta_status():
+    print "--- removing beta flags. Existing versions were:"
+    print_beta_versions()
+    toggle_beta_status(False)
+    print "--- finished modifications, new versions are:"
+    print_beta_versions()
+
+def set_beta_status():
+    print "--- adding beta flags. Existing versions were:"
+    print_beta_versions()
+    toggle_beta_status(True)
+    print "--- finished modifications, new versions are:"
+    print_beta_versions()
+
+def print_library_versions():
+    check_files_exist()
+    check_call_noisy(["egrep", "#define *PR_VERSION|#define PR_VMAJOR|#define *PR_VMINOR|#define *PR_VPATCH|#define *PR_BETA", prinit_h])
+
+def ensure_arguments_after_action(how_many, usage):
+    if (len(sys.argv) != (2+how_many)):
+        exit_with_failure("incorrect number of arguments, expected parameters are:\n" + usage)
+
+def set_major_versions(major):
+    sed_inplace('s/^\(#define *PR_VMAJOR *\).*$/\\1' + major + '/', prinit_h)
+    sed_inplace('s/^MOD_MAJOR_VERSION=.*$/MOD_MAJOR_VERSION=' + major + '/', f_conf)
+    sed_inplace('s/^MOD_MAJOR_VERSION=.*$/MOD_MAJOR_VERSION=' + major + '/', f_conf_in)
+
+def set_minor_versions(minor):
+    sed_inplace('s/^\(#define *PR_VMINOR *\).*$/\\1' + minor + '/', prinit_h)
+    sed_inplace('s/^MOD_MINOR_VERSION=.*$/MOD_MINOR_VERSION=' + minor + '/', f_conf)
+    sed_inplace('s/^MOD_MINOR_VERSION=.*$/MOD_MINOR_VERSION=' + minor + '/', f_conf_in)
+
+def set_patch_versions(patch):
+    sed_inplace('s/^\(#define *PR_VPATCH *\).*$/\\1' + patch + '/', prinit_h)
+    sed_inplace('s/^MOD_PATCH_VERSION=.*$/MOD_PATCH_VERSION=' + patch + '/', f_conf)
+    sed_inplace('s/^MOD_PATCH_VERSION=.*$/MOD_PATCH_VERSION=' + patch + '/', f_conf_in)
+
+def set_full_lib_versions(version):
+    sed_inplace('s/^\(#define *PR_VERSION *\"\)\([0-9.]\+\)\(.*\)$/\\1' + version + '\\3/', prinit_h)
+
+def set_all_lib_versions(version, major, minor, patch):
+    set_full_lib_versions(version)
+    set_major_versions(major)
+    set_minor_versions(minor)
+    set_patch_versions(patch)
+    print
+    print "==========================="
+    print "======== ATTENTION ========"
+    print
+    print "You *MUST* manually edit file pr/tests/vercheck.c"
+    print
+    print "Edit two arrays, named compatible_version and incompatible_version"
+    print "according to the new version you're adding."
+    print
+    print "======== ATTENTION ========"
+    print "==========================="
+
+def set_version_to_minor_release():
+    ensure_arguments_after_action(2, "major_version  minor_version")
+    major = args[1].strip()
+    minor = args[2].strip()
+    version = major + '.' + minor
+    patch = "0"
+    set_all_lib_versions(version, major, minor, patch)
+
+def set_version_to_patch_release():
+    ensure_arguments_after_action(3, "major_version  minor_version  patch_release")
+    major = args[1].strip()
+    minor = args[2].strip()
+    patch = args[3].strip()
+    version = major + '.' + minor + '.' + patch
+    set_all_lib_versions(version, major, minor, patch)
+
+def create_nspr_release_archive():
+    ensure_arguments_after_action(2, "nspr_release_version  nspr_hg_release_tag")
+    nsprrel = args[1].strip() #e.g. 4.10.9
+    nsprreltag = args[2].strip() #e.g. NSPR_4_10_9_RTM
+
+    nspr_tar = "nspr-" + nsprrel + ".tar.gz"
+    nspr_stagedir="../stage/v" + nsprrel + "/src"
+    if (os.path.exists(nspr_stagedir)):
+        exit_with_failure("nspr stage directory already exists: " + nspr_stagedir)
+
+    check_call_noisy(["mkdir", "-p", nspr_stagedir])
+    check_call_noisy(["hg", "archive", "-r", nsprreltag, "--prefix=nspr-" + nsprrel + "/nspr",
+                      "../stage/v" + nsprrel + "/src/" + nspr_tar, "-X", ".hgtags"])
+    print "changing to directory " + nspr_stagedir
+    os.chdir(nspr_stagedir)
+
+    check_call("sha1sum " + nspr_tar + " > SHA1SUMS", shell=True)
+    check_call("sha256sum " + nspr_tar + " > SHA256SUMS", shell=True)
+    print "created directory " + nspr_stagedir + " with files:"
+    check_call_noisy(["ls", "-l"])
+
+if action in ('remove_beta'):
+    remove_beta_status()
+
+elif action in ('set_beta'):
+    set_beta_status()
+
+elif action in ('print_library_versions'):
+    print_library_versions()
+
+# x.y version number - 2 parameters
+elif action in ('set_version_to_minor_release'):
+    set_version_to_minor_release()
+
+# x.y.z version number - 3 parameters
+elif action in ('set_version_to_patch_release'):
+    set_version_to_patch_release()
+
+elif action in ('create_nspr_release_archive'):
+    create_nspr_release_archive()
+
+else:
+    o.print_help()
+    sys.exit(2)
+
+sys.exit(0)
diff --git a/build/autoconf/README b/build/autoconf/README
new file mode 100644
index 0000000..62c1f0c
--- /dev/null
+++ b/build/autoconf/README
@@ -0,0 +1,5 @@
+The config.guess and config.sub scripts were downloaded from
+http://git.savannah.gnu.org/cgit/config.git/tree/config.guess?id=6947a35648e577c2e3a12d5c88d488c6ea94e1c0
+http://git.savannah.gnu.org/cgit/config.git/tree/config.sub?id=6947a35648e577c2e3a12d5c88d488c6ea94e1c0
+
+Our private patches are in the patches/ directory.
diff --git a/build/autoconf/config.guess b/build/autoconf/config.guess
new file mode 100755
index 0000000..72625d4
--- /dev/null
+++ b/build/autoconf/config.guess
@@ -0,0 +1,1420 @@
+#! /bin/sh
+# Attempt to guess a canonical system name.
+#   Copyright 1992-2014 Free Software Foundation, Inc.
+
+timestamp='2014-02-12'
+
+# This file is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, see <http://www.gnu.org/licenses/>.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that
+# program.  This Exception is an additional permission under section 7
+# of the GNU General Public License, version 3 ("GPLv3").
+#
+# Originally written by Per Bothner.
+#
+# You can get the latest version of this script from:
+# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
+#
+# Please send patches with a ChangeLog entry to config-patches@gnu.org.
+
+
+me=`echo "$0" | sed -e 's,.*/,,'`
+
+usage="\
+Usage: $0 [OPTION]
+
+Output the configuration name of the system \`$me' is run on.
+
+Operation modes:
+  -h, --help         print this help, then exit
+  -t, --time-stamp   print date of last modification, then exit
+  -v, --version      print version number, then exit
+
+Report bugs and patches to <config-patches@gnu.org>."
+
+version="\
+GNU config.guess ($timestamp)
+
+Originally written by Per Bothner.
+Copyright 1992-2014 Free Software Foundation, Inc.
+
+This is free software; see the source for copying conditions.  There is NO
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
+
+help="
+Try \`$me --help' for more information."
+
+# Parse command line
+while test $# -gt 0 ; do
+  case $1 in
+    --time-stamp | --time* | -t )
+       echo "$timestamp" ; exit ;;
+    --version | -v )
+       echo "$version" ; exit ;;
+    --help | --h* | -h )
+       echo "$usage"; exit ;;
+    -- )     # Stop option processing
+       shift; break ;;
+    - )	# Use stdin as input.
+       break ;;
+    -* )
+       echo "$me: invalid option $1$help" >&2
+       exit 1 ;;
+    * )
+       break ;;
+  esac
+done
+
+if test $# != 0; then
+  echo "$me: too many arguments$help" >&2
+  exit 1
+fi
+
+trap 'exit 1' 1 2 15
+
+# CC_FOR_BUILD -- compiler used by this script. Note that the use of a
+# compiler to aid in system detection is discouraged as it requires
+# temporary files to be created and, as you can see below, it is a
+# headache to deal with in a portable fashion.
+
+# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still
+# use `HOST_CC' if defined, but it is deprecated.
+
+# Portable tmp directory creation inspired by the Autoconf team.
+
+set_cc_for_build='
+trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
+trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ;
+: ${TMPDIR=/tmp} ;
+ { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
+ { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||
+ { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } ||
+ { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
+dummy=$tmp/dummy ;
+tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ;
+case $CC_FOR_BUILD,$HOST_CC,$CC in
+ ,,)    echo "int x;" > $dummy.c ;
+	for c in cc gcc c89 c99 ; do
+	  if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then
+	     CC_FOR_BUILD="$c"; break ;
+	  fi ;
+	done ;
+	if test x"$CC_FOR_BUILD" = x ; then
+	  CC_FOR_BUILD=no_compiler_found ;
+	fi
+	;;
+ ,,*)   CC_FOR_BUILD=$CC ;;
+ ,*,*)  CC_FOR_BUILD=$HOST_CC ;;
+esac ; set_cc_for_build= ;'
+
+# This is needed to find uname on a Pyramid OSx when run in the BSD universe.
+# (ghazi@noc.rutgers.edu 1994-08-24)
+if (test -f /.attbin/uname) >/dev/null 2>&1 ; then
+	PATH=$PATH:/.attbin ; export PATH
+fi
+
+UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
+UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
+UNAME_SYSTEM=`(uname -s) 2>/dev/null`  || UNAME_SYSTEM=unknown
+UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
+
+case "${UNAME_SYSTEM}" in
+Linux|GNU|GNU/*)
+	# If the system lacks a compiler, then just pick glibc.
+	# We could probably try harder.
+	LIBC=gnu
+
+	eval $set_cc_for_build
+	cat <<-EOF > $dummy.c
+	#include <features.h>
+	#if defined(__UCLIBC__)
+	LIBC=uclibc
+	#elif defined(__dietlibc__)
+	LIBC=dietlibc
+	#else
+	LIBC=gnu
+	#endif
+	EOF
+	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC' | sed 's, ,,g'`
+	;;
+esac
+
+# Note: order is significant - the case branches are not exclusive.
+
+case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
+    *:NetBSD:*:*)
+	# NetBSD (nbsd) targets should (where applicable) match one or
+	# more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*,
+	# *-*-netbsdecoff* and *-*-netbsd*.  For targets that recently
+	# switched to ELF, *-*-netbsd* would select the old
+	# object file format.  This provides both forward
+	# compatibility and a consistent mechanism for selecting the
+	# object file format.
+	#
+	# Note: NetBSD doesn't particularly care about the vendor
+	# portion of the name.  We always set it to "unknown".
+	sysctl="sysctl -n hw.machine_arch"
+	UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \
+	    /usr/sbin/$sysctl 2>/dev/null || echo unknown)`
+	case "${UNAME_MACHINE_ARCH}" in
+	    armeb) machine=armeb-unknown ;;
+	    arm*) machine=arm-unknown ;;
+	    sh3el) machine=shl-unknown ;;
+	    sh3eb) machine=sh-unknown ;;
+	    sh5el) machine=sh5le-unknown ;;
+	    *) machine=${UNAME_MACHINE_ARCH}-unknown ;;
+	esac
+	# The Operating System including object format, if it has switched
+	# to ELF recently, or will in the future.
+	case "${UNAME_MACHINE_ARCH}" in
+	    arm*|i386|m68k|ns32k|sh3*|sparc|vax)
+		eval $set_cc_for_build
+		if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
+			| grep -q __ELF__
+		then
+		    # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout).
+		    # Return netbsd for either.  FIX?
+		    os=netbsd
+		else
+		    os=netbsdelf
+		fi
+		;;
+	    *)
+		os=netbsd
+		;;
+	esac
+	# The OS release
+	# Debian GNU/NetBSD machines have a different userland, and
+	# thus, need a distinct triplet. However, they do not need
+	# kernel version information, so it can be replaced with a
+	# suitable tag, in the style of linux-gnu.
+	case "${UNAME_VERSION}" in
+	    Debian*)
+		release='-gnu'
+		;;
+	    *)
+		release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
+		;;
+	esac
+	# Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM:
+	# contains redundant information, the shorter form:
+	# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
+	echo "${machine}-${os}${release}"
+	exit ;;
+    *:Bitrig:*:*)
+	UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'`
+	echo ${UNAME_MACHINE_ARCH}-unknown-bitrig${UNAME_RELEASE}
+	exit ;;
+    *:OpenBSD:*:*)
+	UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'`
+	echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE}
+	exit ;;
+    *:ekkoBSD:*:*)
+	echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE}
+	exit ;;
+    *:SolidBSD:*:*)
+	echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE}
+	exit ;;
+    macppc:MirBSD:*:*)
+	echo powerpc-unknown-mirbsd${UNAME_RELEASE}
+	exit ;;
+    *:MirBSD:*:*)
+	echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE}
+	exit ;;
+    alpha:OSF1:*:*)
+	case $UNAME_RELEASE in
+	*4.0)
+		UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
+		;;
+	*5.*)
+		UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
+		;;
+	esac
+	# According to Compaq, /usr/sbin/psrinfo has been available on
+	# OSF/1 and Tru64 systems produced since 1995.  I hope that
+	# covers most systems running today.  This code pipes the CPU
+	# types through head -n 1, so we only detect the type of CPU 0.
+	ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^  The alpha \(.*\) processor.*$/\1/p' | head -n 1`
+	case "$ALPHA_CPU_TYPE" in
+	    "EV4 (21064)")
+		UNAME_MACHINE="alpha" ;;
+	    "EV4.5 (21064)")
+		UNAME_MACHINE="alpha" ;;
+	    "LCA4 (21066/21068)")
+		UNAME_MACHINE="alpha" ;;
+	    "EV5 (21164)")
+		UNAME_MACHINE="alphaev5" ;;
+	    "EV5.6 (21164A)")
+		UNAME_MACHINE="alphaev56" ;;
+	    "EV5.6 (21164PC)")
+		UNAME_MACHINE="alphapca56" ;;
+	    "EV5.7 (21164PC)")
+		UNAME_MACHINE="alphapca57" ;;
+	    "EV6 (21264)")
+		UNAME_MACHINE="alphaev6" ;;
+	    "EV6.7 (21264A)")
+		UNAME_MACHINE="alphaev67" ;;
+	    "EV6.8CB (21264C)")
+		UNAME_MACHINE="alphaev68" ;;
+	    "EV6.8AL (21264B)")
+		UNAME_MACHINE="alphaev68" ;;
+	    "EV6.8CX (21264D)")
+		UNAME_MACHINE="alphaev68" ;;
+	    "EV6.9A (21264/EV69A)")
+		UNAME_MACHINE="alphaev69" ;;
+	    "EV7 (21364)")
+		UNAME_MACHINE="alphaev7" ;;
+	    "EV7.9 (21364A)")
+		UNAME_MACHINE="alphaev79" ;;
+	esac
+	# A Pn.n version is a patched version.
+	# A Vn.n version is a released version.
+	# A Tn.n version is a released field test version.
+	# A Xn.n version is an unreleased experimental baselevel.
+	# 1.2 uses "1.2" for uname -r.
+	echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
+	# Reset EXIT trap before exiting to avoid spurious non-zero exit code.
+	exitcode=$?
+	trap '' 0
+	exit $exitcode ;;
+    Alpha\ *:Windows_NT*:*)
+	# How do we know it's Interix rather than the generic POSIX subsystem?
+	# Should we change UNAME_MACHINE based on the output of uname instead
+	# of the specific Alpha model?
+	echo alpha-pc-interix
+	exit ;;
+    21064:Windows_NT:50:3)
+	echo alpha-dec-winnt3.5
+	exit ;;
+    Amiga*:UNIX_System_V:4.0:*)
+	echo m68k-unknown-sysv4
+	exit ;;
+    *:[Aa]miga[Oo][Ss]:*:*)
+	echo ${UNAME_MACHINE}-unknown-amigaos
+	exit ;;
+    *:[Mm]orph[Oo][Ss]:*:*)
+	echo ${UNAME_MACHINE}-unknown-morphos
+	exit ;;
+    *:OS/390:*:*)
+	echo i370-ibm-openedition
+	exit ;;
+    *:z/VM:*:*)
+	echo s390-ibm-zvmoe
+	exit ;;
+    *:OS400:*:*)
+	echo powerpc-ibm-os400
+	exit ;;
+    arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
+	echo arm-acorn-riscix${UNAME_RELEASE}
+	exit ;;
+    arm*:riscos:*:*|arm*:RISCOS:*:*)
+	echo arm-unknown-riscos
+	exit ;;
+    SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*)
+	echo hppa1.1-hitachi-hiuxmpp
+	exit ;;
+    Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*)
+	# akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE.
+	if test "`(/bin/universe) 2>/dev/null`" = att ; then
+		echo pyramid-pyramid-sysv3
+	else
+		echo pyramid-pyramid-bsd
+	fi
+	exit ;;
+    NILE*:*:*:dcosx)
+	echo pyramid-pyramid-svr4
+	exit ;;
+    DRS?6000:unix:4.0:6*)
+	echo sparc-icl-nx6
+	exit ;;
+    DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*)
+	case `/usr/bin/uname -p` in
+	    sparc) echo sparc-icl-nx7; exit ;;
+	esac ;;
+    s390x:SunOS:*:*)
+	echo ${UNAME_MACHINE}-ibm-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit ;;
+    sun4H:SunOS:5.*:*)
+	echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit ;;
+    sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)
+	echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit ;;
+    i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*)
+	echo i386-pc-auroraux${UNAME_RELEASE}
+	exit ;;
+    i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*)
+	eval $set_cc_for_build
+	SUN_ARCH="i386"
+	# If there is a compiler, see if it is configured for 64-bit objects.
+	# Note that the Sun cc does not turn __LP64__ into 1 like gcc does.
+	# This test works for both compilers.
+	if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
+	    if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \
+		(CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
+		grep IS_64BIT_ARCH >/dev/null
+	    then
+		SUN_ARCH="x86_64"
+	    fi
+	fi
+	echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit ;;
+    sun4*:SunOS:6*:*)
+	# According to config.sub, this is the proper way to canonicalize
+	# SunOS6.  Hard to guess exactly what SunOS6 will be like, but
+	# it's likely to be more like Solaris than SunOS4.
+	echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit ;;
+    sun4*:SunOS:*:*)
+	case "`/usr/bin/arch -k`" in
+	    Series*|S4*)
+		UNAME_RELEASE=`uname -v`
+		;;
+	esac
+	# Japanese Language versions have a version number like `4.1.3-JL'.
+	echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'`
+	exit ;;
+    sun3*:SunOS:*:*)
+	echo m68k-sun-sunos${UNAME_RELEASE}
+	exit ;;
+    sun*:*:4.2BSD:*)
+	UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
+	test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3
+	case "`/bin/arch`" in
+	    sun3)
+		echo m68k-sun-sunos${UNAME_RELEASE}
+		;;
+	    sun4)
+		echo sparc-sun-sunos${UNAME_RELEASE}
+		;;
+	esac
+	exit ;;
+    aushp:SunOS:*:*)
+	echo sparc-auspex-sunos${UNAME_RELEASE}
+	exit ;;
+    # The situation for MiNT is a little confusing.  The machine name
+    # can be virtually everything (everything which is not
+    # "atarist" or "atariste" at least should have a processor
+    # > m68000).  The system name ranges from "MiNT" over "FreeMiNT"
+    # to the lowercase version "mint" (or "freemint").  Finally
+    # the system name "TOS" denotes a system which is actually not
+    # MiNT.  But MiNT is downward compatible to TOS, so this should
+    # be no problem.
+    atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*)
+	echo m68k-atari-mint${UNAME_RELEASE}
+	exit ;;
+    atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)
+	echo m68k-atari-mint${UNAME_RELEASE}
+	exit ;;
+    *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)
+	echo m68k-atari-mint${UNAME_RELEASE}
+	exit ;;
+    milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)
+	echo m68k-milan-mint${UNAME_RELEASE}
+	exit ;;
+    hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)
+	echo m68k-hades-mint${UNAME_RELEASE}
+	exit ;;
+    *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
+	echo m68k-unknown-mint${UNAME_RELEASE}
+	exit ;;
+    m68k:machten:*:*)
+	echo m68k-apple-machten${UNAME_RELEASE}
+	exit ;;
+    powerpc:machten:*:*)
+	echo powerpc-apple-machten${UNAME_RELEASE}
+	exit ;;
+    RISC*:Mach:*:*)
+	echo mips-dec-mach_bsd4.3
+	exit ;;
+    RISC*:ULTRIX:*:*)
+	echo mips-dec-ultrix${UNAME_RELEASE}
+	exit ;;
+    VAX*:ULTRIX*:*:*)
+	echo vax-dec-ultrix${UNAME_RELEASE}
+	exit ;;
+    2020:CLIX:*:* | 2430:CLIX:*:*)
+	echo clipper-intergraph-clix${UNAME_RELEASE}
+	exit ;;
+    mips:*:*:UMIPS | mips:*:*:RISCos)
+	eval $set_cc_for_build
+	sed 's/^	//' << EOF >$dummy.c
+#ifdef __cplusplus
+#include <stdio.h>  /* for printf() prototype */
+	int main (int argc, char *argv[]) {
+#else
+	int main (argc, argv) int argc; char *argv[]; {
+#endif
+	#if defined (host_mips) && defined (MIPSEB)
+	#if defined (SYSTYPE_SYSV)
+	  printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0);
+	#endif
+	#if defined (SYSTYPE_SVR4)
+	  printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0);
+	#endif
+	#if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD)
+	  printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0);
+	#endif
+	#endif
+	  exit (-1);
+	}
+EOF
+	$CC_FOR_BUILD -o $dummy $dummy.c &&
+	  dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` &&
+	  SYSTEM_NAME=`$dummy $dummyarg` &&
+	    { echo "$SYSTEM_NAME"; exit; }
+	echo mips-mips-riscos${UNAME_RELEASE}
+	exit ;;
+    Motorola:PowerMAX_OS:*:*)
+	echo powerpc-motorola-powermax
+	exit ;;
+    Motorola:*:4.3:PL8-*)
+	echo powerpc-harris-powermax
+	exit ;;
+    Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*)
+	echo powerpc-harris-powermax
+	exit ;;
+    Night_Hawk:Power_UNIX:*:*)
+	echo powerpc-harris-powerunix
+	exit ;;
+    m88k:CX/UX:7*:*)
+	echo m88k-harris-cxux7
+	exit ;;
+    m88k:*:4*:R4*)
+	echo m88k-motorola-sysv4
+	exit ;;
+    m88k:*:3*:R3*)
+	echo m88k-motorola-sysv3
+	exit ;;
+    AViiON:dgux:*:*)
+	# DG/UX returns AViiON for all architectures
+	UNAME_PROCESSOR=`/usr/bin/uname -p`
+	if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ]
+	then
+	    if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \
+	       [ ${TARGET_BINARY_INTERFACE}x = x ]
+	    then
+		echo m88k-dg-dgux${UNAME_RELEASE}
+	    else
+		echo m88k-dg-dguxbcs${UNAME_RELEASE}
+	    fi
+	else
+	    echo i586-dg-dgux${UNAME_RELEASE}
+	fi
+	exit ;;
+    M88*:DolphinOS:*:*)	# DolphinOS (SVR3)
+	echo m88k-dolphin-sysv3
+	exit ;;
+    M88*:*:R3*:*)
+	# Delta 88k system running SVR3
+	echo m88k-motorola-sysv3
+	exit ;;
+    XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)
+	echo m88k-tektronix-sysv3
+	exit ;;
+    Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)
+	echo m68k-tektronix-bsd
+	exit ;;
+    *:IRIX*:*:*)
+	echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'`
+	exit ;;
+    ????????:AIX?:[12].1:2)   # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
+	echo romp-ibm-aix     # uname -m gives an 8 hex-code CPU id
+	exit ;;               # Note that: echo "'`uname -s`'" gives 'AIX '
+    i*86:AIX:*:*)
+	echo i386-ibm-aix
+	exit ;;
+    ia64:AIX:*:*)
+	if [ -x /usr/bin/oslevel ] ; then
+		IBM_REV=`/usr/bin/oslevel`
+	else
+		IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
+	fi
+	echo ${UNAME_MACHINE}-ibm-aix${IBM_REV}
+	exit ;;
+    *:AIX:2:3)
+	if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
+		eval $set_cc_for_build
+		sed 's/^		//' << EOF >$dummy.c
+		#include <sys/systemcfg.h>
+
+		main()
+			{
+			if (!__power_pc())
+				exit(1);
+			puts("powerpc-ibm-aix3.2.5");
+			exit(0);
+			}
+EOF
+		if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy`
+		then
+			echo "$SYSTEM_NAME"
+		else
+			echo rs6000-ibm-aix3.2.5
+		fi
+	elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
+		echo rs6000-ibm-aix3.2.4
+	else
+		echo rs6000-ibm-aix3.2
+	fi
+	exit ;;
+    *:AIX:*:[4567])
+	IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
+	if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then
+		IBM_ARCH=rs6000
+	else
+		IBM_ARCH=powerpc
+	fi
+	if [ -x /usr/bin/oslevel ] ; then
+		IBM_REV=`/usr/bin/oslevel`
+	else
+		IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
+	fi
+	echo ${IBM_ARCH}-ibm-aix${IBM_REV}
+	exit ;;
+    *:AIX:*:*)
+	echo rs6000-ibm-aix
+	exit ;;
+    ibmrt:4.4BSD:*|romp-ibm:BSD:*)
+	echo romp-ibm-bsd4.4
+	exit ;;
+    ibmrt:*BSD:*|romp-ibm:BSD:*)            # covers RT/PC BSD and
+	echo romp-ibm-bsd${UNAME_RELEASE}   # 4.3 with uname added to
+	exit ;;                             # report: romp-ibm BSD 4.3
+    *:BOSX:*:*)
+	echo rs6000-bull-bosx
+	exit ;;
+    DPX/2?00:B.O.S.:*:*)
+	echo m68k-bull-sysv3
+	exit ;;
+    9000/[34]??:4.3bsd:1.*:*)
+	echo m68k-hp-bsd
+	exit ;;
+    hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)
+	echo m68k-hp-bsd4.4
+	exit ;;
+    9000/[34678]??:HP-UX:*:*)
+	HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
+	case "${UNAME_MACHINE}" in
+	    9000/31? )            HP_ARCH=m68000 ;;
+	    9000/[34]?? )         HP_ARCH=m68k ;;
+	    9000/[678][0-9][0-9])
+		if [ -x /usr/bin/getconf ]; then
+		    sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
+		    sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
+		    case "${sc_cpu_version}" in
+		      523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0
+		      528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1
+		      532)                      # CPU_PA_RISC2_0
+			case "${sc_kernel_bits}" in
+			  32) HP_ARCH="hppa2.0n" ;;
+			  64) HP_ARCH="hppa2.0w" ;;
+			  '') HP_ARCH="hppa2.0" ;;   # HP-UX 10.20
+			esac ;;
+		    esac
+		fi
+		if [ "${HP_ARCH}" = "" ]; then
+		    eval $set_cc_for_build
+		    sed 's/^		//' << EOF >$dummy.c
+
+		#define _HPUX_SOURCE
+		#include <stdlib.h>
+		#include <unistd.h>
+
+		int main ()
+		{
+		#if defined(_SC_KERNEL_BITS)
+		    long bits = sysconf(_SC_KERNEL_BITS);
+		#endif
+		    long cpu  = sysconf (_SC_CPU_VERSION);
+
+		    switch (cpu)
+			{
+			case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
+			case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
+			case CPU_PA_RISC2_0:
+		#if defined(_SC_KERNEL_BITS)
+			    switch (bits)
+				{
+				case 64: puts ("hppa2.0w"); break;
+				case 32: puts ("hppa2.0n"); break;
+				default: puts ("hppa2.0"); break;
+				} break;
+		#else  /* !defined(_SC_KERNEL_BITS) */
+			    puts ("hppa2.0"); break;
+		#endif
+			default: puts ("hppa1.0"); break;
+			}
+		    exit (0);
+		}
+EOF
+		    (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy`
+		    test -z "$HP_ARCH" && HP_ARCH=hppa
+		fi ;;
+	esac
+	if [ ${HP_ARCH} = "hppa2.0w" ]
+	then
+	    eval $set_cc_for_build
+
+	    # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating
+	    # 32-bit code.  hppa64-hp-hpux* has the same kernel and a compiler
+	    # generating 64-bit code.  GNU and HP use different nomenclature:
+	    #
+	    # $ CC_FOR_BUILD=cc ./config.guess
+	    # => hppa2.0w-hp-hpux11.23
+	    # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess
+	    # => hppa64-hp-hpux11.23
+
+	    if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) |
+		grep -q __LP64__
+	    then
+		HP_ARCH="hppa2.0w"
+	    else
+		HP_ARCH="hppa64"
+	    fi
+	fi
+	echo ${HP_ARCH}-hp-hpux${HPUX_REV}
+	exit ;;
+    ia64:HP-UX:*:*)
+	HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
+	echo ia64-hp-hpux${HPUX_REV}
+	exit ;;
+    3050*:HI-UX:*:*)
+	eval $set_cc_for_build
+	sed 's/^	//' << EOF >$dummy.c
+	#include <unistd.h>
+	int
+	main ()
+	{
+	  long cpu = sysconf (_SC_CPU_VERSION);
+	  /* The order matters, because CPU_IS_HP_MC68K erroneously returns
+	     true for CPU_PA_RISC1_0.  CPU_IS_PA_RISC returns correct
+	     results, however.  */
+	  if (CPU_IS_PA_RISC (cpu))
+	    {
+	      switch (cpu)
+		{
+		  case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break;
+		  case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break;
+		  case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break;
+		  default: puts ("hppa-hitachi-hiuxwe2"); break;
+		}
+	    }
+	  else if (CPU_IS_HP_MC68K (cpu))
+	    puts ("m68k-hitachi-hiuxwe2");
+	  else puts ("unknown-hitachi-hiuxwe2");
+	  exit (0);
+	}
+EOF
+	$CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` &&
+		{ echo "$SYSTEM_NAME"; exit; }
+	echo unknown-hitachi-hiuxwe2
+	exit ;;
+    9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )
+	echo hppa1.1-hp-bsd
+	exit ;;
+    9000/8??:4.3bsd:*:*)
+	echo hppa1.0-hp-bsd
+	exit ;;
+    *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*)
+	echo hppa1.0-hp-mpeix
+	exit ;;
+    hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* )
+	echo hppa1.1-hp-osf
+	exit ;;
+    hp8??:OSF1:*:*)
+	echo hppa1.0-hp-osf
+	exit ;;
+    i*86:OSF1:*:*)
+	if [ -x /usr/sbin/sysversion ] ; then
+	    echo ${UNAME_MACHINE}-unknown-osf1mk
+	else
+	    echo ${UNAME_MACHINE}-unknown-osf1
+	fi
+	exit ;;
+    parisc*:Lites*:*:*)
+	echo hppa1.1-hp-lites
+	exit ;;
+    C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
+	echo c1-convex-bsd
+	exit ;;
+    C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
+	if getsysinfo -f scalar_acc
+	then echo c32-convex-bsd
+	else echo c2-convex-bsd
+	fi
+	exit ;;
+    C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
+	echo c34-convex-bsd
+	exit ;;
+    C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
+	echo c38-convex-bsd
+	exit ;;
+    C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
+	echo c4-convex-bsd
+	exit ;;
+    CRAY*Y-MP:*:*:*)
+	echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit ;;
+    CRAY*[A-Z]90:*:*:*)
+	echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \
+	| sed -e 's/CRAY.*\([A-Z]90\)/\1/' \
+	      -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \
+	      -e 's/\.[^.]*$/.X/'
+	exit ;;
+    CRAY*TS:*:*:*)
+	echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit ;;
+    CRAY*T3E:*:*:*)
+	echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit ;;
+    CRAY*SV1:*:*:*)
+	echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit ;;
+    *:UNICOS/mp:*:*)
+	echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit ;;
+    F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
+	FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
+	FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
+	FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
+	echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
+	exit ;;
+    5000:UNIX_System_V:4.*:*)
+	FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
+	FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
+	echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
+	exit ;;
+    i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
+	echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
+	exit ;;
+    sparc*:BSD/OS:*:*)
+	echo sparc-unknown-bsdi${UNAME_RELEASE}
+	exit ;;
+    *:BSD/OS:*:*)
+	echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
+	exit ;;
+    *:FreeBSD:*:*)
+	UNAME_PROCESSOR=`/usr/bin/uname -p`
+	case ${UNAME_PROCESSOR} in
+	    amd64)
+		echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
+	    *)
+		echo ${UNAME_PROCESSOR}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
+	esac
+	exit ;;
+    i*:CYGWIN*:*)
+	echo ${UNAME_MACHINE}-pc-cygwin
+	exit ;;
+    *:MINGW64*:*)
+	echo ${UNAME_MACHINE}-pc-mingw64
+	exit ;;
+    *:MINGW*:*)
+	echo ${UNAME_MACHINE}-pc-mingw32
+	exit ;;
+    i*:MSYS*:*)
+	echo ${UNAME_MACHINE}-pc-msys
+	exit ;;
+    i*:windows32*:*)
+	# uname -m includes "-pc" on this system.
+	echo ${UNAME_MACHINE}-mingw32
+	exit ;;
+    i*:PW*:*)
+	echo ${UNAME_MACHINE}-pc-pw32
+	exit ;;
+    *:Interix*:*)
+	case ${UNAME_MACHINE} in
+	    x86)
+		echo i586-pc-interix${UNAME_RELEASE}
+		exit ;;
+	    authenticamd | genuineintel | EM64T)
+		echo x86_64-unknown-interix${UNAME_RELEASE}
+		exit ;;
+	    IA64)
+		echo ia64-unknown-interix${UNAME_RELEASE}
+		exit ;;
+	esac ;;
+    [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*)
+	echo i${UNAME_MACHINE}-pc-mks
+	exit ;;
+    8664:Windows_NT:*)
+	echo x86_64-pc-mks
+	exit ;;
+    i*:Windows_NT*:* | Pentium*:Windows_NT*:*)
+	# How do we know it's Interix rather than the generic POSIX subsystem?
+	# It also conflicts with pre-2.0 versions of AT&T UWIN. Should we
+	# UNAME_MACHINE based on the output of uname instead of i386?
+	echo i586-pc-interix
+	exit ;;
+    i*:UWIN*:*)
+	echo ${UNAME_MACHINE}-pc-uwin
+	exit ;;
+    amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*)
+	echo x86_64-unknown-cygwin
+	exit ;;
+    p*:CYGWIN*:*)
+	echo powerpcle-unknown-cygwin
+	exit ;;
+    prep*:SunOS:5.*:*)
+	echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+	exit ;;
+    *:GNU:*:*)
+	# the GNU system
+	echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-${LIBC}`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
+	exit ;;
+    *:GNU/*:*:*)
+	# other systems with GNU libc and userland
+	echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-${LIBC}
+	exit ;;
+    i*86:Minix:*:*)
+	echo ${UNAME_MACHINE}-pc-minix
+	exit ;;
+    aarch64:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    aarch64_be:Linux:*:*)
+	UNAME_MACHINE=aarch64_be
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    alpha:Linux:*:*)
+	case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
+	  EV5)   UNAME_MACHINE=alphaev5 ;;
+	  EV56)  UNAME_MACHINE=alphaev56 ;;
+	  PCA56) UNAME_MACHINE=alphapca56 ;;
+	  PCA57) UNAME_MACHINE=alphapca56 ;;
+	  EV6)   UNAME_MACHINE=alphaev6 ;;
+	  EV67)  UNAME_MACHINE=alphaev67 ;;
+	  EV68*) UNAME_MACHINE=alphaev68 ;;
+	esac
+	objdump --private-headers /bin/sh | grep -q ld.so.1
+	if test "$?" = 0 ; then LIBC="gnulibc1" ; fi
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    arc:Linux:*:* | arceb:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    arm*:Linux:*:*)
+	eval $set_cc_for_build
+	if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \
+	    | grep -q __ARM_EABI__
+	then
+	    echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	else
+	    if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \
+		| grep -q __ARM_PCS_VFP
+	    then
+		echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabi
+	    else
+		echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabihf
+	    fi
+	fi
+	exit ;;
+    avr32*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    cris:Linux:*:*)
+	echo ${UNAME_MACHINE}-axis-linux-${LIBC}
+	exit ;;
+    crisv32:Linux:*:*)
+	echo ${UNAME_MACHINE}-axis-linux-${LIBC}
+	exit ;;
+    frv:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    hexagon:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    i*86:Linux:*:*)
+	echo ${UNAME_MACHINE}-pc-linux-${LIBC}
+	exit ;;
+    ia64:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    m32r*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    m68*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    mips:Linux:*:* | mips64:Linux:*:*)
+	eval $set_cc_for_build
+	sed 's/^	//' << EOF >$dummy.c
+	#undef CPU
+	#undef ${UNAME_MACHINE}
+	#undef ${UNAME_MACHINE}el
+	#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
+	CPU=${UNAME_MACHINE}el
+	#else
+	#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
+	CPU=${UNAME_MACHINE}
+	#else
+	CPU=
+	#endif
+	#endif
+EOF
+	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'`
+	test x"${CPU}" != x && { echo "${CPU}-unknown-linux-${LIBC}"; exit; }
+	;;
+    or1k:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    or32:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    padre:Linux:*:*)
+	echo sparc-unknown-linux-${LIBC}
+	exit ;;
+    parisc64:Linux:*:* | hppa64:Linux:*:*)
+	echo hppa64-unknown-linux-${LIBC}
+	exit ;;
+    parisc:Linux:*:* | hppa:Linux:*:*)
+	# Look for CPU level
+	case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in
+	  PA7*) echo hppa1.1-unknown-linux-${LIBC} ;;
+	  PA8*) echo hppa2.0-unknown-linux-${LIBC} ;;
+	  *)    echo hppa-unknown-linux-${LIBC} ;;
+	esac
+	exit ;;
+    ppc64:Linux:*:*)
+	echo powerpc64-unknown-linux-${LIBC}
+	exit ;;
+    ppc:Linux:*:*)
+	echo powerpc-unknown-linux-${LIBC}
+	exit ;;
+    ppc64le:Linux:*:*)
+	echo powerpc64le-unknown-linux-${LIBC}
+	exit ;;
+    ppcle:Linux:*:*)
+	echo powerpcle-unknown-linux-${LIBC}
+	exit ;;
+    s390:Linux:*:* | s390x:Linux:*:*)
+	echo ${UNAME_MACHINE}-ibm-linux-${LIBC}
+	exit ;;
+    sh64*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    sh*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    sparc:Linux:*:* | sparc64:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    tile*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    vax:Linux:*:*)
+	echo ${UNAME_MACHINE}-dec-linux-${LIBC}
+	exit ;;
+    x86_64:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    xtensa*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+	exit ;;
+    i*86:DYNIX/ptx:4*:*)
+	# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.
+	# earlier versions are messed up and put the nodename in both
+	# sysname and nodename.
+	echo i386-sequent-sysv4
+	exit ;;
+    i*86:UNIX_SV:4.2MP:2.*)
+	# Unixware is an offshoot of SVR4, but it has its own version
+	# number series starting with 2...
+	# I am not positive that other SVR4 systems won't match this,
+	# I just have to hope.  -- rms.
+	# Use sysv4.2uw... so that sysv4* matches it.
+	echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
+	exit ;;
+    i*86:OS/2:*:*)
+	# If we were able to find `uname', then EMX Unix compatibility
+	# is probably installed.
+	echo ${UNAME_MACHINE}-pc-os2-emx
+	exit ;;
+    i*86:XTS-300:*:STOP)
+	echo ${UNAME_MACHINE}-unknown-stop
+	exit ;;
+    i*86:atheos:*:*)
+	echo ${UNAME_MACHINE}-unknown-atheos
+	exit ;;
+    i*86:syllable:*:*)
+	echo ${UNAME_MACHINE}-pc-syllable
+	exit ;;
+    i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*)
+	echo i386-unknown-lynxos${UNAME_RELEASE}
+	exit ;;
+    i*86:*DOS:*:*)
+	echo ${UNAME_MACHINE}-pc-msdosdjgpp
+	exit ;;
+    i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*)
+	UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'`
+	if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
+		echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL}
+	else
+		echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL}
+	fi
+	exit ;;
+    i*86:*:5:[678]*)
+	# UnixWare 7.x, OpenUNIX and OpenServer 6.
+	case `/bin/uname -X | grep "^Machine"` in
+	    *486*)	     UNAME_MACHINE=i486 ;;
+	    *Pentium)	     UNAME_MACHINE=i586 ;;
+	    *Pent*|*Celeron) UNAME_MACHINE=i686 ;;
+	esac
+	echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION}
+	exit ;;
+    i*86:*:3.2:*)
+	if test -f /usr/options/cb.name; then
+		UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`
+		echo ${UNAME_MACHINE}-pc-isc$UNAME_REL
+	elif /bin/uname -X 2>/dev/null >/dev/null ; then
+		UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')`
+		(/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486
+		(/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \
+			&& UNAME_MACHINE=i586
+		(/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \
+			&& UNAME_MACHINE=i686
+		(/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \
+			&& UNAME_MACHINE=i686
+		echo ${UNAME_MACHINE}-pc-sco$UNAME_REL
+	else
+		echo ${UNAME_MACHINE}-pc-sysv32
+	fi
+	exit ;;
+    pc:*:*:*)
+	# Left here for compatibility:
+	# uname -m prints for DJGPP always 'pc', but it prints nothing about
+	# the processor, so we play safe by assuming i586.
+	# Note: whatever this is, it MUST be the same as what config.sub
+	# prints for the "djgpp" host, or else GDB configury will decide that
+	# this is a cross-build.
+	echo i586-pc-msdosdjgpp
+	exit ;;
+    Intel:Mach:3*:*)
+	echo i386-pc-mach3
+	exit ;;
+    paragon:*:*:*)
+	echo i860-intel-osf1
+	exit ;;
+    i860:*:4.*:*) # i860-SVR4
+	if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then
+	  echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4
+	else # Add other i860-SVR4 vendors below as they are discovered.
+	  echo i860-unknown-sysv${UNAME_RELEASE}  # Unknown i860-SVR4
+	fi
+	exit ;;
+    mini*:CTIX:SYS*5:*)
+	# "miniframe"
+	echo m68010-convergent-sysv
+	exit ;;
+    mc68k:UNIX:SYSTEM5:3.51m)
+	echo m68k-convergent-sysv
+	exit ;;
+    M680?0:D-NIX:5.3:*)
+	echo m68k-diab-dnix
+	exit ;;
+    M68*:*:R3V[5678]*:*)
+	test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;;
+    3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0)
+	OS_REL=''
+	test -r /etc/.relid \
+	&& OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
+	/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+	  && { echo i486-ncr-sysv4.3${OS_REL}; exit; }
+	/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
+	  && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
+    3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
+	/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+	  && { echo i486-ncr-sysv4; exit; } ;;
+    NCR*:*:4.2:* | MPRAS*:*:4.2:*)
+	OS_REL='.3'
+	test -r /etc/.relid \
+	    && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
+	/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+	    && { echo i486-ncr-sysv4.3${OS_REL}; exit; }
+	/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
+	    && { echo i586-ncr-sysv4.3${OS_REL}; exit; }
+	/bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \
+	    && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
+    m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*)
+	echo m68k-unknown-lynxos${UNAME_RELEASE}
+	exit ;;
+    mc68030:UNIX_System_V:4.*:*)
+	echo m68k-atari-sysv4
+	exit ;;
+    TSUNAMI:LynxOS:2.*:*)
+	echo sparc-unknown-lynxos${UNAME_RELEASE}
+	exit ;;
+    rs6000:LynxOS:2.*:*)
+	echo rs6000-unknown-lynxos${UNAME_RELEASE}
+	exit ;;
+    PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*)
+	echo powerpc-unknown-lynxos${UNAME_RELEASE}
+	exit ;;
+    SM[BE]S:UNIX_SV:*:*)
+	echo mips-dde-sysv${UNAME_RELEASE}
+	exit ;;
+    RM*:ReliantUNIX-*:*:*)
+	echo mips-sni-sysv4
+	exit ;;
+    RM*:SINIX-*:*:*)
+	echo mips-sni-sysv4
+	exit ;;
+    *:SINIX-*:*:*)
+	if uname -p 2>/dev/null >/dev/null ; then
+		UNAME_MACHINE=`(uname -p) 2>/dev/null`
+		echo ${UNAME_MACHINE}-sni-sysv4
+	else
+		echo ns32k-sni-sysv
+	fi
+	exit ;;
+    PENTIUM:*:4.0*:*)	# Unisys `ClearPath HMP IX 4000' SVR4/MP effort
+			# says <Richard.M.Bartel@ccMail.Census.GOV>
+	echo i586-unisys-sysv4
+	exit ;;
+    *:UNIX_System_V:4*:FTX*)
+	# From Gerald Hewes <hewes@openmarket.com>.
+	# How about differentiating between stratus architectures? -djm
+	echo hppa1.1-stratus-sysv4
+	exit ;;
+    *:*:*:FTX*)
+	# From seanf@swdc.stratus.com.
+	echo i860-stratus-sysv4
+	exit ;;
+    i*86:VOS:*:*)
+	# From Paul.Green@stratus.com.
+	echo ${UNAME_MACHINE}-stratus-vos
+	exit ;;
+    *:VOS:*:*)
+	# From Paul.Green@stratus.com.
+	echo hppa1.1-stratus-vos
+	exit ;;
+    mc68*:A/UX:*:*)
+	echo m68k-apple-aux${UNAME_RELEASE}
+	exit ;;
+    news*:NEWS-OS:6*:*)
+	echo mips-sony-newsos6
+	exit ;;
+    R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
+	if [ -d /usr/nec ]; then
+		echo mips-nec-sysv${UNAME_RELEASE}
+	else
+		echo mips-unknown-sysv${UNAME_RELEASE}
+	fi
+	exit ;;
+    BeBox:BeOS:*:*)	# BeOS running on hardware made by Be, PPC only.
+	echo powerpc-be-beos
+	exit ;;
+    BeMac:BeOS:*:*)	# BeOS running on Mac or Mac clone, PPC only.
+	echo powerpc-apple-beos
+	exit ;;
+    BePC:BeOS:*:*)	# BeOS running on Intel PC compatible.
+	echo i586-pc-beos
+	exit ;;
+    BePC:Haiku:*:*)	# Haiku running on Intel PC compatible.
+	echo i586-pc-haiku
+	exit ;;
+    x86_64:Haiku:*:*)
+	echo x86_64-unknown-haiku
+	exit ;;
+    SX-4:SUPER-UX:*:*)
+	echo sx4-nec-superux${UNAME_RELEASE}
+	exit ;;
+    SX-5:SUPER-UX:*:*)
+	echo sx5-nec-superux${UNAME_RELEASE}
+	exit ;;
+    SX-6:SUPER-UX:*:*)
+	echo sx6-nec-superux${UNAME_RELEASE}
+	exit ;;
+    SX-7:SUPER-UX:*:*)
+	echo sx7-nec-superux${UNAME_RELEASE}
+	exit ;;
+    SX-8:SUPER-UX:*:*)
+	echo sx8-nec-superux${UNAME_RELEASE}
+	exit ;;
+    SX-8R:SUPER-UX:*:*)
+	echo sx8r-nec-superux${UNAME_RELEASE}
+	exit ;;
+    Power*:Rhapsody:*:*)
+	echo powerpc-apple-rhapsody${UNAME_RELEASE}
+	exit ;;
+    *:Rhapsody:*:*)
+	echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
+	exit ;;
+    *:Darwin:*:*)
+	UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
+	eval $set_cc_for_build
+	if test "$UNAME_PROCESSOR" = unknown ; then
+	    UNAME_PROCESSOR=powerpc
+	fi
+	if test `echo "$UNAME_RELEASE" | sed -e 's/\..*//'` -le 10 ; then
+	    if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
+		if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \
+		    (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
+		    grep IS_64BIT_ARCH >/dev/null
+		then
+		    case $UNAME_PROCESSOR in
+			i386) UNAME_PROCESSOR=x86_64 ;;
+			powerpc) UNAME_PROCESSOR=powerpc64 ;;
+		    esac
+		fi
+	    fi
+	elif test "$UNAME_PROCESSOR" = i386 ; then
+	    # Avoid executing cc on OS X 10.9, as it ships with a stub
+	    # that puts up a graphical alert prompting to install
+	    # developer tools.  Any system running Mac OS X 10.7 or
+	    # later (Darwin 11 and later) is required to have a 64-bit
+	    # processor. This is not true of the ARM version of Darwin
+	    # that Apple uses in portable devices.
+	    UNAME_PROCESSOR=x86_64
+	fi
+	echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
+	exit ;;
+    *:procnto*:*:* | *:QNX:[0123456789]*:*)
+	UNAME_PROCESSOR=`uname -p`
+	if test "$UNAME_PROCESSOR" = "x86"; then
+		UNAME_PROCESSOR=i386
+		UNAME_MACHINE=pc
+	fi
+	echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE}
+	exit ;;
+    *:QNX:*:4*)
+	echo i386-pc-qnx
+	exit ;;
+    NEO-?:NONSTOP_KERNEL:*:*)
+	echo neo-tandem-nsk${UNAME_RELEASE}
+	exit ;;
+    NSE-*:NONSTOP_KERNEL:*:*)
+	echo nse-tandem-nsk${UNAME_RELEASE}
+	exit ;;
+    NSR-?:NONSTOP_KERNEL:*:*)
+	echo nsr-tandem-nsk${UNAME_RELEASE}
+	exit ;;
+    *:NonStop-UX:*:*)
+	echo mips-compaq-nonstopux
+	exit ;;
+    BS2000:POSIX*:*:*)
+	echo bs2000-siemens-sysv
+	exit ;;
+    DS/*:UNIX_System_V:*:*)
+	echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE}
+	exit ;;
+    *:Plan9:*:*)
+	# "uname -m" is not consistent, so use $cputype instead. 386
+	# is converted to i386 for consistency with other x86
+	# operating systems.
+	if test "$cputype" = "386"; then
+	    UNAME_MACHINE=i386
+	else
+	    UNAME_MACHINE="$cputype"
+	fi
+	echo ${UNAME_MACHINE}-unknown-plan9
+	exit ;;
+    *:TOPS-10:*:*)
+	echo pdp10-unknown-tops10
+	exit ;;
+    *:TENEX:*:*)
+	echo pdp10-unknown-tenex
+	exit ;;
+    KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*)
+	echo pdp10-dec-tops20
+	exit ;;
+    XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*)
+	echo pdp10-xkl-tops20
+	exit ;;
+    *:TOPS-20:*:*)
+	echo pdp10-unknown-tops20
+	exit ;;
+    *:ITS:*:*)
+	echo pdp10-unknown-its
+	exit ;;
+    SEI:*:*:SEIUX)
+	echo mips-sei-seiux${UNAME_RELEASE}
+	exit ;;
+    *:DragonFly:*:*)
+	echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
+	exit ;;
+    *:*VMS:*:*)
+	UNAME_MACHINE=`(uname -p) 2>/dev/null`
+	case "${UNAME_MACHINE}" in
+	    A*) echo alpha-dec-vms ; exit ;;
+	    I*) echo ia64-dec-vms ; exit ;;
+	    V*) echo vax-dec-vms ; exit ;;
+	esac ;;
+    *:XENIX:*:SysV)
+	echo i386-pc-xenix
+	exit ;;
+    i*86:skyos:*:*)
+	echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//'
+	exit ;;
+    i*86:rdos:*:*)
+	echo ${UNAME_MACHINE}-pc-rdos
+	exit ;;
+    i*86:AROS:*:*)
+	echo ${UNAME_MACHINE}-pc-aros
+	exit ;;
+    x86_64:VMkernel:*:*)
+	echo ${UNAME_MACHINE}-unknown-esx
+	exit ;;
+esac
+
+cat >&2 <<EOF
+$0: unable to guess system type
+
+This script, last modified $timestamp, has failed to recognize
+the operating system you are using. It is advised that you
+download the most up to date version of the config scripts from
+
+  http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
+and
+  http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
+
+If the version you run ($0) is already up to date, please
+send the following data and any information you think might be
+pertinent to <config-patches@gnu.org> in order to provide the needed
+information to handle your system.
+
+config.guess timestamp = $timestamp
+
+uname -m = `(uname -m) 2>/dev/null || echo unknown`
+uname -r = `(uname -r) 2>/dev/null || echo unknown`
+uname -s = `(uname -s) 2>/dev/null || echo unknown`
+uname -v = `(uname -v) 2>/dev/null || echo unknown`
+
+/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null`
+/bin/uname -X     = `(/bin/uname -X) 2>/dev/null`
+
+hostinfo               = `(hostinfo) 2>/dev/null`
+/bin/universe          = `(/bin/universe) 2>/dev/null`
+/usr/bin/arch -k       = `(/usr/bin/arch -k) 2>/dev/null`
+/bin/arch              = `(/bin/arch) 2>/dev/null`
+/usr/bin/oslevel       = `(/usr/bin/oslevel) 2>/dev/null`
+/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null`
+
+UNAME_MACHINE = ${UNAME_MACHINE}
+UNAME_RELEASE = ${UNAME_RELEASE}
+UNAME_SYSTEM  = ${UNAME_SYSTEM}
+UNAME_VERSION = ${UNAME_VERSION}
+EOF
+
+exit 1
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "timestamp='"
+# time-stamp-format: "%:y-%02m-%02d"
+# time-stamp-end: "'"
+# End:
diff --git a/build/autoconf/config.sub b/build/autoconf/config.sub
new file mode 100755
index 0000000..4c119ba
--- /dev/null
+++ b/build/autoconf/config.sub
@@ -0,0 +1,1795 @@
+#! /bin/sh
+# Configuration validation subroutine script.
+#   Copyright 1992-2014 Free Software Foundation, Inc.
+
+timestamp='2014-01-01'
+
+# This file is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, see <http://www.gnu.org/licenses/>.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that
+# program.  This Exception is an additional permission under section 7
+# of the GNU General Public License, version 3 ("GPLv3").
+
+
+# Please send patches with a ChangeLog entry to config-patches@gnu.org.
+#
+# Configuration subroutine to validate and canonicalize a configuration type.
+# Supply the specified configuration type as an argument.
+# If it is invalid, we print an error message on stderr and exit with code 1.
+# Otherwise, we print the canonical config type on stdout and succeed.
+
+# You can get the latest version of this script from:
+# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
+
+# This file is supposed to be the same for all GNU packages
+# and recognize all the CPU types, system types and aliases
+# that are meaningful with *any* GNU software.
+# Each package is responsible for reporting which valid configurations
+# it does not support.  The user should be able to distinguish
+# a failure to support a valid configuration from a meaningless
+# configuration.
+
+# The goal of this file is to map all the various variations of a given
+# machine specification into a single specification in the form:
+#	CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
+# or in some cases, the newer four-part form:
+#	CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
+# It is wrong to echo any other type of specification.
+
+me=`echo "$0" | sed -e 's,.*/,,'`
+
+usage="\
+Usage: $0 [OPTION] CPU-MFR-OPSYS
+       $0 [OPTION] ALIAS
+
+Canonicalize a configuration name.
+
+Operation modes:
+  -h, --help         print this help, then exit
+  -t, --time-stamp   print date of last modification, then exit
+  -v, --version      print version number, then exit
+
+Report bugs and patches to <config-patches@gnu.org>."
+
+version="\
+GNU config.sub ($timestamp)
+
+Copyright 1992-2014 Free Software Foundation, Inc.
+
+This is free software; see the source for copying conditions.  There is NO
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
+
+help="
+Try \`$me --help' for more information."
+
+# Parse command line
+while test $# -gt 0 ; do
+  case $1 in
+    --time-stamp | --time* | -t )
+       echo "$timestamp" ; exit ;;
+    --version | -v )
+       echo "$version" ; exit ;;
+    --help | --h* | -h )
+       echo "$usage"; exit ;;
+    -- )     # Stop option processing
+       shift; break ;;
+    - )	# Use stdin as input.
+       break ;;
+    -* )
+       echo "$me: invalid option $1$help"
+       exit 1 ;;
+
+    *local*)
+       # First pass through any local machine types.
+       echo $1
+       exit ;;
+
+    * )
+       break ;;
+  esac
+done
+
+case $# in
+ 0) echo "$me: missing argument$help" >&2
+    exit 1;;
+ 1) ;;
+ *) echo "$me: too many arguments$help" >&2
+    exit 1;;
+esac
+
+# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any).
+# Here we must recognize all the valid KERNEL-OS combinations.
+maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
+case $maybe_os in
+  nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | \
+  linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \
+  knetbsd*-gnu* | netbsd*-gnu* | \
+  kopensolaris*-gnu* | \
+  storm-chaos* | os2-emx* | rtmk-nova*)
+    os=-$maybe_os
+    basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
+    ;;
+  *)
+    basic_machine=`echo $1 | sed 's/-[^-]*$//'`
+    if [ $basic_machine != $1 ]
+    then os=`echo $1 | sed 's/.*-/-/'`
+    else os=; fi
+    ;;
+esac
+
+### Let's recognize common machines as not being operating systems so
+### that things like config.sub decstation-3100 work.  We also
+### recognize some manufacturers as not being operating systems, so we
+### can provide default operating systems below.
+case $os in
+	-sun*os*)
+		# Prevent following clause from handling this invalid input.
+		;;
+	-dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \
+	-att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \
+	-unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \
+	-convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
+	-c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
+	-harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
+	-apple | -axis | -knuth | -cray | -microblaze*)
+		os=
+		basic_machine=$1
+		;;
+	-bluegene*)
+		os=-cnk
+		;;
+	-sim | -cisco | -oki | -wec | -winbond)
+		os=
+		basic_machine=$1
+		;;
+	-scout)
+		;;
+	-wrs)
+		os=-vxworks
+		basic_machine=$1
+		;;
+	-chorusos*)
+		os=-chorusos
+		basic_machine=$1
+		;;
+	-chorusrdb)
+		os=-chorusrdb
+		basic_machine=$1
+		;;
+	-hiux*)
+		os=-hiuxwe2
+		;;
+	-sco6)
+		os=-sco5v6
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco5)
+		os=-sco3.2v5
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco4)
+		os=-sco3.2v4
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco3.2.[4-9]*)
+		os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco3.2v[4-9]*)
+		# Don't forget version if it is 3.2v4 or newer.
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco5v6*)
+		# Don't forget version if it is 3.2v4 or newer.
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-sco*)
+		os=-sco3.2v2
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-udk*)
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-isc)
+		os=-isc2.2
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-clix*)
+		basic_machine=clipper-intergraph
+		;;
+	-isc*)
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
+	-lynx*178)
+		os=-lynxos178
+		;;
+	-lynx*5)
+		os=-lynxos5
+		;;
+	-lynx*)
+		os=-lynxos
+		;;
+	-ptx*)
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'`
+		;;
+	-windowsnt*)
+		os=`echo $os | sed -e 's/windowsnt/winnt/'`
+		;;
+	-psos*)
+		os=-psos
+		;;
+	-mint | -mint[0-9]*)
+		basic_machine=m68k-atari
+		os=-mint
+		;;
+esac
+
+# Decode aliases for certain CPU-COMPANY combinations.
+case $basic_machine in
+	# Recognize the basic CPU types without company name.
+	# Some are omitted here because they have special meanings below.
+	1750a | 580 \
+	| a29k \
+	| aarch64 | aarch64_be \
+	| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
+	| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
+	| am33_2.0 \
+	| arc | arceb \
+	| arm | arm[bl]e | arme[lb] | armv[2-8] | armv[3-8][lb] | armv7[arm] \
+	| avr | avr32 \
+	| be32 | be64 \
+	| bfin \
+	| c4x | c8051 | clipper \
+	| d10v | d30v | dlx | dsp16xx \
+	| epiphany \
+	| fido | fr30 | frv \
+	| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
+	| hexagon \
+	| i370 | i860 | i960 | ia64 \
+	| ip2k | iq2000 \
+	| k1om \
+	| le32 | le64 \
+	| lm32 \
+	| m32c | m32r | m32rle | m68000 | m68k | m88k \
+	| maxq | mb | microblaze | microblazeel | mcore | mep | metag \
+	| mips | mipsbe | mipseb | mipsel | mipsle \
+	| mips16 \
+	| mips64 | mips64el \
+	| mips64octeon | mips64octeonel \
+	| mips64orion | mips64orionel \
+	| mips64r5900 | mips64r5900el \
+	| mips64vr | mips64vrel \
+	| mips64vr4100 | mips64vr4100el \
+	| mips64vr4300 | mips64vr4300el \
+	| mips64vr5000 | mips64vr5000el \
+	| mips64vr5900 | mips64vr5900el \
+	| mipsisa32 | mipsisa32el \
+	| mipsisa32r2 | mipsisa32r2el \
+	| mipsisa64 | mipsisa64el \
+	| mipsisa64r2 | mipsisa64r2el \
+	| mipsisa64sb1 | mipsisa64sb1el \
+	| mipsisa64sr71k | mipsisa64sr71kel \
+	| mipsr5900 | mipsr5900el \
+	| mipstx39 | mipstx39el \
+	| mn10200 | mn10300 \
+	| moxie \
+	| mt \
+	| msp430 \
+	| nds32 | nds32le | nds32be \
+	| nios | nios2 | nios2eb | nios2el \
+	| ns16k | ns32k \
+	| open8 \
+	| or1k | or32 \
+	| pdp10 | pdp11 | pj | pjl \
+	| powerpc | powerpc64 | powerpc64le | powerpcle \
+	| pyramid \
+	| rl78 | rx \
+	| score \
+	| sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \
+	| sh64 | sh64le \
+	| sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \
+	| sparcv8 | sparcv9 | sparcv9b | sparcv9v \
+	| spu \
+	| tahoe | tic4x | tic54x | tic55x | tic6x | tic80 | tron \
+	| ubicom32 \
+	| v850 | v850e | v850e1 | v850e2 | v850es | v850e2v3 \
+	| we32k \
+	| x86 | xc16x | xstormy16 | xtensa \
+	| z8k | z80)
+		basic_machine=$basic_machine-unknown
+		;;
+	c54x)
+		basic_machine=tic54x-unknown
+		;;
+	c55x)
+		basic_machine=tic55x-unknown
+		;;
+	c6x)
+		basic_machine=tic6x-unknown
+		;;
+	m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | nvptx | picochip)
+		basic_machine=$basic_machine-unknown
+		os=-none
+		;;
+	m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k)
+		;;
+	ms1)
+		basic_machine=mt-unknown
+		;;
+
+	strongarm | thumb | xscale)
+		basic_machine=arm-unknown
+		;;
+	xgate)
+		basic_machine=$basic_machine-unknown
+		os=-none
+		;;
+	xscaleeb)
+		basic_machine=armeb-unknown
+		;;
+
+	xscaleel)
+		basic_machine=armel-unknown
+		;;
+
+	# We use `pc' rather than `unknown'
+	# because (1) that's what they normally are, and
+	# (2) the word "unknown" tends to confuse beginning users.
+	i*86 | x86_64)
+	  basic_machine=$basic_machine-pc
+	  ;;
+	# Object if more than one company name word.
+	*-*-*)
+		echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
+		exit 1
+		;;
+	# Recognize the basic CPU types with company name.
+	580-* \
+	| a29k-* \
+	| aarch64-* | aarch64_be-* \
+	| alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
+	| alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
+	| alphapca5[67]-* | alpha64pca5[67]-* | arc-* | arceb-* \
+	| arm-*  | armbe-* | armle-* | armeb-* | armv*-* \
+	| avr-* | avr32-* \
+	| be32-* | be64-* \
+	| bfin-* | bs2000-* \
+	| c[123]* | c30-* | [cjt]90-* | c4x-* \
+	| c8051-* | clipper-* | craynv-* | cydra-* \
+	| d10v-* | d30v-* | dlx-* \
+	| elxsi-* \
+	| f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \
+	| h8300-* | h8500-* \
+	| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
+	| hexagon-* \
+	| i*86-* | i860-* | i960-* | ia64-* \
+	| ip2k-* | iq2000-* \
+	| k1om-* \
+	| le32-* | le64-* \
+	| lm32-* \
+	| m32c-* | m32r-* | m32rle-* \
+	| m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
+	| m88110-* | m88k-* | maxq-* | mcore-* | metag-* \
+	| microblaze-* | microblazeel-* \
+	| mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
+	| mips16-* \
+	| mips64-* | mips64el-* \
+	| mips64octeon-* | mips64octeonel-* \
+	| mips64orion-* | mips64orionel-* \
+	| mips64r5900-* | mips64r5900el-* \
+	| mips64vr-* | mips64vrel-* \
+	| mips64vr4100-* | mips64vr4100el-* \
+	| mips64vr4300-* | mips64vr4300el-* \
+	| mips64vr5000-* | mips64vr5000el-* \
+	| mips64vr5900-* | mips64vr5900el-* \
+	| mipsisa32-* | mipsisa32el-* \
+	| mipsisa32r2-* | mipsisa32r2el-* \
+	| mipsisa64-* | mipsisa64el-* \
+	| mipsisa64r2-* | mipsisa64r2el-* \
+	| mipsisa64sb1-* | mipsisa64sb1el-* \
+	| mipsisa64sr71k-* | mipsisa64sr71kel-* \
+	| mipsr5900-* | mipsr5900el-* \
+	| mipstx39-* | mipstx39el-* \
+	| mmix-* \
+	| mt-* \
+	| msp430-* \
+	| nds32-* | nds32le-* | nds32be-* \
+	| nios-* | nios2-* | nios2eb-* | nios2el-* \
+	| none-* | np1-* | ns16k-* | ns32k-* \
+	| open8-* \
+	| orion-* \
+	| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
+	| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \
+	| pyramid-* \
+	| rl78-* | romp-* | rs6000-* | rx-* \
+	| sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \
+	| shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
+	| sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \
+	| sparclite-* \
+	| sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx?-* \
+	| tahoe-* \
+	| tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
+	| tile*-* \
+	| tron-* \
+	| ubicom32-* \
+	| v850-* | v850e-* | v850e1-* | v850es-* | v850e2-* | v850e2v3-* \
+	| vax-* \
+	| we32k-* \
+	| x86-* | x86_64-* | xc16x-* | xps100-* \
+	| xstormy16-* | xtensa*-* \
+	| ymp-* \
+	| z8k-* | z80-*)
+		;;
+	# Recognize the basic CPU types without company name, with glob match.
+	xtensa*)
+		basic_machine=$basic_machine-unknown
+		;;
+	# Recognize the various machine names and aliases which stand
+	# for a CPU type and a company and sometimes even an OS.
+	386bsd)
+		basic_machine=i386-unknown
+		os=-bsd
+		;;
+	3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
+		basic_machine=m68000-att
+		;;
+	3b*)
+		basic_machine=we32k-att
+		;;
+	a29khif)
+		basic_machine=a29k-amd
+		os=-udi
+		;;
+	abacus)
+		basic_machine=abacus-unknown
+		;;
+	adobe68k)
+		basic_machine=m68010-adobe
+		os=-scout
+		;;
+	alliant | fx80)
+		basic_machine=fx80-alliant
+		;;
+	altos | altos3068)
+		basic_machine=m68k-altos
+		;;
+	am29k)
+		basic_machine=a29k-none
+		os=-bsd
+		;;
+	amd64)
+		basic_machine=x86_64-pc
+		;;
+	amd64-*)
+		basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	amdahl)
+		basic_machine=580-amdahl
+		os=-sysv
+		;;
+	amiga | amiga-*)
+		basic_machine=m68k-unknown
+		;;
+	amigaos | amigados)
+		basic_machine=m68k-unknown
+		os=-amigaos
+		;;
+	amigaunix | amix)
+		basic_machine=m68k-unknown
+		os=-sysv4
+		;;
+	apollo68)
+		basic_machine=m68k-apollo
+		os=-sysv
+		;;
+	apollo68bsd)
+		basic_machine=m68k-apollo
+		os=-bsd
+		;;
+	aros)
+		basic_machine=i386-pc
+		os=-aros
+		;;
+	aux)
+		basic_machine=m68k-apple
+		os=-aux
+		;;
+	balance)
+		basic_machine=ns32k-sequent
+		os=-dynix
+		;;
+	blackfin)
+		basic_machine=bfin-unknown
+		os=-linux
+		;;
+	blackfin-*)
+		basic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'`
+		os=-linux
+		;;
+	bluegene*)
+		basic_machine=powerpc-ibm
+		os=-cnk
+		;;
+	c54x-*)
+		basic_machine=tic54x-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	c55x-*)
+		basic_machine=tic55x-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	c6x-*)
+		basic_machine=tic6x-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	c90)
+		basic_machine=c90-cray
+		os=-unicos
+		;;
+	cegcc)
+		basic_machine=arm-unknown
+		os=-cegcc
+		;;
+	convex-c1)
+		basic_machine=c1-convex
+		os=-bsd
+		;;
+	convex-c2)
+		basic_machine=c2-convex
+		os=-bsd
+		;;
+	convex-c32)
+		basic_machine=c32-convex
+		os=-bsd
+		;;
+	convex-c34)
+		basic_machine=c34-convex
+		os=-bsd
+		;;
+	convex-c38)
+		basic_machine=c38-convex
+		os=-bsd
+		;;
+	cray | j90)
+		basic_machine=j90-cray
+		os=-unicos
+		;;
+	craynv)
+		basic_machine=craynv-cray
+		os=-unicosmp
+		;;
+	cr16 | cr16-*)
+		basic_machine=cr16-unknown
+		os=-elf
+		;;
+	crds | unos)
+		basic_machine=m68k-crds
+		;;
+	crisv32 | crisv32-* | etraxfs*)
+		basic_machine=crisv32-axis
+		;;
+	cris | cris-* | etrax*)
+		basic_machine=cris-axis
+		;;
+	crx)
+		basic_machine=crx-unknown
+		os=-elf
+		;;
+	da30 | da30-*)
+		basic_machine=m68k-da30
+		;;
+	decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn)
+		basic_machine=mips-dec
+		;;
+	decsystem10* | dec10*)
+		basic_machine=pdp10-dec
+		os=-tops10
+		;;
+	decsystem20* | dec20*)
+		basic_machine=pdp10-dec
+		os=-tops20
+		;;
+	delta | 3300 | motorola-3300 | motorola-delta \
+	      | 3300-motorola | delta-motorola)
+		basic_machine=m68k-motorola
+		;;
+	delta88)
+		basic_machine=m88k-motorola
+		os=-sysv3
+		;;
+	dicos)
+		basic_machine=i686-pc
+		os=-dicos
+		;;
+	djgpp)
+		basic_machine=i586-pc
+		os=-msdosdjgpp
+		;;
+	dpx20 | dpx20-*)
+		basic_machine=rs6000-bull
+		os=-bosx
+		;;
+	dpx2* | dpx2*-bull)
+		basic_machine=m68k-bull
+		os=-sysv3
+		;;
+	ebmon29k)
+		basic_machine=a29k-amd
+		os=-ebmon
+		;;
+	elxsi)
+		basic_machine=elxsi-elxsi
+		os=-bsd
+		;;
+	encore | umax | mmax)
+		basic_machine=ns32k-encore
+		;;
+	es1800 | OSE68k | ose68k | ose | OSE)
+		basic_machine=m68k-ericsson
+		os=-ose
+		;;
+	fx2800)
+		basic_machine=i860-alliant
+		;;
+	genix)
+		basic_machine=ns32k-ns
+		;;
+	gmicro)
+		basic_machine=tron-gmicro
+		os=-sysv
+		;;
+	go32)
+		basic_machine=i386-pc
+		os=-go32
+		;;
+	h3050r* | hiux*)
+		basic_machine=hppa1.1-hitachi
+		os=-hiuxwe2
+		;;
+	h8300hms)
+		basic_machine=h8300-hitachi
+		os=-hms
+		;;
+	h8300xray)
+		basic_machine=h8300-hitachi
+		os=-xray
+		;;
+	h8500hms)
+		basic_machine=h8500-hitachi
+		os=-hms
+		;;
+	harris)
+		basic_machine=m88k-harris
+		os=-sysv3
+		;;
+	hp300-*)
+		basic_machine=m68k-hp
+		;;
+	hp300bsd)
+		basic_machine=m68k-hp
+		os=-bsd
+		;;
+	hp300hpux)
+		basic_machine=m68k-hp
+		os=-hpux
+		;;
+	hp3k9[0-9][0-9] | hp9[0-9][0-9])
+		basic_machine=hppa1.0-hp
+		;;
+	hp9k2[0-9][0-9] | hp9k31[0-9])
+		basic_machine=m68000-hp
+		;;
+	hp9k3[2-9][0-9])
+		basic_machine=m68k-hp
+		;;
+	hp9k6[0-9][0-9] | hp6[0-9][0-9])
+		basic_machine=hppa1.0-hp
+		;;
+	hp9k7[0-79][0-9] | hp7[0-79][0-9])
+		basic_machine=hppa1.1-hp
+		;;
+	hp9k78[0-9] | hp78[0-9])
+		# FIXME: really hppa2.0-hp
+		basic_machine=hppa1.1-hp
+		;;
+	hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893)
+		# FIXME: really hppa2.0-hp
+		basic_machine=hppa1.1-hp
+		;;
+	hp9k8[0-9][13679] | hp8[0-9][13679])
+		basic_machine=hppa1.1-hp
+		;;
+	hp9k8[0-9][0-9] | hp8[0-9][0-9])
+		basic_machine=hppa1.0-hp
+		;;
+	hppa-next)
+		os=-nextstep3
+		;;
+	hppaosf)
+		basic_machine=hppa1.1-hp
+		os=-osf
+		;;
+	hppro)
+		basic_machine=hppa1.1-hp
+		os=-proelf
+		;;
+	i370-ibm* | ibm*)
+		basic_machine=i370-ibm
+		;;
+	i*86v32)
+		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		os=-sysv32
+		;;
+	i*86v4*)
+		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		os=-sysv4
+		;;
+	i*86v)
+		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		os=-sysv
+		;;
+	i*86sol2)
+		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+		os=-solaris2
+		;;
+	i386mach)
+		basic_machine=i386-mach
+		os=-mach
+		;;
+	i386-vsta | vsta)
+		basic_machine=i386-unknown
+		os=-vsta
+		;;
+	iris | iris4d)
+		basic_machine=mips-sgi
+		case $os in
+		    -irix*)
+			;;
+		    *)
+			os=-irix4
+			;;
+		esac
+		;;
+	isi68 | isi)
+		basic_machine=m68k-isi
+		os=-sysv
+		;;
+	m68knommu)
+		basic_machine=m68k-unknown
+		os=-linux
+		;;
+	m68knommu-*)
+		basic_machine=m68k-`echo $basic_machine | sed 's/^[^-]*-//'`
+		os=-linux
+		;;
+	m88k-omron*)
+		basic_machine=m88k-omron
+		;;
+	magnum | m3230)
+		basic_machine=mips-mips
+		os=-sysv
+		;;
+	merlin)
+		basic_machine=ns32k-utek
+		os=-sysv
+		;;
+	microblaze*)
+		basic_machine=microblaze-xilinx
+		;;
+	mingw64)
+		basic_machine=x86_64-pc
+		os=-mingw64
+		;;
+	mingw32)
+		basic_machine=i686-pc
+		os=-mingw32
+		;;
+	mingw32ce)
+		basic_machine=arm-unknown
+		os=-mingw32ce
+		;;
+	miniframe)
+		basic_machine=m68000-convergent
+		;;
+	*mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*)
+		basic_machine=m68k-atari
+		os=-mint
+		;;
+	mips3*-*)
+		basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`
+		;;
+	mips3*)
+		basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown
+		;;
+	monitor)
+		basic_machine=m68k-rom68k
+		os=-coff
+		;;
+	morphos)
+		basic_machine=powerpc-unknown
+		os=-morphos
+		;;
+	msdos)
+		basic_machine=i386-pc
+		os=-msdos
+		;;
+	ms1-*)
+		basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'`
+		;;
+	msys)
+		basic_machine=i686-pc
+		os=-msys
+		;;
+	mvs)
+		basic_machine=i370-ibm
+		os=-mvs
+		;;
+	nacl)
+		basic_machine=le32-unknown
+		os=-nacl
+		;;
+	ncr3000)
+		basic_machine=i486-ncr
+		os=-sysv4
+		;;
+	netbsd386)
+		basic_machine=i386-unknown
+		os=-netbsd
+		;;
+	netwinder)
+		basic_machine=armv4l-rebel
+		os=-linux
+		;;
+	news | news700 | news800 | news900)
+		basic_machine=m68k-sony
+		os=-newsos
+		;;
+	news1000)
+		basic_machine=m68030-sony
+		os=-newsos
+		;;
+	news-3600 | risc-news)
+		basic_machine=mips-sony
+		os=-newsos
+		;;
+	necv70)
+		basic_machine=v70-nec
+		os=-sysv
+		;;
+	next | m*-next )
+		basic_machine=m68k-next
+		case $os in
+		    -nextstep* )
+			;;
+		    -ns2*)
+		      os=-nextstep2
+			;;
+		    *)
+		      os=-nextstep3
+			;;
+		esac
+		;;
+	nh3000)
+		basic_machine=m68k-harris
+		os=-cxux
+		;;
+	nh[45]000)
+		basic_machine=m88k-harris
+		os=-cxux
+		;;
+	nindy960)
+		basic_machine=i960-intel
+		os=-nindy
+		;;
+	mon960)
+		basic_machine=i960-intel
+		os=-mon960
+		;;
+	nonstopux)
+		basic_machine=mips-compaq
+		os=-nonstopux
+		;;
+	np1)
+		basic_machine=np1-gould
+		;;
+	neo-tandem)
+		basic_machine=neo-tandem
+		;;
+	nse-tandem)
+		basic_machine=nse-tandem
+		;;
+	nsr-tandem)
+		basic_machine=nsr-tandem
+		;;
+	op50n-* | op60c-*)
+		basic_machine=hppa1.1-oki
+		os=-proelf
+		;;
+	openrisc | openrisc-*)
+		basic_machine=or32-unknown
+		;;
+	os400)
+		basic_machine=powerpc-ibm
+		os=-os400
+		;;
+	OSE68000 | ose68000)
+		basic_machine=m68000-ericsson
+		os=-ose
+		;;
+	os68k)
+		basic_machine=m68k-none
+		os=-os68k
+		;;
+	pa-hitachi)
+		basic_machine=hppa1.1-hitachi
+		os=-hiuxwe2
+		;;
+	paragon)
+		basic_machine=i860-intel
+		os=-osf
+		;;
+	parisc)
+		basic_machine=hppa-unknown
+		os=-linux
+		;;
+	parisc-*)
+		basic_machine=hppa-`echo $basic_machine | sed 's/^[^-]*-//'`
+		os=-linux
+		;;
+	pbd)
+		basic_machine=sparc-tti
+		;;
+	pbb)
+		basic_machine=m68k-tti
+		;;
+	pc532 | pc532-*)
+		basic_machine=ns32k-pc532
+		;;
+	pc98)
+		basic_machine=i386-pc
+		;;
+	pc98-*)
+		basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pentium | p5 | k5 | k6 | nexgen | viac3)
+		basic_machine=i586-pc
+		;;
+	pentiumpro | p6 | 6x86 | athlon | athlon_*)
+		basic_machine=i686-pc
+		;;
+	pentiumii | pentium2 | pentiumiii | pentium3)
+		basic_machine=i686-pc
+		;;
+	pentium4)
+		basic_machine=i786-pc
+		;;
+	pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
+		basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pentiumpro-* | p6-* | 6x86-* | athlon-*)
+		basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)
+		basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pentium4-*)
+		basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	pn)
+		basic_machine=pn-gould
+		;;
+	power)	basic_machine=power-ibm
+		;;
+	ppc | ppcbe)	basic_machine=powerpc-unknown
+		;;
+	ppc-* | ppcbe-*)
+		basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	ppcle | powerpclittle | ppc-le | powerpc-little)
+		basic_machine=powerpcle-unknown
+		;;
+	ppcle-* | powerpclittle-*)
+		basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	ppc64)	basic_machine=powerpc64-unknown
+		;;
+	ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	ppc64le | powerpc64little | ppc64-le | powerpc64-little)
+		basic_machine=powerpc64le-unknown
+		;;
+	ppc64le-* | powerpc64little-*)
+		basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	ps2)
+		basic_machine=i386-ibm
+		;;
+	pw32)
+		basic_machine=i586-unknown
+		os=-pw32
+		;;
+	rdos | rdos64)
+		basic_machine=x86_64-pc
+		os=-rdos
+		;;
+	rdos32)
+		basic_machine=i386-pc
+		os=-rdos
+		;;
+	rom68k)
+		basic_machine=m68k-rom68k
+		os=-coff
+		;;
+	rm[46]00)
+		basic_machine=mips-siemens
+		;;
+	rtpc | rtpc-*)
+		basic_machine=romp-ibm
+		;;
+	s390 | s390-*)
+		basic_machine=s390-ibm
+		;;
+	s390x | s390x-*)
+		basic_machine=s390x-ibm
+		;;
+	sa29200)
+		basic_machine=a29k-amd
+		os=-udi
+		;;
+	sb1)
+		basic_machine=mipsisa64sb1-unknown
+		;;
+	sb1el)
+		basic_machine=mipsisa64sb1el-unknown
+		;;
+	sde)
+		basic_machine=mipsisa32-sde
+		os=-elf
+		;;
+	sei)
+		basic_machine=mips-sei
+		os=-seiux
+		;;
+	sequent)
+		basic_machine=i386-sequent
+		;;
+	sh)
+		basic_machine=sh-hitachi
+		os=-hms
+		;;
+	sh5el)
+		basic_machine=sh5le-unknown
+		;;
+	sh64)
+		basic_machine=sh64-unknown
+		;;
+	sparclite-wrs | simso-wrs)
+		basic_machine=sparclite-wrs
+		os=-vxworks
+		;;
+	sps7)
+		basic_machine=m68k-bull
+		os=-sysv2
+		;;
+	spur)
+		basic_machine=spur-unknown
+		;;
+	st2000)
+		basic_machine=m68k-tandem
+		;;
+	stratus)
+		basic_machine=i860-stratus
+		os=-sysv4
+		;;
+	strongarm-* | thumb-*)
+		basic_machine=arm-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
+	sun2)
+		basic_machine=m68000-sun
+		;;
+	sun2os3)
+		basic_machine=m68000-sun
+		os=-sunos3
+		;;
+	sun2os4)
+		basic_machine=m68000-sun
+		os=-sunos4
+		;;
+	sun3os3)
+		basic_machine=m68k-sun
+		os=-sunos3
+		;;
+	sun3os4)
+		basic_machine=m68k-sun
+		os=-sunos4
+		;;
+	sun4os3)
+		basic_machine=sparc-sun
+		os=-sunos3
+		;;
+	sun4os4)
+		basic_machine=sparc-sun
+		os=-sunos4
+		;;
+	sun4sol2)
+		basic_machine=sparc-sun
+		os=-solaris2
+		;;
+	sun3 | sun3-*)
+		basic_machine=m68k-sun
+		;;
+	sun4)
+		basic_machine=sparc-sun
+		;;
+	sun386 | sun386i | roadrunner)
+		basic_machine=i386-sun
+		;;
+	sv1)
+		basic_machine=sv1-cray
+		os=-unicos
+		;;
+	symmetry)
+		basic_machine=i386-sequent
+		os=-dynix
+		;;
+	t3e)
+		basic_machine=alphaev5-cray
+		os=-unicos
+		;;
+	t90)
+		basic_machine=t90-cray
+		os=-unicos
+		;;
+	tile*)
+		basic_machine=$basic_machine-unknown
+		os=-linux-gnu
+		;;
+	tx39)
+		basic_machine=mipstx39-unknown
+		;;
+	tx39el)
+		basic_machine=mipstx39el-unknown
+		;;
+	toad1)
+		basic_machine=pdp10-xkl
+		os=-tops20
+		;;
+	tower | tower-32)
+		basic_machine=m68k-ncr
+		;;
+	tpf)
+		basic_machine=s390x-ibm
+		os=-tpf
+		;;
+	udi29k)
+		basic_machine=a29k-amd
+		os=-udi
+		;;
+	ultra3)
+		basic_machine=a29k-nyu
+		os=-sym1
+		;;
+	v810 | necv810)
+		basic_machine=v810-nec
+		os=-none
+		;;
+	vaxv)
+		basic_machine=vax-dec
+		os=-sysv
+		;;
+	vms)
+		basic_machine=vax-dec
+		os=-vms
+		;;
+	vpp*|vx|vx-*)
+		basic_machine=f301-fujitsu
+		;;
+	vxworks960)
+		basic_machine=i960-wrs
+		os=-vxworks
+		;;
+	vxworks68)
+		basic_machine=m68k-wrs
+		os=-vxworks
+		;;
+	vxworks29k)
+		basic_machine=a29k-wrs
+		os=-vxworks
+		;;
+	w65*)
+		basic_machine=w65-wdc
+		os=-none
+		;;
+	w89k-*)
+		basic_machine=hppa1.1-winbond
+		os=-proelf
+		;;
+	xbox)
+		basic_machine=i686-pc
+		os=-mingw32
+		;;
+	xps | xps100)
+		basic_machine=xps100-honeywell
+		;;
+	xscale-* | xscalee[bl]-*)
+		basic_machine=`echo $basic_machine | sed 's/^xscale/arm/'`
+		;;
+	ymp)
+		basic_machine=ymp-cray
+		os=-unicos
+		;;
+	z8k-*-coff)
+		basic_machine=z8k-unknown
+		os=-sim
+		;;
+	z80-*-coff)
+		basic_machine=z80-unknown
+		os=-sim
+		;;
+	none)
+		basic_machine=none-none
+		os=-none
+		;;
+
+# Here we handle the default manufacturer of certain CPU types.  It is in
+# some cases the only manufacturer, in others, it is the most popular.
+	w89k)
+		basic_machine=hppa1.1-winbond
+		;;
+	op50n)
+		basic_machine=hppa1.1-oki
+		;;
+	op60c)
+		basic_machine=hppa1.1-oki
+		;;
+	romp)
+		basic_machine=romp-ibm
+		;;
+	mmix)
+		basic_machine=mmix-knuth
+		;;
+	rs6000)
+		basic_machine=rs6000-ibm
+		;;
+	vax)
+		basic_machine=vax-dec
+		;;
+	pdp10)
+		# there are many clones, so DEC is not a safe bet
+		basic_machine=pdp10-unknown
+		;;
+	pdp11)
+		basic_machine=pdp11-dec
+		;;
+	we32k)
+		basic_machine=we32k-att
+		;;
+	sh[1234] | sh[24]a | sh[24]aeb | sh[34]eb | sh[1234]le | sh[23]ele)
+		basic_machine=sh-unknown
+		;;
+	sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v)
+		basic_machine=sparc-sun
+		;;
+	cydra)
+		basic_machine=cydra-cydrome
+		;;
+	orion)
+		basic_machine=orion-highlevel
+		;;
+	orion105)
+		basic_machine=clipper-highlevel
+		;;
+	mac | mpw | mac-mpw)
+		basic_machine=m68k-apple
+		;;
+	pmac | pmac-mpw)
+		basic_machine=powerpc-apple
+		;;
+	*-unknown)
+		# Make sure to match an already-canonicalized machine name.
+		;;
+	*)
+		echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
+		exit 1
+		;;
+esac
+
+# Here we canonicalize certain aliases for manufacturers.
+case $basic_machine in
+	*-digital*)
+		basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'`
+		;;
+	*-commodore*)
+		basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'`
+		;;
+	*)
+		;;
+esac
+
+# Decode manufacturer-specific aliases for certain operating systems.
+
+if [ x"$os" != x"" ]
+then
+case $os in
+	# First match some system type aliases
+	# that might get confused with valid system types.
+	# -solaris* is a basic system type, with this one exception.
+	-auroraux)
+		os=-auroraux
+		;;
+	-solaris1 | -solaris1.*)
+		os=`echo $os | sed -e 's|solaris1|sunos4|'`
+		;;
+	-solaris)
+		os=-solaris2
+		;;
+	-svr4*)
+		os=-sysv4
+		;;
+	-unixware*)
+		os=-sysv4.2uw
+		;;
+	-gnu/linux*)
+		os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`
+		;;
+	# First accept the basic system types.
+	# The portable systems comes first.
+	# Each alternative MUST END IN A *, to match a version number.
+	# -sysv* is not here because it comes later, after sysvr4.
+	-gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
+	      | -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\
+	      | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \
+	      | -sym* | -kopensolaris* | -plan9* \
+	      | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
+	      | -aos* | -aros* \
+	      | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
+	      | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
+	      | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \
+	      | -bitrig* | -openbsd* | -solidbsd* \
+	      | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \
+	      | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
+	      | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
+	      | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
+	      | -chorusos* | -chorusrdb* | -cegcc* \
+	      | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
+	      | -mingw32* | -mingw64* | -linux-gnu* \
+	      | -linux-newlib* | -linux-musl* | -linux-uclibc* \
+	      | -uxpv* | -beos* | -mpeix* | -udk* \
+	      | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
+	      | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
+	      | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
+	      | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
+	      | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
+	      | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
+	      | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es*)
+	# Remember, each alternative MUST END IN *, to match a version number.
+		;;
+	-qnx*)
+		case $basic_machine in
+		    x86-* | i*86-*)
+			;;
+		    *)
+			os=-nto$os
+			;;
+		esac
+		;;
+	-nto-qnx*)
+		;;
+	-nto*)
+		os=`echo $os | sed -e 's|nto|nto-qnx|'`
+		;;
+	-sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \
+	      | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \
+	      | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*)
+		;;
+	-mac*)
+		os=`echo $os | sed -e 's|mac|macos|'`
+		;;
+	-linux-dietlibc)
+		os=-linux-dietlibc
+		;;
+	-linux*)
+		os=`echo $os | sed -e 's|linux|linux-gnu|'`
+		;;
+	-sunos5*)
+		os=`echo $os | sed -e 's|sunos5|solaris2|'`
+		;;
+	-sunos6*)
+		os=`echo $os | sed -e 's|sunos6|solaris3|'`
+		;;
+	-opened*)
+		os=-openedition
+		;;
+	-os400*)
+		os=-os400
+		;;
+	-wince*)
+		os=-wince
+		;;
+	-osfrose*)
+		os=-osfrose
+		;;
+	-osf*)
+		os=-osf
+		;;
+	-utek*)
+		os=-bsd
+		;;
+	-dynix*)
+		os=-bsd
+		;;
+	-acis*)
+		os=-aos
+		;;
+	-atheos*)
+		os=-atheos
+		;;
+	-syllable*)
+		os=-syllable
+		;;
+	-386bsd)
+		os=-bsd
+		;;
+	-ctix* | -uts*)
+		os=-sysv
+		;;
+	-nova*)
+		os=-rtmk-nova
+		;;
+	-ns2 )
+		os=-nextstep2
+		;;
+	-nsk*)
+		os=-nsk
+		;;
+	# Preserve the version number of sinix5.
+	-sinix5.*)
+		os=`echo $os | sed -e 's|sinix|sysv|'`
+		;;
+	-sinix*)
+		os=-sysv4
+		;;
+	-tpf*)
+		os=-tpf
+		;;
+	-triton*)
+		os=-sysv3
+		;;
+	-oss*)
+		os=-sysv3
+		;;
+	-svr4)
+		os=-sysv4
+		;;
+	-svr3)
+		os=-sysv3
+		;;
+	-sysvr4)
+		os=-sysv4
+		;;
+	# This must come after -sysvr4.
+	-sysv*)
+		;;
+	-ose*)
+		os=-ose
+		;;
+	-es1800*)
+		os=-ose
+		;;
+	-xenix)
+		os=-xenix
+		;;
+	-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
+		os=-mint
+		;;
+	-aros*)
+		os=-aros
+		;;
+	-zvmoe)
+		os=-zvmoe
+		;;
+	-dicos*)
+		os=-dicos
+		;;
+	-nacl*)
+		;;
+	-android*)
+		os=-android
+		;;
+	-none)
+		;;
+	*)
+		# Get rid of the `-' at the beginning of $os.
+		os=`echo $os | sed 's/[^-]*-//'`
+		echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2
+		exit 1
+		;;
+esac
+else
+
+# Here we handle the default operating systems that come with various machines.
+# The value should be what the vendor currently ships out the door with their
+# machine or put another way, the most popular os provided with the machine.
+
+# Note that if you're going to try to match "-MANUFACTURER" here (say,
+# "-sun"), then you have to tell the case statement up towards the top
+# that MANUFACTURER isn't an operating system.  Otherwise, code above
+# will signal an error saying that MANUFACTURER isn't an operating
+# system, and we'll never get to this point.
+
+case $basic_machine in
+	score-*)
+		os=-elf
+		;;
+	spu-*)
+		os=-elf
+		;;
+	*-acorn)
+		os=-riscix1.2
+		;;
+	arm*-rebel)
+		os=-linux
+		;;
+	arm*-semi)
+		os=-aout
+		;;
+	c4x-* | tic4x-*)
+		os=-coff
+		;;
+	c8051-*)
+		os=-elf
+		;;
+	hexagon-*)
+		os=-elf
+		;;
+	tic54x-*)
+		os=-coff
+		;;
+	tic55x-*)
+		os=-coff
+		;;
+	tic6x-*)
+		os=-coff
+		;;
+	# This must come before the *-dec entry.
+	pdp10-*)
+		os=-tops20
+		;;
+	pdp11-*)
+		os=-none
+		;;
+	*-dec | vax-*)
+		os=-ultrix4.2
+		;;
+	m68*-apollo)
+		os=-domain
+		;;
+	i386-sun)
+		os=-sunos4.0.2
+		;;
+	m68000-sun)
+		os=-sunos3
+		;;
+	m68*-cisco)
+		os=-aout
+		;;
+	mep-*)
+		os=-elf
+		;;
+	mips*-cisco)
+		os=-elf
+		;;
+	mips*-*)
+		os=-elf
+		;;
+	or1k-*)
+		os=-elf
+		;;
+	or32-*)
+		os=-coff
+		;;
+	*-tti)	# must be before sparc entry or we get the wrong os.
+		os=-sysv3
+		;;
+	sparc-* | *-sun)
+		os=-sunos4.1.1
+		;;
+	*-be)
+		os=-beos
+		;;
+	*-haiku)
+		os=-haiku
+		;;
+	*-ibm)
+		os=-aix
+		;;
+	*-knuth)
+		os=-mmixware
+		;;
+	*-wec)
+		os=-proelf
+		;;
+	*-winbond)
+		os=-proelf
+		;;
+	*-oki)
+		os=-proelf
+		;;
+	*-hp)
+		os=-hpux
+		;;
+	*-hitachi)
+		os=-hiux
+		;;
+	i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent)
+		os=-sysv
+		;;
+	*-cbm)
+		os=-amigaos
+		;;
+	*-dg)
+		os=-dgux
+		;;
+	*-dolphin)
+		os=-sysv3
+		;;
+	m68k-ccur)
+		os=-rtu
+		;;
+	m88k-omron*)
+		os=-luna
+		;;
+	*-next )
+		os=-nextstep
+		;;
+	*-sequent)
+		os=-ptx
+		;;
+	*-crds)
+		os=-unos
+		;;
+	*-ns)
+		os=-genix
+		;;
+	i370-*)
+		os=-mvs
+		;;
+	*-next)
+		os=-nextstep3
+		;;
+	*-gould)
+		os=-sysv
+		;;
+	*-highlevel)
+		os=-bsd
+		;;
+	*-encore)
+		os=-bsd
+		;;
+	*-sgi)
+		os=-irix
+		;;
+	*-siemens)
+		os=-sysv4
+		;;
+	*-masscomp)
+		os=-rtu
+		;;
+	f30[01]-fujitsu | f700-fujitsu)
+		os=-uxpv
+		;;
+	*-rom68k)
+		os=-coff
+		;;
+	*-*bug)
+		os=-coff
+		;;
+	*-apple)
+		os=-macos
+		;;
+	*-atari*)
+		os=-mint
+		;;
+	*)
+		os=-none
+		;;
+esac
+fi
+
+# Here we handle the case where we know the os, and the CPU type, but not the
+# manufacturer.  We pick the logical manufacturer.
+vendor=unknown
+case $basic_machine in
+	*-unknown)
+		case $os in
+			-riscix*)
+				vendor=acorn
+				;;
+			-sunos*)
+				vendor=sun
+				;;
+			-cnk*|-aix*)
+				vendor=ibm
+				;;
+			-beos*)
+				vendor=be
+				;;
+			-hpux*)
+				vendor=hp
+				;;
+			-mpeix*)
+				vendor=hp
+				;;
+			-hiux*)
+				vendor=hitachi
+				;;
+			-unos*)
+				vendor=crds
+				;;
+			-dgux*)
+				vendor=dg
+				;;
+			-luna*)
+				vendor=omron
+				;;
+			-genix*)
+				vendor=ns
+				;;
+			-mvs* | -opened*)
+				vendor=ibm
+				;;
+			-os400*)
+				vendor=ibm
+				;;
+			-ptx*)
+				vendor=sequent
+				;;
+			-tpf*)
+				vendor=ibm
+				;;
+			-vxsim* | -vxworks* | -windiss*)
+				vendor=wrs
+				;;
+			-aux*)
+				vendor=apple
+				;;
+			-hms*)
+				vendor=hitachi
+				;;
+			-mpw* | -macos*)
+				vendor=apple
+				;;
+			-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
+				vendor=atari
+				;;
+			-vos*)
+				vendor=stratus
+				;;
+			*-android*|*-linuxandroid*)
+				vendor=linux-
+				;;
+		esac
+		basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"`
+		;;
+esac
+
+echo $basic_machine$os
+exit
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "timestamp='"
+# time-stamp-format: "%:y-%02m-%02d"
+# time-stamp-end: "'"
+# End:
diff --git a/build/autoconf/install-sh b/build/autoconf/install-sh
new file mode 100755
index 0000000..a4be13e
--- /dev/null
+++ b/build/autoconf/install-sh
@@ -0,0 +1,123 @@
+#!/bin/sh
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+#
+# install - install a program, script, or datafile
+# This comes from X11R5; it is not part of GNU.
+#
+# $XConsortium: install.sh,v 1.2 89/12/18 14:47:22 jim Exp $
+#
+# This script is compatible with the BSD install script, but was written
+# from scratch.
+#
+
+
+# set DOITPROG to echo to test this script
+
+# Don't use :- since 4.3BSD and earlier shells don't like it.
+doit="${DOITPROG-}"
+
+
+# put in absolute paths if you don't have them in your path; or use env. vars.
+
+mvprog="${MVPROG-mv}"
+cpprog="${CPPROG-cp}"
+chmodprog="${CHMODPROG-chmod}"
+chownprog="${CHOWNPROG-chown}"
+chgrpprog="${CHGRPPROG-chgrp}"
+stripprog="${STRIPPROG-strip}"
+rmprog="${RMPROG-rm}"
+
+instcmd="$mvprog"
+chmodcmd=""
+chowncmd=""
+chgrpcmd=""
+stripcmd=""
+rmcmd="$rmprog -f"
+mvcmd="$mvprog"
+src=""
+dst=""
+
+while [ x"$1" != x ]; do
+    case $1 in
+	-c) instcmd="$cpprog"
+	    shift
+	    continue;;
+
+	-m) chmodcmd="$chmodprog $2"
+	    shift
+	    shift
+	    continue;;
+
+	-o) chowncmd="$chownprog $2"
+	    shift
+	    shift
+	    continue;;
+
+	-g) chgrpcmd="$chgrpprog $2"
+	    shift
+	    shift
+	    continue;;
+
+	-s) stripcmd="$stripprog"
+	    shift
+	    continue;;
+
+	*)  if [ x"$src" = x ]
+	    then
+		src=$1
+	    else
+		dst=$1
+	    fi
+	    shift
+	    continue;;
+    esac
+done
+
+if [ x"$src" = x ]
+then
+	echo "install:  no input file specified"
+	exit 1
+fi
+
+if [ x"$dst" = x ]
+then
+	echo "install:  no destination specified"
+	exit 1
+fi
+
+
+# If destination is a directory, append the input filename; if your system
+# does not like double slashes in filenames, you may need to add some logic
+
+if [ -d $dst ]
+then
+	dst="$dst"/`basename $src`
+fi
+
+# Make a temp file name in the proper directory.
+
+dstdir=`dirname $dst`
+dsttmp=$dstdir/#inst.$$#
+
+# Move or copy the file name to the temp name
+
+$doit $instcmd $src $dsttmp
+
+# and set any options; do chmod last to preserve setuid bits
+
+if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; fi
+if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; fi
+if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; fi
+if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; fi
+
+# Now rename the file to the real destination.
+
+$doit $rmcmd $dst
+$doit $mvcmd $dsttmp $dst
+
+
+exit 0
diff --git a/build/autoconf/patches/config.sub.patch b/build/autoconf/patches/config.sub.patch
new file mode 100644
index 0000000..f3afca2
--- /dev/null
+++ b/build/autoconf/patches/config.sub.patch
@@ -0,0 +1,51 @@
+--- config.sub.orig	2014-03-09 18:34:03 -0700
++++ config.sub	2014-03-14 19:49:48 -0700
+@@ -115,7 +115,7 @@
+ # Here we must recognize all the valid KERNEL-OS combinations.
+ maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
+ case $maybe_os in
+-  nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \
++  nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | \
+   linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \
+   knetbsd*-gnu* | netbsd*-gnu* | \
+   kopensolaris*-gnu* | \
+@@ -123,10 +123,6 @@
+     os=-$maybe_os
+     basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
+     ;;
+-  android-linux)
+-    os=-linux-android
+-    basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`-unknown
+-    ;;
+   *)
+     basic_machine=`echo $1 | sed 's/-[^-]*$//'`
+     if [ $basic_machine != $1 ]
+@@ -1367,7 +1363,7 @@
+ 	      | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
+ 	      | -chorusos* | -chorusrdb* | -cegcc* \
+ 	      | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
+-	      | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \
++	      | -mingw32* | -mingw64* | -linux-gnu* \
+ 	      | -linux-newlib* | -linux-musl* | -linux-uclibc* \
+ 	      | -uxpv* | -beos* | -mpeix* | -udk* \
+ 	      | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
+@@ -1508,6 +1504,9 @@
+ 		;;
+ 	-nacl*)
+ 		;;
++	-android*)
++		os=-android
++		;;
+ 	-none)
+ 		;;
+ 	*)
+@@ -1777,6 +1776,9 @@
+ 			-vos*)
+ 				vendor=stratus
+ 				;;
++			*-android*|*-linuxandroid*)
++				vendor=linux-
++				;;
+ 		esac
+ 		basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"`
+ 		;;
diff --git a/build/cygwin-wrapper b/build/cygwin-wrapper
new file mode 100755
index 0000000..3302df8
--- /dev/null
+++ b/build/cygwin-wrapper
@@ -0,0 +1,79 @@
+#!/bin/sh
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#
+# Stupid wrapper to avoid win32 dospath/cygdrive issues
+# Try not to spawn programs from within this file. If the stuff in here looks royally 
+# confusing, see bug: http://bugzilla.mozilla.org/show_bug.cgi?id=206643
+# and look at the older versions of this file that are easier to read, but
+# do basically the same thing
+#
+
+prog=$1
+shift
+if test -z "$prog"; then
+    exit 0
+fi
+
+# If $CYGDRIVE_MOUNT was not set in configure, give $mountpoint the results of mount -p
+mountpoint=$CYGDRIVE_MOUNT
+if test -z "$mountpoint"; then
+    mountpoint=`mount -p`
+    if test -z "$mountpoint"; then
+       print "Cannot determine cygwin mount points. Exiting"
+       exit 1
+    fi
+fi
+
+# Delete everything but "/cygdrive" (or other mountpoint) from mount=`mount -p`
+mountpoint=${mountpoint#*/}
+mountpoint=/${mountpoint%%[!A-Za-z0-9_]*}
+mountpoint=${mountpoint%/}
+
+args=""
+up=""
+if test "${prog}" = "-up"; then
+    up=1
+    prog=${1}
+    shift
+fi
+
+process=1
+
+# Convert the mountpoint in parameters to Win32 filenames
+# For instance: /cygdrive/c/foo -> c:/foo
+for i in "${@}"
+do
+    if test "${i}" = "-wrap"; then
+        process=1
+    else
+        if test "${i}" = "-nowrap"; then
+            process=
+        else
+            if test -n "${process}"; then
+                if test -n "${up}"; then
+                    pathname=${i#-I[a-zA-Z]:/}
+                    if ! test "${pathname}" = "${i}"; then
+                        no_i=${i#-I}
+                        driveletter=${no_i%%:*}
+                        i=-I${mountpoint}/${driveletter}/${pathname}
+                    fi
+                else
+                    eval 'leader=${i%%'${mountpoint}'/[a-zA-Z]/*}'
+                    if ! test "${leader}" = "${i}"; then
+                        eval 'pathname=${i#'${leader}${mountpoint}'/[a-zA-Z]/}'
+                        eval 'no_mountpoint=${i#'${leader}${mountpoint}'/}'
+                        driveletter=${no_mountpoint%%/*}
+                        i=${leader}${driveletter}:/${pathname}
+                    fi
+                fi
+            fi
+
+            args="${args} ${i}"
+        fi
+    fi
+done
+
+exec $prog $args
diff --git a/build/win32/pgomerge.py b/build/win32/pgomerge.py
new file mode 100644
index 0000000..313d668
--- /dev/null
+++ b/build/win32/pgomerge.py
@@ -0,0 +1,44 @@
+#!/usr/bin/python
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# Usage: pgomerge.py <binary basename> <dist/bin>
+# Gathers .pgc files from dist/bin and merges them into
+# $PWD/$basename.pgd using pgomgr, then deletes them.
+# No errors if any of these files don't exist.
+
+import sys, os, os.path, subprocess
+if not sys.platform == "win32":
+    raise Exception("This script was only meant for Windows.")
+
+def MergePGOFiles(basename, pgddir, pgcdir):
+  """Merge pgc files produced from an instrumented binary
+     into the pgd file for the second pass of profile-guided optimization
+     with MSVC.  |basename| is the name of the DLL or EXE without the
+     extension.  |pgddir| is the path that contains <basename>.pgd
+     (should be the objdir it was built in).  |pgcdir| is the path
+     containing basename!N.pgc files, which is probably dist/bin.
+     Calls pgomgr to merge each pgc file into the pgd, then deletes
+     the pgc files."""
+  if not os.path.isdir(pgddir) or not os.path.isdir(pgcdir):
+    return
+  pgdfile = os.path.abspath(os.path.join(pgddir, basename + ".pgd"))
+  if not os.path.isfile(pgdfile):
+    return
+  for file in os.listdir(pgcdir):
+    if file.startswith(basename+"!") and file.endswith(".pgc"):
+      try:
+        pgcfile = os.path.normpath(os.path.join(pgcdir, file))
+        subprocess.call(['pgomgr', '-merge',
+                         pgcfile,
+                         pgdfile])
+        os.remove(pgcfile)
+      except OSError:
+        pass
+
+if __name__ == '__main__':
+  if len(sys.argv) != 3:
+      print >>sys.stderr, "Usage: pgomerge.py <binary basename> <dist/bin>"
+      sys.exit(1)
+  MergePGOFiles(sys.argv[1], os.getcwd(), sys.argv[2])
diff --git a/config/.cvsignore b/config/.cvsignore
new file mode 100644
index 0000000..bb3ee4b
--- /dev/null
+++ b/config/.cvsignore
@@ -0,0 +1,11 @@
+nfspwd
+revdepth
+my_config.mk
+my_overrides.mk
+autoconf.mk
+nsprincl.mk
+nsprincl.sh
+now
+Makefile
+nsinstall
+nspr-config
diff --git a/config/Makefile.in b/config/Makefile.in
new file mode 100644
index 0000000..7062c5c
--- /dev/null
+++ b/config/Makefile.in
@@ -0,0 +1,124 @@
+#! gmake
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+MOD_DEPTH	= ..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+
+include $(MOD_DEPTH)/config/autoconf.mk
+
+# Indicate that this directory builds build tools.
+INTERNAL_TOOLS	= 1
+
+# For sanity's sake, we compile nsinstall without the wrapped system
+# headers, so that we can use it to set up the wrapped system headers.
+VISIBILITY_FLAGS =
+
+# autoconf.mk must be deleted last (from the top-level directory)
+# because it is included by every makefile.
+DIST_GARBAGE	= nsprincl.mk nsprincl.sh nspr-config nspr.pc
+
+RELEASE_BINS	= nspr-config
+
+include $(topsrcdir)/config/config.mk
+
+CSRCS	= now.c
+
+# This version hasn't been ported for us; the one in mozilla/config has
+ifneq ($(OS_ARCH),OS2)
+CSRCS  += nsinstall.c
+ 
+PLSRCS	= nfspwd.pl
+endif
+
+ifeq (,$(CROSS_COMPILE)$(filter-out WINNT OS2,$(OS_ARCH)))
+PROG_SUFFIX = .exe
+else
+PROG_SUFFIX =
+endif
+
+# Temporary workaround to disable the generation of
+# library build time because now.c uses the 'long long'
+# data type that's not available on some platforms.
+ifeq (,$(filter-out QNX SCOOS UNIXWARE,$(OS_ARCH)))
+DEFINES += -DOMIT_LIB_BUILD_TIME
+endif
+
+ifeq ($(OS_ARCH), IRIX)
+    ifeq ($(basename $(OS_RELEASE)),6)
+        ifndef NS_USE_GCC
+            ifeq ($(USE_N32),1)
+                XLDOPTS += -n32 -Wl,-woff,85
+            else
+                ifeq ($(USE_64),1)
+                    XLDOPTS += -64
+                else
+                    XLDOPTS += -32
+                endif
+            endif
+        endif
+    endif
+endif
+
+ifeq ($(OS_ARCH), HP-UX)
+    ifeq ($(USE_64),1)
+        XLDOPTS += +DD64
+    endif
+endif
+
+ifeq ($(OS_ARCH), OS2)
+XCFLAGS = $(OS_CFLAGS)
+endif
+
+include $(topsrcdir)/config/rules.mk
+
+PROGS	= $(OBJDIR)/now$(PROG_SUFFIX)
+
+ifeq (,$(CROSS_COMPILE)$(filter-out OS2 WINNT,$(OS_ARCH)))
+TARGETS = $(PROGS)
+else
+ifeq (,$(filter-out SYMBIAN WINCE,$(OS_ARCH)))
+TARGETS = $(PROGS)
+else
+PROGS	+= $(OBJDIR)/nsinstall$(PROG_SUFFIX)
+TARGETS = $(PROGS) $(PLSRCS:.pl=)
+endif
+endif
+
+OUTOPTION = -o # end of the line
+ifeq (,$(filter-out WINNT WIN95 WINCE,$(OS_TARGET)))
+ifndef NS_USE_GCC
+OUTOPTION = -Fe
+endif
+endif
+
+# Redefine MAKE_OBJDIR for just this directory
+define MAKE_OBJDIR
+if test ! -d $(@D); then rm -rf $(@D); mkdir $(@D); else true; fi
+endef
+
+export:: $(TARGETS)
+	rm -f $(dist_bindir)/nspr-config
+
+ifdef WRAP_SYSTEM_INCLUDES
+export::
+	if test ! -d system_wrappers; then mkdir system_wrappers; fi
+	$(PERL) $(srcdir)/make-system-wrappers.pl system_wrappers < $(srcdir)/system-headers
+	$(INSTALL) system_wrappers $(dist_includedir)
+endif
+
+$(OBJDIR)/%$(PROG_SUFFIX): $(OBJDIR)/%.$(OBJ_SUFFIX)
+	@$(MAKE_OBJDIR)
+	$(CC) $(XCFLAGS) $< $(LDFLAGS) $(XLDOPTS) $(OUTOPTION)$@
+
+install:: nspr.m4
+	$(NSINSTALL) -D $(DESTDIR)$(datadir)/aclocal
+	$(NSINSTALL) -t -m 0644 $< $(DESTDIR)$(datadir)/aclocal
+
+install:: nspr.pc
+	$(NSINSTALL) -D $(DESTDIR)$(libdir)/pkgconfig
+	$(NSINSTALL) -t -m 0644 $< $(DESTDIR)$(libdir)/pkgconfig
diff --git a/config/autoconf.mk.in b/config/autoconf.mk.in
new file mode 100644
index 0000000..8c9a43a
--- /dev/null
+++ b/config/autoconf.mk.in
@@ -0,0 +1,148 @@
+# -*- Mode: Makefile -*-
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+INCLUDED_AUTOCONF_MK = 1
+USE_AUTOCONF	= 1
+@SHELL_OVERRIDE@
+MOZILLA_CLIENT	= @MOZILLA_CLIENT@
+
+prefix		= @prefix@
+exec_prefix	= @exec_prefix@
+bindir		= @bindir@
+includedir	= @includedir@
+libdir		= @libdir@
+datarootdir	= @datarootdir@
+datadir		= @datadir@
+
+dist_prefix	= @dist_prefix@
+dist_bindir	= @dist_bindir@
+dist_includedir = @dist_includedir@
+dist_libdir	= @dist_libdir@
+
+DIST		= $(dist_prefix)
+
+RELEASE_OBJDIR_NAME = @RELEASE_OBJDIR_NAME@
+OBJDIR_NAME	= @OBJDIR_NAME@
+OBJDIR		= @OBJDIR@
+# We do magic with OBJ_SUFFIX in config.mk, the following ensures we don't
+# manually use it before config.mk inclusion
+OBJ_SUFFIX	= $(error config/config.mk needs to be included before using OBJ_SUFFIX)
+_OBJ_SUFFIX	= @OBJ_SUFFIX@
+LIB_SUFFIX	= @LIB_SUFFIX@
+DLL_SUFFIX	= @DLL_SUFFIX@
+ASM_SUFFIX	= @ASM_SUFFIX@
+MOD_NAME	= @NSPR_MODNAME@
+
+MOD_MAJOR_VERSION = @MOD_MAJOR_VERSION@
+MOD_MINOR_VERSION = @MOD_MINOR_VERSION@
+MOD_PATCH_VERSION = @MOD_PATCH_VERSION@
+
+LIBNSPR		= @LIBNSPR@
+LIBPLC		= @LIBPLC@
+
+CROSS_COMPILE	= @CROSS_COMPILE@
+MOZ_OPTIMIZE	= @MOZ_OPTIMIZE@
+MOZ_DEBUG	= @MOZ_DEBUG@
+MOZ_DEBUG_SYMBOLS = @MOZ_DEBUG_SYMBOLS@
+
+USE_CPLUS	= @USE_CPLUS@
+USE_IPV6	= @USE_IPV6@
+USE_N32		= @USE_N32@
+USE_X32		= @USE_X32@
+USE_64		= @USE_64@
+ENABLE_STRIP	= @ENABLE_STRIP@
+
+USE_PTHREADS	= @USE_PTHREADS@
+USE_BTHREADS	= @USE_BTHREADS@
+PTHREADS_USER	= @USE_USER_PTHREADS@
+CLASSIC_NSPR	= @USE_NSPR_THREADS@
+
+AS		= @AS@
+ASFLAGS		= @ASFLAGS@
+CC		= @CC@
+CCC		= @CXX@
+NS_USE_GCC	= @GNU_CC@
+GCC_USE_GNU_LD	= @GCC_USE_GNU_LD@
+MSC_VER		= @MSC_VER@
+AR		= @AR@
+AR_FLAGS	= @AR_FLAGS@
+LD		= @LD@
+RANLIB		= @RANLIB@
+PERL		= @PERL@
+RC		= @RC@
+RCFLAGS		= @RCFLAGS@
+STRIP		= @STRIP@
+NSINSTALL	= @NSINSTALL@
+FILTER		= @FILTER@
+IMPLIB		= @IMPLIB@
+CYGWIN_WRAPPER	= @CYGWIN_WRAPPER@
+MT		= @MT@
+
+OS_CPPFLAGS	= @CPPFLAGS@
+OS_CFLAGS	= $(OS_CPPFLAGS) @CFLAGS@ $(DSO_CFLAGS)
+OS_CXXFLAGS	= $(OS_CPPFLAGS) @CXXFLAGS@ $(DSO_CFLAGS)
+OS_LIBS         = @OS_LIBS@
+OS_LDFLAGS	= @LDFLAGS@
+OS_DLLFLAGS	= @OS_DLLFLAGS@
+DLLFLAGS	= @DLLFLAGS@
+EXEFLAGS  = @EXEFLAGS@
+OPTIMIZER	= @OPTIMIZER@
+
+PROFILE_GEN_CFLAGS  = @PROFILE_GEN_CFLAGS@
+PROFILE_GEN_LDFLAGS = @PROFILE_GEN_LDFLAGS@
+PROFILE_USE_CFLAGS  = @PROFILE_USE_CFLAGS@
+PROFILE_USE_LDFLAGS = @PROFILE_USE_LDFLAGS@
+
+MKSHLIB		= @MKSHLIB@
+WRAP_LDFLAGS	= @WRAP_LDFLAGS@
+DSO_CFLAGS	= @DSO_CFLAGS@
+DSO_LDOPTS	= @DSO_LDOPTS@
+
+RESOLVE_LINK_SYMBOLS = @RESOLVE_LINK_SYMBOLS@
+
+HOST_CC		= @HOST_CC@
+HOST_CFLAGS	= @HOST_CFLAGS@
+HOST_LDFLAGS	= @HOST_LDFLAGS@
+
+DEFINES		= @DEFINES@ @DEFS@
+
+MDCPUCFG_H	= @MDCPUCFG_H@
+PR_MD_CSRCS	= @PR_MD_CSRCS@
+PR_MD_ASFILES	= @PR_MD_ASFILES@
+PR_MD_ARCH_DIR	= @PR_MD_ARCH_DIR@
+CPU_ARCH	= @CPU_ARCH@
+
+OS_TARGET	= @OS_TARGET@
+OS_ARCH		= @OS_ARCH@
+OS_RELEASE	= @OS_RELEASE@
+OS_TEST		= @OS_TEST@
+
+NOSUCHFILE	= @NOSUCHFILE@
+AIX_LINK_OPTS	= @AIX_LINK_OPTS@
+MOZ_OBJFORMAT	= @MOZ_OBJFORMAT@
+ULTRASPARC_LIBRARY = @ULTRASPARC_LIBRARY@
+
+OBJECT_MODE	= @OBJECT_MODE@
+ifdef OBJECT_MODE
+export OBJECT_MODE
+endif
+
+VISIBILITY_FLAGS = @VISIBILITY_FLAGS@
+WRAP_SYSTEM_INCLUDES = @WRAP_SYSTEM_INCLUDES@
+
+MACOSX_DEPLOYMENT_TARGET = @MACOSX_DEPLOYMENT_TARGET@
+ifdef MACOSX_DEPLOYMENT_TARGET
+export MACOSX_DEPLOYMENT_TARGET
+endif
+
+MACOS_SDK_DIR	= @MACOS_SDK_DIR@
+
+SYMBIAN_SDK_DIR = @SYMBIAN_SDK_DIR@
+
+NEXT_ROOT	= @NEXT_ROOT@
+ifdef NEXT_ROOT
+export NEXT_ROOT
+endif
diff --git a/config/config.mk b/config/config.mk
new file mode 100644
index 0000000..05db076
--- /dev/null
+++ b/config/config.mk
@@ -0,0 +1,169 @@
+#! gmake
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# Configuration information for building in the NSPR source module
+
+# Define an include-at-most-once-flag
+NSPR_CONFIG_MK	= 1
+
+#
+# The variable definitions in this file are inputs to NSPR's
+# build system.  This file, if present, is included at the
+# beginning of config.mk.
+#
+# For example:
+#
+# MOZ_OPTIMIZE=1
+# USE_PTHREADS=1
+# NS_USE_GCC=
+#
+ifndef topsrcdir
+topsrcdir=$(MOD_DEPTH)
+endif
+
+ifndef srcdir
+srcdir=.
+endif
+
+NFSPWD		= $(MOD_DEPTH)/config/nfspwd
+
+CFLAGS		= $(VISIBILITY_FLAGS) $(CC_ONLY_FLAGS) $(OPTIMIZER)\
+		  $(OS_CFLAGS) $(XP_DEFINE) $(DEFINES) $(INCLUDES) $(XCFLAGS)
+CCCFLAGS	= $(VISIBILITY_FLAGS) $(CCC_ONLY_FLAGS) $(OPTIMIZER)\
+		  $(OS_CFLAGS) $(XP_DEFINE) $(DEFINES) $(INCLUDES) $(XCFLAGS)
+# For purify
+NOMD_CFLAGS	= $(CC_ONLY_FLAGS) $(OPTIMIZER) $(NOMD_OS_CFLAGS)\
+		  $(XP_DEFINE) $(DEFINES) $(INCLUDES) $(XCFLAGS)
+NOMD_CCFLAGS	= $(CCC_ONLY_FLAGS) $(OPTIMIZER) $(NOMD_OS_CFLAGS)\
+		  $(XP_DEFINE) $(DEFINES) $(INCLUDES) $(XCFLAGS)
+
+LDFLAGS		= $(OS_LDFLAGS)
+
+# Enable profile-guided optimization
+ifndef NO_PROFILE_GUIDED_OPTIMIZE
+ifdef MOZ_PROFILE_GENERATE
+CFLAGS += $(PROFILE_GEN_CFLAGS)
+LDFLAGS += $(PROFILE_GEN_LDFLAGS)
+DLLFLAGS += $(PROFILE_GEN_LDFLAGS)
+ifeq (WINNT,$(OS_ARCH))
+AR_FLAGS += -LTCG
+endif
+endif # MOZ_PROFILE_GENERATE
+
+ifdef MOZ_PROFILE_USE
+CFLAGS += $(PROFILE_USE_CFLAGS)
+LDFLAGS += $(PROFILE_USE_LDFLAGS)
+DLLFLAGS += $(PROFILE_USE_LDFLAGS)
+ifeq (WINNT,$(OS_ARCH))
+AR_FLAGS += -LTCG
+endif
+endif # MOZ_PROFILE_USE
+endif # NO_PROFILE_GUIDED_OPTIMIZE
+
+define MAKE_OBJDIR
+if test ! -d $(@D); then rm -rf $(@D); $(NSINSTALL) -D $(@D); fi
+endef
+
+LINK_DLL	= $(LD) $(OS_DLLFLAGS) $(DLLFLAGS)
+
+ifeq ($(OS_ARCH),Darwin)
+PWD := $(shell pwd)
+endif
+
+ifeq (,$(CROSS_COMPILE)$(filter-out WINNT OS2, $(OS_ARCH)))
+INSTALL		= $(NSINSTALL)
+else
+ifeq ($(NSDISTMODE),copy)
+# copy files, but preserve source mtime
+INSTALL		= $(NSINSTALL) -t
+else
+ifeq ($(NSDISTMODE),absolute_symlink)
+# install using absolute symbolic links
+ifeq ($(OS_ARCH),Darwin)
+INSTALL		= $(NSINSTALL) -L $(PWD)
+else
+INSTALL		= $(NSINSTALL) -L `$(NFSPWD)`
+endif
+else
+# install using relative symbolic links
+INSTALL		= $(NSINSTALL) -R
+endif
+endif
+endif # (WINNT || OS2) && !CROSS_COMPILE
+
+DEPENDENCIES	= $(OBJDIR)/.md
+
+ifdef BUILD_DEBUG_GC
+DEFINES		+= -DDEBUG_GC
+endif
+
+GARBAGE		+= $(DEPENDENCIES) core $(wildcard core.[0-9]*)
+
+DIST_GARBAGE += Makefile
+
+####################################################################
+#
+# The NSPR-specific configuration
+#
+####################################################################
+
+DEFINES += -DFORCE_PR_LOG
+
+ifeq ($(_PR_NO_CLOCK_TIMER),1)
+DEFINES += -D_PR_NO_CLOCK_TIMER
+endif
+
+ifeq ($(USE_PTHREADS), 1)
+DEFINES += -D_PR_PTHREADS -UHAVE_CVAR_BUILT_ON_SEM
+endif
+
+ifeq ($(PTHREADS_USER), 1)
+DEFINES += -DPTHREADS_USER -UHAVE_CVAR_BUILT_ON_SEM
+endif
+
+ifeq ($(USE_IPV6),1)
+DEFINES += -D_PR_INET6
+endif
+
+ifeq ($(MOZ_UNICODE),1)
+DEFINES += -DMOZ_UNICODE
+endif
+
+####################################################################
+#
+# Configuration for the release process
+#
+####################################################################
+
+MDIST = /m/dist
+ifeq ($(OS_ARCH),WINNT)
+MDIST = //helium/dist
+MDIST_DOS = $(subst /,\\,$(MDIST))
+endif
+
+# RELEASE_DIR is ns/dist/<module name>
+
+RELEASE_DIR = $(MOD_DEPTH)/dist/release/$(MOD_NAME)
+
+RELEASE_INCLUDE_DIR = $(RELEASE_DIR)/$(BUILD_NUMBER)/$(OBJDIR_NAME)/include
+RELEASE_BIN_DIR = $(RELEASE_DIR)/$(BUILD_NUMBER)/$(OBJDIR_NAME)/bin
+RELEASE_LIB_DIR = $(RELEASE_DIR)/$(BUILD_NUMBER)/$(OBJDIR_NAME)/lib
+
+# autoconf.mk sets OBJ_SUFFIX to an error to avoid use before including
+# this file
+OBJ_SUFFIX := $(_OBJ_SUFFIX)
+
+# PGO builds with GCC build objects with instrumentation in a first pass,
+# then objects optimized, without instrumentation, in a second pass. If
+# we overwrite the ojects from the first pass with those from the second,
+# we end up not getting instrumentation data for better optimization on
+# incremental builds. As a consequence, we use a different object suffix
+# for the first pass.
+ifdef MOZ_PROFILE_GENERATE
+ifdef NS_USE_GCC
+OBJ_SUFFIX := i_o
+endif
+endif
diff --git a/config/gcc_hidden.h b/config/gcc_hidden.h
new file mode 100644
index 0000000..075e68c
--- /dev/null
+++ b/config/gcc_hidden.h
@@ -0,0 +1,6 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* Begin all files as hidden visibility */
+#pragma GCC visibility push(hidden)
diff --git a/config/libc_r.h b/config/libc_r.h
new file mode 100644
index 0000000..8f144e3
--- /dev/null
+++ b/config/libc_r.h
@@ -0,0 +1,126 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* libc_r.h  --  macros, defines, etc. to make using reentrant libc calls */
+/*               a bit easier.  This was initially done for AIX pthreads, */
+/*               but should be usable for anyone...                       */
+
+/* Most of these use locally defined space instead of static library space. */
+/* Because of this, we use the _INIT_R to declare/allocate space (stack),   */
+/* and the plain routines to actually do it..._WARNING_: avoid allocating   */
+/* memory wherever possible.  Memory allocation is fairly expensive, at     */
+/* least on AIX...use arrays instead (which allocate from the stack.)       */
+/* I know the names are a bit strange, but I wanted to be fairly certain    */
+/* that we didn't have any namespace corruption...in general, the inits are */
+/* R_<name>_INIT_R(), and the actual calls are R_<name>_R().                */
+
+#ifndef _LIBC_R_H
+#define _LIBC_R_H
+
+/************/
+/*  strtok  */
+/************/
+#define R_STRTOK_INIT_R() \
+    char *r_strtok_r=NULL
+
+#define R_STRTOK_R(return,source,delim) \     
+    return=strtok_r(source,delim,&r_strtok_r)
+
+#define R_STRTOK_NORET_R(source,delim) \
+    strtok_r(source,delim,&r_strtok_r)
+
+/**************/
+/*  strerror  */
+/**************/
+#define R_MAX_STRERROR_LEN_R 8192     /* Straight from limits.h */
+
+#define R_STRERROR_INIT_R() \
+    char r_strerror_r[R_MAX_STRERROR_LEN_R]
+
+#define R_STRERROR_R(val) \
+    strerror_r(val,r_strerror_r,R_MAX_STRERROR_LEN_R)
+
+/*****************/
+/*  time things  */
+/*****************/
+#define R_ASCTIME_INIT_R() \
+    char r_asctime_r[26]
+
+#define R_ASCTIME_R(val) \
+    asctime_r(val,r_asctime_r)
+
+#define R_CTIME_INIT_R() \
+    char r_ctime_r[26]
+
+#define R_CTIME_R(val) \
+    ctime_r(val,r_ctime_r)
+
+#define R_GMTIME_INIT_R() \
+    struct tm r_gmtime_r
+
+#define R_GMTIME_R(time) \
+    gmtime_r(time,&r_gmtime_r)
+
+#define R_LOCALTIME_INIT_R() \
+   struct tm r_localtime_r
+
+#define R_LOCALTIME_R(val) \
+   localtime_r(val,&r_localtime_r)
+    
+/***********/
+/*  crypt  */
+/***********/
+#include <crypt.h>
+#define R_CRYPT_INIT_R() \
+    CRYPTD r_cryptd_r; \
+    bzero(&r_cryptd_r,sizeof(CRYPTD)) 
+
+#define R_CRYPT_R(pass,salt) \
+    crypt_r(pass,salt,&r_cryptd_r)
+
+/**************/
+/*  pw stuff  */
+/**************/
+#define R_MAX_PW_LEN_R 1024
+/* The following must be after the last declaration, but */
+/* before the first bit of code...                       */
+#define R_GETPWNAM_INIT_R(pw_ptr) \
+    struct passwd r_getpwnam_pw_r; \
+    char r_getpwnam_line_r[R_MAX_PW_LEN_R]; \
+    pw_ptr = &r_getpwnam_pw_r
+
+#define R_GETPWNAM_R(name) \
+    getpwnam_r(name,&r_getpwnam_pw_r,r_getpwnam_line_r,R_MAX_PW_LEN_R)
+
+/*******************/
+/*  gethost stuff  */
+/*******************/
+#define R_GETHOSTBYADDR_INIT_R() \
+    struct hostent r_gethostbyaddr_r; \
+    struct hostent_data r_gethostbyaddr_data_r
+
+#define R_GETHOSTBYADDR_R(addr,len,type,xptr_ent) \
+    bzero(&r_gethostbyaddr_r,sizeof(struct hostent)); \
+    bzero(&r_gethostbyaddr_data_r,sizeof(struct hostent_data)); \
+    xptr_ent = &r_gethostbyaddr_r; \
+    if (gethostbyaddr_r(addr,len,type, \
+       &r_gethostbyaddr_r,&r_gethostbyaddr_data_r) == -1) { \
+           xptr_ent = NULL; \
+    }
+
+#define R_GETHOSTBYNAME_INIT_R() \
+    struct hostent r_gethostbyname_r; \
+    struct hostent_data r_gethostbyname_data_r
+
+#define R_GETHOSTBYNAME_R(name,xptr_ent) \
+    bzero(&r_gethostbyname_r,sizeof(struct hostent)); \
+    bzero(&r_gethostbyname_data_r,sizeof(struct hostent_data)); \
+    xptr_ent = &r_gethostbyname_r; \
+    if (gethostbyname_r(name, \
+       &r_gethostbyname_r,&r_gethostbyname_data_r) == -1) { \
+          xptr_ent = NULL; \
+    }
+
+#endif /* _LIBC_R_H */
diff --git a/config/make-system-wrappers.pl b/config/make-system-wrappers.pl
new file mode 100644
index 0000000..fa0873a
--- /dev/null
+++ b/config/make-system-wrappers.pl
@@ -0,0 +1,26 @@
+#!/usr/bin/perl
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+$output_dir = shift;
+
+while (<STDIN>) {
+    chomp;
+    if (-e "$output_dir/$_") {
+	next;
+    }
+
+    if (/(.*)\/[^\/*]/) {
+	mkdir "$output_dir/$1";
+    }
+
+    open OUT, ">$output_dir/$_";
+    print OUT "#pragma GCC system_header\n";  # suppress include_next warning
+    print OUT "#pragma GCC visibility push(default)\n";
+    print OUT "#include_next \<$_\>\n";
+    print OUT "#pragma GCC visibility pop\n";
+    close OUT;
+}
+
diff --git a/config/nfspwd.pl b/config/nfspwd.pl
new file mode 100644
index 0000000..1e66be3
--- /dev/null
+++ b/config/nfspwd.pl
@@ -0,0 +1,18 @@
+#! perl
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+require "fastcwd.pl";
+
+$_ = &fastcwd;
+if (m@^/[uh]/@o || s@^/tmp_mnt/@/@o) {
+    print("$_\n");
+} elsif ((($user, $rest) = m@^/usr/people/(\w+)/(.*)@o)
+      && readlink("/u/$user") eq "/usr/people/$user") {
+    print("/u/$user/$rest\n");
+} else {
+    chop($host = `hostname`);
+    print("/h/$host$_\n");
+}
diff --git a/config/now.c b/config/now.c
new file mode 100644
index 0000000..2893c5b
--- /dev/null
+++ b/config/now.c
@@ -0,0 +1,41 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <stdio.h>
+#include <time.h>
+
+int main(int argc, char **argv)
+{
+#if defined(OMIT_LIB_BUILD_TIME)
+    /*
+     * Some platforms don't have any 64-bit integer type
+     * such as 'long long'.  Because we can't use NSPR's
+     * PR_snprintf in this program, it is difficult to
+     * print a static initializer for PRInt64 (a struct).
+     * So we print nothing.  The makefiles that build the
+     * shared libraries will detect the empty output string
+     * of this program and omit the library build time
+     * in PRVersionDescription.
+     */
+#elif defined(_MSC_VER)
+    __int64 now;
+    time_t sec;
+
+    sec = time(NULL);
+    now = (1000000i64) * sec;
+    fprintf(stdout, "%I64d", now);
+#else
+    long long now;
+    time_t sec;
+
+    sec = time(NULL);
+    now = (1000000LL) * sec;
+    fprintf(stdout, "%lld", now);
+#endif
+
+    return 0;
+}  /* main */
+
+/* now.c */
diff --git a/config/nsinstall.c b/config/nsinstall.c
new file mode 100644
index 0000000..f1d2cff
--- /dev/null
+++ b/config/nsinstall.c
@@ -0,0 +1,525 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** Netscape portable install command.
+**
+** Brendan Eich, 7/20/95
+*/
+#include <stdio.h>  /* OSF/1 requires this before grp.h, so put it first */
+#include <assert.h>
+#include <fcntl.h>
+#include <grp.h>
+#include <pwd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <utime.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <errno.h>
+#include <stdarg.h>
+#ifdef USE_REENTRANT_LIBC
+#include "libc_r.h"
+#endif /* USE_REENTRANT_LIBC */
+
+#include "pathsub.h"
+
+#define HAVE_FCHMOD
+
+#if defined(BEOS)
+#undef HAVE_FCHMOD
+#endif
+
+/*
+ * Does getcwd() take NULL as the first argument and malloc
+ * the result buffer?
+ */
+#if !defined(DARWIN)
+#define GETCWD_CAN_MALLOC
+#endif
+
+#if defined(LINUX) || defined(__GNU__) || defined(__GLIBC__) 
+#include <getopt.h>
+#endif
+
+#if defined(SCO) || defined(UNIXWARE)
+#if !defined(S_ISLNK) && defined(S_IFLNK)
+#define S_ISLNK(a)	(((a) & S_IFMT) == S_IFLNK)
+#endif
+#endif
+
+#ifdef QNX
+#define d_ino d_stat.st_ino
+#endif
+
+static void
+usage(void)
+{
+    fprintf(stderr,
+	"usage: %s [-C cwd] [-L linkprefix] [-m mode] [-o owner] [-g group]\n"
+	"       %*s [-DdltR] file [file ...] directory\n",
+	program, (int)strlen(program), "");
+    exit(2);
+}
+
+static int
+mkdirs(char *path, mode_t mode)
+{
+    char *cp;
+    struct stat sb;
+    int res;
+    
+    while (*path == '/' && path[1] == '/')
+	path++;
+    for (cp = strrchr(path, '/'); cp && cp != path && cp[-1] == '/'; cp--)
+	;
+    if (cp && cp != path) {
+	*cp = '\0';
+	if ((stat(path, &sb) < 0 || !S_ISDIR(sb.st_mode)) &&
+	    mkdirs(path, mode) < 0) {
+	    return -1;
+	}
+	*cp = '/';
+    }
+    res = mkdir(path, mode);
+    if ((res != 0) && (errno == EEXIST))
+	return 0;
+     else
+	return res;
+}
+
+static uid_t
+touid(char *owner)
+{
+    struct passwd *pw;
+    uid_t uid;
+    char *cp;
+
+    pw = getpwnam(owner);
+    if (pw)
+	return pw->pw_uid;
+    uid = strtol(owner, &cp, 0);
+    if (uid == 0 && cp == owner)
+	fail("cannot find uid for %s", owner);
+    return uid;
+}
+
+static gid_t
+togid(char *group)
+{
+    struct group *gr;
+    gid_t gid;
+    char *cp;
+
+    gr = getgrnam(group);
+    if (gr)
+	return gr->gr_gid;
+    gid = strtol(group, &cp, 0);
+    if (gid == 0 && cp == group)
+	fail("cannot find gid for %s", group);
+    return gid;
+}
+
+int
+main(int argc, char **argv)
+{
+    int onlydir, dodir, dolink, dorelsymlink, dotimes, opt, len, lplen, tdlen, bnlen, exists, fromfd, tofd, cc, wc;
+    mode_t mode = 0755;
+    char *linkprefix, *owner, *group, *cp, *cwd, *todir, *toname, *name, *base, *linkname, *bp, buf[BUFSIZ];
+    uid_t uid;
+    gid_t gid;
+    struct stat sb, tosb;
+    struct utimbuf utb;
+
+    program = argv[0];
+    cwd = linkname = linkprefix = owner = group = 0;
+    onlydir = dodir = dolink = dorelsymlink = dotimes = lplen = 0;
+
+    while ((opt = getopt(argc, argv, "C:DdlL:Rm:o:g:t")) != EOF) {
+	switch (opt) {
+	  case 'C':
+	    cwd = optarg;
+	    break;
+	  case 'D':
+	    onlydir = 1;
+	    break;
+	  case 'd':
+	    dodir = 1;
+	    break;
+	  case 'l':
+	    dolink = 1;
+	    break;
+	  case 'L':
+	    linkprefix = optarg;
+	    lplen = strlen(linkprefix);
+	    dolink = 1;
+	    break;
+	  case 'R':
+	    dolink = dorelsymlink = 1;
+	    break;
+	  case 'm':
+	    mode = strtoul(optarg, &cp, 8);
+	    if (mode == 0 && cp == optarg)
+		usage();
+	    break;
+	  case 'o':
+	    owner = optarg;
+	    break;
+	  case 'g':
+	    group = optarg;
+	    break;
+	  case 't':
+	    dotimes = 1;
+	    break;
+	  default:
+	    usage();
+	}
+    }
+
+    argc -= optind;
+    argv += optind;
+    if (argc < 2 - onlydir)
+	usage();
+
+    todir = argv[argc-1];
+    if ((stat(todir, &sb) < 0 || !S_ISDIR(sb.st_mode)) &&
+	mkdirs(todir, 0777) < 0) {
+	fail("cannot make directory %s", todir);
+    }
+    if (onlydir)
+	return 0;
+
+    if (!cwd) {
+#ifdef GETCWD_CAN_MALLOC
+	cwd = getcwd(0, PATH_MAX);
+#else
+	cwd = malloc(PATH_MAX + 1);
+	cwd = getcwd(cwd, PATH_MAX);
+#endif
+    }
+    xchdir(todir);
+#ifdef GETCWD_CAN_MALLOC
+    todir = getcwd(0, PATH_MAX);
+#else
+    todir = malloc(PATH_MAX + 1);
+    todir = getcwd(todir, PATH_MAX);
+#endif
+    xchdir(cwd);
+    tdlen = strlen(todir);
+
+    uid = owner ? touid(owner) : -1;
+    gid = group ? togid(group) : -1;
+
+    while (--argc > 0) {
+	name = *argv++;
+	len = strlen(name);
+	base = xbasename(name);
+	bnlen = strlen(base);
+	toname = (char*)xmalloc(tdlen + 1 + bnlen + 1);
+	sprintf(toname, "%s/%s", todir, base);
+	exists = (lstat(toname, &tosb) == 0);
+
+	if (dodir) {
+	    /* -d means create a directory, always */
+	    if (exists && !S_ISDIR(tosb.st_mode)) {
+		(void) unlink(toname);
+		exists = 0;
+	    }
+	    if (!exists && mkdir(toname, mode) < 0)
+		fail("cannot make directory %s", toname);
+	    if ((owner || group) && chown(toname, uid, gid) < 0)
+		fail("cannot change owner of %s", toname);
+	} else if (dolink) {
+	    if (*name == '/') {
+		/* source is absolute pathname, link to it directly */
+		linkname = 0;
+	    } else {
+		if (linkprefix) {
+		    /* -L implies -l and prefixes names with a $cwd arg. */
+		    len += lplen + 1;
+		    linkname = (char*)xmalloc(len + 1);
+		    sprintf(linkname, "%s/%s", linkprefix, name);
+		} else if (dorelsymlink) {
+		    /* Symlink the relative path from todir to source name. */
+		    linkname = (char*)xmalloc(PATH_MAX);
+
+		    if (*todir == '/') {
+			/* todir is absolute: skip over common prefix. */
+			lplen = relatepaths(todir, cwd, linkname);
+			strcpy(linkname + lplen, name);
+		    } else {
+			/* todir is named by a relative path: reverse it. */
+			reversepath(todir, name, len, linkname);
+			xchdir(cwd);
+		    }
+
+		    len = strlen(linkname);
+		}
+		name = linkname;
+	    }
+
+	    /* Check for a pre-existing symlink with identical content. */
+	    if (exists &&
+		(!S_ISLNK(tosb.st_mode) ||
+		 readlink(toname, buf, sizeof buf) != len ||
+		 strncmp(buf, name, len) != 0)) {
+		(void) (S_ISDIR(tosb.st_mode) ? rmdir : unlink)(toname);
+		exists = 0;
+	    }
+	    if (!exists && symlink(name, toname) < 0)
+		fail("cannot make symbolic link %s", toname);
+#ifdef HAVE_LCHOWN
+	    if ((owner || group) && lchown(toname, uid, gid) < 0)
+		fail("cannot change owner of %s", toname);
+#endif
+
+	    if (linkname) {
+		free(linkname);
+		linkname = 0;
+	    }
+	} else {
+	    /* Copy from name to toname, which might be the same file. */
+	    fromfd = open(name, O_RDONLY);
+	    if (fromfd < 0 || fstat(fromfd, &sb) < 0)
+		fail("cannot access %s", name);
+	    if (exists && (!S_ISREG(tosb.st_mode) || access(toname, W_OK) < 0))
+		(void) (S_ISDIR(tosb.st_mode) ? rmdir : unlink)(toname);
+	    tofd = open(toname, O_CREAT | O_WRONLY, 0666);
+	    if (tofd < 0)
+		fail("cannot create %s", toname);
+
+	    bp = buf;
+	    while ((cc = read(fromfd, bp, sizeof buf)) > 0) {
+		while ((wc = write(tofd, bp, cc)) > 0) {
+		    if ((cc -= wc) == 0)
+			break;
+		    bp += wc;
+		}
+		if (wc < 0)
+		    fail("cannot write to %s", toname);
+	    }
+	    if (cc < 0)
+		fail("cannot read from %s", name);
+
+	    if (ftruncate(tofd, sb.st_size) < 0)
+		fail("cannot truncate %s", toname);
+	    if (dotimes) {
+		utb.actime = sb.st_atime;
+		utb.modtime = sb.st_mtime;
+		if (utime(toname, &utb) < 0)
+		    fail("cannot set times of %s", toname);
+	    }
+#ifdef HAVE_FCHMOD
+	    if (fchmod(tofd, mode) < 0)
+#else
+	    if (chmod(toname, mode) < 0)
+#endif
+		fail("cannot change mode of %s", toname);
+	    if ((owner || group) && fchown(tofd, uid, gid) < 0)
+		fail("cannot change owner of %s", toname);
+
+	    /* Must check for delayed (NFS) write errors on close. */
+	    if (close(tofd) < 0)
+		fail("cannot write to %s", toname);
+	    close(fromfd);
+	}
+
+	free(toname);
+    }
+
+    free(cwd);
+    free(todir);
+    return 0;
+}
+
+/*
+** Pathname subroutines.
+**
+** Brendan Eich, 8/29/95
+*/
+
+char *program;
+
+void
+fail(char *format, ...)
+{
+    int error;
+    va_list ap;
+
+#ifdef USE_REENTRANT_LIBC
+    R_STRERROR_INIT_R();
+#endif
+
+    error = errno;
+    fprintf(stderr, "%s: ", program);
+    va_start(ap, format);
+    vfprintf(stderr, format, ap);
+    va_end(ap);
+    if (error)
+
+#ifdef USE_REENTRANT_LIBC
+    R_STRERROR_R(errno);
+	fprintf(stderr, ": %s", r_strerror_r);
+#else
+	fprintf(stderr, ": %s", strerror(errno));
+#endif
+
+    putc('\n', stderr);
+    exit(1);
+}
+
+char *
+getcomponent(char *path, char *name)
+{
+    if (*path == '\0')
+	return 0;
+    if (*path == '/') {
+	*name++ = '/';
+    } else {
+	do {
+	    *name++ = *path++;
+	} while (*path != '/' && *path != '\0');
+    }
+    *name = '\0';
+    while (*path == '/')
+	path++;
+    return path;
+}
+
+#ifdef UNIXWARE_READDIR_BUFFER_TOO_SMALL
+/* Sigh.  The static buffer in Unixware's readdir is too small. */
+struct dirent * readdir(DIR *d)
+{
+        static struct dirent *buf = NULL;
+#define MAX_PATH_LEN 1024
+
+
+        if(buf == NULL)
+                buf = (struct dirent *) malloc(sizeof(struct dirent) + MAX_PATH_LEN)
+;
+        return(readdir_r(d, buf));
+}
+#endif
+
+char *
+ino2name(ino_t ino, char *dir)
+{
+    DIR *dp;
+    struct dirent *ep;
+    char *name;
+
+    dp = opendir("..");
+    if (!dp)
+	fail("cannot read parent directory");
+    for (;;) {
+	if (!(ep = readdir(dp)))
+	    fail("cannot find current directory");
+	if (ep->d_ino == ino)
+	    break;
+    }
+    name = xstrdup(ep->d_name);
+    closedir(dp);
+    return name;
+}
+
+void *
+xmalloc(size_t size)
+{
+    void *p = malloc(size);
+    if (!p)
+	fail("cannot allocate %u bytes", size);
+    return p;
+}
+
+char *
+xstrdup(char *s)
+{
+    return strcpy((char*)xmalloc(strlen(s) + 1), s);
+}
+
+char *
+xbasename(char *path)
+{
+    char *cp;
+
+    while ((cp = strrchr(path, '/')) && cp[1] == '\0')
+	*cp = '\0';
+    if (!cp) return path;
+    return cp + 1;
+}
+
+void
+xchdir(char *dir)
+{
+    if (chdir(dir) < 0)
+	fail("cannot change directory to %s", dir);
+}
+
+int
+relatepaths(char *from, char *to, char *outpath)
+{
+    char *cp, *cp2;
+    int len;
+    char buf[NAME_MAX];
+
+    assert(*from == '/' && *to == '/');
+    for (cp = to, cp2 = from; *cp == *cp2; cp++, cp2++)
+	if (*cp == '\0')
+	    break;
+    while (cp[-1] != '/')
+	cp--, cp2--;
+    if (cp - 1 == to) {
+	/* closest common ancestor is /, so use full pathname */
+	len = strlen(strcpy(outpath, to));
+	if (outpath[len] != '/') {
+	    outpath[len++] = '/';
+	    outpath[len] = '\0';
+	}
+    } else {
+	len = 0;
+	while ((cp2 = getcomponent(cp2, buf)) != 0) {
+	    strcpy(outpath + len, "../");
+	    len += 3;
+	}
+	while ((cp = getcomponent(cp, buf)) != 0) {
+	    sprintf(outpath + len, "%s/", buf);
+	    len += strlen(outpath + len);
+	}
+    }
+    return len;
+}
+
+void
+reversepath(char *inpath, char *name, int len, char *outpath)
+{
+    char *cp, *cp2;
+    char buf[NAME_MAX];
+    struct stat sb;
+
+    cp = strcpy(outpath + PATH_MAX - (len + 1), name);
+    cp2 = inpath;
+    while ((cp2 = getcomponent(cp2, buf)) != 0) {
+	if (strcmp(buf, ".") == 0)
+	    continue;
+	if (strcmp(buf, "..") == 0) {
+	    if (stat(".", &sb) < 0)
+		fail("cannot stat current directory");
+	    name = ino2name(sb.st_ino, "..");
+	    len = strlen(name);
+	    cp -= len + 1;
+	    strcpy(cp, name);
+	    cp[len] = '/';
+	    free(name);
+	    xchdir("..");
+	} else {
+	    cp -= 3;
+	    strncpy(cp, "../", 3);
+	    xchdir(buf);
+	}
+    }
+    strcpy(outpath, cp);
+}
diff --git a/config/nspr-config.in b/config/nspr-config.in
new file mode 100755
index 0000000..2cb62a0
--- /dev/null
+++ b/config/nspr-config.in
@@ -0,0 +1,147 @@
+#!/bin/sh
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+prefix=@prefix@
+
+major_version=@MOD_MAJOR_VERSION@
+minor_version=@MOD_MINOR_VERSION@
+patch_version=@MOD_PATCH_VERSION@
+
+usage()
+{
+	cat <<EOF
+Usage: nspr-config [OPTIONS] [LIBRARIES]
+Options:
+	[--prefix[=DIR]]
+	[--exec-prefix[=DIR]]
+	[--includedir[=DIR]]
+	[--libdir[=DIR]]
+	[--version]
+	[--libs]
+	[--cflags]
+Libraries:
+	nspr
+	plc
+	plds
+EOF
+	exit $1
+}
+
+if test $# -eq 0; then
+	usage 1 1>&2
+fi
+
+lib_nspr=yes
+lib_plc=yes
+lib_plds=yes
+
+while test $# -gt 0; do
+  case "$1" in
+  -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
+  *) optarg= ;;
+  esac
+
+  case $1 in
+    --prefix=*)
+      prefix=$optarg
+      ;;
+    --prefix)
+      echo_prefix=yes
+      ;;
+    --exec-prefix=*)
+      exec_prefix=$optarg
+      ;;
+    --exec-prefix)
+      echo_exec_prefix=yes
+      ;;
+    --includedir=*)
+      includedir=$optarg
+      ;;
+    --includedir)
+      echo_includedir=yes
+      ;;
+    --libdir=*)
+      libdir=$optarg
+      ;;
+    --libdir)
+      echo_libdir=yes
+      ;;
+    --version)
+      echo ${major_version}.${minor_version}.${patch_version}
+      ;;
+    --cflags)
+      echo_cflags=yes
+      ;;
+    --libs)
+      echo_libs=yes
+      ;;
+    nspr)
+      lib_nspr=yes
+      ;;
+    plc)
+      lib_plc=yes
+      ;;
+    plds)
+      lib_plds=yes
+      ;;
+    *)
+      usage 1 1>&2
+      ;;
+  esac
+  shift
+done
+
+# Set variables that may be dependent upon other variables
+if test -z "$exec_prefix"; then
+    exec_prefix=@exec_prefix@
+fi
+if test -z "$includedir"; then
+    includedir=@includedir@
+fi
+if test -z "$libdir"; then
+    libdir=@libdir@
+fi
+
+if test "$echo_prefix" = "yes"; then
+    echo $prefix
+fi
+
+if test "$echo_exec_prefix" = "yes"; then
+    echo $exec_prefix
+fi
+
+if test "$echo_includedir" = "yes"; then
+    echo $includedir
+fi
+
+if test "$echo_libdir" = "yes"; then
+    echo $libdir
+fi
+
+if test "$echo_cflags" = "yes"; then
+    echo -I$includedir
+fi
+
+if test "$echo_libs" = "yes"; then
+      libdirs=-L$libdir
+      if test -n "$lib_plds"; then
+	libdirs="$libdirs -lplds${major_version}"
+      fi
+      if test -n "$lib_plc"; then
+	libdirs="$libdirs -lplc${major_version}"
+      fi
+      if test -n "$lib_nspr"; then
+	libdirs="$libdirs -lnspr${major_version}"
+      fi
+      os_ldflags="@LDFLAGS@"
+      for i in $os_ldflags ; do
+	if echo $i | grep \^-L >/dev/null; then
+	  libdirs="$libdirs $i"
+        fi
+      done
+      echo $libdirs @OS_LIBS@
+fi      
+
diff --git a/config/nspr.m4 b/config/nspr.m4
new file mode 100644
index 0000000..d21df69
--- /dev/null
+++ b/config/nspr.m4
@@ -0,0 +1,82 @@
+# -*- tab-width: 4; -*-
+# Configure paths for NSPR
+# Public domain - Chris Seawood <cls@seawood.org> 2001-04-05
+# Based upon gtk.m4 (also PD) by Owen Taylor
+
+dnl AM_PATH_NSPR([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
+dnl Test for NSPR, and define NSPR_CFLAGS and NSPR_LIBS
+AC_DEFUN([AM_PATH_NSPR],
+[dnl
+
+AC_ARG_WITH(nspr-prefix,
+	[  --with-nspr-prefix=PFX  Prefix where NSPR is installed],
+	nspr_config_prefix="$withval",
+	nspr_config_prefix="")
+
+AC_ARG_WITH(nspr-exec-prefix,
+	[  --with-nspr-exec-prefix=PFX
+                          Exec prefix where NSPR is installed],
+	nspr_config_exec_prefix="$withval",
+	nspr_config_exec_prefix="")
+
+	if test -n "$nspr_config_exec_prefix"; then
+		nspr_config_args="$nspr_config_args --exec-prefix=$nspr_config_exec_prefix"
+		if test -z "$NSPR_CONFIG"; then
+			NSPR_CONFIG=$nspr_config_exec_prefix/bin/nspr-config
+		fi
+	fi
+	if test -n "$nspr_config_prefix"; then
+		nspr_config_args="$nspr_config_args --prefix=$nspr_config_prefix"
+		if test -z "$NSPR_CONFIG"; then
+			NSPR_CONFIG=$nspr_config_prefix/bin/nspr-config
+		fi
+	fi
+
+	unset ac_cv_path_NSPR_CONFIG
+	AC_PATH_PROG(NSPR_CONFIG, nspr-config, no)
+	min_nspr_version=ifelse([$1], ,4.0.0,$1)
+	AC_MSG_CHECKING(for NSPR - version >= $min_nspr_version)
+
+	no_nspr=""
+	if test "$NSPR_CONFIG" = "no"; then
+		no_nspr="yes"
+	else
+		NSPR_CFLAGS=`$NSPR_CONFIG $nspr_config_args --cflags`
+		NSPR_LIBS=`$NSPR_CONFIG $nspr_config_args --libs`
+
+		nspr_config_major_version=`$NSPR_CONFIG $nspr_config_args --version | \
+			sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
+		nspr_config_minor_version=`$NSPR_CONFIG $nspr_config_args --version | \
+			sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
+		nspr_config_micro_version=`$NSPR_CONFIG $nspr_config_args --version | \
+			sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
+		min_nspr_major_version=`echo $min_nspr_version | \
+			sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
+		min_nspr_minor_version=`echo $min_nspr_version | \
+			sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
+		min_nspr_micro_version=`echo $min_nspr_version | \
+			sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
+		if test "$nspr_config_major_version" -ne "$min_nspr_major_version"; then
+			no_nspr="yes"
+		elif test "$nspr_config_major_version" -eq "$min_nspr_major_version" &&
+		     test "$nspr_config_minor_version" -lt "$min_nspr_minor_version"; then
+			no_nspr="yes"
+		elif test "$nspr_config_major_version" -eq "$min_nspr_major_version" &&
+		     test "$nspr_config_minor_version" -eq "$min_nspr_minor_version" &&
+		     test "$nspr_config_micro_version" -lt "$min_nspr_micro_version"; then
+			no_nspr="yes"
+		fi
+	fi
+
+	if test -z "$no_nspr"; then
+		AC_MSG_RESULT(yes)
+		ifelse([$2], , :, [$2])     
+	else
+		AC_MSG_RESULT(no)
+	fi
+
+
+	AC_SUBST(NSPR_CFLAGS)
+	AC_SUBST(NSPR_LIBS)
+
+])
diff --git a/config/nspr.pc.in b/config/nspr.pc.in
new file mode 100644
index 0000000..86300a0
--- /dev/null
+++ b/config/nspr.pc.in
@@ -0,0 +1,10 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: NSPR
+Description: The Netscape Portable Runtime
+Version: @MOD_MAJOR_VERSION@.@MOD_MINOR_VERSION@.@MOD_PATCH_VERSION@
+Libs: -L@libdir@ -lplds@MOD_MAJOR_VERSION@ -lplc@MOD_MAJOR_VERSION@ -lnspr@MOD_MAJOR_VERSION@
+Cflags: -I@includedir@
diff --git a/config/nsprincl.mk.in b/config/nsprincl.mk.in
new file mode 100644
index 0000000..108ed34
--- /dev/null
+++ b/config/nsprincl.mk.in
@@ -0,0 +1,9 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# Include in Makefiles to define NSPR variables
+
+NSPR_VERSION    = @NSPR_VERSION@
+NSPR_LIB        = -lnspr@NSPR_VERSION@
+NSPR_EXTRA_LIBS = @EXTRA_LIBS@
diff --git a/config/nsprincl.sh.in b/config/nsprincl.sh.in
new file mode 100644
index 0000000..8e7a427
--- /dev/null
+++ b/config/nsprincl.sh.in
@@ -0,0 +1,9 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# Include in shell scripts to define NSPR variables
+
+NSPR_VERSION=@NSPR_VERSION@
+NSPR_LIB=-lnspr$NSPR_VERSION
+NSPR_EXTRA_LIBS="@EXTRA_LIBS@"
diff --git a/config/pathsub.h b/config/pathsub.h
new file mode 100644
index 0000000..98b6c11
--- /dev/null
+++ b/config/pathsub.h
@@ -0,0 +1,42 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef pathsub_h___
+#define pathsub_h___
+/*
+** Pathname subroutines.
+**
+** Brendan Eich, 8/29/95
+*/
+#include <limits.h>
+#include <sys/types.h>
+
+#ifndef PATH_MAX
+#define PATH_MAX 1024
+#endif
+
+/*
+ * Just prevent stupidity
+ */
+#undef NAME_MAX
+#define NAME_MAX 256
+
+extern char *program;
+
+extern void fail(char *format, ...);
+extern char *getcomponent(char *path, char *name);
+extern char *ino2name(ino_t ino, char *dir);
+extern void *xmalloc(size_t size);
+extern char *xstrdup(char *s);
+extern char *xbasename(char *path);
+extern void xchdir(char *dir);
+
+/* Relate absolute pathnames from and to returning the result in outpath. */
+extern int relatepaths(char *from, char *to, char *outpath);
+
+/* XXX changes current working directory -- caveat emptor */
+extern void reversepath(char *inpath, char *name, int len, char *outpath);
+
+#endif /* pathsub_h___ */
diff --git a/config/prdepend.h b/config/prdepend.h
new file mode 100644
index 0000000..6c66b37
--- /dev/null
+++ b/config/prdepend.h
@@ -0,0 +1,13 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+ * A dummy header file that is a dependency for all the object files.
+ * Used to force a full recompilation of NSPR in Mozilla's Tinderbox
+ * depend builds.  See comments in rules.mk.
+ */
+
+#error "Do not include this header file."
+
diff --git a/config/rules.mk b/config/rules.mk
new file mode 100644
index 0000000..1c8fdc9
--- /dev/null
+++ b/config/rules.mk
@@ -0,0 +1,527 @@
+#! gmake
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+################################################################################
+# We used to have a 4 pass build process.  Now we do everything in one pass.
+#
+# export - Create generated headers and stubs. Publish public headers to
+#          dist/<arch>/include.
+#          Create libraries. Publish libraries to dist/<arch>/lib.
+#          Create programs. 
+#
+# libs - obsolete.  Now a synonym of "export".
+#
+# all - the default makefile target.  Now a synonym of "export".
+#
+# install - Install headers, libraries, and programs on the system.
+#
+# Parameters to this makefile (set these before including):
+#
+# a)
+#	TARGETS	-- the target to create 
+#			(defaults to $LIBRARY $PROGRAM)
+# b)
+#	DIRS	-- subdirectories for make to recurse on
+#			(the 'all' rule builds $TARGETS $DIRS)
+# c)
+#	CSRCS   -- .c files to compile
+#			(used to define $OBJS)
+# d)
+#	PROGRAM	-- the target program name to create from $OBJS
+#			($OBJDIR automatically prepended to it)
+# e)
+#	LIBRARY	-- the target library name to create from $OBJS
+#			($OBJDIR automatically prepended to it)
+#
+################################################################################
+
+ifndef topsrcdir
+topsrcdir=$(MOD_DEPTH)
+endif
+
+ifndef srcdir
+srcdir=.
+endif
+
+ifndef NSPR_CONFIG_MK
+include $(topsrcdir)/config/config.mk
+endif
+
+ifdef USE_AUTOCONF
+ifdef CROSS_COMPILE
+ifdef INTERNAL_TOOLS
+CC=$(HOST_CC)
+CCC=$(HOST_CXX)
+CFLAGS=$(HOST_CFLAGS)
+CXXFLAGS=$(HOST_CXXFLAGS)
+LDFLAGS=$(HOST_LDFLAGS)
+endif
+endif
+endif
+
+#
+# This makefile contains rules for building the following kinds of
+# libraries:
+# - LIBRARY: a static (archival) library
+# - SHARED_LIBRARY: a shared (dynamic link) library
+# - IMPORT_LIBRARY: an import library, used only on Windows and OS/2
+#
+# The names of these libraries can be generated by simply specifying
+# LIBRARY_NAME and LIBRARY_VERSION.
+#
+
+ifdef LIBRARY_NAME
+ifeq (,$(filter-out WINNT WINCE OS2,$(OS_ARCH)))
+
+#
+# Win95 and OS/2 require library names conforming to the 8.3 rule.
+# other platforms do not.
+#
+ifeq (,$(filter-out WIN95 WINCE WINMO OS2,$(OS_TARGET)))
+SHARED_LIBRARY	= $(OBJDIR)/$(LIBRARY_NAME)$(LIBRARY_VERSION).$(DLL_SUFFIX)
+SHARED_LIB_PDB	= $(OBJDIR)/$(LIBRARY_NAME)$(LIBRARY_VERSION).pdb
+ifdef MSC_VER
+LIBRARY         = $(OBJDIR)/$(LIBRARY_NAME)$(LIBRARY_VERSION)_s.$(LIB_SUFFIX)
+IMPORT_LIBRARY  = $(OBJDIR)/$(LIBRARY_NAME)$(LIBRARY_VERSION).$(LIB_SUFFIX)
+else
+LIBRARY         = $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION)_s.$(LIB_SUFFIX)
+IMPORT_LIBRARY  = $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION).$(LIB_SUFFIX)
+endif
+else
+SHARED_LIBRARY	= $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION).$(DLL_SUFFIX)
+SHARED_LIB_PDB	= $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION).pdb
+LIBRARY         = $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION)_s.$(LIB_SUFFIX)
+IMPORT_LIBRARY  = $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION).$(LIB_SUFFIX)
+endif
+
+else
+
+LIBRARY		= $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION).$(LIB_SUFFIX)
+ifeq ($(OS_ARCH)$(OS_RELEASE), AIX4.1)
+SHARED_LIBRARY	= $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION)_shr.a
+else
+ifdef MKSHLIB
+SHARED_LIBRARY	= $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION).$(DLL_SUFFIX)
+endif
+endif
+
+endif
+endif
+
+ifndef TARGETS
+ifeq (,$(filter-out WINNT WINCE OS2,$(OS_ARCH)))
+TARGETS		= $(LIBRARY) $(SHARED_LIBRARY) $(IMPORT_LIBRARY)
+ifdef MOZ_DEBUG_SYMBOLS
+ifdef MSC_VER
+ifneq (,$(filter-out 1100 1200,$(MSC_VER)))
+TARGETS		+= $(SHARED_LIB_PDB)
+endif
+endif
+endif
+else
+TARGETS		= $(LIBRARY) $(SHARED_LIBRARY)
+endif
+endif
+
+#
+# OBJS is the list of object files.  It can be constructed by
+# specifying CSRCS (list of C source files) and ASFILES (list
+# of assembly language source files).
+#
+
+ifndef OBJS
+OBJS		= $(addprefix $(OBJDIR)/,$(CSRCS:.c=.$(OBJ_SUFFIX))) \
+		  $(addprefix $(OBJDIR)/,$(ASFILES:.$(ASM_SUFFIX)=.$(OBJ_SUFFIX)))
+endif
+
+ALL_TRASH		= $(TARGETS) $(OBJS) $(RES) $(filter-out . .., $(OBJDIR)) LOGS TAGS $(GARBAGE) \
+			  $(NOSUCHFILE) \
+			  $(OBJS:.$(OBJ_SUFFIX)=.i_o) \
+			  so_locations
+
+ifndef RELEASE_LIBS_DEST
+RELEASE_LIBS_DEST	= $(RELEASE_LIB_DIR)
+endif
+
+define MAKE_IN_DIR
+	$(MAKE) -C $(dir) $@
+
+endef # do not remove the blank line!
+
+ifdef DIRS
+LOOP_OVER_DIRS = $(foreach dir,$(DIRS),$(MAKE_IN_DIR))
+endif
+
+################################################################################
+
+all:: export
+
+export::
+	+$(LOOP_OVER_DIRS)
+
+libs:: export
+
+clean::
+	rm -rf $(OBJS) $(RES) so_locations $(NOSUCHFILE) $(GARBAGE)
+	+$(LOOP_OVER_DIRS)
+
+clobber::
+	rm -rf $(OBJS) $(RES) $(TARGETS) $(filter-out . ..,$(OBJDIR)) $(GARBAGE) so_locations $(NOSUCHFILE)
+	+$(LOOP_OVER_DIRS)
+
+realclean clobber_all::
+	rm -rf $(wildcard *.OBJ *.OBJD) dist $(ALL_TRASH)
+	+$(LOOP_OVER_DIRS)
+
+distclean::
+	rm -rf $(wildcard *.OBJ *.OBJD) dist $(ALL_TRASH) $(DIST_GARBAGE)
+	+$(LOOP_OVER_DIRS)
+
+install:: $(RELEASE_BINS) $(RELEASE_HEADERS) $(RELEASE_LIBS)
+ifdef RELEASE_BINS
+	$(NSINSTALL) -t -m 0755 $(RELEASE_BINS) $(DESTDIR)$(bindir)
+endif
+ifdef RELEASE_HEADERS
+	$(NSINSTALL) -t -m 0644 $(RELEASE_HEADERS) $(DESTDIR)$(includedir)/$(include_subdir)
+endif
+ifdef RELEASE_LIBS
+	$(NSINSTALL) -t -m 0755 $(RELEASE_LIBS) $(DESTDIR)$(libdir)/$(lib_subdir)
+endif
+	+$(LOOP_OVER_DIRS)
+
+release:: export
+ifdef RELEASE_BINS
+	@echo "Copying executable programs and scripts to release directory"
+	@if test -z "$(BUILD_NUMBER)"; then \
+		echo "BUILD_NUMBER must be defined"; \
+		false; \
+	else \
+		true; \
+	fi
+	@if test ! -d $(RELEASE_BIN_DIR); then \
+		rm -rf $(RELEASE_BIN_DIR); \
+		$(NSINSTALL) -D $(RELEASE_BIN_DIR);\
+	else \
+		true; \
+	fi
+	cp $(RELEASE_BINS) $(RELEASE_BIN_DIR)
+endif
+ifdef RELEASE_LIBS
+	@echo "Copying libraries to release directory"
+	@if test -z "$(BUILD_NUMBER)"; then \
+		echo "BUILD_NUMBER must be defined"; \
+		false; \
+	else \
+		true; \
+	fi
+	@if test ! -d $(RELEASE_LIBS_DEST); then \
+		rm -rf $(RELEASE_LIBS_DEST); \
+		$(NSINSTALL) -D $(RELEASE_LIBS_DEST);\
+	else \
+		true; \
+	fi
+	cp $(RELEASE_LIBS) $(RELEASE_LIBS_DEST)
+endif
+ifdef RELEASE_HEADERS
+	@echo "Copying header files to release directory"
+	@if test -z "$(BUILD_NUMBER)"; then \
+		echo "BUILD_NUMBER must be defined"; \
+		false; \
+	else \
+		true; \
+	fi
+	@if test ! -d $(RELEASE_HEADERS_DEST); then \
+		rm -rf $(RELEASE_HEADERS_DEST); \
+		$(NSINSTALL) -D $(RELEASE_HEADERS_DEST);\
+	else \
+		true; \
+	fi
+	cp $(RELEASE_HEADERS) $(RELEASE_HEADERS_DEST)
+endif
+	+$(LOOP_OVER_DIRS)
+
+alltags:
+	rm -f TAGS tags
+	find . -name dist -prune -o \( -name '*.[hc]' -o -name '*.cp' -o -name '*.cpp' \) -print | xargs etags -a
+	find . -name dist -prune -o \( -name '*.[hc]' -o -name '*.cp' -o -name '*.cpp' \) -print | xargs ctags -a
+
+$(NFSPWD):
+	cd $(@D); $(MAKE) $(@F)
+
+$(PROGRAM): $(OBJS)
+	@$(MAKE_OBJDIR)
+ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
+ifdef MOZ_PROFILE_USE
+# In the second pass, we need to merge the pgc files into the pgd file.
+# The compiler would do this for us automatically if they were in the right
+# place, but they're in dist/bin.
+	python $(topsrcdir)/build/win32/pgomerge.py \
+		$(notdir $(PROGRAM:.exe=)) $(DIST)/bin
+endif	# MOZ_PROFILE_USE
+	$(CC) $(OBJS) -Fe$@ -link $(LDFLAGS) $(OS_LIBS) $(EXTRA_LIBS)
+ifdef MT
+	@if test -f $@.manifest; then \
+		$(MT) -NOLOGO -MANIFEST $@.manifest -OUTPUTRESOURCE:$@\;1; \
+		rm -f $@.manifest; \
+	fi
+endif	# MSVC with manifest tool
+ifdef MOZ_PROFILE_GENERATE
+# touch it a few seconds into the future to work around FAT's
+# 2-second granularity
+	touch -t `date +%Y%m%d%H%M.%S -d "now+5seconds"` pgo.relink
+endif	# MOZ_PROFILE_GENERATE
+else	# WINNT && !GCC
+	$(CC) -o $@ $(CFLAGS) $(OBJS) $(LDFLAGS) $(WRAP_LDFLAGS)
+endif	# WINNT && !GCC
+ifdef ENABLE_STRIP
+	$(STRIP) $@
+endif
+
+$(LIBRARY): $(OBJS)
+	@$(MAKE_OBJDIR)
+	rm -f $@
+	$(AR) $(AR_FLAGS) $(OBJS) $(AR_EXTRA_ARGS)
+	$(RANLIB) $@
+
+ifeq ($(OS_TARGET), OS2)
+$(IMPORT_LIBRARY): $(MAPFILE)
+	rm -f $@
+	$(IMPLIB) $@ $(MAPFILE)
+else
+ifeq (,$(filter-out WIN95 WINCE WINMO,$(OS_TARGET)))
+# PDBs and import libraries need to depend on the shared library to
+# order dependencies properly.
+$(IMPORT_LIBRARY): $(SHARED_LIBRARY)
+$(SHARED_LIB_PDB): $(SHARED_LIBRARY)
+endif
+endif
+
+$(SHARED_LIBRARY): $(OBJS) $(RES) $(MAPFILE)
+	@$(MAKE_OBJDIR)
+	rm -f $@
+ifeq ($(OS_ARCH)$(OS_RELEASE), AIX4.1)
+	echo "#!" > $(OBJDIR)/lib$(LIBRARY_NAME)_syms
+	nm -B -C -g $(OBJS) \
+		| awk '/ [T,D] / {print $$3}' \
+		| sed -e 's/^\.//' \
+		| sort -u >> $(OBJDIR)/lib$(LIBRARY_NAME)_syms
+	$(LD) $(XCFLAGS) -o $@ $(OBJS) -bE:$(OBJDIR)/lib$(LIBRARY_NAME)_syms \
+		-bM:SRE -bnoentry $(OS_LIBS) $(EXTRA_LIBS)
+else	# AIX 4.1
+ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
+ifdef MOZ_PROFILE_USE
+	python $(topsrcdir)/build/win32/pgomerge.py \
+		$(notdir $(SHARED_LIBRARY:.$(DLL_SUFFIX)=)) $(DIST)/bin
+endif	# MOZ_PROFILE_USE
+	$(LINK_DLL) -MAP $(DLLBASE) $(DLL_LIBS) $(EXTRA_LIBS) $(OBJS) $(RES)
+ifdef MT
+	@if test -f $@.manifest; then \
+		$(MT) -NOLOGO -MANIFEST $@.manifest -OUTPUTRESOURCE:$@\;2; \
+		rm -f $@.manifest; \
+	fi
+endif	# MSVC with manifest tool
+ifdef MOZ_PROFILE_GENERATE
+	touch -t `date +%Y%m%d%H%M.%S -d "now+5seconds"` pgo.relink
+endif	# MOZ_PROFILE_GENERATE
+else	# WINNT && !GCC
+	$(MKSHLIB) $(OBJS) $(RES) $(LDFLAGS) $(WRAP_LDFLAGS) $(EXTRA_LIBS)
+endif	# WINNT && !GCC
+endif	# AIX 4.1
+ifdef ENABLE_STRIP
+	$(STRIP) $@
+endif
+
+################################################################################
+
+ifdef MOZ_PROFILE_USE
+ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
+# When building with PGO, we have to make sure to re-link
+# in the MOZ_PROFILE_USE phase if we linked in the
+# MOZ_PROFILE_GENERATE phase. We'll touch this pgo.relink
+# file in the link rule in the GENERATE phase to indicate
+# that we need a relink.
+$(SHARED_LIBRARY): pgo.relink
+
+$(PROGRAM): pgo.relink
+
+endif	# WINNT && !GCC
+endif	# MOZ_PROFILE_USE
+
+ifneq (,$(MOZ_PROFILE_GENERATE)$(MOZ_PROFILE_USE))
+ifdef NS_USE_GCC
+# Force rebuilding libraries and programs in both passes because each
+# pass uses different object files.
+$(PROGRAM) $(SHARED_LIBRARY) $(LIBRARY): FORCE
+.PHONY: FORCE
+endif
+endif
+
+################################################################################
+
+ifdef MOZ_PROFILE_GENERATE
+# Clean up profiling data during PROFILE_GENERATE phase
+export::
+ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
+	$(foreach pgd,$(wildcard *.pgd),pgomgr -clear $(pgd);)
+else
+ifdef NS_USE_GCC
+	-$(RM) *.gcda
+endif
+endif
+endif
+
+################################################################################
+
+ifeq ($(OS_ARCH),WINNT)
+$(RES): $(RESNAME)
+	@$(MAKE_OBJDIR)
+# The resource compiler does not understand the -U option.
+ifdef NS_USE_GCC
+	$(RC) $(RCFLAGS) $(filter-out -U%,$(DEFINES)) $(INCLUDES:-I%=--include-dir %) -o $@ $<
+else
+	$(RC) $(RCFLAGS) $(filter-out -U%,$(DEFINES)) $(INCLUDES) -Fo$@ $<
+endif # GCC
+	@echo $(RES) finished
+endif
+
+$(MAPFILE): $(LIBRARY_NAME).def
+	@$(MAKE_OBJDIR)
+ifeq ($(OS_ARCH),SunOS)
+	grep -v ';-' $< | \
+	sed -e 's,;+,,' -e 's; DATA ;;' -e 's,;;,,' -e 's,;.*,;,' > $@
+endif
+ifeq ($(OS_ARCH),OS2)
+	echo LIBRARY $(LIBRARY_NAME)$(LIBRARY_VERSION) INITINSTANCE TERMINSTANCE > $@
+	echo PROTMODE >> $@
+	echo CODE    LOADONCALL MOVEABLE DISCARDABLE >> $@
+	echo DATA    PRELOAD MOVEABLE MULTIPLE NONSHARED >> $@
+	echo EXPORTS >> $@
+	grep -v ';+' $< | grep -v ';-' | \
+	sed -e 's; DATA ;;' -e 's,;;,,' -e 's,;.*,,' -e 's,\([\t ]*\),\1_,' | \
+	awk 'BEGIN {ord=1;} { print($$0 " @" ord " RESIDENTNAME"); ord++;}'	>> $@
+	$(ADD_TO_DEF_FILE)
+endif
+
+#
+# Translate source filenames to absolute paths. This is required for
+# debuggers under Windows and OS/2 to find source files automatically.
+#
+
+ifeq (,$(filter-out AIX OS2,$(OS_ARCH)))
+NEED_ABSOLUTE_PATH = 1
+endif
+
+ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
+NEED_ABSOLUTE_PATH = 1
+endif
+
+ifdef NEED_ABSOLUTE_PATH
+# The quotes allow absolute paths to contain spaces.
+pr_abspath = "$(if $(findstring :,$(1)),$(1),$(if $(filter /%,$(1)),$(1),$(CURDIR)/$(1)))"
+endif
+
+$(OBJDIR)/%.$(OBJ_SUFFIX): %.cpp
+	@$(MAKE_OBJDIR)
+ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
+	$(CCC) -Fo$@ -c $(CCCFLAGS) $(call pr_abspath,$<)
+else
+ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINCE)
+	$(CCC) -Fo$@ -c $(CCCFLAGS) $<
+else
+ifdef NEED_ABSOLUTE_PATH
+	$(CCC) -o $@ -c $(CCCFLAGS) $(call pr_abspath,$<)
+else
+	$(CCC) -o $@ -c $(CCCFLAGS) $<
+endif
+endif
+endif
+
+WCCFLAGS1 = $(subst /,\\,$(CFLAGS))
+WCCFLAGS2 = $(subst -I,-i=,$(WCCFLAGS1))
+WCCFLAGS3 = $(subst -D,-d,$(WCCFLAGS2))
+$(OBJDIR)/%.$(OBJ_SUFFIX): %.c
+	@$(MAKE_OBJDIR)
+ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
+	$(CC) -Fo$@ -c $(CFLAGS) $(call pr_abspath,$<)
+else
+ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINCE)
+	$(CC) -Fo$@ -c $(CFLAGS) $<
+else
+ifdef NEED_ABSOLUTE_PATH
+	$(CC) -o $@ -c $(CFLAGS) $(call pr_abspath,$<)
+else
+	$(CC) -o $@ -c $(CFLAGS) $<
+endif
+endif
+endif
+
+
+$(OBJDIR)/%.$(OBJ_SUFFIX): %.s
+	@$(MAKE_OBJDIR)
+	$(AS) -o $@ $(ASFLAGS) -c $<
+
+%.i: %.c
+	$(CC) -C -E $(CFLAGS) $< > $*.i
+
+%: %.pl
+	rm -f $@; cp $< $@; chmod +x $@
+
+#
+# HACK ALERT
+#
+# The only purpose of this rule is to pass Mozilla's Tinderbox depend
+# builds (http://tinderbox.mozilla.org/showbuilds.cgi).  Mozilla's
+# Tinderbox builds NSPR continuously as part of the Mozilla client.
+# Because NSPR's make depend is not implemented, whenever we change
+# an NSPR header file, the depend build does not recompile the NSPR
+# files that depend on the header.
+#
+# This rule makes all the objects depend on a dummy header file.
+# Touch this dummy header file to force the depend build to recompile
+# everything.
+#
+# This rule should be removed when make depend is implemented.
+#
+
+DUMMY_DEPEND_H = $(topsrcdir)/config/prdepend.h
+
+$(filter $(OBJDIR)/%.$(OBJ_SUFFIX),$(OBJS)): $(OBJDIR)/%.$(OBJ_SUFFIX): $(DUMMY_DEPEND_H)
+
+# END OF HACK
+
+################################################################################
+# Special gmake rules.
+################################################################################
+
+#
+# Disallow parallel builds with MSVC < 8 since it can't open the PDB file in
+# parallel.
+#
+ifeq (,$(filter-out 1200 1300 1310,$(MSC_VER)))
+.NOTPARALLEL:
+endif
+
+#
+# Re-define the list of default suffixes, so gmake won't have to churn through
+# hundreds of built-in suffix rules for stuff we don't need.
+#
+.SUFFIXES:
+.SUFFIXES: .a .$(OBJ_SUFFIX) .c .cpp .s .h .i .pl
+
+#
+# Fake targets.  Always run these rules, even if a file/directory with that
+# name already exists.
+#
+.PHONY: all alltags clean export install libs realclean release
+
+#
+# List the target pattern of an implicit rule as a dependency of the
+# special target .PRECIOUS to preserve intermediate files made by
+# implicit rules whose target patterns match that file's name.
+# (See GNU Make documentation, Edition 0.51, May 1996, Sec. 10.4,
+# p. 107.)
+#
+.PRECIOUS: $(OBJDIR)/%.$(OBJ_SUFFIX)
diff --git a/config/system-headers b/config/system-headers
new file mode 100644
index 0000000..cf0f114
--- /dev/null
+++ b/config/system-headers
@@ -0,0 +1,172 @@
+Aliases.h
+arpa/inet.h
+assert.h
+bsd/libc.h
+bsd/syscall.h
+bstring.h
+builtin.h
+c_asm.h
+cf.h
+CFBundle.h
+CFData.h
+CFDictionary.h
+CFString.h
+CFURL.h
+CodeFragments.h
+commdlg.h
+crt_externs.h
+crypt.h
+ctype.h
+descrip.h
+Devices.h
+direct.h
+dirent.h
+dlfcn.h
+dl.h
+DriverServices.h
+dvidef.h
+errno.h
+Errors.h
+Events.h
+fcntl.h
+fibdef.h
+files.h
+Files.h
+float.h
+Folders.h
+Gestalt.h
+getopt.h
+grp.h
+ia64/sys/inline.h
+ifaddrs.h
+image.h
+ints.h
+iodef.h
+io.h
+iostream.h
+kernel/OS.h
+lib$routines.h
+limits.h
+loader.h
+locale.h
+LowMem.h
+MacErrors.h
+machine/builtins.h
+machine/clock.h
+machine/endian.h
+machine/inline.h
+mach/mach_init.h
+mach/mach_host.h
+mach-o/dyld.h
+MacTypes.h
+Math64.h
+math.h
+mbstring.h
+memory.h
+MixedMode.h
+model.h
+mswsock.h
+Multiprocessing.h
+mutex.h
+netdb.h
+net/if.h
+netinet/in.h
+netinet/in_systm.h
+netinet/tcp.h
+OpenTptInternet.h
+OpenTransport.h
+os2.h
+OS.h
+osreldate.h
+OSUtils.h
+poll.h
+PPCToolbox.h
+Processes.h
+process.h
+pthread.h
+pwd.h
+QDOffscreen.h
+Resources.h
+rld_interface.h
+rpc/types.h
+semaphore.h
+setjmp.h
+share.h
+signal.h
+ssdef.h
+starlet.h
+stat.h
+stdarg.h
+stddef.h
+stdio.h
+stdlib.h
+string.h
+stropts.h
+stsdef.h
+support/SupportDefs.h
+support/TLS.h
+synch.h
+sys/atomic_op.h
+syscall.h
+sys/cfgodm.h
+sys/file.h
+sys/filio.h
+sys/immu.h
+sys/ioctl.h
+sys/ipc.h
+sys/ldr.h
+sys/locking.h
+sys/lwp.h
+sys/mman.h
+sys/mpctl.h
+sys/param.h
+sys/pda.h
+sys/poll.h
+sys/prctl.h
+sys/priv.h
+sys/procfs.h
+sys/pstat.h
+sys/regset.h
+sys/resource.h
+sys/sched.h
+sys/select.h
+sys/sem.h
+sys/sendfile.h
+sys/shm.h
+sys/socket.h
+sys/stack.h
+sys/stat.h
+sys/statvfs.h
+sys/syscall.h
+sys/sysctl.h
+sys/sysmp.h
+sys/syssgi.h
+sys/systeminfo.h
+sys/timeb.h
+sys/time.h
+sys/times.h
+sys/types.h
+sys/ucontext.h
+sys/uio.h
+sys/utsname.h
+sys/wait.h
+task.h
+TextUtils.h
+thread.h
+time.h
+Timer.h
+types.h
+Types.h
+ucontext.h
+ucx$inetdef.h
+ulocks.h
+unistd.h
+unix.h
+unixlib.h
+utime.h
+wchar.h
+winbase.h
+win/compobj.h
+windef.h
+windows.h
+winsock.h
diff --git a/configure b/configure
new file mode 100755
index 0000000..fb3b3e2
--- /dev/null
+++ b/configure
@@ -0,0 +1,9931 @@
+#! /bin/sh
+# Guess values for system-dependent variables and create Makefiles.
+# Generated by GNU Autoconf 2.69.
+#
+#
+# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
+#
+#
+# This configure script is free software; the Free Software Foundation
+# gives unlimited permission to copy, distribute and modify it.
+## -------------------- ##
+## M4sh Initialization. ##
+## -------------------- ##
+
+# Be more Bourne compatible
+DUALCASE=1; export DUALCASE # for MKS sh
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
+  emulate sh
+  NULLCMD=:
+  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+  setopt NO_GLOB_SUBST
+else
+  case `(set -o) 2>/dev/null` in #(
+  *posix*) :
+    set -o posix ;; #(
+  *) :
+     ;;
+esac
+fi
+
+
+as_nl='
+'
+export as_nl
+# Printing a long string crashes Solaris 7 /usr/bin/printf.
+as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
+# Prefer a ksh shell builtin over an external printf program on Solaris,
+# but without wasting forks for bash or zsh.
+if test -z "$BASH_VERSION$ZSH_VERSION" \
+    && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='print -r --'
+  as_echo_n='print -rn --'
+elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='printf %s\n'
+  as_echo_n='printf %s'
+else
+  if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
+    as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"'
+    as_echo_n='/usr/ucb/echo -n'
+  else
+    as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
+    as_echo_n_body='eval
+      arg=$1;
+      case $arg in #(
+      *"$as_nl"*)
+	expr "X$arg" : "X\\(.*\\)$as_nl";
+	arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
+      esac;
+      expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
+    '
+    export as_echo_n_body
+    as_echo_n='sh -c $as_echo_n_body as_echo'
+  fi
+  export as_echo_body
+  as_echo='sh -c $as_echo_body as_echo'
+fi
+
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  PATH_SEPARATOR=:
+  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
+    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
+      PATH_SEPARATOR=';'
+  }
+fi
+
+
+# IFS
+# We need space, tab and new line, in precisely that order.  Quoting is
+# there to prevent editors from complaining about space-tab.
+# (If _AS_PATH_WALK were called with IFS unset, it would disable word
+# splitting by setting IFS to empty value.)
+IFS=" ""	$as_nl"
+
+# Find who we are.  Look in the path if we contain no directory separator.
+as_myself=
+case $0 in #((
+  *[\\/]* ) as_myself=$0 ;;
+  *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+  done
+IFS=$as_save_IFS
+
+     ;;
+esac
+# We did not find ourselves, most probably we were run as `sh COMMAND'
+# in which case we are not to be found in the path.
+if test "x$as_myself" = x; then
+  as_myself=$0
+fi
+if test ! -f "$as_myself"; then
+  $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
+  exit 1
+fi
+
+# Unset variables that we do not need and which cause bugs (e.g. in
+# pre-3.0 UWIN ksh).  But do not cause bugs in bash 2.01; the "|| exit 1"
+# suppresses any "Segmentation fault" message there.  '((' could
+# trigger a bug in pdksh 5.2.14.
+for as_var in BASH_ENV ENV MAIL MAILPATH
+do eval test x\${$as_var+set} = xset \
+  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
+done
+PS1='$ '
+PS2='> '
+PS4='+ '
+
+# NLS nuisances.
+LC_ALL=C
+export LC_ALL
+LANGUAGE=C
+export LANGUAGE
+
+# CDPATH.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+# Use a proper internal environment variable to ensure we don't fall
+  # into an infinite loop, continuously re-executing ourselves.
+  if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then
+    _as_can_reexec=no; export _as_can_reexec;
+    # We cannot yet assume a decent shell, so we have to provide a
+# neutralization value for shells without unset; and this also
+# works around shells that cannot unset nonexistent variables.
+# Preserve -v and -x to the replacement shell.
+BASH_ENV=/dev/null
+ENV=/dev/null
+(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
+case $- in # ((((
+  *v*x* | *x*v* ) as_opts=-vx ;;
+  *v* ) as_opts=-v ;;
+  *x* ) as_opts=-x ;;
+  * ) as_opts= ;;
+esac
+exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
+# Admittedly, this is quite paranoid, since all the known shells bail
+# out after a failed `exec'.
+$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
+as_fn_exit 255
+  fi
+  # We don't want this to propagate to other subprocesses.
+          { _as_can_reexec=; unset _as_can_reexec;}
+if test "x$CONFIG_SHELL" = x; then
+  as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then :
+  emulate sh
+  NULLCMD=:
+  # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '\${1+\"\$@\"}'='\"\$@\"'
+  setopt NO_GLOB_SUBST
+else
+  case \`(set -o) 2>/dev/null\` in #(
+  *posix*) :
+    set -o posix ;; #(
+  *) :
+     ;;
+esac
+fi
+"
+  as_required="as_fn_return () { (exit \$1); }
+as_fn_success () { as_fn_return 0; }
+as_fn_failure () { as_fn_return 1; }
+as_fn_ret_success () { return 0; }
+as_fn_ret_failure () { return 1; }
+
+exitcode=0
+as_fn_success || { exitcode=1; echo as_fn_success failed.; }
+as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; }
+as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; }
+as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; }
+if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then :
+
+else
+  exitcode=1; echo positional parameters were not saved.
+fi
+test x\$exitcode = x0 || exit 1
+test -x / || exit 1"
+  as_suggested="  as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO
+  as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO
+  eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" &&
+  test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1
+test \$(( 1 + 1 )) = 2 || exit 1"
+  if (eval "$as_required") 2>/dev/null; then :
+  as_have_required=yes
+else
+  as_have_required=no
+fi
+  if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then :
+
+else
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+as_found=false
+for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+  as_found=:
+  case $as_dir in #(
+	 /*)
+	   for as_base in sh bash ksh sh5; do
+	     # Try only shells that exist, to save several forks.
+	     as_shell=$as_dir/$as_base
+	     if { test -f "$as_shell" || test -f "$as_shell.exe"; } &&
+		    { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then :
+  CONFIG_SHELL=$as_shell as_have_required=yes
+		   if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then :
+  break 2
+fi
+fi
+	   done;;
+       esac
+  as_found=false
+done
+$as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } &&
+	      { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then :
+  CONFIG_SHELL=$SHELL as_have_required=yes
+fi; }
+IFS=$as_save_IFS
+
+
+      if test "x$CONFIG_SHELL" != x; then :
+  export CONFIG_SHELL
+             # We cannot yet assume a decent shell, so we have to provide a
+# neutralization value for shells without unset; and this also
+# works around shells that cannot unset nonexistent variables.
+# Preserve -v and -x to the replacement shell.
+BASH_ENV=/dev/null
+ENV=/dev/null
+(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
+case $- in # ((((
+  *v*x* | *x*v* ) as_opts=-vx ;;
+  *v* ) as_opts=-v ;;
+  *x* ) as_opts=-x ;;
+  * ) as_opts= ;;
+esac
+exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
+# Admittedly, this is quite paranoid, since all the known shells bail
+# out after a failed `exec'.
+$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
+exit 255
+fi
+
+    if test x$as_have_required = xno; then :
+  $as_echo "$0: This script requires a shell more modern than all"
+  $as_echo "$0: the shells that I found on your system."
+  if test x${ZSH_VERSION+set} = xset ; then
+    $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should"
+    $as_echo "$0: be upgraded to zsh 4.3.4 or later."
+  else
+    $as_echo "$0: Please tell bug-autoconf@gnu.org about your system,
+$0: including any error possibly output before this
+$0: message. Then install a modern shell, or manually run
+$0: the script under such a shell if you do have one."
+  fi
+  exit 1
+fi
+fi
+fi
+SHELL=${CONFIG_SHELL-/bin/sh}
+export SHELL
+# Unset more variables known to interfere with behavior of common tools.
+CLICOLOR_FORCE= GREP_OPTIONS=
+unset CLICOLOR_FORCE GREP_OPTIONS
+
+## --------------------- ##
+## M4sh Shell Functions. ##
+## --------------------- ##
+# as_fn_unset VAR
+# ---------------
+# Portably unset VAR.
+as_fn_unset ()
+{
+  { eval $1=; unset $1;}
+}
+as_unset=as_fn_unset
+
+# as_fn_set_status STATUS
+# -----------------------
+# Set $? to STATUS, without forking.
+as_fn_set_status ()
+{
+  return $1
+} # as_fn_set_status
+
+# as_fn_exit STATUS
+# -----------------
+# Exit the shell with STATUS, even in a "trap 0" or "set -e" context.
+as_fn_exit ()
+{
+  set +e
+  as_fn_set_status $1
+  exit $1
+} # as_fn_exit
+
+# as_fn_mkdir_p
+# -------------
+# Create "$as_dir" as a directory, including parents if necessary.
+as_fn_mkdir_p ()
+{
+
+  case $as_dir in #(
+  -*) as_dir=./$as_dir;;
+  esac
+  test -d "$as_dir" || eval $as_mkdir_p || {
+    as_dirs=
+    while :; do
+      case $as_dir in #(
+      *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
+      *) as_qdir=$as_dir;;
+      esac
+      as_dirs="'$as_qdir' $as_dirs"
+      as_dir=`$as_dirname -- "$as_dir" ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$as_dir" : 'X\(//\)[^/]' \| \
+	 X"$as_dir" : 'X\(//\)$' \| \
+	 X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$as_dir" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+      test -d "$as_dir" && break
+    done
+    test -z "$as_dirs" || eval "mkdir $as_dirs"
+  } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir"
+
+
+} # as_fn_mkdir_p
+
+# as_fn_executable_p FILE
+# -----------------------
+# Test if FILE is an executable regular file.
+as_fn_executable_p ()
+{
+  test -f "$1" && test -x "$1"
+} # as_fn_executable_p
+# as_fn_append VAR VALUE
+# ----------------------
+# Append the text in VALUE to the end of the definition contained in VAR. Take
+# advantage of any shell optimizations that allow amortized linear growth over
+# repeated appends, instead of the typical quadratic growth present in naive
+# implementations.
+if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then :
+  eval 'as_fn_append ()
+  {
+    eval $1+=\$2
+  }'
+else
+  as_fn_append ()
+  {
+    eval $1=\$$1\$2
+  }
+fi # as_fn_append
+
+# as_fn_arith ARG...
+# ------------------
+# Perform arithmetic evaluation on the ARGs, and store the result in the
+# global $as_val. Take advantage of shells that can avoid forks. The arguments
+# must be portable across $(()) and expr.
+if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
+  eval 'as_fn_arith ()
+  {
+    as_val=$(( $* ))
+  }'
+else
+  as_fn_arith ()
+  {
+    as_val=`expr "$@" || test $? -eq 1`
+  }
+fi # as_fn_arith
+
+
+# as_fn_error STATUS ERROR [LINENO LOG_FD]
+# ----------------------------------------
+# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
+# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
+# script with STATUS, using 1 if that was 0.
+as_fn_error ()
+{
+  as_status=$1; test $as_status -eq 0 && as_status=1
+  if test "$4"; then
+    as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+    $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
+  fi
+  $as_echo "$as_me: error: $2" >&2
+  as_fn_exit $as_status
+} # as_fn_error
+
+if expr a : '\(a\)' >/dev/null 2>&1 &&
+   test "X`expr 00001 : '.*\(...\)'`" = X001; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then
+  as_basename=basename
+else
+  as_basename=false
+fi
+
+if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
+  as_dirname=dirname
+else
+  as_dirname=false
+fi
+
+as_me=`$as_basename -- "$0" ||
+$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
+	 X"$0" : 'X\(//\)$' \| \
+	 X"$0" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X/"$0" |
+    sed '/^.*\/\([^/][^/]*\)\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\/\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\/\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+
+  as_lineno_1=$LINENO as_lineno_1a=$LINENO
+  as_lineno_2=$LINENO as_lineno_2a=$LINENO
+  eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" &&
+  test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || {
+  # Blame Lee E. McMahon (1931-1989) for sed's syntax.  :-)
+  sed -n '
+    p
+    /[$]LINENO/=
+  ' <$as_myself |
+    sed '
+      s/[$]LINENO.*/&-/
+      t lineno
+      b
+      :lineno
+      N
+      :loop
+      s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/
+      t loop
+      s/-\n.*//
+    ' >$as_me.lineno &&
+  chmod +x "$as_me.lineno" ||
+    { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; }
+
+  # If we had to re-execute with $CONFIG_SHELL, we're ensured to have
+  # already done that, so ensure we don't try to do so again and fall
+  # in an infinite loop.  This has already happened in practice.
+  _as_can_reexec=no; export _as_can_reexec
+  # Don't try to exec as it changes $[0], causing all sort of problems
+  # (the dirname of $[0] is not the place where we might find the
+  # original and so on.  Autoconf is especially sensitive to this).
+  . "./$as_me.lineno"
+  # Exit status is that of the last command.
+  exit
+}
+
+ECHO_C= ECHO_N= ECHO_T=
+case `echo -n x` in #(((((
+-n*)
+  case `echo 'xy\c'` in
+  *c*) ECHO_T='	';;	# ECHO_T is single tab character.
+  xy)  ECHO_C='\c';;
+  *)   echo `echo ksh88 bug on AIX 6.1` > /dev/null
+       ECHO_T='	';;
+  esac;;
+*)
+  ECHO_N='-n';;
+esac
+
+rm -f conf$$ conf$$.exe conf$$.file
+if test -d conf$$.dir; then
+  rm -f conf$$.dir/conf$$.file
+else
+  rm -f conf$$.dir
+  mkdir conf$$.dir 2>/dev/null
+fi
+if (echo >conf$$.file) 2>/dev/null; then
+  if ln -s conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s='ln -s'
+    # ... but there are two gotchas:
+    # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
+    # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
+    # In both cases, we have to default to `cp -pR'.
+    ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
+      as_ln_s='cp -pR'
+  elif ln conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s=ln
+  else
+    as_ln_s='cp -pR'
+  fi
+else
+  as_ln_s='cp -pR'
+fi
+rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
+rmdir conf$$.dir 2>/dev/null
+
+if mkdir -p . 2>/dev/null; then
+  as_mkdir_p='mkdir -p "$as_dir"'
+else
+  test -d ./-p && rmdir ./-p
+  as_mkdir_p=false
+fi
+
+as_test_x='test -x'
+as_executable_p=as_fn_executable_p
+
+# Sed expression to map a string onto a valid CPP name.
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
+
+# Sed expression to map a string onto a valid variable name.
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
+
+
+test -n "$DJDIR" || exec 7<&0 </dev/null
+exec 6>&1
+
+# Name of the host.
+# hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status,
+# so uname gets run too.
+ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q`
+
+#
+# Initializations.
+#
+ac_default_prefix=/usr/local
+ac_clean_files=
+ac_config_libobj_dir=.
+LIBOBJS=
+cross_compiling=no
+subdirs=
+MFLAGS=
+MAKEFLAGS=
+
+# Identity of this package.
+PACKAGE_NAME=
+PACKAGE_TARNAME=
+PACKAGE_VERSION=
+PACKAGE_STRING=
+PACKAGE_BUGREPORT=
+PACKAGE_URL=
+
+ac_unique_file="pr/include/nspr.h"
+# Factoring default headers for most tests.
+ac_includes_default="\
+#include <stdio.h>
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
+#ifdef STDC_HEADERS
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+#  include <stdlib.h>
+# endif
+#endif
+#ifdef HAVE_STRING_H
+# if !defined STDC_HEADERS && defined HAVE_MEMORY_H
+#  include <memory.h>
+# endif
+# include <string.h>
+#endif
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+#ifdef HAVE_INTTYPES_H
+# include <inttypes.h>
+#endif
+#ifdef HAVE_STDINT_H
+# include <stdint.h>
+#endif
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif"
+
+ac_subst_vars='LTLIBOBJS
+LIBOBJS
+MT
+NEXT_ROOT
+SYMBIAN_SDK_DIR
+MACOS_SDK_DIR
+WRAP_SYSTEM_INCLUDES
+VISIBILITY_FLAGS
+CYGWIN_WRAPPER
+OS_DLLFLAGS
+EXEFLAGS
+DLLFLAGS
+RCFLAGS
+RC
+OPTIMIZER
+NSINSTALL
+RELEASE_OBJDIR_NAME
+OBJDIR_NAME
+OBJDIR
+ULTRASPARC_LIBRARY
+MOZ_OBJFORMAT
+NOSUCHFILE
+AIX_LINK_OPTS
+RESOLVE_LINK_SYMBOLS
+OS_LIBS
+PROFILE_USE_LDFLAGS
+PROFILE_USE_CFLAGS
+PROFILE_GEN_LDFLAGS
+PROFILE_GEN_CFLAGS
+IMPLIB
+FILTER
+ASFLAGS
+AR_FLAGS
+DEFINES
+MACOSX_DEPLOYMENT_TARGET
+OS_TEST
+OS_RELEASE
+OS_ARCH
+OS_TARGET
+DSO_LDOPTS
+DSO_CFLAGS
+MKSHLIB
+WRAP_LDFLAGS
+ASM_SUFFIX
+DLL_SUFFIX
+LIB_SUFFIX
+OBJ_SUFFIX
+CPU_ARCH
+PR_MD_ARCH_DIR
+PR_MD_ASFILES
+PR_MD_CSRCS
+MDCPUCFG_H
+NSPR_MODNAME
+MOD_PATCH_VERSION
+MOD_MINOR_VERSION
+MOD_MAJOR_VERSION
+LIBPLC
+LIBNSPR
+USE_NSPR_THREADS
+USE_USER_PTHREADS
+USE_BTHREADS
+USE_PTHREADS
+ENABLE_STRIP
+OBJECT_MODE
+USE_64
+USE_X32
+USE_N32
+USE_IPV6
+USE_CPLUS
+MOZ_DEBUG_SYMBOLS
+MOZ_DEBUG
+MOZ_OPTIMIZE
+CROSS_COMPILE
+MSC_VER
+GCC_USE_GNU_LD
+GNU_CC
+HOST_LDFLAGS
+HOST_CFLAGS
+MOZILLA_CLIENT
+SHELL_OVERRIDE
+CCACHE
+EGREP
+GREP
+PERL
+CPP
+HOST_CC
+WINDRES
+STRIP
+LD
+AS
+AR
+RANLIB
+ac_ct_CXX
+CXXFLAGS
+CXX
+OBJEXT
+EXEEXT
+ac_ct_CC
+CPPFLAGS
+LDFLAGS
+CFLAGS
+WHOAMI
+dist_libdir
+dist_includedir
+dist_bindir
+dist_prefix
+CC
+target_os
+target_vendor
+target_cpu
+target
+host_os
+host_vendor
+host_cpu
+host
+build_os
+build_vendor
+build_cpu
+build
+target_alias
+host_alias
+build_alias
+LIBS
+ECHO_T
+ECHO_N
+ECHO_C
+DEFS
+mandir
+localedir
+libdir
+psdir
+pdfdir
+dvidir
+htmldir
+infodir
+docdir
+oldincludedir
+includedir
+localstatedir
+sharedstatedir
+sysconfdir
+datadir
+datarootdir
+libexecdir
+sbindir
+bindir
+program_transform_name
+prefix
+exec_prefix
+PACKAGE_URL
+PACKAGE_BUGREPORT
+PACKAGE_STRING
+PACKAGE_VERSION
+PACKAGE_TARNAME
+PACKAGE_NAME
+PATH_SEPARATOR
+SHELL'
+ac_subst_files=''
+ac_user_opts='
+enable_option_checking
+with_android_ndk
+with_android_toolchain
+with_android_version
+with_android_platform
+with_gonk
+with_dist_prefix
+with_dist_bindir
+with_dist_includedir
+with_dist_libdir
+with_mozilla
+enable_optimize
+enable_debug
+enable_debug_symbols
+enable_win32_target
+enable_symbian_target
+enable_debug_rtl
+enable_static_rtl
+enable_n32
+enable_x32
+enable_64bit
+enable_mdupdate
+enable_cplus
+with_arm_kuser
+with_macos_sdk
+enable_macos_target
+enable_os2_high_mem
+enable_thumb2
+with_thumb
+with_thumb_interwork
+with_arch
+with_fpu
+with_float_abi
+with_soft_float
+with_symbian_sdk
+with_ccache
+enable_strip
+with_pthreads
+enable_user_pthreads
+enable_nspr_threads
+with_bthreads
+enable_ipv6
+enable_wrap_malloc
+with_wrap_malloc
+'
+      ac_precious_vars='build_alias
+host_alias
+target_alias
+CC
+CFLAGS
+LDFLAGS
+LIBS
+CPPFLAGS
+CXX
+CXXFLAGS
+CCC
+CPP'
+
+
+# Initialize some variables set by options.
+ac_init_help=
+ac_init_version=false
+ac_unrecognized_opts=
+ac_unrecognized_sep=
+# The variables have the same names as the options, with
+# dashes changed to underlines.
+cache_file=/dev/null
+exec_prefix=NONE
+no_create=
+no_recursion=
+prefix=NONE
+program_prefix=NONE
+program_suffix=NONE
+program_transform_name=s,x,x,
+silent=
+site=
+srcdir=
+verbose=
+x_includes=NONE
+x_libraries=NONE
+
+# Installation directory options.
+# These are left unexpanded so users can "make install exec_prefix=/foo"
+# and all the variables that are supposed to be based on exec_prefix
+# by default will actually change.
+# Use braces instead of parens because sh, perl, etc. also accept them.
+# (The list follows the same order as the GNU Coding Standards.)
+bindir='${exec_prefix}/bin'
+sbindir='${exec_prefix}/sbin'
+libexecdir='${exec_prefix}/libexec'
+datarootdir='${prefix}/share'
+datadir='${datarootdir}'
+sysconfdir='${prefix}/etc'
+sharedstatedir='${prefix}/com'
+localstatedir='${prefix}/var'
+includedir='${prefix}/include'
+oldincludedir='/usr/include'
+docdir='${datarootdir}/doc/${PACKAGE}'
+infodir='${datarootdir}/info'
+htmldir='${docdir}'
+dvidir='${docdir}'
+pdfdir='${docdir}'
+psdir='${docdir}'
+libdir='${exec_prefix}/lib'
+localedir='${datarootdir}/locale'
+mandir='${datarootdir}/man'
+
+ac_prev=
+ac_dashdash=
+for ac_option
+do
+  # If the previous option needs an argument, assign it.
+  if test -n "$ac_prev"; then
+    eval $ac_prev=\$ac_option
+    ac_prev=
+    continue
+  fi
+
+  case $ac_option in
+  *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;;
+  *=)   ac_optarg= ;;
+  *)    ac_optarg=yes ;;
+  esac
+
+  # Accept the important Cygnus configure options, so we can diagnose typos.
+
+  case $ac_dashdash$ac_option in
+  --)
+    ac_dashdash=yes ;;
+
+  -bindir | --bindir | --bindi | --bind | --bin | --bi)
+    ac_prev=bindir ;;
+  -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*)
+    bindir=$ac_optarg ;;
+
+  -build | --build | --buil | --bui | --bu)
+    ac_prev=build_alias ;;
+  -build=* | --build=* | --buil=* | --bui=* | --bu=*)
+    build_alias=$ac_optarg ;;
+
+  -cache-file | --cache-file | --cache-fil | --cache-fi \
+  | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c)
+    ac_prev=cache_file ;;
+  -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \
+  | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*)
+    cache_file=$ac_optarg ;;
+
+  --config-cache | -C)
+    cache_file=config.cache ;;
+
+  -datadir | --datadir | --datadi | --datad)
+    ac_prev=datadir ;;
+  -datadir=* | --datadir=* | --datadi=* | --datad=*)
+    datadir=$ac_optarg ;;
+
+  -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \
+  | --dataroo | --dataro | --datar)
+    ac_prev=datarootdir ;;
+  -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \
+  | --dataroot=* | --dataroo=* | --dataro=* | --datar=*)
+    datarootdir=$ac_optarg ;;
+
+  -disable-* | --disable-*)
+    ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      as_fn_error $? "invalid feature name: $ac_useropt"
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"enable_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig"
+	 ac_unrecognized_sep=', ';;
+    esac
+    eval enable_$ac_useropt=no ;;
+
+  -docdir | --docdir | --docdi | --doc | --do)
+    ac_prev=docdir ;;
+  -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*)
+    docdir=$ac_optarg ;;
+
+  -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv)
+    ac_prev=dvidir ;;
+  -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*)
+    dvidir=$ac_optarg ;;
+
+  -enable-* | --enable-*)
+    ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      as_fn_error $? "invalid feature name: $ac_useropt"
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"enable_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig"
+	 ac_unrecognized_sep=', ';;
+    esac
+    eval enable_$ac_useropt=\$ac_optarg ;;
+
+  -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \
+  | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \
+  | --exec | --exe | --ex)
+    ac_prev=exec_prefix ;;
+  -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \
+  | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \
+  | --exec=* | --exe=* | --ex=*)
+    exec_prefix=$ac_optarg ;;
+
+  -gas | --gas | --ga | --g)
+    # Obsolete; use --with-gas.
+    with_gas=yes ;;
+
+  -help | --help | --hel | --he | -h)
+    ac_init_help=long ;;
+  -help=r* | --help=r* | --hel=r* | --he=r* | -hr*)
+    ac_init_help=recursive ;;
+  -help=s* | --help=s* | --hel=s* | --he=s* | -hs*)
+    ac_init_help=short ;;
+
+  -host | --host | --hos | --ho)
+    ac_prev=host_alias ;;
+  -host=* | --host=* | --hos=* | --ho=*)
+    host_alias=$ac_optarg ;;
+
+  -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht)
+    ac_prev=htmldir ;;
+  -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \
+  | --ht=*)
+    htmldir=$ac_optarg ;;
+
+  -includedir | --includedir | --includedi | --included | --include \
+  | --includ | --inclu | --incl | --inc)
+    ac_prev=includedir ;;
+  -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \
+  | --includ=* | --inclu=* | --incl=* | --inc=*)
+    includedir=$ac_optarg ;;
+
+  -infodir | --infodir | --infodi | --infod | --info | --inf)
+    ac_prev=infodir ;;
+  -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*)
+    infodir=$ac_optarg ;;
+
+  -libdir | --libdir | --libdi | --libd)
+    ac_prev=libdir ;;
+  -libdir=* | --libdir=* | --libdi=* | --libd=*)
+    libdir=$ac_optarg ;;
+
+  -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \
+  | --libexe | --libex | --libe)
+    ac_prev=libexecdir ;;
+  -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \
+  | --libexe=* | --libex=* | --libe=*)
+    libexecdir=$ac_optarg ;;
+
+  -localedir | --localedir | --localedi | --localed | --locale)
+    ac_prev=localedir ;;
+  -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*)
+    localedir=$ac_optarg ;;
+
+  -localstatedir | --localstatedir | --localstatedi | --localstated \
+  | --localstate | --localstat | --localsta | --localst | --locals)
+    ac_prev=localstatedir ;;
+  -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \
+  | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*)
+    localstatedir=$ac_optarg ;;
+
+  -mandir | --mandir | --mandi | --mand | --man | --ma | --m)
+    ac_prev=mandir ;;
+  -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*)
+    mandir=$ac_optarg ;;
+
+  -nfp | --nfp | --nf)
+    # Obsolete; use --without-fp.
+    with_fp=no ;;
+
+  -no-create | --no-create | --no-creat | --no-crea | --no-cre \
+  | --no-cr | --no-c | -n)
+    no_create=yes ;;
+
+  -no-recursion | --no-recursion | --no-recursio | --no-recursi \
+  | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r)
+    no_recursion=yes ;;
+
+  -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \
+  | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \
+  | --oldin | --oldi | --old | --ol | --o)
+    ac_prev=oldincludedir ;;
+  -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \
+  | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \
+  | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*)
+    oldincludedir=$ac_optarg ;;
+
+  -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
+    ac_prev=prefix ;;
+  -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
+    prefix=$ac_optarg ;;
+
+  -program-prefix | --program-prefix | --program-prefi | --program-pref \
+  | --program-pre | --program-pr | --program-p)
+    ac_prev=program_prefix ;;
+  -program-prefix=* | --program-prefix=* | --program-prefi=* \
+  | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*)
+    program_prefix=$ac_optarg ;;
+
+  -program-suffix | --program-suffix | --program-suffi | --program-suff \
+  | --program-suf | --program-su | --program-s)
+    ac_prev=program_suffix ;;
+  -program-suffix=* | --program-suffix=* | --program-suffi=* \
+  | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*)
+    program_suffix=$ac_optarg ;;
+
+  -program-transform-name | --program-transform-name \
+  | --program-transform-nam | --program-transform-na \
+  | --program-transform-n | --program-transform- \
+  | --program-transform | --program-transfor \
+  | --program-transfo | --program-transf \
+  | --program-trans | --program-tran \
+  | --progr-tra | --program-tr | --program-t)
+    ac_prev=program_transform_name ;;
+  -program-transform-name=* | --program-transform-name=* \
+  | --program-transform-nam=* | --program-transform-na=* \
+  | --program-transform-n=* | --program-transform-=* \
+  | --program-transform=* | --program-transfor=* \
+  | --program-transfo=* | --program-transf=* \
+  | --program-trans=* | --program-tran=* \
+  | --progr-tra=* | --program-tr=* | --program-t=*)
+    program_transform_name=$ac_optarg ;;
+
+  -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd)
+    ac_prev=pdfdir ;;
+  -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*)
+    pdfdir=$ac_optarg ;;
+
+  -psdir | --psdir | --psdi | --psd | --ps)
+    ac_prev=psdir ;;
+  -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*)
+    psdir=$ac_optarg ;;
+
+  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+  | -silent | --silent | --silen | --sile | --sil)
+    silent=yes ;;
+
+  -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
+    ac_prev=sbindir ;;
+  -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
+  | --sbi=* | --sb=*)
+    sbindir=$ac_optarg ;;
+
+  -sharedstatedir | --sharedstatedir | --sharedstatedi \
+  | --sharedstated | --sharedstate | --sharedstat | --sharedsta \
+  | --sharedst | --shareds | --shared | --share | --shar \
+  | --sha | --sh)
+    ac_prev=sharedstatedir ;;
+  -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \
+  | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \
+  | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \
+  | --sha=* | --sh=*)
+    sharedstatedir=$ac_optarg ;;
+
+  -site | --site | --sit)
+    ac_prev=site ;;
+  -site=* | --site=* | --sit=*)
+    site=$ac_optarg ;;
+
+  -srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
+    ac_prev=srcdir ;;
+  -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
+    srcdir=$ac_optarg ;;
+
+  -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \
+  | --syscon | --sysco | --sysc | --sys | --sy)
+    ac_prev=sysconfdir ;;
+  -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \
+  | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*)
+    sysconfdir=$ac_optarg ;;
+
+  -target | --target | --targe | --targ | --tar | --ta | --t)
+    ac_prev=target_alias ;;
+  -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)
+    target_alias=$ac_optarg ;;
+
+  -v | -verbose | --verbose | --verbos | --verbo | --verb)
+    verbose=yes ;;
+
+  -version | --version | --versio | --versi | --vers | -V)
+    ac_init_version=: ;;
+
+  -with-* | --with-*)
+    ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      as_fn_error $? "invalid package name: $ac_useropt"
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"with_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig"
+	 ac_unrecognized_sep=', ';;
+    esac
+    eval with_$ac_useropt=\$ac_optarg ;;
+
+  -without-* | --without-*)
+    ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'`
+    # Reject names that are not valid shell variable names.
+    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
+      as_fn_error $? "invalid package name: $ac_useropt"
+    ac_useropt_orig=$ac_useropt
+    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
+    case $ac_user_opts in
+      *"
+"with_$ac_useropt"
+"*) ;;
+      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig"
+	 ac_unrecognized_sep=', ';;
+    esac
+    eval with_$ac_useropt=no ;;
+
+  --x)
+    # Obsolete; use --with-x.
+    with_x=yes ;;
+
+  -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \
+  | --x-incl | --x-inc | --x-in | --x-i)
+    ac_prev=x_includes ;;
+  -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \
+  | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*)
+    x_includes=$ac_optarg ;;
+
+  -x-libraries | --x-libraries | --x-librarie | --x-librari \
+  | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l)
+    ac_prev=x_libraries ;;
+  -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \
+  | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)
+    x_libraries=$ac_optarg ;;
+
+  -*) as_fn_error $? "unrecognized option: \`$ac_option'
+Try \`$0 --help' for more information"
+    ;;
+
+  *=*)
+    ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='`
+    # Reject names that are not valid shell variable names.
+    case $ac_envvar in #(
+      '' | [0-9]* | *[!_$as_cr_alnum]* )
+      as_fn_error $? "invalid variable name: \`$ac_envvar'" ;;
+    esac
+    eval $ac_envvar=\$ac_optarg
+    export $ac_envvar ;;
+
+  *)
+    # FIXME: should be removed in autoconf 3.0.
+    $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2
+    expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null &&
+      $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2
+    : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}"
+    ;;
+
+  esac
+done
+
+if test -n "$ac_prev"; then
+  ac_option=--`echo $ac_prev | sed 's/_/-/g'`
+  as_fn_error $? "missing argument to $ac_option"
+fi
+
+if test -n "$ac_unrecognized_opts"; then
+  case $enable_option_checking in
+    no) ;;
+    fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;;
+    *)     $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;;
+  esac
+fi
+
+# Check all directory arguments for consistency.
+for ac_var in	exec_prefix prefix bindir sbindir libexecdir datarootdir \
+		datadir sysconfdir sharedstatedir localstatedir includedir \
+		oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
+		libdir localedir mandir
+do
+  eval ac_val=\$$ac_var
+  # Remove trailing slashes.
+  case $ac_val in
+    */ )
+      ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'`
+      eval $ac_var=\$ac_val;;
+  esac
+  # Be sure to have absolute directory names.
+  case $ac_val in
+    [\\/$]* | ?:[\\/]* )  continue;;
+    NONE | '' ) case $ac_var in *prefix ) continue;; esac;;
+  esac
+  as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val"
+done
+
+# There might be people who depend on the old broken behavior: `$host'
+# used to hold the argument of --host etc.
+# FIXME: To remove some day.
+build=$build_alias
+host=$host_alias
+target=$target_alias
+
+# FIXME: To remove some day.
+if test "x$host_alias" != x; then
+  if test "x$build_alias" = x; then
+    cross_compiling=maybe
+  elif test "x$build_alias" != "x$host_alias"; then
+    cross_compiling=yes
+  fi
+fi
+
+ac_tool_prefix=
+test -n "$host_alias" && ac_tool_prefix=$host_alias-
+
+test "$silent" = yes && exec 6>/dev/null
+
+
+ac_pwd=`pwd` && test -n "$ac_pwd" &&
+ac_ls_di=`ls -di .` &&
+ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` ||
+  as_fn_error $? "working directory cannot be determined"
+test "X$ac_ls_di" = "X$ac_pwd_ls_di" ||
+  as_fn_error $? "pwd does not report name of working directory"
+
+
+# Find the source files, if location was not specified.
+if test -z "$srcdir"; then
+  ac_srcdir_defaulted=yes
+  # Try the directory containing this script, then the parent directory.
+  ac_confdir=`$as_dirname -- "$as_myself" ||
+$as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$as_myself" : 'X\(//\)[^/]' \| \
+	 X"$as_myself" : 'X\(//\)$' \| \
+	 X"$as_myself" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$as_myself" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+  srcdir=$ac_confdir
+  if test ! -r "$srcdir/$ac_unique_file"; then
+    srcdir=..
+  fi
+else
+  ac_srcdir_defaulted=no
+fi
+if test ! -r "$srcdir/$ac_unique_file"; then
+  test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .."
+  as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir"
+fi
+ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work"
+ac_abs_confdir=`(
+	cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg"
+	pwd)`
+# When building in place, set srcdir=.
+if test "$ac_abs_confdir" = "$ac_pwd"; then
+  srcdir=.
+fi
+# Remove unnecessary trailing slashes from srcdir.
+# Double slashes in file names in object file debugging info
+# mess up M-x gdb in Emacs.
+case $srcdir in
+*/) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;;
+esac
+for ac_var in $ac_precious_vars; do
+  eval ac_env_${ac_var}_set=\${${ac_var}+set}
+  eval ac_env_${ac_var}_value=\$${ac_var}
+  eval ac_cv_env_${ac_var}_set=\${${ac_var}+set}
+  eval ac_cv_env_${ac_var}_value=\$${ac_var}
+done
+
+#
+# Report the --help message.
+#
+if test "$ac_init_help" = "long"; then
+  # Omit some internal or obsolete options to make the list less imposing.
+  # This message is too long to be a string in the A/UX 3.1 sh.
+  cat <<_ACEOF
+\`configure' configures this package to adapt to many kinds of systems.
+
+Usage: $0 [OPTION]... [VAR=VALUE]...
+
+To assign environment variables (e.g., CC, CFLAGS...), specify them as
+VAR=VALUE.  See below for descriptions of some of the useful variables.
+
+Defaults for the options are specified in brackets.
+
+Configuration:
+  -h, --help              display this help and exit
+      --help=short        display options specific to this package
+      --help=recursive    display the short help of all the included packages
+  -V, --version           display version information and exit
+  -q, --quiet, --silent   do not print \`checking ...' messages
+      --cache-file=FILE   cache test results in FILE [disabled]
+  -C, --config-cache      alias for \`--cache-file=config.cache'
+  -n, --no-create         do not create output files
+      --srcdir=DIR        find the sources in DIR [configure dir or \`..']
+
+Installation directories:
+  --prefix=PREFIX         install architecture-independent files in PREFIX
+                          [$ac_default_prefix]
+  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
+                          [PREFIX]
+
+By default, \`make install' will install all the files in
+\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc.  You can specify
+an installation prefix other than \`$ac_default_prefix' using \`--prefix',
+for instance \`--prefix=\$HOME'.
+
+For better control, use the options below.
+
+Fine tuning of the installation directories:
+  --bindir=DIR            user executables [EPREFIX/bin]
+  --sbindir=DIR           system admin executables [EPREFIX/sbin]
+  --libexecdir=DIR        program executables [EPREFIX/libexec]
+  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
+  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
+  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
+  --libdir=DIR            object code libraries [EPREFIX/lib]
+  --includedir=DIR        C header files [PREFIX/include]
+  --oldincludedir=DIR     C header files for non-gcc [/usr/include]
+  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
+  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
+  --infodir=DIR           info documentation [DATAROOTDIR/info]
+  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
+  --mandir=DIR            man documentation [DATAROOTDIR/man]
+  --docdir=DIR            documentation root [DATAROOTDIR/doc/PACKAGE]
+  --htmldir=DIR           html documentation [DOCDIR]
+  --dvidir=DIR            dvi documentation [DOCDIR]
+  --pdfdir=DIR            pdf documentation [DOCDIR]
+  --psdir=DIR             ps documentation [DOCDIR]
+_ACEOF
+
+  cat <<\_ACEOF
+
+System types:
+  --build=BUILD     configure for building on BUILD [guessed]
+  --host=HOST       cross-compile to build programs to run on HOST [BUILD]
+  --target=TARGET   configure for building compilers for TARGET [HOST]
+_ACEOF
+fi
+
+if test -n "$ac_init_help"; then
+
+  cat <<\_ACEOF
+
+Optional Features:
+  --disable-option-checking  ignore unrecognized --enable/--with options
+  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
+  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
+  --enable-optimize=OPT Enable code optimizations (ie. -O2)
+  --enable-debug=DBG    Enable debugging (using compiler flags DBG)
+  --enable-debug-symbols=DBG    Enable debugging symbols
+                                       (using compiler flags DBG)
+  --enable-win32-target=\$t
+                          Specify win32 flavor. (WIN95 or WINNT)
+  --enable-symbian-target=\$t
+                          Specify symbian flavor. (WINSCW or GCCE)
+  --enable-debug-rtl      Use the MSVC debug runtime library
+  --enable-static-rtl     Use the MSVC static runtime library
+  --enable-n32            Enable n32 ABI support (IRIX only)
+  --enable-x32            Enable x32 ABI support (x86_64 only)
+  --enable-64bit          Enable 64-bit support (on certain platforms)
+  --enable-mdupdate       Enable use of certain compilers' mdupdate feature
+  --enable-cplus          Enable some c++ api routines
+  --enable-macos-target=VER
+                          Set the minimum MacOS version needed at runtime
+                          10.2 for ppc, 10.4 for x86
+  --disable-os2-high-mem  Disable high-memory support on OS/2
+
+  --enable-strip          Enable stripping of shared libs and programs
+  --enable-user-pthreads  Build using userland pthreads
+  --enable-nspr-threads   Build using classic nspr threads
+  --enable-ipv6           Compile ipv6 support
+  --enable-wrap-malloc    Wrap malloc calls (gnu linker only)
+
+Optional Packages:
+  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
+  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
+  --with-android-ndk=DIR
+                          location where the Android NDK can be found
+  --with-android-toolchain=DIR
+                          location of the Android toolchain
+  --with-android-version=VER
+                          Android platform version, default 5 for arm, 9 for x86/mips
+  --with-android-platform=DIR
+                          location of platform dir
+  --with-gonk=DIR         location of gonk dir
+  --with-dist-prefix=DIST_PREFIX
+                          place build files in DIST_PREFIX dist
+  --with-dist-bindir=DIR  build execuatables in DIR DIST_PREFIX/bin
+  --with-dist-includedir=DIR
+                          build include files in DIR DIST_PREFIX/include/nspr
+  --with-dist-libdir=DIR  build library files in DIR DIST_PREFIX/lib
+  --with-mozilla          Compile NSPR with Mozilla support
+  --with-arm-kuser        Use kuser helpers (Linux/ARM only)
+                          (Requires kernel 2.6.13 or later)
+  --with-macos-sdk=dir    Location of platform SDK to use (Mac OS X only)
+  --with-thumb[=yes|no|toolchain-default]
+                          Use Thumb instruction set (-mthumb)
+  --with-thumb-interwork[=yes|no|toolchain-default]
+                           Use Thumb/ARM instuctions interwork (-mthumb-interwork)
+  --with-arch=[type|toolchain-default]
+                           Use specific CPU features (-march=type)
+  --with-fpu=[type|toolchain-default]
+                           Use specific FPU type (-mfpu=type)
+  --with-float-abi=[type|toolchain-default]
+                           Use specific arm float ABI (-mfloat-abi=type)
+  --with-soft-float[=yes|no|toolchain-default]
+                           Use soft float library (-msoft-float)
+  --with-symbian-sdk=SYMBIAN_SDK_DIR
+                          The path to the Symbian SDK
+  --with-ccache=path/to/ccache
+                          Enable compiling with ccache
+  --with-pthreads         Use system pthreads library as thread subsystem
+  --with-bthreads         Use system bthreads library as thread subsystem
+                          (BeOS only)
+  --with-wrap-malloc=SHAREDLIB  Location of malloc wrapper library
+
+Some influential environment variables:
+  CC          C compiler command
+  CFLAGS      C compiler flags
+  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
+              nonstandard directory <lib dir>
+  LIBS        libraries to pass to the linker, e.g. -l<library>
+  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
+              you have headers in a nonstandard directory <include dir>
+  CXX         C++ compiler command
+  CXXFLAGS    C++ compiler flags
+  CPP         C preprocessor
+
+Use these variables to override the choices made by `configure' or to help
+it to find libraries and programs with nonstandard names/locations.
+
+Report bugs to the package provider.
+_ACEOF
+ac_status=$?
+fi
+
+if test "$ac_init_help" = "recursive"; then
+  # If there are subdirs, report their specific --help.
+  for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue
+    test -d "$ac_dir" ||
+      { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } ||
+      continue
+    ac_builddir=.
+
+case "$ac_dir" in
+.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
+*)
+  ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'`
+  # A ".." for each directory in $ac_dir_suffix.
+  ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
+  case $ac_top_builddir_sub in
+  "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
+  *)  ac_top_build_prefix=$ac_top_builddir_sub/ ;;
+  esac ;;
+esac
+ac_abs_top_builddir=$ac_pwd
+ac_abs_builddir=$ac_pwd$ac_dir_suffix
+# for backward compatibility:
+ac_top_builddir=$ac_top_build_prefix
+
+case $srcdir in
+  .)  # We are building in place.
+    ac_srcdir=.
+    ac_top_srcdir=$ac_top_builddir_sub
+    ac_abs_top_srcdir=$ac_pwd ;;
+  [\\/]* | ?:[\\/]* )  # Absolute name.
+    ac_srcdir=$srcdir$ac_dir_suffix;
+    ac_top_srcdir=$srcdir
+    ac_abs_top_srcdir=$srcdir ;;
+  *) # Relative name.
+    ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix
+    ac_top_srcdir=$ac_top_build_prefix$srcdir
+    ac_abs_top_srcdir=$ac_pwd/$srcdir ;;
+esac
+ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix
+
+    cd "$ac_dir" || { ac_status=$?; continue; }
+    # Check for guested configure.
+    if test -f "$ac_srcdir/configure.gnu"; then
+      echo &&
+      $SHELL "$ac_srcdir/configure.gnu" --help=recursive
+    elif test -f "$ac_srcdir/configure"; then
+      echo &&
+      $SHELL "$ac_srcdir/configure" --help=recursive
+    else
+      $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2
+    fi || ac_status=$?
+    cd "$ac_pwd" || { ac_status=$?; break; }
+  done
+fi
+
+test -n "$ac_init_help" && exit $ac_status
+if $ac_init_version; then
+  cat <<\_ACEOF
+configure
+generated by GNU Autoconf 2.69
+
+Copyright (C) 2012 Free Software Foundation, Inc.
+This configure script is free software; the Free Software Foundation
+gives unlimited permission to copy, distribute and modify it.
+_ACEOF
+  exit
+fi
+
+## ------------------------ ##
+## Autoconf initialization. ##
+## ------------------------ ##
+
+# ac_fn_c_try_compile LINENO
+# --------------------------
+# Try to compile conftest.$ac_ext, and return whether this succeeded.
+ac_fn_c_try_compile ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  rm -f conftest.$ac_objext
+  if { { ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_compile") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    grep -v '^ *+' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+    mv -f conftest.er1 conftest.err
+  fi
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then :
+  ac_retval=0
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_retval=1
+fi
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+  as_fn_set_status $ac_retval
+
+} # ac_fn_c_try_compile
+
+# ac_fn_cxx_try_compile LINENO
+# ----------------------------
+# Try to compile conftest.$ac_ext, and return whether this succeeded.
+ac_fn_cxx_try_compile ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  rm -f conftest.$ac_objext
+  if { { ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_compile") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    grep -v '^ *+' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+    mv -f conftest.er1 conftest.err
+  fi
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && {
+	 test -z "$ac_cxx_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then :
+  ac_retval=0
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_retval=1
+fi
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+  as_fn_set_status $ac_retval
+
+} # ac_fn_cxx_try_compile
+
+# ac_fn_c_try_cpp LINENO
+# ----------------------
+# Try to preprocess conftest.$ac_ext, and return whether this succeeded.
+ac_fn_c_try_cpp ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  if { { ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    grep -v '^ *+' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+    mv -f conftest.er1 conftest.err
+  fi
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } > conftest.i && {
+	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       }; then :
+  ac_retval=0
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+    ac_retval=1
+fi
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+  as_fn_set_status $ac_retval
+
+} # ac_fn_c_try_cpp
+
+# ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES
+# -------------------------------------------------------
+# Tests whether HEADER exists, giving a warning if it cannot be compiled using
+# the include files in INCLUDES and setting the cache variable VAR
+# accordingly.
+ac_fn_c_check_header_mongrel ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  if eval \${$3+:} false; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if eval \${$3+:} false; then :
+  $as_echo_n "(cached) " >&6
+fi
+eval ac_res=\$$3
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+else
+  # Is the header compilable?
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5
+$as_echo_n "checking $2 usability... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+#include <$2>
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_header_compiler=yes
+else
+  ac_header_compiler=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5
+$as_echo "$ac_header_compiler" >&6; }
+
+# Is the header present?
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5
+$as_echo_n "checking $2 presence... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <$2>
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+  ac_header_preproc=yes
+else
+  ac_header_preproc=no
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5
+$as_echo "$ac_header_preproc" >&6; }
+
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #((
+  yes:no: )
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5
+$as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
+$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
+    ;;
+  no:yes:* )
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5
+$as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2:     check for missing prerequisite headers?" >&5
+$as_echo "$as_me: WARNING: $2:     check for missing prerequisite headers?" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5
+$as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2:     section \"Present But Cannot Be Compiled\"" >&5
+$as_echo "$as_me: WARNING: $2:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
+$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
+    ;;
+esac
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if eval \${$3+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  eval "$3=\$ac_header_compiler"
+fi
+eval ac_res=\$$3
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+fi
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+
+} # ac_fn_c_check_header_mongrel
+
+# ac_fn_c_try_run LINENO
+# ----------------------
+# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes
+# that executables *can* be run.
+ac_fn_c_try_run ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  if { { ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_link") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && { ac_try='./conftest$ac_exeext'
+  { { case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }; then :
+  ac_retval=0
+else
+  $as_echo "$as_me: program exited with status $ac_status" >&5
+       $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+       ac_retval=$ac_status
+fi
+  rm -rf conftest.dSYM conftest_ipa8_conftest.oo
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+  as_fn_set_status $ac_retval
+
+} # ac_fn_c_try_run
+
+# ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES
+# -------------------------------------------------------
+# Tests whether HEADER exists and can be compiled using the include files in
+# INCLUDES, setting the cache variable VAR accordingly.
+ac_fn_c_check_header_compile ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if eval \${$3+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+#include <$2>
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  eval "$3=yes"
+else
+  eval "$3=no"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+eval ac_res=\$$3
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+
+} # ac_fn_c_check_header_compile
+
+# ac_fn_c_try_link LINENO
+# -----------------------
+# Try to link conftest.$ac_ext, and return whether this succeeded.
+ac_fn_c_try_link ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  rm -f conftest.$ac_objext conftest$ac_exeext
+  if { { ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_link") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    grep -v '^ *+' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+    mv -f conftest.er1 conftest.err
+  fi
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 test -x conftest$ac_exeext
+       }; then :
+  ac_retval=0
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_retval=1
+fi
+  # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information
+  # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would
+  # interfere with the next link command; also delete a directory that is
+  # left behind by Apple's compiler.  We do this before executing the actions.
+  rm -rf conftest.dSYM conftest_ipa8_conftest.oo
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+  as_fn_set_status $ac_retval
+
+} # ac_fn_c_try_link
+
+# ac_fn_c_check_func LINENO FUNC VAR
+# ----------------------------------
+# Tests whether FUNC exists, setting the cache variable VAR accordingly
+ac_fn_c_check_func ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
+$as_echo_n "checking for $2... " >&6; }
+if eval \${$3+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+/* Define $2 to an innocuous variant, in case <limits.h> declares $2.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define $2 innocuous_$2
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $2 (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $2
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char $2 ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined __stub_$2 || defined __stub___$2
+choke me
+#endif
+
+int
+main ()
+{
+return $2 ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval "$3=yes"
+else
+  eval "$3=no"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+fi
+eval ac_res=\$$3
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+
+} # ac_fn_c_check_func
+cat >config.log <<_ACEOF
+This file contains any messages produced by compilers while
+running configure, to aid debugging if configure makes a mistake.
+
+It was created by $as_me, which was
+generated by GNU Autoconf 2.69.  Invocation command line was
+
+  $ $0 $@
+
+_ACEOF
+exec 5>>config.log
+{
+cat <<_ASUNAME
+## --------- ##
+## Platform. ##
+## --------- ##
+
+hostname = `(hostname || uname -n) 2>/dev/null | sed 1q`
+uname -m = `(uname -m) 2>/dev/null || echo unknown`
+uname -r = `(uname -r) 2>/dev/null || echo unknown`
+uname -s = `(uname -s) 2>/dev/null || echo unknown`
+uname -v = `(uname -v) 2>/dev/null || echo unknown`
+
+/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown`
+/bin/uname -X     = `(/bin/uname -X) 2>/dev/null     || echo unknown`
+
+/bin/arch              = `(/bin/arch) 2>/dev/null              || echo unknown`
+/usr/bin/arch -k       = `(/usr/bin/arch -k) 2>/dev/null       || echo unknown`
+/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown`
+/usr/bin/hostinfo      = `(/usr/bin/hostinfo) 2>/dev/null      || echo unknown`
+/bin/machine           = `(/bin/machine) 2>/dev/null           || echo unknown`
+/usr/bin/oslevel       = `(/usr/bin/oslevel) 2>/dev/null       || echo unknown`
+/bin/universe          = `(/bin/universe) 2>/dev/null          || echo unknown`
+
+_ASUNAME
+
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    $as_echo "PATH: $as_dir"
+  done
+IFS=$as_save_IFS
+
+} >&5
+
+cat >&5 <<_ACEOF
+
+
+## ----------- ##
+## Core tests. ##
+## ----------- ##
+
+_ACEOF
+
+
+# Keep a trace of the command line.
+# Strip out --no-create and --no-recursion so they do not pile up.
+# Strip out --silent because we don't want to record it for future runs.
+# Also quote any args containing shell meta-characters.
+# Make two passes to allow for proper duplicate-argument suppression.
+ac_configure_args=
+ac_configure_args0=
+ac_configure_args1=
+ac_must_keep_next=false
+for ac_pass in 1 2
+do
+  for ac_arg
+  do
+    case $ac_arg in
+    -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;;
+    -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+    | -silent | --silent | --silen | --sile | --sil)
+      continue ;;
+    *\'*)
+      ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
+    esac
+    case $ac_pass in
+    1) as_fn_append ac_configure_args0 " '$ac_arg'" ;;
+    2)
+      as_fn_append ac_configure_args1 " '$ac_arg'"
+      if test $ac_must_keep_next = true; then
+	ac_must_keep_next=false # Got value, back to normal.
+      else
+	case $ac_arg in
+	  *=* | --config-cache | -C | -disable-* | --disable-* \
+	  | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \
+	  | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \
+	  | -with-* | --with-* | -without-* | --without-* | --x)
+	    case "$ac_configure_args0 " in
+	      "$ac_configure_args1"*" '$ac_arg' "* ) continue ;;
+	    esac
+	    ;;
+	  -* ) ac_must_keep_next=true ;;
+	esac
+      fi
+      as_fn_append ac_configure_args " '$ac_arg'"
+      ;;
+    esac
+  done
+done
+{ ac_configure_args0=; unset ac_configure_args0;}
+{ ac_configure_args1=; unset ac_configure_args1;}
+
+# When interrupted or exit'd, cleanup temporary files, and complete
+# config.log.  We remove comments because anyway the quotes in there
+# would cause problems or look ugly.
+# WARNING: Use '\'' to represent an apostrophe within the trap.
+# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug.
+trap 'exit_status=$?
+  # Save into config.log some information that might help in debugging.
+  {
+    echo
+
+    $as_echo "## ---------------- ##
+## Cache variables. ##
+## ---------------- ##"
+    echo
+    # The following way of writing the cache mishandles newlines in values,
+(
+  for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do
+    eval ac_val=\$$ac_var
+    case $ac_val in #(
+    *${as_nl}*)
+      case $ac_var in #(
+      *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
+$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
+      esac
+      case $ac_var in #(
+      _ | IFS | as_nl) ;; #(
+      BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
+      *) { eval $ac_var=; unset $ac_var;} ;;
+      esac ;;
+    esac
+  done
+  (set) 2>&1 |
+    case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #(
+    *${as_nl}ac_space=\ *)
+      sed -n \
+	"s/'\''/'\''\\\\'\'''\''/g;
+	  s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p"
+      ;; #(
+    *)
+      sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"
+      ;;
+    esac |
+    sort
+)
+    echo
+
+    $as_echo "## ----------------- ##
+## Output variables. ##
+## ----------------- ##"
+    echo
+    for ac_var in $ac_subst_vars
+    do
+      eval ac_val=\$$ac_var
+      case $ac_val in
+      *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
+      esac
+      $as_echo "$ac_var='\''$ac_val'\''"
+    done | sort
+    echo
+
+    if test -n "$ac_subst_files"; then
+      $as_echo "## ------------------- ##
+## File substitutions. ##
+## ------------------- ##"
+      echo
+      for ac_var in $ac_subst_files
+      do
+	eval ac_val=\$$ac_var
+	case $ac_val in
+	*\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
+	esac
+	$as_echo "$ac_var='\''$ac_val'\''"
+      done | sort
+      echo
+    fi
+
+    if test -s confdefs.h; then
+      $as_echo "## ----------- ##
+## confdefs.h. ##
+## ----------- ##"
+      echo
+      cat confdefs.h
+      echo
+    fi
+    test "$ac_signal" != 0 &&
+      $as_echo "$as_me: caught signal $ac_signal"
+    $as_echo "$as_me: exit $exit_status"
+  } >&5
+  rm -f core *.core core.conftest.* &&
+    rm -f -r conftest* confdefs* conf$$* $ac_clean_files &&
+    exit $exit_status
+' 0
+for ac_signal in 1 2 13 15; do
+  trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal
+done
+ac_signal=0
+
+# confdefs.h avoids OS command line length limits that DEFS can exceed.
+rm -f -r conftest* confdefs.h
+
+$as_echo "/* confdefs.h */" > confdefs.h
+
+# Predefined preprocessor variables.
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_NAME "$PACKAGE_NAME"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_TARNAME "$PACKAGE_TARNAME"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_VERSION "$PACKAGE_VERSION"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_STRING "$PACKAGE_STRING"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT"
+_ACEOF
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_URL "$PACKAGE_URL"
+_ACEOF
+
+
+# Let the site file select an alternate cache file if it wants to.
+# Prefer an explicitly selected file to automatically selected ones.
+ac_site_file1=NONE
+ac_site_file2=NONE
+if test -n "$CONFIG_SITE"; then
+  # We do not want a PATH search for config.site.
+  case $CONFIG_SITE in #((
+    -*)  ac_site_file1=./$CONFIG_SITE;;
+    */*) ac_site_file1=$CONFIG_SITE;;
+    *)   ac_site_file1=./$CONFIG_SITE;;
+  esac
+elif test "x$prefix" != xNONE; then
+  ac_site_file1=$prefix/share/config.site
+  ac_site_file2=$prefix/etc/config.site
+else
+  ac_site_file1=$ac_default_prefix/share/config.site
+  ac_site_file2=$ac_default_prefix/etc/config.site
+fi
+for ac_site_file in "$ac_site_file1" "$ac_site_file2"
+do
+  test "x$ac_site_file" = xNONE && continue
+  if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5
+$as_echo "$as_me: loading site script $ac_site_file" >&6;}
+    sed 's/^/| /' "$ac_site_file" >&5
+    . "$ac_site_file" \
+      || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "failed to load site script $ac_site_file
+See \`config.log' for more details" "$LINENO" 5; }
+  fi
+done
+
+if test -r "$cache_file"; then
+  # Some versions of bash will fail to source /dev/null (special files
+  # actually), so we avoid doing that.  DJGPP emulates it as a regular file.
+  if test /dev/null != "$cache_file" && test -f "$cache_file"; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5
+$as_echo "$as_me: loading cache $cache_file" >&6;}
+    case $cache_file in
+      [\\/]* | ?:[\\/]* ) . "$cache_file";;
+      *)                      . "./$cache_file";;
+    esac
+  fi
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5
+$as_echo "$as_me: creating cache $cache_file" >&6;}
+  >$cache_file
+fi
+
+# Check that the precious variables saved in the cache have kept the same
+# value.
+ac_cache_corrupted=false
+for ac_var in $ac_precious_vars; do
+  eval ac_old_set=\$ac_cv_env_${ac_var}_set
+  eval ac_new_set=\$ac_env_${ac_var}_set
+  eval ac_old_val=\$ac_cv_env_${ac_var}_value
+  eval ac_new_val=\$ac_env_${ac_var}_value
+  case $ac_old_set,$ac_new_set in
+    set,)
+      { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5
+$as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;}
+      ac_cache_corrupted=: ;;
+    ,set)
+      { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5
+$as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;}
+      ac_cache_corrupted=: ;;
+    ,);;
+    *)
+      if test "x$ac_old_val" != "x$ac_new_val"; then
+	# differences in whitespace do not lead to failure.
+	ac_old_val_w=`echo x $ac_old_val`
+	ac_new_val_w=`echo x $ac_new_val`
+	if test "$ac_old_val_w" != "$ac_new_val_w"; then
+	  { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5
+$as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;}
+	  ac_cache_corrupted=:
+	else
+	  { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5
+$as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;}
+	  eval $ac_var=\$ac_old_val
+	fi
+	{ $as_echo "$as_me:${as_lineno-$LINENO}:   former value:  \`$ac_old_val'" >&5
+$as_echo "$as_me:   former value:  \`$ac_old_val'" >&2;}
+	{ $as_echo "$as_me:${as_lineno-$LINENO}:   current value: \`$ac_new_val'" >&5
+$as_echo "$as_me:   current value: \`$ac_new_val'" >&2;}
+      fi;;
+  esac
+  # Pass precious variables to config.status.
+  if test "$ac_new_set" = set; then
+    case $ac_new_val in
+    *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;;
+    *) ac_arg=$ac_var=$ac_new_val ;;
+    esac
+    case " $ac_configure_args " in
+      *" '$ac_arg' "*) ;; # Avoid dups.  Use of quotes ensures accuracy.
+      *) as_fn_append ac_configure_args " '$ac_arg'" ;;
+    esac
+  fi
+done
+if $ac_cache_corrupted; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+  { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5
+$as_echo "$as_me: error: changes in the environment can compromise the build" >&2;}
+  as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5
+fi
+## -------------------- ##
+## Main body of script. ##
+## -------------------- ##
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+
+
+ac_aux_dir=
+for ac_dir in ${srcdir}/build/autoconf "$srcdir"/${srcdir}/build/autoconf; do
+  if test -f "$ac_dir/install-sh"; then
+    ac_aux_dir=$ac_dir
+    ac_install_sh="$ac_aux_dir/install-sh -c"
+    break
+  elif test -f "$ac_dir/install.sh"; then
+    ac_aux_dir=$ac_dir
+    ac_install_sh="$ac_aux_dir/install.sh -c"
+    break
+  elif test -f "$ac_dir/shtool"; then
+    ac_aux_dir=$ac_dir
+    ac_install_sh="$ac_aux_dir/shtool install -c"
+    break
+  fi
+done
+if test -z "$ac_aux_dir"; then
+  as_fn_error $? "cannot find install-sh, install.sh, or shtool in ${srcdir}/build/autoconf \"$srcdir\"/${srcdir}/build/autoconf" "$LINENO" 5
+fi
+
+# These three variables are undocumented and unsupported,
+# and are intended to be withdrawn in a future Autoconf release.
+# They can cause serious problems if a builder's source tree is in a directory
+# whose full name contains unusual characters.
+ac_config_guess="$SHELL $ac_aux_dir/config.guess"  # Please don't use this var.
+ac_config_sub="$SHELL $ac_aux_dir/config.sub"  # Please don't use this var.
+ac_configure="$SHELL $ac_aux_dir/configure"  # Please don't use this var.
+
+
+# Make sure we can run config.sub.
+$SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
+  as_fn_error $? "cannot run $SHELL $ac_aux_dir/config.sub" "$LINENO" 5
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking build system type" >&5
+$as_echo_n "checking build system type... " >&6; }
+if ${ac_cv_build+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_build_alias=$build_alias
+test "x$ac_build_alias" = x &&
+  ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"`
+test "x$ac_build_alias" = x &&
+  as_fn_error $? "cannot guess build type; you must specify one" "$LINENO" 5
+ac_cv_build=`$SHELL "$ac_aux_dir/config.sub" $ac_build_alias` ||
+  as_fn_error $? "$SHELL $ac_aux_dir/config.sub $ac_build_alias failed" "$LINENO" 5
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5
+$as_echo "$ac_cv_build" >&6; }
+case $ac_cv_build in
+*-*-*) ;;
+*) as_fn_error $? "invalid value of canonical build" "$LINENO" 5;;
+esac
+build=$ac_cv_build
+ac_save_IFS=$IFS; IFS='-'
+set x $ac_cv_build
+shift
+build_cpu=$1
+build_vendor=$2
+shift; shift
+# Remember, the first character of IFS is used to create $*,
+# except with old shells:
+build_os=$*
+IFS=$ac_save_IFS
+case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking host system type" >&5
+$as_echo_n "checking host system type... " >&6; }
+if ${ac_cv_host+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test "x$host_alias" = x; then
+  ac_cv_host=$ac_cv_build
+else
+  ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias` ||
+    as_fn_error $? "$SHELL $ac_aux_dir/config.sub $host_alias failed" "$LINENO" 5
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5
+$as_echo "$ac_cv_host" >&6; }
+case $ac_cv_host in
+*-*-*) ;;
+*) as_fn_error $? "invalid value of canonical host" "$LINENO" 5;;
+esac
+host=$ac_cv_host
+ac_save_IFS=$IFS; IFS='-'
+set x $ac_cv_host
+shift
+host_cpu=$1
+host_vendor=$2
+shift; shift
+# Remember, the first character of IFS is used to create $*,
+# except with old shells:
+host_os=$*
+IFS=$ac_save_IFS
+case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking target system type" >&5
+$as_echo_n "checking target system type... " >&6; }
+if ${ac_cv_target+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test "x$target_alias" = x; then
+  ac_cv_target=$ac_cv_host
+else
+  ac_cv_target=`$SHELL "$ac_aux_dir/config.sub" $target_alias` ||
+    as_fn_error $? "$SHELL $ac_aux_dir/config.sub $target_alias failed" "$LINENO" 5
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_target" >&5
+$as_echo "$ac_cv_target" >&6; }
+case $ac_cv_target in
+*-*-*) ;;
+*) as_fn_error $? "invalid value of canonical target" "$LINENO" 5;;
+esac
+target=$ac_cv_target
+ac_save_IFS=$IFS; IFS='-'
+set x $ac_cv_target
+shift
+target_cpu=$1
+target_vendor=$2
+shift; shift
+# Remember, the first character of IFS is used to create $*,
+# except with old shells:
+target_os=$*
+IFS=$ac_save_IFS
+case $target_os in *\ *) target_os=`echo "$target_os" | sed 's/ /-/g'`;; esac
+
+
+# The aliases save the names the user supplied, while $host etc.
+# will get canonicalized.
+test -n "$target_alias" &&
+  test "$program_prefix$program_suffix$program_transform_name" = \
+    NONENONEs,x,x, &&
+  program_prefix=${target_alias}-
+
+MOD_MAJOR_VERSION=4
+MOD_MINOR_VERSION=13
+MOD_PATCH_VERSION=1
+NSPR_MODNAME=nspr20
+_HAVE_PTHREADS=
+USE_PTHREADS=
+USE_USER_PTHREADS=
+USE_NSPR_THREADS=
+USE_N32=
+USE_X32=
+USE_64=
+USE_CPLUS=
+USE_IPV6=
+USE_MDUPDATE=
+_MACOSX_DEPLOYMENT_TARGET=
+_OPTIMIZE_FLAGS=-O
+_DEBUG_FLAGS=-g
+MOZ_DEBUG=1
+MOZ_OPTIMIZE=
+OBJDIR='$(OBJDIR_NAME)'
+OBJDIR_NAME=.
+OBJDIR_SUFFIX=OBJ
+NSINSTALL='$(MOD_DEPTH)/config/$(OBJDIR_NAME)/nsinstall'
+NOSUCHFILE=/no-such-file
+LIBNSPR='-L$(dist_libdir) -lnspr$(MOD_MAJOR_VERSION)'
+LIBPLC='-L$(dist_libdir) -lplc$(MOD_MAJOR_VERSION)'
+CYGWIN_WRAPPER=
+MACOS_SDK_DIR=
+NEXT_ROOT=
+MT=
+MOZ_OS2_HIGH_MEMORY=1
+PROFILE_GEN_CFLAGS=
+PROFILE_GEN_LDFLAGS=
+PROFILE_USE_CFLAGS=
+PROFILE_USE_LDFLAGS=
+
+RESOLVE_LINK_SYMBOLS=
+
+CFLAGS="${CFLAGS=}"
+CXXFLAGS="${CXXFLAGS=}"
+LDFLAGS="${LDFLAGS=}"
+DLLFLAGS="${DLLFLAGS=}"
+HOST_CFLAGS="${HOST_CFLAGS=}"
+HOST_LDFLAGS="${HOST_LDFLAGS=}"
+
+case "$target" in
+*-cygwin*|*-mingw*|*-msys*)
+    # Check to see if we are really running in a msvc environemnt
+    _WIN32_MSVC=
+    for ac_prog in cl
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_CC+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_CC="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$CC" && break
+done
+
+    cat > conftest.c <<EOF
+#ifdef _MSC_VER
+COMPILER IS MSVC
+#endif
+EOF
+    read dummy <<EOF
+$($CC -E conftest.c 2>/dev/null | grep COMPILER)
+EOF
+    if test -n "$dummy"; then
+        _WIN32_MSVC=1
+        CXX=$CC
+    fi
+    rm -f conftest.c
+    ;;
+*-mks*)
+    _WIN32_MSVC=1
+    ;;
+esac
+
+if test -n "$_WIN32_MSVC"; then
+    SKIP_PATH_CHECKS=1
+    SKIP_COMPILER_CHECKS=1
+    SKIP_LIBRARY_CHECKS=1
+fi
+
+
+
+# Check whether --with-android-ndk was given.
+if test "${with_android_ndk+set}" = set; then :
+  withval=$with_android_ndk; android_ndk=$withval
+fi
+
+
+
+# Check whether --with-android-toolchain was given.
+if test "${with_android_toolchain+set}" = set; then :
+  withval=$with_android_toolchain; android_toolchain=$withval
+fi
+
+
+case "$target_cpu" in
+arm)
+    android_version=5
+    ;;
+i?86|mipsel)
+    android_version=9
+    ;;
+esac
+
+
+# Check whether --with-android-version was given.
+if test "${with_android_version+set}" = set; then :
+  withval=$with_android_version; android_version=$withval
+fi
+
+
+
+# Check whether --with-android-platform was given.
+if test "${with_android_platform+set}" = set; then :
+  withval=$with_android_platform; android_platform=$withval
+fi
+
+
+case "$target" in
+arm-linux*-android*|*-linuxandroid*)
+    android_tool_prefix="arm-linux-androideabi"
+    ;;
+i?86-*android*)
+    android_tool_prefix="i686-linux-android"
+    ;;
+mipsel-*android*)
+    android_tool_prefix="mipsel-linux-android"
+    ;;
+*)
+    android_tool_prefix="$target_os"
+    ;;
+esac
+
+
+
+# Check whether --with-gonk was given.
+if test "${with_gonk+set}" = set; then :
+  withval=$with_gonk; gonkdir=$withval
+fi
+
+
+if test -n "$gonkdir" ; then
+
+    $as_echo "#define ANDROID 1" >>confdefs.h
+
+else
+case "$target" in
+*-android*|*-linuxandroid*)
+    if test -z "$android_ndk" ; then
+       as_fn_error $? "You must specify --with-android-ndk=/path/to/ndk when targeting Android." "$LINENO" 5
+    fi
+
+    if test -z "$android_toolchain" ; then
+        { $as_echo "$as_me:${as_lineno-$LINENO}: checking for android toolchain directory" >&5
+$as_echo_n "checking for android toolchain directory... " >&6; }
+
+        kernel_name=`uname -s | tr "[:upper:]" "[:lower:]"`
+
+        case "$target_cpu" in
+        arm)
+            target_name=arm-linux-androideabi-4.4.3
+            ;;
+        i?86)
+            target_name=x86-4.4.3
+            ;;
+        mipsel)
+            target_name=mipsel-linux-android-4.4.3
+            ;;
+        esac
+        android_toolchain="$android_ndk"/toolchains/$target_name/prebuilt/$kernel_name-x86
+
+        if test -d "$android_toolchain" ; then
+            { $as_echo "$as_me:${as_lineno-$LINENO}: result: $android_toolchain" >&5
+$as_echo "$android_toolchain" >&6; }
+        else
+            as_fn_error $? "not found. You have to specify --with-android-toolchain=/path/to/ndk/toolchain." "$LINENO" 5
+        fi
+    fi
+
+    if test -z "$android_platform" ; then
+        { $as_echo "$as_me:${as_lineno-$LINENO}: checking for android platform directory" >&5
+$as_echo_n "checking for android platform directory... " >&6; }
+
+        case "$target_cpu" in
+        arm)
+            target_name=arm
+            ;;
+        i?86)
+            target_name=x86
+            ;;
+        mipsel)
+            target_name=mips
+            ;;
+        esac
+
+        android_platform="$android_ndk"/platforms/android-"$android_version"/arch-"$target_name"
+
+        if test -d "$android_platform" ; then
+            { $as_echo "$as_me:${as_lineno-$LINENO}: result: $android_platform" >&5
+$as_echo "$android_platform" >&6; }
+        else
+            as_fn_error $? "not found. You have to specify --with-android-platform=/path/to/ndk/platform." "$LINENO" 5
+        fi
+    fi
+
+            case "$target_cpu" in
+    i?86)
+        if ! test -e "$android_toolchain"/bin/"$android_tool_prefix"-gcc; then
+                        android_tool_prefix="i686-android-linux"
+        fi
+        ;;
+    esac
+
+        AS="$android_toolchain"/bin/"$android_tool_prefix"-as
+    CC="$android_toolchain"/bin/"$android_tool_prefix"-gcc
+    CXX="$android_toolchain"/bin/"$android_tool_prefix"-g++
+    CPP="$android_toolchain"/bin/"$android_tool_prefix"-cpp
+    LD="$android_toolchain"/bin/"$android_tool_prefix"-ld
+    AR="$android_toolchain"/bin/"$android_tool_prefix"-ar
+    RANLIB="$android_toolchain"/bin/"$android_tool_prefix"-ranlib
+    STRIP="$android_toolchain"/bin/"$android_tool_prefix"-strip
+
+    CPPFLAGS="-I$android_platform/usr/include $CPPFLAGS"
+    CFLAGS="-mandroid -I$android_platform/usr/include -fno-short-enums -fno-exceptions $CFLAGS"
+    CXXFLAGS="-mandroid -I$android_platform/usr/include -fpic -fno-short-enums -fno-exceptions $CXXFLAGS"
+    LDFLAGS="-mandroid -L$android_platform/usr/lib -Wl,-rpath-link=$android_platform/usr/lib --sysroot=$android_platform $LDFLAGS"
+
+    $as_echo "#define ANDROID 1" >>confdefs.h
+
+    ;;
+esac
+fi
+
+dist_prefix='${MOD_DEPTH}/dist'
+dist_bindir='${dist_prefix}/bin'
+dist_includedir='${dist_prefix}/include/nspr'
+dist_libdir='${dist_prefix}/lib'
+if test "${includedir}" = '${prefix}/include'; then
+    includedir='${prefix}/include/nspr'
+fi
+
+
+# Check whether --with-dist-prefix was given.
+if test "${with_dist_prefix+set}" = set; then :
+  withval=$with_dist_prefix; dist_prefix=$withval
+fi
+
+
+
+# Check whether --with-dist-bindir was given.
+if test "${with_dist_bindir+set}" = set; then :
+  withval=$with_dist_bindir; dist_bindir=$withval
+fi
+
+
+
+# Check whether --with-dist-includedir was given.
+if test "${with_dist_includedir+set}" = set; then :
+  withval=$with_dist_includedir; dist_includedir=$withval
+fi
+
+
+
+# Check whether --with-dist-libdir was given.
+if test "${with_dist_libdir+set}" = set; then :
+  withval=$with_dist_libdir; dist_libdir=$withval
+fi
+
+
+
+
+
+
+
+
+# Check whether --with-mozilla was given.
+if test "${with_mozilla+set}" = set; then :
+  withval=$with_mozilla;    if test "$withval" = "yes"; then
+            $as_echo "#define MOZILLA_CLIENT 1" >>confdefs.h
+
+            MOZILLA_CLIENT=1
+	    else
+	        MOZILLA_CLIENT=
+	    fi
+else
+  	if test -n "$MOZILLA_CLIENT"; then
+	        $as_echo "#define MOZILLA_CLIENT 1" >>confdefs.h
+
+	    fi
+fi
+
+
+# Check whether --enable-optimize was given.
+if test "${enable_optimize+set}" = set; then :
+  enableval=$enable_optimize;  if test "$enableval" != "no"; then
+          MOZ_OPTIMIZE=1
+          if test -n "$enableval" -a "$enableval" != "yes"; then
+            _OPTIMIZE_FLAGS=`echo $enableval | sed -e 's|\\\ | |g'`
+            _SAVE_OPTIMIZE_FLAGS=$_OPTIMIZE_FLAGS
+          fi
+      else
+          MOZ_OPTIMIZE=
+      fi
+fi
+
+
+# Check whether --enable-debug was given.
+if test "${enable_debug+set}" = set; then :
+  enableval=$enable_debug;  if test "$enableval" != "no"; then
+          MOZ_DEBUG=1
+          MOZ_DEBUG_SYMBOLS=1
+          if test -n "$enableval" -a "$enableval" != "yes"; then
+              _DEBUG_FLAGS=`echo $enableval | sed -e 's|\\\ | |g'`
+              _SAVE_DEBUG_FLAGS=$_DEBUG_FLAGS
+          fi
+      else
+          MOZ_DEBUG=
+      fi
+else
+  MOZ_DEBUG_SYMBOLS=1
+fi
+
+
+# Check whether --enable-debug-symbols was given.
+if test "${enable_debug_symbols+set}" = set; then :
+  enableval=$enable_debug_symbols;  if test "$enableval" != "no"; then
+          MOZ_DEBUG_SYMBOLS=1
+          if test -n "$enableval" -a "$enableval" != "yes"; then
+              if test -z "$_SAVE_DEBUG_FLAGS"; then
+                  _DEBUG_FLAGS=`echo $enableval | sed -e 's|\\\ | |g'`
+                  _SAVE_DEBUG_FLAGS=$_DEBUG_FLAGS
+              else
+                  as_fn_error $? "--enable-debug-symbols flags cannot be used with --enable-debug flags" "$LINENO" 5
+              fi
+          fi
+      else
+          MOZ_DEBUG_SYMBOLS=
+      fi
+fi
+
+
+# Check whether --enable-win32-target was given.
+if test "${enable_win32_target+set}" = set; then :
+  enableval=$enable_win32_target; OS_TARGET=`echo $enableval | tr a-z A-Z`
+fi
+
+
+# Check whether --enable-symbian-target was given.
+if test "${enable_symbian_target+set}" = set; then :
+  enableval=$enable_symbian_target; OS_TARGET=`echo $enableval | tr a-z A-Z`
+fi
+
+
+# Check whether --enable-debug-rtl was given.
+if test "${enable_debug_rtl+set}" = set; then :
+  enableval=$enable_debug_rtl;  if test "$enableval" = "yes"; then
+	    USE_DEBUG_RTL=1
+      else
+	    USE_DEBUG_RTL=0
+      fi
+fi
+
+
+# Check whether --enable-static-rtl was given.
+if test "${enable_static_rtl+set}" = set; then :
+  enableval=$enable_static_rtl;  if test "$enableval" = "yes"; then
+	    USE_STATIC_RTL=1
+      fi
+fi
+
+
+# Check whether --enable-n32 was given.
+if test "${enable_n32+set}" = set; then :
+  enableval=$enable_n32;  if test "$enableval" = "yes"; then
+	USE_N32=1
+      else if test "$enableval" = "no"; then
+	USE_N32=
+      fi
+    fi
+fi
+
+
+# Check whether --enable-x32 was given.
+if test "${enable_x32+set}" = set; then :
+  enableval=$enable_x32;  if test "$enableval" = "yes"; then
+        USE_X32=1
+      else if test "$enableval" = "no"; then
+        USE_X32=
+      fi
+    fi
+fi
+
+
+# Check whether --enable-64bit was given.
+if test "${enable_64bit+set}" = set; then :
+  enableval=$enable_64bit;  if test "$enableval" = "yes"; then
+	    USE_64=1
+      fi
+fi
+
+
+# Check whether --enable-mdupdate was given.
+if test "${enable_mdupdate+set}" = set; then :
+  enableval=$enable_mdupdate;  if test "$enableval" = "yes"; then
+	    USE_MDUPDATE=1
+      fi
+fi
+
+
+# Check whether --enable-cplus was given.
+if test "${enable_cplus+set}" = set; then :
+  enableval=$enable_cplus;  if test "$enableval" = "yes"; then
+	    USE_CPLUS=1
+      fi
+fi
+
+
+
+# Check whether --with-arm-kuser was given.
+if test "${with_arm_kuser+set}" = set; then :
+  withval=$with_arm_kuser;  if test "$withval" = "yes"; then
+	    $as_echo "#define _PR_ARM_KUSER 1" >>confdefs.h
+
+      fi
+fi
+
+
+
+# Check whether --with-macos-sdk was given.
+if test "${with_macos_sdk+set}" = set; then :
+  withval=$with_macos_sdk; MACOS_SDK_DIR=$withval
+fi
+
+
+# Check whether --enable-macos-target was given.
+if test "${enable_macos_target+set}" = set; then :
+  enableval=$enable_macos_target; _MACOSX_DEPLOYMENT_TARGET=$enableval
+fi
+
+
+case "$target" in
+
+*-aix*)
+    case "${target_os}" in
+    aix3.2*)
+        USE_NSPR_THREADS=1
+        ;;
+    *)
+        USE_PTHREADS=1
+        ;;
+    esac
+    ;;
+
+esac
+
+if test -z "$CC"; then
+    case "$target" in
+
+    *-aix*)
+        if test -z "$USE_NSPR_THREADS"; then
+            CC=xlc_r
+        else
+            CC=xlc
+        fi
+    ;;
+
+    *-hpux*)
+        CC=cc
+    ;;
+
+    *-irix*)
+        CC=cc
+    ;;
+
+    *-osf*)
+        CC=cc
+    ;;
+
+    *-solaris*)
+        CC=cc
+    ;;
+
+    esac
+fi
+
+if test -z "$CXX"; then
+    case "$target" in
+
+    *-aix*)
+        if test -z "$USE_NSPR_THREADS"; then
+            CXX=xlC_r
+        else
+            CXX=xlC
+        fi
+    ;;
+
+    *-hpux*)
+        case "${target_os}" in
+        hpux10.30)
+            CXX=aCC
+            ;;
+        hpux11.*)
+            CXX=aCC
+            ;;
+        *)
+            CXX=CC
+            ;;
+        esac
+    ;;
+
+    *-irix*)
+        CXX=CC
+    ;;
+
+    *-osf*)
+        CXX=cxx
+    ;;
+
+    *-solaris*)
+        CXX=CC
+    ;;
+
+    esac
+fi
+
+if test -z "$SKIP_PATH_CHECKS"; then
+    # Extract the first word of "$WHOAMI whoami", so it can be a program name with args.
+set dummy $WHOAMI whoami; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_WHOAMI+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $WHOAMI in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_WHOAMI="$WHOAMI" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_WHOAMI="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  test -z "$ac_cv_path_WHOAMI" && ac_cv_path_WHOAMI="echo not_whoami"
+  ;;
+esac
+fi
+WHOAMI=$ac_cv_path_WHOAMI
+if test -n "$WHOAMI"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $WHOAMI" >&5
+$as_echo "$WHOAMI" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+
+if test -n "$MOZ_DEBUG"; then
+    $as_echo "#define DEBUG 1" >>confdefs.h
+
+    DEFINES="$DEFINES -UNDEBUG"
+
+    case "${target_os}" in
+    beos*)
+        DEFINES="$DEFINES -DDEBUG_${USER}"
+        ;;
+    mks*|cygwin*|mingw*|msys*|os2*)
+        DEFINES="$DEFINES -DDEBUG_`echo ${USERNAME} | sed -e 's| |_|g'`"
+        ;;
+    *)
+        DEFINES="$DEFINES -DDEBUG_`$WHOAMI`"
+        ;;
+    esac
+else
+    $as_echo "#define NDEBUG 1" >>confdefs.h
+
+    DEFINES="$DEFINES -UDEBUG"
+fi
+
+if test -z "$SKIP_COMPILER_CHECKS"; then
+if test "$target" != "$host"; then
+    echo "cross compiling from $host to $target"
+    cross_compiling=yes
+
+    case "$build:$target" in
+      powerpc-apple-darwin8*:i?86-apple-darwin*)
+                                                _SAVE_CFLAGS=$CFLAGS
+        _SAVE_CXXFLAGS=$CXXFLAGS
+        CFLAGS="-isysroot /Developer/SDKs/MacOSX10.4u.sdk $CFLAGS"
+        CXXFLAGS="-isysroot /Developer/SDKs/MacOSX10.4u.sdk $CXXFLAGS"
+        ;;
+    esac
+
+    for ac_prog in $CC "${target_alias}-gcc" "${target}-gcc"
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_CC+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_CC="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$CC" && break
+done
+test -n "$CC" || CC="echo"
+
+    unset ac_cv_prog_CC
+    fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args.
+set dummy ${ac_tool_prefix}gcc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_CC+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_CC="${ac_tool_prefix}gcc"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_CC"; then
+  ac_ct_CC=$CC
+  # Extract the first word of "gcc", so it can be a program name with args.
+set dummy gcc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_CC+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_CC"; then
+  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_CC="gcc"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
+$as_echo "$ac_ct_CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_CC" = x; then
+    CC=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    CC=$ac_ct_CC
+  fi
+else
+  CC="$ac_cv_prog_CC"
+fi
+
+if test -z "$CC"; then
+          if test -n "$ac_tool_prefix"; then
+    # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args.
+set dummy ${ac_tool_prefix}cc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_CC+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_CC="${ac_tool_prefix}cc"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  fi
+fi
+if test -z "$CC"; then
+  # Extract the first word of "cc", so it can be a program name with args.
+set dummy cc; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_CC+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+  ac_prog_rejected=no
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
+       ac_prog_rejected=yes
+       continue
+     fi
+    ac_cv_prog_CC="cc"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+if test $ac_prog_rejected = yes; then
+  # We found a bogon in the path, so make sure we never use it.
+  set dummy $ac_cv_prog_CC
+  shift
+  if test $# != 0; then
+    # We chose a different compiler from the bogus one.
+    # However, it has the same basename, so the bogon will be chosen
+    # first if we set CC to just the basename; use the full file name.
+    shift
+    ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@"
+  fi
+fi
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$CC"; then
+  if test -n "$ac_tool_prefix"; then
+  for ac_prog in cl.exe
+  do
+    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
+set dummy $ac_tool_prefix$ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_CC+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_CC="$ac_tool_prefix$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+$as_echo "$CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+    test -n "$CC" && break
+  done
+fi
+if test -z "$CC"; then
+  ac_ct_CC=$CC
+  for ac_prog in cl.exe
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_CC+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_CC"; then
+  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_CC="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
+$as_echo "$ac_ct_CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$ac_ct_CC" && break
+done
+
+  if test "x$ac_ct_CC" = x; then
+    CC=""
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    CC=$ac_ct_CC
+  fi
+fi
+
+fi
+
+
+test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "no acceptable C compiler found in \$PATH
+See \`config.log' for more details" "$LINENO" 5; }
+
+# Provide some information about the compiler.
+$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5
+set X $ac_compile
+ac_compiler=$2
+for ac_option in --version -v -V -qversion; do
+  { { ac_try="$ac_compiler $ac_option >&5"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_compiler $ac_option >&5") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    sed '10a\
+... rest of stderr output deleted ...
+         10q' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+  fi
+  rm -f conftest.er1 conftest.err
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }
+done
+
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+ac_clean_files_save=$ac_clean_files
+ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out"
+# Try to create an executable without -o first, disregard a.out.
+# It will help us diagnose broken compilers, and finding out an intuition
+# of exeext.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5
+$as_echo_n "checking whether the C compiler works... " >&6; }
+ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'`
+
+# The possible output files:
+ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*"
+
+ac_rmfiles=
+for ac_file in $ac_files
+do
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
+    * ) ac_rmfiles="$ac_rmfiles $ac_file";;
+  esac
+done
+rm -f $ac_rmfiles
+
+if { { ac_try="$ac_link_default"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_link_default") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then :
+  # Autoconf-2.13 could set the ac_cv_exeext variable to `no'.
+# So ignore a value of `no', otherwise this would lead to `EXEEXT = no'
+# in a Makefile.  We should not override ac_cv_exeext if it was cached,
+# so that the user can short-circuit this test for compilers unknown to
+# Autoconf.
+for ac_file in $ac_files ''
+do
+  test -f "$ac_file" || continue
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj )
+	;;
+    [ab].out )
+	# We found the default executable, but exeext='' is most
+	# certainly right.
+	break;;
+    *.* )
+	if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no;
+	then :; else
+	   ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
+	fi
+	# We set ac_cv_exeext here because the later test for it is not
+	# safe: cross compilers may not add the suffix if given an `-o'
+	# argument, so we may need to know it at that point already.
+	# Even if this section looks crufty: it has the advantage of
+	# actually working.
+	break;;
+    * )
+	break;;
+  esac
+done
+test "$ac_cv_exeext" = no && ac_cv_exeext=
+
+else
+  ac_file=''
+fi
+if test -z "$ac_file"; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+$as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error 77 "C compiler cannot create executables
+See \`config.log' for more details" "$LINENO" 5; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5
+$as_echo_n "checking for C compiler default output file name... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5
+$as_echo "$ac_file" >&6; }
+ac_exeext=$ac_cv_exeext
+
+rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out
+ac_clean_files=$ac_clean_files_save
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5
+$as_echo_n "checking for suffix of executables... " >&6; }
+if { { ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_link") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then :
+  # If both `conftest.exe' and `conftest' are `present' (well, observable)
+# catch `conftest.exe'.  For instance with Cygwin, `ls conftest' will
+# work properly (i.e., refer to `conftest.exe'), while it won't with
+# `rm'.
+for ac_file in conftest.exe conftest conftest.*; do
+  test -f "$ac_file" || continue
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
+    *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
+	  break;;
+    * ) break;;
+  esac
+done
+else
+  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot compute suffix of executables: cannot compile and link
+See \`config.log' for more details" "$LINENO" 5; }
+fi
+rm -f conftest conftest$ac_cv_exeext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5
+$as_echo "$ac_cv_exeext" >&6; }
+
+rm -f conftest.$ac_ext
+EXEEXT=$ac_cv_exeext
+ac_exeext=$EXEEXT
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdio.h>
+int
+main ()
+{
+FILE *f = fopen ("conftest.out", "w");
+ return ferror (f) || fclose (f) != 0;
+
+  ;
+  return 0;
+}
+_ACEOF
+ac_clean_files="$ac_clean_files conftest.out"
+# Check that the compiler produces executables we can run.  If not, either
+# the compiler is broken, or we cross compile.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5
+$as_echo_n "checking whether we are cross compiling... " >&6; }
+if test "$cross_compiling" != yes; then
+  { { ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_link") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }
+  if { ac_try='./conftest$ac_cv_exeext'
+  { { case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }; then
+    cross_compiling=no
+  else
+    if test "$cross_compiling" = maybe; then
+	cross_compiling=yes
+    else
+	{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot run C compiled programs.
+If you meant to cross compile, use \`--host'.
+See \`config.log' for more details" "$LINENO" 5; }
+    fi
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5
+$as_echo "$cross_compiling" >&6; }
+
+rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out
+ac_clean_files=$ac_clean_files_save
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5
+$as_echo_n "checking for suffix of object files... " >&6; }
+if ${ac_cv_objext+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.o conftest.obj
+if { { ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_compile") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then :
+  for ac_file in conftest.o conftest.obj conftest.*; do
+  test -f "$ac_file" || continue;
+  case $ac_file in
+    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;;
+    *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'`
+       break;;
+  esac
+done
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot compute suffix of object files: cannot compile
+See \`config.log' for more details" "$LINENO" 5; }
+fi
+rm -f conftest.$ac_cv_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5
+$as_echo "$ac_cv_objext" >&6; }
+OBJEXT=$ac_cv_objext
+ac_objext=$OBJEXT
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5
+$as_echo_n "checking whether we are using the GNU C compiler... " >&6; }
+if ${ac_cv_c_compiler_gnu+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+#ifndef __GNUC__
+       choke me
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_compiler_gnu=yes
+else
+  ac_compiler_gnu=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_cv_c_compiler_gnu=$ac_compiler_gnu
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5
+$as_echo "$ac_cv_c_compiler_gnu" >&6; }
+if test $ac_compiler_gnu = yes; then
+  GCC=yes
+else
+  GCC=
+fi
+ac_test_CFLAGS=${CFLAGS+set}
+ac_save_CFLAGS=$CFLAGS
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5
+$as_echo_n "checking whether $CC accepts -g... " >&6; }
+if ${ac_cv_prog_cc_g+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_save_c_werror_flag=$ac_c_werror_flag
+   ac_c_werror_flag=yes
+   ac_cv_prog_cc_g=no
+   CFLAGS="-g"
+   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_prog_cc_g=yes
+else
+  CFLAGS=""
+      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+else
+  ac_c_werror_flag=$ac_save_c_werror_flag
+	 CFLAGS="-g"
+	 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_prog_cc_g=yes
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+   ac_c_werror_flag=$ac_save_c_werror_flag
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5
+$as_echo "$ac_cv_prog_cc_g" >&6; }
+if test "$ac_test_CFLAGS" = set; then
+  CFLAGS=$ac_save_CFLAGS
+elif test $ac_cv_prog_cc_g = yes; then
+  if test "$GCC" = yes; then
+    CFLAGS="-g -O2"
+  else
+    CFLAGS="-g"
+  fi
+else
+  if test "$GCC" = yes; then
+    CFLAGS="-O2"
+  else
+    CFLAGS=
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5
+$as_echo_n "checking for $CC option to accept ISO C89... " >&6; }
+if ${ac_cv_prog_cc_c89+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_cv_prog_cc_c89=no
+ac_save_CC=$CC
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdarg.h>
+#include <stdio.h>
+struct stat;
+/* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
+struct buf { int x; };
+FILE * (*rcsopen) (struct buf *, struct stat *, int);
+static char *e (p, i)
+     char **p;
+     int i;
+{
+  return p[i];
+}
+static char *f (char * (*g) (char **, int), char **p, ...)
+{
+  char *s;
+  va_list v;
+  va_start (v,p);
+  s = g (p, va_arg (v,int));
+  va_end (v);
+  return s;
+}
+
+/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
+   function prototypes and stuff, but not '\xHH' hex character constants.
+   These don't provoke an error unfortunately, instead are silently treated
+   as 'x'.  The following induces an error, until -std is added to get
+   proper ANSI mode.  Curiously '\x00'!='x' always comes out true, for an
+   array size at least.  It's necessary to write '\x00'==0 to get something
+   that's true only with -std.  */
+int osf4_cc_array ['\x00' == 0 ? 1 : -1];
+
+/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
+   inside strings and character constants.  */
+#define FOO(x) 'x'
+int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];
+
+int test (int i, double x);
+struct s1 {int (*f) (int a);};
+struct s2 {int (*f) (double a);};
+int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
+int argc;
+char **argv;
+int
+main ()
+{
+return f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];
+  ;
+  return 0;
+}
+_ACEOF
+for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \
+	-Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
+do
+  CC="$ac_save_CC $ac_arg"
+  if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_prog_cc_c89=$ac_arg
+fi
+rm -f core conftest.err conftest.$ac_objext
+  test "x$ac_cv_prog_cc_c89" != "xno" && break
+done
+rm -f conftest.$ac_ext
+CC=$ac_save_CC
+
+fi
+# AC_CACHE_VAL
+case "x$ac_cv_prog_cc_c89" in
+  x)
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5
+$as_echo "none needed" >&6; } ;;
+  xno)
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
+$as_echo "unsupported" >&6; } ;;
+  *)
+    CC="$CC $ac_cv_prog_cc_c89"
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5
+$as_echo "$ac_cv_prog_cc_c89" >&6; } ;;
+esac
+if test "x$ac_cv_prog_cc_c89" != xno; then :
+
+fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+if test "$target" != "$host"; then
+    if test -n "$USE_CPLUS"; then
+        for ac_prog in $CXX "${target_alias}-g++" "${target}-g++"
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_CXX+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CXX"; then
+  ac_cv_prog_CXX="$CXX" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_CXX="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+CXX=$ac_cv_prog_CXX
+if test -n "$CXX"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CXX" >&5
+$as_echo "$CXX" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$CXX" && break
+done
+test -n "$CXX" || CXX="echo"
+
+        unset ac_cv_prog_CXX
+        ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+if test -z "$CXX"; then
+  if test -n "$CCC"; then
+    CXX=$CCC
+  else
+    if test -n "$ac_tool_prefix"; then
+  for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC
+  do
+    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
+set dummy $ac_tool_prefix$ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_CXX+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CXX"; then
+  ac_cv_prog_CXX="$CXX" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_CXX="$ac_tool_prefix$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+CXX=$ac_cv_prog_CXX
+if test -n "$CXX"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CXX" >&5
+$as_echo "$CXX" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+    test -n "$CXX" && break
+  done
+fi
+if test -z "$CXX"; then
+  ac_ct_CXX=$CXX
+  for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_CXX+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_CXX"; then
+  ac_cv_prog_ac_ct_CXX="$ac_ct_CXX" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_CXX="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_CXX=$ac_cv_prog_ac_ct_CXX
+if test -n "$ac_ct_CXX"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CXX" >&5
+$as_echo "$ac_ct_CXX" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$ac_ct_CXX" && break
+done
+
+  if test "x$ac_ct_CXX" = x; then
+    CXX="g++"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    CXX=$ac_ct_CXX
+  fi
+fi
+
+  fi
+fi
+# Provide some information about the compiler.
+$as_echo "$as_me:${as_lineno-$LINENO}: checking for C++ compiler version" >&5
+set X $ac_compile
+ac_compiler=$2
+for ac_option in --version -v -V -qversion; do
+  { { ac_try="$ac_compiler $ac_option >&5"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_compiler $ac_option >&5") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    sed '10a\
+... rest of stderr output deleted ...
+         10q' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+  fi
+  rm -f conftest.er1 conftest.err
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }
+done
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C++ compiler" >&5
+$as_echo_n "checking whether we are using the GNU C++ compiler... " >&6; }
+if ${ac_cv_cxx_compiler_gnu+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+#ifndef __GNUC__
+       choke me
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+  ac_compiler_gnu=yes
+else
+  ac_compiler_gnu=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_cv_cxx_compiler_gnu=$ac_compiler_gnu
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cxx_compiler_gnu" >&5
+$as_echo "$ac_cv_cxx_compiler_gnu" >&6; }
+if test $ac_compiler_gnu = yes; then
+  GXX=yes
+else
+  GXX=
+fi
+ac_test_CXXFLAGS=${CXXFLAGS+set}
+ac_save_CXXFLAGS=$CXXFLAGS
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX accepts -g" >&5
+$as_echo_n "checking whether $CXX accepts -g... " >&6; }
+if ${ac_cv_prog_cxx_g+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_save_cxx_werror_flag=$ac_cxx_werror_flag
+   ac_cxx_werror_flag=yes
+   ac_cv_prog_cxx_g=no
+   CXXFLAGS="-g"
+   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+  ac_cv_prog_cxx_g=yes
+else
+  CXXFLAGS=""
+      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+
+else
+  ac_cxx_werror_flag=$ac_save_cxx_werror_flag
+	 CXXFLAGS="-g"
+	 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+  ac_cv_prog_cxx_g=yes
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+   ac_cxx_werror_flag=$ac_save_cxx_werror_flag
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cxx_g" >&5
+$as_echo "$ac_cv_prog_cxx_g" >&6; }
+if test "$ac_test_CXXFLAGS" = set; then
+  CXXFLAGS=$ac_save_CXXFLAGS
+elif test $ac_cv_prog_cxx_g = yes; then
+  if test "$GXX" = yes; then
+    CXXFLAGS="-g -O2"
+  else
+    CXXFLAGS="-g"
+  fi
+else
+  if test "$GXX" = yes; then
+    CXXFLAGS="-O2"
+  else
+    CXXFLAGS=
+  fi
+fi
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+    fi
+
+    case "$build:$target" in
+      powerpc-apple-darwin8*:i?86-apple-darwin*|*:arm*-apple-darwin*)
+                                CFLAGS=$_SAVE_CFLAGS
+        CXXFLAGS=$_SAVE_CXXFLAGS
+        ;;
+    esac
+
+    for ac_prog in $RANLIB "${target_alias}-ranlib" "${target}-ranlib"
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_RANLIB+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$RANLIB"; then
+  ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_RANLIB="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+RANLIB=$ac_cv_prog_RANLIB
+if test -n "$RANLIB"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5
+$as_echo "$RANLIB" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$RANLIB" && break
+done
+test -n "$RANLIB" || RANLIB="echo"
+
+    for ac_prog in $AR "${target_alias}-ar" "${target}-ar"
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_AR+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$AR"; then
+  ac_cv_prog_AR="$AR" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_AR="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+AR=$ac_cv_prog_AR
+if test -n "$AR"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AR" >&5
+$as_echo "$AR" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$AR" && break
+done
+test -n "$AR" || AR="echo"
+
+    for ac_prog in $AS "${target_alias}-as" "${target}-as"
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_AS+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$AS"; then
+  ac_cv_prog_AS="$AS" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_AS="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+AS=$ac_cv_prog_AS
+if test -n "$AS"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AS" >&5
+$as_echo "$AS" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$AS" && break
+done
+test -n "$AS" || AS="echo"
+
+    for ac_prog in $LD "${target_alias}-ld" "${target}-ld"
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_LD+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$LD"; then
+  ac_cv_prog_LD="$LD" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_LD="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+LD=$ac_cv_prog_LD
+if test -n "$LD"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LD" >&5
+$as_echo "$LD" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$LD" && break
+done
+test -n "$LD" || LD="echo"
+
+    for ac_prog in $STRIP "${target_alias}-strip" "${target}-strip"
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_STRIP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$STRIP"; then
+  ac_cv_prog_STRIP="$STRIP" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_STRIP="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+STRIP=$ac_cv_prog_STRIP
+if test -n "$STRIP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5
+$as_echo "$STRIP" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$STRIP" && break
+done
+test -n "$STRIP" || STRIP="echo"
+
+    for ac_prog in $WINDRES "${target_alias}-windres" "${target}-windres"
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_WINDRES+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$WINDRES"; then
+  ac_cv_prog_WINDRES="$WINDRES" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_WINDRES="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+WINDRES=$ac_cv_prog_WINDRES
+if test -n "$WINDRES"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $WINDRES" >&5
+$as_echo "$WINDRES" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$WINDRES" && break
+done
+test -n "$WINDRES" || WINDRES="echo"
+
+
+    _SAVE_CC="$CC"
+    _SAVE_CFLAGS="$CFLAGS"
+    _SAVE_LDFLAGS="$LDFLAGS"
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $host compiler" >&5
+$as_echo_n "checking for $host compiler... " >&6; }
+    for ac_prog in $HOST_CC gcc cc /usr/ucb/cc
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_HOST_CC+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$HOST_CC"; then
+  ac_cv_prog_HOST_CC="$HOST_CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_HOST_CC="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+HOST_CC=$ac_cv_prog_HOST_CC
+if test -n "$HOST_CC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $HOST_CC" >&5
+$as_echo "$HOST_CC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$HOST_CC" && break
+done
+test -n "$HOST_CC" || HOST_CC=""""
+
+    if test -z "$HOST_CC"; then
+        as_fn_error $? "no acceptable cc found in \$PATH" "$LINENO" 5
+    fi
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $HOST_CC" >&5
+$as_echo "$HOST_CC" >&6; }
+
+    CC="$HOST_CC"
+    CFLAGS="$HOST_CFLAGS"
+    LDFLAGS="$HOST_LDFLAGS"
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $host compiler ($HOST_CC $HOST_CFLAGS $HOST_LDFLAGS) works" >&5
+$as_echo_n "checking whether the $host compiler ($HOST_CC $HOST_CFLAGS $HOST_LDFLAGS) works... " >&6; }
+
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+return 0;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  as_fn_error $? "installation or configuration problem: $host compiler $HOST_CC cannot create executables." "$LINENO" 5
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+    CC=$_SAVE_CC
+    CFLAGS=$_SAVE_CFLAGS
+    LDFLAGS=$_SAVE_LDFLAGS
+else
+    if test -n "$USE_CPLUS"; then
+        if test "$CC" = "cl" -a -z "$CXX"; then
+            CXX=$CC
+        else
+            ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+if test -z "$CXX"; then
+  if test -n "$CCC"; then
+    CXX=$CCC
+  else
+    if test -n "$ac_tool_prefix"; then
+  for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC
+  do
+    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
+set dummy $ac_tool_prefix$ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_CXX+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$CXX"; then
+  ac_cv_prog_CXX="$CXX" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_CXX="$ac_tool_prefix$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+CXX=$ac_cv_prog_CXX
+if test -n "$CXX"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CXX" >&5
+$as_echo "$CXX" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+    test -n "$CXX" && break
+  done
+fi
+if test -z "$CXX"; then
+  ac_ct_CXX=$CXX
+  for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_CXX+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_CXX"; then
+  ac_cv_prog_ac_ct_CXX="$ac_ct_CXX" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_CXX="$ac_prog"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_CXX=$ac_cv_prog_ac_ct_CXX
+if test -n "$ac_ct_CXX"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CXX" >&5
+$as_echo "$ac_ct_CXX" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$ac_ct_CXX" && break
+done
+
+  if test "x$ac_ct_CXX" = x; then
+    CXX="g++"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    CXX=$ac_ct_CXX
+  fi
+fi
+
+  fi
+fi
+# Provide some information about the compiler.
+$as_echo "$as_me:${as_lineno-$LINENO}: checking for C++ compiler version" >&5
+set X $ac_compile
+ac_compiler=$2
+for ac_option in --version -v -V -qversion; do
+  { { ac_try="$ac_compiler $ac_option >&5"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
+$as_echo "$ac_try_echo"; } >&5
+  (eval "$ac_compiler $ac_option >&5") 2>conftest.err
+  ac_status=$?
+  if test -s conftest.err; then
+    sed '10a\
+... rest of stderr output deleted ...
+         10q' conftest.err >conftest.er1
+    cat conftest.er1 >&5
+  fi
+  rm -f conftest.er1 conftest.err
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }
+done
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C++ compiler" >&5
+$as_echo_n "checking whether we are using the GNU C++ compiler... " >&6; }
+if ${ac_cv_cxx_compiler_gnu+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+#ifndef __GNUC__
+       choke me
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+  ac_compiler_gnu=yes
+else
+  ac_compiler_gnu=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_cv_cxx_compiler_gnu=$ac_compiler_gnu
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cxx_compiler_gnu" >&5
+$as_echo "$ac_cv_cxx_compiler_gnu" >&6; }
+if test $ac_compiler_gnu = yes; then
+  GXX=yes
+else
+  GXX=
+fi
+ac_test_CXXFLAGS=${CXXFLAGS+set}
+ac_save_CXXFLAGS=$CXXFLAGS
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX accepts -g" >&5
+$as_echo_n "checking whether $CXX accepts -g... " >&6; }
+if ${ac_cv_prog_cxx_g+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_save_cxx_werror_flag=$ac_cxx_werror_flag
+   ac_cxx_werror_flag=yes
+   ac_cv_prog_cxx_g=no
+   CXXFLAGS="-g"
+   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+  ac_cv_prog_cxx_g=yes
+else
+  CXXFLAGS=""
+      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+
+else
+  ac_cxx_werror_flag=$ac_save_cxx_werror_flag
+	 CXXFLAGS="-g"
+	 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+  ac_cv_prog_cxx_g=yes
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+   ac_cxx_werror_flag=$ac_save_cxx_werror_flag
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cxx_g" >&5
+$as_echo "$ac_cv_prog_cxx_g" >&6; }
+if test "$ac_test_CXXFLAGS" = set; then
+  CXXFLAGS=$ac_save_CXXFLAGS
+elif test $ac_cv_prog_cxx_g = yes; then
+  if test "$GXX" = yes; then
+    CXXFLAGS="-g -O2"
+  else
+    CXXFLAGS="-g"
+  fi
+else
+  if test "$GXX" = yes; then
+    CXXFLAGS="-O2"
+  else
+    CXXFLAGS=
+  fi
+fi
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+        fi
+    fi
+    if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args.
+set dummy ${ac_tool_prefix}ranlib; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_RANLIB+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$RANLIB"; then
+  ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+RANLIB=$ac_cv_prog_RANLIB
+if test -n "$RANLIB"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5
+$as_echo "$RANLIB" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_RANLIB"; then
+  ac_ct_RANLIB=$RANLIB
+  # Extract the first word of "ranlib", so it can be a program name with args.
+set dummy ranlib; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_RANLIB+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_RANLIB"; then
+  ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_RANLIB="ranlib"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB
+if test -n "$ac_ct_RANLIB"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5
+$as_echo "$ac_ct_RANLIB" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_RANLIB" = x; then
+    RANLIB=":"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    RANLIB=$ac_ct_RANLIB
+  fi
+else
+  RANLIB="$ac_cv_prog_RANLIB"
+fi
+
+    for ac_prog in as
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_AS+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $AS in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_AS="$AS" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_AS="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+AS=$ac_cv_path_AS
+if test -n "$AS"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AS" >&5
+$as_echo "$AS" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$AS" && break
+done
+test -n "$AS" || AS="$CC"
+
+    for ac_prog in ar
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_AR+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $AR in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_AR="$AR" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_AR="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+AR=$ac_cv_path_AR
+if test -n "$AR"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AR" >&5
+$as_echo "$AR" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$AR" && break
+done
+test -n "$AR" || AR="echo not_ar"
+
+    for ac_prog in ld link
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_LD+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $LD in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_LD="$LD" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_LD="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+LD=$ac_cv_path_LD
+if test -n "$LD"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LD" >&5
+$as_echo "$LD" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$LD" && break
+done
+test -n "$LD" || LD="echo not_ld"
+
+    for ac_prog in strip
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_STRIP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $STRIP in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_STRIP="$STRIP" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_STRIP="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+STRIP=$ac_cv_path_STRIP
+if test -n "$STRIP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5
+$as_echo "$STRIP" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$STRIP" && break
+done
+test -n "$STRIP" || STRIP="echo not_strip"
+
+    for ac_prog in windres
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_WINDRES+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $WINDRES in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_WINDRES="$WINDRES" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_WINDRES="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+WINDRES=$ac_cv_path_WINDRES
+if test -n "$WINDRES"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $WINDRES" >&5
+$as_echo "$WINDRES" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$WINDRES" && break
+done
+test -n "$WINDRES" || WINDRES="echo not_windres"
+
+    if test -z "$HOST_CC"; then
+        HOST_CC="$CC"
+    fi
+    if test -z "$HOST_CFLAGS"; then
+        HOST_CFLAGS="$CFLAGS"
+    fi
+fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5
+$as_echo_n "checking how to run the C preprocessor... " >&6; }
+# On Suns, sometimes $CPP names a directory.
+if test -n "$CPP" && test -d "$CPP"; then
+  CPP=
+fi
+if test -z "$CPP"; then
+  if ${ac_cv_prog_CPP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+      # Double quotes because CPP needs to be expanded
+    for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp"
+    do
+      ac_preproc_ok=false
+for ac_c_preproc_warn_flag in '' yes
+do
+  # Use a header file that comes with gcc, so configuring glibc
+  # with a fresh cross-compiler works.
+  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+  # <limits.h> exists even on freestanding compilers.
+  # On the NeXT, cc -E runs the code through the compiler's parser,
+  # not just through cpp. "Syntax error" is here to catch this case.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+		     Syntax error
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+
+else
+  # Broken: fails on valid input.
+continue
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+
+  # OK, works on sane cases.  Now check whether nonexistent headers
+  # can be detected and how.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <ac_nonexistent.h>
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+  # Broken: success on invalid input.
+continue
+else
+  # Passes both tests.
+ac_preproc_ok=:
+break
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+
+done
+# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
+rm -f conftest.i conftest.err conftest.$ac_ext
+if $ac_preproc_ok; then :
+  break
+fi
+
+    done
+    ac_cv_prog_CPP=$CPP
+
+fi
+  CPP=$ac_cv_prog_CPP
+else
+  ac_cv_prog_CPP=$CPP
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5
+$as_echo "$CPP" >&6; }
+ac_preproc_ok=false
+for ac_c_preproc_warn_flag in '' yes
+do
+  # Use a header file that comes with gcc, so configuring glibc
+  # with a fresh cross-compiler works.
+  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+  # <limits.h> exists even on freestanding compilers.
+  # On the NeXT, cc -E runs the code through the compiler's parser,
+  # not just through cpp. "Syntax error" is here to catch this case.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+		     Syntax error
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+
+else
+  # Broken: fails on valid input.
+continue
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+
+  # OK, works on sane cases.  Now check whether nonexistent headers
+  # can be detected and how.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <ac_nonexistent.h>
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+  # Broken: success on invalid input.
+continue
+else
+  # Passes both tests.
+ac_preproc_ok=:
+break
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+
+done
+# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
+rm -f conftest.i conftest.err conftest.$ac_ext
+if $ac_preproc_ok; then :
+
+else
+  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "C preprocessor \"$CPP\" fails sanity check
+See \`config.log' for more details" "$LINENO" 5; }
+fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+if test "$GCC" = "yes"; then
+    GNU_CC=1
+fi
+if test "$GXX" = "yes"; then
+    GNU_CXX=1
+fi
+if test "`echo | $AS -v 2>&1 | grep -c GNU`" != "0"; then
+    GNU_AS=1
+fi
+rm -f a.out
+
+case "$build:$target" in
+    i?86-apple-darwin*:powerpc-apple-darwin*)
+                                cross_compiling=yes
+        ;;
+esac
+
+if test "$cross_compiling"  = "yes"; then
+    CROSS_COMPILE=1
+else
+    CROSS_COMPILE=
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for gcc -pipe support" >&5
+$as_echo_n "checking for gcc -pipe support... " >&6; }
+if test -n "$GNU_CC" && test -n "$GNU_CXX" && test -n "$GNU_AS"; then
+    echo '#include <stdio.h>' > dummy-hello.c
+    echo 'int main() { printf("Hello World\n"); return 0; }' >> dummy-hello.c
+    ${CC} -S dummy-hello.c -o dummy-hello.s 2>&5
+    cat dummy-hello.s | ${AS} -o dummy-hello.S - 2>&5
+    if test $? = 0; then
+        _res_as_stdin="yes"
+    else
+        _res_as_stdin="no"
+    fi
+    if test "$_res_as_stdin" = "yes"; then
+        _SAVE_CFLAGS=$CFLAGS
+        CFLAGS="$CFLAGS -pipe"
+        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+ #include <stdio.h>
+int
+main ()
+{
+printf("Hello World\n");
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  _res_gcc_pipe="yes"
+else
+  _res_gcc_pipe="no"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+        CFLAGS=$_SAVE_CFLAGS
+    fi
+    if test "$_res_as_stdin" = "yes" && test "$_res_gcc_pipe" = "yes"; then
+        _res="yes";
+        CFLAGS="$CFLAGS -pipe"
+        CXXFLAGS="$CXXFLAGS -pipe"
+    else
+        _res="no"
+    fi
+    rm -f dummy-hello.c dummy-hello.s dummy-hello.S dummy-hello a.out
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $_res" >&5
+$as_echo "$_res" >&6; }
+else
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+_SAVE_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS -fprofile-generate -fprofile-correction"
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C compiler supports -fprofile-generate" >&5
+$as_echo_n "checking whether C compiler supports -fprofile-generate... " >&6; }
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+return 0;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+   PROFILE_GEN_CFLAGS="-fprofile-generate"
+                 result="yes"
+else
+  result="no"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $result" >&5
+$as_echo "$result" >&6; }
+
+if test $result = "yes"; then
+   PROFILE_GEN_LDFLAGS="-fprofile-generate"
+   PROFILE_USE_CFLAGS="-fprofile-use -fprofile-correction -Wcoverage-mismatch"
+   PROFILE_USE_LDFLAGS="-fprofile-use"
+fi
+
+CFLAGS="$_SAVE_CFLAGS"
+
+if test "$GNU_CC"; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for visibility(hidden) attribute" >&5
+$as_echo_n "checking for visibility(hidden) attribute... " >&6; }
+if ${ac_cv_visibility_hidden+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat > conftest.c <<EOF
+        int foo __attribute__ ((visibility ("hidden"))) = 1;
+EOF
+        ac_cv_visibility_hidden=no
+        if ${CC-cc} -Werror -S conftest.c -o conftest.s >/dev/null 2>&1; then
+            if grep '\.hidden.*foo' conftest.s >/dev/null; then
+                ac_cv_visibility_hidden=yes
+            fi
+        fi
+        rm -f conftest.cs
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_visibility_hidden" >&5
+$as_echo "$ac_cv_visibility_hidden" >&6; }
+    if test "$ac_cv_visibility_hidden" = "yes"; then
+        $as_echo "#define HAVE_VISIBILITY_HIDDEN_ATTRIBUTE 1" >>confdefs.h
+
+        { $as_echo "$as_me:${as_lineno-$LINENO}: checking for visibility pragma support" >&5
+$as_echo_n "checking for visibility pragma support... " >&6; }
+if ${ac_cv_visibility_pragma+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat > conftest.c <<EOF
+#pragma GCC visibility push(hidden)
+            int foo_hidden = 1;
+#pragma GCC visibility push(default)
+            int foo_default = 1;
+EOF
+            ac_cv_visibility_pragma=no
+            if ${CC-cc} -Werror -S conftest.c -o conftest.s >/dev/null 2>&1; then
+                if grep '\.hidden.*foo_hidden' conftest.s >/dev/null; then
+                    if ! grep '\.hidden.*foo_default' conftest.s > /dev/null; then
+                        ac_cv_visibility_pragma=yes
+                    fi
+                fi
+            fi
+            rm -f conftest.cs
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_visibility_pragma" >&5
+$as_echo "$ac_cv_visibility_pragma" >&6; }
+        if test "$ac_cv_visibility_pragma" = "yes"; then
+            $as_echo "#define HAVE_VISIBILITY_PRAGMA 1" >>confdefs.h
+
+            # To work around a build problem on Linux x86-64 (Bugzilla bug
+            # 293438), we use the -fvisibility=hidden flag.  This flag is less
+            # optimal than #pragma GCC visibility push(hidden) because the flag
+            # assumes that symbols defined outside the current source file have
+            # the default visibility.  This has the advantage that we don't need
+            # to wrap system header files, but has the disadvantage that calls
+            # to hidden symbols defined in other source files cannot be
+            # optimized by the compiler.  The -fvisibility=hidden flag does
+            # hide and export symbols correctly.
+            #VISIBILITY_FLAGS='-I$(dist_includedir)/system_wrappers -include $(topsrcdir)/config/gcc_hidden.h'
+            #WRAP_SYSTEM_INCLUDES=1
+            VISIBILITY_FLAGS="-fvisibility=hidden"
+            WRAP_SYSTEM_INCLUDES=
+        fi
+    fi
+fi # GNU_CC
+
+fi # SKIP_COMPILER_CHECKS
+
+if test -z "$SKIP_PATH_CHECKS"; then
+    for ac_prog in perl5 perl
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_PERL+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $PERL in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_PERL="$PERL" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_PERL="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+PERL=$ac_cv_path_PERL
+if test -n "$PERL"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PERL" >&5
+$as_echo "$PERL" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$PERL" && break
+done
+test -n "$PERL" || PERL="echo not_perl"
+
+elif test -z "$PERL"; then
+    PERL=perl
+fi
+
+OBJ_SUFFIX=o
+LIB_SUFFIX=a
+DLL_SUFFIX=so
+ASM_SUFFIX=s
+MKSHLIB='$(LD) $(DSO_LDOPTS) -o $@'
+PR_MD_ASFILES=
+PR_MD_CSRCS=
+PR_MD_ARCH_DIR=unix
+AR_FLAGS='cr $@'
+AS='$(CC)'
+ASFLAGS='$(CFLAGS)'
+
+if test -n "$CROSS_COMPILE"; then
+    OS_ARCH=`echo $target_os | sed -e 's|/|_|g'`
+    OS_RELEASE=
+    OS_TEST="${target_cpu}"
+    case "${target_os}" in
+        linux*)       OS_ARCH=Linux ;;
+        solaris*)     OS_ARCH=SunOS OS_RELEASE=5 ;;
+        mingw*)       OS_ARCH=WINNT CPU_ARCH=x86 ;;
+        darwin*)      OS_ARCH=Darwin ;;
+        riscos*)      OS_ARCH=RISCOS ;;
+    esac
+else
+    OS_ARCH=`uname -s | sed -e 's|/|_|g'`
+    OS_RELEASE=`uname -r`
+    OS_TEST=`uname -m`
+fi
+
+if test "$OS_ARCH" = "IRIX64"; then
+    OS_ARCH=IRIX
+fi
+
+if test "$OS_ARCH" = "AIX"; then
+    OS_RELEASE=`uname -v`.`uname -r`
+fi
+
+if test "$OS_ARCH" = "FreeBSD"; then
+    OS_RELEASE=`echo $OS_RELEASE | sed 's/-.*//'`
+fi
+
+if test "$OS_ARCH" = "Linux"; then
+    OS_RELEASE=`echo $OS_RELEASE | sed 's/-.*//'`
+    OS_RELEASE=`echo $OS_RELEASE | awk -F\. '{ print $1 "." $2 }'`
+fi
+
+#######################################################################
+# Master "Core Components" macros for getting the OS target           #
+#######################################################################
+
+#
+# Note: OS_TARGET should be specified on the command line for gmake.
+# When OS_TARGET=WIN95 is specified, then a Windows 95 target is built.
+# The difference between the Win95 target and the WinNT target is that
+# the WinNT target uses Windows NT specific features not available
+# in Windows 95. The Win95 target will run on Windows NT, but (supposedly)
+# at lesser performance (the Win95 target uses threads; the WinNT target
+# uses fibers).
+#
+# If OS_TARGET is not specified, it defaults to $(OS_ARCH), i.e., no
+# cross-compilation.
+#
+
+#
+# The following hack allows one to build on a WIN95 machine (as if
+# s/he were cross-compiling on a WINNT host for a WIN95 target).
+# It also accomodates for MKS's uname.exe.  If you never intend
+# to do development on a WIN95 machine, you don't need this hack.
+#
+case "$OS_ARCH" in
+Windows_95)
+    OS_ARCH=Windows_NT
+    OS_TARGET=WIN95
+    ;;
+Windows_98)
+    OS_ARCH=Windows_NT
+    OS_TARGET=WIN95
+    ;;
+CYGWIN_9*|CYGWIN_ME*)
+    OS_ARCH='CYGWIN_NT-4.0'
+    OS_TARGET=WIN95
+    ;;
+OS_2)
+    OS_ARCH=OS2
+    OS_TARGET=OS2
+    ;;
+esac
+
+#
+# On WIN32, we also define the variable CPU_ARCH.
+#
+
+case "$OS_ARCH" in
+Windows_NT)
+#
+# If uname -s returns "Windows_NT", we assume that we are using
+# the uname.exe in MKS toolkit.
+#
+# The -r option of MKS uname only returns the major version number.
+# So we need to use its -v option to get the minor version number.
+# Moreover, it doesn't have the -p option, so we need to use uname -m.
+#
+    OS_ARCH=WINNT
+    OS_MINOR_RELEASE=`uname -v`
+    if test "$OS_MINOR_RELEASE" = "00"; then
+        OS_MINOR_RELEASE=0
+    fi
+    OS_RELEASE="${OS_RELEASE}.${OS_MINOR_RELEASE}"
+    CPU_ARCH=`uname -m`
+    #
+    # MKS's uname -m returns "586" on a Pentium machine.
+    #
+    if echo "$CPU_ARCH" | grep -c 86 >/dev/null; then
+        CPU_ARCH=x86
+    fi
+    ;;
+CYGWIN_NT*|MINGW*_NT*|MSYS_NT*)
+#
+# If uname -s returns "CYGWIN_NT-4.0", we assume that we are using
+# the uname.exe in the Cygwin tools.
+# If uname -s returns "MINGW32_NT-5.1", we assume that we are using
+# the uname.exe in the MSYS tools.
+# If uname -s returns "MSYS_NT-6.3", we assume that we are using
+# the uname.exe in the MSYS2 tools.
+#
+    OS_RELEASE=`expr $OS_ARCH : '.*NT-\(.*\)'`
+    OS_ARCH=WINNT
+    CPU_ARCH=`uname -m`
+    #
+    # Cygwin's uname -m returns "i686" on a Pentium Pro machine.
+    #
+    if echo "$CPU_ARCH" | grep -c 86 >/dev/null; then
+        CPU_ARCH=x86
+    fi
+    ;;
+esac
+
+if test -n "$MOZILLA_CLIENT" && test "$OS_ARCH" = "WINNT"; then
+    OS_TARGET=WIN95
+    if test -n "$MOZ_DEBUG" -a -z "$USE_DEBUG_RTL"; then
+        USE_DEBUG_RTL=1
+    fi
+fi
+if test -z "$OS_TARGET"; then
+    OS_TARGET=$OS_ARCH
+fi
+if test "$OS_TARGET" = "WIN95"; then
+    OS_RELEASE="4.0"
+fi
+OS_CONFIG="${OS_TARGET}${OS_RELEASE}"
+
+# Check whether --enable-os2-high-mem was given.
+if test "${enable_os2_high_mem+set}" = set; then :
+  enableval=$enable_os2_high_mem;  if test "$enableval" = "no"; then
+        MOZ_OS2_HIGH_MEMORY=
+      else
+        MOZ_OS2_HIGH_MEMORY=1
+      fi
+fi
+
+
+
+MOZ_ALIGN=toolchain-default
+
+case "$target" in
+arm*-android*|arm*-linuxandroid*)
+    MOZ_THUMB=yes
+    MOZ_ARCH=armv7-a
+    MOZ_FPU=vfp
+    MOZ_FLOAT_ABI=softfp
+    MOZ_SOFT_FLOAT=yes
+    MOZ_ALIGN=no
+    ;;
+arm*-*)
+    if test -n "$MOZ_PLATFORM_MAEMO"; then
+        MOZ_THUMB=no
+        MOZ_ARCH=armv7-a
+        MOZ_FLOAT_ABI=softfp
+    fi
+    if test "$MOZ_PLATFORM_MAEMO" = 6; then
+        MOZ_THUMB=yes
+    fi
+    ;;
+esac
+
+# Check whether --enable-thumb2 was given.
+if test "${enable_thumb2+set}" = set; then :
+  enableval=$enable_thumb2; MOZ_THUMB=$enableval
+fi
+
+
+
+# Check whether --with-thumb was given.
+if test "${with_thumb+set}" = set; then :
+  withval=$with_thumb; if test -z "$GNU_CC"; then
+        as_fn_error $? "--with-thumb is not supported on non-GNU toolchain-defaults" "$LINENO" 5
+    fi
+    MOZ_THUMB=$withval
+fi
+
+
+
+# Check whether --with-thumb-interwork was given.
+if test "${with_thumb_interwork+set}" = set; then :
+  withval=$with_thumb_interwork; if test -z "$GNU_CC"; then
+        as_fn_error $? "--with-thumb-interwork is not supported on non-GNU toolchain-defaults" "$LINENO" 5
+    fi
+    MOZ_THUMB_INTERWORK=$withval
+fi
+
+
+
+# Check whether --with-arch was given.
+if test "${with_arch+set}" = set; then :
+  withval=$with_arch; if test -z "$GNU_CC"; then
+        as_fn_error $? "--with-arch is not supported on non-GNU toolchain-defaults" "$LINENO" 5
+    fi
+    MOZ_ARCH=$withval
+fi
+
+
+
+# Check whether --with-fpu was given.
+if test "${with_fpu+set}" = set; then :
+  withval=$with_fpu; if test -z "$GNU_CC"; then
+        as_fn_error $? "--with-fpu is not supported on non-GNU toolchain-defaults" "$LINENO" 5
+    fi
+    MOZ_FPU=$withval
+fi
+
+
+
+# Check whether --with-float-abi was given.
+if test "${with_float_abi+set}" = set; then :
+  withval=$with_float_abi; if test -z "$GNU_CC"; then
+        as_fn_error $? "--with-float-abi is not supported on non-GNU toolchain-defaults" "$LINENO" 5
+    fi
+    MOZ_FLOAT_ABI=$withval
+fi
+
+
+
+# Check whether --with-soft-float was given.
+if test "${with_soft_float+set}" = set; then :
+  withval=$with_soft_float; if test -z "$GNU_CC"; then
+        as_fn_error $? "--with-soft-float is not supported on non-GNU toolchain-defaults" "$LINENO" 5
+    fi
+    MOZ_SOFT_FLOAT=$withval
+fi
+
+
+case "$MOZ_ARCH" in
+toolchain-default|"")
+    arch_flag=""
+    ;;
+*)
+    arch_flag="-march=$MOZ_ARCH"
+    ;;
+esac
+
+case "$MOZ_THUMB" in
+yes)
+    MOZ_THUMB2=1
+    thumb_flag="-mthumb"
+    ;;
+no)
+    MOZ_THUMB2=
+    thumb_flag="-marm"
+    ;;
+*)
+    _SAVE_CFLAGS="$CFLAGS"
+    CFLAGS="$arch_flag"
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+return sizeof(__thumb2__);
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  MOZ_THUMB2=1
+else
+  MOZ_THUMB2=
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+    CFLAGS="$_SAVE_CFLAGS"
+    thumb_flag=""
+    ;;
+esac
+
+case "$MOZ_THUMB_INTERWORK" in
+yes)
+    thumb_interwork_flag="-mthumb-interwork"
+    ;;
+no)
+    thumb_interwork_flag="-mno-thumb-interwork"
+    ;;
+*) # toolchain-default
+    thumb_interwork_flag=""
+    ;;
+esac
+
+case "$MOZ_FPU" in
+toolchain-default|"")
+    fpu_flag=""
+    ;;
+*)
+    fpu_flag="-mfpu=$MOZ_FPU"
+    ;;
+esac
+
+case "$MOZ_FLOAT_ABI" in
+toolchain-default|"")
+    float_abi_flag=""
+    ;;
+*)
+    float_abi_flag="-mfloat-abi=$MOZ_FLOAT_ABI"
+    ;;
+esac
+
+case "$MOZ_SOFT_FLOAT" in
+yes)
+    soft_float_flag="-msoft-float"
+    ;;
+no)
+    soft_float_flag="-mno-soft-float"
+    ;;
+*) # toolchain-default
+    soft_float_flag=""
+    ;;
+esac
+
+case "$MOZ_ALIGN" in
+toolchain-default|"")
+    align_flag=""
+    ;;
+no)
+    align_flag="-mno-unaligned-access"
+    ;;
+yes)
+    align_flag="-munaligned-access"
+    ;;
+*)
+    align_flag=""
+    ;;
+esac
+
+if test -n "$align_flag"; then
+  _SAVE_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS $align_flag"
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether alignment flag ($align_flag) is supported" >&5
+$as_echo_n "checking whether alignment flag ($align_flag) is supported... " >&6; }
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+else
+  align_flag=""
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  CFLAGS="$_SAVE_CFLAGS"
+fi
+
+all_flags=`echo $arch_flag $thumb_flag $thumb_interwork_flag $fpu_flag $float_abi_flag $soft_float_flag $align_flag`
+if test -n "$all_flags"; then
+    _SAVE_CFLAGS="$CFLAGS"
+    CFLAGS="$all_flags"
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the chosen combination of compiler flags ($all_flags) works" >&5
+$as_echo_n "checking whether the chosen combination of compiler flags ($all_flags) works... " >&6; }
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+return 0;
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  as_fn_error $? "no" "$LINENO" 5
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+    CFLAGS="$_SAVE_CFLAGS $all_flags"
+    CXXFLAGS="$CXXFLAGS $all_flags"
+    ASFLAGS="$ASFLAGS $all_flags"
+    if test -n "$thumb_flag"; then
+        LDFLAGS="$LDFLAGS $thumb_flag"
+    fi
+fi
+
+case "$host" in
+*-mingw*|*-msys*)
+    NSINSTALL=nsinstall
+    ;;
+*-cygwin*|*-mks*)
+    NSINSTALL='$(CYGWIN_WRAPPER) nsinstall'
+    if test `echo "${PATH}" | grep -c \;` = 0; then
+        CYGWIN_WRAPPER='sh $(topsrcdir)/build/cygwin-wrapper'
+    fi
+    ;;
+*-beos*)
+    HOST_CFLAGS="$HOST_CFLAGS -DXP_BEOS -DBeOS -DBEOS -D_POSIX_SOURCE"
+    ;;
+*os2*)
+    ;;
+*)
+    HOST_CFLAGS="$HOST_CFLAGS -DXP_UNIX"
+    ;;
+esac
+
+case "$target" in
+
+*-aix*)
+    $as_echo "#define XP_UNIX 1" >>confdefs.h
+
+    $as_echo "#define AIX 1" >>confdefs.h
+
+    $as_echo "#define SYSV 1" >>confdefs.h
+
+    DSO_LDOPTS='-brtl -bnortllib -bM:SRE -bnoentry -bexpall -blibpath:/usr/lib:/lib'
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5
+$as_echo_n "checking for grep that handles long lines and -e... " >&6; }
+if ${ac_cv_path_GREP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -z "$GREP"; then
+  ac_path_GREP_found=false
+  # Loop through the user's path and test for each of PROGNAME-LIST
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_prog in grep ggrep; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext"
+      as_fn_executable_p "$ac_path_GREP" || continue
+# Check for GNU ac_path_GREP and select it if it is found.
+  # Check for GNU $ac_path_GREP
+case `"$ac_path_GREP" --version 2>&1` in
+*GNU*)
+  ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;;
+*)
+  ac_count=0
+  $as_echo_n 0123456789 >"conftest.in"
+  while :
+  do
+    cat "conftest.in" "conftest.in" >"conftest.tmp"
+    mv "conftest.tmp" "conftest.in"
+    cp "conftest.in" "conftest.nl"
+    $as_echo 'GREP' >> "conftest.nl"
+    "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break
+    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+    as_fn_arith $ac_count + 1 && ac_count=$as_val
+    if test $ac_count -gt ${ac_path_GREP_max-0}; then
+      # Best one so far, save it but keep looking for a better one
+      ac_cv_path_GREP="$ac_path_GREP"
+      ac_path_GREP_max=$ac_count
+    fi
+    # 10*(2^10) chars as input seems more than enough
+    test $ac_count -gt 10 && break
+  done
+  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+      $ac_path_GREP_found && break 3
+    done
+  done
+  done
+IFS=$as_save_IFS
+  if test -z "$ac_cv_path_GREP"; then
+    as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
+  fi
+else
+  ac_cv_path_GREP=$GREP
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5
+$as_echo "$ac_cv_path_GREP" >&6; }
+ GREP="$ac_cv_path_GREP"
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5
+$as_echo_n "checking for egrep... " >&6; }
+if ${ac_cv_path_EGREP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if echo a | $GREP -E '(a|b)' >/dev/null 2>&1
+   then ac_cv_path_EGREP="$GREP -E"
+   else
+     if test -z "$EGREP"; then
+  ac_path_EGREP_found=false
+  # Loop through the user's path and test for each of PROGNAME-LIST
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_prog in egrep; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext"
+      as_fn_executable_p "$ac_path_EGREP" || continue
+# Check for GNU ac_path_EGREP and select it if it is found.
+  # Check for GNU $ac_path_EGREP
+case `"$ac_path_EGREP" --version 2>&1` in
+*GNU*)
+  ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;;
+*)
+  ac_count=0
+  $as_echo_n 0123456789 >"conftest.in"
+  while :
+  do
+    cat "conftest.in" "conftest.in" >"conftest.tmp"
+    mv "conftest.tmp" "conftest.in"
+    cp "conftest.in" "conftest.nl"
+    $as_echo 'EGREP' >> "conftest.nl"
+    "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break
+    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+    as_fn_arith $ac_count + 1 && ac_count=$as_val
+    if test $ac_count -gt ${ac_path_EGREP_max-0}; then
+      # Best one so far, save it but keep looking for a better one
+      ac_cv_path_EGREP="$ac_path_EGREP"
+      ac_path_EGREP_max=$ac_count
+    fi
+    # 10*(2^10) chars as input seems more than enough
+    test $ac_count -gt 10 && break
+  done
+  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+      $ac_path_EGREP_found && break 3
+    done
+  done
+  done
+IFS=$as_save_IFS
+  if test -z "$ac_cv_path_EGREP"; then
+    as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
+  fi
+else
+  ac_cv_path_EGREP=$EGREP
+fi
+
+   fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5
+$as_echo "$ac_cv_path_EGREP" >&6; }
+ EGREP="$ac_cv_path_EGREP"
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5
+$as_echo_n "checking for ANSI C header files... " >&6; }
+if ${ac_cv_header_stdc+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <float.h>
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_header_stdc=yes
+else
+  ac_cv_header_stdc=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+if test $ac_cv_header_stdc = yes; then
+  # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <string.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "memchr" >/dev/null 2>&1; then :
+
+else
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <stdlib.h>
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "free" >/dev/null 2>&1; then :
+
+else
+  ac_cv_header_stdc=no
+fi
+rm -f conftest*
+
+fi
+
+if test $ac_cv_header_stdc = yes; then
+  # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
+  if test "$cross_compiling" = yes; then :
+  :
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <ctype.h>
+#include <stdlib.h>
+#if ((' ' & 0x0FF) == 0x020)
+# define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
+# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
+#else
+# define ISLOWER(c) \
+		   (('a' <= (c) && (c) <= 'i') \
+		     || ('j' <= (c) && (c) <= 'r') \
+		     || ('s' <= (c) && (c) <= 'z'))
+# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
+#endif
+
+#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
+int
+main ()
+{
+  int i;
+  for (i = 0; i < 256; i++)
+    if (XOR (islower (i), ISLOWER (i))
+	|| toupper (i) != TOUPPER (i))
+      return 2;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+
+else
+  ac_cv_header_stdc=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5
+$as_echo "$ac_cv_header_stdc" >&6; }
+if test $ac_cv_header_stdc = yes; then
+
+$as_echo "#define STDC_HEADERS 1" >>confdefs.h
+
+fi
+
+# On IRIX 5.3, sys/types and inttypes.h are conflicting.
+for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \
+		  inttypes.h stdint.h unistd.h
+do :
+  as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
+ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default
+"
+if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+
+done
+
+
+ac_fn_c_check_header_mongrel "$LINENO" "sys/atomic_op.h" "ac_cv_header_sys_atomic_op_h" "$ac_includes_default"
+if test "x$ac_cv_header_sys_atomic_op_h" = xyes; then :
+  $as_echo "#define AIX_HAVE_ATOMIC_OP_H 1" >>confdefs.h
+
+fi
+
+
+    case "${target_os}" in
+    aix3.2*)
+        $as_echo "#define AIX_RENAME_SELECT 1" >>confdefs.h
+
+        $as_echo "#define _PR_NO_LARGE_FILES 1" >>confdefs.h
+
+        AIX_LINK_OPTS='-bnso -berok'
+        PR_MD_ASFILES=os_AIX.s
+        ;;
+    aix4.1*)
+        $as_echo "#define AIX_TIMERS 1" >>confdefs.h
+
+        $as_echo "#define _PR_NO_LARGE_FILES 1" >>confdefs.h
+
+        $as_echo "#define AIX4_1 1" >>confdefs.h
+
+        MKSHLIB=
+        DSO_LDOPTS=
+        AIX_LINK_OPTS='-bnso -berok'
+        LIBNSPR='-L$(dist_libdir) -lnspr$(MOD_MAJOR_VERSION)_shr'
+        LIBPLC='-L$(dist_libdir) -lplc$(MOD_MAJOR_VERSION)_shr'
+        ;;
+    aix4.2*)
+        $as_echo "#define AIX_TIMERS 1" >>confdefs.h
+
+        $as_echo "#define _PR_HAVE_OFF64_T 1" >>confdefs.h
+
+        AIX_LINK_OPTS='-brtl -bnso -berok'
+        ;;
+    aix4.3*)
+        $as_echo "#define AIX_TIMERS 1" >>confdefs.h
+
+        $as_echo "#define _PR_HAVE_OFF64_T 1" >>confdefs.h
+
+        $as_echo "#define AIX4_3_PLUS 1" >>confdefs.h
+
+        $as_echo "#define HAVE_SOCKLEN_T 1" >>confdefs.h
+
+        $as_echo "#define HAVE_FCNTL_FILE_LOCKING 1" >>confdefs.h
+
+        USE_IPV6=1
+        AIX_LINK_OPTS='-brtl -bnso -berok'
+        ;;
+    *)
+        $as_echo "#define AIX_TIMERS 1" >>confdefs.h
+
+        $as_echo "#define _PR_HAVE_OFF64_T 1" >>confdefs.h
+
+        $as_echo "#define AIX4_3_PLUS 1" >>confdefs.h
+
+        $as_echo "#define HAVE_SOCKLEN_T 1" >>confdefs.h
+
+        $as_echo "#define HAVE_FCNTL_FILE_LOCKING 1" >>confdefs.h
+
+        USE_IPV6=1
+        AIX_LINK_OPTS='-brtl -bnso -berok'
+        ;;
+    esac
+    CFLAGS="$CFLAGS -qro -qroconst"
+    AIX_WRAP='$(DIST)/lib/aixwrap.o'
+    AIX_TMP='./_aix_tmp.o'
+    if test -n "$USE_64"; then
+        MDCPUCFG_H=_aix64.cfg
+        OBJECT_MODE=64
+    else
+        MDCPUCFG_H=_aix32.cfg
+    fi
+    PR_MD_CSRCS=aix.c
+    RESOLVE_LINK_SYMBOLS=1
+    ;;
+
+*-beos*)
+    $as_echo "#define XP_BEOS 1" >>confdefs.h
+
+    $as_echo "#define BeOS 1" >>confdefs.h
+
+    $as_echo "#define BEOS 1" >>confdefs.h
+
+    $as_echo "#define _POSIX_SOURCE 1" >>confdefs.h
+
+    DSO_LDOPTS=-nostart
+    MDCPUCFG_H=_beos.cfg
+    USE_BTHREADS=1
+    PR_MD_ARCH_DIR=beos
+    RESOLVE_LINK_SYMBOLS=1
+    case "${target_cpu}" in
+    i*86)
+        _OPTIMIZE_FLAGS=-O2
+        _DEBUG_FLAGS='-gdwarf-2 -O0'
+        MKSHLIB='$(CCC) $(DSO_LDOPTS) -o $@'
+        { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gethostbyaddr in -lbind" >&5
+$as_echo_n "checking for gethostbyaddr in -lbind... " >&6; }
+if ${ac_cv_lib_bind_gethostbyaddr+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lbind  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char gethostbyaddr ();
+int
+main ()
+{
+return gethostbyaddr ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_bind_gethostbyaddr=yes
+else
+  ac_cv_lib_bind_gethostbyaddr=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_bind_gethostbyaddr" >&5
+$as_echo "$ac_cv_lib_bind_gethostbyaddr" >&6; }
+if test "x$ac_cv_lib_bind_gethostbyaddr" = xyes; then :
+  OS_LIBS="$OS_LIBS -lbind -lsocket"
+fi
+
+        ;;
+    powerpc)
+        CC=mwcc
+        CCC=mwcc
+        LD=mwld
+        DSO_LDOPTS='-xms -export pragma -init _init_routine_ -term _term_routine_ -lroot -lnet /boot/develop/lib/ppc/glue-noinit.a /boot/develop/lib/ppc/init_term_dyn.o /boot/develop/lib/ppc/start_dyn.o'
+        _OPTIMIZE_FLAGS=-O2
+        _DEBUG_FLAGS='-g -O0'
+        ;;
+    esac
+    ;;
+
+*-bsdi*)
+    $as_echo "#define XP_UNIX 1" >>confdefs.h
+
+    $as_echo "#define BSDI 1" >>confdefs.h
+
+    $as_echo "#define NEED_BSDREGEX 1" >>confdefs.h
+
+
+    CFLAGS="$CFLAGS -Wall -Wno-format"
+    CXXFLAGS="$CXXFLAGS -Wall -Wno-format"
+
+    if echo "$OS_TEST" | grep -c 86 >/dev/null; then
+        CPU_ARCH=x86
+    elif echo "$OS_TEST" | grep -c sparc >/dev/null; then
+        CPU_ARCH=sparc
+    fi
+
+    MDCPUCFG_H=_bsdi.cfg
+    PR_MD_CSRCS=bsdi.c
+
+    DSO_LDOPTS=-r
+
+    case "$target_os" in
+    bsdi1.1*)
+        $as_echo "#define _PR_BSDI_JMPBUF_IS_ARRAY 1" >>confdefs.h
+
+        $as_echo "#define _PR_STAT_HAS_ONLY_ST_ATIME 1" >>confdefs.h
+
+        $as_echo "#define _PR_NEED_H_ERRNO 1" >>confdefs.h
+
+        MKSHLIB=
+        DSO_CFLAGS=
+        DSO_LDOPTS=
+        ;;
+
+    bsdi2.1*)
+        $as_echo "#define _PR_TIMESPEC_HAS_TS_SEC 1" >>confdefs.h
+
+        $as_echo "#define _PR_BSDI_JMPBUF_IS_ARRAY 1" >>confdefs.h
+
+        $as_echo "#define HAVE_DLL 1" >>confdefs.h
+
+        $as_echo "#define USE_DLFCN 1" >>confdefs.h
+
+        $as_echo "#define _PR_STAT_HAS_ST_ATIMESPEC 1" >>confdefs.h
+
+        PR_MD_ASFILES=os_BSD_OS_386_2.s
+        ;;
+
+    bsdi4.* | bsdi5.*)
+        $as_echo "#define _PR_SELECT_CONST_TIMEVAL 1" >>confdefs.h
+
+        $as_echo "#define _PR_BSDI_JMPBUF_IS_STRUCT 1" >>confdefs.h
+
+        $as_echo "#define HAVE_DLL 1" >>confdefs.h
+
+        $as_echo "#define USE_DLFCN 1" >>confdefs.h
+
+        $as_echo "#define _PR_STAT_HAS_ST_ATIMESPEC 1" >>confdefs.h
+
+        MKSHLIB='$(CC) -o $@ $(DSO_LDOPTS)'
+        DSO_CFLAGS=-fPIC
+        DSO_LDOPTS='-shared -Wl,-soname,$(@:$(OBJDIR)/%.so=%.so)'
+        STRIP="$STRIP -d"
+        case "$target_os" in
+        bsdi4.2* | bsdi4.3* | bsdi5.*)
+            $as_echo "#define _PR_HAVE_GETPROTO_R 1" >>confdefs.h
+
+            $as_echo "#define _PR_HAVE_GETPROTO_R_POINTER 1" >>confdefs.h
+
+            ;;
+        esac
+        ;;
+    *)
+        $as_echo "#define _PR_SELECT_CONST_TIMEVAL 1" >>confdefs.h
+
+        $as_echo "#define _PR_BSDI_JMPBUF_IS_STRUCT 1" >>confdefs.h
+
+        $as_echo "#define HAVE_DLL 1" >>confdefs.h
+
+        $as_echo "#define USE_DLFCN 1" >>confdefs.h
+
+        $as_echo "#define _PR_STAT_HAS_ST_ATIMESPEC 1" >>confdefs.h
+
+        ;;
+    esac
+
+    ;;
+
+*-darwin*)
+    $as_echo "#define XP_UNIX 1" >>confdefs.h
+
+    $as_echo "#define DARWIN 1" >>confdefs.h
+
+    $as_echo "#define HAVE_BSD_FLOCK 1" >>confdefs.h
+
+    $as_echo "#define HAVE_SOCKLEN_T 1" >>confdefs.h
+
+    AS='$(CC) -x assembler-with-cpp'
+    CFLAGS="$CFLAGS -Wall -fno-common"
+    case "${target_cpu}" in
+        arm*)
+            CPU_ARCH=arm
+            ;;
+        i*86*|x86_64)
+            if test -n "$USE_64"; then
+                CPU_ARCH=x86_64
+            else
+                CPU_ARCH=i386
+            fi
+            ;;
+        *)
+            CPU_ARCH=ppc
+            ;;
+    esac
+    if test "`echo $CC | grep -c '\-arch '`" = "0"; then
+        CC="$CC -arch $CPU_ARCH"
+    fi
+    ac_fn_c_check_header_mongrel "$LINENO" "crt_externs.h" "ac_cv_header_crt_externs_h" "$ac_includes_default"
+if test "x$ac_cv_header_crt_externs_h" = xyes; then :
+  $as_echo "#define HAVE_CRT_EXTERNS_H 1" >>confdefs.h
+
+fi
+
+
+    DSO_CFLAGS=-fPIC
+    DSO_LDOPTS='-dynamiclib -compatibility_version 1 -current_version 1 -all_load -install_name @executable_path/$@ -headerpad_max_install_names'
+    _OPTIMIZE_FLAGS=-O2
+    MKSHLIB='$(CC) $(DSO_LDOPTS) -o $@'
+    STRIP="$STRIP -x -S"
+    DLL_SUFFIX=dylib
+    USE_PTHREADS=1
+    MDCPUCFG_H=_darwin.cfg
+    PR_MD_CSRCS=darwin.c
+    PR_MD_ASFILES=os_Darwin.s
+
+    # Add Mac OS X support for loading CFM & CFBundle plugins
+    if test -f "${MACOS_SDK_DIR}/System/Library/Frameworks/Carbon.framework/Carbon"; then
+        $as_echo "#define XP_MACOSX 1" >>confdefs.h
+
+        OS_TARGET=MacOSX
+
+        if test -n "$_MACOSX_DEPLOYMENT_TARGET" ; then
+                        export MACOSX_DEPLOYMENT_TARGET=$_MACOSX_DEPLOYMENT_TARGET
+        elif test -z "$MACOSX_DEPLOYMENT_TARGET" ; then
+                                                case "${target_cpu}" in
+                powerpc*)
+                                        export MACOSX_DEPLOYMENT_TARGET=10.2
+                    ;;
+                i*86*)
+                                        export MACOSX_DEPLOYMENT_TARGET=10.4
+                    ;;
+            esac
+        fi
+
+
+        if test "$MACOS_SDK_DIR"; then
+
+            if test ! -d "$MACOS_SDK_DIR"; then
+                as_fn_error $? "SDK not found.  When using --with-macos-sdk, you must
+specify a valid SDK.  SDKs are installed when the optional cross-development
+tools are selected during the Xcode/Developer Tools installation." "$LINENO" 5
+            fi
+
+
+            CC_VERSION=`$CC -v 2>&1 | grep 'gcc version'`
+            GCC_VERSION_FULL=`echo $CC_VERSION | $PERL -pe 's/^.*gcc version ([^ ]*).*/$1/'`
+            GCC_VERSION=`echo $GCC_VERSION_FULL | $PERL -pe '(split(/\./))[0]>=4&&s/(^\d*\.\d*).*/$1/;'`
+
+            GCC_VERSION_MAJOR=`echo $GCC_VERSION_FULL | $PERL -pe 's/(^\d*).*/$1/;'`
+            if test "$GCC_VERSION_MAJOR" -lt "4" ; then
+                SDK_C_FRAMEWORK="-F${MACOS_SDK_DIR}/System/Library/Frameworks"
+                if test -d "${MACOS_SDK_DIR}/Library/Frameworks" ; then
+                    SDK_C_FRAMEWORK="$SDK_C_FRAMEWORK -F${MACOS_SDK_DIR}/Library/Frameworks"
+                fi
+
+                SDK_C_INCLUDE="-isystem ${MACOS_SDK_DIR}/usr/include/gcc/darwin/${GCC_VERSION} -isystem ${MACOS_SDK_DIR}/usr/include ${SDK_C_FRAMEWORK}"
+
+                CFLAGS="$CFLAGS -nostdinc ${SDK_C_INCLUDE}"
+
+                                CPP="$CPP -nostdinc ${SDK_C_INCLUDE}"
+
+
+                HOST_DARWIN_MAJOR=`echo "$build_os" | sed -E -e 's/^darwin([0-9]+).*$/\1/'`
+
+                if test "$HOST_DARWIN_MAJOR" -lt 9 ; then
+                                                                                                                        MACOS_SDK_LIBS="-L${MACOS_SDK_DIR}/usr/lib/gcc/darwin -L${MACOS_SDK_DIR}/usr/lib/gcc/darwin/${GCC_VERSION_FULL} -L${MACOS_SDK_DIR}/usr/lib ${SDK_C_FRAMEWORK}"
+                else
+                                                                                                                                                                                                        MACOS_SDK_LIBS="-Wl,-syslibroot,${MACOS_SDK_DIR}"
+                fi
+
+                LDFLAGS="${MACOS_SDK_LIBS} $LDFLAGS"
+                export NEXT_ROOT=$MACOS_SDK_DIR
+
+                if test -n "$CROSS_COMPILE" ; then
+                                                                                HOST_CC="NEXT_ROOT= $HOST_CC"
+                    HOST_CXX="NEXT_ROOT= $HOST_CXX"
+                fi
+            else
+                                                CFLAGS="$CFLAGS -isysroot ${MACOS_SDK_DIR}"
+
+                                CPP="$CPP -isysroot ${MACOS_SDK_DIR}"
+
+                                                                                if test "$GCC_VERSION_FULL" != "4.0.0" ; then
+                                                            LDFLAGS="$LDFLAGS -isysroot ${MACOS_SDK_DIR}"
+                else
+                                                            LDFLAGS="$LDFLAGS -Wl,-syslibroot,${MACOS_SDK_DIR}"
+                fi
+            fi
+        fi
+    fi
+    ;;
+
+*-dgux*)
+    $as_echo "#define XP_UNIX 1" >>confdefs.h
+
+    $as_echo "#define _PR_LOCAL_THREADS_ONLY 1" >>confdefs.h
+
+    $as_echo "#define SVR4 1" >>confdefs.h
+
+    $as_echo "#define SYSV 1" >>confdefs.h
+
+    $as_echo "#define DGUX 1" >>confdefs.h
+
+    $as_echo "#define _DGUX_SOURCE 1" >>confdefs.h
+
+    $as_echo "#define _POSIX4A_DRAFT6_SOURCE 1" >>confdefs.h
+
+    DSO_LDOPTS=-G
+    _OPTIMIZE_FLAGS=-O2
+    _DEBUG_FLAGS=
+    MDCPUCFG_H=_dgux.cfg
+    PR_MD_CSRCS=dgux.c
+    ;;
+
+*-freebsd*)
+    if test -z "$USE_NSPR_THREADS"; then
+        USE_PTHREADS=1
+    fi
+    $as_echo "#define XP_UNIX 1" >>confdefs.h
+
+    $as_echo "#define FREEBSD 1" >>confdefs.h
+
+    $as_echo "#define HAVE_BSD_FLOCK 1" >>confdefs.h
+
+    $as_echo "#define HAVE_SOCKLEN_T 1" >>confdefs.h
+
+    CFLAGS="$CFLAGS $(DSO_CFLAGS) -ansi -Wall"
+    MOZ_OBJFORMAT=`test -x /usr/bin/objformat && /usr/bin/objformat || echo elf`
+    if test "$MOZ_OBJFORMAT" = "elf"; then
+        DLL_SUFFIX=so
+    else
+        DLL_SUFFIX=so.1.0
+    fi
+    MKSHLIB='$(CC) $(DSO_LDOPTS) -o $@'
+    DSO_CFLAGS=-fPIC
+    DSO_LDOPTS='-shared -Wl,-soname -Wl,$(notdir $@)'
+    MDCPUCFG_H=_freebsd.cfg
+    PR_MD_CSRCS=freebsd.c
+    ;;
+
+*-hpux*)
+    $as_echo "#define XP_UNIX 1" >>confdefs.h
+
+    $as_echo "#define HPUX 1" >>confdefs.h
+
+    $as_echo "#define _HPUX_SOURCE 1" >>confdefs.h
+
+    # OSF1 and HPUX report the POLLHUP event for a socket when the
+    # shutdown(SHUT_WR) operation is called for the remote end, even though
+    # the socket is still writeable. Use select(), instead of poll(), to
+    # workaround this problem.
+    $as_echo "#define _PR_POLL_WITH_SELECT 1" >>confdefs.h
+
+    $as_echo "#define _USE_BIG_FDS 1" >>confdefs.h
+
+    DSO_LDOPTS='-b +h $(notdir $@)'
+    PR_MD_CSRCS=hpux.c
+    if test "$OS_TEST" = "ia64"; then
+        DLL_SUFFIX=so
+        DSO_LDOPTS="$DSO_LDOPTS +b '\$\$ORIGIN'"
+        CPU_ARCH_TAG=_$OS_TEST
+        if test -z "$USE_64"; then
+            COMPILER_TAG=_32
+        fi
+        PR_MD_ASFILES=os_HPUX_ia64.s
+    else
+        $as_echo "#define hppa 1" >>confdefs.h
+
+        DLL_SUFFIX=sl
+        PR_MD_ASFILES=os_HPUX.s
+    fi
+    if test -n "$USE_64"; then
+        MDCPUCFG_H=_hpux64.cfg
+    else
+        MDCPUCFG_H=_hpux32.cfg
+    fi
+    if test -z "$GNU_CC"; then
+        CC="$CC -Ae"
+        CXX="$CXX -ext"
+        DSO_CFLAGS=+Z
+    else
+        DSO_CFLAGS=-fPIC
+        ASFLAGS="$ASFLAGS -x assembler-with-cpp"
+    fi
+
+    if test -n "$MOZILLA_CLIENT"; then
+        DEFAULT_IMPL_STRATEGY=_EMU
+    fi
+
+    if echo "$OS_RELEASE" | grep ^A.09 >/dev/null; then
+        $as_echo "#define _PR_NEED_H_ERRNO 1" >>confdefs.h
+
+        $as_echo "#define HPUX9 1" >>confdefs.h
+
+        DEFAULT_IMPL_STRATEGY=_EMU
+    	USE_NSPR_THREADS=1
+    fi
+
+    if echo "$OS_RELEASE" | egrep '^(A.09|B.10)' >/dev/null; then
+        $as_echo "#define _PR_NO_LARGE_FILES 1" >>confdefs.h
+
+    fi
+
+    if echo "$OS_RELEASE" | egrep '^(B.10.10|B.10.20)' >/dev/null; then
+        $as_echo "#define _PR_NEED_H_ERRNO 1" >>confdefs.h
+
+    fi
+
+    if echo "$OS_RELEASE" | egrep '^(B.10.10|B.10.20)' >/dev/null; then
+        $as_echo "#define HAVE_INT_LOCALTIME_R 1" >>confdefs.h
+
+    fi
+
+    if echo "$OS_RELEASE" | egrep '^(B.10.30|B.11)' >/dev/null; then
+        $as_echo "#define HAVE_POINTER_LOCALTIME_R 1" >>confdefs.h
+
+    fi
+
+    # HP-UX 11i v2 (B.11.23) or higher
+
+    case "$OS_RELEASE" in
+    [C-Z]*|B.[2-9]*|B.1[2-9]*|B.11.[3-9]*|B.11.2[3-9]*)
+        USE_IPV6=1
+        ;;
+    esac
+
+
+    if test "$OS_RELEASE" = "B.10.01"; then
+        $as_echo "#define HPUX10 1" >>confdefs.h
+
+        DEFAULT_IMPL_STRATEGY=_EMU
+    fi
+
+    if test "$OS_RELEASE" = "B.10.10"; then
+        $as_echo "#define HPUX10 1" >>confdefs.h
+
+        $as_echo "#define HPUX10_10 1" >>confdefs.h
+
+        DEFAULT_IMPL_STRATEGY=_PTH
+    fi
+
+    if test "$OS_RELEASE" = "B.10.20"; then
+        $as_echo "#define HPUX10 1" >>confdefs.h
+
+        $as_echo "#define HPUX10_20 1" >>confdefs.h
+
+        if test -z "$GNU_CC"; then
+            CFLAGS="$CFLAGS +DAportable +DS1.1"
+            CXXFLAGS="$CXXFLAGS +DAportable +DS1.1"
+        fi
+        DEFAULT_IMPL_STRATEGY=_PTH
+    fi
+
+    if test "$OS_RELEASE" = "B.10.30"; then
+        $as_echo "#define HPUX10 1" >>confdefs.h
+
+        $as_echo "#define HPUX10_30 1" >>confdefs.h
+
+        if test -z "$GNU_CC"; then
+            CFLAGS="$CFLAGS +DAportable +DS1.1"
+            CXXFLAGS="$CXXFLAGS +DAportable +DS1.1"
+        fi
+        DEFAULT_IMPL_STRATEGY=_PTH
+    fi
+
+    if echo "$OS_RELEASE" | grep ^B.11 >/dev/null; then
+        $as_echo "#define HPUX10 1" >>confdefs.h
+
+        $as_echo "#define HPUX11 1" >>confdefs.h
+
+        $as_echo "#define _LARGEFILE64_SOURCE 1" >>confdefs.h
+
+        $as_echo "#define _PR_HAVE_OFF64_T 1" >>confdefs.h
+
+        $as_echo "#define HAVE_FCNTL_FILE_LOCKING 1" >>confdefs.h
+
+        if test -z "$GNU_CC"; then
+            if test -z "$USE_64"; then
+                if test "$OS_TEST" = "ia64"; then
+                    CFLAGS="$CFLAGS +DD32"
+                    CXXFLAGS="$CXXFLAGS +DD32"
+                else
+                    CFLAGS="$CFLAGS +DAportable +DS2.0"
+                    CXXFLAGS="$CXXFLAGS +DAportable +DS2.0"
+                fi
+            else
+                if test "$OS_TEST" = "ia64"; then
+                    CFLAGS="$CFLAGS +DD64"
+                    CXXFLAGS="$CXXFLAGS +DD64"
+                else
+                    CFLAGS="$CFLAGS +DA2.0W +DS2.0"
+                    CXXFLAGS="$CXXFLAGS +DA2.0W +DS2.0"
+                fi
+            fi
+        fi
+        DEFAULT_IMPL_STRATEGY=_PTH
+    fi
+
+    if test "$DEFAULT_IMPL_STRATEGY" = "_EMU"; then
+        USE_NSPR_THREADS=1
+        USE_PTHREADS=
+        USE_USER_PTHREADS=
+    elif test "$DEFAULT_IMPL_STRATEGY" = "_PTH"; then
+        USE_PTHREADS=1
+        if test "$USE_NSPR_THREADS"; then
+            USE_PTHREADS=
+        fi
+        if test "$USE_USER_PTHREADS"; then
+            USE_PTHREADS=
+        fi
+    fi
+    ;;
+
+*-irix*)
+    $as_echo "#define XP_UNIX 1" >>confdefs.h
+
+    $as_echo "#define IRIX 1" >>confdefs.h
+
+    $as_echo "#define SVR4 1" >>confdefs.h
+
+    $as_echo "#define _SGI_MP_SOURCE 1" >>confdefs.h
+
+    $as_echo "#define HAVE_FCNTL_FILE_LOCKING 1" >>confdefs.h
+
+    PR_MD_CSRCS=irix.c
+    PR_MD_ASFILES=os_Irix.s
+    MKSHLIB='$(LD) $(DSO_LDOPTS) -rdata_shared -shared -soname $(notdir $@) -o $@'
+    STRIP="$STRIP -f"
+    RESOLVE_LINK_SYMBOLS=1
+    if test -n "$USE_64"; then
+        MDCPUCFG_H=_irix64.cfg
+    else
+        MDCPUCFG_H=_irix32.cfg
+    fi
+    case "${target_os}" in
+    irix6*)
+        $as_echo "#define IRIX6 1" >>confdefs.h
+
+        USE_PTHREADS=1
+        USE_N32=1
+        COMPILER_TAG=_n32
+        IMPL_STRATEGY=_PTH
+        ;;
+    irix5*)
+        $as_echo "#define IRIX5 1" >>confdefs.h
+
+        USE_NSPR_THREADS=1
+        ;;
+    *)
+        USE_PTHREADS=1
+        USE_N32=1
+        ;;
+    esac
+    if test "$GNU_CC"; then
+                                                        	    AS='$(CC) -Wp,-P -x assembler-with-cpp -D_ASM -mips2 $(INCLUDES)'
+	    CFLAGS="$CFLAGS -Wall -Wno-format"
+	    _OPTIMIZE_FLAGS="-O6"
+    else
+	    if test -n "$USE_N32"; then
+		AS='as -D_ASM $(INCLUDES) -n32'
+	    else
+		AS='as -D_ASM $(INCLUDES)'
+	    fi
+	    CFLAGS="$CFLAGS -fullwarn -xansi"
+	    if test "$USE_N32"; then
+	        _OPTIMIZE_FLAGS="-O -OPT:Olimit=4000"
+	    else
+	        _OPTIMIZE_FLAGS="-O -Olimit 4000"
+	    fi
+	    if test "$USE_MDUPDATE"; then
+                CFLAGS="$CFLAGS -MDupdate \$(DEPENDENCIES)"
+	    fi
+	    case "${target}" in
+	    *-irix6.*)
+	        CFLAGS="$CFLAGS -multigot"
+	        DSO_LDOPTS="-no_unresolved"
+	        if test "$USE_N32"; then
+		        CFLAGS="$CFLAGS -n32 -woff 1209"
+		        DSO_LDOPTS="$DSO_LDOPTS -n32"
+	        else
+		        if test "$USE_64"; then
+		            CFLAGS="$CFLAGS -64"
+		        else
+		            CFLAGS="$CFLAGS -32"
+		        fi
+	        fi
+	        ;;
+	    *)
+	        CFLAGS="$CFLAGS -xgot"
+	        ;;
+	    esac
+    fi
+    if test "${target_os}" = "irix5.3"; then
+	    $as_echo "#define IRIX5_3 1" >>confdefs.h
+
+    fi
+    case "${target_os}" in
+	irix6.5)
+	    if test -z "$GNU_CC"; then
+		    CFLAGS="$CFLAGS -mips3"
+	    fi
+	    $as_echo "#define _PR_HAVE_GETPROTO_R 1" >>confdefs.h
+
+	    $as_echo "#define _PR_HAVE_GETPROTO_R_POINTER 1" >>confdefs.h
+
+	    $as_echo "#define _PR_HAVE_SGI_PRDA_PROCMASK 1" >>confdefs.h
+
+	    ;;
+	irix5*)
+	    ;;
+	*)
+	    $as_echo "#define _PR_HAVE_SGI_PRDA_PROCMASK 1" >>confdefs.h
+
+	    ;;
+	esac
+    ;;
+
+*-linux*|*-gnu*|*-k*bsd*-gnu|*-android*|*-linuxandroid*)
+    if test -z "$USE_NSPR_THREADS"; then
+        USE_PTHREADS=1
+        IMPL_STRATEGY=_PTH
+    fi
+    $as_echo "#define XP_UNIX 1" >>confdefs.h
+
+    $as_echo "#define _GNU_SOURCE 1" >>confdefs.h
+
+    $as_echo "#define HAVE_FCNTL_FILE_LOCKING 1" >>confdefs.h
+
+    case "${target}" in
+    *-android*|*-linuxandroid*)
+        OS_TARGET=Android
+        $as_echo "#define LINUX 1" >>confdefs.h
+
+        ;;
+    *-linux*)
+        $as_echo "#define LINUX 1" >>confdefs.h
+
+        ;;
+    esac
+    CFLAGS="$CFLAGS -Wall"
+    CXXFLAGS="$CXXFLAGS -Wall"
+    MDCPUCFG_H=_linux.cfg
+    PR_MD_CSRCS=linux.c
+    MKSHLIB='$(CC) $(DSO_LDOPTS) -o $@'
+    DSO_CFLAGS=-fPIC
+    DSO_LDOPTS='-shared -Wl,-soname -Wl,$(notdir $@)'
+    _OPTIMIZE_FLAGS=-O2
+    _DEBUG_FLAGS="-g -fno-inline"  # most people on linux use gcc/gdb, and that
+                                   # combo is not yet good at debugging inlined
+                                   # functions (even when using DWARF2 as the
+                                   # debugging format)
+    COMPILER_TAG=_glibc
+    if echo "$OS_TEST" | grep -c 86 >/dev/null; then
+        CPU_ARCH=x86
+    else
+        CPU_ARCH=$OS_TEST
+    fi
+    CPU_ARCH_TAG=_${CPU_ARCH}
+    case "${target_cpu}" in
+    alpha)
+        $as_echo "#define _ALPHA_ 1" >>confdefs.h
+
+        $as_echo "#define __alpha 1" >>confdefs.h
+
+        CFLAGS="$CFLAGS -mieee"
+        CXXFLAGS="$CXXFLAGS -mieee"
+        ;;
+    i*86)
+        $as_echo "#define i386 1" >>confdefs.h
+
+        PR_MD_ASFILES=os_Linux_x86.s
+        ;;
+    ia64)
+        PR_MD_ASFILES=os_Linux_ia64.s
+        ;;
+    x86_64)
+        if test -n "$USE_64"; then
+            PR_MD_ASFILES=os_Linux_x86_64.s
+        elif test -n "$USE_X32"; then
+            PR_MD_ASFILES=os_Linux_x86_64.s
+            CC="$CC -mx32"
+            CXX="$CXX -mx32"
+        else
+            $as_echo "#define i386 1" >>confdefs.h
+
+            PR_MD_ASFILES=os_Linux_x86.s
+            CC="$CC -m32"
+            CXX="$CXX -m32"
+        fi
+        ;;
+    ppc|powerpc)
+        PR_MD_ASFILES=os_Linux_ppc.s
+        ;;
+    powerpc64)
+        if test -n "$USE_64"; then
+            CC="$CC -m64"
+            CXX="$CXX -m64"
+        else
+            PR_MD_ASFILES=os_Linux_ppc.s
+        fi
+        ;;
+    esac
+    ;;
+
+*-mingw*|*-msys*|*-cygwin*|*-mks*)
+    $as_echo "#define XP_PC 1" >>confdefs.h
+
+    $as_echo "#define WIN32 1" >>confdefs.h
+
+    PR_MD_ARCH_DIR=windows
+    RESOLVE_LINK_SYMBOLS=1
+
+    if test -n "$GNU_CC"; then
+        CC="$CC -mwindows"
+        CXX="$CXX -mwindows"
+        DLL_SUFFIX=dll
+        MKSHLIB='$(CC) -shared -Wl,--export-all-symbols -Wl,--out-implib -Wl,$(IMPORT_LIBRARY) $(DLLBASE) -o $(subst $(OBJDIR)/,,$(SHARED_LIBRARY))'
+        RC=$WINDRES
+        # Use temp file for windres (bug 213281)
+        RCFLAGS='-O coff --use-temp-file'
+    else
+        LD=link
+        AR='lib -NOLOGO -OUT:"$@"'
+        AR_FLAGS=
+        RANLIB='echo not_ranlib'
+        STRIP='echo not_strip'
+        RC=rc.exe
+        GARBAGE='$(OBJDIR)/vc20.pdb $(OBJDIR)/vc40.pdb'
+        OBJ_SUFFIX=obj
+        LIB_SUFFIX=lib
+        DLL_SUFFIX=dll
+
+        # Determine compiler version
+
+        _MSVC_VER_FILTER='s|.* \([0-9]\+\.[0-9]\+\.[0-9]\+\(\.[0-9]\+\)\?\).*|\1|p'
+
+        CC_VERSION=`${CC} -v 2>&1 | sed -ne "$_MSVC_VER_FILTER"`
+        if test -z "$CC_VERSION"; then
+            as_fn_error $? "Could not determine MSC version." "$LINENO" 5
+        fi
+
+        _CC_MAJOR_VERSION=`echo ${CC_VERSION} | awk -F\. '{ print $1 }'`
+        _CC_MINOR_VERSION=`echo ${CC_VERSION} | awk -F\. '{ print $2 }'`
+        _CC_RELEASE=`echo ${CC_VERSION} | awk -F\. '{ print $3 }'`
+        _CC_BUILD=`echo ${CC_VERSION} | awk -F\. '{ print $4 }'`
+        MSC_VER=${_CC_MAJOR_VERSION}${_CC_MINOR_VERSION}
+
+        if test "$_CC_MAJOR_VERSION" -eq "14"; then
+                                            if test $_CC_RELEASE -gt 50727; then
+              _USE_DYNAMICBASE=1
+           elif test $_CC_BUILD -ge 762; then
+              _USE_DYNAMICBASE=1
+           fi
+           $as_echo "#define _CRT_SECURE_NO_DEPRECATE 1" >>confdefs.h
+
+           $as_echo "#define _CRT_NONSTDC_NO_DEPRECATE 1" >>confdefs.h
+
+        elif test $_CC_MAJOR_VERSION -ge 15; then
+           _USE_DYNAMICBASE=1
+           $as_echo "#define _CRT_SECURE_NO_WARNINGS 1" >>confdefs.h
+
+           $as_echo "#define _CRT_NONSTDC_NO_WARNINGS 1" >>confdefs.h
+
+        fi
+
+        if test -n "$_USE_DYNAMICBASE"; then
+           DLLFLAGS="$DLLFLAGS -DYNAMICBASE"
+        fi
+
+        # Ensure that mt is Microsoft (R) Manifest Tool and not magnetic
+        # tape manipulation utility (or something else)
+        if test "$MSC_VER" -ge "1400"; then
+
+            _MSMT_VER_FILTER='s|.* \([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*|\1|p'
+
+
+            MSMT_TOOL=`mt 2>&1|grep 'Microsoft (R) Manifest Tool'`
+            if test -n "$MSMT_TOOL"; then
+                MSMANIFEST_TOOL_VERSION=`echo ${MSMT_TOOL}|sed -ne "$_MSMT_VER_FILTER"`
+                if test -z "$MSMANIFEST_TOOL_VERSION"; then
+                    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Unknown version of the Microsoft (R) Manifest Tool." >&5
+$as_echo "$as_me: WARNING: Unknown version of the Microsoft (R) Manifest Tool." >&2;}
+                fi
+                MT=mt
+                unset MSMT_TOOL
+            else
+                as_fn_error $? "Microsoft (R) Manifest Tool must be in your \$PATH." "$LINENO" 5
+            fi
+        fi
+
+        CFLAGS="$CFLAGS -W3 -nologo -GF -Gy"
+        DLLFLAGS="$DLLFLAGS -OUT:\"\$@\""
+        _DEBUG_FLAGS=-Zi
+        _OPTIMIZE_FLAGS=-O2
+
+        PROFILE_GEN_CFLAGS="-GL"
+        PROFILE_GEN_LDFLAGS="-LTCG:PGINSTRUMENT"
+        PROFILE_USE_CFLAGS="-GL -wd4624 -wd4952"
+        PROFILE_USE_LDFLAGS="-LTCG:PGUPDATE"
+
+        if test "$MSC_VER" -ge "1800"; then
+                                                CFLAGS="$CFLAGS -FS"
+                                    PROFILE_GEN_CFLAGS="$PROFILE_GEN_CFLAGS -Gw"
+            PROFILE_USE_CFLAGS="$PROFILE_USE_CFLAGS -Gw"
+        fi
+
+        if test -z "$MOZ_OPTIMIZE"; then
+            CFLAGS="$CFLAGS -Od"
+        fi
+
+        if test "$USE_DEBUG_RTL" = 1; then
+            if test -n "$USE_STATIC_RTL"; then
+                CFLAGS="$CFLAGS -MTd"
+            else
+                CFLAGS="$CFLAGS -MDd"
+            fi
+        else
+            if test -n "$USE_STATIC_RTL"; then
+                CFLAGS="$CFLAGS -MT"
+            else
+                CFLAGS="$CFLAGS -MD"
+            fi
+        fi
+
+        if test -n "$MOZ_DEBUG"; then
+            $as_echo "#define _DEBUG 1" >>confdefs.h
+
+        else
+            DEFINES="$DEFINES -U_DEBUG"
+        fi
+
+        if test -n "$MOZ_DEBUG_SYMBOLS"; then
+            if test -n "$MOZ_OPTIMIZE"; then
+                DLLFLAGS="$DLLFLAGS -DEBUG -OPT:REF"
+                LDFLAGS="$LDFLAGS -DEBUG -OPT:REF"
+            else
+                DLLFLAGS="$DLLFLAGS -DEBUG"
+                LDFLAGS="$LDFLAGS -DEBUG"
+            fi
+        fi
+
+        OS_DLLFLAGS="-nologo -DLL -SUBSYSTEM:WINDOWS"
+        if test "$MSC_VER" -le "1200" -a -z "$MOZ_DEBUG_SYMBOLS"; then
+            OS_DLLFLAGS="$OS_DLLFLAGS -PDB:NONE"
+        fi
+
+        if test "$OS_TARGET" = "WINNT"; then
+            CFLAGS="$CFLAGS -GT"
+            LIBNSPR='$(dist_libdir)/libnspr$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)'
+            LIBPLC='$(dist_libdir)/libplc$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)'
+        else
+            LIBNSPR='$(dist_libdir)/nspr$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)'
+            LIBPLC='$(dist_libdir)/plc$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)'
+        fi
+    fi # GNU_CC
+
+    if test -n "$USE_STATIC_TLS"; then
+        $as_echo "#define _PR_USE_STATIC_TLS 1" >>confdefs.h
+
+    fi
+
+    if test "$OS_TARGET" = "WINNT"; then
+        $as_echo "#define WINNT 1" >>confdefs.h
+
+    else
+        $as_echo "#define WIN95 1" >>confdefs.h
+
+        # undefine WINNT as some versions of mingw gcc define it by default
+        DEFINES="$DEFINES -UWINNT"
+        $as_echo "#define _PR_GLOBAL_THREADS_ONLY 1" >>confdefs.h
+
+    fi
+
+    if test "$CPU_ARCH" = "x86"; then
+        CPU_ARCH_TAG=
+    else
+        CPU_ARCH_TAG=$CPU_ARCH
+    fi
+
+    if test "$USE_DEBUG_RTL" = 1; then
+        OBJDIR_SUFFIX=OBJD
+    fi
+
+    case "$OS_TARGET" in
+    WINNT)
+	    MDCPUCFG_H=_winnt.cfg
+	    ;;
+    WIN95)
+	    MDCPUCFG_H=_win95.cfg
+	    ;;
+    *)
+	    as_fn_error $? "Missing OS_TARGET for ${target}.  Use --enable-win32-target to set." "$LINENO" 5
+   	;;
+    esac
+
+    case "$target_cpu" in
+    i*86)
+	if test -n "$USE_64"; then
+	    $as_echo "#define _AMD64_ 1" >>confdefs.h
+
+	else
+	    $as_echo "#define _X86_ 1" >>confdefs.h
+
+            if test -z "$GNU_CC" -a "$MSC_VER" -ge "1700"; then
+                                                CFLAGS="$CFLAGS -arch:IA32"
+            fi
+	fi
+        ;;
+    x86_64)
+	    $as_echo "#define _AMD64_ 1" >>confdefs.h
+
+	    USE_64=1
+	    ;;
+    ia64)
+	    $as_echo "#define _IA64_ 1" >>confdefs.h
+
+	    USE_64=1
+	    ;;
+    *)
+	    $as_echo "#define _CPU_ARCH_NOT_DEFINED 1" >>confdefs.h
+
+	    ;;
+    esac
+    ;;
+
+*-netbsd*)
+    $as_echo "#define XP_UNIX 1" >>confdefs.h
+
+    $as_echo "#define NETBSD 1" >>confdefs.h
+
+    $as_echo "#define HAVE_BSD_FLOCK 1" >>confdefs.h
+
+    $as_echo "#define HAVE_SOCKLEN_T 1" >>confdefs.h
+
+    if test -z "$USE_NSPR_THREADS"; then
+        USE_PTHREADS=1
+    fi
+    MDCPUCFG_H=_netbsd.cfg
+    PR_MD_CSRCS=netbsd.c
+
+    DSO_CFLAGS='-fPIC -DPIC'
+    CFLAGS="$CFLAGS -ansi -Wall"
+    CXXFLAGS="$CXXFLAGS -ansi -Wall"
+    MKSHLIB='$(CC) -o $@ $(DSO_LDOPTS)'
+
+    if test -z "$OBJECT_FMT"; then
+        if echo __ELF__ | ${CC-cc} -E - | grep -q __ELF__ 2>/dev/null; then
+            OBJECT_FMT=a.out
+            DLL_SUFFIX=so.1.0
+            DSO_LDOPTS='-shared'
+        else
+            OBJECT_FMT=ELF
+            DLL_SUFFIX=so
+            DSO_LDOPTS='-shared -Wl,-soname,$(notdir $@)'
+        fi
+    fi
+
+    if test "$LIBRUNPATH"; then
+        DSO_LDOPTS="$DSO_LDOPTS -Wl,-R$LIBRUNPATH"
+    fi
+    ;;
+
+*-nto*)
+    $as_echo "#define XP_UNIX 1" >>confdefs.h
+
+    $as_echo "#define NTO 1" >>confdefs.h
+
+    $as_echo "#define _QNX_SOURCE 1" >>confdefs.h
+
+    $as_echo "#define HAVE_POINTER_LOCALTIME_R 1" >>confdefs.h
+
+    MDCPUCFG_H=_nto.cfg
+    PR_MD_CSRCS=nto.c
+    MKSHLIB='$(CC) $(DSO_LDOPTS) -Wl,-soname -Wl,$(notdir $@) -o $@'
+    DSO_CFLAGS=-fPIC
+    DSO_LDOPTS=-shared
+    OS_LIBS="$OS_LIBS -lsocket"
+    _OPTIMIZE_FLAGS="-O1"
+    _DEBUG_FLAGS="-gstabs"
+	;;
+
+*-openbsd*)
+    $as_echo "#define XP_UNIX 1" >>confdefs.h
+
+    $as_echo "#define OPENBSD 1" >>confdefs.h
+
+    $as_echo "#define HAVE_BSD_FLOCK 1" >>confdefs.h
+
+    $as_echo "#define HAVE_SOCKLEN_T 1" >>confdefs.h
+
+    CFLAGS="$CFLAGS -ansi -Wall"
+    CXXFLAGS="$CXXFLAGS -ansi -Wall"
+    DLL_SUFFIX=so.1.0
+    DSO_CFLAGS=-fPIC
+    MDCPUCFG_H=_openbsd.cfg
+    PR_MD_CSRCS=openbsd.c
+    OS_LIBS="-lc"
+    if test -z "$USE_NSPR_THREADS"; then
+        USE_PTHREADS=1
+    fi
+    DSO_LDOPTS='-shared -fPIC -Wl,-soname,$(notdir $@)'
+    MKSHLIB='$(CC) $(DSO_LDOPTS) -o $@'
+    ;;
+
+*-osf*)
+    SHELL_OVERRIDE="SHELL		= /usr/bin/ksh"
+    $as_echo "#define XP_UNIX 1" >>confdefs.h
+
+    $as_echo "#define OSF1 1" >>confdefs.h
+
+    $as_echo "#define _REENTRANT 1" >>confdefs.h
+
+    # OSF1 and HPUX report the POLLHUP event for a socket when the
+    # shutdown(SHUT_WR) operation is called for the remote end, even though
+    # the socket is still writeable. Use select(), instead of poll(), to
+    # workaround this problem.
+    $as_echo "#define _PR_POLL_WITH_SELECT 1" >>confdefs.h
+
+
+    if echo "$OS_RELEASE" | egrep -c '(V2.0|V3.2)' 2>/dev/null ; then
+        USE_NSPR_THREADS=1
+    fi
+
+    if test -z "$GNU_CC"; then
+        CC="$CC -std1 -ieee_with_inexact"
+        if test "$OS_RELEASE" != "V2.0"; then
+            CC="$CC -readonly_strings"
+        fi
+        _OPTIMIZE_FLAGS="$_OPTIMIZE_FLAGS -Olimit 4000"
+        ac_fn_c_check_header_mongrel "$LINENO" "machine/builtins.h" "ac_cv_header_machine_builtins_h" "$ac_includes_default"
+if test "x$ac_cv_header_machine_builtins_h" = xyes; then :
+  $as_echo "#define OSF1_HAVE_MACHINE_BUILTINS_H 1" >>confdefs.h
+
+fi
+
+
+    else
+        CFLAGS="$CFLAGS -mieee"
+        CXXFLAGS="$CXXFLAGS -mieee"
+    fi
+
+    if echo $OS_RELEASE | egrep -c '(V2.0|V3.2)' 2>/dev/null; then
+        $as_echo "#define HAVE_INT_LOCALTIME_R 1" >>confdefs.h
+
+    else
+        $as_echo "#define HAVE_FCNTL_FILE_LOCKING 1" >>confdefs.h
+
+        $as_echo "#define HAVE_POINTER_LOCALTIME_R 1" >>confdefs.h
+
+    fi
+    if echo $OS_RELEASE | grep -c V4.0 >/dev/null; then
+        $as_echo "#define OSF1V4_MAP_PRIVATE_BUG 1" >>confdefs.h
+
+    fi
+    DSO_LDOPTS='-shared -all -expect_unresolved "*" -soname $(notdir $@)'
+    MDCPUCFG_H=_osf1.cfg
+    PR_MD_CSRCS=osf1.c
+    ;;
+
+*-qnx*)
+    $as_echo "#define XP_UNIX 1" >>confdefs.h
+
+    $as_echo "#define QNX 1" >>confdefs.h
+
+    $as_echo "#define _PR_NEED_H_ERRNO 1" >>confdefs.h
+
+    USE_NSPR_THREADS=1
+    MDCPUCFG_H=_qnx.cfg
+    PR_MD_CSRCS=qnx.c
+    ;;
+
+*-riscos*)
+    $as_echo "#define XP_UNIX 1" >>confdefs.h
+
+    $as_echo "#define RISCOS 1" >>confdefs.h
+
+    $as_echo "#define _PR_NEED_H_ERRNO 1" >>confdefs.h
+
+    USE_PTHREADS=1
+    MDCPUCFG_H=_riscos.cfg
+    PR_MD_CSRCS=riscos.c
+    DSO_CFLAGS=-fPIC
+    DSO_LDOPTS='-shared -Wl,-soname -Wl,$(notdir $@)'
+    MKSHLIB='$(CC) $(DSO_LDOPTS) -o $@'
+    ;;
+
+*-*-sco*)
+    $as_echo "#define XP_UNIX 1" >>confdefs.h
+
+    $as_echo "#define SCO 1" >>confdefs.h
+
+    $as_echo "#define sco 1" >>confdefs.h
+
+    $as_echo "#define SYSV 1" >>confdefs.h
+
+    $as_echo "#define _SVID3 1" >>confdefs.h
+
+    $as_echo "#define _PR_NEED_H_ERRNO 1" >>confdefs.h
+
+    CC='cc -b elf -KPIC'
+    CXX='$(NSDEPTH)/build/hcpp CC +.cpp +w'
+    USE_NSPR_THREADS=1
+    CPU_ARCH=x86
+    DSO_LDOPTS='-b elf -G'
+    MDCPUCFG_H=_scoos.cfg
+    PR_MD_SRCS=scoos.c
+    ;;
+
+*-solaris*)
+    if test -z "$USE_NSPR_THREADS"; then
+        USE_PTHREADS=1
+    fi
+    $as_echo "#define XP_UNIX 1" >>confdefs.h
+
+    $as_echo "#define SVR4 1" >>confdefs.h
+
+    $as_echo "#define SYSV 1" >>confdefs.h
+
+    $as_echo "#define __svr4 1" >>confdefs.h
+
+    $as_echo "#define __svr4__ 1" >>confdefs.h
+
+    $as_echo "#define SOLARIS 1" >>confdefs.h
+
+    $as_echo "#define HAVE_FCNTL_FILE_LOCKING 1" >>confdefs.h
+
+    CPU_ARCH=`uname -p`
+    MDCPUCFG_H=_solaris.cfg
+    PR_MD_CSRCS=solaris.c
+    LD=/usr/ccs/bin/ld
+    MKSHLIB='$(CC) $(DSO_LDOPTS) -o $@'
+    RESOLVE_LINK_SYMBOLS=1
+    case "${OS_RELEASE}" in
+    5.8|5.9)
+        ;;
+    *)
+        # It is safe to use the -Bdirect linker flag on Solaris 10 or later.
+        USE_B_DIRECT=1
+        ;;
+    esac
+    if test -n "$GNU_CC"; then
+        DSO_CFLAGS=-fPIC
+        if `$CC -print-prog-name=ld` -v 2>&1 | grep -c GNU >/dev/null; then
+            GCC_USE_GNU_LD=1
+        fi
+        DSO_LDOPTS='-shared -Wl,-h,$(notdir $@),-z,combreloc,-z,defs,-z,ignore'
+        if test -n "$USE_B_DIRECT"; then
+            DSO_LDOPTS="$DSO_LDOPTS,-Bdirect"
+        fi
+    else
+        DSO_CFLAGS=-KPIC
+        DSO_LDOPTS='-G -h $(notdir $@) -z combreloc -z defs -z ignore'
+        if test -n "$USE_B_DIRECT"; then
+            DSO_LDOPTS="$DSO_LDOPTS -Bdirect"
+        fi
+    fi
+    if test -n "$GNU_CC"; then
+        CFLAGS="$CFLAGS -Wall"
+        CXXFLAGS="$CXXFLAGS -Wall"
+        if test -n "$USE_MDUPDATE"; then
+            CFLAGS="$CFLAGS -MDupdate \$(DEPENDENCIES)"
+            CXXFLAGS="$CXXFLAGS -MDupdate \$(DEPENDENCIES)"
+        fi
+        GCC_AS=`$CC -print-prog-name=as`
+        if test "`echo | $GCC_AS -v 2>&1 | grep -c GNU`" != "0"; then
+            GNU_AS=1
+        fi
+    else
+        CFLAGS="$CFLAGS -xstrconst"
+        CXXFLAGS="$CXXFLAGS -Qoption cg -xstrconst -features=tmplife"
+        if test -z "$MOZ_OPTIMIZE"; then
+            CFLAGS="$CFLAGS -xs"
+            CXXFLAGS="$CXXFLAGS -xs"
+        fi
+        _OPTIMIZE_FLAGS=-xO4
+    fi
+    if test -z "$GNU_AS"; then
+        ASFLAGS="$ASFLAGS -Wa,-P"
+    fi
+    if test -n "$USE_64"; then
+        if test -n "$GNU_CC"; then
+            CC="$CC -m64"
+            CXX="$CXX -m64"
+        else
+            if test "$OS_TEST" = "i86pc"; then
+                CC="$CC -xarch=amd64"
+                CXX="$CXX -xarch=amd64"
+            else
+                CC="$CC -xarch=v9"
+                CXX="$CXX -xarch=v9"
+            fi
+        fi
+    fi
+    if test "$OS_TEST" = "i86pc"; then
+        if test -z "$USE_64"; then
+            $as_echo "#define i386 1" >>confdefs.h
+
+        fi
+        CPU_ARCH_TAG=_$OS_TEST
+        # The default debug format, DWARF (-g), is not supported by gcc
+        # on i386-ANY-sysv4/solaris, but the stabs format is.  It is
+        # assumed that the Solaris assembler /usr/ccs/bin/as is used.
+        # If your gcc uses GNU as, you do not need the -Wa,-s option.
+        if test -n "$MOZ_DEBUG" && test -n "$GNU_CC"; then
+            _DEBUG_FLAGS=-gstabs
+            if test -z "$GNU_AS"; then
+                _DEBUG_FLAGS="$_DEBUG_FLAGS -Wa,-s"
+            fi
+        fi
+    fi
+    case "${target_os}" in
+    solaris2.3*)
+        $as_echo "#define _PR_NO_LARGE_FILES 1" >>confdefs.h
+
+        ;;
+    solaris2.4*)
+        $as_echo "#define _PR_NO_LARGE_FILES 1" >>confdefs.h
+
+        ;;
+    solaris2.5*)
+        $as_echo "#define SOLARIS2_5 1" >>confdefs.h
+
+        ;;
+    *)
+        $as_echo "#define _PR_HAVE_OFF64_T 1" >>confdefs.h
+
+        # The lfcompile64(5) man page on Solaris 2.6 says:
+        #     For applications that do not wish to conform to the POSIX or
+        #     X/Open  specifications,  the  64-bit transitional interfaces
+        #     are available by default.  No compile-time flags need to  be
+        #     set.
+        # But gcc 2.7.2.x fails to define _LARGEFILE64_SOURCE by default.
+        # The native compiler, gcc 2.8.x, and egcs don't have this problem.
+        if test -n "$GNU_CC"; then
+            $as_echo "#define _LARGEFILE64_SOURCE 1" >>confdefs.h
+
+        fi
+        ;;
+    esac
+    case "${target_os}" in
+    solaris2.3*)
+        ;;
+    solaris2.4*)
+        ;;
+    solaris2.5*)
+        ;;
+    solaris2.6*)
+        ;;
+    solaris2.7*)
+        ;;
+    *)
+        # Solaris 8 or higher has IPv6.
+        $as_echo "#define _PR_INET6 1" >>confdefs.h
+
+        ;;
+    esac
+    if test "$CPU_ARCH" = "sparc"; then
+        # 64-bit Solaris SPARC requires V9 architecture, so the following
+        # is not needed.
+        if test -z "$USE_64"; then
+            ULTRASPARC_LIBRARY=nspr_flt
+        fi
+    fi
+    # Purify requires that binaries linked against nspr also
+    # be linked against -lrt (or -lposix4) so add it to OS_LIBS
+    _rev=`uname -r`
+    _librt=`echo $_rev 5.6 | awk '{ if ($1 > $2) print "-lrt"; else print "-lposix4" }'`
+    OS_LIBS="$OS_LIBS $_librt"
+    ;;
+
+*-sco-sysv5*)
+    $as_echo "#define XP_UNIX 1" >>confdefs.h
+
+    $as_echo "#define UNIXWARE 1" >>confdefs.h
+
+    $as_echo "#define SVR4 1" >>confdefs.h
+
+    $as_echo "#define SYSV 1" >>confdefs.h
+
+    USE_NSPR_THREADS=1
+    if echo $OS_RELEASE | grep -c 2.1 2>/dev/null; then
+        $as_echo "#define _PR_NO_LARGE_FILES 1" >>confdefs.h
+
+        CC='$(NSDEPTH)/build/hcc cc'
+        CXX='$(NSDEPTH)/build/hcpp CC'
+        MDCPUCFG_H=_unixware.cfg
+    else
+        $as_echo "#define _LARGEFILE64_SOURCE 1" >>confdefs.h
+
+        $as_echo "#define _PR_HAVE_OFF64_T 1" >>confdefs.h
+
+        $as_echo "#define _PR_HAVE_SOCKADDR_LEN 1" >>confdefs.h
+
+        MDCPUCFG_H=_unixware7.cfg
+    fi
+    PR_MD_CSRCS=unixware.c
+    DSO_LDOPTS=-G
+    CPU_ARCH=x86
+    ;;
+
+*-symbian*)
+
+# Check whether --with-symbian-sdk was given.
+if test "${with_symbian_sdk+set}" = set; then :
+  withval=$with_symbian_sdk; SYMBIAN_SDK_DIR=$withval
+fi
+
+
+    echo -----------------------------------------------------------------------------
+    echo Building with Symbian SDK in: $SYMBIAN_SDK_DIR
+    echo -----------------------------------------------------------------------------
+
+    $as_echo "#define XP_UNIX 1" >>confdefs.h
+
+    $as_echo "#define SYMBIAN 1" >>confdefs.h
+
+    $as_echo "#define __arm__ 1" >>confdefs.h
+
+    $as_echo "#define __SYMBIAN32__ 1" >>confdefs.h
+
+    $as_echo "#define _UNICODE 1" >>confdefs.h
+
+    $as_echo "#define NDEBUG 1" >>confdefs.h
+
+    $as_echo "#define __SUPPORT_CPP_EXCEPTIONS__ 1" >>confdefs.h
+
+    $as_echo "#define MOZ_STDERR_TO_STDOUT 1" >>confdefs.h
+
+    $as_echo "#define HAVE_FCNTL_FILE_LOCKING 1" >>confdefs.h
+
+    $as_echo "#define HAVE_SOCKLEN_T 1" >>confdefs.h
+
+    USE_PTHREADS=1
+    LIB_SUFFIX=lib
+    DLL_SUFFIX=dll
+    MKSHLIB=
+    DSO_LDOPTS=
+    DSO_CFLAGS=
+    VISIBILITY_FLAGS=
+    MDCPUCFG_H=_symbian.cfg
+    PR_MD_CSRCS=symbian.c
+    NSINSTALL=nsinstall
+    RANLIB='echo no ranlib '
+    CPU_ARCH=ARM
+    OS_ARCH=SYMBIAN
+    OS_EXE_CFLAGS="$OS_EXE_CFLAGS -D__EXE__"
+    CFLAGS="$CFLAGS -MD -nostdinc"
+    SYMBIAN_SYS_INCLUDE="-I$SYMBIAN_SDK_DIR/Epoc32/include/variant -I$SYMBIAN_SDK_DIR/Epoc32/include -I$SYMBIAN_SDK_DIR/Epoc32/include/stdapis"
+    echo -------------------------------------------------------
+    echo SYMBIAN_SYS_INCLUDE is: $SYMBIAN_SYS_INCLUDE
+    echo -------------------------------------------------------
+    case "$OS_TARGET" in
+    WINSCW)
+        CC=mwccsym2.exe
+        CXX=mwccsym2.exe
+        LD=mwldsym2.exe
+        AR=mwldsym2.exe
+        WINSCW_LD_DIR="\$(SYMBIAN_SDK_DIR)/EPOC32/RELEASE/WINSCW/UDEB"
+        CFLAGS="$CFLAGS -O0 -inline off -wchar_t off -align 4 -warnings on -w nohidevirtual,nounusedexpr -msgstyle gcc -enum int -str pool -exc ms -trigraphs on -nostderr -gccdep -cwd source -i- -I\$(VPATH)"
+        SYMBIAN_SYS_INCLUDE="$SYMBIAN_SYS_INCLUDE -include Symbian_OS_v9.2.hrh"
+        AR_FLAGS="-library -msgstyle gcc -stdlib -subsystem windows -noimplib -o \$@"
+        $as_echo "#define _DEBUG 1" >>confdefs.h
+
+        $as_echo "#define __CW32__ 1" >>confdefs.h
+
+        $as_echo "#define __WINS__ 1" >>confdefs.h
+
+        $as_echo "#define __WINSCW__ 1" >>confdefs.h
+
+        DEFINES="$DEFINES -U_WIN32"
+	    ;;
+    GCCE)
+        CFLAGS="$CFLAGS -Wall -Wno-unknown-pragmas -fexceptions -march=armv5t -mapcs -pipe -x c -msoft-float"
+        CXXFLAGS="$CXXFLAGS $CFLAGS -Wno-ctor-dtor-privacy"
+        SYMBIAN_SYS_INCLUDE="$SYMBIAN_SYS_INCLUDE -include $SYMBIAN_SDK_DIR/EPOC32/INCLUDE/GCCE/GCCE.h"
+        $as_echo "#define __GCCE__ 1" >>confdefs.h
+
+        $as_echo "#define __EABI__ 1" >>confdefs.h
+
+        DEFINES="$DEFINES -D__PRODUCT_INCLUDE__=$SYMBIAN_SDK_DIR/Epoc32/include/variant/Symbian_OS_v9.2.hrh"
+	    ;;
+    *)
+	    as_fn_error $? "Missing OS_TARGET for ${target}. Set --enable-symbian-target to with 'WINSCW' or 'GCCE'." "$LINENO" 5
+   	;;
+    esac
+    CFLAGS="$CFLAGS ${SYMBIAN_SYS_INCLUDE}"
+    ;;
+
+*-os2*)
+    $as_echo "#define XP_OS2 1" >>confdefs.h
+
+    $as_echo "#define XP_PC 1" >>confdefs.h
+
+    $as_echo "#define BSD_SELECT 1" >>confdefs.h
+
+    $as_echo "#define TCPV40HDRS 1" >>confdefs.h
+
+    LIB_SUFFIX=lib
+    DLL_SUFFIX=dll
+    RC=rc.exe
+    PR_MD_ARCH_DIR=os2
+    PROG_SUFFIX=.exe
+    NSINSTALL=nsinstall
+    MDCPUCFG_H=_os2.cfg
+    RESOLVE_LINK_SYMBOLS=1
+
+    $as_echo "#define OS2 1" >>confdefs.h
+
+    AR=emxomfar
+    AR_FLAGS='r $@'
+    CFLAGS="$CFLAGS -Wall -Zomf"
+    CXXFLAGS="$CFLAGS -Wall -Zomf"
+    MKSHLIB='$(CC) $(DSO_LDOPTS) -o $@'
+    DSO_CFLAGS=
+    DSO_LDOPTS='-Zomf -Zdll'
+    LDFLAGS='-Zmap'
+    _OPTIMIZE_FLAGS="-O2 -s"
+    _DEBUG_FLAGS="-g -fno-inline"
+    if test -n "$MOZ_OPTIMIZE"; then
+      DSO_LDOPTS="$DSO_LDOPTS -Zlinker /EXEPACK:2 -Zlinker /PACKCODE -Zlinker /PACKDATA"
+    fi
+    IMPLIB='emximp -o'
+    FILTER='emxexp -o'
+    if test -n "$MOZ_OS2_HIGH_MEMORY"; then
+      LDFLAGS="$LDFLAGS -Zhigh-mem"
+      $as_echo "#define MOZ_OS2_HIGH_MEMORY 1" >>confdefs.h
+
+    fi
+
+    # GCC for OS/2 currently predefines these, but we don't want them
+    DEFINES="$DEFINES -Uunix -U__unix -U__unix__"
+    ;;
+
+*)
+    $as_echo "#define XP_UNIX 1" >>confdefs.h
+
+    ;;
+
+esac
+
+if test -z "$SKIP_LIBRARY_CHECKS"; then
+
+
+
+case $target in
+*-darwin*|*-beos*|*-os2*)
+    ;;
+*)
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5
+$as_echo_n "checking for dlopen in -ldl... " >&6; }
+if ${ac_cv_lib_dl_dlopen+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-ldl  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dlopen ();
+int
+main ()
+{
+return dlopen ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_dl_dlopen=yes
+else
+  ac_cv_lib_dl_dlopen=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5
+$as_echo "$ac_cv_lib_dl_dlopen" >&6; }
+if test "x$ac_cv_lib_dl_dlopen" = xyes; then :
+  ac_fn_c_check_header_mongrel "$LINENO" "dlfcn.h" "ac_cv_header_dlfcn_h" "$ac_includes_default"
+if test "x$ac_cv_header_dlfcn_h" = xyes; then :
+  OS_LIBS="-ldl $OS_LIBS"
+fi
+
+
+fi
+
+    ;;
+esac
+
+
+
+
+if test $ac_cv_c_compiler_gnu = yes; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC needs -traditional" >&5
+$as_echo_n "checking whether $CC needs -traditional... " >&6; }
+if ${ac_cv_prog_gcc_traditional+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+    ac_pattern="Autoconf.*'x'"
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sgtty.h>
+Autoconf TIOCGETP
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "$ac_pattern" >/dev/null 2>&1; then :
+  ac_cv_prog_gcc_traditional=yes
+else
+  ac_cv_prog_gcc_traditional=no
+fi
+rm -f conftest*
+
+
+  if test $ac_cv_prog_gcc_traditional = no; then
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <termio.h>
+Autoconf TCGETA
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "$ac_pattern" >/dev/null 2>&1; then :
+  ac_cv_prog_gcc_traditional=yes
+fi
+rm -f conftest*
+
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_gcc_traditional" >&5
+$as_echo "$ac_cv_prog_gcc_traditional" >&6; }
+  if test $ac_cv_prog_gcc_traditional = yes; then
+    CC="$CC -traditional"
+  fi
+fi
+
+_SAVE_LIBS="$LIBS"
+LIBS="$LIBS $OS_LIBS"
+for ac_func in dladdr gettid lchown setpriority strerror syscall  secure_getenv __secure_getenv
+do :
+  as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
+ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
+if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+done
+
+LIBS="$_SAVE_LIBS"
+
+
+
+# Check whether --with-ccache was given.
+if test "${with_ccache+set}" = set; then :
+  withval=$with_ccache; CCACHE=$withval
+else
+  CCACHE="no"
+fi
+
+
+if test "$CCACHE" != "no"; then
+    if test -n "$CCACHE"; then
+        if test "$CCACHE" = "yes"; then
+            CCACHE=
+        else
+            if test ! -e "$CCACHE"; then
+                as_fn_error $? "$CCACHE not found" "$LINENO" 5
+            fi
+        fi
+    fi
+    for ac_prog in $CCACHE ccache
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_CCACHE+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $CCACHE in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_CCACHE="$CCACHE" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_CCACHE="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+CCACHE=$ac_cv_path_CCACHE
+if test -n "$CCACHE"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CCACHE" >&5
+$as_echo "$CCACHE" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$CCACHE" && break
+done
+
+    if test -z "$CCACHE" -o "$CCACHE" = ":"; then
+        as_fn_error $? "ccache not found" "$LINENO" 5
+    elif test -x "$CCACHE"; then
+        CC="$CCACHE $CC"
+        CXX="$CCACHE $CXX"
+    else
+        as_fn_error $? "$CCACHE is not executable" "$LINENO" 5
+    fi
+fi
+
+# Check whether --enable-strip was given.
+if test "${enable_strip+set}" = set; then :
+  enableval=$enable_strip;  if test "$enableval" = "yes"; then
+	    ENABLE_STRIP=1
+      fi
+fi
+
+
+case "${target_os}" in
+hpux*)
+if test -z "$GNU_CC"; then
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for +Olit support" >&5
+$as_echo_n "checking for +Olit support... " >&6; }
+if ${ac_cv_hpux_usable_olit_option+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+                  ac_cv_hpux_usable_olit_option=no
+        rm -f conftest*
+        echo 'int main() { return 0; }' | cat > conftest.c
+        ${CC-cc} ${CFLAGS} +Olit=all -o conftest conftest.c > conftest.out 2>&1
+        if test $? -eq 0; then
+            if test -z "`egrep -i '(unrecognize|unknown)' conftest.out`"; then
+                ac_cv_hpux_usable_olit_option=yes
+            fi
+        fi
+        rm -f conftest*
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_hpux_usable_olit_option" >&5
+$as_echo "$ac_cv_hpux_usable_olit_option" >&6; }
+
+    if test "$ac_cv_hpux_usable_olit_option" = "yes"; then
+        CFLAGS="$CFLAGS +Olit=all"
+        CXXFLAGS="$CXXFLAGS +Olit=all"
+    else
+        CFLAGS="$CFLAGS +ESlit"
+        CXXFLAGS="$CXXFLAGS +ESlit"
+    fi
+fi
+;;
+esac
+
+case "$target_os" in
+darwin*)
+    _HAVE_PTHREADS=1
+    ;;
+*)
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_create in -lpthreads" >&5
+$as_echo_n "checking for pthread_create in -lpthreads... " >&6; }
+if ${ac_cv_lib_pthreads_pthread_create+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lpthreads  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char pthread_create ();
+int
+main ()
+{
+return pthread_create ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_pthreads_pthread_create=yes
+else
+  ac_cv_lib_pthreads_pthread_create=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthreads_pthread_create" >&5
+$as_echo "$ac_cv_lib_pthreads_pthread_create" >&6; }
+if test "x$ac_cv_lib_pthreads_pthread_create" = xyes; then :
+  _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthreads"
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_create in -lpthread" >&5
+$as_echo_n "checking for pthread_create in -lpthread... " >&6; }
+if ${ac_cv_lib_pthread_pthread_create+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lpthread  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char pthread_create ();
+int
+main ()
+{
+return pthread_create ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_pthread_pthread_create=yes
+else
+  ac_cv_lib_pthread_pthread_create=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthread_pthread_create" >&5
+$as_echo "$ac_cv_lib_pthread_pthread_create" >&6; }
+if test "x$ac_cv_lib_pthread_pthread_create" = xyes; then :
+  _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthread"
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_create in -lc_r" >&5
+$as_echo_n "checking for pthread_create in -lc_r... " >&6; }
+if ${ac_cv_lib_c_r_pthread_create+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lc_r  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char pthread_create ();
+int
+main ()
+{
+return pthread_create ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_c_r_pthread_create=yes
+else
+  ac_cv_lib_c_r_pthread_create=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_c_r_pthread_create" >&5
+$as_echo "$ac_cv_lib_c_r_pthread_create" >&6; }
+if test "x$ac_cv_lib_c_r_pthread_create" = xyes; then :
+  _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lc_r"
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_create in -lc" >&5
+$as_echo_n "checking for pthread_create in -lc... " >&6; }
+if ${ac_cv_lib_c_pthread_create+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lc  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char pthread_create ();
+int
+main ()
+{
+return pthread_create ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_c_pthread_create=yes
+else
+  ac_cv_lib_c_pthread_create=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_c_pthread_create" >&5
+$as_echo "$ac_cv_lib_c_pthread_create" >&6; }
+if test "x$ac_cv_lib_c_pthread_create" = xyes; then :
+  _HAVE_PTHREADS=1
+
+fi
+
+
+fi
+
+
+fi
+
+
+fi
+
+    ;;
+esac
+
+
+# Check whether --with-pthreads was given.
+if test "${with_pthreads+set}" = set; then :
+  withval=$with_pthreads;  if test "$withval" = "yes"; then
+	    if test -n "$_HAVE_PTHREADS"; then
+		    USE_PTHREADS=1
+		    USE_USER_PTHREADS=
+		    USE_NSPR_THREADS=
+	    else
+		    as_fn_error $? " --with-pthreads specified for a system without pthread support " "$LINENO" 5;
+	    fi
+	  else
+	    USE_PTHREADS=
+	    _PTHREAD_LDFLAGS=
+	  fi
+else
+   if test -n "$_HAVE_PTHREADS" && test -z "$USE_USER_PTHREADS" && test -z "$USE_NSPR_THREADS"; then
+	    USE_PTHREADS=1
+	    USE_USER_PTHREADS=
+	    USE_NSPR_THREADS=
+	  fi
+fi
+
+
+# Check whether --enable-user-pthreads was given.
+if test "${enable_user_pthreads+set}" = set; then :
+  enableval=$enable_user_pthreads;  if test "$enableval" = "yes"; then
+        if test -n "$_HAVE_PTHREADS"; then
+		    USE_PTHREADS=
+		    USE_USER_PTHREADS=1
+		    USE_NSPR_THREADS=
+	    else
+		    as_fn_error $? " --enable-user-pthreads specified for a system without pthread support " "$LINENO" 5;
+	    fi
+	  fi
+fi
+
+
+# Check whether --enable-nspr-threads was given.
+if test "${enable_nspr_threads+set}" = set; then :
+  enableval=$enable_nspr_threads;  if test "$enableval" = "yes"; then
+	    USE_PTHREADS=
+	    USE_USER_PTHREADS=
+	    USE_NSPR_THREADS=1
+	  fi
+fi
+
+
+case "$target" in
+*-beos*)
+
+# Check whether --with-bthreads was given.
+if test "${with_bthreads+set}" = set; then :
+  withval=$with_bthreads; 	if test "$withval" = "yes"; then
+    	    USE_BTHREADS=1
+	        USE_USER_PTHREADS=
+	        USE_PTHREADS=
+	    fi
+fi
+
+    ;;
+esac
+
+fi # SKIP_LIBRARY_CHECKS
+
+# Check whether --enable-ipv6 was given.
+if test "${enable_ipv6+set}" = set; then :
+  enableval=$enable_ipv6;  if test "$enableval" = "yes"; then
+	    USE_IPV6=1
+      else
+	    USE_IPV6=
+      fi
+fi
+
+
+if test -n "$USE_PTHREADS"; then
+      rm -f conftest*
+   ac_cv_have_dash_pthread=no
+   { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC-cc} accepts -pthread" >&5
+$as_echo_n "checking whether ${CC-cc} accepts -pthread... " >&6; }
+   echo 'int main() { return 0; }' | cat > conftest.c
+   ${CC-cc} -pthread -o conftest conftest.c > conftest.out 2>&1
+   if test $? -eq 0; then
+	if test -z "`egrep -i '(unrecognize|unknown)' conftest.out | grep pthread`" && test -z "`egrep -i '(error|incorrect)' conftest.out`" ; then
+	    ac_cv_have_dash_pthread=yes
+		case "$target_os" in
+	    freebsd*)
+# Freebsd doesn't use -pthread for compiles, it uses them for linking
+            ;;
+	    *)
+            CFLAGS="$CFLAGS -pthread"
+            CXXFLAGS="$CXXFLAGS -pthread"
+            ;;
+        esac
+	fi
+    fi
+    rm -f conftest*
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_have_dash_pthread" >&5
+$as_echo "$ac_cv_have_dash_pthread" >&6; }
+
+			    ac_cv_have_dash_pthreads=no
+    if test "$ac_cv_have_dash_pthread" = "no"; then
+	    { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC-cc} accepts -pthreads" >&5
+$as_echo_n "checking whether ${CC-cc} accepts -pthreads... " >&6; }
+    	echo 'int main() { return 0; }' | cat > conftest.c
+	    ${CC-cc} -pthreads -o conftest conftest.c > conftest.out 2>&1
+    	if test $? -eq 0; then
+	    	if test -z "`egrep -i '(unrecognize|unknown)' conftest.out | grep pthreads`" && test -z "`egrep -i '(error|incorrect)' conftest.out`" ; then
+			    ac_cv_have_dash_pthreads=yes
+			    CFLAGS="$CFLAGS -pthreads"
+			    CXXFLAGS="$CXXFLAGS -pthreads"
+		    fi
+	    fi
+	    rm -f conftest*
+    	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_have_dash_pthreads" >&5
+$as_echo "$ac_cv_have_dash_pthreads" >&6; }
+    fi
+
+    case "$target" in
+    *-solaris*)
+        if test "$ac_cv_have_dash_pthreads" = "yes"; then
+            _PTHREAD_LDFLAGS=
+        fi
+	    ;;
+    *-freebsd*)
+	    $as_echo "#define _REENTRANT 1" >>confdefs.h
+
+	    $as_echo "#define _THREAD_SAFE 1" >>confdefs.h
+
+	    	    if test "$ac_cv_have_dash_pthread" = "yes"; then
+	        _PTHREAD_LDFLAGS="-pthread"
+	    else
+	        _PTHREAD_LDFLAGS="-lc_r"
+	    fi
+	    ;;
+    *-netbsd*)
+	    if test "$ac_cv_have_dash_pthread" = "yes"; then
+	        _PTHREAD_LDFLAGS="-pthread"
+	    fi
+	    ;;
+    *-bsdi*)
+	    $as_echo "#define _THREAD_SAFE 1" >>confdefs.h
+
+	    	    if test "$ac_cv_have_dash_pthread" = "yes"; then
+	        _PTHREAD_LDFLAGS=
+	    fi
+	    ;;
+    *-openbsd*)
+        if test "$ac_cv_have_dash_pthread" = "yes"; then
+            _PTHREAD_LDFLAGS=-pthread
+        fi
+        ;;
+    *-linux*|*-gnu*|*-k*bsd*-gnu)
+        $as_echo "#define _REENTRANT 1" >>confdefs.h
+
+        ;;
+    esac
+
+else
+    if test -n "$USE_USER_PTHREADS"; then
+	    USE_PTHREADS=
+	    USE_NSPR_THREADS=
+    else
+        _PTHREAD_LDFLAGS=
+    fi
+fi
+
+case "$target" in
+*-aix*)
+    if test -n "$USE_NSPR_THREADS"; then
+        $as_echo "#define _PR_LOCAL_THREADS_ONLY 1" >>confdefs.h
+
+    fi
+    case "$target_os" in
+    aix4.1*)
+        if test -z "$USE_PTHREADS"; then
+            $as_echo "#define AIX_RENAME_SELECT 1" >>confdefs.h
+
+        fi
+        ;;
+    aix4.2*)
+        if test -z "$USE_NSPR_THREADS"; then
+            $as_echo "#define HAVE_POINTER_LOCALTIME_R 1" >>confdefs.h
+
+        fi
+        ;;
+    aix4.3*)
+        if test -z "$USE_NSPR_THREADS"; then
+            $as_echo "#define HAVE_POINTER_LOCALTIME_R 1" >>confdefs.h
+
+        fi
+        if test -n "$USE_PTHREADS"; then
+            $as_echo "#define _PR_HAVE_THREADSAFE_GETHOST 1" >>confdefs.h
+
+        fi
+        ;;
+    *)
+        if test -z "$USE_NSPR_THREADS"; then
+            $as_echo "#define HAVE_POINTER_LOCALTIME_R 1" >>confdefs.h
+
+        fi
+        if test -n "$USE_PTHREADS"; then
+            $as_echo "#define _PR_HAVE_THREADSAFE_GETHOST 1" >>confdefs.h
+
+        fi
+        ;;
+    esac
+    ;;
+*-bsdi*)
+    if test -n "$USE_PTHREADS"; then
+        $as_echo "#define _PR_NEED_PTHREAD_INIT 1" >>confdefs.h
+
+    fi
+    ;;
+*-freebsd*)
+    if test -n "$USE_NSPR_THREADS"; then
+        $as_echo "#define _PR_LOCAL_THREADS_ONLY 1" >>confdefs.h
+
+    fi
+    ;;
+*-hpux*)
+    if test -n "$USE_NSPR_THREADS"; then
+        $as_echo "#define _PR_LOCAL_THREADS_ONLY 1" >>confdefs.h
+
+    fi
+    if test "$USE_PTHREADS"; then
+        if echo "$OS_RELEASE" | egrep '^(B.10.10|B.10.20)' >/dev/null; then
+            $as_echo "#define _REENTRANT 1" >>confdefs.h
+
+            $as_echo "#define _PR_DCETHREADS 1" >>confdefs.h
+
+        else
+            cat >>confdefs.h <<_ACEOF
+#define _POSIX_C_SOURCE 199506L
+_ACEOF
+
+            $as_echo "#define _PR_HAVE_THREADSAFE_GETHOST 1" >>confdefs.h
+
+        fi
+    fi
+    if test "$USE_USER_PTHREADS"; then
+        cat >>confdefs.h <<_ACEOF
+#define _POSIX_C_SOURCE 199506L
+_ACEOF
+
+    fi
+    ;;
+*-irix*)
+    if test "${target_os}" = "irix6.5"; then
+        if test -n "$USE_PTHREADS"; then
+            $as_echo "#define _PR_HAVE_GETHOST_R 1" >>confdefs.h
+
+            $as_echo "#define _PR_HAVE_GETHOST_R_POINTER 1" >>confdefs.h
+
+        fi
+    fi
+    ;;
+*-linux*|*-gnu*|*-k*bsd*-gnu)
+    if test -n "$USE_NSPR_THREADS"; then
+        $as_echo "#define _PR_LOCAL_THREADS_ONLY 1" >>confdefs.h
+
+    fi
+    ;;
+*-mingw*|*-msys*|*-cygwin*|*-mks*|*-os2*|*-beos*)
+        USE_PTHREADS=
+    _PTHREAD_LDFLAGS=
+    USE_USER_PTHREADS=
+    ;;
+*-netbsd*|*-openbsd*)
+    if test -n "$USE_NSPR_THREADS"; then
+        $as_echo "#define _PR_LOCAL_THREADS_ONLY 1" >>confdefs.h
+
+    fi
+    ;;
+*-osf*)
+    if test -n "$USE_NSPR_THREADS"; then
+        $as_echo "#define _PR_LOCAL_THREADS_ONLY 1" >>confdefs.h
+
+    fi
+    if test -n "$USE_PTHREADS"; then
+        if echo $OS_RELEASE | egrep -c '(V2.0|V3.2)' 2>/dev/null; then
+            :
+        else
+            $as_echo "#define _PR_HAVE_THREADSAFE_GETHOST 1" >>confdefs.h
+
+        fi
+    fi
+    ;;
+*-solaris*)
+    if test -n "$USE_NSPR_THREADS"; then
+        $as_echo "#define _PR_LOCAL_THREADS_ONLY 1" >>confdefs.h
+
+    fi
+    if test -n "$USE_PTHREADS"; then
+        $as_echo "#define _REENTRANT 1" >>confdefs.h
+
+        $as_echo "#define HAVE_POINTER_LOCALTIME_R 1" >>confdefs.h
+
+        if test "$OS_TEST" = "i86pc"; then
+            if test -n "$USE_64"; then
+               PR_MD_ASFILES=os_SunOS_x86_64.s
+            else
+               PR_MD_ASFILES=os_SunOS_x86.s
+            fi
+        else
+            if test -n "$USE_64"; then
+                PR_MD_ASFILES=os_SunOS_sparcv9.s
+            fi
+        fi
+    fi
+    ;;
+*-nto*)
+    if test -n "$USE_PTHREADS"; then
+        $as_echo "#define _PR_HAVE_GETHOST_R 1" >>confdefs.h
+
+        $as_echo "#define _PR_HAVE_GETHOST_R_POINTER 1" >>confdefs.h
+
+    fi
+    ;;
+esac
+
+OS_LIBS="$_PTHREAD_LDFLAGS $OS_LIBS"
+
+if test -n "$_SAVE_OPTIMIZE_FLAGS"; then
+    _OPTIMIZE_FLAGS="$_SAVE_OPTIMIZE_FLAGS"
+fi
+
+if test -n "$_SAVE_DEBUG_FLAGS"; then
+    _DEBUG_FLAGS="$_SAVE_DEBUG_FLAGS"
+fi
+
+if test -n "$MOZ_OPTIMIZE"; then
+    CFLAGS="$CFLAGS $_OPTIMIZE_FLAGS"
+    CXXFLAGS="$CXXFLAGS $_OPTIMIZE_FLAGS"
+fi
+
+if test -n "$MOZ_DEBUG_SYMBOLS"; then
+    CFLAGS="$CFLAGS $_DEBUG_FLAGS"
+    CXXFLAGS="$CXXFLAGS $_DEBUG_FLAGS"
+fi
+
+if test -n "$MOZ_OPTIMIZE"; then
+    OBJDIR_TAG=_OPT
+else
+    OBJDIR_TAG=_DBG
+fi
+
+if test -n "$USE_64"; then
+    COMPILER_TAG=_64
+fi
+
+RELEASE_OBJDIR_NAME="${OS_CONFIG}${CPU_ARCH_TAG}${COMPILER_TAG}${IMPL_STRATEGY}${OBJDIR_TAG}.${OBJDIR_SUFFIX}"
+
+case "$target_os" in
+cygwin*|mks*)
+    CC="\$(CYGWIN_WRAPPER) $CC"
+    CXX="\$(CYGWIN_WRAPPER) $CXX"
+    RC="\$(CYGWIN_WRAPPER) $RC"
+    ;;
+esac
+
+# Check whether --enable-wrap-malloc was given.
+if test "${enable_wrap_malloc+set}" = set; then :
+  enableval=$enable_wrap_malloc;      if test "$enableval" = "yes"; then
+	    _WRAP_MALLOC=1
+      fi
+fi
+
+
+if test -n "$_WRAP_MALLOC"; then
+    if test -n "$GNU_CC"; then
+        WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=malloc,--wrap=calloc,--wrap=valloc,--wrap=free,--wrap=realloc,--wrap=memalign"
+        WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=__builtin_new,--wrap=__builtin_vec_new,--wrap=__builtin_delete,--wrap=__builtin_vec_delete"
+        WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=strdup,--wrap=strndup"
+        WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=posix_memalign,--wrap=malloc_usable_size"
+    else
+        as_fn_error $? "--enable-wrap-malloc is not supported for non-GNU toolchains" "$LINENO" 5
+    fi
+fi
+
+
+# Check whether --with-wrap-malloc was given.
+if test "${with_wrap_malloc+set}" = set; then :
+  withval=$with_wrap_malloc; WRAP_LDFLAGS="${WRAP_LDFLAGS} $withval"
+fi
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+MAKEFILES="
+    Makefile
+    config/Makefile
+    config/autoconf.mk
+    config/nsprincl.mk
+    config/nsprincl.sh
+    config/nspr-config
+    config/nspr.pc
+    lib/Makefile
+    lib/ds/Makefile
+    lib/libc/Makefile
+    lib/libc/include/Makefile
+    lib/libc/src/Makefile
+    lib/tests/Makefile
+    pkg/Makefile
+    pr/Makefile
+    pr/include/Makefile
+    pr/include/md/Makefile
+    pr/include/obsolete/Makefile
+    pr/include/private/Makefile
+    pr/src/Makefile
+    pr/src/io/Makefile
+    pr/src/linking/Makefile
+    pr/src/malloc/Makefile
+    pr/src/md/Makefile
+    pr/src/md/${PR_MD_ARCH_DIR}/Makefile
+    pr/src/memory/Makefile
+    pr/src/misc/Makefile
+    pr/src/threads/Makefile
+    pr/tests/Makefile
+    pr/tests/dll/Makefile
+"
+
+if test "$OS_TARGET" = "Linux"; then
+    MAKEFILES="$MAKEFILES
+        pkg/linux/Makefile
+    "
+elif test "$OS_TARGET" = "SunOS"; then
+    MAKEFILES="$MAKEFILES
+        pkg/solaris/Makefile
+        pkg/solaris/SUNWpr/Makefile
+        pkg/solaris/SUNWprd/Makefile
+    "
+fi
+
+if test -z "$USE_PTHREADS" && test -z "$USE_BTHREADS"; then
+    MAKEFILES="$MAKEFILES
+        pr/src/threads/combined/Makefile
+    "
+elif test -n "$USE_PTHREADS"; then
+    MAKEFILES="$MAKEFILES
+        pr/src/pthreads/Makefile
+    "
+elif test -n "$USE_BTHREADS"; then
+    MAKEFILES="$MAKEFILES
+        pr/src/bthreads/Makefile
+    "
+fi
+
+if test -n "$USE_CPLUS"; then
+    MAKEFILES="$MAKEFILES
+        pr/src/cplus/Makefile
+        pr/src/cplus/tests/Makefile
+    "
+fi
+
+echo $MAKEFILES > unallmakefiles
+
+ac_config_files="$ac_config_files $MAKEFILES"
+
+ac_config_commands="$ac_config_commands default"
+
+cat >confcache <<\_ACEOF
+# This file is a shell script that caches the results of configure
+# tests run on this system so they can be shared between configure
+# scripts and configure runs, see configure's option --config-cache.
+# It is not useful on other systems.  If it contains results you don't
+# want to keep, you may remove or edit it.
+#
+# config.status only pays attention to the cache file if you give it
+# the --recheck option to rerun configure.
+#
+# `ac_cv_env_foo' variables (set or unset) will be overridden when
+# loading this file, other *unset* `ac_cv_foo' will be assigned the
+# following values.
+
+_ACEOF
+
+# The following way of writing the cache mishandles newlines in values,
+# but we know of no workaround that is simple, portable, and efficient.
+# So, we kill variables containing newlines.
+# Ultrix sh set writes to stderr and can't be redirected directly,
+# and sets the high bit in the cache file unless we assign to the vars.
+(
+  for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do
+    eval ac_val=\$$ac_var
+    case $ac_val in #(
+    *${as_nl}*)
+      case $ac_var in #(
+      *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
+$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
+      esac
+      case $ac_var in #(
+      _ | IFS | as_nl) ;; #(
+      BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
+      *) { eval $ac_var=; unset $ac_var;} ;;
+      esac ;;
+    esac
+  done
+
+  (set) 2>&1 |
+    case $as_nl`(ac_space=' '; set) 2>&1` in #(
+    *${as_nl}ac_space=\ *)
+      # `set' does not quote correctly, so add quotes: double-quote
+      # substitution turns \\\\ into \\, and sed turns \\ into \.
+      sed -n \
+	"s/'/'\\\\''/g;
+	  s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p"
+      ;; #(
+    *)
+      # `set' quotes correctly as required by POSIX, so do not add quotes.
+      sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"
+      ;;
+    esac |
+    sort
+) |
+  sed '
+     /^ac_cv_env_/b end
+     t clear
+     :clear
+     s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/
+     t end
+     s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/
+     :end' >>confcache
+if diff "$cache_file" confcache >/dev/null 2>&1; then :; else
+  if test -w "$cache_file"; then
+    if test "x$cache_file" != "x/dev/null"; then
+      { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5
+$as_echo "$as_me: updating cache $cache_file" >&6;}
+      if test ! -f "$cache_file" || test -h "$cache_file"; then
+	cat confcache >"$cache_file"
+      else
+        case $cache_file in #(
+        */* | ?:*)
+	  mv -f confcache "$cache_file"$$ &&
+	  mv -f "$cache_file"$$ "$cache_file" ;; #(
+        *)
+	  mv -f confcache "$cache_file" ;;
+	esac
+      fi
+    fi
+  else
+    { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5
+$as_echo "$as_me: not updating unwritable cache $cache_file" >&6;}
+  fi
+fi
+rm -f confcache
+
+test "x$prefix" = xNONE && prefix=$ac_default_prefix
+# Let make expand exec_prefix.
+test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
+
+# Transform confdefs.h into DEFS.
+# Protect against shell expansion while executing Makefile rules.
+# Protect against Makefile macro expansion.
+#
+# If the first sed substitution is executed (which looks for macros that
+# take arguments), then branch to the quote section.  Otherwise,
+# look for a macro that doesn't take arguments.
+ac_script='
+:mline
+/\\$/{
+ N
+ s,\\\n,,
+ b mline
+}
+t clear
+:clear
+s/^[	 ]*#[	 ]*define[	 ][	 ]*\([^	 (][^	 (]*([^)]*)\)[	 ]*\(.*\)/-D\1=\2/g
+t quote
+s/^[	 ]*#[	 ]*define[	 ][	 ]*\([^	 ][^	 ]*\)[	 ]*\(.*\)/-D\1=\2/g
+t quote
+b any
+:quote
+s/[	 `~#$^&*(){}\\|;'\''"<>?]/\\&/g
+s/\[/\\&/g
+s/\]/\\&/g
+s/\$/$$/g
+H
+:any
+${
+	g
+	s/^\n//
+	s/\n/ /g
+	p
+}
+'
+DEFS=`sed -n "$ac_script" confdefs.h`
+
+
+ac_libobjs=
+ac_ltlibobjs=
+U=
+for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue
+  # 1. Remove the extension, and $U if already installed.
+  ac_script='s/\$U\././;s/\.o$//;s/\.obj$//'
+  ac_i=`$as_echo "$ac_i" | sed "$ac_script"`
+  # 2. Prepend LIBOBJDIR.  When used with automake>=1.10 LIBOBJDIR
+  #    will be set to the directory where LIBOBJS objects are built.
+  as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext"
+  as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo'
+done
+LIBOBJS=$ac_libobjs
+
+LTLIBOBJS=$ac_ltlibobjs
+
+
+
+: "${CONFIG_STATUS=./config.status}"
+ac_write_fail=0
+ac_clean_files_save=$ac_clean_files
+ac_clean_files="$ac_clean_files $CONFIG_STATUS"
+{ $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5
+$as_echo "$as_me: creating $CONFIG_STATUS" >&6;}
+as_write_fail=0
+cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1
+#! $SHELL
+# Generated by $as_me.
+# Run this file to recreate the current configuration.
+# Compiler output produced by configure, useful for debugging
+# configure, is in config.log if it exists.
+
+debug=false
+ac_cs_recheck=false
+ac_cs_silent=false
+
+SHELL=\${CONFIG_SHELL-$SHELL}
+export SHELL
+_ASEOF
+cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1
+## -------------------- ##
+## M4sh Initialization. ##
+## -------------------- ##
+
+# Be more Bourne compatible
+DUALCASE=1; export DUALCASE # for MKS sh
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
+  emulate sh
+  NULLCMD=:
+  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+  setopt NO_GLOB_SUBST
+else
+  case `(set -o) 2>/dev/null` in #(
+  *posix*) :
+    set -o posix ;; #(
+  *) :
+     ;;
+esac
+fi
+
+
+as_nl='
+'
+export as_nl
+# Printing a long string crashes Solaris 7 /usr/bin/printf.
+as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
+as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
+# Prefer a ksh shell builtin over an external printf program on Solaris,
+# but without wasting forks for bash or zsh.
+if test -z "$BASH_VERSION$ZSH_VERSION" \
+    && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='print -r --'
+  as_echo_n='print -rn --'
+elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='printf %s\n'
+  as_echo_n='printf %s'
+else
+  if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
+    as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"'
+    as_echo_n='/usr/ucb/echo -n'
+  else
+    as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
+    as_echo_n_body='eval
+      arg=$1;
+      case $arg in #(
+      *"$as_nl"*)
+	expr "X$arg" : "X\\(.*\\)$as_nl";
+	arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
+      esac;
+      expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
+    '
+    export as_echo_n_body
+    as_echo_n='sh -c $as_echo_n_body as_echo'
+  fi
+  export as_echo_body
+  as_echo='sh -c $as_echo_body as_echo'
+fi
+
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+  PATH_SEPARATOR=:
+  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
+    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
+      PATH_SEPARATOR=';'
+  }
+fi
+
+
+# IFS
+# We need space, tab and new line, in precisely that order.  Quoting is
+# there to prevent editors from complaining about space-tab.
+# (If _AS_PATH_WALK were called with IFS unset, it would disable word
+# splitting by setting IFS to empty value.)
+IFS=" ""	$as_nl"
+
+# Find who we are.  Look in the path if we contain no directory separator.
+as_myself=
+case $0 in #((
+  *[\\/]* ) as_myself=$0 ;;
+  *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+  done
+IFS=$as_save_IFS
+
+     ;;
+esac
+# We did not find ourselves, most probably we were run as `sh COMMAND'
+# in which case we are not to be found in the path.
+if test "x$as_myself" = x; then
+  as_myself=$0
+fi
+if test ! -f "$as_myself"; then
+  $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
+  exit 1
+fi
+
+# Unset variables that we do not need and which cause bugs (e.g. in
+# pre-3.0 UWIN ksh).  But do not cause bugs in bash 2.01; the "|| exit 1"
+# suppresses any "Segmentation fault" message there.  '((' could
+# trigger a bug in pdksh 5.2.14.
+for as_var in BASH_ENV ENV MAIL MAILPATH
+do eval test x\${$as_var+set} = xset \
+  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
+done
+PS1='$ '
+PS2='> '
+PS4='+ '
+
+# NLS nuisances.
+LC_ALL=C
+export LC_ALL
+LANGUAGE=C
+export LANGUAGE
+
+# CDPATH.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+
+# as_fn_error STATUS ERROR [LINENO LOG_FD]
+# ----------------------------------------
+# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
+# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
+# script with STATUS, using 1 if that was 0.
+as_fn_error ()
+{
+  as_status=$1; test $as_status -eq 0 && as_status=1
+  if test "$4"; then
+    as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+    $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
+  fi
+  $as_echo "$as_me: error: $2" >&2
+  as_fn_exit $as_status
+} # as_fn_error
+
+
+# as_fn_set_status STATUS
+# -----------------------
+# Set $? to STATUS, without forking.
+as_fn_set_status ()
+{
+  return $1
+} # as_fn_set_status
+
+# as_fn_exit STATUS
+# -----------------
+# Exit the shell with STATUS, even in a "trap 0" or "set -e" context.
+as_fn_exit ()
+{
+  set +e
+  as_fn_set_status $1
+  exit $1
+} # as_fn_exit
+
+# as_fn_unset VAR
+# ---------------
+# Portably unset VAR.
+as_fn_unset ()
+{
+  { eval $1=; unset $1;}
+}
+as_unset=as_fn_unset
+# as_fn_append VAR VALUE
+# ----------------------
+# Append the text in VALUE to the end of the definition contained in VAR. Take
+# advantage of any shell optimizations that allow amortized linear growth over
+# repeated appends, instead of the typical quadratic growth present in naive
+# implementations.
+if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then :
+  eval 'as_fn_append ()
+  {
+    eval $1+=\$2
+  }'
+else
+  as_fn_append ()
+  {
+    eval $1=\$$1\$2
+  }
+fi # as_fn_append
+
+# as_fn_arith ARG...
+# ------------------
+# Perform arithmetic evaluation on the ARGs, and store the result in the
+# global $as_val. Take advantage of shells that can avoid forks. The arguments
+# must be portable across $(()) and expr.
+if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
+  eval 'as_fn_arith ()
+  {
+    as_val=$(( $* ))
+  }'
+else
+  as_fn_arith ()
+  {
+    as_val=`expr "$@" || test $? -eq 1`
+  }
+fi # as_fn_arith
+
+
+if expr a : '\(a\)' >/dev/null 2>&1 &&
+   test "X`expr 00001 : '.*\(...\)'`" = X001; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then
+  as_basename=basename
+else
+  as_basename=false
+fi
+
+if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
+  as_dirname=dirname
+else
+  as_dirname=false
+fi
+
+as_me=`$as_basename -- "$0" ||
+$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
+	 X"$0" : 'X\(//\)$' \| \
+	 X"$0" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X/"$0" |
+    sed '/^.*\/\([^/][^/]*\)\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\/\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\/\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+ECHO_C= ECHO_N= ECHO_T=
+case `echo -n x` in #(((((
+-n*)
+  case `echo 'xy\c'` in
+  *c*) ECHO_T='	';;	# ECHO_T is single tab character.
+  xy)  ECHO_C='\c';;
+  *)   echo `echo ksh88 bug on AIX 6.1` > /dev/null
+       ECHO_T='	';;
+  esac;;
+*)
+  ECHO_N='-n';;
+esac
+
+rm -f conf$$ conf$$.exe conf$$.file
+if test -d conf$$.dir; then
+  rm -f conf$$.dir/conf$$.file
+else
+  rm -f conf$$.dir
+  mkdir conf$$.dir 2>/dev/null
+fi
+if (echo >conf$$.file) 2>/dev/null; then
+  if ln -s conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s='ln -s'
+    # ... but there are two gotchas:
+    # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
+    # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
+    # In both cases, we have to default to `cp -pR'.
+    ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
+      as_ln_s='cp -pR'
+  elif ln conf$$.file conf$$ 2>/dev/null; then
+    as_ln_s=ln
+  else
+    as_ln_s='cp -pR'
+  fi
+else
+  as_ln_s='cp -pR'
+fi
+rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
+rmdir conf$$.dir 2>/dev/null
+
+
+# as_fn_mkdir_p
+# -------------
+# Create "$as_dir" as a directory, including parents if necessary.
+as_fn_mkdir_p ()
+{
+
+  case $as_dir in #(
+  -*) as_dir=./$as_dir;;
+  esac
+  test -d "$as_dir" || eval $as_mkdir_p || {
+    as_dirs=
+    while :; do
+      case $as_dir in #(
+      *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
+      *) as_qdir=$as_dir;;
+      esac
+      as_dirs="'$as_qdir' $as_dirs"
+      as_dir=`$as_dirname -- "$as_dir" ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$as_dir" : 'X\(//\)[^/]' \| \
+	 X"$as_dir" : 'X\(//\)$' \| \
+	 X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$as_dir" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+      test -d "$as_dir" && break
+    done
+    test -z "$as_dirs" || eval "mkdir $as_dirs"
+  } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir"
+
+
+} # as_fn_mkdir_p
+if mkdir -p . 2>/dev/null; then
+  as_mkdir_p='mkdir -p "$as_dir"'
+else
+  test -d ./-p && rmdir ./-p
+  as_mkdir_p=false
+fi
+
+
+# as_fn_executable_p FILE
+# -----------------------
+# Test if FILE is an executable regular file.
+as_fn_executable_p ()
+{
+  test -f "$1" && test -x "$1"
+} # as_fn_executable_p
+as_test_x='test -x'
+as_executable_p=as_fn_executable_p
+
+# Sed expression to map a string onto a valid CPP name.
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
+
+# Sed expression to map a string onto a valid variable name.
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
+
+
+exec 6>&1
+## ----------------------------------- ##
+## Main body of $CONFIG_STATUS script. ##
+## ----------------------------------- ##
+_ASEOF
+test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+# Save the log message, to keep $0 and so on meaningful, and to
+# report actual input values of CONFIG_FILES etc. instead of their
+# values after options handling.
+ac_log="
+This file was extended by $as_me, which was
+generated by GNU Autoconf 2.69.  Invocation command line was
+
+  CONFIG_FILES    = $CONFIG_FILES
+  CONFIG_HEADERS  = $CONFIG_HEADERS
+  CONFIG_LINKS    = $CONFIG_LINKS
+  CONFIG_COMMANDS = $CONFIG_COMMANDS
+  $ $0 $@
+
+on `(hostname || uname -n) 2>/dev/null | sed 1q`
+"
+
+_ACEOF
+
+case $ac_config_files in *"
+"*) set x $ac_config_files; shift; ac_config_files=$*;;
+esac
+
+
+
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+# Files that config.status was made for.
+config_files="$ac_config_files"
+config_commands="$ac_config_commands"
+
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+ac_cs_usage="\
+\`$as_me' instantiates files and other configuration actions
+from templates according to the current configuration.  Unless the files
+and actions are specified as TAGs, all are instantiated by default.
+
+Usage: $0 [OPTION]... [TAG]...
+
+  -h, --help       print this help, then exit
+  -V, --version    print version number and configuration settings, then exit
+      --config     print configuration, then exit
+  -q, --quiet, --silent
+                   do not print progress messages
+  -d, --debug      don't remove temporary files
+      --recheck    update $as_me by reconfiguring in the same conditions
+      --file=FILE[:TEMPLATE]
+                   instantiate the configuration file FILE
+
+Configuration files:
+$config_files
+
+Configuration commands:
+$config_commands
+
+Report bugs to the package provider."
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
+ac_cs_version="\\
+config.status
+configured by $0, generated by GNU Autoconf 2.69,
+  with options \\"\$ac_cs_config\\"
+
+Copyright (C) 2012 Free Software Foundation, Inc.
+This config.status script is free software; the Free Software Foundation
+gives unlimited permission to copy, distribute and modify it."
+
+ac_pwd='$ac_pwd'
+srcdir='$srcdir'
+test -n "\$AWK" || AWK=awk
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+# The default lists apply if the user does not specify any file.
+ac_need_defaults=:
+while test $# != 0
+do
+  case $1 in
+  --*=?*)
+    ac_option=`expr "X$1" : 'X\([^=]*\)='`
+    ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'`
+    ac_shift=:
+    ;;
+  --*=)
+    ac_option=`expr "X$1" : 'X\([^=]*\)='`
+    ac_optarg=
+    ac_shift=:
+    ;;
+  *)
+    ac_option=$1
+    ac_optarg=$2
+    ac_shift=shift
+    ;;
+  esac
+
+  case $ac_option in
+  # Handling of the options.
+  -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
+    ac_cs_recheck=: ;;
+  --version | --versio | --versi | --vers | --ver | --ve | --v | -V )
+    $as_echo "$ac_cs_version"; exit ;;
+  --config | --confi | --conf | --con | --co | --c )
+    $as_echo "$ac_cs_config"; exit ;;
+  --debug | --debu | --deb | --de | --d | -d )
+    debug=: ;;
+  --file | --fil | --fi | --f )
+    $ac_shift
+    case $ac_optarg in
+    *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;
+    '') as_fn_error $? "missing file argument" ;;
+    esac
+    as_fn_append CONFIG_FILES " '$ac_optarg'"
+    ac_need_defaults=false;;
+  --he | --h |  --help | --hel | -h )
+    $as_echo "$ac_cs_usage"; exit ;;
+  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+  | -silent | --silent | --silen | --sile | --sil | --si | --s)
+    ac_cs_silent=: ;;
+
+  # This is an error.
+  -*) as_fn_error $? "unrecognized option: \`$1'
+Try \`$0 --help' for more information." ;;
+
+  *) as_fn_append ac_config_targets " $1"
+     ac_need_defaults=false ;;
+
+  esac
+  shift
+done
+
+ac_configure_extra_args=
+
+if $ac_cs_silent; then
+  exec 6>/dev/null
+  ac_configure_extra_args="$ac_configure_extra_args --silent"
+fi
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+if \$ac_cs_recheck; then
+  set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
+  shift
+  \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6
+  CONFIG_SHELL='$SHELL'
+  export CONFIG_SHELL
+  exec "\$@"
+fi
+
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+exec 5>>config.log
+{
+  echo
+  sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
+## Running $as_me. ##
+_ASBOX
+  $as_echo "$ac_log"
+} >&5
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+
+# Handling of arguments.
+for ac_config_target in $ac_config_targets
+do
+  case $ac_config_target in
+    "$MAKEFILES") CONFIG_FILES="$CONFIG_FILES $MAKEFILES" ;;
+    "default") CONFIG_COMMANDS="$CONFIG_COMMANDS default" ;;
+
+  *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
+  esac
+done
+
+
+# If the user did not use the arguments to specify the items to instantiate,
+# then the envvar interface is used.  Set only those that are not.
+# We use the long form for the default assignment because of an extremely
+# bizarre bug on SunOS 4.1.3.
+if $ac_need_defaults; then
+  test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files
+  test "${CONFIG_COMMANDS+set}" = set || CONFIG_COMMANDS=$config_commands
+fi
+
+# Have a temporary directory for convenience.  Make it in the build tree
+# simply because there is no reason against having it here, and in addition,
+# creating and moving files from /tmp can sometimes cause problems.
+# Hook for its removal unless debugging.
+# Note that there is a small window in which the directory will not be cleaned:
+# after its creation but before its name has been assigned to `$tmp'.
+$debug ||
+{
+  tmp= ac_tmp=
+  trap 'exit_status=$?
+  : "${ac_tmp:=$tmp}"
+  { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status
+' 0
+  trap 'as_fn_exit 1' 1 2 13 15
+}
+# Create a (secure) tmp directory for tmp files.
+
+{
+  tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` &&
+  test -d "$tmp"
+}  ||
+{
+  tmp=./conf$$-$RANDOM
+  (umask 077 && mkdir "$tmp")
+} || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5
+ac_tmp=$tmp
+
+# Set up the scripts for CONFIG_FILES section.
+# No need to generate them if there are no CONFIG_FILES.
+# This happens for instance with `./config.status config.h'.
+if test -n "$CONFIG_FILES"; then
+
+
+ac_cr=`echo X | tr X '\015'`
+# On cygwin, bash can eat \r inside `` if the user requested igncr.
+# But we know of no other shell where ac_cr would be empty at this
+# point, so we can use a bashism as a fallback.
+if test "x$ac_cr" = x; then
+  eval ac_cr=\$\'\\r\'
+fi
+ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' </dev/null 2>/dev/null`
+if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then
+  ac_cs_awk_cr='\\r'
+else
+  ac_cs_awk_cr=$ac_cr
+fi
+
+echo 'BEGIN {' >"$ac_tmp/subs1.awk" &&
+_ACEOF
+
+
+{
+  echo "cat >conf$$subs.awk <<_ACEOF" &&
+  echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' &&
+  echo "_ACEOF"
+} >conf$$subs.sh ||
+  as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
+ac_delim_num=`echo "$ac_subst_vars" | grep -c '^'`
+ac_delim='%!_!# '
+for ac_last_try in false false false false false :; do
+  . ./conf$$subs.sh ||
+    as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
+
+  ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X`
+  if test $ac_delim_n = $ac_delim_num; then
+    break
+  elif $ac_last_try; then
+    as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
+  else
+    ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
+  fi
+done
+rm -f conf$$subs.sh
+
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+cat >>"\$ac_tmp/subs1.awk" <<\\_ACAWK &&
+_ACEOF
+sed -n '
+h
+s/^/S["/; s/!.*/"]=/
+p
+g
+s/^[^!]*!//
+:repl
+t repl
+s/'"$ac_delim"'$//
+t delim
+:nl
+h
+s/\(.\{148\}\)..*/\1/
+t more1
+s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/
+p
+n
+b repl
+:more1
+s/["\\]/\\&/g; s/^/"/; s/$/"\\/
+p
+g
+s/.\{148\}//
+t nl
+:delim
+h
+s/\(.\{148\}\)..*/\1/
+t more2
+s/["\\]/\\&/g; s/^/"/; s/$/"/
+p
+b
+:more2
+s/["\\]/\\&/g; s/^/"/; s/$/"\\/
+p
+g
+s/.\{148\}//
+t delim
+' <conf$$subs.awk | sed '
+/^[^""]/{
+  N
+  s/\n//
+}
+' >>$CONFIG_STATUS || ac_write_fail=1
+rm -f conf$$subs.awk
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+_ACAWK
+cat >>"\$ac_tmp/subs1.awk" <<_ACAWK &&
+  for (key in S) S_is_set[key] = 1
+  FS = ""
+
+}
+{
+  line = $ 0
+  nfields = split(line, field, "@")
+  substed = 0
+  len = length(field[1])
+  for (i = 2; i < nfields; i++) {
+    key = field[i]
+    keylen = length(key)
+    if (S_is_set[key]) {
+      value = S[key]
+      line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3)
+      len += length(value) + length(field[++i])
+      substed = 1
+    } else
+      len += 1 + keylen
+  }
+
+  print line
+}
+
+_ACAWK
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then
+  sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g"
+else
+  cat
+fi < "$ac_tmp/subs1.awk" > "$ac_tmp/subs.awk" \
+  || as_fn_error $? "could not setup config files machinery" "$LINENO" 5
+_ACEOF
+
+# VPATH may cause trouble with some makes, so we remove sole $(srcdir),
+# ${srcdir} and @srcdir@ entries from VPATH if srcdir is ".", strip leading and
+# trailing colons and then remove the whole line if VPATH becomes empty
+# (actually we leave an empty line to preserve line numbers).
+if test "x$srcdir" = x.; then
+  ac_vpsub='/^[	 ]*VPATH[	 ]*=[	 ]*/{
+h
+s///
+s/^/:/
+s/[	 ]*$/:/
+s/:\$(srcdir):/:/g
+s/:\${srcdir}:/:/g
+s/:@srcdir@:/:/g
+s/^:*//
+s/:*$//
+x
+s/\(=[	 ]*\).*/\1/
+G
+s/\n//
+s/^[^=]*=[	 ]*$//
+}'
+fi
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+fi # test -n "$CONFIG_FILES"
+
+
+eval set X "  :F $CONFIG_FILES      :C $CONFIG_COMMANDS"
+shift
+for ac_tag
+do
+  case $ac_tag in
+  :[FHLC]) ac_mode=$ac_tag; continue;;
+  esac
+  case $ac_mode$ac_tag in
+  :[FHL]*:*);;
+  :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;;
+  :[FH]-) ac_tag=-:-;;
+  :[FH]*) ac_tag=$ac_tag:$ac_tag.in;;
+  esac
+  ac_save_IFS=$IFS
+  IFS=:
+  set x $ac_tag
+  IFS=$ac_save_IFS
+  shift
+  ac_file=$1
+  shift
+
+  case $ac_mode in
+  :L) ac_source=$1;;
+  :[FH])
+    ac_file_inputs=
+    for ac_f
+    do
+      case $ac_f in
+      -) ac_f="$ac_tmp/stdin";;
+      *) # Look for the file first in the build tree, then in the source tree
+	 # (if the path is not absolute).  The absolute path cannot be DOS-style,
+	 # because $ac_f cannot contain `:'.
+	 test -f "$ac_f" ||
+	   case $ac_f in
+	   [\\/$]*) false;;
+	   *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";;
+	   esac ||
+	   as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;;
+      esac
+      case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac
+      as_fn_append ac_file_inputs " '$ac_f'"
+    done
+
+    # Let's still pretend it is `configure' which instantiates (i.e., don't
+    # use $as_me), people would be surprised to read:
+    #    /* config.h.  Generated by config.status.  */
+    configure_input='Generated from '`
+	  $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g'
+	`' by configure.'
+    if test x"$ac_file" != x-; then
+      configure_input="$ac_file.  $configure_input"
+      { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5
+$as_echo "$as_me: creating $ac_file" >&6;}
+    fi
+    # Neutralize special characters interpreted by sed in replacement strings.
+    case $configure_input in #(
+    *\&* | *\|* | *\\* )
+       ac_sed_conf_input=`$as_echo "$configure_input" |
+       sed 's/[\\\\&|]/\\\\&/g'`;; #(
+    *) ac_sed_conf_input=$configure_input;;
+    esac
+
+    case $ac_tag in
+    *:-:* | *:-) cat >"$ac_tmp/stdin" \
+      || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;;
+    esac
+    ;;
+  esac
+
+  ac_dir=`$as_dirname -- "$ac_file" ||
+$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$ac_file" : 'X\(//\)[^/]' \| \
+	 X"$ac_file" : 'X\(//\)$' \| \
+	 X"$ac_file" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$ac_file" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+  as_dir="$ac_dir"; as_fn_mkdir_p
+  ac_builddir=.
+
+case "$ac_dir" in
+.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
+*)
+  ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'`
+  # A ".." for each directory in $ac_dir_suffix.
+  ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
+  case $ac_top_builddir_sub in
+  "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
+  *)  ac_top_build_prefix=$ac_top_builddir_sub/ ;;
+  esac ;;
+esac
+ac_abs_top_builddir=$ac_pwd
+ac_abs_builddir=$ac_pwd$ac_dir_suffix
+# for backward compatibility:
+ac_top_builddir=$ac_top_build_prefix
+
+case $srcdir in
+  .)  # We are building in place.
+    ac_srcdir=.
+    ac_top_srcdir=$ac_top_builddir_sub
+    ac_abs_top_srcdir=$ac_pwd ;;
+  [\\/]* | ?:[\\/]* )  # Absolute name.
+    ac_srcdir=$srcdir$ac_dir_suffix;
+    ac_top_srcdir=$srcdir
+    ac_abs_top_srcdir=$srcdir ;;
+  *) # Relative name.
+    ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix
+    ac_top_srcdir=$ac_top_build_prefix$srcdir
+    ac_abs_top_srcdir=$ac_pwd/$srcdir ;;
+esac
+ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix
+
+
+  case $ac_mode in
+  :F)
+  #
+  # CONFIG_FILE
+  #
+
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+# If the template does not know about datarootdir, expand it.
+# FIXME: This hack should be removed a few years after 2.60.
+ac_datarootdir_hack=; ac_datarootdir_seen=
+ac_sed_dataroot='
+/datarootdir/ {
+  p
+  q
+}
+/@datadir@/p
+/@docdir@/p
+/@infodir@/p
+/@localedir@/p
+/@mandir@/p'
+case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in
+*datarootdir*) ac_datarootdir_seen=yes;;
+*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*)
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5
+$as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;}
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+  ac_datarootdir_hack='
+  s&@datadir@&$datadir&g
+  s&@docdir@&$docdir&g
+  s&@infodir@&$infodir&g
+  s&@localedir@&$localedir&g
+  s&@mandir@&$mandir&g
+  s&\\\${datarootdir}&$datarootdir&g' ;;
+esac
+_ACEOF
+
+# Neutralize VPATH when `$srcdir' = `.'.
+# Shell code in configure.ac might set extrasub.
+# FIXME: do we really want to maintain this feature?
+cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
+ac_sed_extra="$ac_vpsub
+$extrasub
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+:t
+/@[a-zA-Z_][a-zA-Z_0-9]*@/!b
+s|@configure_input@|$ac_sed_conf_input|;t t
+s&@top_builddir@&$ac_top_builddir_sub&;t t
+s&@top_build_prefix@&$ac_top_build_prefix&;t t
+s&@srcdir@&$ac_srcdir&;t t
+s&@abs_srcdir@&$ac_abs_srcdir&;t t
+s&@top_srcdir@&$ac_top_srcdir&;t t
+s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t
+s&@builddir@&$ac_builddir&;t t
+s&@abs_builddir@&$ac_abs_builddir&;t t
+s&@abs_top_builddir@&$ac_abs_top_builddir&;t t
+$ac_datarootdir_hack
+"
+eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \
+  >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5
+
+test -z "$ac_datarootdir_hack$ac_datarootdir_seen" &&
+  { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } &&
+  { ac_out=`sed -n '/^[	 ]*datarootdir[	 ]*:*=/p' \
+      "$ac_tmp/out"`; test -z "$ac_out"; } &&
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir'
+which seems to be undefined.  Please make sure it is defined" >&5
+$as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir'
+which seems to be undefined.  Please make sure it is defined" >&2;}
+
+  rm -f "$ac_tmp/stdin"
+  case $ac_file in
+  -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";;
+  *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";;
+  esac \
+  || as_fn_error $? "could not create $ac_file" "$LINENO" 5
+ ;;
+
+
+  :C)  { $as_echo "$as_me:${as_lineno-$LINENO}: executing $ac_file commands" >&5
+$as_echo "$as_me: executing $ac_file commands" >&6;}
+ ;;
+  esac
+
+
+  case $ac_file$ac_mode in
+    "default":C) chmod +x config/nspr-config ;;
+
+  esac
+done # for ac_tag
+
+
+as_fn_exit 0
+_ACEOF
+ac_clean_files=$ac_clean_files_save
+
+test $ac_write_fail = 0 ||
+  as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5
+
+
+# configure is writing to config.log, and then calls config.status.
+# config.status does its own redirection, appending to config.log.
+# Unfortunately, on DOS this fails, as config.log is still kept open
+# by configure, so config.status won't be able to write to it; its
+# output is simply discarded.  So we exec the FD to /dev/null,
+# effectively closing config.log, so it can be properly (re)opened and
+# appended to by config.status.  When coming back to configure, we
+# need to make the FD available again.
+if test "$no_create" != yes; then
+  ac_cs_success=:
+  ac_config_status_args=
+  test "$silent" = yes &&
+    ac_config_status_args="$ac_config_status_args --quiet"
+  exec 5>/dev/null
+  $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false
+  exec 5>>config.log
+  # Use ||, not &&, to avoid exiting from the if with $? = 1, which
+  # would make configure fail if this is the last instruction.
+  $ac_cs_success || as_fn_exit 1
+fi
+if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5
+$as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;}
+fi
+
diff --git a/configure.in b/configure.in
new file mode 100644
index 0000000..202158b
--- /dev/null
+++ b/configure.in
@@ -0,0 +1,3176 @@
+dnl -*- Mode: Autoconf; tab-width: 4; indent-tabs-mode: nil; -*-
+dnl 
+dnl This Source Code Form is subject to the terms of the Mozilla Public
+dnl License, v. 2.0. If a copy of the MPL was not distributed with this
+dnl file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+AC_PREREQ(2.61)
+AC_INIT
+AC_CONFIG_SRCDIR([pr/include/nspr.h])
+
+AC_CONFIG_AUX_DIR(${srcdir}/build/autoconf)
+AC_CANONICAL_TARGET
+
+dnl ========================================================
+dnl = Defaults
+dnl ========================================================
+MOD_MAJOR_VERSION=4
+MOD_MINOR_VERSION=13
+MOD_PATCH_VERSION=1
+NSPR_MODNAME=nspr20
+_HAVE_PTHREADS=
+USE_PTHREADS=
+USE_USER_PTHREADS=
+USE_NSPR_THREADS=
+USE_N32=
+USE_X32=
+USE_64=
+USE_CPLUS=
+USE_IPV6=
+USE_MDUPDATE=
+_MACOSX_DEPLOYMENT_TARGET=
+_OPTIMIZE_FLAGS=-O
+_DEBUG_FLAGS=-g
+MOZ_DEBUG=1
+MOZ_OPTIMIZE=
+OBJDIR='$(OBJDIR_NAME)'
+OBJDIR_NAME=.
+OBJDIR_SUFFIX=OBJ
+NSINSTALL='$(MOD_DEPTH)/config/$(OBJDIR_NAME)/nsinstall'
+NOSUCHFILE=/no-such-file
+LIBNSPR='-L$(dist_libdir) -lnspr$(MOD_MAJOR_VERSION)'
+LIBPLC='-L$(dist_libdir) -lplc$(MOD_MAJOR_VERSION)'
+CYGWIN_WRAPPER=
+MACOS_SDK_DIR=
+NEXT_ROOT=
+MT=
+MOZ_OS2_HIGH_MEMORY=1
+PROFILE_GEN_CFLAGS=
+PROFILE_GEN_LDFLAGS=
+PROFILE_USE_CFLAGS=
+PROFILE_USE_LDFLAGS=
+
+dnl Link in libraries necessary to resolve all symbols for shared libs
+RESOLVE_LINK_SYMBOLS=
+
+dnl ========================================================
+dnl =
+dnl = Dont change the following lines.  Doing so breaks:
+dnl =
+dnl = CFLAGS="-foo" ./configure
+dnl =
+dnl ========================================================
+CFLAGS="${CFLAGS=}"
+CXXFLAGS="${CXXFLAGS=}"
+LDFLAGS="${LDFLAGS=}"
+DLLFLAGS="${DLLFLAGS=}"
+HOST_CFLAGS="${HOST_CFLAGS=}"
+HOST_LDFLAGS="${HOST_LDFLAGS=}"
+
+case "$target" in
+*-cygwin*|*-mingw*|*-msys*)
+    # Check to see if we are really running in a msvc environemnt
+    _WIN32_MSVC=
+    AC_CHECK_PROGS(CC, cl)
+    cat > conftest.c <<EOF
+#ifdef _MSC_VER
+COMPILER IS MSVC
+#endif
+EOF
+    read dummy <<EOF
+$($CC -E conftest.c 2>/dev/null | grep COMPILER)
+EOF
+    if test -n "$dummy"; then
+        _WIN32_MSVC=1
+        CXX=$CC
+    fi
+    rm -f conftest.c
+    ;;
+*-mks*)
+    _WIN32_MSVC=1
+    ;;
+esac
+
+if test -n "$_WIN32_MSVC"; then
+    SKIP_PATH_CHECKS=1
+    SKIP_COMPILER_CHECKS=1
+    SKIP_LIBRARY_CHECKS=1
+fi
+
+dnl ========================================================
+dnl = Android uses a very custom (hacky) toolchain; we need to do this
+dnl = here, so that the compiler checks can succeed
+dnl ========================================================
+
+AC_ARG_WITH(android-ndk,
+[  --with-android-ndk=DIR
+                          location where the Android NDK can be found],
+    android_ndk=$withval)
+
+AC_ARG_WITH(android-toolchain,
+[  --with-android-toolchain=DIR
+                          location of the Android toolchain],
+    android_toolchain=$withval)
+
+dnl The default android_version is different for each target cpu.
+case "$target_cpu" in
+arm)
+    android_version=5
+    ;;
+i?86|mipsel)
+    android_version=9
+    ;;
+esac
+
+AC_ARG_WITH(android-version,
+[  --with-android-version=VER
+                          Android platform version, default 5 for arm, 9 for x86/mips],
+    android_version=$withval)
+
+AC_ARG_WITH(android-platform,
+[  --with-android-platform=DIR
+                          location of platform dir],
+    android_platform=$withval)
+
+case "$target" in
+arm-linux*-android*|*-linuxandroid*)
+    android_tool_prefix="arm-linux-androideabi"
+    ;;
+i?86-*android*)
+    android_tool_prefix="i686-linux-android"
+    ;;
+mipsel-*android*)
+    android_tool_prefix="mipsel-linux-android"
+    ;;
+*)
+    android_tool_prefix="$target_os"
+    ;;
+esac
+
+dnl ========================================================
+dnl = Gonk is a fork of Android used for Mozilla's B2G project.
+dnl = Configuration is done largely by the top level config
+dnl = and the specified gonk directory doesn't matter here.
+dnl ========================================================
+
+AC_ARG_WITH(gonk,
+[  --with-gonk=DIR         location of gonk dir],
+    gonkdir=$withval)
+
+if test -n "$gonkdir" ; then
+    dnl Most things are directly configured by env vars when building for gonk
+
+    AC_DEFINE(ANDROID)
+else
+case "$target" in
+*-android*|*-linuxandroid*)
+    if test -z "$android_ndk" ; then
+       AC_MSG_ERROR([You must specify --with-android-ndk=/path/to/ndk when targeting Android.])
+    fi
+
+    if test -z "$android_toolchain" ; then
+        AC_MSG_CHECKING([for android toolchain directory])
+
+        kernel_name=`uname -s | tr "[[:upper:]]" "[[:lower:]]"`
+
+        case "$target_cpu" in
+        arm)
+            target_name=arm-linux-androideabi-4.4.3
+            ;;
+        i?86)
+            target_name=x86-4.4.3
+            ;;
+        mipsel)
+            target_name=mipsel-linux-android-4.4.3
+            ;;
+        esac
+        android_toolchain="$android_ndk"/toolchains/$target_name/prebuilt/$kernel_name-x86
+
+        if test -d "$android_toolchain" ; then
+            AC_MSG_RESULT([$android_toolchain])
+        else
+            AC_MSG_ERROR([not found. You have to specify --with-android-toolchain=/path/to/ndk/toolchain.])
+        fi
+    fi
+
+    if test -z "$android_platform" ; then
+        AC_MSG_CHECKING([for android platform directory])
+
+        case "$target_cpu" in
+        arm)
+            target_name=arm
+            ;;
+        i?86)
+            target_name=x86
+            ;;
+        mipsel)
+            target_name=mips
+            ;;
+        esac
+
+        android_platform="$android_ndk"/platforms/android-"$android_version"/arch-"$target_name"
+
+        if test -d "$android_platform" ; then
+            AC_MSG_RESULT([$android_platform])
+        else
+            AC_MSG_ERROR([not found. You have to specify --with-android-platform=/path/to/ndk/platform.])
+        fi
+    fi
+
+    dnl Old NDK support. If minimum requirement is changed to NDK r8b,
+    dnl please remove this.
+    case "$target_cpu" in
+    i?86)
+        if ! test -e "$android_toolchain"/bin/"$android_tool_prefix"-gcc; then
+            dnl Old NDK toolchain name
+            android_tool_prefix="i686-android-linux"
+        fi
+        ;;
+    esac
+
+    dnl set up compilers
+    AS="$android_toolchain"/bin/"$android_tool_prefix"-as
+    CC="$android_toolchain"/bin/"$android_tool_prefix"-gcc
+    CXX="$android_toolchain"/bin/"$android_tool_prefix"-g++
+    CPP="$android_toolchain"/bin/"$android_tool_prefix"-cpp
+    LD="$android_toolchain"/bin/"$android_tool_prefix"-ld
+    AR="$android_toolchain"/bin/"$android_tool_prefix"-ar
+    RANLIB="$android_toolchain"/bin/"$android_tool_prefix"-ranlib
+    STRIP="$android_toolchain"/bin/"$android_tool_prefix"-strip
+
+    CPPFLAGS="-I$android_platform/usr/include $CPPFLAGS"
+    CFLAGS="-mandroid -I$android_platform/usr/include -fno-short-enums -fno-exceptions $CFLAGS"
+    CXXFLAGS="-mandroid -I$android_platform/usr/include -fpic -fno-short-enums -fno-exceptions $CXXFLAGS"
+    LDFLAGS="-mandroid -L$android_platform/usr/lib -Wl,-rpath-link=$android_platform/usr/lib --sysroot=$android_platform $LDFLAGS"
+
+    AC_DEFINE(ANDROID)
+    ;;
+esac
+fi
+
+dnl ========================================================
+dnl =
+dnl = Check options that may affect the compiler
+dnl =
+dnl ========================================================
+dist_prefix='${MOD_DEPTH}/dist'
+dist_bindir='${dist_prefix}/bin'
+dist_includedir='${dist_prefix}/include/nspr'
+dist_libdir='${dist_prefix}/lib'
+dnl If the --includedir option was not specified, add '/nspr' to autoconf's
+dnl default value of includedir.
+if test "${includedir}" = '${prefix}/include'; then
+    includedir='${prefix}/include/nspr'
+fi
+
+AC_ARG_WITH(dist-prefix,
+    [  --with-dist-prefix=DIST_PREFIX
+                          place build files in DIST_PREFIX [dist]],
+    dist_prefix=$withval)
+
+AC_ARG_WITH(dist-bindir,
+    [  --with-dist-bindir=DIR  build execuatables in DIR [DIST_PREFIX/bin]],
+    dist_bindir=$withval)
+
+AC_ARG_WITH(dist-includedir,
+    [  --with-dist-includedir=DIR
+                          build include files in DIR [DIST_PREFIX/include/nspr]],
+    dist_includedir=$withval)
+
+AC_ARG_WITH(dist-libdir,
+    [  --with-dist-libdir=DIR  build library files in DIR [DIST_PREFIX/lib]],
+    dist_libdir=$withval)
+
+AC_SUBST(dist_prefix)
+AC_SUBST(dist_bindir)
+AC_SUBST(dist_includedir)
+AC_SUBST(dist_libdir)
+
+dnl Check if NSPR is being compiled for Mozilla
+dnl Let --with-arg override environment setting
+dnl
+AC_ARG_WITH(mozilla,
+    [  --with-mozilla          Compile NSPR with Mozilla support],
+    [   if test "$withval" = "yes"; then
+            AC_DEFINE(MOZILLA_CLIENT)
+            MOZILLA_CLIENT=1
+	    else
+	        MOZILLA_CLIENT=
+	    fi],
+    [	if test -n "$MOZILLA_CLIENT"; then
+	        AC_DEFINE(MOZILLA_CLIENT)
+	    fi])
+
+AC_ARG_ENABLE(optimize,
+    [  --enable-optimize[=OPT] Enable code optimizations (ie. -O2) ],
+    [ if test "$enableval" != "no"; then
+          MOZ_OPTIMIZE=1
+          if test -n "$enableval" -a "$enableval" != "yes"; then
+            _OPTIMIZE_FLAGS=`echo $enableval | sed -e 's|\\\ | |g'`
+            _SAVE_OPTIMIZE_FLAGS=$_OPTIMIZE_FLAGS
+          fi
+      else
+          MOZ_OPTIMIZE=
+      fi ])
+
+AC_ARG_ENABLE(debug,
+    [  --enable-debug[=DBG]    Enable debugging (using compiler flags DBG)],
+    [ if test "$enableval" != "no"; then
+          MOZ_DEBUG=1
+          MOZ_DEBUG_SYMBOLS=1
+          if test -n "$enableval" -a "$enableval" != "yes"; then
+              _DEBUG_FLAGS=`echo $enableval | sed -e 's|\\\ | |g'`
+              _SAVE_DEBUG_FLAGS=$_DEBUG_FLAGS
+          fi
+      else
+          MOZ_DEBUG=
+      fi ],
+      MOZ_DEBUG_SYMBOLS=1)
+
+AC_ARG_ENABLE(debug-symbols,
+    [  --enable-debug-symbols[=DBG]    Enable debugging symbols
+                                       (using compiler flags DBG)],
+    [ if test "$enableval" != "no"; then
+          MOZ_DEBUG_SYMBOLS=1
+          if test -n "$enableval" -a "$enableval" != "yes"; then
+              if test -z "$_SAVE_DEBUG_FLAGS"; then
+                  _DEBUG_FLAGS=`echo $enableval | sed -e 's|\\\ | |g'`
+                  _SAVE_DEBUG_FLAGS=$_DEBUG_FLAGS
+              else
+                  AC_MSG_ERROR([--enable-debug-symbols flags cannot be used with --enable-debug flags])
+              fi
+          fi
+      else
+          MOZ_DEBUG_SYMBOLS=
+      fi ])
+
+AC_ARG_ENABLE(win32-target,
+    [  --enable-win32-target=\$t
+                          Specify win32 flavor. (WIN95 or WINNT)],
+    OS_TARGET=`echo $enableval | tr a-z A-Z`)
+
+AC_ARG_ENABLE(symbian-target,
+    [  --enable-symbian-target=\$t
+                          Specify symbian flavor. (WINSCW or GCCE)],
+    OS_TARGET=`echo $enableval | tr a-z A-Z`)
+
+AC_ARG_ENABLE(debug-rtl,
+    [  --enable-debug-rtl      Use the MSVC debug runtime library],
+    [ if test "$enableval" = "yes"; then
+	    USE_DEBUG_RTL=1
+      else
+	    USE_DEBUG_RTL=0
+      fi ])
+
+AC_ARG_ENABLE(static-rtl,
+    [  --enable-static-rtl     Use the MSVC static runtime library],
+    [ if test "$enableval" = "yes"; then
+	    USE_STATIC_RTL=1
+      fi ])
+
+AC_ARG_ENABLE(n32,
+    [  --enable-n32            Enable n32 ABI support (IRIX only)],
+    [ if test "$enableval" = "yes"; then
+	USE_N32=1
+      else if test "$enableval" = "no"; then
+	USE_N32=
+      fi
+    fi ])
+
+AC_ARG_ENABLE(x32,
+    [  --enable-x32            Enable x32 ABI support (x86_64 only)],
+    [ if test "$enableval" = "yes"; then
+        USE_X32=1
+      else if test "$enableval" = "no"; then
+        USE_X32=
+      fi
+    fi ])
+
+AC_ARG_ENABLE(64bit,
+    [  --enable-64bit          Enable 64-bit support (on certain platforms)],
+    [ if test "$enableval" = "yes"; then
+	    USE_64=1
+      fi ])
+
+AC_ARG_ENABLE(mdupdate,
+    [  --enable-mdupdate       Enable use of certain compilers' mdupdate feature],
+    [ if test "$enableval" = "yes"; then
+	    USE_MDUPDATE=1
+      fi ])
+
+AC_ARG_ENABLE(cplus,
+    [  --enable-cplus          Enable some c++ api routines],
+    [ if test "$enableval" = "yes"; then
+	    USE_CPLUS=1
+      fi]) 
+
+AC_ARG_WITH(arm-kuser,
+    [  --with-arm-kuser        Use kuser helpers (Linux/ARM only)
+                          (Requires kernel 2.6.13 or later)],
+    [ if test "$withval" = "yes"; then
+	    AC_DEFINE(_PR_ARM_KUSER)
+      fi ])
+
+dnl ========================================================
+dnl = Mac OS X SDK support
+dnl ========================================================
+AC_ARG_WITH(macos-sdk,
+    [  --with-macos-sdk=dir    Location of platform SDK to use (Mac OS X only)],
+    MACOS_SDK_DIR=$withval)
+
+AC_ARG_ENABLE(macos-target,
+             [  --enable-macos-target=VER
+                          Set the minimum MacOS version needed at runtime
+                          [10.2 for ppc, 10.4 for x86]],
+             [_MACOSX_DEPLOYMENT_TARGET=$enableval])
+
+dnl ========================================================
+dnl =
+dnl = Set the threading model
+dnl =
+dnl ========================================================
+case "$target" in
+
+*-aix*)
+    case "${target_os}" in
+    aix3.2*)
+        USE_NSPR_THREADS=1
+        ;;
+    *)
+        USE_PTHREADS=1
+        ;;
+    esac
+    ;;
+
+esac
+
+dnl ========================================================
+dnl =
+dnl = Set the default C compiler
+dnl =
+dnl ========================================================
+if test -z "$CC"; then
+    case "$target" in
+
+    *-aix*)
+        if test -z "$USE_NSPR_THREADS"; then
+            CC=xlc_r
+        else
+            CC=xlc
+        fi
+    ;;
+
+    *-hpux*)
+        CC=cc
+    ;;
+
+    *-irix*)
+        CC=cc
+    ;;
+
+    *-osf*)
+        CC=cc
+    ;;
+
+    *-solaris*)
+        CC=cc
+    ;;
+
+    esac
+fi
+
+dnl ========================================================
+dnl =
+dnl = Set the default C++ compiler
+dnl =
+dnl ========================================================
+if test -z "$CXX"; then
+    case "$target" in
+
+    *-aix*)
+        if test -z "$USE_NSPR_THREADS"; then
+            CXX=xlC_r
+        else
+            CXX=xlC
+        fi
+    ;;
+
+    *-hpux*)
+        case "${target_os}" in
+        hpux10.30)
+            CXX=aCC
+            ;;
+        hpux11.*)
+            CXX=aCC
+            ;;
+        *)
+            CXX=CC
+            ;;
+        esac
+    ;;
+
+    *-irix*)
+        CXX=CC
+    ;;
+
+    *-osf*)
+        CXX=cxx
+    ;;
+
+    *-solaris*)
+        CXX=CC
+    ;;
+
+    esac
+fi
+
+if test -z "$SKIP_PATH_CHECKS"; then
+    AC_PATH_PROG(WHOAMI, $WHOAMI whoami, echo not_whoami)
+fi
+
+if test -n "$MOZ_DEBUG"; then
+    AC_DEFINE(DEBUG)
+    DEFINES="$DEFINES -UNDEBUG"
+
+    case "${target_os}" in
+    beos*)
+        DEFINES="$DEFINES -DDEBUG_${USER}"
+        ;;
+    mks*|cygwin*|mingw*|msys*|os2*)
+        DEFINES="$DEFINES -DDEBUG_`echo ${USERNAME} | sed -e 's| |_|g'`"
+        ;;
+    *)
+        DEFINES="$DEFINES -DDEBUG_`$WHOAMI`"
+        ;;
+    esac
+else
+    AC_DEFINE(NDEBUG)
+    DEFINES="$DEFINES -UDEBUG"
+fi
+
+if test -z "$SKIP_COMPILER_CHECKS"; then
+dnl ========================================================
+dnl Checks for compilers.
+dnl ========================================================
+if test "$target" != "$host"; then
+    echo "cross compiling from $host to $target"
+    cross_compiling=yes
+
+    case "$build:$target" in
+      powerpc-apple-darwin8*:i?86-apple-darwin*)
+        dnl The Darwin cross compiler doesn't necessarily point itself at a
+        dnl root that has libraries for the proper architecture, it defaults
+        dnl to the system root.  The libraries in the system root on current
+        dnl versions of PPC OS X 10.4 aren't fat, so these target compiler
+        dnl checks will fail.  Fake a working SDK in that case.
+        _SAVE_CFLAGS=$CFLAGS
+        _SAVE_CXXFLAGS=$CXXFLAGS
+        CFLAGS="-isysroot /Developer/SDKs/MacOSX10.4u.sdk $CFLAGS"
+        CXXFLAGS="-isysroot /Developer/SDKs/MacOSX10.4u.sdk $CXXFLAGS"
+        ;;
+    esac
+
+    AC_CHECK_PROGS(CC, $CC "${target_alias}-gcc" "${target}-gcc", echo)
+    unset ac_cv_prog_CC
+    dnl Now exit the conditional block to invoke AC_PROG_CC.
+fi
+
+dnl In the latest versions of autoconf, AC_PROG_CC is a one-shot macro,
+dnl declared with AC_DEFUN_ONCE. So it must not be expanded inside a
+dnl conditional block. Invoke AC_PROG_CC outside any conditional block
+dnl and before invoking AC_TRY_COMPILE (which requires AC_PROG_CC).
+AC_PROG_CC
+
+dnl Reenter the conditional blocks after invoking AC_PROG_CC.
+if test "$target" != "$host"; then
+    if test -n "$USE_CPLUS"; then
+        AC_CHECK_PROGS(CXX, $CXX "${target_alias}-g++" "${target}-g++", echo)
+        unset ac_cv_prog_CXX
+        AC_PROG_CXX
+    fi
+
+    case "$build:$target" in
+      powerpc-apple-darwin8*:i?86-apple-darwin*|*:arm*-apple-darwin*)
+        dnl Revert the changes made above.  From this point on, the target
+        dnl compiler will never be used without applying the SDK to CFLAGS
+        dnl (see --with-macos-sdk below).
+        CFLAGS=$_SAVE_CFLAGS
+        CXXFLAGS=$_SAVE_CXXFLAGS
+        ;;
+    esac
+
+    AC_CHECK_PROGS(RANLIB, $RANLIB "${target_alias}-ranlib" "${target}-ranlib", echo)
+    AC_CHECK_PROGS(AR, $AR "${target_alias}-ar" "${target}-ar", echo)
+    AC_CHECK_PROGS(AS, $AS "${target_alias}-as" "${target}-as", echo)
+    AC_CHECK_PROGS(LD, $LD "${target_alias}-ld" "${target}-ld", echo)
+    AC_CHECK_PROGS(STRIP, $STRIP "${target_alias}-strip" "${target}-strip", echo)
+    AC_CHECK_PROGS(WINDRES, $WINDRES "${target_alias}-windres" "${target}-windres", echo)
+
+    _SAVE_CC="$CC"
+    _SAVE_CFLAGS="$CFLAGS"
+    _SAVE_LDFLAGS="$LDFLAGS"
+
+    AC_MSG_CHECKING([for $host compiler])
+    AC_CHECK_PROGS(HOST_CC, $HOST_CC gcc cc /usr/ucb/cc, "")
+    if test -z "$HOST_CC"; then
+        AC_MSG_ERROR([no acceptable cc found in \$PATH])
+    fi
+    AC_MSG_RESULT([$HOST_CC])
+
+    CC="$HOST_CC"
+    CFLAGS="$HOST_CFLAGS"
+    LDFLAGS="$HOST_LDFLAGS"
+
+    AC_MSG_CHECKING([whether the $host compiler ($HOST_CC $HOST_CFLAGS $HOST_LDFLAGS) works])
+    AC_TRY_COMPILE([], [return 0;],
+        [AC_MSG_RESULT([yes])],
+        [AC_MSG_ERROR([installation or configuration problem: $host compiler $HOST_CC cannot create executables.])] )
+
+    CC=$_SAVE_CC
+    CFLAGS=$_SAVE_CFLAGS
+    LDFLAGS=$_SAVE_LDFLAGS
+else
+    if test -n "$USE_CPLUS"; then
+        if test "$CC" = "cl" -a -z "$CXX"; then
+            CXX=$CC
+        else
+            AC_PROG_CXX
+        fi
+    fi
+    AC_PROG_RANLIB
+    AC_PATH_PROGS(AS, as, $CC)
+    AC_PATH_PROGS(AR, ar, echo not_ar)
+    AC_PATH_PROGS(LD, ld link, echo not_ld)
+    AC_PATH_PROGS(STRIP, strip, echo not_strip)
+    AC_PATH_PROGS(WINDRES, windres, echo not_windres)
+    if test -z "$HOST_CC"; then
+        HOST_CC="$CC"
+    fi
+    if test -z "$HOST_CFLAGS"; then
+        HOST_CFLAGS="$CFLAGS"
+    fi
+fi
+
+AC_PROG_CPP
+
+if test "$GCC" = "yes"; then
+    GNU_CC=1
+fi
+if test "$GXX" = "yes"; then
+    GNU_CXX=1
+fi
+if test "`echo | $AS -v 2>&1 | grep -c GNU`" != "0"; then
+    GNU_AS=1
+fi
+rm -f a.out
+
+case "$build:$target" in
+    i?86-apple-darwin*:powerpc-apple-darwin*)
+        dnl cross_compiling will have erroneously been set to "no" in this
+        dnl case, because the x86 build host is able to run ppc code in a
+        dnl translated environment, making a cross compiler appear native.
+        cross_compiling=yes
+        ;;
+esac
+
+if test "$cross_compiling"  = "yes"; then
+    CROSS_COMPILE=1
+else
+    CROSS_COMPILE=
+fi
+
+dnl ========================================================
+dnl Check for gcc -pipe support
+dnl ========================================================
+AC_MSG_CHECKING([for gcc -pipe support])
+if test -n "$GNU_CC" && test -n "$GNU_CXX" && test -n "$GNU_AS"; then
+    echo '#include <stdio.h>' > dummy-hello.c
+    echo 'int main() { printf("Hello World\n"); return 0; }' >> dummy-hello.c
+    ${CC} -S dummy-hello.c -o dummy-hello.s 2>&5
+    cat dummy-hello.s | ${AS} -o dummy-hello.S - 2>&5
+    if test $? = 0; then
+        _res_as_stdin="yes"
+    else
+        _res_as_stdin="no"
+    fi
+    if test "$_res_as_stdin" = "yes"; then
+        _SAVE_CFLAGS=$CFLAGS
+        CFLAGS="$CFLAGS -pipe"
+        AC_TRY_COMPILE( [ #include <stdio.h> ],
+            [printf("Hello World\n");],
+            [_res_gcc_pipe="yes"],
+            [_res_gcc_pipe="no"] )
+        CFLAGS=$_SAVE_CFLAGS
+    fi
+    if test "$_res_as_stdin" = "yes" && test "$_res_gcc_pipe" = "yes"; then
+        _res="yes";
+        CFLAGS="$CFLAGS -pipe"
+        CXXFLAGS="$CXXFLAGS -pipe"
+    else
+        _res="no"
+    fi
+    rm -f dummy-hello.c dummy-hello.s dummy-hello.S dummy-hello a.out
+    AC_MSG_RESULT([$_res])
+else
+    AC_MSG_RESULT([no])
+fi
+
+dnl ========================================================
+dnl Profile guided optimization
+dnl ========================================================
+dnl Test for profiling options
+dnl Under gcc 3.4+, use -fprofile-generate/-fprofile-use
+
+_SAVE_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS -fprofile-generate -fprofile-correction"
+
+AC_MSG_CHECKING([whether C compiler supports -fprofile-generate])
+AC_TRY_COMPILE([], [return 0;],
+               [ PROFILE_GEN_CFLAGS="-fprofile-generate"
+                 result="yes" ], result="no")
+AC_MSG_RESULT([$result])
+
+if test $result = "yes"; then
+   PROFILE_GEN_LDFLAGS="-fprofile-generate"
+   PROFILE_USE_CFLAGS="-fprofile-use -fprofile-correction -Wcoverage-mismatch"
+   PROFILE_USE_LDFLAGS="-fprofile-use"
+fi
+
+CFLAGS="$_SAVE_CFLAGS"
+
+dnl ===============================================================
+dnl Check for .hidden assembler directive and visibility attribute.
+dnl Borrowed from glibc configure.in
+dnl ===============================================================
+if test "$GNU_CC"; then
+    AC_CACHE_CHECK(for visibility(hidden) attribute,
+        ac_cv_visibility_hidden,
+        [cat > conftest.c <<EOF
+        int foo __attribute__ ((visibility ("hidden"))) = 1;
+EOF
+        ac_cv_visibility_hidden=no
+        if ${CC-cc} -Werror -S conftest.c -o conftest.s >/dev/null 2>&1; then
+            if grep '\.hidden.*foo' conftest.s >/dev/null; then
+                ac_cv_visibility_hidden=yes
+            fi
+        fi
+        rm -f conftest.[cs]
+        ])
+    if test "$ac_cv_visibility_hidden" = "yes"; then
+        AC_DEFINE(HAVE_VISIBILITY_HIDDEN_ATTRIBUTE)
+        AC_CACHE_CHECK(for visibility pragma support,
+            ac_cv_visibility_pragma,
+            [cat > conftest.c <<EOF
+#pragma GCC visibility push(hidden)
+            int foo_hidden = 1;
+#pragma GCC visibility push(default)
+            int foo_default = 1;
+EOF
+            ac_cv_visibility_pragma=no
+            if ${CC-cc} -Werror -S conftest.c -o conftest.s >/dev/null 2>&1; then
+                if grep '\.hidden.*foo_hidden' conftest.s >/dev/null; then
+                    if ! grep '\.hidden.*foo_default' conftest.s > /dev/null; then
+                        ac_cv_visibility_pragma=yes
+                    fi
+                fi
+            fi
+            rm -f conftest.[cs]
+            ])
+        if test "$ac_cv_visibility_pragma" = "yes"; then
+            AC_DEFINE(HAVE_VISIBILITY_PRAGMA)
+            # To work around a build problem on Linux x86-64 (Bugzilla bug
+            # 293438), we use the -fvisibility=hidden flag.  This flag is less
+            # optimal than #pragma GCC visibility push(hidden) because the flag
+            # assumes that symbols defined outside the current source file have
+            # the default visibility.  This has the advantage that we don't need
+            # to wrap system header files, but has the disadvantage that calls
+            # to hidden symbols defined in other source files cannot be
+            # optimized by the compiler.  The -fvisibility=hidden flag does
+            # hide and export symbols correctly.
+            #VISIBILITY_FLAGS='-I$(dist_includedir)/system_wrappers -include $(topsrcdir)/config/gcc_hidden.h'
+            #WRAP_SYSTEM_INCLUDES=1
+            VISIBILITY_FLAGS="-fvisibility=hidden"
+            WRAP_SYSTEM_INCLUDES=
+        fi
+    fi
+fi # GNU_CC
+
+fi # SKIP_COMPILER_CHECKS
+
+dnl ========================================================
+dnl Checks for programs.
+dnl ========================================================
+if test -z "$SKIP_PATH_CHECKS"; then
+    AC_PATH_PROGS(PERL, perl5 perl, echo not_perl)
+elif test -z "$PERL"; then
+    PERL=perl
+fi
+
+dnl ========================================================
+dnl Default platform specific options
+dnl ========================================================
+OBJ_SUFFIX=o
+LIB_SUFFIX=a
+DLL_SUFFIX=so
+ASM_SUFFIX=s
+MKSHLIB='$(LD) $(DSO_LDOPTS) -o $@'
+PR_MD_ASFILES=
+PR_MD_CSRCS=
+PR_MD_ARCH_DIR=unix
+AR_FLAGS='cr $@'
+AS='$(CC)'
+ASFLAGS='$(CFLAGS)'
+
+if test -n "$CROSS_COMPILE"; then
+    OS_ARCH=`echo $target_os | sed -e 's|/|_|g'`
+    OS_RELEASE=
+    OS_TEST="${target_cpu}"
+    case "${target_os}" in
+        linux*)       OS_ARCH=Linux ;;
+        solaris*)     OS_ARCH=SunOS OS_RELEASE=5 ;;
+        mingw*)       OS_ARCH=WINNT CPU_ARCH=x86 ;;
+        darwin*)      OS_ARCH=Darwin ;;
+        riscos*)      OS_ARCH=RISCOS ;;
+    esac
+else
+    OS_ARCH=`uname -s | sed -e 's|/|_|g'`
+    OS_RELEASE=`uname -r`
+    OS_TEST=`uname -m`
+fi
+
+if test "$OS_ARCH" = "IRIX64"; then
+    OS_ARCH=IRIX
+fi
+
+if test "$OS_ARCH" = "AIX"; then
+    OS_RELEASE=`uname -v`.`uname -r`
+fi
+
+if test "$OS_ARCH" = "FreeBSD"; then
+    OS_RELEASE=`echo $OS_RELEASE | sed 's/-.*//'`
+fi
+
+if test "$OS_ARCH" = "Linux"; then
+    OS_RELEASE=`echo $OS_RELEASE | sed 's/-.*//'`
+    OS_RELEASE=`echo $OS_RELEASE | awk -F\. '{ print $1 "." $2 }'`
+fi
+
+#######################################################################
+# Master "Core Components" macros for getting the OS target           #
+#######################################################################
+
+#
+# Note: OS_TARGET should be specified on the command line for gmake.
+# When OS_TARGET=WIN95 is specified, then a Windows 95 target is built.
+# The difference between the Win95 target and the WinNT target is that
+# the WinNT target uses Windows NT specific features not available
+# in Windows 95. The Win95 target will run on Windows NT, but (supposedly)
+# at lesser performance (the Win95 target uses threads; the WinNT target
+# uses fibers).
+#
+# If OS_TARGET is not specified, it defaults to $(OS_ARCH), i.e., no
+# cross-compilation.
+#
+
+#
+# The following hack allows one to build on a WIN95 machine (as if
+# s/he were cross-compiling on a WINNT host for a WIN95 target).
+# It also accomodates for MKS's uname.exe.  If you never intend
+# to do development on a WIN95 machine, you don't need this hack.
+#
+case "$OS_ARCH" in
+Windows_95)
+    OS_ARCH=Windows_NT
+    OS_TARGET=WIN95
+    ;;
+Windows_98)
+    OS_ARCH=Windows_NT
+    OS_TARGET=WIN95
+    ;;
+CYGWIN_9*|CYGWIN_ME*)
+    OS_ARCH='CYGWIN_NT-4.0'
+    OS_TARGET=WIN95
+    ;;
+OS_2)
+    OS_ARCH=OS2
+    OS_TARGET=OS2
+    ;;
+esac
+
+#
+# On WIN32, we also define the variable CPU_ARCH.
+#
+
+case "$OS_ARCH" in
+Windows_NT)
+#
+# If uname -s returns "Windows_NT", we assume that we are using
+# the uname.exe in MKS toolkit.
+#
+# The -r option of MKS uname only returns the major version number.
+# So we need to use its -v option to get the minor version number.
+# Moreover, it doesn't have the -p option, so we need to use uname -m.
+#
+    OS_ARCH=WINNT
+    OS_MINOR_RELEASE=`uname -v`
+    if test "$OS_MINOR_RELEASE" = "00"; then
+        OS_MINOR_RELEASE=0
+    fi
+    OS_RELEASE="${OS_RELEASE}.${OS_MINOR_RELEASE}"
+    CPU_ARCH=`uname -m`
+    #
+    # MKS's uname -m returns "586" on a Pentium machine.
+    #
+    if echo "$CPU_ARCH" | grep -c 86 >/dev/null; then
+        CPU_ARCH=x86
+    fi
+    ;;
+CYGWIN_NT*|MINGW*_NT*|MSYS_NT*)
+#
+# If uname -s returns "CYGWIN_NT-4.0", we assume that we are using
+# the uname.exe in the Cygwin tools.
+# If uname -s returns "MINGW32_NT-5.1", we assume that we are using
+# the uname.exe in the MSYS tools.
+# If uname -s returns "MSYS_NT-6.3", we assume that we are using
+# the uname.exe in the MSYS2 tools.
+#
+    OS_RELEASE=`expr $OS_ARCH : '.*NT-\(.*\)'`
+    OS_ARCH=WINNT
+    CPU_ARCH=`uname -m`
+    #
+    # Cygwin's uname -m returns "i686" on a Pentium Pro machine.
+    #
+    if echo "$CPU_ARCH" | grep -c 86 >/dev/null; then
+        CPU_ARCH=x86
+    fi
+    ;;
+esac
+
+if test -n "$MOZILLA_CLIENT" && test "$OS_ARCH" = "WINNT"; then
+    OS_TARGET=WIN95
+    if test -n "$MOZ_DEBUG" -a -z "$USE_DEBUG_RTL"; then
+        USE_DEBUG_RTL=1
+    fi
+fi
+if test -z "$OS_TARGET"; then
+    OS_TARGET=$OS_ARCH
+fi
+if test "$OS_TARGET" = "WIN95"; then
+    OS_RELEASE="4.0"
+fi
+OS_CONFIG="${OS_TARGET}${OS_RELEASE}"
+
+dnl ========================================================
+dnl Enable high-memory support on OS/2 by default.
+dnl ========================================================
+AC_ARG_ENABLE(os2-high-mem,
+    [  --disable-os2-high-mem  Disable high-memory support on OS/2],
+    [ if test "$enableval" = "no"; then
+        MOZ_OS2_HIGH_MEMORY=
+      else
+        MOZ_OS2_HIGH_MEMORY=1
+      fi ])
+
+dnl ========================================================
+dnl = ARM toolchain tweaks
+dnl ========================================================
+
+dnl Defaults
+MOZ_ALIGN=toolchain-default
+
+case "$target" in
+arm*-android*|arm*-linuxandroid*)
+    MOZ_THUMB=yes
+    MOZ_ARCH=armv7-a
+    MOZ_FPU=vfp
+    MOZ_FLOAT_ABI=softfp
+    MOZ_SOFT_FLOAT=yes
+    MOZ_ALIGN=no
+    ;;
+arm*-*)
+    if test -n "$MOZ_PLATFORM_MAEMO"; then
+        MOZ_THUMB=no
+        MOZ_ARCH=armv7-a
+        MOZ_FLOAT_ABI=softfp
+    fi
+    if test "$MOZ_PLATFORM_MAEMO" = 6; then
+        MOZ_THUMB=yes
+    fi
+    ;;
+esac
+
+dnl Kept for compatibility with some buildbot mozconfig
+AC_ARG_ENABLE(thumb2, [], MOZ_THUMB=$enableval)
+
+AC_ARG_WITH(thumb,
+[  --with-thumb[[=yes|no|toolchain-default]]]
+[                          Use Thumb instruction set (-mthumb)],
+    if test -z "$GNU_CC"; then
+        AC_MSG_ERROR([--with-thumb is not supported on non-GNU toolchain-defaults])
+    fi
+    MOZ_THUMB=$withval)
+
+AC_ARG_WITH(thumb-interwork,
+[  --with-thumb-interwork[[=yes|no|toolchain-default]]
+                           Use Thumb/ARM instuctions interwork (-mthumb-interwork)],
+    if test -z "$GNU_CC"; then
+        AC_MSG_ERROR([--with-thumb-interwork is not supported on non-GNU toolchain-defaults])
+    fi
+    MOZ_THUMB_INTERWORK=$withval)
+
+AC_ARG_WITH(arch,
+[  --with-arch=[[type|toolchain-default]]
+                           Use specific CPU features (-march=type)],
+    if test -z "$GNU_CC"; then
+        AC_MSG_ERROR([--with-arch is not supported on non-GNU toolchain-defaults])
+    fi
+    MOZ_ARCH=$withval)
+
+AC_ARG_WITH(fpu,
+[  --with-fpu=[[type|toolchain-default]]
+                           Use specific FPU type (-mfpu=type)],
+    if test -z "$GNU_CC"; then
+        AC_MSG_ERROR([--with-fpu is not supported on non-GNU toolchain-defaults])
+    fi
+    MOZ_FPU=$withval)
+
+AC_ARG_WITH(float-abi,
+[  --with-float-abi=[[type|toolchain-default]]
+                           Use specific arm float ABI (-mfloat-abi=type)],
+    if test -z "$GNU_CC"; then
+        AC_MSG_ERROR([--with-float-abi is not supported on non-GNU toolchain-defaults])
+    fi
+    MOZ_FLOAT_ABI=$withval)
+
+AC_ARG_WITH(soft-float,
+[  --with-soft-float[[=yes|no|toolchain-default]]
+                           Use soft float library (-msoft-float)],
+    if test -z "$GNU_CC"; then
+        AC_MSG_ERROR([--with-soft-float is not supported on non-GNU toolchain-defaults])
+    fi
+    MOZ_SOFT_FLOAT=$withval)
+
+case "$MOZ_ARCH" in
+toolchain-default|"")
+    arch_flag=""
+    ;;
+*)
+    arch_flag="-march=$MOZ_ARCH"
+    ;;
+esac
+
+case "$MOZ_THUMB" in
+yes)
+    MOZ_THUMB2=1
+    thumb_flag="-mthumb"
+    ;;
+no)
+    MOZ_THUMB2=
+    thumb_flag="-marm"
+    ;;
+*)
+    _SAVE_CFLAGS="$CFLAGS"
+    CFLAGS="$arch_flag"
+    AC_TRY_COMPILE([],[return sizeof(__thumb2__);],
+        MOZ_THUMB2=1,
+        MOZ_THUMB2=)
+    CFLAGS="$_SAVE_CFLAGS"
+    thumb_flag=""
+    ;;
+esac
+
+case "$MOZ_THUMB_INTERWORK" in
+yes)
+    thumb_interwork_flag="-mthumb-interwork"
+    ;;
+no)
+    thumb_interwork_flag="-mno-thumb-interwork"
+    ;;
+*) # toolchain-default
+    thumb_interwork_flag=""
+    ;;
+esac
+
+case "$MOZ_FPU" in
+toolchain-default|"")
+    fpu_flag=""
+    ;;
+*)
+    fpu_flag="-mfpu=$MOZ_FPU"
+    ;;
+esac
+
+case "$MOZ_FLOAT_ABI" in
+toolchain-default|"")
+    float_abi_flag=""
+    ;;
+*)
+    float_abi_flag="-mfloat-abi=$MOZ_FLOAT_ABI"
+    ;;
+esac
+
+case "$MOZ_SOFT_FLOAT" in
+yes)
+    soft_float_flag="-msoft-float"
+    ;;
+no)
+    soft_float_flag="-mno-soft-float"
+    ;;
+*) # toolchain-default
+    soft_float_flag=""
+    ;;
+esac
+
+case "$MOZ_ALIGN" in
+toolchain-default|"")
+    align_flag=""
+    ;;
+no)
+    align_flag="-mno-unaligned-access"
+    ;;
+yes)
+    align_flag="-munaligned-access"
+    ;;
+*)
+    align_flag=""
+    ;;
+esac
+
+if test -n "$align_flag"; then
+  _SAVE_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS $align_flag"
+  AC_MSG_CHECKING(whether alignment flag ($align_flag) is supported)
+  AC_TRY_COMPILE([],[],,align_flag="")
+  CFLAGS="$_SAVE_CFLAGS"
+fi
+
+dnl Use echo to avoid accumulating space characters
+all_flags=`echo $arch_flag $thumb_flag $thumb_interwork_flag $fpu_flag $float_abi_flag $soft_float_flag $align_flag`
+if test -n "$all_flags"; then
+    _SAVE_CFLAGS="$CFLAGS"
+    CFLAGS="$all_flags"
+    AC_MSG_CHECKING(whether the chosen combination of compiler flags ($all_flags) works)
+    AC_TRY_COMPILE([],[return 0;],
+        AC_MSG_RESULT([yes]),
+        AC_MSG_ERROR([no]))
+
+    CFLAGS="$_SAVE_CFLAGS $all_flags"
+    CXXFLAGS="$CXXFLAGS $all_flags"
+    ASFLAGS="$ASFLAGS $all_flags"
+    if test -n "$thumb_flag"; then
+        LDFLAGS="$LDFLAGS $thumb_flag"
+    fi
+fi
+
+dnl ========================================================
+dnl Override of system specific host options
+dnl ========================================================
+case "$host" in
+*-mingw*|*-msys*)
+    NSINSTALL=nsinstall
+    ;;
+*-cygwin*|*-mks*)
+    NSINSTALL='$(CYGWIN_WRAPPER) nsinstall'
+    if test `echo "${PATH}" | grep -c \;` = 0; then
+        CYGWIN_WRAPPER='sh $(topsrcdir)/build/cygwin-wrapper'
+    fi
+    ;;
+*-beos*)
+    HOST_CFLAGS="$HOST_CFLAGS -DXP_BEOS -DBeOS -DBEOS -D_POSIX_SOURCE"
+    ;;
+*os2*)
+    ;;
+*)
+    HOST_CFLAGS="$HOST_CFLAGS -DXP_UNIX"
+    ;;
+esac
+
+dnl ========================================================
+dnl Override of system specific target options
+dnl ========================================================
+case "$target" in
+
+*-aix*)
+    AC_DEFINE(XP_UNIX)
+    AC_DEFINE(AIX)
+    AC_DEFINE(SYSV)
+    DSO_LDOPTS='-brtl -bnortllib -bM:SRE -bnoentry -bexpall -blibpath:/usr/lib:/lib'
+    AC_CHECK_HEADER(sys/atomic_op.h, AC_DEFINE(AIX_HAVE_ATOMIC_OP_H))
+    case "${target_os}" in
+    aix3.2*)
+        AC_DEFINE(AIX_RENAME_SELECT)
+        AC_DEFINE(_PR_NO_LARGE_FILES)
+        AIX_LINK_OPTS='-bnso -berok'
+        PR_MD_ASFILES=os_AIX.s
+        ;;
+    aix4.1*)
+        AC_DEFINE(AIX_TIMERS)
+        AC_DEFINE(_PR_NO_LARGE_FILES)
+        AC_DEFINE(AIX4_1)
+        MKSHLIB=
+        DSO_LDOPTS=
+        AIX_LINK_OPTS='-bnso -berok'
+        LIBNSPR='-L$(dist_libdir) -lnspr$(MOD_MAJOR_VERSION)_shr'
+        LIBPLC='-L$(dist_libdir) -lplc$(MOD_MAJOR_VERSION)_shr'
+        ;;
+    aix4.2*)
+        AC_DEFINE(AIX_TIMERS)
+        AC_DEFINE(_PR_HAVE_OFF64_T)
+        AIX_LINK_OPTS='-brtl -bnso -berok'
+        ;;
+    aix4.3*)
+        AC_DEFINE(AIX_TIMERS)
+        AC_DEFINE(_PR_HAVE_OFF64_T)
+        AC_DEFINE(AIX4_3_PLUS)
+        AC_DEFINE(HAVE_SOCKLEN_T)
+        AC_DEFINE(HAVE_FCNTL_FILE_LOCKING)
+        USE_IPV6=1
+        AIX_LINK_OPTS='-brtl -bnso -berok'
+        ;;
+    *)
+        AC_DEFINE(AIX_TIMERS)
+        AC_DEFINE(_PR_HAVE_OFF64_T)
+        AC_DEFINE(AIX4_3_PLUS)
+        AC_DEFINE(HAVE_SOCKLEN_T)
+        AC_DEFINE(HAVE_FCNTL_FILE_LOCKING)
+        USE_IPV6=1
+        AIX_LINK_OPTS='-brtl -bnso -berok'
+        ;;
+    esac
+    CFLAGS="$CFLAGS -qro -qroconst"
+    AIX_WRAP='$(DIST)/lib/aixwrap.o'
+    AIX_TMP='./_aix_tmp.o'
+    if test -n "$USE_64"; then
+        MDCPUCFG_H=_aix64.cfg
+        OBJECT_MODE=64
+    else
+        MDCPUCFG_H=_aix32.cfg
+    fi
+    PR_MD_CSRCS=aix.c
+    RESOLVE_LINK_SYMBOLS=1
+    ;;
+        
+*-beos*)
+    AC_DEFINE(XP_BEOS)
+    AC_DEFINE(BeOS)
+    AC_DEFINE(BEOS)
+    AC_DEFINE(_POSIX_SOURCE)
+    DSO_LDOPTS=-nostart
+    MDCPUCFG_H=_beos.cfg
+    USE_BTHREADS=1
+    PR_MD_ARCH_DIR=beos
+    RESOLVE_LINK_SYMBOLS=1
+    case "${target_cpu}" in
+    i*86)
+        _OPTIMIZE_FLAGS=-O2
+        _DEBUG_FLAGS='-gdwarf-2 -O0'
+        MKSHLIB='$(CCC) $(DSO_LDOPTS) -o $@'
+        AC_CHECK_LIB(bind, gethostbyaddr, [OS_LIBS="$OS_LIBS -lbind -lsocket"])
+        ;;
+    powerpc)
+        CC=mwcc
+        CCC=mwcc
+        LD=mwld
+        DSO_LDOPTS='-xms -export pragma -init _init_routine_ -term _term_routine_ -lroot -lnet /boot/develop/lib/ppc/glue-noinit.a /boot/develop/lib/ppc/init_term_dyn.o /boot/develop/lib/ppc/start_dyn.o'
+        _OPTIMIZE_FLAGS=-O2    
+        _DEBUG_FLAGS='-g -O0'
+        ;;
+    esac
+    ;;
+
+*-bsdi*)
+    AC_DEFINE(XP_UNIX)
+    AC_DEFINE(BSDI)
+    AC_DEFINE(NEED_BSDREGEX)
+
+    CFLAGS="$CFLAGS -Wall -Wno-format"
+    CXXFLAGS="$CXXFLAGS -Wall -Wno-format"
+
+    if echo "$OS_TEST" | grep -c 86 >/dev/null; then
+        CPU_ARCH=x86
+    elif echo "$OS_TEST" | grep -c sparc >/dev/null; then 
+        CPU_ARCH=sparc
+    fi
+
+    MDCPUCFG_H=_bsdi.cfg
+    PR_MD_CSRCS=bsdi.c
+
+    DSO_LDOPTS=-r
+
+    case "$target_os" in
+    bsdi1.1*)
+        AC_DEFINE(_PR_BSDI_JMPBUF_IS_ARRAY)
+        AC_DEFINE(_PR_STAT_HAS_ONLY_ST_ATIME)
+        AC_DEFINE(_PR_NEED_H_ERRNO)
+        MKSHLIB=
+        DSO_CFLAGS=
+        DSO_LDOPTS=
+        ;;
+
+    bsdi2.1*)
+        AC_DEFINE(_PR_TIMESPEC_HAS_TS_SEC)
+        AC_DEFINE(_PR_BSDI_JMPBUF_IS_ARRAY)
+        AC_DEFINE(HAVE_DLL)
+        AC_DEFINE(USE_DLFCN)
+        AC_DEFINE(_PR_STAT_HAS_ST_ATIMESPEC)
+        PR_MD_ASFILES=os_BSD_OS_386_2.s
+        ;;
+
+    bsdi4.* | bsdi5.*)
+        AC_DEFINE(_PR_SELECT_CONST_TIMEVAL)
+        AC_DEFINE(_PR_BSDI_JMPBUF_IS_STRUCT)
+        AC_DEFINE(HAVE_DLL)
+        AC_DEFINE(USE_DLFCN)
+        AC_DEFINE(_PR_STAT_HAS_ST_ATIMESPEC)
+        MKSHLIB='$(CC) -o $@ $(DSO_LDOPTS)'
+        DSO_CFLAGS=-fPIC
+        DSO_LDOPTS='-shared -Wl,-soname,$(@:$(OBJDIR)/%.so=%.so)'
+        STRIP="$STRIP -d"
+        case "$target_os" in
+        bsdi4.2* | bsdi4.3* | bsdi5.*)
+            AC_DEFINE(_PR_HAVE_GETPROTO_R)
+            AC_DEFINE(_PR_HAVE_GETPROTO_R_POINTER)
+            ;;
+        esac
+        ;;
+    *)
+        AC_DEFINE(_PR_SELECT_CONST_TIMEVAL)
+        AC_DEFINE(_PR_BSDI_JMPBUF_IS_STRUCT)
+        AC_DEFINE(HAVE_DLL)
+        AC_DEFINE(USE_DLFCN)
+        AC_DEFINE(_PR_STAT_HAS_ST_ATIMESPEC)
+        ;;
+    esac
+
+    ;;
+
+*-darwin*)
+    AC_DEFINE(XP_UNIX)
+    AC_DEFINE(DARWIN)
+    AC_DEFINE(HAVE_BSD_FLOCK)
+    AC_DEFINE(HAVE_SOCKLEN_T)
+    AS='$(CC) -x assembler-with-cpp'
+    CFLAGS="$CFLAGS -Wall -fno-common"
+    case "${target_cpu}" in
+        arm*)
+            CPU_ARCH=arm
+            ;;
+        i*86*|x86_64)
+            if test -n "$USE_64"; then
+                CPU_ARCH=x86_64
+            else        
+                CPU_ARCH=i386
+            fi
+            ;;
+        *)
+            CPU_ARCH=ppc
+            ;;
+    esac
+    if test "`echo $CC | grep -c '\-arch '`" = "0"; then
+        CC="$CC -arch $CPU_ARCH"
+    fi
+    AC_CHECK_HEADER(crt_externs.h, AC_DEFINE(HAVE_CRT_EXTERNS_H))
+    DSO_CFLAGS=-fPIC
+    DSO_LDOPTS='-dynamiclib -compatibility_version 1 -current_version 1 -all_load -install_name @executable_path/$@ -headerpad_max_install_names'
+    _OPTIMIZE_FLAGS=-O2
+    MKSHLIB='$(CC) $(DSO_LDOPTS) -o $@'
+    STRIP="$STRIP -x -S"
+    DLL_SUFFIX=dylib
+    USE_PTHREADS=1
+    MDCPUCFG_H=_darwin.cfg
+    PR_MD_CSRCS=darwin.c
+    PR_MD_ASFILES=os_Darwin.s
+
+    # Add Mac OS X support for loading CFM & CFBundle plugins
+    if test -f "${MACOS_SDK_DIR}/System/Library/Frameworks/Carbon.framework/Carbon"; then
+        AC_DEFINE(XP_MACOSX)
+        OS_TARGET=MacOSX
+
+        if test -n "$_MACOSX_DEPLOYMENT_TARGET" ; then
+            dnl Use the specified value
+            export MACOSX_DEPLOYMENT_TARGET=$_MACOSX_DEPLOYMENT_TARGET
+        elif test -z "$MACOSX_DEPLOYMENT_TARGET" ; then
+            dnl No value specified on the command line or in the environment,
+            dnl use the lesser of the library's minimum or the architecture's
+            dnl minimum.
+            case "${target_cpu}" in
+                powerpc*)
+                    dnl Architecture minimum 10.2
+                    export MACOSX_DEPLOYMENT_TARGET=10.2
+                    ;;
+                i*86*)
+                    dnl Architecture minimum 10.4
+                    export MACOSX_DEPLOYMENT_TARGET=10.4
+                    ;;
+            esac
+        fi
+
+        dnl MACOS_SDK_DIR will be set to the SDK location whenever one is
+        dnl in use.  NEXT_ROOT will be set and exported if it's needed for
+        dnl ld.
+
+        if test "$MACOS_SDK_DIR"; then
+            dnl Sync this section with the one in Mozilla's top level.
+
+            if test ! -d "$MACOS_SDK_DIR"; then
+                AC_MSG_ERROR([SDK not found.  When using --with-macos-sdk, you must
+specify a valid SDK.  SDKs are installed when the optional cross-development
+tools are selected during the Xcode/Developer Tools installation.])
+            fi
+
+            changequote(,)
+            CC_VERSION=`$CC -v 2>&1 | grep 'gcc version'`
+            GCC_VERSION_FULL=`echo $CC_VERSION | $PERL -pe 's/^.*gcc version ([^ ]*).*/$1/'`
+            GCC_VERSION=`echo $GCC_VERSION_FULL | $PERL -pe '(split(/\./))[0]>=4&&s/(^\d*\.\d*).*/$1/;'`
+            changequote([,])
+            GCC_VERSION_MAJOR=`echo $GCC_VERSION_FULL | $PERL -pe 's/(^\d*).*/$1/;'`
+            if test "$GCC_VERSION_MAJOR" -lt "4" ; then
+                SDK_C_FRAMEWORK="-F${MACOS_SDK_DIR}/System/Library/Frameworks"
+                if test -d "${MACOS_SDK_DIR}/Library/Frameworks" ; then
+                    SDK_C_FRAMEWORK="$SDK_C_FRAMEWORK -F${MACOS_SDK_DIR}/Library/Frameworks"
+                fi
+
+                SDK_C_INCLUDE="-isystem ${MACOS_SDK_DIR}/usr/include/gcc/darwin/${GCC_VERSION} -isystem ${MACOS_SDK_DIR}/usr/include ${SDK_C_FRAMEWORK}"
+
+                CFLAGS="$CFLAGS -nostdinc ${SDK_C_INCLUDE}"
+
+                dnl CPP needs to be set for AC_CHECK_HEADER.
+                CPP="$CPP -nostdinc ${SDK_C_INCLUDE}"
+
+                changequote(,)
+                HOST_DARWIN_MAJOR=`echo "$build_os" | sed -E -e 's/^darwin([0-9]+).*$/\1/'`
+                changequote([,])
+                if test "$HOST_DARWIN_MAJOR" -lt 9 ; then
+                    dnl The build host is running Tiger (10.4) or earlier.
+                    dnl ld support for -syslibroot is compiler-agnostic, but
+                    dnl only available on Tiger and later.  On Tiger and
+                    dnl earlier build hosts, just rely on NEXT_ROOT, because
+                    dnl it's not been shown to cause any problems.
+                    MACOS_SDK_LIBS="-L${MACOS_SDK_DIR}/usr/lib/gcc/darwin -L${MACOS_SDK_DIR}/usr/lib/gcc/darwin/${GCC_VERSION_FULL} -L${MACOS_SDK_DIR}/usr/lib ${SDK_C_FRAMEWORK}"
+                else
+                    dnl The build host is running Leopard (10.5) or later.
+                    dnl With NEXT_ROOT set, the linker will still not apply
+                    dnl it when resolving dependencies.  This causes problems
+                    dnl on Leopard, where an SDK depends on frameworks which
+                    dnl were present in earlier OS releases (and the associated
+                    dnl SDK) but not in Leopard.  -syslibroot does not have
+                    dnl this problem, but it results in harmless warnings when
+                    dnl NEXT_ROOT is set.  NEXT_ROOT needs to remain set even
+                    dnl on Leopard because the compiler uses it too.
+                    MACOS_SDK_LIBS="-Wl,-syslibroot,${MACOS_SDK_DIR}"
+                fi
+
+                LDFLAGS="${MACOS_SDK_LIBS} $LDFLAGS"
+                export NEXT_ROOT=$MACOS_SDK_DIR
+
+                if test -n "$CROSS_COMPILE" ; then
+                    dnl NEXT_ROOT will be in the environment, but it
+                    dnl shouldn't be set for the build host.  HOST_CXX is
+                    dnl presently unused.
+                    HOST_CC="NEXT_ROOT= $HOST_CC"
+                    HOST_CXX="NEXT_ROOT= $HOST_CXX"
+                fi
+            else
+                dnl gcc >= 4.0 uses different paths than above, but knows
+                dnl how to find them itself.
+                CFLAGS="$CFLAGS -isysroot ${MACOS_SDK_DIR}"
+
+                dnl CPP needs to be set for AC_CHECK_HEADER.
+                CPP="$CPP -isysroot ${MACOS_SDK_DIR}"
+
+                dnl If gcc >= 4.0.0, we're guaranteed to be on Tiger, which
+                dnl has an ld that supports -syslibroot.  Don't set
+                dnl NEXT_ROOT because it will be ignored and cause
+                dnl warnings when -syslibroot is specified.
+                if test "$GCC_VERSION_FULL" != "4.0.0" ; then
+                    dnl gcc > 4.0.0 will pass -syslibroot to ld automatically
+                    dnl based on the -isysroot it receives.
+                    LDFLAGS="$LDFLAGS -isysroot ${MACOS_SDK_DIR}"
+                else
+                    dnl gcc 4.0.0 doesn't pass -syslibroot to ld, it needs
+                    dnl to be explicit.
+                    LDFLAGS="$LDFLAGS -Wl,-syslibroot,${MACOS_SDK_DIR}"
+                fi
+            fi
+        fi
+    fi
+    ;;
+
+*-dgux*)
+    AC_DEFINE(XP_UNIX)
+    AC_DEFINE(_PR_LOCAL_THREADS_ONLY)
+    AC_DEFINE(SVR4)
+    AC_DEFINE(SYSV)
+    AC_DEFINE(DGUX)
+    AC_DEFINE(_DGUX_SOURCE)
+    AC_DEFINE(_POSIX4A_DRAFT6_SOURCE)
+    DSO_LDOPTS=-G
+    _OPTIMIZE_FLAGS=-O2
+    _DEBUG_FLAGS=
+    MDCPUCFG_H=_dgux.cfg
+    PR_MD_CSRCS=dgux.c
+    ;;
+
+*-freebsd*)
+    if test -z "$USE_NSPR_THREADS"; then
+        USE_PTHREADS=1
+    fi
+    AC_DEFINE(XP_UNIX)
+    AC_DEFINE(FREEBSD)
+    AC_DEFINE(HAVE_BSD_FLOCK)
+    AC_DEFINE(HAVE_SOCKLEN_T)
+    CFLAGS="$CFLAGS $(DSO_CFLAGS) -ansi -Wall"
+    MOZ_OBJFORMAT=`test -x /usr/bin/objformat && /usr/bin/objformat || echo elf`
+    if test "$MOZ_OBJFORMAT" = "elf"; then
+        DLL_SUFFIX=so
+    else
+        DLL_SUFFIX=so.1.0
+    fi
+    MKSHLIB='$(CC) $(DSO_LDOPTS) -o $@'
+    DSO_CFLAGS=-fPIC
+    DSO_LDOPTS='-shared -Wl,-soname -Wl,$(notdir $@)'
+    MDCPUCFG_H=_freebsd.cfg
+    PR_MD_CSRCS=freebsd.c
+    ;;
+
+*-hpux*)
+    AC_DEFINE(XP_UNIX)
+    AC_DEFINE(HPUX)
+    AC_DEFINE(_HPUX_SOURCE)
+    # OSF1 and HPUX report the POLLHUP event for a socket when the
+    # shutdown(SHUT_WR) operation is called for the remote end, even though
+    # the socket is still writeable. Use select(), instead of poll(), to
+    # workaround this problem.
+    AC_DEFINE(_PR_POLL_WITH_SELECT)
+    AC_DEFINE(_USE_BIG_FDS)
+    DSO_LDOPTS='-b +h $(notdir $@)'
+    PR_MD_CSRCS=hpux.c
+    if test "$OS_TEST" = "ia64"; then
+        DLL_SUFFIX=so
+        DSO_LDOPTS="$DSO_LDOPTS +b '\$\$ORIGIN'"
+        CPU_ARCH_TAG=_$OS_TEST 
+        if test -z "$USE_64"; then
+            COMPILER_TAG=_32
+        fi
+        PR_MD_ASFILES=os_HPUX_ia64.s
+    else
+        AC_DEFINE(hppa)
+        DLL_SUFFIX=sl
+        PR_MD_ASFILES=os_HPUX.s
+    fi
+    if test -n "$USE_64"; then
+        MDCPUCFG_H=_hpux64.cfg
+    else
+        MDCPUCFG_H=_hpux32.cfg
+    fi
+    if test -z "$GNU_CC"; then
+        CC="$CC -Ae"
+        CXX="$CXX -ext"
+        DSO_CFLAGS=+Z
+    else
+        DSO_CFLAGS=-fPIC
+        ASFLAGS="$ASFLAGS -x assembler-with-cpp"
+    fi
+
+    if test -n "$MOZILLA_CLIENT"; then
+        DEFAULT_IMPL_STRATEGY=_EMU
+    fi
+
+    if echo "$OS_RELEASE" | grep ^A.09 >/dev/null; then
+        AC_DEFINE(_PR_NEED_H_ERRNO)
+        AC_DEFINE(HPUX9)
+        DEFAULT_IMPL_STRATEGY=_EMU
+    	USE_NSPR_THREADS=1
+    fi
+
+    if echo "$OS_RELEASE" | egrep '^(A.09|B.10)' >/dev/null; then
+        AC_DEFINE(_PR_NO_LARGE_FILES)
+    fi
+
+    if echo "$OS_RELEASE" | egrep '^(B.10.10|B.10.20)' >/dev/null; then
+        AC_DEFINE(_PR_NEED_H_ERRNO)
+    fi
+
+    if echo "$OS_RELEASE" | egrep '^(B.10.10|B.10.20)' >/dev/null; then
+        AC_DEFINE(HAVE_INT_LOCALTIME_R)
+    fi
+
+    if echo "$OS_RELEASE" | egrep '^(B.10.30|B.11)' >/dev/null; then
+        AC_DEFINE(HAVE_POINTER_LOCALTIME_R)
+    fi
+
+    # HP-UX 11i v2 (B.11.23) or higher
+    changequote(<<,>>)
+    case "$OS_RELEASE" in
+    [C-Z]*|B.[2-9]*|B.1[2-9]*|B.11.[3-9]*|B.11.2[3-9]*)
+        USE_IPV6=1
+        ;;
+    esac
+    changequote([,])
+
+    if test "$OS_RELEASE" = "B.10.01"; then
+        AC_DEFINE(HPUX10)
+        DEFAULT_IMPL_STRATEGY=_EMU
+    fi
+
+    if test "$OS_RELEASE" = "B.10.10"; then
+        AC_DEFINE(HPUX10)
+        AC_DEFINE(HPUX10_10)
+        DEFAULT_IMPL_STRATEGY=_PTH
+    fi
+
+    if test "$OS_RELEASE" = "B.10.20"; then
+        AC_DEFINE(HPUX10)
+        AC_DEFINE(HPUX10_20)
+        if test -z "$GNU_CC"; then
+            CFLAGS="$CFLAGS +DAportable +DS1.1"
+            CXXFLAGS="$CXXFLAGS +DAportable +DS1.1"
+        fi
+        DEFAULT_IMPL_STRATEGY=_PTH
+    fi
+
+    if test "$OS_RELEASE" = "B.10.30"; then
+        AC_DEFINE(HPUX10)
+        AC_DEFINE(HPUX10_30)
+        if test -z "$GNU_CC"; then
+            CFLAGS="$CFLAGS +DAportable +DS1.1"
+            CXXFLAGS="$CXXFLAGS +DAportable +DS1.1"
+        fi
+        DEFAULT_IMPL_STRATEGY=_PTH
+    fi
+
+    if echo "$OS_RELEASE" | grep ^B.11 >/dev/null; then
+        AC_DEFINE(HPUX10)
+        AC_DEFINE(HPUX11)
+        AC_DEFINE(_LARGEFILE64_SOURCE)
+        AC_DEFINE(_PR_HAVE_OFF64_T)
+        AC_DEFINE(HAVE_FCNTL_FILE_LOCKING)
+        if test -z "$GNU_CC"; then
+            if test -z "$USE_64"; then
+                if test "$OS_TEST" = "ia64"; then
+                    CFLAGS="$CFLAGS +DD32"
+                    CXXFLAGS="$CXXFLAGS +DD32"
+                else
+                    CFLAGS="$CFLAGS +DAportable +DS2.0"
+                    CXXFLAGS="$CXXFLAGS +DAportable +DS2.0"
+                fi
+            else
+                if test "$OS_TEST" = "ia64"; then
+                    CFLAGS="$CFLAGS +DD64"
+                    CXXFLAGS="$CXXFLAGS +DD64"
+                else
+                    CFLAGS="$CFLAGS +DA2.0W +DS2.0"
+                    CXXFLAGS="$CXXFLAGS +DA2.0W +DS2.0"
+                fi
+            fi
+        fi
+        DEFAULT_IMPL_STRATEGY=_PTH
+    fi
+
+    if test "$DEFAULT_IMPL_STRATEGY" = "_EMU"; then
+        USE_NSPR_THREADS=1
+        USE_PTHREADS=
+        USE_USER_PTHREADS=
+    elif test "$DEFAULT_IMPL_STRATEGY" = "_PTH"; then
+        USE_PTHREADS=1
+        if test "$USE_NSPR_THREADS"; then
+            USE_PTHREADS=
+        fi
+        if test "$USE_USER_PTHREADS"; then
+            USE_PTHREADS=
+        fi
+    fi
+    ;;
+
+*-irix*)
+    AC_DEFINE(XP_UNIX)
+    AC_DEFINE(IRIX)
+    AC_DEFINE(SVR4)
+    AC_DEFINE(_SGI_MP_SOURCE)
+    AC_DEFINE(HAVE_FCNTL_FILE_LOCKING)
+    PR_MD_CSRCS=irix.c
+    PR_MD_ASFILES=os_Irix.s
+    MKSHLIB='$(LD) $(DSO_LDOPTS) -rdata_shared -shared -soname $(notdir $@) -o $@'
+    STRIP="$STRIP -f"
+    RESOLVE_LINK_SYMBOLS=1
+    if test -n "$USE_64"; then
+        MDCPUCFG_H=_irix64.cfg
+    else
+        MDCPUCFG_H=_irix32.cfg
+    fi
+    case "${target_os}" in
+    irix6*)
+        AC_DEFINE(IRIX6)
+        USE_PTHREADS=1
+        USE_N32=1
+        COMPILER_TAG=_n32
+        IMPL_STRATEGY=_PTH
+        ;;
+    irix5*)
+        AC_DEFINE(IRIX5)
+        USE_NSPR_THREADS=1
+        ;;
+    *)
+        USE_PTHREADS=1
+        USE_N32=1
+        ;;
+    esac
+    if test "$GNU_CC"; then
+        dnl
+        dnl If we are using gcc with native binutils, we need to
+        dnl suppress the
+        dnl #lineno "filename" num num
+        dnl lines, which confuse IRIX native as.  Add -Wp,-P to the
+        dnl gcc command line, which passes -P to the preprocessor.
+        dnl
+	    AS='$(CC) -Wp,-P -x assembler-with-cpp -D_ASM -mips2 $(INCLUDES)'
+	    CFLAGS="$CFLAGS -Wall -Wno-format"
+	    _OPTIMIZE_FLAGS="-O6"
+    else
+	    if test -n "$USE_N32"; then
+		AS='as -D_ASM $(INCLUDES) -n32'
+	    else
+		AS='as -D_ASM $(INCLUDES)'
+	    fi
+	    CFLAGS="$CFLAGS -fullwarn -xansi"
+	    if test "$USE_N32"; then
+	        _OPTIMIZE_FLAGS="-O -OPT:Olimit=4000"
+	    else
+	        _OPTIMIZE_FLAGS="-O -Olimit 4000"
+	    fi
+	    if test "$USE_MDUPDATE"; then
+                CFLAGS="$CFLAGS -MDupdate \$(DEPENDENCIES)"
+	    fi
+	    case "${target}" in
+	    *-irix6.*)
+	        CFLAGS="$CFLAGS -multigot"
+	        DSO_LDOPTS="-no_unresolved"
+	        if test "$USE_N32"; then
+		        CFLAGS="$CFLAGS -n32 -woff 1209"
+		        DSO_LDOPTS="$DSO_LDOPTS -n32"
+	        else
+		        if test "$USE_64"; then
+		            CFLAGS="$CFLAGS -64"
+		        else
+		            CFLAGS="$CFLAGS -32"
+		        fi
+	        fi
+	        ;;
+	    *)
+	        CFLAGS="$CFLAGS -xgot"
+	        ;;
+	    esac
+    fi
+    if test "${target_os}" = "irix5.3"; then
+	    AC_DEFINE(IRIX5_3)
+    fi
+    case "${target_os}" in
+	irix6.5)
+	    if test -z "$GNU_CC"; then
+		    CFLAGS="$CFLAGS -mips3"
+	    fi
+	    AC_DEFINE(_PR_HAVE_GETPROTO_R)
+	    AC_DEFINE(_PR_HAVE_GETPROTO_R_POINTER)
+	    AC_DEFINE(_PR_HAVE_SGI_PRDA_PROCMASK)
+	    ;;
+	irix5*)
+	    ;;
+	*)
+	    AC_DEFINE(_PR_HAVE_SGI_PRDA_PROCMASK)
+	    ;;
+	esac
+    ;;
+
+*-linux*|*-gnu*|*-k*bsd*-gnu|*-android*|*-linuxandroid*)
+    if test -z "$USE_NSPR_THREADS"; then
+        USE_PTHREADS=1
+        IMPL_STRATEGY=_PTH
+    fi
+    AC_DEFINE(XP_UNIX)
+    AC_DEFINE(_GNU_SOURCE)
+    AC_DEFINE(HAVE_FCNTL_FILE_LOCKING)
+    case "${target}" in
+    *-android*|*-linuxandroid*)
+        OS_TARGET=Android
+        AC_DEFINE(LINUX)
+        ;;
+    *-linux*)
+        AC_DEFINE(LINUX)
+        ;;
+    esac
+    CFLAGS="$CFLAGS -Wall"
+    CXXFLAGS="$CXXFLAGS -Wall"
+    MDCPUCFG_H=_linux.cfg
+    PR_MD_CSRCS=linux.c
+    MKSHLIB='$(CC) $(DSO_LDOPTS) -o $@'
+    DSO_CFLAGS=-fPIC
+    DSO_LDOPTS='-shared -Wl,-soname -Wl,$(notdir $@)'
+    _OPTIMIZE_FLAGS=-O2
+    _DEBUG_FLAGS="-g -fno-inline"  # most people on linux use gcc/gdb, and that
+                                   # combo is not yet good at debugging inlined
+                                   # functions (even when using DWARF2 as the
+                                   # debugging format)
+    COMPILER_TAG=_glibc
+    if echo "$OS_TEST" | grep -c 86 >/dev/null; then
+        CPU_ARCH=x86
+    else
+        CPU_ARCH=$OS_TEST
+    fi
+    CPU_ARCH_TAG=_${CPU_ARCH}
+    case "${target_cpu}" in
+    alpha)
+        AC_DEFINE(_ALPHA_)
+        AC_DEFINE(__alpha)
+        CFLAGS="$CFLAGS -mieee"
+        CXXFLAGS="$CXXFLAGS -mieee"
+        ;;
+    i*86)
+        AC_DEFINE(i386)
+        PR_MD_ASFILES=os_Linux_x86.s
+        ;;
+    ia64)
+        PR_MD_ASFILES=os_Linux_ia64.s
+        ;;
+    x86_64)
+        if test -n "$USE_64"; then
+            PR_MD_ASFILES=os_Linux_x86_64.s
+        elif test -n "$USE_X32"; then
+            PR_MD_ASFILES=os_Linux_x86_64.s
+            CC="$CC -mx32"
+            CXX="$CXX -mx32"
+        else
+            AC_DEFINE(i386)
+            PR_MD_ASFILES=os_Linux_x86.s
+            CC="$CC -m32"
+            CXX="$CXX -m32"
+        fi
+        ;;
+    ppc|powerpc)
+        PR_MD_ASFILES=os_Linux_ppc.s
+        ;;
+    powerpc64)
+        if test -n "$USE_64"; then
+            CC="$CC -m64"
+            CXX="$CXX -m64"
+        else
+            PR_MD_ASFILES=os_Linux_ppc.s
+        fi
+        ;;
+    esac    
+    ;;
+
+*-mingw*|*-msys*|*-cygwin*|*-mks*)
+    AC_DEFINE(XP_PC)
+    AC_DEFINE(WIN32)
+    PR_MD_ARCH_DIR=windows
+    RESOLVE_LINK_SYMBOLS=1
+
+    if test -n "$GNU_CC"; then
+        CC="$CC -mwindows"
+        CXX="$CXX -mwindows"
+        DLL_SUFFIX=dll
+        MKSHLIB='$(CC) -shared -Wl,--export-all-symbols -Wl,--out-implib -Wl,$(IMPORT_LIBRARY) $(DLLBASE) -o $(subst $(OBJDIR)/,,$(SHARED_LIBRARY))'
+        RC=$WINDRES
+        # Use temp file for windres (bug 213281)
+        RCFLAGS='-O coff --use-temp-file'
+    else
+        LD=link
+        AR='lib -NOLOGO -OUT:"$@"'
+        AR_FLAGS=
+        RANLIB='echo not_ranlib'
+        STRIP='echo not_strip'
+        RC=rc.exe
+        GARBAGE='$(OBJDIR)/vc20.pdb $(OBJDIR)/vc40.pdb'
+        OBJ_SUFFIX=obj
+        LIB_SUFFIX=lib
+        DLL_SUFFIX=dll
+
+        # Determine compiler version
+        changequote(,)
+        _MSVC_VER_FILTER='s|.* \([0-9]\+\.[0-9]\+\.[0-9]\+\(\.[0-9]\+\)\?\).*|\1|p'
+        changequote([,])
+        CC_VERSION=`${CC} -v 2>&1 | sed -ne "$_MSVC_VER_FILTER"`
+        if test -z "$CC_VERSION"; then
+            AC_MSG_ERROR([Could not determine MSC version.])
+        fi
+
+        _CC_MAJOR_VERSION=`echo ${CC_VERSION} | awk -F\. '{ print $1 }'`
+        _CC_MINOR_VERSION=`echo ${CC_VERSION} | awk -F\. '{ print $2 }'`
+        _CC_RELEASE=`echo ${CC_VERSION} | awk -F\. '{ print $3 }'`
+        _CC_BUILD=`echo ${CC_VERSION} | awk -F\. '{ print $4 }'`
+        MSC_VER=${_CC_MAJOR_VERSION}${_CC_MINOR_VERSION}
+
+        if test "$_CC_MAJOR_VERSION" -eq "14"; then
+           dnl -DYNAMICBASE is only supported on VC8SP1 or newer,
+           dnl so be very specific here!
+           dnl VC8 is 14.00.50727.42, VC8SP1 is 14.00.50727.762
+           if test $_CC_RELEASE -gt 50727; then
+              _USE_DYNAMICBASE=1
+           elif test $_CC_BUILD -ge 762; then
+              _USE_DYNAMICBASE=1
+           fi
+           AC_DEFINE(_CRT_SECURE_NO_DEPRECATE)
+           AC_DEFINE(_CRT_NONSTDC_NO_DEPRECATE)
+        elif test $_CC_MAJOR_VERSION -ge 15; then
+           _USE_DYNAMICBASE=1    
+           AC_DEFINE(_CRT_SECURE_NO_WARNINGS)
+           AC_DEFINE(_CRT_NONSTDC_NO_WARNINGS)
+        fi
+
+        if test -n "$_USE_DYNAMICBASE"; then
+           DLLFLAGS="$DLLFLAGS -DYNAMICBASE"
+        fi
+
+        # Ensure that mt is Microsoft (R) Manifest Tool and not magnetic
+        # tape manipulation utility (or something else)
+        if test "$MSC_VER" -ge "1400"; then
+            changequote(,)
+            _MSMT_VER_FILTER='s|.* \([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*|\1|p'
+            changequote([,])
+
+            MSMT_TOOL=`mt 2>&1|grep 'Microsoft (R) Manifest Tool'`
+            if test -n "$MSMT_TOOL"; then
+                MSMANIFEST_TOOL_VERSION=`echo ${MSMT_TOOL}|sed -ne "$_MSMT_VER_FILTER"`
+                if test -z "$MSMANIFEST_TOOL_VERSION"; then
+                    AC_MSG_WARN([Unknown version of the Microsoft (R) Manifest Tool.])
+                fi
+                MT=mt
+                unset MSMT_TOOL
+            else
+                AC_MSG_ERROR([Microsoft (R) Manifest Tool must be in your \$PATH.])
+            fi
+        fi
+        
+        CFLAGS="$CFLAGS -W3 -nologo -GF -Gy"
+        DLLFLAGS="$DLLFLAGS -OUT:\"\$@\""
+        _DEBUG_FLAGS=-Zi
+        _OPTIMIZE_FLAGS=-O2
+
+        PROFILE_GEN_CFLAGS="-GL"
+        PROFILE_GEN_LDFLAGS="-LTCG:PGINSTRUMENT"
+        PROFILE_USE_CFLAGS="-GL -wd4624 -wd4952"
+        PROFILE_USE_LDFLAGS="-LTCG:PGUPDATE"
+
+        if test "$MSC_VER" -ge "1800"; then
+            dnl Visual C++ 2013 requires -FS when parallel building with
+            dnl make -jN. If not specified, compiler sometimes emits C1041
+            dnl error.
+            CFLAGS="$CFLAGS -FS"
+            dnl -Gw can benefit when using linker optimization on PGO.
+            dnl http://blogs.msdn.com/b/vcblog/archive/2013/09/11/introducing-gw-compiler-switch.aspx
+            PROFILE_GEN_CFLAGS="$PROFILE_GEN_CFLAGS -Gw"
+            PROFILE_USE_CFLAGS="$PROFILE_USE_CFLAGS -Gw"
+        fi
+
+        if test -z "$MOZ_OPTIMIZE"; then
+            CFLAGS="$CFLAGS -Od"
+        fi
+
+        if test "$USE_DEBUG_RTL" = 1; then
+            if test -n "$USE_STATIC_RTL"; then
+                CFLAGS="$CFLAGS -MTd"
+            else
+                CFLAGS="$CFLAGS -MDd"
+            fi
+        else
+            if test -n "$USE_STATIC_RTL"; then
+                CFLAGS="$CFLAGS -MT"
+            else
+                CFLAGS="$CFLAGS -MD"
+            fi
+        fi
+
+        if test -n "$MOZ_DEBUG"; then
+            AC_DEFINE(_DEBUG)
+        else
+            DEFINES="$DEFINES -U_DEBUG"
+        fi
+
+        if test -n "$MOZ_DEBUG_SYMBOLS"; then
+            if test -n "$MOZ_OPTIMIZE"; then
+                DLLFLAGS="$DLLFLAGS -DEBUG -OPT:REF"
+                LDFLAGS="$LDFLAGS -DEBUG -OPT:REF"
+            else
+                DLLFLAGS="$DLLFLAGS -DEBUG"
+                LDFLAGS="$LDFLAGS -DEBUG"
+            fi
+        fi
+
+        OS_DLLFLAGS="-nologo -DLL -SUBSYSTEM:WINDOWS"
+        if test "$MSC_VER" -le "1200" -a -z "$MOZ_DEBUG_SYMBOLS"; then
+            OS_DLLFLAGS="$OS_DLLFLAGS -PDB:NONE"
+        fi
+        
+        if test "$OS_TARGET" = "WINNT"; then
+            CFLAGS="$CFLAGS -GT"
+            LIBNSPR='$(dist_libdir)/libnspr$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)'
+            LIBPLC='$(dist_libdir)/libplc$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)'
+        else
+            LIBNSPR='$(dist_libdir)/nspr$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)'
+            LIBPLC='$(dist_libdir)/plc$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)'
+        fi
+    fi # GNU_CC
+
+    if test -n "$USE_STATIC_TLS"; then
+        AC_DEFINE(_PR_USE_STATIC_TLS)
+    fi
+
+    if test "$OS_TARGET" = "WINNT"; then
+        AC_DEFINE(WINNT)
+    else
+        AC_DEFINE(WIN95)
+        # undefine WINNT as some versions of mingw gcc define it by default
+        DEFINES="$DEFINES -UWINNT"
+        AC_DEFINE(_PR_GLOBAL_THREADS_ONLY)
+    fi
+
+    if test "$CPU_ARCH" = "x86"; then
+        CPU_ARCH_TAG=
+    else
+        CPU_ARCH_TAG=$CPU_ARCH
+    fi
+
+    if test "$USE_DEBUG_RTL" = 1; then
+        OBJDIR_SUFFIX=OBJD
+    fi
+
+    case "$OS_TARGET" in
+    WINNT)
+	    MDCPUCFG_H=_winnt.cfg
+	    ;;
+    WIN95)
+	    MDCPUCFG_H=_win95.cfg
+	    ;;
+    *)
+	    AC_MSG_ERROR([Missing OS_TARGET for ${target}.  Use --enable-win32-target to set.])
+   	;;
+    esac
+
+    case "$target_cpu" in
+    i*86)
+	if test -n "$USE_64"; then
+	    AC_DEFINE(_AMD64_)
+	else		
+	    AC_DEFINE(_X86_)
+            if test -z "$GNU_CC" -a "$MSC_VER" -ge "1700"; then
+                dnl Visual C++ 2012 defaults to -arch:SSE2. Use -arch:IA32
+                dnl to avoid requiring SSE2.
+                CFLAGS="$CFLAGS -arch:IA32"
+            fi
+	fi
+        ;;
+    x86_64)
+	    AC_DEFINE(_AMD64_)
+	    USE_64=1
+	    ;;
+    ia64)
+	    AC_DEFINE(_IA64_)
+	    USE_64=1
+	    ;;
+    *)
+	    AC_DEFINE(_CPU_ARCH_NOT_DEFINED)
+	    ;;
+    esac
+    ;;
+
+*-netbsd*)
+    AC_DEFINE(XP_UNIX)
+    AC_DEFINE(NETBSD)
+    AC_DEFINE(HAVE_BSD_FLOCK)
+    AC_DEFINE(HAVE_SOCKLEN_T)
+    if test -z "$USE_NSPR_THREADS"; then
+        USE_PTHREADS=1
+    fi
+    MDCPUCFG_H=_netbsd.cfg
+    PR_MD_CSRCS=netbsd.c
+
+    DSO_CFLAGS='-fPIC -DPIC'
+    CFLAGS="$CFLAGS -ansi -Wall"
+    CXXFLAGS="$CXXFLAGS -ansi -Wall"
+    MKSHLIB='$(CC) -o $@ $(DSO_LDOPTS)'
+
+    if test -z "$OBJECT_FMT"; then
+        if echo __ELF__ | ${CC-cc} -E - | grep -q __ELF__ 2>/dev/null; then
+            OBJECT_FMT=a.out
+            DLL_SUFFIX=so.1.0
+            DSO_LDOPTS='-shared'
+        else
+            OBJECT_FMT=ELF
+            DLL_SUFFIX=so
+            DSO_LDOPTS='-shared -Wl,-soname,$(notdir $@)'
+        fi
+    fi
+
+    if test "$LIBRUNPATH"; then
+        DSO_LDOPTS="$DSO_LDOPTS -Wl,-R$LIBRUNPATH"
+    fi
+    ;;
+
+*-nto*)
+    AC_DEFINE(XP_UNIX)
+    AC_DEFINE(NTO)
+    AC_DEFINE(_QNX_SOURCE)
+    AC_DEFINE(HAVE_POINTER_LOCALTIME_R)
+    MDCPUCFG_H=_nto.cfg
+    PR_MD_CSRCS=nto.c
+    MKSHLIB='$(CC) $(DSO_LDOPTS) -Wl,-soname -Wl,$(notdir $@) -o $@'
+    DSO_CFLAGS=-fPIC
+    DSO_LDOPTS=-shared
+    OS_LIBS="$OS_LIBS -lsocket"
+    _OPTIMIZE_FLAGS="-O1"
+    _DEBUG_FLAGS="-gstabs"
+	;;
+
+*-openbsd*)
+    AC_DEFINE(XP_UNIX)
+    AC_DEFINE(OPENBSD)
+    AC_DEFINE(HAVE_BSD_FLOCK)
+    AC_DEFINE(HAVE_SOCKLEN_T)
+    CFLAGS="$CFLAGS -ansi -Wall"
+    CXXFLAGS="$CXXFLAGS -ansi -Wall"
+    DLL_SUFFIX=so.1.0
+    DSO_CFLAGS=-fPIC
+    MDCPUCFG_H=_openbsd.cfg
+    PR_MD_CSRCS=openbsd.c
+    OS_LIBS="-lc"
+    if test -z "$USE_NSPR_THREADS"; then
+        USE_PTHREADS=1
+    fi
+    DSO_LDOPTS='-shared -fPIC -Wl,-soname,$(notdir $@)'
+    MKSHLIB='$(CC) $(DSO_LDOPTS) -o $@'
+    ;;
+
+*-osf*)
+    SHELL_OVERRIDE="SHELL		= /usr/bin/ksh"
+    AC_DEFINE(XP_UNIX)
+    AC_DEFINE(OSF1)
+    AC_DEFINE(_REENTRANT)
+    # OSF1 and HPUX report the POLLHUP event for a socket when the
+    # shutdown(SHUT_WR) operation is called for the remote end, even though
+    # the socket is still writeable. Use select(), instead of poll(), to
+    # workaround this problem.
+    AC_DEFINE(_PR_POLL_WITH_SELECT)
+
+    if echo "$OS_RELEASE" | egrep -c '(V2.0|V3.2)' 2>/dev/null ; then
+        USE_NSPR_THREADS=1
+    fi
+
+    if test -z "$GNU_CC"; then
+        CC="$CC -std1 -ieee_with_inexact"
+        if test "$OS_RELEASE" != "V2.0"; then
+            CC="$CC -readonly_strings"
+        fi
+        _OPTIMIZE_FLAGS="$_OPTIMIZE_FLAGS -Olimit 4000"
+        AC_CHECK_HEADER(machine/builtins.h, AC_DEFINE(OSF1_HAVE_MACHINE_BUILTINS_H))
+    else
+        CFLAGS="$CFLAGS -mieee"
+        CXXFLAGS="$CXXFLAGS -mieee"
+    fi
+
+    if echo $OS_RELEASE | egrep -c '(V2.0|V3.2)' 2>/dev/null; then
+        AC_DEFINE(HAVE_INT_LOCALTIME_R)
+    else
+        AC_DEFINE(HAVE_FCNTL_FILE_LOCKING)
+        AC_DEFINE(HAVE_POINTER_LOCALTIME_R)
+    fi
+    if echo $OS_RELEASE | grep -c V4.0 >/dev/null; then
+        AC_DEFINE(OSF1V4_MAP_PRIVATE_BUG)
+    fi
+    DSO_LDOPTS='-shared -all -expect_unresolved "*" -soname $(notdir $@)'
+    MDCPUCFG_H=_osf1.cfg
+    PR_MD_CSRCS=osf1.c
+    ;;
+
+*-qnx*)
+    AC_DEFINE(XP_UNIX)
+    AC_DEFINE(QNX)
+    AC_DEFINE(_PR_NEED_H_ERRNO)
+    USE_NSPR_THREADS=1
+    MDCPUCFG_H=_qnx.cfg
+    PR_MD_CSRCS=qnx.c
+    ;;
+
+*-riscos*)
+    AC_DEFINE(XP_UNIX)
+    AC_DEFINE(RISCOS)
+    AC_DEFINE(_PR_NEED_H_ERRNO)
+    USE_PTHREADS=1
+    MDCPUCFG_H=_riscos.cfg
+    PR_MD_CSRCS=riscos.c
+    DSO_CFLAGS=-fPIC
+    DSO_LDOPTS='-shared -Wl,-soname -Wl,$(notdir $@)'
+    MKSHLIB='$(CC) $(DSO_LDOPTS) -o $@'
+    ;;
+
+*-*-sco*)
+    AC_DEFINE(XP_UNIX)
+    AC_DEFINE(SCO)
+    AC_DEFINE(sco)
+    AC_DEFINE(SYSV)
+    AC_DEFINE(_SVID3)
+    AC_DEFINE(_PR_NEED_H_ERRNO)
+    CC='cc -b elf -KPIC'
+    CXX='$(NSDEPTH)/build/hcpp CC +.cpp +w'
+    USE_NSPR_THREADS=1
+    CPU_ARCH=x86
+    DSO_LDOPTS='-b elf -G'
+    MDCPUCFG_H=_scoos.cfg
+    PR_MD_SRCS=scoos.c
+    ;;
+
+*-solaris*)
+    if test -z "$USE_NSPR_THREADS"; then
+        USE_PTHREADS=1
+    fi
+    AC_DEFINE(XP_UNIX)
+    AC_DEFINE(SVR4)
+    AC_DEFINE(SYSV)
+    AC_DEFINE(__svr4)
+    AC_DEFINE(__svr4__)
+    AC_DEFINE(SOLARIS)
+    AC_DEFINE(HAVE_FCNTL_FILE_LOCKING)
+    CPU_ARCH=`uname -p`
+    MDCPUCFG_H=_solaris.cfg
+    PR_MD_CSRCS=solaris.c
+    LD=/usr/ccs/bin/ld
+    MKSHLIB='$(CC) $(DSO_LDOPTS) -o $@'
+    RESOLVE_LINK_SYMBOLS=1
+    case "${OS_RELEASE}" in
+    5.8|5.9)
+        ;;
+    *)
+        # It is safe to use the -Bdirect linker flag on Solaris 10 or later.
+        USE_B_DIRECT=1
+        ;;
+    esac
+    if test -n "$GNU_CC"; then
+        DSO_CFLAGS=-fPIC
+        if `$CC -print-prog-name=ld` -v 2>&1 | grep -c GNU >/dev/null; then
+            GCC_USE_GNU_LD=1
+        fi
+        DSO_LDOPTS='-shared -Wl,-h,$(notdir $@),-z,combreloc,-z,defs,-z,ignore' 
+        if test -n "$USE_B_DIRECT"; then
+            DSO_LDOPTS="$DSO_LDOPTS,-Bdirect"
+        fi
+    else
+        DSO_CFLAGS=-KPIC
+        DSO_LDOPTS='-G -h $(notdir $@) -z combreloc -z defs -z ignore'
+        if test -n "$USE_B_DIRECT"; then
+            DSO_LDOPTS="$DSO_LDOPTS -Bdirect"
+        fi
+    fi
+    if test -n "$GNU_CC"; then
+        CFLAGS="$CFLAGS -Wall"
+        CXXFLAGS="$CXXFLAGS -Wall"
+        if test -n "$USE_MDUPDATE"; then
+            CFLAGS="$CFLAGS -MDupdate \$(DEPENDENCIES)"
+            CXXFLAGS="$CXXFLAGS -MDupdate \$(DEPENDENCIES)"
+        fi
+        GCC_AS=`$CC -print-prog-name=as`
+        if test "`echo | $GCC_AS -v 2>&1 | grep -c GNU`" != "0"; then
+            GNU_AS=1
+        fi
+    else
+        CFLAGS="$CFLAGS -xstrconst"
+        CXXFLAGS="$CXXFLAGS -Qoption cg -xstrconst -features=tmplife"
+        if test -z "$MOZ_OPTIMIZE"; then
+            CFLAGS="$CFLAGS -xs"
+            CXXFLAGS="$CXXFLAGS -xs"
+        fi
+        _OPTIMIZE_FLAGS=-xO4
+    fi
+    if test -z "$GNU_AS"; then
+        ASFLAGS="$ASFLAGS -Wa,-P"
+    fi
+    if test -n "$USE_64"; then
+        if test -n "$GNU_CC"; then
+            CC="$CC -m64"
+            CXX="$CXX -m64"
+        else
+            if test "$OS_TEST" = "i86pc"; then
+                CC="$CC -xarch=amd64"
+                CXX="$CXX -xarch=amd64"
+            else
+                CC="$CC -xarch=v9"
+                CXX="$CXX -xarch=v9"
+            fi
+        fi
+    fi
+    if test "$OS_TEST" = "i86pc"; then
+        if test -z "$USE_64"; then
+            AC_DEFINE(i386)
+        fi
+        CPU_ARCH_TAG=_$OS_TEST
+        # The default debug format, DWARF (-g), is not supported by gcc
+        # on i386-ANY-sysv4/solaris, but the stabs format is.  It is
+        # assumed that the Solaris assembler /usr/ccs/bin/as is used.
+        # If your gcc uses GNU as, you do not need the -Wa,-s option.
+        if test -n "$MOZ_DEBUG" && test -n "$GNU_CC"; then
+            _DEBUG_FLAGS=-gstabs
+            if test -z "$GNU_AS"; then
+                _DEBUG_FLAGS="$_DEBUG_FLAGS -Wa,-s"
+            fi
+        fi
+    fi
+    case "${target_os}" in
+    solaris2.3*)
+        AC_DEFINE(_PR_NO_LARGE_FILES)
+        ;;
+    solaris2.4*)
+        AC_DEFINE(_PR_NO_LARGE_FILES)
+        ;;
+    solaris2.5*)
+        AC_DEFINE(SOLARIS2_5)    
+        ;;
+    *)
+        AC_DEFINE(_PR_HAVE_OFF64_T)
+        # The lfcompile64(5) man page on Solaris 2.6 says:
+        #     For applications that do not wish to conform to the POSIX or
+        #     X/Open  specifications,  the  64-bit transitional interfaces
+        #     are available by default.  No compile-time flags need to  be
+        #     set.
+        # But gcc 2.7.2.x fails to define _LARGEFILE64_SOURCE by default.
+        # The native compiler, gcc 2.8.x, and egcs don't have this problem.
+        if test -n "$GNU_CC"; then
+            AC_DEFINE(_LARGEFILE64_SOURCE)
+        fi
+        ;;
+    esac
+    case "${target_os}" in
+    solaris2.3*)
+        ;;
+    solaris2.4*)
+        ;;
+    solaris2.5*)
+        ;;
+    solaris2.6*)
+        ;;
+    solaris2.7*)
+        ;;
+    *)
+        # Solaris 8 or higher has IPv6.
+        AC_DEFINE(_PR_INET6)
+        ;;
+    esac
+    if test "$CPU_ARCH" = "sparc"; then
+        # 64-bit Solaris SPARC requires V9 architecture, so the following
+        # is not needed.
+        if test -z "$USE_64"; then
+            ULTRASPARC_LIBRARY=nspr_flt
+        fi
+    fi
+    # Purify requires that binaries linked against nspr also
+    # be linked against -lrt (or -lposix4) so add it to OS_LIBS
+    _rev=`uname -r`
+    _librt=`echo $_rev 5.6 | awk '{ if ($1 > $2) print "-lrt"; else print "-lposix4" }'`
+    OS_LIBS="$OS_LIBS $_librt"
+    ;;
+
+*-sco-sysv5*)
+    AC_DEFINE(XP_UNIX)
+    AC_DEFINE(UNIXWARE)
+    AC_DEFINE(SVR4)
+    AC_DEFINE(SYSV)
+    USE_NSPR_THREADS=1
+    if echo $OS_RELEASE | grep -c 2.1 2>/dev/null; then
+        AC_DEFINE(_PR_NO_LARGE_FILES)
+        CC='$(NSDEPTH)/build/hcc cc'
+        CXX='$(NSDEPTH)/build/hcpp CC'
+        MDCPUCFG_H=_unixware.cfg
+    else
+        AC_DEFINE(_LARGEFILE64_SOURCE)
+        AC_DEFINE(_PR_HAVE_OFF64_T)
+        AC_DEFINE(_PR_HAVE_SOCKADDR_LEN)
+        MDCPUCFG_H=_unixware7.cfg
+    fi
+    PR_MD_CSRCS=unixware.c
+    DSO_LDOPTS=-G
+    CPU_ARCH=x86
+    ;;
+
+*-symbian*)
+    AC_ARG_WITH(symbian-sdk,
+    [  --with-symbian-sdk=SYMBIAN_SDK_DIR
+                          The path to the Symbian SDK],
+    SYMBIAN_SDK_DIR=$withval)
+
+    echo -----------------------------------------------------------------------------
+    echo Building with Symbian SDK in: $SYMBIAN_SDK_DIR
+    echo -----------------------------------------------------------------------------
+
+    AC_DEFINE(XP_UNIX)
+    AC_DEFINE(SYMBIAN)
+    AC_DEFINE(__arm__)
+    AC_DEFINE(__SYMBIAN32__)
+    AC_DEFINE(_UNICODE)
+    AC_DEFINE(NDEBUG)
+    AC_DEFINE(__SUPPORT_CPP_EXCEPTIONS__)
+    AC_DEFINE(MOZ_STDERR_TO_STDOUT)
+    AC_DEFINE(HAVE_FCNTL_FILE_LOCKING)
+    AC_DEFINE(HAVE_SOCKLEN_T)
+    USE_PTHREADS=1
+    LIB_SUFFIX=lib
+    DLL_SUFFIX=dll
+    MKSHLIB=
+    DSO_LDOPTS=
+    DSO_CFLAGS=
+    VISIBILITY_FLAGS=
+    MDCPUCFG_H=_symbian.cfg
+    PR_MD_CSRCS=symbian.c
+    NSINSTALL=nsinstall
+    RANLIB='echo no ranlib '
+    CPU_ARCH=ARM
+    OS_ARCH=SYMBIAN
+    OS_EXE_CFLAGS="$OS_EXE_CFLAGS -D__EXE__"
+    CFLAGS="$CFLAGS -MD -nostdinc"
+    SYMBIAN_SYS_INCLUDE="-I$SYMBIAN_SDK_DIR/Epoc32/include/variant -I$SYMBIAN_SDK_DIR/Epoc32/include -I$SYMBIAN_SDK_DIR/Epoc32/include/stdapis"
+    echo -------------------------------------------------------
+    echo SYMBIAN_SYS_INCLUDE is: $SYMBIAN_SYS_INCLUDE
+    echo -------------------------------------------------------
+    case "$OS_TARGET" in
+    WINSCW)
+        CC=mwccsym2.exe
+        CXX=mwccsym2.exe
+        LD=mwldsym2.exe
+        AR=mwldsym2.exe
+        WINSCW_LD_DIR="\$(SYMBIAN_SDK_DIR)/EPOC32/RELEASE/WINSCW/UDEB"
+        CFLAGS="$CFLAGS -O0 -inline off -wchar_t off -align 4 -warnings on -w nohidevirtual,nounusedexpr -msgstyle gcc -enum int -str pool -exc ms -trigraphs on -nostderr -gccdep -cwd source -i- -I\$(VPATH)"
+        SYMBIAN_SYS_INCLUDE="$SYMBIAN_SYS_INCLUDE -include Symbian_OS_v9.2.hrh"
+        AR_FLAGS="-library -msgstyle gcc -stdlib -subsystem windows -noimplib -o \$@"
+        AC_DEFINE(_DEBUG)
+        AC_DEFINE(__CW32__)
+        AC_DEFINE(__WINS__)
+        AC_DEFINE(__WINSCW__)
+        DEFINES="$DEFINES -U_WIN32"
+	    ;;
+    GCCE)
+        CFLAGS="$CFLAGS -Wall -Wno-unknown-pragmas -fexceptions -march=armv5t -mapcs -pipe -x c -msoft-float"
+        CXXFLAGS="$CXXFLAGS $CFLAGS -Wno-ctor-dtor-privacy"
+        SYMBIAN_SYS_INCLUDE="$SYMBIAN_SYS_INCLUDE -include $SYMBIAN_SDK_DIR/EPOC32/INCLUDE/GCCE/GCCE.h"
+        AC_DEFINE(__GCCE__)
+        AC_DEFINE(__EABI__)
+        DEFINES="$DEFINES -D__PRODUCT_INCLUDE__=$SYMBIAN_SDK_DIR/Epoc32/include/variant/Symbian_OS_v9.2.hrh"
+	    ;;
+    *)
+	    AC_MSG_ERROR([Missing OS_TARGET for ${target}. Set --enable-symbian-target to with 'WINSCW' or 'GCCE'.])
+   	;;
+    esac
+    CFLAGS="$CFLAGS ${SYMBIAN_SYS_INCLUDE}"
+    ;;
+
+*-os2*)
+    AC_DEFINE(XP_OS2)
+    AC_DEFINE(XP_PC)
+    AC_DEFINE(BSD_SELECT)
+    AC_DEFINE(TCPV40HDRS)
+    LIB_SUFFIX=lib
+    DLL_SUFFIX=dll
+    RC=rc.exe
+    PR_MD_ARCH_DIR=os2
+    PROG_SUFFIX=.exe
+    NSINSTALL=nsinstall
+    MDCPUCFG_H=_os2.cfg
+    RESOLVE_LINK_SYMBOLS=1
+
+    AC_DEFINE(OS2)
+    AR=emxomfar
+    AR_FLAGS='r $@'
+    CFLAGS="$CFLAGS -Wall -Zomf"
+    CXXFLAGS="$CFLAGS -Wall -Zomf"
+    MKSHLIB='$(CC) $(DSO_LDOPTS) -o $@'
+    DSO_CFLAGS=
+    DSO_LDOPTS='-Zomf -Zdll'
+    LDFLAGS='-Zmap'
+    _OPTIMIZE_FLAGS="-O2 -s"
+    _DEBUG_FLAGS="-g -fno-inline"
+    if test -n "$MOZ_OPTIMIZE"; then
+      DSO_LDOPTS="$DSO_LDOPTS -Zlinker /EXEPACK:2 -Zlinker /PACKCODE -Zlinker /PACKDATA"
+    fi
+    IMPLIB='emximp -o'
+    FILTER='emxexp -o'
+    if test -n "$MOZ_OS2_HIGH_MEMORY"; then
+      LDFLAGS="$LDFLAGS -Zhigh-mem"
+      AC_DEFINE(MOZ_OS2_HIGH_MEMORY)
+    fi
+
+    # GCC for OS/2 currently predefines these, but we don't want them
+    DEFINES="$DEFINES -Uunix -U__unix -U__unix__"
+    ;;
+
+*)
+    AC_DEFINE(XP_UNIX)
+    ;;
+   
+esac
+
+if test -z "$SKIP_LIBRARY_CHECKS"; then
+dnl ========================================================
+dnl Check for system libraries
+dnl ========================================================
+
+
+dnl We don't want anything to link with libdl even if it's present on OS X, 
+dnl since it's not used and not part of the default installation.
+dnl The same goes for BeOS.
+dnl OS/2 has dlfcn in libc.
+
+case $target in
+*-darwin*|*-beos*|*-os2*)
+    ;;
+*)
+    AC_CHECK_LIB(dl, dlopen,
+        [AC_CHECK_HEADER(dlfcn.h,
+            OS_LIBS="-ldl $OS_LIBS")])
+    ;;
+esac
+
+
+dnl ========================================================
+dnl Check for system header files.
+dnl ========================================================
+
+dnl ========================================================
+dnl Check for typedefs and structs
+dnl ========================================================
+
+dnl ========================================================
+dnl Checks for library functions.
+dnl ========================================================
+AC_PROG_GCC_TRADITIONAL
+_SAVE_LIBS="$LIBS"
+LIBS="$LIBS $OS_LIBS"
+AC_CHECK_FUNCS(dladdr gettid lchown setpriority strerror syscall dnl
+ secure_getenv __secure_getenv)
+LIBS="$_SAVE_LIBS"
+
+dnl ========================================================
+dnl Check options
+dnl ========================================================
+
+dnl ======================================================
+dnl = Enable compiling with ccache
+dnl ======================================================
+AC_ARG_WITH(ccache,
+[  --with-ccache[=path/to/ccache]
+                          Enable compiling with ccache],
+    CCACHE=$withval, CCACHE="no")
+
+if test "$CCACHE" != "no"; then
+    if test -n "$CCACHE"; then
+        if test "$CCACHE" = "yes"; then
+            CCACHE=
+        else
+            if test ! -e "$CCACHE"; then
+                AC_MSG_ERROR([$CCACHE not found])
+            fi
+        fi
+    fi
+    AC_PATH_PROGS(CCACHE, $CCACHE ccache)
+    if test -z "$CCACHE" -o "$CCACHE" = ":"; then
+        AC_MSG_ERROR([ccache not found])
+    elif test -x "$CCACHE"; then
+        CC="$CCACHE $CC"
+        CXX="$CCACHE $CXX"
+    else
+        AC_MSG_ERROR([$CCACHE is not executable])
+    fi
+fi
+
+dnl ========================================================
+dnl =
+dnl = --enable-strip
+dnl = 
+dnl = Enable stripping of libs and executables
+dnl = 
+dnl ========================================================
+AC_ARG_ENABLE(strip,
+    [  --enable-strip          Enable stripping of shared libs and programs],
+    [ if test "$enableval" = "yes"; then
+	    ENABLE_STRIP=1
+      fi ])
+
+dnl Check for hpux options
+case "${target_os}" in
+hpux*)
+if test -z "$GNU_CC"; then
+
+    AC_CACHE_CHECK(for +Olit support,
+        ac_cv_hpux_usable_olit_option,
+        dnl since aCC doesn't throw an error on invalid options,
+        dnl we have to test this the hard way
+        [ac_cv_hpux_usable_olit_option=no
+        rm -f conftest*
+        echo 'int main() { return 0; }' | cat > conftest.c
+        ${CC-cc} ${CFLAGS} +Olit=all -o conftest conftest.c > conftest.out 2>&1
+        if test $? -eq 0; then
+            if test -z "`egrep -i '(unrecognize|unknown)' conftest.out`"; then
+                ac_cv_hpux_usable_olit_option=yes
+            fi
+        fi
+        rm -f conftest*
+        ])
+
+    if test "$ac_cv_hpux_usable_olit_option" = "yes"; then
+        CFLAGS="$CFLAGS +Olit=all"
+        CXXFLAGS="$CXXFLAGS +Olit=all"
+    else
+        CFLAGS="$CFLAGS +ESlit"
+        CXXFLAGS="$CXXFLAGS +ESlit"
+    fi
+fi
+;;
+esac
+
+case "$target_os" in
+darwin*)
+    _HAVE_PTHREADS=1
+    ;;
+*)
+    AC_CHECK_LIB(pthreads, pthread_create,
+        _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthreads",
+        AC_CHECK_LIB(pthread, pthread_create,
+            _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthread",
+            AC_CHECK_LIB(c_r, pthread_create,
+                _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lc_r",
+                AC_CHECK_LIB(c, pthread_create,
+                    _HAVE_PTHREADS=1
+                )
+            )
+        )
+    )
+    ;;
+esac
+
+AC_ARG_WITH(pthreads,
+    [  --with-pthreads         Use system pthreads library as thread subsystem],
+    [ if test "$withval" = "yes"; then
+	    if test -n "$_HAVE_PTHREADS"; then
+		    USE_PTHREADS=1 
+		    USE_USER_PTHREADS=
+		    USE_NSPR_THREADS=
+	    else
+		    AC_MSG_ERROR([ --with-pthreads specified for a system without pthread support ]);
+	    fi
+	  else
+	    USE_PTHREADS=
+	    _PTHREAD_LDFLAGS=
+	  fi],
+	[ if test -n "$_HAVE_PTHREADS" && test -z "$USE_USER_PTHREADS" && test -z "$USE_NSPR_THREADS"; then
+	    USE_PTHREADS=1
+	    USE_USER_PTHREADS=
+	    USE_NSPR_THREADS=
+	  fi])
+
+AC_ARG_ENABLE(user-pthreads,
+    [  --enable-user-pthreads  Build using userland pthreads],
+    [ if test "$enableval" = "yes"; then
+        if test -n "$_HAVE_PTHREADS"; then
+		    USE_PTHREADS=
+		    USE_USER_PTHREADS=1
+		    USE_NSPR_THREADS=
+	    else
+		    AC_MSG_ERROR([ --enable-user-pthreads specified for a system without pthread support ]);
+	    fi
+	  fi])
+
+AC_ARG_ENABLE(nspr-threads,
+    [  --enable-nspr-threads   Build using classic nspr threads],
+    [ if test "$enableval" = "yes"; then
+	    USE_PTHREADS=
+	    USE_USER_PTHREADS=
+	    USE_NSPR_THREADS=1
+	  fi])
+
+case "$target" in
+*-beos*)
+    AC_ARG_WITH(bthreads,
+    [  --with-bthreads         Use system bthreads library as thread subsystem
+                          (BeOS only)],
+    [	if test "$withval" = "yes"; then
+    	    USE_BTHREADS=1
+	        USE_USER_PTHREADS=
+	        USE_PTHREADS=
+	    fi])
+    ;;
+esac
+
+fi # SKIP_LIBRARY_CHECKS
+
+AC_ARG_ENABLE(ipv6,
+    [  --enable-ipv6           Compile ipv6 support],
+    [ if test "$enableval" = "yes"; then
+	    USE_IPV6=1
+      else
+	    USE_IPV6=
+      fi])
+
+if test -n "$USE_PTHREADS"; then
+   dnl See if -pthread is supported.
+   rm -f conftest*
+   ac_cv_have_dash_pthread=no
+   AC_MSG_CHECKING(whether ${CC-cc} accepts -pthread)
+   echo 'int main() { return 0; }' | cat > conftest.c
+   ${CC-cc} -pthread -o conftest conftest.c > conftest.out 2>&1
+   if test $? -eq 0; then
+	if test -z "`egrep -i '(unrecognize|unknown)' conftest.out | grep pthread`" && test -z "`egrep -i '(error|incorrect)' conftest.out`" ; then
+	    ac_cv_have_dash_pthread=yes
+		case "$target_os" in
+	    freebsd*)
+# Freebsd doesn't use -pthread for compiles, it uses them for linking
+            ;;
+	    *)
+            CFLAGS="$CFLAGS -pthread"
+            CXXFLAGS="$CXXFLAGS -pthread"
+            ;;
+        esac
+	fi
+    fi
+    rm -f conftest*
+    AC_MSG_RESULT($ac_cv_have_dash_pthread)
+
+	dnl
+	dnl See if -pthreads is supported.
+	dnl
+    ac_cv_have_dash_pthreads=no
+    if test "$ac_cv_have_dash_pthread" = "no"; then
+	    AC_MSG_CHECKING(whether ${CC-cc} accepts -pthreads)
+    	echo 'int main() { return 0; }' | cat > conftest.c
+	    ${CC-cc} -pthreads -o conftest conftest.c > conftest.out 2>&1
+    	if test $? -eq 0; then
+	    	if test -z "`egrep -i '(unrecognize|unknown)' conftest.out | grep pthreads`" && test -z "`egrep -i '(error|incorrect)' conftest.out`" ; then
+			    ac_cv_have_dash_pthreads=yes
+			    CFLAGS="$CFLAGS -pthreads"
+			    CXXFLAGS="$CXXFLAGS -pthreads"
+		    fi
+	    fi
+	    rm -f conftest*
+    	AC_MSG_RESULT($ac_cv_have_dash_pthreads)
+    fi
+
+    case "$target" in
+    *-solaris*)
+        if test "$ac_cv_have_dash_pthreads" = "yes"; then
+            _PTHREAD_LDFLAGS=
+        fi
+	    ;;
+    *-freebsd*)
+	    AC_DEFINE(_REENTRANT)
+	    AC_DEFINE(_THREAD_SAFE)
+	    dnl -pthread links in -lc_r, so don't specify it explicitly.
+	    if test "$ac_cv_have_dash_pthread" = "yes"; then
+	        _PTHREAD_LDFLAGS="-pthread"
+	    else
+	        _PTHREAD_LDFLAGS="-lc_r"
+	    fi
+	    ;;
+    *-netbsd*)
+	    if test "$ac_cv_have_dash_pthread" = "yes"; then
+	        _PTHREAD_LDFLAGS="-pthread"
+	    fi
+	    ;;
+    *-bsdi*)
+	    AC_DEFINE(_THREAD_SAFE)
+	    dnl -pthread links in -lc_r, so don't specify it explicitly.
+	    if test "$ac_cv_have_dash_pthread" = "yes"; then
+	        _PTHREAD_LDFLAGS=
+	    fi
+	    ;;
+    *-openbsd*)
+        if test "$ac_cv_have_dash_pthread" = "yes"; then
+            _PTHREAD_LDFLAGS=-pthread
+        fi
+        ;;
+    *-linux*|*-gnu*|*-k*bsd*-gnu)
+        AC_DEFINE(_REENTRANT)
+        ;;
+    esac
+
+else 
+    if test -n "$USE_USER_PTHREADS"; then
+	    USE_PTHREADS=
+	    USE_NSPR_THREADS=
+    else
+        _PTHREAD_LDFLAGS=
+    fi
+fi
+dnl Special thread exceptions
+
+case "$target" in
+*-aix*)
+    if test -n "$USE_NSPR_THREADS"; then
+        AC_DEFINE(_PR_LOCAL_THREADS_ONLY)
+    fi
+    case "$target_os" in
+    aix4.1*)
+        if test -z "$USE_PTHREADS"; then
+            AC_DEFINE(AIX_RENAME_SELECT)
+        fi
+        ;;
+    aix4.2*)
+        if test -z "$USE_NSPR_THREADS"; then
+            AC_DEFINE(HAVE_POINTER_LOCALTIME_R)
+        fi
+        ;;
+    aix4.3*)
+        if test -z "$USE_NSPR_THREADS"; then
+            AC_DEFINE(HAVE_POINTER_LOCALTIME_R)
+        fi
+        if test -n "$USE_PTHREADS"; then
+            AC_DEFINE(_PR_HAVE_THREADSAFE_GETHOST)
+        fi
+        ;;
+    *)
+        if test -z "$USE_NSPR_THREADS"; then
+            AC_DEFINE(HAVE_POINTER_LOCALTIME_R)
+        fi
+        if test -n "$USE_PTHREADS"; then
+            AC_DEFINE(_PR_HAVE_THREADSAFE_GETHOST)
+        fi
+        ;;
+    esac
+    ;;
+*-bsdi*)
+    if test -n "$USE_PTHREADS"; then
+        AC_DEFINE(_PR_NEED_PTHREAD_INIT)
+    fi
+    ;;
+*-freebsd*)
+    if test -n "$USE_NSPR_THREADS"; then
+        AC_DEFINE(_PR_LOCAL_THREADS_ONLY)
+    fi
+    ;;
+*-hpux*)
+    if test -n "$USE_NSPR_THREADS"; then
+        AC_DEFINE(_PR_LOCAL_THREADS_ONLY)
+    fi 
+    if test "$USE_PTHREADS"; then
+        if echo "$OS_RELEASE" | egrep '^(B.10.10|B.10.20)' >/dev/null; then
+            AC_DEFINE(_REENTRANT)
+            AC_DEFINE(_PR_DCETHREADS)
+        else
+            AC_DEFINE_UNQUOTED(_POSIX_C_SOURCE,199506L)
+            AC_DEFINE(_PR_HAVE_THREADSAFE_GETHOST)
+        fi
+    fi
+    if test "$USE_USER_PTHREADS"; then
+        AC_DEFINE_UNQUOTED(_POSIX_C_SOURCE,199506L)
+    fi
+    ;;
+*-irix*)
+    if test "${target_os}" = "irix6.5"; then
+        if test -n "$USE_PTHREADS"; then
+            AC_DEFINE(_PR_HAVE_GETHOST_R)
+            AC_DEFINE(_PR_HAVE_GETHOST_R_POINTER)
+        fi
+    fi
+    ;;
+*-linux*|*-gnu*|*-k*bsd*-gnu)
+    if test -n "$USE_NSPR_THREADS"; then
+        AC_DEFINE(_PR_LOCAL_THREADS_ONLY)
+    fi
+    ;;
+*-mingw*|*-msys*|*-cygwin*|*-mks*|*-os2*|*-beos*)
+    dnl win32, os2 & beos cannot use pthreads
+    USE_PTHREADS=
+    _PTHREAD_LDFLAGS=
+    USE_USER_PTHREADS=
+    ;;
+*-netbsd*|*-openbsd*)
+    if test -n "$USE_NSPR_THREADS"; then
+        AC_DEFINE(_PR_LOCAL_THREADS_ONLY)
+    fi
+    ;;
+*-osf*)
+    if test -n "$USE_NSPR_THREADS"; then
+        AC_DEFINE(_PR_LOCAL_THREADS_ONLY)
+    fi
+    if test -n "$USE_PTHREADS"; then
+        if echo $OS_RELEASE | egrep -c '(V2.0|V3.2)' 2>/dev/null; then
+            :
+        else
+            AC_DEFINE(_PR_HAVE_THREADSAFE_GETHOST)
+        fi
+    fi
+    ;;
+*-solaris*)
+    if test -n "$USE_NSPR_THREADS"; then
+        AC_DEFINE(_PR_LOCAL_THREADS_ONLY)
+    fi
+    if test -n "$USE_PTHREADS"; then
+        AC_DEFINE(_REENTRANT)
+        AC_DEFINE(HAVE_POINTER_LOCALTIME_R)
+        if test "$OS_TEST" = "i86pc"; then
+            if test -n "$USE_64"; then
+               PR_MD_ASFILES=os_SunOS_x86_64.s
+            else
+               PR_MD_ASFILES=os_SunOS_x86.s
+            fi
+        else
+            if test -n "$USE_64"; then
+                PR_MD_ASFILES=os_SunOS_sparcv9.s
+            fi
+        fi
+    fi
+    ;;
+*-nto*)
+    if test -n "$USE_PTHREADS"; then
+        AC_DEFINE(_PR_HAVE_GETHOST_R)
+        AC_DEFINE(_PR_HAVE_GETHOST_R_POINTER)
+    fi
+    ;;
+esac
+
+OS_LIBS="$_PTHREAD_LDFLAGS $OS_LIBS"
+
+dnl If the user passed in arg to --enable-optimize or --enable-debug,
+dnl make sure that we use it.
+if test -n "$_SAVE_OPTIMIZE_FLAGS"; then
+    _OPTIMIZE_FLAGS="$_SAVE_OPTIMIZE_FLAGS"
+fi
+
+if test -n "$_SAVE_DEBUG_FLAGS"; then
+    _DEBUG_FLAGS="$_SAVE_DEBUG_FLAGS"
+fi
+
+if test -n "$MOZ_OPTIMIZE"; then
+    CFLAGS="$CFLAGS $_OPTIMIZE_FLAGS"
+    CXXFLAGS="$CXXFLAGS $_OPTIMIZE_FLAGS"
+fi
+
+if test -n "$MOZ_DEBUG_SYMBOLS"; then
+    CFLAGS="$CFLAGS $_DEBUG_FLAGS"
+    CXXFLAGS="$CXXFLAGS $_DEBUG_FLAGS"
+fi
+
+if test -n "$MOZ_OPTIMIZE"; then
+    OBJDIR_TAG=_OPT
+else
+    OBJDIR_TAG=_DBG
+fi
+
+if test -n "$USE_64"; then
+    COMPILER_TAG=_64
+fi
+
+RELEASE_OBJDIR_NAME="${OS_CONFIG}${CPU_ARCH_TAG}${COMPILER_TAG}${IMPL_STRATEGY}${OBJDIR_TAG}.${OBJDIR_SUFFIX}"
+
+dnl ========================================================
+dnl Use cygwin wrapper for win32 builds, except MSYS/MinGW
+dnl ========================================================
+case "$target_os" in
+cygwin*|mks*)
+    CC="\$(CYGWIN_WRAPPER) $CC"
+    CXX="\$(CYGWIN_WRAPPER) $CXX"
+    RC="\$(CYGWIN_WRAPPER) $RC"
+    ;;
+esac
+
+dnl ========================================================
+dnl = Use malloc wrapper lib
+dnl ========================================================
+AC_ARG_ENABLE(wrap-malloc,
+[  --enable-wrap-malloc    Wrap malloc calls (gnu linker only)],
+[     if test "$enableval" = "yes"; then
+	    _WRAP_MALLOC=1
+      fi ])
+
+if test -n "$_WRAP_MALLOC"; then
+    if test -n "$GNU_CC"; then
+        WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=malloc,--wrap=calloc,--wrap=valloc,--wrap=free,--wrap=realloc,--wrap=memalign"
+        WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=__builtin_new,--wrap=__builtin_vec_new,--wrap=__builtin_delete,--wrap=__builtin_vec_delete"
+        WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=strdup,--wrap=strndup"
+        WRAP_LDFLAGS="${WRAP_LDFLAGS} -Wl,--wrap=posix_memalign,--wrap=malloc_usable_size"
+    else
+        AC_MSG_ERROR([--enable-wrap-malloc is not supported for non-GNU toolchains])
+    fi
+fi
+
+dnl ========================================================
+dnl = Location of malloc wrapper lib
+dnl ========================================================
+AC_ARG_WITH(wrap-malloc,
+[  --with-wrap-malloc=SHAREDLIB  Location of malloc wrapper library],
+    WRAP_LDFLAGS="${WRAP_LDFLAGS} $withval")
+
+dnl ========================================================
+dnl Substitution of found variables.
+dnl ========================================================
+AC_SUBST(SHELL_OVERRIDE)
+
+AC_SUBST(MOZILLA_CLIENT)
+AC_SUBST(CC)
+AC_SUBST(CXX)
+AC_SUBST(CFLAGS)
+AC_SUBST(CXXFLAGS)
+AC_SUBST(CPPFLAGS)
+AC_SUBST(HOST_CC)
+AC_SUBST(HOST_CFLAGS)
+AC_SUBST(LDFLAGS)
+AC_SUBST(HOST_LDFLAGS)
+AC_SUBST(GNU_CC)
+AC_SUBST(GCC_USE_GNU_LD)
+AC_SUBST(MSC_VER)
+AC_SUBST(CROSS_COMPILE)
+
+AC_SUBST(MOZ_OPTIMIZE)
+AC_SUBST(MOZ_DEBUG)
+AC_SUBST(MOZ_DEBUG_SYMBOLS)
+
+AC_SUBST(USE_CPLUS)
+AC_SUBST(USE_IPV6)
+AC_SUBST(USE_N32)
+AC_SUBST(USE_X32)
+AC_SUBST(USE_64)
+AC_SUBST(OBJECT_MODE)
+AC_SUBST(ENABLE_STRIP)
+
+AC_SUBST(USE_PTHREADS)
+AC_SUBST(USE_BTHREADS)
+AC_SUBST(USE_USER_PTHREADS)
+AC_SUBST(USE_NSPR_THREADS)
+
+AC_SUBST(LIBNSPR)
+AC_SUBST(LIBPLC)
+
+AC_SUBST(MOD_MAJOR_VERSION)
+AC_SUBST(MOD_MINOR_VERSION)
+AC_SUBST(MOD_PATCH_VERSION)
+AC_SUBST(NSPR_MODNAME)
+AC_SUBST(MDCPUCFG_H)
+AC_SUBST(PR_MD_CSRCS)
+AC_SUBST(PR_MD_ASFILES)
+AC_SUBST(PR_MD_ARCH_DIR)
+AC_SUBST(CPU_ARCH)
+
+AC_SUBST(OBJ_SUFFIX)
+AC_SUBST(LIB_SUFFIX)
+AC_SUBST(DLL_SUFFIX)
+AC_SUBST(ASM_SUFFIX)
+AC_SUBST(WRAP_LDFLAGS)
+AC_SUBST(MKSHLIB)
+AC_SUBST(DSO_CFLAGS)
+AC_SUBST(DSO_LDOPTS)
+
+AC_SUBST(OS_TARGET)
+AC_SUBST(OS_ARCH)
+AC_SUBST(OS_RELEASE)
+AC_SUBST(OS_TEST)
+AC_SUBST(MACOSX_DEPLOYMENT_TARGET)
+
+AC_SUBST(DEFINES)
+AC_SUBST(DEFS)
+AC_SUBST(AR)
+AC_SUBST(AR_FLAGS)
+AC_SUBST(AS)
+AC_SUBST(ASFLAGS)
+AC_SUBST(LD)
+AC_SUBST(RANLIB)
+AC_SUBST(PERL)
+AC_SUBST(STRIP)
+AC_SUBST(FILTER)
+AC_SUBST(IMPLIB)
+
+AC_SUBST(PROFILE_GEN_CFLAGS)
+AC_SUBST(PROFILE_GEN_LDFLAGS)
+AC_SUBST(PROFILE_USE_CFLAGS)
+AC_SUBST(PROFILE_USE_LDFLAGS)
+
+AC_SUBST(OS_LIBS)
+AC_SUBST(RESOLVE_LINK_SYMBOLS)
+AC_SUBST(AIX_LINK_OPTS)
+AC_SUBST(NOSUCHFILE)
+AC_SUBST(MOZ_OBJFORMAT)
+AC_SUBST(ULTRASPARC_LIBRARY)
+
+AC_SUBST(OBJDIR)
+AC_SUBST(OBJDIR_NAME)
+AC_SUBST(RELEASE_OBJDIR_NAME)
+AC_SUBST(NSINSTALL)
+AC_SUBST(OPTIMIZER)
+AC_SUBST(RC)
+AC_SUBST(RCFLAGS)
+AC_SUBST(DLLFLAGS)
+AC_SUBST(EXEFLAGS)
+AC_SUBST(OS_DLLFLAGS)
+AC_SUBST(CYGWIN_WRAPPER)
+AC_SUBST(VISIBILITY_FLAGS)
+AC_SUBST(WRAP_SYSTEM_INCLUDES)
+AC_SUBST(MACOS_SDK_DIR)
+AC_SUBST(SYMBIAN_SDK_DIR)
+AC_SUBST(NEXT_ROOT)
+AC_SUBST(MT)
+
+dnl ========================================================
+dnl Generate output files.
+dnl ========================================================
+MAKEFILES="
+    Makefile
+    config/Makefile
+    config/autoconf.mk
+    config/nsprincl.mk
+    config/nsprincl.sh
+    config/nspr-config
+    config/nspr.pc
+    lib/Makefile
+    lib/ds/Makefile
+    lib/libc/Makefile
+    lib/libc/include/Makefile
+    lib/libc/src/Makefile
+    lib/tests/Makefile
+    pkg/Makefile
+    pr/Makefile
+    pr/include/Makefile
+    pr/include/md/Makefile
+    pr/include/obsolete/Makefile
+    pr/include/private/Makefile
+    pr/src/Makefile
+    pr/src/io/Makefile
+    pr/src/linking/Makefile
+    pr/src/malloc/Makefile
+    pr/src/md/Makefile
+    pr/src/md/${PR_MD_ARCH_DIR}/Makefile
+    pr/src/memory/Makefile
+    pr/src/misc/Makefile
+    pr/src/threads/Makefile
+    pr/tests/Makefile
+    pr/tests/dll/Makefile
+"
+
+if test "$OS_TARGET" = "Linux"; then
+    MAKEFILES="$MAKEFILES
+        pkg/linux/Makefile
+    "
+elif test "$OS_TARGET" = "SunOS"; then
+    MAKEFILES="$MAKEFILES
+        pkg/solaris/Makefile
+        pkg/solaris/SUNWpr/Makefile
+        pkg/solaris/SUNWprd/Makefile
+    "
+fi
+
+if test -z "$USE_PTHREADS" && test -z "$USE_BTHREADS"; then
+    MAKEFILES="$MAKEFILES
+        pr/src/threads/combined/Makefile
+    "
+elif test -n "$USE_PTHREADS"; then
+    MAKEFILES="$MAKEFILES
+        pr/src/pthreads/Makefile
+    "
+elif test -n "$USE_BTHREADS"; then
+    MAKEFILES="$MAKEFILES
+        pr/src/bthreads/Makefile
+    "
+fi
+
+if test -n "$USE_CPLUS"; then
+    MAKEFILES="$MAKEFILES
+        pr/src/cplus/Makefile
+        pr/src/cplus/tests/Makefile
+    "
+fi
+
+echo $MAKEFILES > unallmakefiles
+
+AC_CONFIG_FILES([$MAKEFILES])
+AC_CONFIG_COMMANDS([default], [chmod +x config/nspr-config])
+AC_OUTPUT
diff --git a/lib/.cvsignore b/lib/.cvsignore
new file mode 100644
index 0000000..f3c7a7c
--- /dev/null
+++ b/lib/.cvsignore
@@ -0,0 +1 @@
+Makefile
diff --git a/lib/Makefile.in b/lib/Makefile.in
new file mode 100644
index 0000000..64dd43d
--- /dev/null
+++ b/lib/Makefile.in
@@ -0,0 +1,24 @@
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#! gmake
+
+MOD_DEPTH	= ..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+
+include $(MOD_DEPTH)/config/autoconf.mk
+
+export NSPR20=1
+
+include $(topsrcdir)/config/config.mk
+
+DIRS = ds libc
+
+include $(topsrcdir)/config/rules.mk
+
+export:: $(TARGETS)
+
diff --git a/lib/ds/.cvsignore b/lib/ds/.cvsignore
new file mode 100644
index 0000000..bcab60f
--- /dev/null
+++ b/lib/ds/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+_pl_bld.h
diff --git a/lib/ds/Makefile.in b/lib/ds/Makefile.in
new file mode 100644
index 0000000..e737791
--- /dev/null
+++ b/lib/ds/Makefile.in
@@ -0,0 +1,151 @@
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#! gmake
+
+MOD_DEPTH	= ../..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+
+include $(MOD_DEPTH)/config/autoconf.mk
+
+include $(topsrcdir)/config/config.mk
+
+INCLUDES = -I$(dist_includedir) -I$(topsrcdir)/pr/include
+
+CSRCS = \
+	plarena.c \
+	plhash.c \
+	plvrsion.c \
+	$(NULL)
+
+HEADERS = \
+	plarenas.h \
+	plarena.h \
+	plhash.h \
+	$(NULL)
+
+HEADERS := $(addprefix $(srcdir)/, $(HEADERS))
+
+ifeq ($(OS_ARCH), WINNT)
+RES=$(OBJDIR)/plds.res
+RESNAME=plds.rc
+endif # WINNT
+
+ifeq ($(OS_ARCH), AIX)
+ifeq ($(CLASSIC_NSPR),1)
+OS_LIBS = -lc
+else
+OS_LIBS = -lc_r
+endif
+endif
+
+ifeq ($(OS_ARCH),IRIX)
+OS_LIBS = -lc
+endif
+
+ifeq ($(OS_ARCH),SunOS)
+OS_LIBS = -lc
+MAPFILE = $(OBJDIR)/pldsmap.sun
+GARBAGE += $(MAPFILE)
+ifdef NS_USE_GCC
+ifdef GCC_USE_GNU_LD
+MKSHLIB += -Wl,--version-script,$(MAPFILE)
+else
+MKSHLIB += -Wl,-M,$(MAPFILE)
+endif
+else
+MKSHLIB += -M $(MAPFILE)
+endif
+# The -R '$ORIGIN' linker option instructs this library to search for its
+# dependencies in the same directory where it resides.
+MKSHLIB += -R '$$ORIGIN'
+endif
+
+ifeq ($(OS_ARCH),OS2)
+MAPFILE = $(OBJDIR)/$(LIBRARY_NAME)$(LIBRARY_VERSION).def
+GARBAGE += $(MAPFILE)
+MKSHLIB += $(MAPFILE)
+endif
+
+EXTRA_LIBS = $(LIBNSPR)
+
+# On SCOOS, we can't link with extra libraries when
+# we build a shared library.  If we do so, the linker doesn't
+# complain, but we would run into weird problems at run-time.
+# Therefore on these platforms, we link just the .o files.
+ifeq ($(OS_ARCH),SCOOS)
+EXTRA_LIBS =
+endif
+
+ifdef RESOLVE_LINK_SYMBOLS
+EXTRA_LIBS += $(OS_LIBS)
+endif
+
+LIBRARY_NAME	= plds
+LIBRARY_VERSION	= $(MOD_MAJOR_VERSION)
+
+RELEASE_HEADERS = $(HEADERS)
+RELEASE_HEADERS_DEST = $(RELEASE_INCLUDE_DIR)
+RELEASE_LIBS	= $(TARGETS)
+
+include $(topsrcdir)/config/rules.mk
+
+#
+# Version information generation (begin)
+#
+ECHO = echo
+TINC = $(OBJDIR)/_pl_bld.h
+PROD = $(notdir $(SHARED_LIBRARY))
+NOW = $(MOD_DEPTH)/config/$(OBJDIR)/now
+SH_DATE = $(shell date "+%Y-%m-%d %T")
+SH_NOW = $(shell $(NOW))
+
+ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
+	SUF = i64
+else
+	SUF = LL
+endif
+
+GARBAGE += $(TINC)
+
+$(TINC):
+	@$(MAKE_OBJDIR)
+	@$(ECHO) '#define _BUILD_STRING "$(SH_DATE)"' > $(TINC)
+	@if test ! -z "$(SH_NOW)"; then \
+	    $(ECHO) '#define _BUILD_TIME $(SH_NOW)$(SUF)' >> $(TINC); \
+	else \
+	    true; \
+	fi
+	@$(ECHO) '#define _PRODUCTION "$(PROD)"' >> $(TINC)
+
+
+$(OBJDIR)/plvrsion.$(OBJ_SUFFIX): plvrsion.c $(TINC)
+ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
+	$(CC) -Fo$@ -c $(CFLAGS) -I$(OBJDIR) $<
+else
+	$(CC) -o $@ -c $(CFLAGS) -I$(OBJDIR) $<
+endif
+#
+# Version information generation (end)
+#
+
+#
+# The Client build wants the shared libraries in $(dist_bindir),
+# so we also install them there.
+#
+
+export:: $(TARGETS)
+	$(INSTALL) -m 444 $(HEADERS) $(dist_includedir)
+	$(INSTALL) -m 444 $(TARGETS) $(dist_libdir)
+ifdef SHARED_LIBRARY
+ifeq ($(OS_ARCH),HP-UX)
+	$(INSTALL) -m 755 $(SHARED_LIBRARY) $(dist_libdir)
+	$(INSTALL) -m 755 $(SHARED_LIBRARY) $(dist_bindir)
+else
+	$(INSTALL) -m 444 $(SHARED_LIBRARY) $(dist_bindir)
+endif
+endif
diff --git a/lib/ds/plarena.c b/lib/ds/plarena.c
new file mode 100644
index 0000000..a582ac6
--- /dev/null
+++ b/lib/ds/plarena.c
@@ -0,0 +1,334 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+ * Lifetime-based fast allocation, inspired by much prior art, including
+ * "Fast Allocation and Deallocation of Memory Based on Object Lifetimes"
+ * David R. Hanson, Software -- Practice and Experience, Vol. 20(1).
+ */
+#include <stdlib.h>
+#include <string.h>
+#include "plarena.h"
+#include "prmem.h"
+#include "prbit.h"
+#include "prlog.h"
+#include "prlock.h"
+#include "prinit.h"
+
+#ifdef PL_ARENAMETER
+static PLArenaStats *arena_stats_list;
+
+#define COUNT(pool,what)  (pool)->stats.what++
+#else
+#define COUNT(pool,what)  /* nothing */
+#endif
+
+#define PL_ARENA_DEFAULT_ALIGN  sizeof(double)
+
+PR_IMPLEMENT(void) PL_InitArenaPool(
+    PLArenaPool *pool, const char *name, PRUint32 size, PRUint32 align)
+{
+    /*
+     * Look-up table of PR_BITMASK(PR_CeilingLog2(align)) values for
+     * align = 1 to 32.
+     */
+    static const PRUint8 pmasks[33] = {
+         0,                                               /*  not used */
+         0, 1, 3, 3, 7, 7, 7, 7,15,15,15,15,15,15,15,15,  /*  1 ... 16 */
+        31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31}; /* 17 ... 32 */
+
+    if (align == 0)
+        align = PL_ARENA_DEFAULT_ALIGN;
+
+    if (align < sizeof(pmasks)/sizeof(pmasks[0]))
+        pool->mask = pmasks[align];
+    else
+        pool->mask = PR_BITMASK(PR_CeilingLog2(align));
+
+    pool->first.next = NULL;
+    /* Set all three addresses in pool->first to the same dummy value.
+     * These addresses are only compared with each other, but never
+     * dereferenced. */
+    pool->first.base = pool->first.avail = pool->first.limit =
+        (PRUword)PL_ARENA_ALIGN(pool, &pool->first + 1);
+    pool->current = &pool->first;
+    /*
+     * Compute the net size so that each arena's gross size is |size|.
+     * sizeof(PLArena) + pool->mask is the header and alignment slop
+     * that PL_ArenaAllocate adds to the net size.
+     */
+    if (size > sizeof(PLArena) + pool->mask)
+        pool->arenasize = size - (sizeof(PLArena) + pool->mask);
+    else
+        pool->arenasize = size;
+#ifdef PL_ARENAMETER
+    memset(&pool->stats, 0, sizeof pool->stats);
+    pool->stats.name = strdup(name);
+    pool->stats.next = arena_stats_list;
+    arena_stats_list = &pool->stats;
+#endif
+}
+
+
+/*
+** PL_ArenaAllocate() -- allocate space from an arena pool
+** 
+** Description: PL_ArenaAllocate() allocates space from an arena
+** pool. 
+**
+** First, try to satisfy the request from arenas starting at
+** pool->current. Then try to allocate a new arena from the heap.
+**
+** Returns: pointer to allocated space or NULL
+** 
+** Notes: The original implementation had some difficult to
+** solve bugs; the code was difficult to read. Sometimes it's
+** just easier to rewrite it. I did that. larryh.
+**
+** See also: bugzilla: 45343.
+**
+*/
+
+PR_IMPLEMENT(void *) PL_ArenaAllocate(PLArenaPool *pool, PRUint32 nb)
+{
+    PLArena *a;   
+    char *rp;     /* returned pointer */
+    PRUint32 nbOld;
+
+    PR_ASSERT((nb & pool->mask) == 0);
+    
+    nbOld = nb;
+    nb = (PRUword)PL_ARENA_ALIGN(pool, nb); /* force alignment */
+    if (nb < nbOld)
+        return NULL;
+
+    /* attempt to allocate from arenas at pool->current */
+    {
+        a = pool->current;
+        do {
+            if ( nb <= a->limit - a->avail )  {
+                pool->current = a;
+                rp = (char *)a->avail;
+                a->avail += nb;
+                return rp;
+            }
+        } while( NULL != (a = a->next) );
+    }
+
+    /* attempt to allocate from the heap */ 
+    {  
+        PRUint32 sz = PR_MAX(pool->arenasize, nb);
+        if (PR_UINT32_MAX - sz < sizeof *a + pool->mask) {
+            a = NULL;
+        } else {
+            sz += sizeof *a + pool->mask;  /* header and alignment slop */
+            a = (PLArena*)PR_MALLOC(sz);
+        }
+        if ( NULL != a )  {
+            a->limit = (PRUword)a + sz;
+            a->base = a->avail = (PRUword)PL_ARENA_ALIGN(pool, a + 1);
+            PL_MAKE_MEM_NOACCESS((void*)a->avail, a->limit - a->avail);
+            rp = (char *)a->avail;
+            a->avail += nb;
+            PR_ASSERT(a->avail <= a->limit);
+            /* the newly allocated arena is linked after pool->current 
+            *  and becomes pool->current */
+            a->next = pool->current->next;
+            pool->current->next = a;
+            pool->current = a;
+            if ( NULL == pool->first.next )
+                pool->first.next = a;
+            PL_COUNT_ARENA(pool,++);
+            COUNT(pool, nmallocs);
+            return(rp);
+        }
+    }
+
+    /* we got to here, and there's no memory to allocate */
+    return(NULL);
+} /* --- end PL_ArenaAllocate() --- */
+
+PR_IMPLEMENT(void *) PL_ArenaGrow(
+    PLArenaPool *pool, void *p, PRUint32 size, PRUint32 incr)
+{
+    void *newp;
+
+    if (PR_UINT32_MAX - size < incr)
+        return NULL;
+    PL_ARENA_ALLOCATE(newp, pool, size + incr);
+    if (newp)
+        memcpy(newp, p, size);
+    return newp;
+}
+
+PR_IMPLEMENT(void) PL_ClearArenaPool(PLArenaPool *pool, PRInt32 pattern)
+{
+    PLArena *a;
+
+    for (a = pool->first.next; a; a = a->next) {
+        PR_ASSERT(a->base <= a->avail && a->avail <= a->limit);
+        a->avail = a->base;
+        PL_CLEAR_UNUSED_PATTERN(a, pattern);
+        PL_MAKE_MEM_NOACCESS((void*)a->avail, a->limit - a->avail);
+    }
+}
+
+/*
+ * Free tail arenas linked after head, which may not be the true list head.
+ * Reset pool->current to point to head in case it pointed at a tail arena.
+ */
+static void FreeArenaList(PLArenaPool *pool, PLArena *head)
+{
+    PLArena *a = head->next;
+    if (!a)
+        return;
+
+    head->next = NULL;
+
+    do {
+        PLArena *tmp = a;
+        a = a->next;
+        PL_CLEAR_ARENA(tmp);
+        PL_COUNT_ARENA(pool,--);
+        PR_DELETE(tmp);
+    } while (a);
+
+    pool->current = head;
+}
+
+PR_IMPLEMENT(void) PL_ArenaRelease(PLArenaPool *pool, char *mark)
+{
+    PLArena *a;
+
+    for (a = &pool->first; a; a = a->next) {
+        if (PR_UPTRDIFF(mark, a->base) <= PR_UPTRDIFF(a->avail, a->base)) {
+            a->avail = (PRUword)PL_ARENA_ALIGN(pool, mark);
+            FreeArenaList(pool, a);
+            return;
+        }
+    }
+}
+
+PR_IMPLEMENT(void) PL_FreeArenaPool(PLArenaPool *pool)
+{
+    FreeArenaList(pool, &pool->first);
+    COUNT(pool, ndeallocs);
+}
+
+PR_IMPLEMENT(void) PL_FinishArenaPool(PLArenaPool *pool)
+{
+    FreeArenaList(pool, &pool->first);
+#ifdef PL_ARENAMETER
+    {
+        PLArenaStats *stats, **statsp;
+
+        if (pool->stats.name)
+            PR_DELETE(pool->stats.name);
+        for (statsp = &arena_stats_list; (stats = *statsp) != 0;
+             statsp = &stats->next) {
+            if (stats == &pool->stats) {
+                *statsp = stats->next;
+                return;
+            }
+        }
+    }
+#endif
+}
+
+PR_IMPLEMENT(void) PL_CompactArenaPool(PLArenaPool *ap)
+{
+}
+
+PR_IMPLEMENT(void) PL_ArenaFinish(void)
+{
+}
+
+PR_IMPLEMENT(size_t) PL_SizeOfArenaPoolExcludingPool(
+    const PLArenaPool *pool, PLMallocSizeFn mallocSizeOf)
+{
+    /*
+     * The first PLArena is within |pool|, so don't measure it.  Subsequent
+     * PLArenas are separate and must be measured.
+     */
+    size_t size = 0;
+    const PLArena *arena = pool->first.next;
+    while (arena) {
+        size += mallocSizeOf(arena);
+        arena = arena->next;
+    }
+    return size;
+}
+
+#ifdef PL_ARENAMETER
+PR_IMPLEMENT(void) PL_ArenaCountAllocation(PLArenaPool *pool, PRUint32 nb)
+{
+    pool->stats.nallocs++;
+    pool->stats.nbytes += nb;
+    if (nb > pool->stats.maxalloc)
+        pool->stats.maxalloc = nb;
+    pool->stats.variance += nb * nb;
+}
+
+PR_IMPLEMENT(void) PL_ArenaCountInplaceGrowth(
+    PLArenaPool *pool, PRUint32 size, PRUint32 incr)
+{
+    pool->stats.ninplace++;
+}
+
+PR_IMPLEMENT(void) PL_ArenaCountGrowth(
+    PLArenaPool *pool, PRUint32 size, PRUint32 incr)
+{
+    pool->stats.ngrows++;
+    pool->stats.nbytes += incr;
+    pool->stats.variance -= size * size;
+    size += incr;
+    if (size > pool->stats.maxalloc)
+        pool->stats.maxalloc = size;
+    pool->stats.variance += size * size;
+}
+
+PR_IMPLEMENT(void) PL_ArenaCountRelease(PLArenaPool *pool, char *mark)
+{
+    pool->stats.nreleases++;
+}
+
+PR_IMPLEMENT(void) PL_ArenaCountRetract(PLArenaPool *pool, char *mark)
+{
+    pool->stats.nfastrels++;
+}
+
+#include <math.h>
+#include <stdio.h>
+
+PR_IMPLEMENT(void) PL_DumpArenaStats(FILE *fp)
+{
+    PLArenaStats *stats;
+    double mean, variance;
+
+    for (stats = arena_stats_list; stats; stats = stats->next) {
+        if (stats->nallocs != 0) {
+            mean = (double)stats->nbytes / stats->nallocs;
+            variance = fabs(stats->variance / stats->nallocs - mean * mean);
+        } else {
+            mean = variance = 0;
+        }
+
+        fprintf(fp, "\n%s allocation statistics:\n", stats->name);
+        fprintf(fp, "              number of arenas: %u\n", stats->narenas);
+        fprintf(fp, "         number of allocations: %u\n", stats->nallocs);
+        fprintf(fp, " number of free arena reclaims: %u\n", stats->nreclaims);
+        fprintf(fp, "        number of malloc calls: %u\n", stats->nmallocs);
+        fprintf(fp, "       number of deallocations: %u\n", stats->ndeallocs);
+        fprintf(fp, "  number of allocation growths: %u\n", stats->ngrows);
+        fprintf(fp, "    number of in-place growths: %u\n", stats->ninplace);
+        fprintf(fp, "number of released allocations: %u\n", stats->nreleases);
+        fprintf(fp, "       number of fast releases: %u\n", stats->nfastrels);
+        fprintf(fp, "         total bytes allocated: %u\n", stats->nbytes);
+        fprintf(fp, "          mean allocation size: %g\n", mean);
+        fprintf(fp, "            standard deviation: %g\n", sqrt(variance));
+        fprintf(fp, "       maximum allocation size: %u\n", stats->maxalloc);
+    }
+}
+#endif /* PL_ARENAMETER */
diff --git a/lib/ds/plarena.h b/lib/ds/plarena.h
new file mode 100644
index 0000000..5336a0e
--- /dev/null
+++ b/lib/ds/plarena.h
@@ -0,0 +1,327 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef plarena_h___
+#define plarena_h___
+/*
+ * Lifetime-based fast allocation, inspired by much prior art, including
+ * "Fast Allocation and Deallocation of Memory Based on Object Lifetimes"
+ * David R. Hanson, Software -- Practice and Experience, Vol. 20(1).
+ *
+ * Also supports LIFO allocation (PL_ARENA_MARK/PL_ARENA_RELEASE).
+ */
+#include "prtypes.h"
+
+PR_BEGIN_EXTERN_C
+
+typedef struct PLArena          PLArena;
+
+struct PLArena {
+    PLArena     *next;          /* next arena for this lifetime */
+    PRUword     base;           /* aligned base address, follows this header */
+    PRUword     limit;          /* one beyond last byte in arena */
+    PRUword     avail;          /* points to next available byte */
+};
+
+#ifdef PL_ARENAMETER
+typedef struct PLArenaStats PLArenaStats;
+
+struct PLArenaStats {
+    PLArenaStats  *next;        /* next in arenaStats list */
+    char          *name;        /* name for debugging */
+    PRUint32      narenas;      /* number of arenas in pool */
+    PRUint32      nallocs;      /* number of PL_ARENA_ALLOCATE() calls */
+    PRUint32      nreclaims;    /* number of reclaims from freeArenas */
+    PRUint32      nmallocs;     /* number of malloc() calls */
+    PRUint32      ndeallocs;    /* number of lifetime deallocations */
+    PRUint32      ngrows;       /* number of PL_ARENA_GROW() calls */
+    PRUint32      ninplace;     /* number of in-place growths */
+    PRUint32      nreleases;    /* number of PL_ARENA_RELEASE() calls */
+    PRUint32      nfastrels;    /* number of "fast path" releases */
+    PRUint32      nbytes;       /* total bytes allocated */
+    PRUint32      maxalloc;     /* maximum allocation size in bytes */
+    PRFloat64     variance;     /* size variance accumulator */
+};
+#endif
+
+typedef struct PLArenaPool      PLArenaPool;
+
+struct PLArenaPool {
+    PLArena     first;          /* first arena in pool list */
+    PLArena     *current;       /* arena from which to allocate space */
+    PRUint32    arenasize;      /* net exact size of a new arena */
+    PRUword     mask;           /* alignment mask (power-of-2 - 1) */
+#ifdef PL_ARENAMETER
+    PLArenaStats stats;
+#endif
+};
+
+/*
+ * WARNING: The PL_MAKE_MEM_ macros are for internal use by NSPR. Do NOT use
+ * them in your code.
+ *
+ * NOTE: Valgrind support to be added.
+ *
+ * The PL_MAKE_MEM_ macros are modeled after the MOZ_MAKE_MEM_ macros in
+ * Mozilla's mfbt/MemoryChecking.h. Only AddressSanitizer is supported now.
+ *
+ * Provides a common interface to the ASan (AddressSanitizer) and Valgrind
+ * functions used to mark memory in certain ways. In detail, the following
+ * three macros are provided:
+ *
+ *   PL_MAKE_MEM_NOACCESS  - Mark memory as unsafe to access (e.g. freed)
+ *   PL_MAKE_MEM_UNDEFINED - Mark memory as accessible, with content undefined
+ *   PL_MAKE_MEM_DEFINED - Mark memory as accessible, with content defined
+ *
+ * With Valgrind in use, these directly map to the three respective Valgrind
+ * macros. With ASan in use, the NOACCESS macro maps to poisoning the memory,
+ * while the UNDEFINED/DEFINED macros unpoison memory.
+ *
+ * With no memory checker available, all macros expand to the empty statement.
+ */
+
+/* WARNING: PL_SANITIZE_ADDRESS is for internal use by this header. Do NOT
+ * define or test this macro in your code.
+ */
+#if defined(__has_feature)
+#if __has_feature(address_sanitizer)
+#define PL_SANITIZE_ADDRESS 1
+#endif
+#elif defined(__SANITIZE_ADDRESS__)
+#define PL_SANITIZE_ADDRESS 1
+#endif
+
+#if defined(PL_SANITIZE_ADDRESS)
+
+/* These definitions are usually provided through the
+ * sanitizer/asan_interface.h header installed by ASan.
+ * See https://github.com/google/sanitizers/wiki/AddressSanitizerManualPoisoning
+ */
+
+PR_IMPORT(void) __asan_poison_memory_region(void const volatile *addr, size_t size);
+PR_IMPORT(void) __asan_unpoison_memory_region(void const volatile *addr, size_t size);
+
+#define PL_MAKE_MEM_NOACCESS(addr, size) \
+    __asan_poison_memory_region((addr), (size))
+
+#define PL_MAKE_MEM_UNDEFINED(addr, size) \
+    __asan_unpoison_memory_region((addr), (size))
+
+#define PL_MAKE_MEM_DEFINED(addr, size) \
+    __asan_unpoison_memory_region((addr), (size))
+
+#else
+
+#define PL_MAKE_MEM_NOACCESS(addr, size)
+#define PL_MAKE_MEM_UNDEFINED(addr, size)
+#define PL_MAKE_MEM_DEFINED(addr, size)
+
+#endif
+
+/*
+ * If the including .c file uses only one power-of-2 alignment, it may define
+ * PL_ARENA_CONST_ALIGN_MASK to the alignment mask and save a few instructions
+ * per ALLOCATE and GROW.
+ */
+#ifdef PL_ARENA_CONST_ALIGN_MASK
+#define PL_ARENA_ALIGN(pool, n) (((PRUword)(n) + PL_ARENA_CONST_ALIGN_MASK) \
+                                & ~PL_ARENA_CONST_ALIGN_MASK)
+
+#define PL_INIT_ARENA_POOL(pool, name, size) \
+        PL_InitArenaPool(pool, name, size, PL_ARENA_CONST_ALIGN_MASK + 1)
+#else
+#define PL_ARENA_ALIGN(pool, n) (((PRUword)(n) + (pool)->mask) & ~(pool)->mask)
+#endif
+
+#define PL_ARENA_ALLOCATE(p, pool, nb) \
+    PR_BEGIN_MACRO \
+        PLArena *_a = (pool)->current; \
+        PRUint32 _nb = PL_ARENA_ALIGN(pool, (PRUint32)nb); \
+        PRUword _p = _a->avail; \
+        if (_nb < (PRUint32)nb) { \
+            _p = 0; \
+        } else if (_nb > (_a->limit - _a->avail)) { \
+            _p = (PRUword)PL_ArenaAllocate(pool, _nb); \
+        } else { \
+            _a->avail += _nb; \
+        } \
+        p = (void *)_p; \
+        if (p) { \
+            PL_MAKE_MEM_UNDEFINED(p, (PRUint32)nb); \
+            PL_ArenaCountAllocation(pool, (PRUint32)nb); \
+        } \
+    PR_END_MACRO
+
+#define PL_ARENA_GROW(p, pool, size, incr) \
+    PR_BEGIN_MACRO \
+        PLArena *_a = (pool)->current; \
+        PRUint32 _incr = PL_ARENA_ALIGN(pool, (PRUint32)incr); \
+        if (_incr < (PRUint32)incr) { \
+            p = NULL; \
+        } else if (_a->avail == (PRUword)(p) + PL_ARENA_ALIGN(pool, size) && \
+            _incr <= (_a->limit - _a->avail)) { \
+            PL_MAKE_MEM_UNDEFINED((unsigned char *)(p) + size, (PRUint32)incr); \
+            _a->avail += _incr; \
+            PL_ArenaCountInplaceGrowth(pool, size, (PRUint32)incr); \
+        } else { \
+            p = PL_ArenaGrow(pool, p, size, (PRUint32)incr); \
+        } \
+        if (p) {\
+            PL_ArenaCountGrowth(pool, size, (PRUint32)incr); \
+        } \
+    PR_END_MACRO
+
+#define PL_ARENA_MARK(pool) ((void *) (pool)->current->avail)
+#define PR_UPTRDIFF(p,q) ((PRUword)(p) - (PRUword)(q))
+
+#define PL_CLEAR_UNUSED_PATTERN(a, pattern) \
+    PR_BEGIN_MACRO \
+        PR_ASSERT((a)->avail <= (a)->limit); \
+        PL_MAKE_MEM_UNDEFINED((void*)(a)->avail, (a)->limit - (a)->avail); \
+        memset((void*)(a)->avail, (pattern), (a)->limit - (a)->avail); \
+    PR_END_MACRO
+#ifdef DEBUG
+#define PL_FREE_PATTERN 0xDA
+#define PL_CLEAR_UNUSED(a) PL_CLEAR_UNUSED_PATTERN((a), PL_FREE_PATTERN)
+#define PL_CLEAR_ARENA(a) \
+    PR_BEGIN_MACRO \
+        PL_MAKE_MEM_UNDEFINED((void*)(a), (a)->limit - (PRUword)(a)); \
+        memset((void*)(a), PL_FREE_PATTERN, (a)->limit - (PRUword)(a)); \
+    PR_END_MACRO
+#else
+#define PL_CLEAR_UNUSED(a)
+#define PL_CLEAR_ARENA(a)
+#endif
+
+#define PL_ARENA_RELEASE(pool, mark) \
+    PR_BEGIN_MACRO \
+        char *_m = (char *)(mark); \
+        PLArena *_a = (pool)->current; \
+        if (PR_UPTRDIFF(_m, _a->base) <= PR_UPTRDIFF(_a->avail, _a->base)) { \
+            _a->avail = (PRUword)PL_ARENA_ALIGN(pool, _m); \
+            PL_CLEAR_UNUSED(_a); \
+            PL_MAKE_MEM_NOACCESS((void*)_a->avail, _a->limit - _a->avail); \
+            PL_ArenaCountRetract(pool, _m); \
+        } else { \
+            PL_ArenaRelease(pool, _m); \
+        } \
+        PL_ArenaCountRelease(pool, _m); \
+    PR_END_MACRO
+
+#ifdef PL_ARENAMETER
+#define PL_COUNT_ARENA(pool,op) ((pool)->stats.narenas op)
+#else
+#define PL_COUNT_ARENA(pool,op)
+#endif
+
+#define PL_ARENA_DESTROY(pool, a, pnext) \
+    PR_BEGIN_MACRO \
+        PL_COUNT_ARENA(pool,--); \
+        if ((pool)->current == (a)) (pool)->current = &(pool)->first; \
+        *(pnext) = (a)->next; \
+        PL_CLEAR_ARENA(a); \
+        free(a); \
+        (a) = 0; \
+    PR_END_MACRO
+
+/*
+** Initialize an arena pool with the given name for debugging and metering,
+** with a minimum gross size per arena of size bytes.  The net size per arena
+** is smaller than the gross size by a header of four pointers plus any
+** necessary padding for alignment.
+**
+** Note: choose a gross size that's a power of two to avoid the heap allocator
+** rounding the size up.
+**/
+PR_EXTERN(void) PL_InitArenaPool(
+    PLArenaPool *pool, const char *name, PRUint32 size, PRUint32 align);
+
+/*
+** Finish using arenas, freeing all memory associated with them.
+** NOTE: this function is now a no-op. If you want to free a single
+** PLArenaPoolUse use PL_FreeArenaPool() or PL_FinishArenaPool().
+**/
+PR_EXTERN(void) PL_ArenaFinish(void);
+
+/*
+** Free the arenas in pool.  The user may continue to allocate from pool
+** after calling this function.  There is no need to call PL_InitArenaPool()
+** again unless PL_FinishArenaPool(pool) has been called.
+**/
+PR_EXTERN(void) PL_FreeArenaPool(PLArenaPool *pool);
+
+/*
+** Free the arenas in pool and finish using it altogether.
+**/
+PR_EXTERN(void) PL_FinishArenaPool(PLArenaPool *pool);
+
+/*
+** Compact all of the arenas in a pool so that no space is wasted.
+** NOT IMPLEMENTED.  Do not use.
+**/
+PR_EXTERN(void) PL_CompactArenaPool(PLArenaPool *pool);
+
+/*
+** Friend functions used by the PL_ARENA_*() macros.
+**
+** WARNING: do not call these functions directly. Always use the
+** PL_ARENA_*() macros.
+**/
+PR_EXTERN(void *) PL_ArenaAllocate(PLArenaPool *pool, PRUint32 nb);
+
+PR_EXTERN(void *) PL_ArenaGrow(
+    PLArenaPool *pool, void *p, PRUint32 size, PRUint32 incr);
+
+PR_EXTERN(void) PL_ArenaRelease(PLArenaPool *pool, char *mark);
+
+/*
+** memset contents of all arenas in pool to pattern
+*/
+PR_EXTERN(void) PL_ClearArenaPool(PLArenaPool *pool, PRInt32 pattern);
+
+/*
+** A function like malloc_size() or malloc_usable_size() that measures the
+** size of a heap block.
+*/
+typedef size_t (*PLMallocSizeFn)(const void *ptr);
+
+/*
+** Measure all memory used by a PLArenaPool, excluding the PLArenaPool
+** structure.
+*/
+PR_EXTERN(size_t) PL_SizeOfArenaPoolExcludingPool(
+    const PLArenaPool *pool, PLMallocSizeFn mallocSizeOf);
+
+#ifdef PL_ARENAMETER
+
+#include <stdio.h>
+
+PR_EXTERN(void) PL_ArenaCountAllocation(PLArenaPool *pool, PRUint32 nb);
+
+PR_EXTERN(void) PL_ArenaCountInplaceGrowth(
+    PLArenaPool *pool, PRUint32 size, PRUint32 incr);
+
+PR_EXTERN(void) PL_ArenaCountGrowth(
+    PLArenaPool *pool, PRUint32 size, PRUint32 incr);
+
+PR_EXTERN(void) PL_ArenaCountRelease(PLArenaPool *pool, char *mark);
+
+PR_EXTERN(void) PL_ArenaCountRetract(PLArenaPool *pool, char *mark);
+
+PR_EXTERN(void) PL_DumpArenaStats(FILE *fp);
+
+#else  /* !PL_ARENAMETER */
+
+#define PL_ArenaCountAllocation(ap, nb)                 /* nothing */
+#define PL_ArenaCountInplaceGrowth(ap, size, incr)      /* nothing */
+#define PL_ArenaCountGrowth(ap, size, incr)             /* nothing */
+#define PL_ArenaCountRelease(ap, mark)                  /* nothing */
+#define PL_ArenaCountRetract(ap, mark)                  /* nothing */
+
+#endif /* !PL_ARENAMETER */
+
+PR_END_EXTERN_C
+
+#endif /* plarena_h___ */
diff --git a/lib/ds/plarenas.h b/lib/ds/plarenas.h
new file mode 100644
index 0000000..4a0f5a8
--- /dev/null
+++ b/lib/ds/plarenas.h
@@ -0,0 +1,12 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** PLArena-related declarations used to be split between plarenas.h and
+** plarena.h. That split wasn't useful, so now all the declarations are in
+** plarena.h. However, this file still exists so that any old code that
+** includes it will still work.
+**/
+#include "plarena.h"
diff --git a/lib/ds/plds.def b/lib/ds/plds.def
new file mode 100644
index 0000000..cc54a4d
--- /dev/null
+++ b/lib/ds/plds.def
@@ -0,0 +1,60 @@
+;+#
+;+# This Source Code Form is subject to the terms of the Mozilla Public
+;+# License, v. 2.0. If a copy of the MPL was not distributed with this
+;+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+;+#
+;+# OK, this file is meant to support SUN, LINUX, AIX, OS/2 and WINDOWS
+;+#   1. For all unix platforms, the string ";-"  means "remove this line"
+;+#   2. For all unix platforms, the string " DATA " will be removed from any 
+;+#     line on which it occurs.
+;+#   3. Lines containing ";+" will have ";+" removed on SUN and LINUX.
+;+#      On AIX, lines containing ";+" will be removed.
+;+#   4. For all unix platforms, the string ";;" will thave the ";;" removed.
+;+#   5. For all unix platforms, after the above processing has taken place,
+;+#    all characters after the first ";" on the line will be removed.
+;+#    And for AIX, the first ";" will also be removed.
+;+#  This file is passed directly to windows. Since ';' is a comment, all UNIX
+;+#   directives are hidden behind ";", ";+", and ";-"
+;+NSPR_4.0 {
+;+    global:
+LIBRARY plds4 ;-
+EXPORTS ;-
+PL_ArenaAllocate;
+PL_ArenaFinish;
+PL_ArenaGrow;
+PL_ArenaRelease;
+PL_CompactArenaPool;
+PL_CompareStrings;
+PL_CompareValues;
+PL_FinishArenaPool;
+PL_FreeArenaPool;
+PL_HashString;
+PL_HashTableAdd;
+PL_HashTableDestroy;
+PL_HashTableDump;
+PL_HashTableEnumerateEntries;
+PL_HashTableLookup;
+PL_HashTableRawAdd;
+PL_HashTableRawLookup;
+PL_HashTableRawRemove;
+PL_HashTableRemove;
+PL_InitArenaPool;
+PL_NewHashTable;
+libVersionPoint;
+;+    local: *;
+;+};
+;+
+;+NSPR_4.1 {
+;+    global:
+PL_HashTableLookupConst;
+PL_HashTableRawLookupConst;
+;+} NSPR_4.0;
+;+
+;+NSPR_4.8.5 {
+;+    global:
+PL_ClearArenaPool;
+;+} NSPR_4.1;
+;+NSPR_4.9.6 {
+;+    global:
+PL_SizeOfArenaPoolExcludingPool;
+;+} NSPR_4.8.5;
diff --git a/lib/ds/plds.rc b/lib/ds/plds.rc
new file mode 100644
index 0000000..d8017e7
--- /dev/null
+++ b/lib/ds/plds.rc
@@ -0,0 +1,69 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "prinit.h"
+#include <winver.h>
+
+#define MY_LIBNAME "plds"
+#define MY_FILEDESCRIPTION "PLDS Library"
+
+#define STRINGIZE(x) #x
+#define STRINGIZE2(x) STRINGIZE(x)
+#define PR_VMAJOR_STR STRINGIZE2(PR_VMAJOR)
+
+#ifdef _DEBUG
+#define MY_DEBUG_STR " (debug)"
+#define MY_FILEFLAGS_1 VS_FF_DEBUG
+#else
+#define MY_DEBUG_STR ""
+#define MY_FILEFLAGS_1 0x0L
+#endif
+#if PR_BETA
+#define MY_FILEFLAGS_2 MY_FILEFLAGS_1|VS_FF_PRERELEASE
+#else
+#define MY_FILEFLAGS_2 MY_FILEFLAGS_1
+#endif
+
+#ifdef WINNT
+#define MY_FILEOS VOS_NT_WINDOWS32
+#define MY_INTERNAL_NAME "lib" MY_LIBNAME PR_VMAJOR_STR
+#else
+#define MY_FILEOS VOS__WINDOWS32
+#define MY_INTERNAL_NAME MY_LIBNAME PR_VMAJOR_STR
+#endif
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Version-information resource
+//
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION PR_VMAJOR,PR_VMINOR,PR_VPATCH,0
+ PRODUCTVERSION PR_VMAJOR,PR_VMINOR,PR_VPATCH,0
+ FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
+ FILEFLAGS MY_FILEFLAGS_2
+ FILEOS MY_FILEOS
+ FILETYPE VFT_DLL
+ FILESUBTYPE 0x0L // not used
+
+BEGIN
+    BLOCK "StringFileInfo"
+    BEGIN
+        BLOCK "040904B0" // Lang=US English, CharSet=Unicode
+        BEGIN
+            VALUE "CompanyName", "Mozilla Foundation\0"
+            VALUE "FileDescription", MY_FILEDESCRIPTION MY_DEBUG_STR "\0"
+            VALUE "FileVersion", PR_VERSION "\0"
+            VALUE "InternalName", MY_INTERNAL_NAME "\0"
+            VALUE "OriginalFilename", MY_INTERNAL_NAME ".dll\0"
+            VALUE "ProductName", "Netscape Portable Runtime\0"
+            VALUE "ProductVersion", PR_VERSION "\0"
+        END
+    END
+    BLOCK "VarFileInfo"
+    BEGIN
+        VALUE "Translation", 0x409, 1200
+    END
+END
diff --git a/lib/ds/plhash.c b/lib/ds/plhash.c
new file mode 100644
index 0000000..0011df3
--- /dev/null
+++ b/lib/ds/plhash.c
@@ -0,0 +1,483 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+ * PL hash table package.
+ */
+#include "plhash.h"
+#include "prbit.h"
+#include "prlog.h"
+#include "prmem.h"
+#include "prtypes.h"
+#include <stdlib.h>
+#include <string.h>
+
+/* Compute the number of buckets in ht */
+#define NBUCKETS(ht)    (1 << (PL_HASH_BITS - (ht)->shift))
+
+/* The smallest table has 16 buckets */
+#define MINBUCKETSLOG2  4
+#define MINBUCKETS      (1 << MINBUCKETSLOG2)
+
+/* Compute the maximum entries given n buckets that we will tolerate, ~90% */
+#define OVERLOADED(n)   ((n) - ((n) >> 3))
+
+/* Compute the number of entries below which we shrink the table by half */
+#define UNDERLOADED(n)  (((n) > MINBUCKETS) ? ((n) >> 2) : 0)
+
+/*
+** Stubs for default hash allocator ops.
+*/
+static void * PR_CALLBACK
+DefaultAllocTable(void *pool, PRSize size)
+{
+    return PR_MALLOC(size);
+}
+
+static void PR_CALLBACK
+DefaultFreeTable(void *pool, void *item)
+{
+    PR_Free(item);
+}
+
+static PLHashEntry * PR_CALLBACK
+DefaultAllocEntry(void *pool, const void *key)
+{
+    return PR_NEW(PLHashEntry);
+}
+
+static void PR_CALLBACK
+DefaultFreeEntry(void *pool, PLHashEntry *he, PRUintn flag)
+{
+    if (flag == HT_FREE_ENTRY)
+        PR_Free(he);
+}
+
+static PLHashAllocOps defaultHashAllocOps = {
+    DefaultAllocTable, DefaultFreeTable,
+    DefaultAllocEntry, DefaultFreeEntry
+};
+
+PR_IMPLEMENT(PLHashTable *)
+PL_NewHashTable(PRUint32 n, PLHashFunction keyHash,
+                PLHashComparator keyCompare, PLHashComparator valueCompare,
+                const PLHashAllocOps *allocOps, void *allocPriv)
+{
+    PLHashTable *ht;
+    PRSize nb;
+
+    if (n <= MINBUCKETS) {
+        n = MINBUCKETSLOG2;
+    } else {
+        n = PR_CeilingLog2(n);
+        if ((PRInt32)n < 0)
+            return 0;
+    }
+
+    if (!allocOps) allocOps = &defaultHashAllocOps;
+
+    ht = (PLHashTable*)((*allocOps->allocTable)(allocPriv, sizeof *ht));
+    if (!ht)
+	return 0;
+    memset(ht, 0, sizeof *ht);
+    ht->shift = PL_HASH_BITS - n;
+    n = 1 << n;
+    nb = n * sizeof(PLHashEntry *);
+    ht->buckets = (PLHashEntry**)((*allocOps->allocTable)(allocPriv, nb));
+    if (!ht->buckets) {
+        (*allocOps->freeTable)(allocPriv, ht);
+        return 0;
+    }
+    memset(ht->buckets, 0, nb);
+
+    ht->keyHash = keyHash;
+    ht->keyCompare = keyCompare;
+    ht->valueCompare = valueCompare;
+    ht->allocOps = allocOps;
+    ht->allocPriv = allocPriv;
+    return ht;
+}
+
+PR_IMPLEMENT(void)
+PL_HashTableDestroy(PLHashTable *ht)
+{
+    PRUint32 i, n;
+    PLHashEntry *he, *next;
+    const PLHashAllocOps *allocOps = ht->allocOps;
+    void *allocPriv = ht->allocPriv;
+
+    n = NBUCKETS(ht);
+    for (i = 0; i < n; i++) {
+        for (he = ht->buckets[i]; he; he = next) {
+            next = he->next;
+            (*allocOps->freeEntry)(allocPriv, he, HT_FREE_ENTRY);
+        }
+    }
+#ifdef DEBUG
+    memset(ht->buckets, 0xDB, n * sizeof ht->buckets[0]);
+#endif
+    (*allocOps->freeTable)(allocPriv, ht->buckets);
+#ifdef DEBUG
+    memset(ht, 0xDB, sizeof *ht);
+#endif
+    (*allocOps->freeTable)(allocPriv, ht);
+}
+
+/*
+** Multiplicative hash, from Knuth 6.4.
+*/
+#define GOLDEN_RATIO    0x9E3779B9U  /* 2/(1+sqrt(5))*(2^32) */
+
+PR_IMPLEMENT(PLHashEntry **)
+PL_HashTableRawLookup(PLHashTable *ht, PLHashNumber keyHash, const void *key)
+{
+    PLHashEntry *he, **hep, **hep0;
+    PLHashNumber h;
+
+#ifdef HASHMETER
+    ht->nlookups++;
+#endif
+    h = keyHash * GOLDEN_RATIO;
+    h >>= ht->shift;
+    hep = hep0 = &ht->buckets[h];
+    while ((he = *hep) != 0) {
+        if (he->keyHash == keyHash && (*ht->keyCompare)(key, he->key)) {
+            /* Move to front of chain if not already there */
+            if (hep != hep0) {
+                *hep = he->next;
+                he->next = *hep0;
+                *hep0 = he;
+            }
+            return hep0;
+        }
+        hep = &he->next;
+#ifdef HASHMETER
+        ht->nsteps++;
+#endif
+    }
+    return hep;
+}
+
+/*
+** Same as PL_HashTableRawLookup but doesn't reorder the hash entries.
+*/
+PR_IMPLEMENT(PLHashEntry **)
+PL_HashTableRawLookupConst(PLHashTable *ht, PLHashNumber keyHash,
+                           const void *key)
+{
+    PLHashEntry *he, **hep;
+    PLHashNumber h;
+
+#ifdef HASHMETER
+    ht->nlookups++;
+#endif
+    h = keyHash * GOLDEN_RATIO;
+    h >>= ht->shift;
+    hep = &ht->buckets[h];
+    while ((he = *hep) != 0) {
+        if (he->keyHash == keyHash && (*ht->keyCompare)(key, he->key)) {
+            break;
+        }
+        hep = &he->next;
+#ifdef HASHMETER
+        ht->nsteps++;
+#endif
+    }
+    return hep;
+}
+
+PR_IMPLEMENT(PLHashEntry *)
+PL_HashTableRawAdd(PLHashTable *ht, PLHashEntry **hep,
+                   PLHashNumber keyHash, const void *key, void *value)
+{
+    PRUint32 i, n;
+    PLHashEntry *he, *next, **oldbuckets;
+    PRSize nb;
+
+    /* Grow the table if it is overloaded */
+    n = NBUCKETS(ht);
+    if (ht->nentries >= OVERLOADED(n)) {
+        oldbuckets = ht->buckets;
+        nb = 2 * n * sizeof(PLHashEntry *);
+        ht->buckets = (PLHashEntry**)
+            ((*ht->allocOps->allocTable)(ht->allocPriv, nb));
+        if (!ht->buckets) {
+            ht->buckets = oldbuckets;
+            return 0;
+        }
+        memset(ht->buckets, 0, nb);
+#ifdef HASHMETER
+        ht->ngrows++;
+#endif
+        ht->shift--;
+
+        for (i = 0; i < n; i++) {
+            for (he = oldbuckets[i]; he; he = next) {
+                next = he->next;
+                hep = PL_HashTableRawLookup(ht, he->keyHash, he->key);
+                PR_ASSERT(*hep == 0);
+                he->next = 0;
+                *hep = he;
+            }
+        }
+#ifdef DEBUG
+        memset(oldbuckets, 0xDB, n * sizeof oldbuckets[0]);
+#endif
+        (*ht->allocOps->freeTable)(ht->allocPriv, oldbuckets);
+        hep = PL_HashTableRawLookup(ht, keyHash, key);
+    }
+
+    /* Make a new key value entry */
+    he = (*ht->allocOps->allocEntry)(ht->allocPriv, key);
+    if (!he)
+	return 0;
+    he->keyHash = keyHash;
+    he->key = key;
+    he->value = value;
+    he->next = *hep;
+    *hep = he;
+    ht->nentries++;
+    return he;
+}
+
+PR_IMPLEMENT(PLHashEntry *)
+PL_HashTableAdd(PLHashTable *ht, const void *key, void *value)
+{
+    PLHashNumber keyHash;
+    PLHashEntry *he, **hep;
+
+    keyHash = (*ht->keyHash)(key);
+    hep = PL_HashTableRawLookup(ht, keyHash, key);
+    if ((he = *hep) != 0) {
+        /* Hit; see if values match */
+        if ((*ht->valueCompare)(he->value, value)) {
+            /* key,value pair is already present in table */
+            return he;
+        }
+        if (he->value)
+            (*ht->allocOps->freeEntry)(ht->allocPriv, he, HT_FREE_VALUE);
+        he->value = value;
+        return he;
+    }
+    return PL_HashTableRawAdd(ht, hep, keyHash, key, value);
+}
+
+PR_IMPLEMENT(void)
+PL_HashTableRawRemove(PLHashTable *ht, PLHashEntry **hep, PLHashEntry *he)
+{
+    PRUint32 i, n;
+    PLHashEntry *next, **oldbuckets;
+    PRSize nb;
+
+    *hep = he->next;
+    (*ht->allocOps->freeEntry)(ht->allocPriv, he, HT_FREE_ENTRY);
+
+    /* Shrink table if it's underloaded */
+    n = NBUCKETS(ht);
+    if (--ht->nentries < UNDERLOADED(n)) {
+        oldbuckets = ht->buckets;
+        nb = n * sizeof(PLHashEntry*) / 2;
+        ht->buckets = (PLHashEntry**)(
+            (*ht->allocOps->allocTable)(ht->allocPriv, nb));
+        if (!ht->buckets) {
+            ht->buckets = oldbuckets;
+            return;
+        }
+        memset(ht->buckets, 0, nb);
+#ifdef HASHMETER
+        ht->nshrinks++;
+#endif
+        ht->shift++;
+
+        for (i = 0; i < n; i++) {
+            for (he = oldbuckets[i]; he; he = next) {
+                next = he->next;
+                hep = PL_HashTableRawLookup(ht, he->keyHash, he->key);
+                PR_ASSERT(*hep == 0);
+                he->next = 0;
+                *hep = he;
+            }
+        }
+#ifdef DEBUG
+        memset(oldbuckets, 0xDB, n * sizeof oldbuckets[0]);
+#endif
+        (*ht->allocOps->freeTable)(ht->allocPriv, oldbuckets);
+    }
+}
+
+PR_IMPLEMENT(PRBool)
+PL_HashTableRemove(PLHashTable *ht, const void *key)
+{
+    PLHashNumber keyHash;
+    PLHashEntry *he, **hep;
+
+    keyHash = (*ht->keyHash)(key);
+    hep = PL_HashTableRawLookup(ht, keyHash, key);
+    if ((he = *hep) == 0)
+        return PR_FALSE;
+
+    /* Hit; remove element */
+    PL_HashTableRawRemove(ht, hep, he);
+    return PR_TRUE;
+}
+
+PR_IMPLEMENT(void *)
+PL_HashTableLookup(PLHashTable *ht, const void *key)
+{
+    PLHashNumber keyHash;
+    PLHashEntry *he, **hep;
+
+    keyHash = (*ht->keyHash)(key);
+    hep = PL_HashTableRawLookup(ht, keyHash, key);
+    if ((he = *hep) != 0) {
+        return he->value;
+    }
+    return 0;
+}
+
+/*
+** Same as PL_HashTableLookup but doesn't reorder the hash entries.
+*/
+PR_IMPLEMENT(void *)
+PL_HashTableLookupConst(PLHashTable *ht, const void *key)
+{
+    PLHashNumber keyHash;
+    PLHashEntry *he, **hep;
+
+    keyHash = (*ht->keyHash)(key);
+    hep = PL_HashTableRawLookupConst(ht, keyHash, key);
+    if ((he = *hep) != 0) {
+        return he->value;
+    }
+    return 0;
+}
+
+/*
+** Iterate over the entries in the hash table calling func for each
+** entry found. Stop if "f" says to (return value & PR_ENUMERATE_STOP).
+** Return a count of the number of elements scanned.
+*/
+PR_IMPLEMENT(int)
+PL_HashTableEnumerateEntries(PLHashTable *ht, PLHashEnumerator f, void *arg)
+{
+    PLHashEntry *he, **hep;
+    PRUint32 i, nbuckets;
+    int rv, n = 0;
+    PLHashEntry *todo = 0;
+
+    nbuckets = NBUCKETS(ht);
+    for (i = 0; i < nbuckets; i++) {
+        hep = &ht->buckets[i];
+        while ((he = *hep) != 0) {
+            rv = (*f)(he, n, arg);
+            n++;
+            if (rv & (HT_ENUMERATE_REMOVE | HT_ENUMERATE_UNHASH)) {
+                *hep = he->next;
+                if (rv & HT_ENUMERATE_REMOVE) {
+                    he->next = todo;
+                    todo = he;
+                }
+            } else {
+                hep = &he->next;
+            }
+            if (rv & HT_ENUMERATE_STOP) {
+                goto out;
+            }
+        }
+    }
+
+out:
+    hep = &todo;
+    while ((he = *hep) != 0) {
+        PL_HashTableRawRemove(ht, hep, he);
+    }
+    return n;
+}
+
+#ifdef HASHMETER
+#include <math.h>
+#include <stdio.h>
+
+PR_IMPLEMENT(void)
+PL_HashTableDumpMeter(PLHashTable *ht, PLHashEnumerator dump, FILE *fp)
+{
+    double mean, variance;
+    PRUint32 nchains, nbuckets;
+    PRUint32 i, n, maxChain, maxChainLen;
+    PLHashEntry *he;
+
+    variance = 0;
+    nchains = 0;
+    maxChainLen = 0;
+    nbuckets = NBUCKETS(ht);
+    for (i = 0; i < nbuckets; i++) {
+        he = ht->buckets[i];
+        if (!he)
+            continue;
+        nchains++;
+        for (n = 0; he; he = he->next)
+            n++;
+        variance += n * n;
+        if (n > maxChainLen) {
+            maxChainLen = n;
+            maxChain = i;
+        }
+    }
+    mean = (double)ht->nentries / nchains;
+    variance = fabs(variance / nchains - mean * mean);
+
+    fprintf(fp, "\nHash table statistics:\n");
+    fprintf(fp, "     number of lookups: %u\n", ht->nlookups);
+    fprintf(fp, "     number of entries: %u\n", ht->nentries);
+    fprintf(fp, "       number of grows: %u\n", ht->ngrows);
+    fprintf(fp, "     number of shrinks: %u\n", ht->nshrinks);
+    fprintf(fp, "   mean steps per hash: %g\n", (double)ht->nsteps
+                                                / ht->nlookups);
+    fprintf(fp, "mean hash chain length: %g\n", mean);
+    fprintf(fp, "    standard deviation: %g\n", sqrt(variance));
+    fprintf(fp, " max hash chain length: %u\n", maxChainLen);
+    fprintf(fp, "        max hash chain: [%u]\n", maxChain);
+
+    for (he = ht->buckets[maxChain], i = 0; he; he = he->next, i++)
+        if ((*dump)(he, i, fp) != HT_ENUMERATE_NEXT)
+            break;
+}
+#endif /* HASHMETER */
+
+PR_IMPLEMENT(int)
+PL_HashTableDump(PLHashTable *ht, PLHashEnumerator dump, FILE *fp)
+{
+    int count;
+
+    count = PL_HashTableEnumerateEntries(ht, dump, fp);
+#ifdef HASHMETER
+    PL_HashTableDumpMeter(ht, dump, fp);
+#endif
+    return count;
+}
+
+PR_IMPLEMENT(PLHashNumber)
+PL_HashString(const void *key)
+{
+    PLHashNumber h;
+    const PRUint8 *s;
+
+    h = 0;
+    for (s = (const PRUint8*)key; *s; s++)
+        h = PR_ROTATE_LEFT32(h, 4) ^ *s;
+    return h;
+}
+
+PR_IMPLEMENT(int)
+PL_CompareStrings(const void *v1, const void *v2)
+{
+    return strcmp((const char*)v1, (const char*)v2) == 0;
+}
+
+PR_IMPLEMENT(int)
+PL_CompareValues(const void *v1, const void *v2)
+{
+    return v1 == v2;
+}
diff --git a/lib/ds/plhash.h b/lib/ds/plhash.h
new file mode 100644
index 0000000..2c221ae
--- /dev/null
+++ b/lib/ds/plhash.h
@@ -0,0 +1,126 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef plhash_h___
+#define plhash_h___
+/*
+ * API to portable hash table code.
+ */
+#include <stdio.h>
+#include "prtypes.h"
+
+PR_BEGIN_EXTERN_C
+
+typedef struct PLHashEntry  PLHashEntry;
+typedef struct PLHashTable  PLHashTable;
+typedef PRUint32 PLHashNumber;
+#define PL_HASH_BITS 32  /* Number of bits in PLHashNumber */
+typedef PLHashNumber (PR_CALLBACK *PLHashFunction)(const void *key);
+typedef PRIntn (PR_CALLBACK *PLHashComparator)(const void *v1, const void *v2);
+
+typedef PRIntn (PR_CALLBACK *PLHashEnumerator)(PLHashEntry *he, PRIntn i, void *arg);
+
+/* Flag bits in PLHashEnumerator's return value */
+#define HT_ENUMERATE_NEXT       0       /* continue enumerating entries */
+#define HT_ENUMERATE_STOP       1       /* stop enumerating entries */
+#define HT_ENUMERATE_REMOVE     2       /* remove and free the current entry */
+#define HT_ENUMERATE_UNHASH     4       /* just unhash the current entry */
+
+typedef struct PLHashAllocOps {
+    void *              (PR_CALLBACK *allocTable)(void *pool, PRSize size);
+    void                (PR_CALLBACK *freeTable)(void *pool, void *item);
+    PLHashEntry *       (PR_CALLBACK *allocEntry)(void *pool, const void *key);
+    void                (PR_CALLBACK *freeEntry)(void *pool, PLHashEntry *he, PRUintn flag);
+} PLHashAllocOps;
+
+#define HT_FREE_VALUE   0               /* just free the entry's value */
+#define HT_FREE_ENTRY   1               /* free value and entire entry */
+
+struct PLHashEntry {
+    PLHashEntry         *next;          /* hash chain linkage */
+    PLHashNumber        keyHash;        /* key hash function result */
+    const void          *key;           /* ptr to opaque key */
+    void                *value;         /* ptr to opaque value */
+};
+
+struct PLHashTable {
+    PLHashEntry         **buckets;      /* vector of hash buckets */
+    PRUint32              nentries;       /* number of entries in table */
+    PRUint32              shift;          /* multiplicative hash shift */
+    PLHashFunction      keyHash;        /* key hash function */
+    PLHashComparator    keyCompare;     /* key comparison function */
+    PLHashComparator    valueCompare;   /* value comparison function */
+    const PLHashAllocOps *allocOps;     /* allocation operations */
+    void                *allocPriv;     /* allocation private data */
+#ifdef HASHMETER
+    PRUint32              nlookups;       /* total number of lookups */
+    PRUint32              nsteps;         /* number of hash chains traversed */
+    PRUint32              ngrows;         /* number of table expansions */
+    PRUint32              nshrinks;       /* number of table contractions */
+#endif
+};
+
+/*
+ * Create a new hash table.
+ * If allocOps is null, use default allocator ops built on top of malloc().
+ */
+PR_EXTERN(PLHashTable *)
+PL_NewHashTable(PRUint32 numBuckets, PLHashFunction keyHash,
+                PLHashComparator keyCompare, PLHashComparator valueCompare,
+                const PLHashAllocOps *allocOps, void *allocPriv);
+
+PR_EXTERN(void)
+PL_HashTableDestroy(PLHashTable *ht);
+
+/* Higher level access methods */
+PR_EXTERN(PLHashEntry *)
+PL_HashTableAdd(PLHashTable *ht, const void *key, void *value);
+
+PR_EXTERN(PRBool)
+PL_HashTableRemove(PLHashTable *ht, const void *key);
+
+PR_EXTERN(void *)
+PL_HashTableLookup(PLHashTable *ht, const void *key);
+
+PR_EXTERN(void *)
+PL_HashTableLookupConst(PLHashTable *ht, const void *key);
+
+PR_EXTERN(PRIntn)
+PL_HashTableEnumerateEntries(PLHashTable *ht, PLHashEnumerator f, void *arg);
+
+/* General-purpose C string hash function. */
+PR_EXTERN(PLHashNumber)
+PL_HashString(const void *key);
+
+/* Compare strings using strcmp(), return true if equal. */
+PR_EXTERN(PRIntn)
+PL_CompareStrings(const void *v1, const void *v2);
+
+/* Stub function just returns v1 == v2 */
+PR_EXTERN(PRIntn)
+PL_CompareValues(const void *v1, const void *v2);
+
+/* Low level access methods */
+PR_EXTERN(PLHashEntry **)
+PL_HashTableRawLookup(PLHashTable *ht, PLHashNumber keyHash, const void *key);
+
+PR_EXTERN(PLHashEntry **)
+PL_HashTableRawLookupConst(PLHashTable *ht, PLHashNumber keyHash,
+                           const void *key);
+
+PR_EXTERN(PLHashEntry *)
+PL_HashTableRawAdd(PLHashTable *ht, PLHashEntry **hep, PLHashNumber keyHash,
+                   const void *key, void *value);
+
+PR_EXTERN(void)
+PL_HashTableRawRemove(PLHashTable *ht, PLHashEntry **hep, PLHashEntry *he);
+
+/* This can be trivially implemented using PL_HashTableEnumerateEntries. */
+PR_EXTERN(PRIntn)
+PL_HashTableDump(PLHashTable *ht, PLHashEnumerator dump, FILE *fp);
+
+PR_END_EXTERN_C
+
+#endif /* plhash_h___ */
diff --git a/lib/ds/plvrsion.c b/lib/ds/plvrsion.c
new file mode 100644
index 0000000..e251a5a
--- /dev/null
+++ b/lib/ds/plvrsion.c
@@ -0,0 +1,93 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "prinit.h"
+#include "prvrsion.h"
+
+/************************************************************************/
+/**************************IDENTITY AND VERSIONING***********************/
+/************************************************************************/
+#include "_pl_bld.h"
+#if !defined(_BUILD_TIME)
+#ifdef HAVE_LONG_LONG
+#define _BUILD_TIME 0
+#else
+#define _BUILD_TIME {0, 0}
+#endif
+#endif
+#if !defined(_BUILD_STRING)
+#define _BUILD_STRING ""
+#endif
+#if !defined(_PRODUCTION)
+#define _PRODUCTION ""
+#endif
+#if defined(DEBUG)
+#define _DEBUG_STRING " (debug)"
+#else
+#define _DEBUG_STRING ""
+#endif
+
+/*
+ * A trick to expand the PR_VMAJOR macro before concatenation.
+ */
+#define CONCAT(x, y) x ## y
+#define CONCAT2(x, y) CONCAT(x, y)
+#define VERSION_DESC_NAME CONCAT2(prVersionDescription_libplds, PR_VMAJOR)
+
+PRVersionDescription VERSION_DESC_NAME =
+{
+    /* version          */  2,                  /* this is the only one supported */
+    /* buildTime        */  _BUILD_TIME,        /* usecs since midnight 1/1/1970 GMT */
+    /* buildTimeString  */  _BUILD_STRING,       /*    ditto, but human readable */
+    /* vMajor           */  PR_VMAJOR,          /* NSPR's version number */
+    /* vMinor           */  PR_VMINOR,          /*  and minor version */
+    /* vPatch           */  PR_VPATCH,          /*  and patch */
+    /* beta             */  PR_BETA,            /* beta build boolean */
+#if defined(DEBUG)
+    /* debug            */  PR_TRUE,            /* a debug build */
+#else
+    /* debug            */  PR_FALSE,           /* an optomized build */
+#endif
+    /* special          */  PR_FALSE,           /* they're all special, but ... */
+    /* filename         */  _PRODUCTION,        /* the produced library name */
+    /* description      */ "Portable runtime",  /* what we are */
+    /* security         */ "N/A",               /* not applicable here */
+    /* copywrite        */  "Copyright (c) 1998 Netscape Communications Corporation. All Rights Reserved",
+    /* comment          */  "http://www.mozilla.org/MPL/",
+    /* specialString    */ ""
+};
+
+#ifdef XP_UNIX
+
+/*
+ * Version information for the 'ident' and 'what commands
+ *
+ * NOTE: the first component of the concatenated rcsid string
+ * must not end in a '$' to prevent rcs keyword substitution.
+ */
+static char rcsid[] = "$Header: NSPR " PR_VERSION _DEBUG_STRING
+        "  " _BUILD_STRING " $";
+static char sccsid[] = "@(#)NSPR " PR_VERSION _DEBUG_STRING
+        "  " _BUILD_STRING;
+
+#endif /* XP_UNIX */
+
+PR_IMPLEMENT(const PRVersionDescription*) libVersionPoint()
+{
+#ifdef XP_UNIX
+    /*
+     * Add dummy references to rcsid and sccsid to prevent them
+     * from being optimized away as unused variables.
+     */
+    const char *dummy;
+    
+    dummy = rcsid;
+    dummy = sccsid;
+#endif
+    return &VERSION_DESC_NAME;
+}  /* versionEntryPointType */
+
+/* plvrsion.c */
+
diff --git a/lib/libc/.cvsignore b/lib/libc/.cvsignore
new file mode 100644
index 0000000..f3c7a7c
--- /dev/null
+++ b/lib/libc/.cvsignore
@@ -0,0 +1 @@
+Makefile
diff --git a/lib/libc/Makefile.in b/lib/libc/Makefile.in
new file mode 100644
index 0000000..28027f9
--- /dev/null
+++ b/lib/libc/Makefile.in
@@ -0,0 +1,24 @@
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#! gmake
+
+MOD_DEPTH	= ../..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+
+include $(MOD_DEPTH)/config/autoconf.mk
+
+export NSPR20=1
+
+include $(topsrcdir)/config/config.mk
+
+DIRS = include src
+
+include $(topsrcdir)/config/rules.mk
+
+export:: $(TARGETS)
+
diff --git a/lib/libc/README b/lib/libc/README
new file mode 100644
index 0000000..74f2469
--- /dev/null
+++ b/lib/libc/README
@@ -0,0 +1,20 @@
+NSPR 2.0 libc functions
+-----------------------
+
+Last edited: AOF 04 March 1997
+
+This directory contains various libc-types of functions. All functions in
+this directory are platform independent, thread friendly (both safe and
+efficient). They are contributed from various sources, though the contri-
+butions are monitored by the NSPR group (mailto:freier).
+
+All API items exported by these functions will contain the same three
+character prefix, "PL_" (Portable Library). Internal function names
+that are not exported (static) are of little concern, though some caution
+must be used on those elements that are 'extern' but not really intended
+to be part of the API. Those should all have a prefix of "_PL_" (is that
+legal?).
+
+The responsibility for contributions in this area are distributed among
+all interested parties.
+
diff --git a/lib/libc/include/.cvsignore b/lib/libc/include/.cvsignore
new file mode 100644
index 0000000..f3c7a7c
--- /dev/null
+++ b/lib/libc/include/.cvsignore
@@ -0,0 +1 @@
+Makefile
diff --git a/lib/libc/include/Makefile.in b/lib/libc/include/Makefile.in
new file mode 100644
index 0000000..642e0a1
--- /dev/null
+++ b/lib/libc/include/Makefile.in
@@ -0,0 +1,24 @@
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#! gmake
+
+MOD_DEPTH	= ../../..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+
+include $(MOD_DEPTH)/config/autoconf.mk
+include $(topsrcdir)/config/config.mk
+
+HEADERS = $(wildcard $(srcdir)/*.h)
+
+RELEASE_HEADERS = $(HEADERS)
+RELEASE_HEADERS_DEST = $(RELEASE_INCLUDE_DIR)
+
+include $(topsrcdir)/config/rules.mk
+
+export:: $(HEADERS)
+	$(INSTALL) -m 444 $(HEADERS) $(dist_includedir)
diff --git a/lib/libc/include/README b/lib/libc/include/README
new file mode 100644
index 0000000..2b85218
--- /dev/null
+++ b/lib/libc/include/README
@@ -0,0 +1,7 @@
+NSPR 2.0 libc functions
+-----------------------
+
+Last edited: AOF 04 March 1997
+
+This directory contains the API for various libc-types of functions.
+
diff --git a/lib/libc/include/plbase64.h b/lib/libc/include/plbase64.h
new file mode 100644
index 0000000..7d17ea7
--- /dev/null
+++ b/lib/libc/include/plbase64.h
@@ -0,0 +1,76 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef _plbase64_h
+#define _plbase64_h
+
+#include "prtypes.h"
+
+PR_BEGIN_EXTERN_C
+
+/*
+ * PL_Base64Encode
+ *
+ * This routine encodes the data pointed to by the "src" parameter using the
+ * base64 algorithm, and returns a pointer to the result.  If the "srclen"
+ * parameter is not zero, it specifies the length of the source data.  If it
+ * is zero, the source data is assumed to be null-terminated, and PL_strlen
+ * is used to determine the source length.  If the "dest" parameter is not
+ * null, it is assumed to point to a buffer of sufficient size (which may be
+ * calculated: ((srclen + 2)/3)*4) into which the encoded data is placed 
+ * (without any termination).  If the "dest" parameter is null, a buffer is
+ * allocated from the heap to hold the encoded data, and the result *will*
+ * be terminated with an extra null character.  It is the caller's 
+ * responsibility to free the result when it is allocated.  A null is returned 
+ * if the allocation fails.
+ *
+ * NOTE: when calculating ((srclen + 2)/3)*4), first ensure that
+ *     srclen <= (PR_UINT32_MAX/4) * 3
+ * to avoid PRUint32 overflow.
+ */
+
+PR_EXTERN(char *)
+PL_Base64Encode
+(
+    const char *src,
+    PRUint32    srclen,
+    char       *dest
+);
+
+/*
+ * PL_Base64Decode
+ *
+ * This routine decodes the data pointed to by the "src" parameter using
+ * the base64 algorithm, and returns a pointer to the result.  The source
+ * may either include or exclude any trailing '=' characters.  If the
+ * "srclen" parameter is not zero, it specifies the length of the source
+ * data.  If it is zero, PL_strlen will be used to determine the source
+ * length.  If the "dest" parameter is not null, it is assumed to point to
+ * a buffer of sufficient size (which may be calculated: (srclen * 3)/4
+ * when srclen includes the '=' characters) into which the decoded data
+ * is placed (without any termination).  If the "dest" parameter is null,
+ * a buffer is allocated from the heap to hold the decoded data, and the
+ * result *will* be terminated with an extra null character.  It is the
+ * caller's responsibility to free the result when it is allocated.  A null
+ * is retuned if the allocation fails, or if the source is not well-coded.
+ *
+ * NOTE: when calculating (srclen * 3)/4, first ensure that 
+ *     srclen <= PR_UINT32_MAX/3
+ * to avoid PRUint32 overflow.  Alternatively, calculate
+ *     (srclen/4) * 3 + ((srclen%4) * 3)/4
+ * which is equivalent but doesn't overflow for any value of srclen.
+ */
+
+PR_EXTERN(char *)
+PL_Base64Decode
+(
+    const char *src,
+    PRUint32    srclen,
+    char       *dest
+);
+
+PR_END_EXTERN_C
+
+#endif /* _plbase64_h */
diff --git a/lib/libc/include/plerror.h b/lib/libc/include/plerror.h
new file mode 100644
index 0000000..cd85dd3
--- /dev/null
+++ b/lib/libc/include/plerror.h
@@ -0,0 +1,34 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** File:        plerror.h
+** Description: Simple routine to print translate the calling thread's
+**              error numbers and print them.
+*/
+
+#if defined(PLERROR_H)
+#else
+#define PLERROR_H
+
+#include "prio.h"
+#include "prtypes.h"
+
+PR_BEGIN_EXTERN_C
+/*
+** Print the messages to "syserr" prepending 'msg' if not NULL.
+*/
+PR_EXTERN(void) PL_PrintError(const char *msg);
+
+/*
+** Print the messages to specified output file prepending 'msg' if not NULL.
+*/
+PR_EXTERN(void) PL_FPrintError(PRFileDesc *output, const char *msg);
+
+PR_END_EXTERN_C
+
+#endif /* defined(PLERROR_H) */
+
+/* plerror.h */
diff --git a/lib/libc/include/plgetopt.h b/lib/libc/include/plgetopt.h
new file mode 100644
index 0000000..19cafa6
--- /dev/null
+++ b/lib/libc/include/plgetopt.h
@@ -0,0 +1,125 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** File:          plgetopt.h
+** Description:   utilities to parse argc/argv
+*/
+
+#if defined(PLGETOPT_H_)
+#else
+#define PLGETOPT_H_
+
+#include "prtypes.h"
+
+PR_BEGIN_EXTERN_C
+
+typedef struct PLOptionInternal PLOptionInternal; 
+
+typedef enum
+{
+        PL_OPT_OK,              /* all's well with the option */
+        PL_OPT_EOL,             /* end of options list */
+        PL_OPT_BAD              /* invalid option (and value) */
+} PLOptStatus;
+
+typedef struct PLLongOpt
+{
+    const char * longOptName;   /* long option name string                  */
+    PRIntn       longOption;    /* value put in PLOptState for this option. */
+    PRBool       valueRequired; /* If option name not followed by '=',      */
+                                /* value is the next argument from argv.    */
+} PLLongOpt;
+
+typedef struct PLOptState
+{
+    char option;                /* the name of the option */
+    const char *value;          /* the value of that option | NULL */
+
+    PLOptionInternal *internal; /* private processing state */
+
+    PRIntn   longOption;        /* value from PLLongOpt put here */
+    PRIntn   longOptIndex;      /* index into caller's array of PLLongOpts */
+} PLOptState;
+
+/*
+ * PL_CreateOptState
+ *
+ * The argument "options" points to a string of single-character option 
+ * names.  Option names that may have an option argument value must be 
+ * followed immediately by a ':' character.  
+ */
+PR_EXTERN(PLOptState*) PL_CreateOptState(
+        PRIntn argc, char **argv, const char *options);
+
+/* 
+ * PL_CreateLongOptState
+ *
+ * Alternative to PL_CreateOptState.  
+ * Allows caller to specify BOTH a string of single-character option names, 
+ * AND an array of structures describing "long" (keyword) option names.  
+ * The array is terminated by a structure in which longOptName is NULL.  
+ * Long option values (arguments) may always be given as "--name=value".
+ * If PLLongOpt.valueRequired is not PR_FALSE, and the option name was not 
+ * followed by '=' then the next argument from argv is taken as the value.  
+ */
+PR_EXTERN(PLOptState*) PL_CreateLongOptState(
+        PRIntn argc, char **argv, const char *options, 
+        const PLLongOpt *longOpts);
+/*
+ * PL_DestroyOptState
+ *
+ * Call this to destroy the PLOptState returned from PL_CreateOptState or
+ * PL_CreateLongOptState.
+ */
+PR_EXTERN(void) PL_DestroyOptState(PLOptState *opt);
+
+/*
+ * PL_GetNextOpt
+ *
+ * When this function returns PL_OPT_OK, 
+ * - opt->option will hold the single-character option name that was parsed, 
+ *   or zero.  
+ * When opt->option is zero, the token parsed was either a "long" (keyword) 
+ *   option or a positional parameter.  
+ * For a positional parameter, 
+ * - opt->longOptIndex will contain -1, and
+ * - opt->value will point to the positional parameter string.
+ * For a long option name, 
+ * - opt->longOptIndex will contain the non-negative index of the 
+ *   PLLongOpt structure in the caller's array of PLLongOpt structures 
+ *   corresponding to the long option name, and 
+ * For a single-character or long option, 
+ * - opt->longOption will contain the value of the single-character option
+ *   name, or the value of the longOption from the PLLongOpt structure
+ *   for that long option.  See notes below.
+ * - opt->value will point to the argument option string, or will
+ *   be NULL if option does not require argument.  If option requires
+ *   argument but it is not provided, PL_OPT_BAD is returned.
+ * When opt->option is non-zero, 
+ * - opt->longOptIndex will be -1
+ * When this function returns PL_OPT_EOL, or PL_OPT_BAD, the contents of
+ *   opt are undefined.
+ *
+ * Notes: It is possible to ignore opt->option, and always look at 
+ *   opt->longOption instead.  opt->longOption will contain the same value
+ *   as opt->option for single-character option names, and will contain the
+ *   value of longOption from the PLLongOpt structure for long option names.
+ * This means that it is possible to equivalence long option names to 
+ *   single character names by giving the longOption in the PLLongOpt struct
+ *   the same value as the single-character option name.  
+ * For long options that are NOT intended to be equivalent to any single-
+ *   character option, the longOption value should be chosen to not match 
+ *   any possible single character name.  It might be advisable to choose
+ *   longOption values greater than 0xff for such long options.
+ */
+PR_EXTERN(PLOptStatus) PL_GetNextOpt(PLOptState *opt);
+
+PR_END_EXTERN_C
+
+#endif /* defined(PLGETOPT_H_) */
+
+/* plgetopt.h */
+
diff --git a/lib/libc/include/plstr.h b/lib/libc/include/plstr.h
new file mode 100644
index 0000000..57814c7
--- /dev/null
+++ b/lib/libc/include/plstr.h
@@ -0,0 +1,437 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef _plstr_h
+#define _plstr_h
+
+/*
+ * plstr.h
+ *
+ * This header file exports the API to the NSPR portable library or string-
+ * handling functions.  
+ * 
+ * This API was not designed as an "optimal" or "ideal" string library; it 
+ * was based on the good ol' unix string.3 functions, and was written to
+ *
+ *  1) replace the libc functions, for cross-platform consistency, 
+ *  2) complete the API on platforms lacking common functions (e.g., 
+ *     strcase*), and
+ *  3) to implement some obvious "closure" functions that I've seen
+ *     people hacking around in our code.
+ *
+ * Point number three largely means that most functions have an "strn"
+ * limited-length version, and all comparison routines have a non-case-
+ * sensitive version available.
+ */
+
+#include "prtypes.h"
+
+PR_BEGIN_EXTERN_C
+/*
+ * PL_strlen
+ *
+ * Returns the length of the provided string, not including the trailing '\0'.
+ */
+
+PR_EXTERN(PRUint32)
+PL_strlen(const char *str);
+
+/*
+ * PL_strnlen
+ *
+ * Returns the length of the provided string, not including the trailing '\0',
+ * up to the indicated maximum.  The string will not be examined beyond the
+ * maximum; if no terminating '\0' is found, the maximum will be returned.
+ */
+
+PR_EXTERN(PRUint32)
+PL_strnlen(const char *str, PRUint32 max);
+
+/*
+ * PL_strcpy
+ *
+ * Copies the source string, up to and including the trailing '\0', into the
+ * destination buffer.  It does not (can not) verify that the destination
+ * buffer is large enough.  It returns the "dest" argument.
+ */
+
+PR_EXTERN(char *)
+PL_strcpy(char *dest, const char *src);
+
+/*
+ * PL_strncpy
+ *
+ * Copies the source string into the destination buffer, up to and including
+ * the trailing '\0' or up to and including the max'th character, whichever
+ * comes first.  It does not (can not) verify that the destination buffer is
+ * large enough.  If the source string is longer than the maximum length,
+ * the result will *not* be null-terminated (JLRU).
+ */
+
+PR_EXTERN(char *)
+PL_strncpy(char *dest, const char *src, PRUint32 max);
+
+/*
+ * PL_strncpyz
+ *
+ * Copies the source string into the destination buffer, up to and including 
+ * the trailing '\0' or up but not including the max'th character, whichever 
+ * comes first.  It does not (can not) verify that the destination buffer is
+ * large enough.  The destination string is always terminated with a '\0',
+ * unlike the traditional libc implementation.  It returns the "dest" argument.
+ *
+ * NOTE: If you call this with a source "abcdefg" and a max of 5, the 
+ * destination will end up with "abcd\0" (i.e., its strlen length will be 4)!
+ *
+ * This means you can do this:
+ *
+ *     char buffer[ SOME_SIZE ];
+ *     PL_strncpyz(buffer, src, sizeof(buffer));
+ *
+ * and the result will be properly terminated.
+ */
+
+PR_EXTERN(char *)
+PL_strncpyz(char *dest, const char *src, PRUint32 max);
+
+/*
+ * PL_strdup
+ *
+ * Returns a pointer to a malloc'd extent of memory containing a duplicate
+ * of the argument string.  The size of the allocated extent is one greater
+ * than the length of the argument string, because of the terminator.  A
+ * null argument, like a zero-length argument, will result in a pointer to
+ * a one-byte extent containing the null value.  This routine returns null
+ * upon malloc failure.
+ */
+
+PR_EXTERN(char *)
+PL_strdup(const char *s);
+
+/*
+ * PL_strfree
+ *
+ * Free memory allocated by PL_strdup
+ */
+
+PR_EXTERN(void)
+PL_strfree(char *s);
+
+/*
+ * PL_strndup
+ *
+ * Returns a pointer to a malloc'd extent of memory containing a duplicate
+ * of the argument string, up to the maximum specified.  If the argument
+ * string has a length greater than the value of the specified maximum, the
+ * return value will be a pointer to an extent of memory of length one
+ * greater than the maximum specified.  A null string, a zero-length string,
+ * or a zero maximum will all result in a pointer to a one-byte extent
+ * containing the null value.  This routine returns null upon malloc failure.
+ */
+
+PR_EXTERN(char *)
+PL_strndup(const char *s, PRUint32 max);
+
+/*
+ * PL_strcat
+ *
+ * Appends a copy of the string pointed to by the second argument to the
+ * end of the string pointed to by the first.  The destination buffer is
+ * not (can not be) checked for sufficient size.  A null destination
+ * argument returns null; otherwise, the first argument is returned.
+ */
+
+PR_EXTERN(char *)
+PL_strcat(char *dst, const char *src);
+
+/*
+ * PL_strncat
+ *
+ * Appends a copy of the string pointed to by the second argument, up to
+ * the maximum size specified, to the end of the string pointed to by the
+ * first.  The destination buffer is not (can not be) checked for sufficient
+ * size.  A null destination argument returns null; otherwise, the first 
+ * argument is returned.  If the maximum size limits the copy, then the
+ * result will *not* be null-terminated (JLRU).  A null destination
+ * returns null; otherwise, the destination argument is returned.
+ */
+
+PR_EXTERN(char *)
+PL_strncat(char *dst, const char *src, PRUint32 max);
+
+/*
+ * PL_strcatn
+ *
+ * Appends a copy of the string pointed to by the third argument, to the
+ * end of the string pointed to by the first.  The second argument specifies
+ * the maximum size of the destination buffer, including the null termination.
+ * If the existing string in dst is longer than the max, no action is taken.
+ * The resulting string will be null-terminated.  A null destination returns
+ * null; otherwise, the destination argument is returned.
+ */
+
+PR_EXTERN(char *)
+PL_strcatn(char *dst, PRUint32 max, const char *src);
+
+/*
+ * PL_strcmp
+ *
+ * Returns an integer, the sign of which -- positive, zero, or negative --
+ * reflects the lexical sorting order of the two strings indicated.  The
+ * result is positive if the first string comes after the second.  The
+ * NSPR implementation is not i18n.
+ */
+
+PR_EXTERN(PRIntn)
+PL_strcmp(const char *a, const char *b);
+
+/*
+ * PL_strncmp
+ * 
+ * Returns an integer, the sign of which -- positive, zero, or negative --
+ * reflects the lexical sorting order of the two strings indicated, up to
+ * the maximum specified.  The result is positive if the first string comes 
+ * after the second.  The NSPR implementation is not i18n.  If the maximum
+ * is zero, only the existance or non-existance (pointer is null) of the
+ * strings is compared.
+ */
+
+PR_EXTERN(PRIntn)
+PL_strncmp(const char *a, const char *b, PRUint32 max);
+
+/*
+ * PL_strcasecmp
+ *
+ * Returns an integer, the sign of which -- positive, zero or negative --
+ * reflects the case-insensitive lexical sorting order of the two strings
+ * indicated.  The result is positive if the first string comes after the 
+ * second.  The NSPR implementation is not i18n.
+ */
+
+PR_EXTERN(PRIntn)
+PL_strcasecmp(const char *a, const char *b);
+
+/*
+ * PL_strncasecmp
+ *
+ * Returns an integer, the sign of which -- positive, zero or negative --
+ * reflects the case-insensitive lexical sorting order of the first n characters
+ * of the two strings indicated.  The result is positive if the first string comes 
+ * after the second.  The NSPR implementation is not i18n.
+ */
+
+PR_EXTERN(PRIntn)
+PL_strncasecmp(const char *a, const char *b, PRUint32 max);
+
+/*
+ * PL_strchr
+ *
+ * Returns a pointer to the first instance of the specified character in the
+ * provided string.  It returns null if the character is not found, or if the
+ * provided string is null.  The character may be the null character.
+ */
+
+PR_EXTERN(char *)
+PL_strchr(const char *s, char c);
+
+/*
+ * PL_strrchr
+ *
+ * Returns a pointer to the last instance of the specified character in the
+ * provided string.  It returns null if the character is not found, or if the
+ * provided string is null.  The character may be the null character.
+ */
+
+PR_EXTERN(char *)
+PL_strrchr(const char *s, char c);
+
+/*
+ * PL_strnchr
+ * 
+ * Returns a pointer to the first instance of the specified character within the
+ * first n characters of the provided string.  It returns null if the character
+ * is not found, or if the provided string is null.  The character may be the
+ * null character.
+ */
+
+PR_EXTERN(char *)
+PL_strnchr(const char *s, char c, PRUint32 n);
+
+/*
+ * PL_strnrchr
+ *
+ * Returns a pointer to the last instance of the specified character within the
+ * first n characters of the provided string.  It returns null if the character is
+ * not found, or if the provided string is null.  The character may be the null
+ * character.
+ */
+
+PR_EXTERN(char *)
+PL_strnrchr(const char *s, char c, PRUint32 n);
+
+/*
+ * NOTE: Looking for strcasechr, strcaserchr, strncasechr, or strncaserchr?
+ * Use strpbrk, strprbrk, strnpbrk or strnprbrk.
+ */
+
+/*
+ * PL_strpbrk
+ *
+ * Returns a pointer to the first instance in the first string of any character
+ * (not including the terminating null character) of the second string.  It returns
+ * null if either string is null.
+ */
+
+PR_EXTERN(char *)
+PL_strpbrk(const char *s, const char *list);
+
+/*
+ * PL_strprbrk
+ *
+ * Returns a pointer to the last instance in the first string of any character
+ * (not including the terminating null character) of the second string.  It returns
+ * null if either string is null.
+ */
+
+PR_EXTERN(char *)
+PL_strprbrk(const char *s, const char *list);
+
+/*
+ * PL_strnpbrk
+ *
+ * Returns a pointer to the first instance (within the first n characters) of any
+ * character (not including the terminating null character) of the second string.
+ * It returns null if either string is null.
+ */
+
+PR_EXTERN(char *)
+PL_strnpbrk(const char *s, const char *list, PRUint32 n);
+
+/*
+ * PL_strnprbrk
+ *
+ * Returns a pointer to the last instance (within the first n characters) of any
+ * character (not including the terminating null character) of the second string.
+ * It returns null if either string is null.
+ */
+
+PR_EXTERN(char *)
+PL_strnprbrk(const char *s, const char *list, PRUint32 n);
+
+/*
+ * PL_strstr
+ *
+ * Returns a pointer to the first instance of the little string within the
+ * big one.  It returns null if either string is null.
+ */
+
+PR_EXTERN(char *)
+PL_strstr(const char *big, const char *little);
+
+/*
+ * PL_strrstr
+ *
+ * Returns a pointer to the last instance of the little string within the big one.
+ * It returns null if either string is null.
+ */
+
+PR_EXTERN(char *)
+PL_strrstr(const char *big, const char *little);
+
+/*
+ * PL_strnstr
+ *
+ * Returns a pointer to the first instance of the little string within the first
+ * n characters of the big one.  It returns null if either string is null.  It
+ * returns null if the length of the little string is greater than n.
+ */
+
+PR_EXTERN(char *)
+PL_strnstr(const char *big, const char *little, PRUint32 n);
+
+/*
+ * PL_strnrstr
+ *
+ * Returns a pointer to the last instance of the little string within the first
+ * n characters of the big one.  It returns null if either string is null.  It
+ * returns null if the length of the little string is greater than n.
+ */
+
+PR_EXTERN(char *)
+PL_strnrstr(const char *big, const char *little, PRUint32 max);
+
+/*
+ * PL_strcasestr
+ *
+ * Returns a pointer to the first instance of the little string within the big one,
+ * ignoring case.  It returns null if either string is null.
+ */
+
+PR_EXTERN(char *)
+PL_strcasestr(const char *big, const char *little);
+
+/*
+ * PL_strcaserstr
+ *
+ * Returns a pointer to the last instance of the little string within the big one,
+ * ignoring case.  It returns null if either string is null.
+ */
+
+PR_EXTERN(char *)
+PL_strcaserstr(const char *big, const char *little);
+
+/*
+ * PL_strncasestr
+ *
+ * Returns a pointer to the first instance of the little string within the first
+ * n characters of the big one, ignoring case.  It returns null if either string is 
+ * null.  It returns null if the length of the little string is greater than n.
+ */
+
+PR_EXTERN(char *)
+PL_strncasestr(const char *big, const char *little, PRUint32 max);
+
+/*
+ * PL_strncaserstr
+ *
+ * Returns a pointer to the last instance of the little string within the first
+ * n characters of the big one, ignoring case.  It returns null if either string is
+ * null.  It returns null if the length of the little string is greater than n.
+ */
+
+PR_EXTERN(char *)
+PL_strncaserstr(const char *big, const char *little, PRUint32 max);
+
+/*
+ * PL_strtok_r
+ *
+ * Splits the string s1 into tokens, separated by one or more characters
+ * from the separator string s2.  The argument lasts points to a
+ * user-supplied char * pointer in which PL_strtok_r stores information
+ * for it to continue scanning the same string.
+ *
+ * In the first call to PL_strtok_r, s1 points to a string and the value
+ * of *lasts is ignored.  PL_strtok_r returns a pointer to the first
+ * token, writes '\0' into the character following the first token, and
+ * updates *lasts.
+ *
+ * In subsequent calls, s1 is null and lasts must stay unchanged from the
+ * previous call.  The separator string s2 may be different from call to
+ * call.  PL_strtok_r returns a pointer to the next token in s1.  When no
+ * token remains in s1, PL_strtok_r returns null.
+ */
+
+PR_EXTERN(char *)
+PL_strtok_r(char *s1, const char *s2, char **lasts);
+
+/*
+ * Things not (yet?) included: strspn/strcspn, strsep.
+ * memchr, memcmp, memcpy, memccpy, index, rindex, bcmp, bcopy, bzero.
+ * Any and all i18n/l10n stuff.
+ */
+
+PR_END_EXTERN_C
+
+#endif /* _plstr_h */
diff --git a/lib/libc/src/.cvsignore b/lib/libc/src/.cvsignore
new file mode 100644
index 0000000..bcab60f
--- /dev/null
+++ b/lib/libc/src/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+_pl_bld.h
diff --git a/lib/libc/src/Makefile.in b/lib/libc/src/Makefile.in
new file mode 100644
index 0000000..e8a6d9f
--- /dev/null
+++ b/lib/libc/src/Makefile.in
@@ -0,0 +1,152 @@
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+#! gmake
+
+MOD_DEPTH	= ../../..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+
+include $(MOD_DEPTH)/config/autoconf.mk
+
+include $(topsrcdir)/config/config.mk
+
+INCLUDES = -I$(dist_includedir)
+
+CSRCS =\
+	plvrsion.c  \
+	strlen.c  \
+	strcpy.c  \
+	strdup.c  \
+	strcase.c \
+	strcat.c  \
+	strcmp.c  \
+	strchr.c  \
+	strpbrk.c \
+	strstr.c  \
+	strtok.c  \
+	base64.c \
+	plerror.c \
+	plgetopt.c \
+	$(NULL)
+
+LIBRARY_NAME	= plc
+LIBRARY_VERSION	= $(MOD_MAJOR_VERSION)
+
+RELEASE_LIBS = $(TARGETS)
+
+ifeq ($(OS_ARCH),WINNT)
+RES=$(OBJDIR)/plc.res
+RESNAME=plc.rc
+endif # WINNT
+
+ifeq ($(OS_ARCH), AIX)
+ifeq ($(CLASSIC_NSPR),1)
+OS_LIBS = -lc
+else
+OS_LIBS = -lc_r
+endif
+endif
+
+ifeq ($(OS_ARCH),IRIX)
+OS_LIBS = -lc
+endif
+
+ifeq ($(OS_ARCH),SunOS)
+OS_LIBS = -lc
+MAPFILE = $(OBJDIR)/plcmap.sun
+GARBAGE += $(MAPFILE)
+ifdef NS_USE_GCC
+ifdef GCC_USE_GNU_LD
+MKSHLIB += -Wl,--version-script,$(MAPFILE)
+else
+MKSHLIB += -Wl,-M,$(MAPFILE)
+endif
+else
+MKSHLIB += -M $(MAPFILE)
+endif
+# The -R '$ORIGIN' linker option instructs this library to search for its
+# dependencies in the same directory where it resides.
+MKSHLIB += -R '$$ORIGIN'
+endif
+
+ifeq ($(OS_ARCH),OS2)
+MAPFILE = $(OBJDIR)/$(LIBRARY_NAME)$(LIBRARY_VERSION).def
+GARBAGE += $(MAPFILE)
+MKSHLIB += $(MAPFILE)
+endif
+
+EXTRA_LIBS = $(LIBNSPR)
+
+# On SCOOS, we can't link with extra libraries when
+# we build a shared library.  If we do so, the linker doesn't
+# complain, but we would run into weird problems at run-time.
+# Therefore on these platforms, we link just the .o files.
+ifeq ($(OS_ARCH),SCOOS)
+EXTRA_LIBS =
+endif
+
+ifdef RESOLVE_LINK_SYMBOLS
+EXTRA_LIBS += $(OS_LIBS)
+endif
+
+include $(topsrcdir)/config/rules.mk
+
+#
+# Version information generation (begin)
+#
+ECHO = echo
+TINC = $(OBJDIR)/_pl_bld.h
+PROD = $(notdir $(SHARED_LIBRARY))
+NOW = $(MOD_DEPTH)/config/$(OBJDIR)/now
+SH_DATE = $(shell date "+%Y-%m-%d %T")
+SH_NOW = $(shell $(NOW))
+
+ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
+	SUF = i64
+else
+	SUF = LL
+endif
+
+GARBAGE += $(TINC)
+
+$(TINC):
+	@$(MAKE_OBJDIR)
+	@$(ECHO) '#define _BUILD_STRING "$(SH_DATE)"' > $(TINC)
+	@if test ! -z "$(SH_NOW)"; then \
+	    $(ECHO) '#define _BUILD_TIME $(SH_NOW)$(SUF)' >> $(TINC); \
+	else \
+	    true; \
+	fi
+	@$(ECHO) '#define _PRODUCTION "$(PROD)"' >> $(TINC)
+
+
+$(OBJDIR)/plvrsion.$(OBJ_SUFFIX): plvrsion.c $(TINC)
+ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
+	$(CC) -Fo$@ -c $(CFLAGS) -I$(OBJDIR) $<
+else
+	$(CC) -o $@ -c $(CFLAGS) -I$(OBJDIR) $<
+endif
+#
+# Version information generation (end)
+#
+
+#
+# The Client build wants the shared libraries in $(dist_bindir),
+# so we also install them there.
+#
+
+export:: $(TARGETS)
+	$(INSTALL) -m 444 $(TARGETS) $(dist_libdir)
+ifdef SHARED_LIBRARY
+ifeq ($(OS_ARCH),HP-UX)
+	$(INSTALL) -m 755 $(SHARED_LIBRARY) $(dist_libdir)
+	$(INSTALL) -m 755 $(SHARED_LIBRARY) $(dist_bindir)
+else
+	$(INSTALL) -m 444 $(SHARED_LIBRARY) $(dist_bindir)
+endif
+endif
diff --git a/lib/libc/src/README b/lib/libc/src/README
new file mode 100644
index 0000000..74f2469
--- /dev/null
+++ b/lib/libc/src/README
@@ -0,0 +1,20 @@
+NSPR 2.0 libc functions
+-----------------------
+
+Last edited: AOF 04 March 1997
+
+This directory contains various libc-types of functions. All functions in
+this directory are platform independent, thread friendly (both safe and
+efficient). They are contributed from various sources, though the contri-
+butions are monitored by the NSPR group (mailto:freier).
+
+All API items exported by these functions will contain the same three
+character prefix, "PL_" (Portable Library). Internal function names
+that are not exported (static) are of little concern, though some caution
+must be used on those elements that are 'extern' but not really intended
+to be part of the API. Those should all have a prefix of "_PL_" (is that
+legal?).
+
+The responsibility for contributions in this area are distributed among
+all interested parties.
+
diff --git a/lib/libc/src/base64.c b/lib/libc/src/base64.c
new file mode 100644
index 0000000..07a4902
--- /dev/null
+++ b/lib/libc/src/base64.c
@@ -0,0 +1,416 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "plbase64.h"
+#include "prlog.h" /* For PR_NOT_REACHED */
+#include "prmem.h" /* for malloc / PR_MALLOC */
+
+#include <string.h> /* for strlen */
+
+static unsigned char *base = (unsigned char *)"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+static void
+encode3to4
+(
+    const unsigned char    *src,
+    unsigned char          *dest
+)
+{
+    PRUint32 b32 = (PRUint32)0;
+    PRIntn i, j = 18;
+
+    for( i = 0; i < 3; i++ )
+    {
+        b32 <<= 8;
+        b32 |= (PRUint32)src[i];
+    }
+
+    for( i = 0; i < 4; i++ )
+    {
+        dest[i] = base[ (PRUint32)((b32>>j) & 0x3F) ];
+        j -= 6;
+    }
+
+    return;
+}
+
+static void
+encode2to4
+(
+    const unsigned char    *src,
+    unsigned char          *dest
+)
+{
+    dest[0] = base[ (PRUint32)((src[0]>>2) & 0x3F) ];
+    dest[1] = base[ (PRUint32)(((src[0] & 0x03) << 4) | ((src[1] >> 4) & 0x0F)) ];
+    dest[2] = base[ (PRUint32)((src[1] & 0x0F) << 2) ];
+    dest[3] = (unsigned char)'=';
+    return;
+}
+
+static void
+encode1to4
+(
+    const unsigned char    *src,
+    unsigned char          *dest
+)
+{
+    dest[0] = base[ (PRUint32)((src[0]>>2) & 0x3F) ];
+    dest[1] = base[ (PRUint32)((src[0] & 0x03) << 4) ];
+    dest[2] = (unsigned char)'=';
+    dest[3] = (unsigned char)'=';
+    return;
+}
+
+static void
+encode
+(
+    const unsigned char    *src,
+    PRUint32                srclen,
+    unsigned char          *dest
+)
+{
+    while( srclen >= 3 )
+    {
+        encode3to4(src, dest);
+        src += 3;
+        dest += 4;
+        srclen -= 3;
+    }
+
+    switch( srclen )
+    {
+        case 2:
+            encode2to4(src, dest);
+            break;
+        case 1:
+            encode1to4(src, dest);
+            break;
+        case 0:
+            break;
+        default:
+            PR_NOT_REACHED("coding error");
+    }
+
+    return;
+}
+
+/*
+ * PL_Base64Encode
+ *
+ * If the destination argument is NULL, a return buffer is 
+ * allocated, and the data therein will be null-terminated.  
+ * If the destination argument is not NULL, it is assumed to
+ * be of sufficient size, and the contents will not be null-
+ * terminated by this routine.
+ *
+ * Returns null if the allocation fails.
+ */
+
+PR_IMPLEMENT(char *)
+PL_Base64Encode
+(
+    const char *src,
+    PRUint32    srclen,
+    char       *dest
+)
+{
+    if( 0 == srclen )
+    {
+        size_t len = strlen(src);
+        srclen = len;
+        /* Detect truncation. */
+        if( srclen != len )
+        {
+            return (char *)0;
+        }
+    }
+
+    if( (char *)0 == dest )
+    {
+        PRUint32 destlen;
+        /* Ensure all PRUint32 values stay within range. */
+        if( srclen > (PR_UINT32_MAX/4) * 3 )
+        {
+            return (char *)0;
+        }
+        destlen = ((srclen + 2)/3) * 4;
+        dest = (char *)PR_MALLOC(destlen + 1);
+        if( (char *)0 == dest )
+        {
+            return (char *)0;
+        }
+        dest[ destlen ] = (char)0; /* null terminate */
+    }
+
+    encode((const unsigned char *)src, srclen, (unsigned char *)dest);
+    return dest;
+}
+
+static PRInt32
+codetovalue
+(
+    unsigned char c
+)
+{
+    if( (c >= (unsigned char)'A') && (c <= (unsigned char)'Z') )
+    {
+        return (PRInt32)(c - (unsigned char)'A');
+    }
+    else if( (c >= (unsigned char)'a') && (c <= (unsigned char)'z') )
+    {
+        return ((PRInt32)(c - (unsigned char)'a') +26);
+    }
+    else if( (c >= (unsigned char)'0') && (c <= (unsigned char)'9') )
+    {
+        return ((PRInt32)(c - (unsigned char)'0') +52);
+    }
+    else if( (unsigned char)'+' == c )
+    {
+        return (PRInt32)62;
+    }
+    else if( (unsigned char)'/' == c )
+    {
+        return (PRInt32)63;
+    }
+    else
+    {
+        return -1;
+    }
+}
+
+static PRStatus
+decode4to3
+(
+    const unsigned char    *src,
+    unsigned char          *dest
+)
+{
+    PRUint32 b32 = (PRUint32)0;
+    PRInt32 bits;
+    PRIntn i;
+
+    for( i = 0; i < 4; i++ )
+    {
+        bits = codetovalue(src[i]);
+        if( bits < 0 )
+        {
+            return PR_FAILURE;
+        }
+
+        b32 <<= 6;
+        b32 |= bits;
+    }
+
+    dest[0] = (unsigned char)((b32 >> 16) & 0xFF);
+    dest[1] = (unsigned char)((b32 >>  8) & 0xFF);
+    dest[2] = (unsigned char)((b32      ) & 0xFF);
+
+    return PR_SUCCESS;
+}
+
+static PRStatus
+decode3to2
+(
+    const unsigned char    *src,
+    unsigned char          *dest
+)
+{
+    PRUint32 b32 = (PRUint32)0;
+    PRInt32 bits;
+    PRUint32 ubits;
+
+    bits = codetovalue(src[0]);
+    if( bits < 0 )
+    {
+        return PR_FAILURE;
+    }
+
+    b32 = (PRUint32)bits;
+    b32 <<= 6;
+
+    bits = codetovalue(src[1]);
+    if( bits < 0 )
+    {
+        return PR_FAILURE;
+    }
+
+    b32 |= (PRUint32)bits;
+    b32 <<= 4;
+
+    bits = codetovalue(src[2]);
+    if( bits < 0 )
+    {
+        return PR_FAILURE;
+    }
+
+    ubits = (PRUint32)bits;
+    b32 |= (ubits >> 2);
+
+    dest[0] = (unsigned char)((b32 >> 8) & 0xFF);
+    dest[1] = (unsigned char)((b32     ) & 0xFF);
+
+    return PR_SUCCESS;
+}
+
+static PRStatus
+decode2to1
+(
+    const unsigned char    *src,
+    unsigned char          *dest
+)
+{
+    PRUint32 b32;
+    PRUint32 ubits;
+    PRInt32 bits;
+
+    bits = codetovalue(src[0]);
+    if( bits < 0 )
+    {
+        return PR_FAILURE;
+    }
+
+    ubits = (PRUint32)bits;
+    b32 = (ubits << 2);
+
+    bits = codetovalue(src[1]);
+    if( bits < 0 )
+    {
+        return PR_FAILURE;
+    }
+
+    ubits = (PRUint32)bits;
+    b32 |= (ubits >> 4);
+
+    dest[0] = (unsigned char)b32;
+
+    return PR_SUCCESS;
+}
+
+static PRStatus
+decode
+(
+    const unsigned char    *src,
+    PRUint32                srclen,
+    unsigned char          *dest
+)
+{
+    PRStatus rv;
+
+    while( srclen >= 4 )
+    {
+        rv = decode4to3(src, dest);
+        if( PR_SUCCESS != rv )
+        {
+            return PR_FAILURE;
+        }
+
+        src += 4;
+        dest += 3;
+        srclen -= 4;
+    }
+
+    switch( srclen )
+    {
+        case 3:
+            rv = decode3to2(src, dest);
+            break;
+        case 2:
+            rv = decode2to1(src, dest);
+            break;
+        case 1:
+            rv = PR_FAILURE;
+            break;
+        case 0:
+            rv = PR_SUCCESS;
+            break;
+        default:
+            PR_NOT_REACHED("coding error");
+    }
+
+    return rv;
+}
+
+/*
+ * PL_Base64Decode
+ *
+ * If the destination argument is NULL, a return buffer is
+ * allocated and the data therein will be null-terminated.
+ * If the destination argument is not null, it is assumed
+ * to be of sufficient size, and the data will not be null-
+ * terminated by this routine.
+ * 
+ * Returns null if the allocation fails, or if the source string is 
+ * not well-formed.
+ */
+
+PR_IMPLEMENT(char *)
+PL_Base64Decode
+(
+    const char *src,
+    PRUint32    srclen,
+    char       *dest
+)
+{
+    PRStatus status;
+    PRBool allocated = PR_FALSE;
+
+    if( (char *)0 == src )
+    {
+        return (char *)0;
+    }
+
+    if( 0 == srclen )
+    {
+        size_t len = strlen(src);
+        srclen = len;
+        /* Detect truncation. */
+        if( srclen != len )
+        {
+            return (char *)0;
+        }
+    }
+
+    if( srclen && (0 == (srclen & 3)) )
+    {
+        if( (char)'=' == src[ srclen-1 ] )
+        {
+            if( (char)'=' == src[ srclen-2 ] )
+            {
+                srclen -= 2;
+            }
+            else
+            {
+                srclen -= 1;
+            }
+        }
+    }
+
+    if( (char *)0 == dest )
+    {
+        /* The following computes ((srclen * 3) / 4) without overflow. */
+        PRUint32 destlen = (srclen / 4) * 3 + ((srclen % 4) * 3) / 4;
+        dest = (char *)PR_MALLOC(destlen + 1);
+        if( (char *)0 == dest )
+        {
+            return (char *)0;
+        }
+        dest[ destlen ] = (char)0; /* null terminate */
+        allocated = PR_TRUE;
+    }
+
+    status = decode((const unsigned char *)src, srclen, (unsigned char *)dest);
+    if( PR_SUCCESS != status )
+    {
+        if( PR_TRUE == allocated )
+        {
+            PR_DELETE(dest);
+        }
+
+        return (char *)0;
+    }
+
+    return dest;
+}
diff --git a/lib/libc/src/plc.def b/lib/libc/src/plc.def
new file mode 100644
index 0000000..ac8aa7b
--- /dev/null
+++ b/lib/libc/src/plc.def
@@ -0,0 +1,72 @@
+;+#
+;+# This Source Code Form is subject to the terms of the Mozilla Public
+;+# License, v. 2.0. If a copy of the MPL was not distributed with this
+;+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+;+#
+;+# OK, this file is meant to support SUN, LINUX, AIX, OS/2 and WINDOWS
+;+#   1. For all unix platforms, the string ";-"  means "remove this line"
+;+#   2. For all unix platforms, the string " DATA " will be removed from any 
+;+#     line on which it occurs.
+;+#   3. Lines containing ";+" will have ";+" removed on SUN and LINUX.
+;+#      On AIX, lines containing ";+" will be removed.
+;+#   4. For all unix platforms, the string ";;" will thave the ";;" removed.
+;+#   5. For all unix platforms, after the above processing has taken place,
+;+#    all characters after the first ";" on the line will be removed.
+;+#    And for AIX, the first ";" will also be removed.
+;+#  This file is passed directly to windows. Since ';' is a comment, all UNIX
+;+#   directives are hidden behind ";", ";+", and ";-"
+;+NSPR_4.0 {
+;+    global:
+LIBRARY plc4 ;-
+EXPORTS ;-
+PL_Base64Decode;
+PL_Base64Encode;
+PL_CreateOptState;
+PL_DestroyOptState;
+PL_FPrintError;
+PL_GetNextOpt;
+PL_PrintError;
+PL_strcasecmp;
+PL_strcaserstr;
+PL_strcasestr;
+PL_strcat;
+PL_strcatn;
+PL_strchr;
+PL_strcmp;
+PL_strcpy;
+PL_strdup;
+PL_strfree;
+PL_strlen;
+PL_strncasecmp;
+PL_strncaserstr;
+PL_strncasestr;
+PL_strncat;
+PL_strnchr;
+PL_strncmp;
+PL_strncpy;
+PL_strncpyz;
+PL_strndup;
+PL_strnlen;
+PL_strnpbrk;
+PL_strnprbrk;
+PL_strnrchr;
+PL_strnrstr;
+PL_strnstr;
+PL_strpbrk;
+PL_strprbrk;
+PL_strrchr;
+PL_strrstr;
+PL_strstr;
+libVersionPoint;
+;+    local: *;
+;+};
+;+
+;+NSPR_4.2 {
+;+    global:
+PL_strtok_r;
+;+} NSPR_4.0;
+;+
+;+NSPR_4.7 {
+;+    global:
+PL_CreateLongOptState;
+;+} NSPR_4.2;
diff --git a/lib/libc/src/plc.rc b/lib/libc/src/plc.rc
new file mode 100644
index 0000000..144d273
--- /dev/null
+++ b/lib/libc/src/plc.rc
@@ -0,0 +1,70 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+#include "prinit.h"
+#include <winver.h>
+
+#define MY_LIBNAME "plc"
+#define MY_FILEDESCRIPTION "PLC Library"
+
+#define STRINGIZE(x) #x
+#define STRINGIZE2(x) STRINGIZE(x)
+#define PR_VMAJOR_STR STRINGIZE2(PR_VMAJOR)
+
+#ifdef _DEBUG
+#define MY_DEBUG_STR " (debug)"
+#define MY_FILEFLAGS_1 VS_FF_DEBUG
+#else
+#define MY_DEBUG_STR ""
+#define MY_FILEFLAGS_1 0x0L
+#endif
+#if PR_BETA
+#define MY_FILEFLAGS_2 MY_FILEFLAGS_1|VS_FF_PRERELEASE
+#else
+#define MY_FILEFLAGS_2 MY_FILEFLAGS_1
+#endif
+
+#ifdef WINNT
+#define MY_FILEOS VOS_NT_WINDOWS32
+#define MY_INTERNAL_NAME "lib" MY_LIBNAME PR_VMAJOR_STR
+#else
+#define MY_FILEOS VOS__WINDOWS32
+#define MY_INTERNAL_NAME MY_LIBNAME PR_VMAJOR_STR
+#endif
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Version-information resource
+//
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION PR_VMAJOR,PR_VMINOR,PR_VPATCH,0
+ PRODUCTVERSION PR_VMAJOR,PR_VMINOR,PR_VPATCH,0
+ FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
+ FILEFLAGS MY_FILEFLAGS_2
+ FILEOS MY_FILEOS
+ FILETYPE VFT_DLL
+ FILESUBTYPE 0x0L // not used
+
+BEGIN
+    BLOCK "StringFileInfo"
+    BEGIN
+        BLOCK "040904B0" // Lang=US English, CharSet=Unicode
+        BEGIN
+            VALUE "CompanyName", "Mozilla Foundation\0"
+            VALUE "FileDescription", MY_FILEDESCRIPTION MY_DEBUG_STR "\0"
+            VALUE "FileVersion", PR_VERSION "\0"
+            VALUE "InternalName", MY_INTERNAL_NAME "\0"
+            VALUE "OriginalFilename", MY_INTERNAL_NAME ".dll\0"
+            VALUE "ProductName", "Netscape Portable Runtime\0"
+            VALUE "ProductVersion", PR_VERSION "\0"
+        END
+    END
+    BLOCK "VarFileInfo"
+    BEGIN
+        VALUE "Translation", 0x409, 1200
+    END
+END
diff --git a/lib/libc/src/plerror.c b/lib/libc/src/plerror.c
new file mode 100644
index 0000000..bb8e08d
--- /dev/null
+++ b/lib/libc/src/plerror.c
@@ -0,0 +1,40 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** File:plerror.c
+** Description: Simple routine to print translate the calling thread's
+**  error numbers and print them to "syserr".
+*/
+
+#include "plerror.h"
+
+#include "prprf.h"
+#include "prerror.h"
+
+PR_IMPLEMENT(void) PL_FPrintError(PRFileDesc *fd, const char *msg)
+{
+PRErrorCode error = PR_GetError();
+PRInt32 oserror = PR_GetOSError();
+const char *name = PR_ErrorToName(error);
+
+	if (NULL != msg) PR_fprintf(fd, "%s: ", msg);
+    if (NULL == name)
+        PR_fprintf(
+			fd, " (%d)OUT OF RANGE, oserror = %d\n", error, oserror);
+    else
+        PR_fprintf(
+            fd, "%s(%d), oserror = %d\n",
+            name, error, oserror);
+}  /* PL_FPrintError */
+
+PR_IMPLEMENT(void) PL_PrintError(const char *msg)
+{
+	static PRFileDesc *fd = NULL;
+	if (NULL == fd) fd = PR_GetSpecialFD(PR_StandardError);
+	PL_FPrintError(fd, msg);
+}  /* PL_PrintError */
+
+/* plerror.c */
diff --git a/lib/libc/src/plgetopt.c b/lib/libc/src/plgetopt.c
new file mode 100644
index 0000000..960decf
--- /dev/null
+++ b/lib/libc/src/plgetopt.c
@@ -0,0 +1,248 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** File:          plgetopt.c
+** Description:   utilities to parse argc/argv
+*/
+
+#include "prmem.h"
+#include "prlog.h"
+#include "prerror.h"
+#include "plstr.h"
+#include "plgetopt.h"
+
+#include <string.h>
+
+static char static_Nul = 0;
+
+struct PLOptionInternal
+{
+    const char *options;        /* client options list specification */
+    PRIntn argc;                /* original number of arguments */
+    char **argv;                /* vector of pointers to arguments */
+    PRIntn xargc;               /* which one we're processing now */
+    const char *xargv;          /* where within *argv[xargc] */
+    PRIntn minus;               /* do we already have the '-'? */
+    const PLLongOpt *longOpts;  /* Caller's array */
+    PRBool endOfOpts;           /* have reached a "--" argument */
+    PRIntn optionsLen;          /* is strlen(options) */
+};
+
+/*
+** Create the state in which to parse the tokens.
+**
+** argc        the sum of the number of options and their values
+** argv        the options and their values
+** options    vector of single character options w/ | w/o ':
+*/
+PR_IMPLEMENT(PLOptState*) PL_CreateOptState(
+    PRIntn argc, char **argv, const char *options)
+{
+    return PL_CreateLongOptState( argc, argv, options, NULL);
+}  /* PL_CreateOptState */
+
+PR_IMPLEMENT(PLOptState*) PL_CreateLongOptState(
+    PRIntn argc, char **argv, const char *options, 
+    const PLLongOpt *longOpts)
+{
+    PLOptState *opt = NULL;
+    PLOptionInternal *internal;
+
+    if (NULL == options) 
+    {
+        PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+        return opt;
+    }
+
+    opt = PR_NEWZAP(PLOptState);
+    if (NULL == opt) 
+    {
+        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+        return opt;
+    }
+
+    internal = PR_NEW(PLOptionInternal);
+    if (NULL == internal)
+    {
+        PR_DELETE(opt);
+        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+        return NULL;
+    }
+
+    opt->option = 0;
+    opt->value = NULL;
+    opt->internal = internal;
+    opt->longOption   =  0;
+    opt->longOptIndex = -1;
+
+    internal->argc = argc;
+    internal->argv = argv;
+    internal->xargc = 0;
+    internal->xargv = &static_Nul;
+    internal->minus = 0;
+    internal->options = options;
+    internal->longOpts = longOpts;
+    internal->endOfOpts = PR_FALSE;
+    internal->optionsLen = PL_strlen(options);
+
+    return opt;
+}  /* PL_CreateLongOptState */
+
+/*
+** Destroy object created by CreateOptState()
+*/
+PR_IMPLEMENT(void) PL_DestroyOptState(PLOptState *opt)
+{
+    PR_DELETE(opt->internal);
+    PR_DELETE(opt);
+}  /* PL_DestroyOptState */
+
+PR_IMPLEMENT(PLOptStatus) PL_GetNextOpt(PLOptState *opt)
+{
+    PLOptionInternal *internal = opt->internal;
+
+    opt->longOption   =  0;
+    opt->longOptIndex = -1;
+    /*
+    ** If the current xarg points to nul, advance to the next
+    ** element of the argv vector. If the vector index is equal
+    ** to argc, we're out of arguments, so return an EOL.
+    ** Note whether the first character of the new argument is
+    ** a '-' and skip by it if it is.
+    */
+    while (0 == *internal->xargv)
+    {
+        internal->xargc += 1;
+        if (internal->xargc >= internal->argc)
+        {
+            opt->option = 0;
+            opt->value = NULL;
+            return PL_OPT_EOL;
+        }
+        internal->xargv = internal->argv[internal->xargc];
+        internal->minus = 0;
+        if (!internal->endOfOpts && ('-' == *internal->xargv)) 
+        {
+            internal->minus++;
+            internal->xargv++;  /* and consume */
+            if ('-' == *internal->xargv && internal->longOpts) 
+            {
+                internal->minus++;
+                internal->xargv++;
+                if (0 == *internal->xargv) 
+                {
+                    internal->endOfOpts = PR_TRUE;
+                }
+            }
+        }
+    }
+
+    /*
+    ** If we already have a '-' or '--' in hand, xargv points to the next
+    ** option. See if we can find a match in the list of possible
+    ** options supplied.
+    */
+    if (internal->minus == 2) 
+    {
+        char * foundEqual = strchr(internal->xargv,'=');
+        PRIntn optNameLen = foundEqual ? (foundEqual - internal->xargv) :
+                            strlen(internal->xargv);
+        const PLLongOpt *longOpt = internal->longOpts;
+        PLOptStatus result = PL_OPT_BAD;
+
+        opt->option = 0;
+        opt->value  = NULL;
+
+        for (; longOpt->longOptName; ++longOpt) 
+        {
+            if (strncmp(longOpt->longOptName, internal->xargv, optNameLen))
+                continue;  /* not a possible match */
+            if (strlen(longOpt->longOptName) != optNameLen)
+                continue;  /* not a match */
+            /* option name match */
+            opt->longOptIndex = longOpt - internal->longOpts;
+            opt->longOption   = longOpt->longOption;
+            /* value is part of the current argv[] element if = was found */
+            /* note: this sets value even for long options that do not
+             * require option if specified as --long=value */
+            if (foundEqual) 
+            {
+                opt->value = foundEqual + 1;
+            }
+            else if (longOpt->valueRequired)
+            {
+                /* value is the next argv[] element, if any */
+                if (internal->xargc + 1 < internal->argc)
+                {
+                    opt->value = internal->argv[++(internal->xargc)];
+                }
+                /* missing value */
+                else
+                {
+                    break; /* return PL_OPT_BAD */
+                }
+            }
+            result = PL_OPT_OK;
+            break;
+        }
+        internal->xargv = &static_Nul; /* consume this */
+        return result;
+    }
+    if (internal->minus)
+    {
+        PRIntn cop;
+        PRIntn eoo = internal->optionsLen;
+        for (cop = 0; cop < eoo; ++cop)
+        {
+            if (internal->options[cop] == *internal->xargv)
+            {
+                opt->option = *internal->xargv++;
+                opt->longOption = opt->option & 0xff;
+                /*
+                ** if options indicates that there's an associated
+                ** value, it must be provided, either as part of this
+                ** argv[] element or as the next one
+                */
+                if (':' == internal->options[cop + 1])
+                {
+                    /* value is part of the current argv[] element */
+                    if (0 != *internal->xargv)
+                    {
+                        opt->value = internal->xargv;
+                    }
+                    /* value is the next argv[] element, if any */
+                    else if (internal->xargc + 1 < internal->argc)
+                    {
+                        opt->value = internal->argv[++(internal->xargc)];
+                    }
+                    /* missing value */
+                    else
+                    {
+                        return PL_OPT_BAD;
+                    }
+
+                    internal->xargv = &static_Nul;
+                    internal->minus = 0;
+                }
+                else 
+                    opt->value = NULL; 
+                return PL_OPT_OK;
+            }
+        }
+        internal->xargv += 1;  /* consume that option */
+        return PL_OPT_BAD;
+    }
+
+    /*
+    ** No '-', so it must be a standalone value. The option is nul.
+    */
+    opt->value = internal->argv[internal->xargc];
+    internal->xargv = &static_Nul;
+    opt->option = 0;
+    return PL_OPT_OK;
+}  /* PL_GetNextOpt */
+
+/* plgetopt.c */
diff --git a/lib/libc/src/plvrsion.c b/lib/libc/src/plvrsion.c
new file mode 100644
index 0000000..b25be1e
--- /dev/null
+++ b/lib/libc/src/plvrsion.c
@@ -0,0 +1,93 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "prinit.h"
+#include "prvrsion.h"
+
+/************************************************************************/
+/**************************IDENTITY AND VERSIONING***********************/
+/************************************************************************/
+#include "_pl_bld.h"
+#if !defined(_BUILD_TIME)
+#ifdef HAVE_LONG_LONG
+#define _BUILD_TIME 0
+#else
+#define _BUILD_TIME {0, 0}
+#endif
+#endif
+#if !defined(_BUILD_STRING)
+#define _BUILD_STRING ""
+#endif
+#if !defined(_PRODUCTION)
+#define _PRODUCTION ""
+#endif
+#if defined(DEBUG)
+#define _DEBUG_STRING " (debug)"
+#else
+#define _DEBUG_STRING ""
+#endif
+
+/*
+ * A trick to expand the PR_VMAJOR macro before concatenation.
+ */
+#define CONCAT(x, y) x ## y
+#define CONCAT2(x, y) CONCAT(x, y)
+#define VERSION_DESC_NAME CONCAT2(prVersionDescription_libplc, PR_VMAJOR)
+
+PRVersionDescription VERSION_DESC_NAME =
+{
+    /* version          */  2,                  /* this is the only one supported */
+    /* buildTime        */  _BUILD_TIME,        /* usecs since midnight 1/1/1970 GMT */
+    /* buildTimeString  */  _BUILD_STRING,       /*    ditto, but human readable */
+    /* vMajor           */  PR_VMAJOR,          /* NSPR's version number */
+    /* vMinor           */  PR_VMINOR,          /*  and minor version */
+    /* vPatch           */  PR_VPATCH,          /*  and patch */
+    /* beta             */  PR_BETA,            /* beta build boolean */
+#if defined(DEBUG)
+    /* debug            */  PR_TRUE,            /* a debug build */
+#else
+    /* debug            */  PR_FALSE,           /* an optomized build */
+#endif
+    /* special          */  PR_FALSE,           /* they're all special, but ... */
+    /* filename         */  _PRODUCTION,        /* the produced library name */
+    /* description      */ "Portable runtime",  /* what we are */
+    /* security         */ "N/A",               /* not applicable here */
+    /* copywrite        */  "Copyright (c) 1998 Netscape Communications Corporation. All Rights Reserved",
+    /* comment          */  "http://www.mozilla.org/MPL/",
+    /* specialString    */ ""
+};
+
+#ifdef XP_UNIX
+
+/*
+ * Version information for the 'ident' and 'what commands
+ *
+ * NOTE: the first component of the concatenated rcsid string
+ * must not end in a '$' to prevent rcs keyword substitution.
+ */
+static char rcsid[] = "$Header: NSPR " PR_VERSION _DEBUG_STRING
+        "  " _BUILD_STRING " $";
+static char sccsid[] = "@(#)NSPR " PR_VERSION _DEBUG_STRING
+        "  " _BUILD_STRING;
+
+#endif /* XP_UNIX */
+
+PR_IMPLEMENT(const PRVersionDescription*) libVersionPoint()
+{
+#ifdef XP_UNIX
+    /*
+     * Add dummy references to rcsid and sccsid to prevent them
+     * from being optimized away as unused variables.
+     */
+    const char *dummy;
+    
+    dummy = rcsid;
+    dummy = sccsid;
+#endif
+    return &VERSION_DESC_NAME;
+}  /* versionEntryPointType */
+
+/* plvrsion.c */
+
diff --git a/lib/libc/src/strcase.c b/lib/libc/src/strcase.c
new file mode 100644
index 0000000..ad54258
--- /dev/null
+++ b/lib/libc/src/strcase.c
@@ -0,0 +1,174 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "plstr.h"
+#include <string.h>
+
+static const unsigned char uc[] =
+{
+    '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
+    '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
+    '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
+    '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
+    ' ',    '!',    '"',    '#',    '$',    '%',    '&',    '\'',
+    '(',    ')',    '*',    '+',    ',',    '-',    '.',    '/',
+    '0',    '1',    '2',    '3',    '4',    '5',    '6',    '7',
+    '8',    '9',    ':',    ';',    '<',    '=',    '>',    '?',
+    '@',    'A',    'B',    'C',    'D',    'E',    'F',    'G',
+    'H',    'I',    'J',    'K',    'L',    'M',    'N',    'O',
+    'P',    'Q',    'R',    'S',    'T',    'U',    'V',    'W',
+    'X',    'Y',    'Z',    '[',    '\\',   ']',    '^',    '_',
+    '`',    'A',    'B',    'C',    'D',    'E',    'F',    'G',
+    'H',    'I',    'J',    'K',    'L',    'M',    'N',    'O',
+    'P',    'Q',    'R',    'S',    'T',    'U',    'V',    'W',
+    'X',    'Y',    'Z',    '{',    '|',    '}',    '~',    '\177',
+    0200,   0201,   0202,   0203,   0204,   0205,   0206,   0207,
+    0210,   0211,   0212,   0213,   0214,   0215,   0216,   0217,
+    0220,   0221,   0222,   0223,   0224,   0225,   0226,   0227,
+    0230,   0231,   0232,   0233,   0234,   0235,   0236,   0237,
+    0240,   0241,   0242,   0243,   0244,   0245,   0246,   0247,
+    0250,   0251,   0252,   0253,   0254,   0255,   0256,   0257,
+    0260,   0261,   0262,   0263,   0264,   0265,   0266,   0267,
+    0270,   0271,   0272,   0273,   0274,   0275,   0276,   0277,
+    0300,   0301,   0302,   0303,   0304,   0305,   0306,   0307,
+    0310,   0311,   0312,   0313,   0314,   0315,   0316,   0317,
+    0320,   0321,   0322,   0323,   0324,   0325,   0326,   0327,
+    0330,   0331,   0332,   0333,   0334,   0335,   0336,   0337,
+    0340,   0341,   0342,   0343,   0344,   0345,   0346,   0347,
+    0350,   0351,   0352,   0353,   0354,   0355,   0356,   0357,
+    0360,   0361,   0362,   0363,   0364,   0365,   0366,   0367,
+    0370,   0371,   0372,   0373,   0374,   0375,   0376,   0377
+};
+
+PR_IMPLEMENT(PRIntn)
+PL_strcasecmp(const char *a, const char *b)
+{
+    const unsigned char *ua = (const unsigned char *)a;
+    const unsigned char *ub = (const unsigned char *)b;
+
+    if( (const char *)0 == a )
+        return ((const char *)0 == b) ? 0 : -1;
+    if( (const char *)0 == b )
+        return 1;
+
+    while( (uc[*ua] == uc[*ub]) && ('\0' != *a) )
+    {
+        a++;
+        ua++;
+        ub++;
+    }
+
+    return (PRIntn)(uc[*ua] - uc[*ub]);
+}
+
+PR_IMPLEMENT(PRIntn)
+PL_strncasecmp(const char *a, const char *b, PRUint32 max)
+{
+    const unsigned char *ua = (const unsigned char *)a;
+    const unsigned char *ub = (const unsigned char *)b;
+
+    if( (const char *)0 == a )
+        return ((const char *)0 == b) ? 0 : -1;
+    if( (const char *)0 == b )
+        return 1;
+
+    while( max && (uc[*ua] == uc[*ub]) && ('\0' != *a) )
+    {
+        a++;
+        ua++;
+        ub++;
+        max--;
+    }
+
+    if( 0 == max ) return (PRIntn)0;
+
+    return (PRIntn)(uc[*ua] - uc[*ub]);
+}
+
+PR_IMPLEMENT(char *)
+PL_strcasestr(const char *big, const char *little)
+{
+    PRUint32 ll;
+
+    if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
+    if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
+
+    ll = strlen(little);
+
+    for( ; *big; big++ )
+        /* obvious improvement available here */
+            if( 0 == PL_strncasecmp(big, little, ll) )
+                return (char *)big;
+
+    return (char *)0;
+}
+
+PR_IMPLEMENT(char *)
+PL_strcaserstr(const char *big, const char *little)
+{
+    const char *p;
+    PRUint32 bl, ll;
+
+    if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
+    if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
+
+    bl = strlen(big);
+    ll = strlen(little);
+    if( bl < ll ) return (char *)0;
+    p = &big[ bl - ll ];
+
+    for( ; p >= big; p-- )
+        /* obvious improvement available here */
+            if( 0 == PL_strncasecmp(p, little, ll) )
+                return (char *)p;
+
+    return (char *)0;
+}
+
+PR_IMPLEMENT(char *)
+PL_strncasestr(const char *big, const char *little, PRUint32 max)
+{
+    PRUint32 ll;
+
+    if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
+    if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
+
+    ll = strlen(little);
+    if( ll > max ) return (char *)0;
+    max -= ll;
+    max++;
+
+    for( ; max && *big; big++, max-- )
+        /* obvious improvement available here */
+            if( 0 == PL_strncasecmp(big, little, ll) )
+                return (char *)big;
+
+    return (char *)0;
+}
+
+PR_IMPLEMENT(char *)
+PL_strncaserstr(const char *big, const char *little, PRUint32 max)
+{
+    const char *p;
+    PRUint32 ll;
+
+    if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
+    if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
+
+    ll = strlen(little);
+
+    for( p = big; max && *p; p++, max-- )
+        ;
+
+    p -= ll;
+    if( p < big ) return (char *)0;
+
+    for( ; p >= big; p-- )
+        /* obvious improvement available here */
+            if( 0 == PL_strncasecmp(p, little, ll) )
+                return (char *)p;
+
+    return (char *)0;
+}
diff --git a/lib/libc/src/strcat.c b/lib/libc/src/strcat.c
new file mode 100644
index 0000000..05b7b46
--- /dev/null
+++ b/lib/libc/src/strcat.c
@@ -0,0 +1,49 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "plstr.h"
+#include <string.h>
+
+PR_IMPLEMENT(char *)
+PL_strcat(char *dest, const char *src)
+{
+    if( ((char *)0 == dest) || ((const char *)0 == src) )
+        return dest;
+
+    return strcat(dest, src);
+}
+
+PR_IMPLEMENT(char *)
+PL_strncat(char *dest, const char *src, PRUint32 max)
+{
+    char *rv;
+
+    if( ((char *)0 == dest) || ((const char *)0 == src) || (0 == max) )
+        return dest;
+
+    for( rv = dest; *dest; dest++ )
+        ;
+
+    (void)PL_strncpy(dest, src, max);
+    return rv;
+}
+
+PR_IMPLEMENT(char *)
+PL_strcatn(char *dest, PRUint32 max, const char *src)
+{
+    char *rv;
+    PRUint32 dl;
+
+    if( ((char *)0 == dest) || ((const char *)0 == src) )
+        return dest;
+
+    for( rv = dest, dl = 0; *dest; dest++, dl++ )
+        ;
+
+    if( max <= dl ) return rv;
+    (void)PL_strncpyz(dest, src, max-dl);
+
+    return rv;
+}
diff --git a/lib/libc/src/strchr.c b/lib/libc/src/strchr.c
new file mode 100644
index 0000000..523378b
--- /dev/null
+++ b/lib/libc/src/strchr.c
@@ -0,0 +1,56 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "plstr.h"
+#include <string.h>
+
+PR_IMPLEMENT(char *)
+PL_strchr(const char *s, char c)
+{
+    if( (const char *)0 == s ) return (char *)0;
+
+    return strchr(s, c);
+}
+
+PR_IMPLEMENT(char *)
+PL_strrchr(const char *s, char c)
+{
+    if( (const char *)0 == s ) return (char *)0;
+
+    return strrchr(s, c);
+}
+
+PR_IMPLEMENT(char *)
+PL_strnchr(const char *s, char c, PRUint32 n)
+{
+    if( (const char *)0 == s ) return (char *)0;
+
+    for( ; n && *s; s++, n-- )
+        if( *s == c )
+            return (char *)s;
+
+    if( ((char)0 == c) && (n > 0) && ((char)0 == *s) ) return (char *)s;
+
+    return (char *)0;
+}
+
+PR_IMPLEMENT(char *)
+PL_strnrchr(const char *s, char c, PRUint32 n)
+{
+    const char *p;
+
+    if( (const char *)0 == s ) return (char *)0;
+
+    for( p = s; n && *p; p++, n-- )
+        ;
+
+    if( ((char)0 == c) && (n > 0) && ((char)0 == *p) ) return (char *)p;
+
+    for( p--; p >= s; p-- )
+        if( *p == c )
+            return (char *)p;
+
+    return (char *)0;
+}
diff --git a/lib/libc/src/strcmp.c b/lib/libc/src/strcmp.c
new file mode 100644
index 0000000..296d716
--- /dev/null
+++ b/lib/libc/src/strcmp.c
@@ -0,0 +1,29 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "plstr.h"
+#include <string.h>
+
+PR_IMPLEMENT(PRIntn)
+PL_strcmp(const char *a, const char *b)
+{
+    if( (const char *)0 == a )
+        return ((const char *)0 == b) ? 0 : -1;
+    if( (const char *)0 == b )
+        return 1;
+
+    return (PRIntn)strcmp(a, b);
+}
+
+PR_IMPLEMENT(PRIntn)
+PL_strncmp(const char *a, const char *b, PRUint32 max)
+{
+    if( (const char *)0 == a )
+        return ((const char *)0 == b) ? 0 : -1;
+    if( (const char *)0 == b )
+        return 1;
+
+    return (PRIntn)strncmp(a, b, (size_t)max);
+}
diff --git a/lib/libc/src/strcpy.c b/lib/libc/src/strcpy.c
new file mode 100644
index 0000000..9d319aa
--- /dev/null
+++ b/lib/libc/src/strcpy.c
@@ -0,0 +1,52 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "plstr.h"
+#include <string.h>
+
+PR_IMPLEMENT(char *)
+PL_strcpy(char *dest, const char *src)
+{
+    if( ((char *)0 == dest) || ((const char *)0 == src) ) return (char *)0;
+
+    return strcpy(dest, src);
+}
+
+PR_IMPLEMENT(char *)
+PL_strncpy(char *dest, const char *src, PRUint32 max)
+{
+    char *rv;
+    
+    if( (char *)0 == dest ) return (char *)0;
+    if( (const char *)0 == src ) return (char *)0;
+
+    for( rv = dest; max && ((*dest = *src) != 0); dest++, src++, max-- )
+        ;
+
+#ifdef JLRU
+    /* XXX I (wtc) think the -- and ++ operators should be postfix. */
+    while( --max )
+        *++dest = '\0';
+#endif /* JLRU */
+
+    return rv;
+}
+
+PR_IMPLEMENT(char *)
+PL_strncpyz(char *dest, const char *src, PRUint32 max)
+{
+    char *rv;
+    
+    if( (char *)0 == dest ) return (char *)0;
+    if( (const char *)0 == src ) return (char *)0;
+    if( 0 == max ) return (char *)0;
+
+    for( rv = dest, max--; max && ((*dest = *src) != 0); dest++, src++, max-- )
+        ;
+
+    *dest = '\0';
+
+    return rv;
+}
diff --git a/lib/libc/src/strdup.c b/lib/libc/src/strdup.c
new file mode 100644
index 0000000..c267147
--- /dev/null
+++ b/lib/libc/src/strdup.c
@@ -0,0 +1,53 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "plstr.h"
+#include "prmem.h"
+#include <string.h>
+
+PR_IMPLEMENT(char *)
+PL_strdup(const char *s)
+{
+    char *rv;
+    size_t n;
+
+    if( (const char *)0 == s )
+        s = "";
+
+    n = strlen(s) + 1;
+
+    rv = (char *)malloc(n);
+    if( (char *)0 == rv ) return rv;
+
+    (void)memcpy(rv, s, n);
+
+    return rv;
+}
+
+PR_IMPLEMENT(void)
+PL_strfree(char *s)
+{
+    free(s);
+}
+
+PR_IMPLEMENT(char *)
+PL_strndup(const char *s, PRUint32 max)
+{
+    char *rv;
+    size_t l;
+
+    if( (const char *)0 == s )
+        s = "";
+
+    l = PL_strnlen(s, max);
+
+    rv = (char *)malloc(l+1);
+    if( (char *)0 == rv ) return rv;
+
+    (void)memcpy(rv, s, l);
+    rv[l] = '\0';
+
+    return rv;
+}
diff --git a/lib/libc/src/strlen.c b/lib/libc/src/strlen.c
new file mode 100644
index 0000000..ba6c612
--- /dev/null
+++ b/lib/libc/src/strlen.c
@@ -0,0 +1,42 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "plstr.h"
+#include "prtypes.h"
+#include "prlog.h"
+#include <string.h>
+
+PR_IMPLEMENT(PRUint32)
+PL_strlen(const char *str)
+{
+    size_t l;
+
+    if( (const char *)0 == str ) return 0;
+
+    l = strlen(str);
+
+    /* error checking in case we have a 64-bit platform -- make sure
+     * we don't have ultra long strings that overflow an int32
+     */ 
+    if( sizeof(PRUint32) < sizeof(size_t) )
+    {
+        if( l > PR_INT32_MAX )
+            PR_Assert("l <= PR_INT32_MAX", __FILE__, __LINE__);
+    }
+
+    return (PRUint32)l;
+}
+
+PR_IMPLEMENT(PRUint32)
+PL_strnlen(const char *str, PRUint32 max)
+{
+    register const char *s;
+
+    if( (const char *)0 == str ) return 0;
+    for( s = str; max && *s; s++, max-- )
+        ;
+
+    return (PRUint32)(s - str);
+}
diff --git a/lib/libc/src/strpbrk.c b/lib/libc/src/strpbrk.c
new file mode 100644
index 0000000..0d2be98
--- /dev/null
+++ b/lib/libc/src/strpbrk.c
@@ -0,0 +1,68 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "plstr.h"
+#include <string.h>
+
+PR_IMPLEMENT(char *)
+PL_strpbrk(const char *s, const char *list)
+{
+    if( ((const char *)0 == s) || ((const char *)0 == list) ) return (char *)0;
+
+    return strpbrk(s, list);
+}
+
+PR_IMPLEMENT(char *)
+PL_strprbrk(const char *s, const char *list)
+{
+    const char *p;
+    const char *r;
+
+    if( ((const char *)0 == s) || ((const char *)0 == list) ) return (char *)0;
+
+    for( r = s; *r; r++ )
+        ;
+
+    for( r--; r >= s; r-- )
+        for( p = list; *p; p++ )
+            if( *r == *p )
+                return (char *)r;
+
+    return (char *)0;
+}
+
+PR_IMPLEMENT(char *)
+PL_strnpbrk(const char *s, const char *list, PRUint32 max)
+{
+    const char *p;
+
+    if( ((const char *)0 == s) || ((const char *)0 == list) ) return (char *)0;
+
+    for( ; max && *s; s++, max-- )
+        for( p = list; *p; p++ )
+            if( *s == *p )
+                return (char *)s;
+
+    return (char *)0;
+}
+
+PR_IMPLEMENT(char *)
+PL_strnprbrk(const char *s, const char *list, PRUint32 max)
+{
+    const char *p;
+    const char *r;
+
+    if( ((const char *)0 == s) || ((const char *)0 == list) ) return (char *)0;
+
+    for( r = s; max && *r; r++, max-- )
+        ;
+
+    for( r--; r >= s; r-- )
+        for( p = list; *p; p++ )
+            if( *r == *p )
+                return (char *)r;
+
+    return (char *)0;
+}
diff --git a/lib/libc/src/strstr.c b/lib/libc/src/strstr.c
new file mode 100644
index 0000000..a90d822
--- /dev/null
+++ b/lib/libc/src/strstr.c
@@ -0,0 +1,85 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "plstr.h"
+#include <string.h>
+
+PR_IMPLEMENT(char *)
+PL_strstr(const char *big, const char *little)
+{
+    if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
+    if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
+
+    return strstr(big, little);
+}
+
+PR_IMPLEMENT(char *)
+PL_strrstr(const char *big, const char *little)
+{
+    const char *p;
+    size_t ll;
+    size_t bl;
+
+    if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
+    if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
+
+    ll = strlen(little);
+    bl = strlen(big);
+    if( bl < ll ) return (char *)0;
+    p = &big[ bl - ll ];
+
+    for( ; p >= big; p-- )
+        if( *little == *p )
+            if( 0 == strncmp(p, little, ll) )
+                return (char *)p;
+
+    return (char *)0;
+}
+
+PR_IMPLEMENT(char *)
+PL_strnstr(const char *big, const char *little, PRUint32 max)
+{
+    size_t ll;
+
+    if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
+    if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
+
+    ll = strlen(little);
+    if( ll > (size_t)max ) return (char *)0;
+    max -= (PRUint32)ll;
+    max++;
+
+    for( ; max && *big; big++, max-- )
+        if( *little == *big )
+            if( 0 == strncmp(big, little, ll) )
+                return (char *)big;
+
+    return (char *)0;
+}
+
+PR_IMPLEMENT(char *)
+PL_strnrstr(const char *big, const char *little, PRUint32 max)
+{
+    const char *p;
+    size_t ll;
+
+    if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
+    if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
+
+    ll = strlen(little);
+
+    for( p = big; max && *p; p++, max-- )
+        ;
+
+    p -= ll;
+    if( p < big ) return (char *)0;
+
+    for( ; p >= big; p-- )
+        if( *little == *p )
+            if( 0 == strncmp(p, little, ll) )
+                return (char *)p;
+
+    return (char *)0;
+}
diff --git a/lib/libc/src/strtok.c b/lib/libc/src/strtok.c
new file mode 100644
index 0000000..2daaea3
--- /dev/null
+++ b/lib/libc/src/strtok.c
@@ -0,0 +1,56 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "plstr.h"
+
+PR_IMPLEMENT(char *)
+PL_strtok_r(char *s1, const char *s2, char **lasts)
+{
+    const char *sepp;
+    int         c, sc;
+    char       *tok;
+
+    if( s1 == NULL )
+    {
+        if( *lasts == NULL )
+            return NULL;
+
+        s1 = *lasts;
+    }
+  
+    for( ; (c = *s1) != 0; s1++ )
+    {
+        for( sepp = s2 ; (sc = *sepp) != 0 ; sepp++ )
+        {
+            if( c == sc )
+                break;
+        }
+        if( sc == 0 )
+            break; 
+    }
+
+    if( c == 0 )
+    {
+        *lasts = NULL;
+        return NULL;
+    }
+  
+    tok = s1++;
+
+    for( ; (c = *s1) != 0; s1++ )
+    {
+        for( sepp = s2; (sc = *sepp) != 0; sepp++ )
+        {
+            if( c == sc )
+            {
+                *s1++ = '\0';
+                *lasts = s1;
+                return tok;
+            }
+        }
+    }
+    *lasts = NULL;
+    return tok;
+}
diff --git a/lib/prstreams/.cvsignore b/lib/prstreams/.cvsignore
new file mode 100644
index 0000000..f3c7a7c
--- /dev/null
+++ b/lib/prstreams/.cvsignore
@@ -0,0 +1 @@
+Makefile
diff --git a/lib/prstreams/Makefile.in b/lib/prstreams/Makefile.in
new file mode 100644
index 0000000..aeb2944
--- /dev/null
+++ b/lib/prstreams/Makefile.in
@@ -0,0 +1,148 @@
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#! gmake
+
+MOD_DEPTH	= ../..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+
+include $(MOD_DEPTH)/config/autoconf.mk
+
+include $(topsrcdir)/config/config.mk
+
+ifeq ($(OS_ARCH), IRIX)
+    ifneq ($(OS_RELEASE),5.3)
+        CCC_ONLY_FLAGS += -exceptions
+    endif
+endif
+
+ifeq ($(OS_ARCH), BeOS)
+    CFLAGS += -frtti -fexceptions
+endif
+
+INCLUDES = -I$(dist_includedir)
+
+HEADERS = $(wildcard $(srcdir)/*.h)
+
+CSRCS = \
+	plvrsion.c \
+	$(NULL)
+
+CXXSRCS = \
+	prstrms.cpp \
+	$(NULL)
+
+OBJS = $(addprefix $(OBJDIR)/,$(CSRCS:.c=.$(OBJ_SUFFIX)) $(CXXSRCS:.cpp=.$(OBJ_SUFFIX)))
+
+ifeq ($(OS_ARCH), WINNT)
+        RES=$(OBJDIR)/prstrms.res
+        RESNAME=prstrms.rc
+        OS_LIBS = user32.lib
+else
+    ifeq ($(OS_ARCH),OS2)
+        OS_LIBS = -lstdcpp
+    else
+    ifeq ($(OS_ARCH), AIX)
+      ifeq ($(OS_RELEASE), 4.1)
+        ifeq ($(CLASSIC_NSPR),1)
+            OS_LIBS += -lC -lc
+        else
+            OS_LIBS += -lC_r -lc_r
+        endif
+      else
+        # makeC++SharedLib(_r) is in either /usr/lpp/xlC/bin
+        # or /usr/ibmcxx/bin.
+        ifeq ($(CLASSIC_NSPR),1)
+            MKSHLIB = makeC++SharedLib -p 0
+        else
+            MKSHLIB = makeC++SharedLib_r -p 0
+        endif
+        OS_LIBS += -ldl
+      endif
+    endif
+    endif
+endif
+
+ifeq ($(OS_ARCH),BeOS)
+    OS_LIBS = -lstdc++.r4
+endif
+
+ifeq ($(OS_ARCH), UNIXWARE)
+    OS_LIBS += -lC
+endif
+
+EXTRA_LIBS = $(LIBNSPR)
+
+# On SCOOS, we can't link with extra libraries when
+# we build a shared library.  If we do so, the linker doesn't
+# complain, but we would run into weird problems at run-time.
+# Therefore on these platforms, we link just the object files.
+ifeq ($(OS_ARCH),SCOOS)
+    EXTRA_LIBS =
+endif
+
+ifdef RESOLVE_LINK_SYMBOLS
+EXTRA_LIBS += $(OS_LIBS)
+endif
+
+LIBRARY_NAME    = prstrms
+LIBRARY_VERSION = $(MOD_MAJOR_VERSION)
+
+RELEASE_HEADERS = $(HEADERS)
+RELEASE_HEADERS_DEST = $(RELEASE_INCLUDE_DIR)
+RELEASE_LIBS    = $(TARGETS)
+
+include $(topsrcdir)/config/rules.mk
+
+#
+# Version information generation (begin)
+#
+ECHO = echo
+TINC = $(OBJDIR)/_pl_bld.h
+PROD = $(notdir $(SHARED_LIBRARY))
+NOW = $(MOD_DEPTH)/config/$(OBJDIR)/now
+SH_DATE = $(shell date "+%Y-%m-%d %T")
+SH_NOW = $(shell $(NOW))
+
+ifeq ($(OS_ARCH), WINNT)
+	SUF = i64
+else
+	SUF = LL
+endif
+
+$(TINC):
+	@$(MAKE_OBJDIR)
+	@$(ECHO) '#define _BUILD_STRING "$(SH_DATE)"' > $(TINC)
+	@if test ! -z "$(SH_NOW)"; then \
+	    $(ECHO) '#define _BUILD_TIME $(SH_NOW)$(SUF)' >> $(TINC); \
+	else \
+	    true; \
+	fi
+	@$(ECHO) '#define _PRODUCTION "$(PROD)"' >> $(TINC)
+
+
+$(OBJDIR)/plvrsion.$(OBJ_SUFFIX): plvrsion.c $(TINC)
+ifeq ($(OS_ARCH), WINNT)
+	$(CC) -o $@ -c $(CFLAGS) -I$(OBJDIR) $<
+else
+	$(CC) -o $@ -c $(CFLAGS) -I$(OBJDIR) $<
+endif
+#
+# Version information generation (end)
+#
+
+export:: $(TARGETS) $(HEADERS)
+	$(INSTALL) -m 444 $(HEADERS) $(dist_includedir)
+	$(INSTALL) -m 444 $(TARGETS) $(dist_libdir)
+ifeq ($(OS_ARCH),OS2)
+	$(INSTALL) -m 444 $(TARGETS) $(dist_bindir)
+endif
+ifeq ($(OS_ARCH),HP-UX)
+ifdef SHARED_LIBRARY
+	$(INSTALL) -m 755 $(SHARED_LIBRARY) $(dist_libdir)
+endif
+endif
diff --git a/lib/prstreams/plvrsion.c b/lib/prstreams/plvrsion.c
new file mode 100644
index 0000000..511e4c4
--- /dev/null
+++ b/lib/prstreams/plvrsion.c
@@ -0,0 +1,93 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "prinit.h"
+#include "prvrsion.h"
+
+/************************************************************************/
+/**************************IDENTITY AND VERSIONING***********************/
+/************************************************************************/
+#include "_pl_bld.h"
+#if !defined(_BUILD_TIME)
+#ifdef HAVE_LONG_LONG
+#define _BUILD_TIME 0
+#else
+#define _BUILD_TIME {0, 0}
+#endif
+#endif
+#if !defined(_BUILD_STRING)
+#define _BUILD_STRING ""
+#endif
+#if !defined(_PRODUCTION)
+#define _PRODUCTION ""
+#endif
+#if defined(DEBUG)
+#define _DEBUG_STRING " (debug)"
+#else
+#define _DEBUG_STRING ""
+#endif
+
+/*
+ * A trick to expand the PR_VMAJOR macro before concatenation.
+ */
+#define CONCAT(x, y) x ## y
+#define CONCAT2(x, y) CONCAT(x, y)
+#define VERSION_DESC_NAME CONCAT2(prVersionDescription_libprstrms, PR_VMAJOR)
+
+PRVersionDescription VERSION_DESC_NAME =
+{
+    /* version          */  2,                  /* this is the only one supported */
+    /* buildTime        */  _BUILD_TIME,        /* usecs since midnight 1/1/1970 GMT */
+    /* buildTimeString  */  _BUILD_STRING,       /*    ditto, but human readable */
+    /* vMajor           */  PR_VMAJOR,          /* NSPR's version number */
+    /* vMinor           */  PR_VMINOR,          /*  and minor version */
+    /* vPatch           */  PR_VPATCH,          /*  and patch */
+    /* beta             */  PR_BETA,            /* beta build boolean */
+#if defined(DEBUG)
+    /* debug            */  PR_TRUE,            /* a debug build */
+#else
+    /* debug            */  PR_FALSE,           /* an optomized build */
+#endif
+    /* special          */  PR_FALSE,           /* they're all special, but ... */
+    /* filename         */  _PRODUCTION,        /* the produced library name */
+    /* description      */ "Portable runtime",  /* what we are */
+    /* security         */ "N/A",               /* not applicable here */
+    /* copywrite        */  "Copyright (c) 1998 Netscape Communications Corporation. All Rights Reserved",
+    /* comment          */  "http://www.mozilla.org/MPL/",
+    /* specialString    */ ""
+};
+
+#ifdef XP_UNIX
+
+/*
+ * Version information for the 'ident' and 'what commands
+ *
+ * NOTE: the first component of the concatenated rcsid string
+ * must not end in a '$' to prevent rcs keyword substitution.
+ */
+static char rcsid[] = "$Header: NSPR " PR_VERSION _DEBUG_STRING
+        "  " _BUILD_STRING " $";
+static char sccsid[] = "@(#)NSPR " PR_VERSION _DEBUG_STRING
+        "  " _BUILD_STRING;
+
+#endif /* XP_UNIX */
+
+PR_IMPLEMENT(const PRVersionDescription*) libVersionPoint()
+{
+#ifdef XP_UNIX
+    /*
+     * Add dummy references to rcsid and sccsid to prevent them
+     * from being optimized away as unused variables.
+     */
+    const char *dummy;
+    
+    dummy = rcsid;
+    dummy = sccsid;
+#endif
+    return &VERSION_DESC_NAME;
+}  /* versionEntryPointType */
+
+/* plvrsion.c */
+
diff --git a/lib/prstreams/prstrms.cpp b/lib/prstreams/prstrms.cpp
new file mode 100644
index 0000000..d601fce
--- /dev/null
+++ b/lib/prstreams/prstrms.cpp
@@ -0,0 +1,516 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+ * Robin J. Maxwell 11-22-96
+ * Fredrik Roubert <roubert@google.com> 2010-07-23
+ * Matt Austern <austern@google.com> 2010-07-23
+ */
+
+#include "prstrms.h"
+
+#include <cstdio>
+#include <cstring>
+#include <ios>
+#include <new>
+
+using std::ios_base;
+using std::iostream;
+using std::istream;
+using std::nothrow;
+using std::ostream;
+using std::streambuf;
+using std::streamsize;
+
+
+PRfilebuf::PRfilebuf():
+    _fd(NULL),
+    _opened(false),
+    _allocated(false),
+    _unbuffered(false),
+    _user_buf(false),
+    _buf_base(NULL),
+    _buf_end(NULL) { }
+
+
+PRfilebuf::PRfilebuf(PRFileDesc *fd):
+    _fd(fd),
+    _opened(false),
+    _allocated(false),
+    _unbuffered(false),
+    _user_buf(false),
+    _buf_base(NULL),
+    _buf_end(NULL) { }
+
+
+PRfilebuf::PRfilebuf(PRFileDesc *fd, char_type *ptr, streamsize len):
+    _fd(fd),
+    _opened(false),
+    _allocated(false),
+    _unbuffered(false),
+    _user_buf(false),
+    _buf_base(NULL),
+    _buf_end(NULL)
+{
+    setbuf(ptr, len);
+}
+
+
+PRfilebuf::~PRfilebuf()
+{
+    if (_opened) {
+        close();
+    } else {
+        sync();
+    }
+    if (_allocated) {
+        delete _buf_base;
+    }
+}
+
+
+PRfilebuf *PRfilebuf::open(
+    const char *name, ios_base::openmode flags, PRIntn mode)
+{
+    if (_fd != NULL) {
+        return NULL;  // Error if already open.
+    }
+
+    // Translate flags argument.
+    PRIntn prflags = 0;
+    bool ate = (flags & ios_base::ate) != 0;
+    flags &= ~(ios_base::ate | ios_base::binary);
+
+    // TODO: The flag PR_CREATE_FILE should probably be used for the cases
+    // (out), (out|app), (out|trunc) and (in|out|trunc) as the C++ standard
+    // specifies that these cases should open files 'as if by using fopen with
+    // "w"'. But adding that flag here will cause the unit test to leave files
+    // behind after running (which might or might not be an error in the unit
+    // test) so the matter needs further investigation before any changes are
+    // made. The old prstreams implementation used the non-standard flag
+    // ios::nocreate to control the use of PR_CREATE_FILE.
+
+    if (flags == (ios_base::out)) {
+        prflags = PR_WRONLY | PR_TRUNCATE;
+    } else if (flags == (ios_base::out | ios_base::app)) {
+        prflags = PR_RDWR | PR_APPEND;
+    } else if (flags == (ios_base::out | ios_base::trunc)) {
+        prflags = PR_WRONLY | PR_TRUNCATE;
+    } else if (flags == (ios_base::in)) {
+        prflags = PR_RDONLY;
+    } else if (flags == (ios_base::in | ios_base::out)) {
+        prflags = PR_RDWR;
+    } else if (flags == (ios_base::in | ios_base::out | ios_base::trunc)) {
+        prflags = PR_RDWR | PR_TRUNCATE;
+    } else {
+        return NULL;  // Unrecognized flag combination.
+    }
+
+    if ((_fd = PR_Open(name, prflags, mode)) == NULL) {
+        return NULL;
+    }
+
+    _opened = true;
+
+    if (ate &&
+            seekoff(0, ios_base::end, flags) == pos_type(traits_type::eof())) {
+        close();
+        return NULL;
+    }
+
+    return this;
+}
+
+
+PRfilebuf *PRfilebuf::attach(PRFileDesc *fd)
+{
+    if (_fd != NULL) {
+        return NULL;  // Error if already open.
+    }
+
+    _opened = false;
+    _fd = fd;
+    return this;
+}
+
+
+PRfilebuf *PRfilebuf::close()
+{
+    if (_fd == NULL)
+        return NULL;
+
+    int status = sync();
+
+    if (PR_Close(_fd) == PR_FAILURE ||
+            traits_type::eq_int_type(status, traits_type::eof())) {
+        return NULL;
+    }
+
+    _fd = NULL;
+    return this;
+}
+
+
+streambuf *PRfilebuf::setbuf(char_type *ptr, streamsize len)
+{
+    if (is_open() && _buf_end) {
+        return NULL;
+    }
+
+    if (!ptr || len <= 0) {
+        _unbuffered = true;
+    } else {
+        setb(ptr, ptr + len, false);
+    }
+
+    return this;
+}
+
+
+streambuf::pos_type PRfilebuf::seekoff(
+    off_type offset, ios_base::seekdir dir, ios_base::openmode /*flags*/)
+{
+    if (PR_GetDescType(_fd) != PR_DESC_FILE) {
+        return traits_type::eof();
+    }
+
+    PRSeekWhence whence;
+    PRInt64 pos;
+
+    switch (dir) {
+        case ios_base::beg: whence = PR_SEEK_SET; break;
+        case ios_base::cur: whence = PR_SEEK_CUR; break;
+        case ios_base::end: whence = PR_SEEK_END; break;
+        default:
+            return traits_type::eof();  // This should never happen.
+    }
+
+    if (traits_type::eq_int_type(sync(), traits_type::eof())) {
+        return traits_type::eof();
+    }
+
+    if ((pos = PR_Seek64(_fd, offset, whence)) == -1) {
+        return traits_type::eof();
+    }
+
+    return pos;
+}
+
+
+int PRfilebuf::sync()
+{
+    if (_fd == NULL) {
+        return traits_type::eof();
+    }
+
+    if (!_unbuffered) {
+        // Sync write area.
+        PRInt32 waiting;
+        if ((waiting = pptr() - pbase()) != 0) {
+            PRInt32 nout;
+            if ((nout = PR_Write(_fd, pbase(), waiting)) != waiting) {
+                if (nout > 0) {
+                    // Should set _pptr -= nout.
+                    pbump(-nout);
+                    memmove(pbase(), pbase() + nout, waiting - nout);
+                }
+                return traits_type::eof();
+            }
+        }
+        setp(NULL, NULL);  // Empty put area.
+
+        if (PR_GetDescType(_fd) == PR_DESC_FILE) {
+            // Sockets can't seek; don't need this.
+            PROffset64 avail;
+            if ((avail = in_avail()) > 0) {
+                if (PR_Seek64(_fd, -avail, PR_SEEK_CUR) != -1) {
+                    return traits_type::eof();
+                }
+            }
+        }
+        setg(NULL, NULL, NULL);  // Empty get area.
+    }
+
+    return 0;
+}
+
+
+streambuf::int_type PRfilebuf::underflow()
+{
+    PRInt32 count;
+    char_type byte;
+
+    if (gptr() != NULL && gptr() < egptr()) {
+        return traits_type::to_int_type(*gptr());
+    }
+
+    // Make sure there is a reserve area.
+    if (!_unbuffered && _buf_base == NULL && !allocate()) {
+        return traits_type::eof();
+    }
+
+    // Sync before new buffer created below.
+    if (traits_type::eq_int_type(sync(), traits_type::eof())) {
+        return traits_type::eof();
+    }
+
+    if (_unbuffered) {
+        if (PR_Read(_fd, &byte, 1) <= 0) {
+            return traits_type::eof();
+        }
+
+        return traits_type::to_int_type(byte);
+    }
+
+    if ((count = PR_Read(_fd, _buf_base, _buf_end - _buf_base)) <= 0) {
+        return traits_type::eof();  // Reached EOF.
+    }
+
+    setg(_buf_base, _buf_base, _buf_base + count);
+    return traits_type::to_int_type(*gptr());
+}
+
+
+streambuf::int_type PRfilebuf::overflow(int_type c)
+{
+    // Make sure there is a reserve area.
+    if (!_unbuffered && _buf_base == NULL && !allocate()) {
+        return traits_type::eof();
+    }
+
+    // Sync before new buffer created below.
+    if (traits_type::eq_int_type(sync(), traits_type::eof())) {
+        return traits_type::eof();
+    }
+
+    if (!_unbuffered) {
+        setp(_buf_base, _buf_end);
+    }
+
+    if (!traits_type::eq_int_type(c, traits_type::eof())) {
+        // Extract the byte to be written.
+        // (Required on big-endian architectures.)
+        char_type byte = traits_type::to_char_type(c);
+        if (!_unbuffered && pptr() < epptr()) {  // Guard against recursion.
+            return sputc(byte);
+        } else {
+            if (PR_Write(_fd, &byte, 1) != 1) {
+                return traits_type::eof();
+            }
+        }
+    }
+
+    return traits_type::not_eof(c);
+}
+
+
+bool PRfilebuf::allocate()
+{
+    char_type *buf = new(nothrow) char_type[BUFSIZ];
+    if (buf == NULL) {
+        return false;
+    }
+
+    setb(buf, buf + BUFSIZ, true);
+    return true;
+}
+
+
+void PRfilebuf::setb(char_type *buf_base, char_type *buf_end, bool user_buf)
+{
+    if (_buf_base && !_user_buf) {
+        delete[] _buf_base;
+    }
+
+    _buf_base = buf_base;
+    _buf_end = buf_end;
+    _user_buf = user_buf;
+}
+
+
+PRifstream::PRifstream():
+    istream(NULL),
+    _filebuf()
+{
+    init(&_filebuf);
+}
+
+
+PRifstream::PRifstream(PRFileDesc *fd):
+    istream(NULL),
+    _filebuf(fd)
+{
+    init(&_filebuf);
+}
+
+
+PRifstream::PRifstream(PRFileDesc *fd, char_type *ptr, streamsize len):
+    istream(NULL),
+    _filebuf(fd, ptr, len)
+{
+    init(&_filebuf);
+}
+
+
+PRifstream::PRifstream(const char *name, openmode flags, PRIntn mode):
+    istream(NULL),
+    _filebuf()
+{
+    init(&_filebuf);
+    if (!_filebuf.open(name, flags | in, mode)) {
+        setstate(failbit);
+    }
+}
+
+
+PRifstream::~PRifstream() { }
+
+
+void PRifstream::open(const char *name, openmode flags, PRIntn mode)
+{
+    if (is_open() || !_filebuf.open(name, flags | in, mode)) {
+        setstate(failbit);
+    }
+}
+
+
+void PRifstream::attach(PRFileDesc *fd)
+{
+    if (!_filebuf.attach(fd)) {
+        setstate(failbit);
+    }
+}
+
+
+void PRifstream::close()
+{
+    if (_filebuf.close() == NULL) {
+        setstate(failbit);
+    }
+}
+
+
+PRofstream::PRofstream():
+    ostream(NULL),
+    _filebuf()
+{
+    init(&_filebuf);
+}
+
+
+PRofstream::PRofstream(PRFileDesc *fd):
+    ostream(NULL),
+    _filebuf(fd)
+{
+    init(&_filebuf);
+}
+
+
+PRofstream::PRofstream(PRFileDesc *fd, char_type *ptr, streamsize len):
+    ostream(NULL),
+    _filebuf(fd, ptr, len)
+{
+    init(&_filebuf);
+}
+
+
+PRofstream::PRofstream(const char *name, openmode flags, PRIntn mode):
+    ostream(NULL),
+    _filebuf()
+{
+    init(&_filebuf);
+    if (!_filebuf.open(name, flags | out, mode)) {
+        setstate(failbit);
+    }
+}
+
+
+PRofstream::~PRofstream() { }
+
+
+void PRofstream::open(const char *name, openmode flags, PRIntn mode)
+{
+    if (is_open() || !_filebuf.open(name, flags | out, mode)) {
+        setstate(failbit);
+    }
+}
+
+
+void PRofstream::attach(PRFileDesc *fd)
+{
+    if (!_filebuf.attach(fd)) {
+        setstate(failbit);
+    }
+}
+
+
+void PRofstream::close()
+{
+    if (_filebuf.close() == NULL) {
+        setstate(failbit);
+    }
+}
+
+
+PRfstream::PRfstream():
+    iostream(NULL),
+    _filebuf()
+{
+    init(&_filebuf);
+}
+
+
+PRfstream::PRfstream(PRFileDesc *fd):
+    iostream(NULL),
+    _filebuf(fd)
+{
+    init(&_filebuf);
+}
+
+
+PRfstream::PRfstream(PRFileDesc *fd, char_type *ptr, streamsize len):
+    iostream(NULL),
+    _filebuf(fd, ptr, len)
+{
+    init(&_filebuf);
+}
+
+
+PRfstream::PRfstream(const char *name, openmode flags, PRIntn mode):
+    iostream(NULL),
+    _filebuf()
+{
+    init(&_filebuf);
+    if (!_filebuf.open(name, flags | in | out, mode)) {
+        setstate(failbit);
+    }
+}
+
+
+PRfstream::~PRfstream() { }
+
+
+void PRfstream::open(const char *name, openmode flags, PRIntn mode)
+{
+    if (is_open() || !_filebuf.open(name, flags | in | out, mode)) {
+        setstate(failbit);
+    }
+}
+
+
+void PRfstream::attach(PRFileDesc *fd)
+{
+    if (!_filebuf.attach(fd)) {
+        setstate(failbit);
+    }
+}
+
+
+void PRfstream::close()
+{
+    if (_filebuf.close() == NULL) {
+        setstate(failbit);
+    }
+}
diff --git a/lib/prstreams/prstrms.h b/lib/prstreams/prstrms.h
new file mode 100644
index 0000000..319dbf9
--- /dev/null
+++ b/lib/prstreams/prstrms.h
@@ -0,0 +1,140 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+ * Robin J. Maxwell 11-22-96
+ * Fredrik Roubert <roubert@google.com> 2010-07-23
+ * Matt Austern <austern@google.com> 2010-07-23
+ */
+
+#ifndef _PRSTRMS_H
+#define _PRSTRMS_H
+
+#include <cstddef>
+#include <istream>
+#include <ostream>
+#include <streambuf>
+
+#include "prio.h"
+
+#ifdef _MSC_VER
+// http://support.microsoft.com/kb/q168958/
+class PR_IMPLEMENT(std::_Mutex);
+class PR_IMPLEMENT(std::ios_base);
+#endif
+
+
+class PR_IMPLEMENT(PRfilebuf): public std::streambuf
+{
+public:
+    PRfilebuf();
+    PRfilebuf(PRFileDesc *fd);
+    PRfilebuf(PRFileDesc *fd, char_type *ptr, std::streamsize len);
+    virtual ~PRfilebuf();
+
+    bool is_open() const { return _fd != NULL; }
+
+    PRfilebuf *open(
+                  const char *name,
+                  std::ios_base::openmode flags,
+                  PRIntn mode);
+    PRfilebuf *attach(PRFileDesc *fd);
+    PRfilebuf *close();
+
+protected:
+    virtual std::streambuf *setbuf(char_type *ptr, std::streamsize len);
+    virtual pos_type seekoff(
+                         off_type offset,
+                         std::ios_base::seekdir dir,
+                         std::ios_base::openmode flags);
+    virtual pos_type seekpos(
+                         pos_type pos,
+                         std::ios_base::openmode flags) {
+        return seekoff(pos, std::ios_base::beg, flags);
+    }
+    virtual int sync();
+    virtual int_type underflow();
+    virtual int_type overflow(int_type c = traits_type::eof());
+
+    // TODO: Override pbackfail(), showmanyc(), uflow(), xsgetn(), and xsputn().
+
+private:
+    bool allocate();
+    void setb(char_type *buf_base, char_type *buf_end, bool user_buf);
+
+    PRFileDesc *_fd;
+    bool _opened;
+    bool _allocated;
+    bool _unbuffered;
+    bool _user_buf;
+    char_type *_buf_base;
+    char_type *_buf_end;
+};
+
+
+class PR_IMPLEMENT(PRifstream): public std::istream
+{
+public:
+    PRifstream();
+    PRifstream(PRFileDesc *fd);
+    PRifstream(PRFileDesc *fd, char_type *ptr, std::streamsize len);
+    PRifstream(const char *name, openmode flags = in, PRIntn mode = 0);
+    virtual ~PRifstream();
+
+    PRfilebuf *rdbuf() const { return &_filebuf; }
+    bool is_open() const { return _filebuf.is_open(); }
+
+    void open(const char *name, openmode flags = in, PRIntn mode = 0);
+    void attach(PRFileDesc *fd);
+    void close();
+
+private:
+    mutable PRfilebuf _filebuf;
+};
+
+
+class PR_IMPLEMENT(PRofstream): public std::ostream
+{
+public:
+    PRofstream();
+    PRofstream(PRFileDesc *fd);
+    PRofstream(PRFileDesc *fd, char_type *ptr, std::streamsize len);
+    PRofstream(const char *name, openmode flags = out, PRIntn mode = 0);
+    virtual ~PRofstream();
+
+    PRfilebuf *rdbuf() const { return &_filebuf; }
+    bool is_open() const { return _filebuf.is_open(); }
+
+    void open(const char *name, openmode flags = out, PRIntn mode = 0);
+    void attach(PRFileDesc *fd);
+    void close();
+
+private:
+    mutable PRfilebuf _filebuf;
+};
+
+
+class PR_IMPLEMENT(PRfstream): public std::iostream
+{
+public:
+    PRfstream();
+    PRfstream(PRFileDesc *fd);
+    PRfstream(PRFileDesc *fd, char_type *ptr, std::streamsize len);
+    PRfstream(const char *name, openmode flags = in | out, PRIntn mode = 0);
+    virtual ~PRfstream();
+
+    PRfilebuf *rdbuf() const { return &_filebuf; }
+    bool is_open() const { return _filebuf.is_open(); }
+
+    void open(const char *name, openmode flags = in | out, PRIntn mode = 0);
+    void attach(PRFileDesc *fd);
+    void close();
+
+private:
+    mutable PRfilebuf _filebuf;
+};
+
+
+#endif /* _PRSTRMS_H */
diff --git a/lib/prstreams/prstrms.rc b/lib/prstreams/prstrms.rc
new file mode 100644
index 0000000..5f72583
--- /dev/null
+++ b/lib/prstreams/prstrms.rc
@@ -0,0 +1,69 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "prinit.h"
+#include <winver.h>
+
+#define MY_LIBNAME "prstrms"
+#define MY_FILEDESCRIPTION "PRSTRMS Library"
+
+#define STRINGIZE(x) #x
+#define STRINGIZE2(x) STRINGIZE(x)
+#define PR_VMAJOR_STR STRINGIZE2(PR_VMAJOR)
+
+#ifdef _DEBUG
+#define MY_DEBUG_STR " (debug)"
+#define MY_FILEFLAGS_1 VS_FF_DEBUG
+#else
+#define MY_DEBUG_STR ""
+#define MY_FILEFLAGS_1 0x0L
+#endif
+#if PR_BETA
+#define MY_FILEFLAGS_2 MY_FILEFLAGS_1|VS_FF_PRERELEASE
+#else
+#define MY_FILEFLAGS_2 MY_FILEFLAGS_1
+#endif
+
+#ifdef WINNT
+#define MY_FILEOS VOS_NT_WINDOWS32
+#define MY_INTERNAL_NAME "lib" MY_LIBNAME PR_VMAJOR_STR
+#else
+#define MY_FILEOS VOS__WINDOWS32
+#define MY_INTERNAL_NAME MY_LIBNAME PR_VMAJOR_STR
+#endif
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Version-information resource
+//
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION PR_VMAJOR,PR_VMINOR,PR_VPATCH,0
+ PRODUCTVERSION PR_VMAJOR,PR_VMINOR,PR_VPATCH,0
+ FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
+ FILEFLAGS MY_FILEFLAGS_2
+ FILEOS MY_FILEOS
+ FILETYPE VFT_DLL
+ FILESUBTYPE 0x0L // not used
+
+BEGIN
+    BLOCK "StringFileInfo"
+    BEGIN
+        BLOCK "040904B0" // Lang=US English, CharSet=Unicode
+        BEGIN
+            VALUE "CompanyName", "Mozilla Foundation\0"
+            VALUE "FileDescription", MY_FILEDESCRIPTION MY_DEBUG_STR "\0"
+            VALUE "FileVersion", PR_VERSION "\0"
+            VALUE "InternalName", MY_INTERNAL_NAME "\0"
+            VALUE "OriginalFilename", MY_INTERNAL_NAME ".dll\0"
+            VALUE "ProductName", "Netscape Portable Runtime\0"
+            VALUE "ProductVersion", PR_VERSION "\0"
+        END
+    END
+    BLOCK "VarFileInfo"
+    BEGIN
+        VALUE "Translation", 0x409, 1200
+    END
+END
diff --git a/lib/prstreams/tests/testprstrm/.cvsignore b/lib/prstreams/tests/testprstrm/.cvsignore
new file mode 100644
index 0000000..f3c7a7c
--- /dev/null
+++ b/lib/prstreams/tests/testprstrm/.cvsignore
@@ -0,0 +1 @@
+Makefile
diff --git a/lib/prstreams/tests/testprstrm/Makefile.in b/lib/prstreams/tests/testprstrm/Makefile.in
new file mode 100644
index 0000000..1271f94
--- /dev/null
+++ b/lib/prstreams/tests/testprstrm/Makefile.in
@@ -0,0 +1,168 @@
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#! gmake
+
+MOD_DEPTH	= ../../../..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+
+include $(MOD_DEPTH)/config/autoconf.mk
+
+include $(topsrcdir)/config/config.mk
+
+CXXSRCS =           \
+	testprstrm.cpp    \
+	$(NULL)
+
+OBJS = $(addprefix $(OBJDIR)/,$(CXXSRCS:.cpp=.$(OBJ_SUFFIX)))
+
+ifeq (,$(filter-out WINNT OS2,$(OS_ARCH)))
+PROG_SUFFIX = .exe
+else
+PROG_SUFFIX =
+endif
+
+PROGS = $(addprefix $(OBJDIR)/, $(CXXSRCS:.cpp=$(PROG_SUFFIX)))
+
+TARGETS = $(PROGS) $(OBJS)
+
+INCLUDES = -I$(dist_includedir)
+
+# Setting the variables LDOPTS and LIBPR.  We first initialize
+# them to the default values, then adjust them for some platforms.
+LDOPTS = -L$(dist_libdir)
+LIBPR = -lnspr$(MOD_MAJOR_VERSION)
+LIBPRSTRMS = -lprstrms$(MOD_MAJOR_VERSION)
+
+ifeq ($(OS_ARCH), WINNT)
+  LDOPTS = -NOLOGO -DEBUG -INCREMENTAL:NO
+  ifeq ($(OS_TARGET), WIN95)
+    LIBPR = $(dist_libdir)/nspr$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)
+    LIBPRSTRMS = $(dist_libdir)/prstrms$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)
+  else
+    LIBPR = $(dist_libdir)/libnspr$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)
+    LIBPRSTRMS = $(dist_libdir)/libprstrms$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)
+  endif
+endif
+
+ifeq ($(OS_ARCH),OS2)
+LDOPTS += -Zomf -Zlinker /PM:VIO -lstdcpp
+endif
+
+ifneq ($(OS_ARCH), WINNT)
+PWD = $(shell pwd)
+endif
+
+ifeq ($(OS_ARCH), IRIX)
+LDOPTS += -rpath $(PWD)/$(dist_libdir)
+endif
+
+ifeq ($(OS_ARCH), OSF1)
+LDOPTS += -rpath $(PWD)/$(dist_libdir)
+endif
+
+ifeq ($(OS_ARCH), HP-UX)
+LDOPTS += -Wl,+s,+b,$(PWD)/$(dist_libdir)
+endif
+
+# AIX
+ifeq ($(OS_ARCH),AIX)
+LDOPTS += -blibpath:$(PWD)/$(dist_libdir):/usr/lib:/lib
+ifeq ($(OS_ARCH)$(OS_RELEASE),AIX4.1)
+LIBPR = -lnspr$(MOD_MAJOR_VERSION)_shr
+LIBPRSTRMS = -lprstrms$(MOD_MAJOR_VERSION)_shr
+else
+LDOPTS += -brtl
+EXTRA_LIBS = -ldl
+endif
+endif
+
+# Solaris
+ifeq ($(OS_ARCH), SunOS)
+ifdef NS_USE_GCC
+LDOPTS += -Xlinker -R -Xlinker $(PWD)/$(dist_libdir)
+else
+LDOPTS += -R $(PWD)/$(dist_libdir)
+# CC on SunOS 5.5.x needs to link with -lpthread even though we already
+# linked with this system library when we built libnspr.so.
+ifdef USE_PTHREADS
+EXTRA_LIBS = -lpthread
+endif # USE_PTHREADS
+endif # NS_USE_GCC
+endif # SunOS
+
+ifeq ($(OS_ARCH), SCOOS)
+# SCO Unix needs to link against -lsocket again even though we
+# already linked with these system libraries when we built libnspr.so.
+EXTRA_LIBS = -lsocket
+# This hardcodes in the executable programs the directory to find
+# libnspr.so etc. at program startup.  Equivalent to the -R or -rpath
+# option for ld on other platforms.
+export LD_RUN_PATH = $(PWD)/$(dist_libdir)
+endif
+
+ifeq ($(OS_ARCH), UNIXWARE)
+export LD_RUN_PATH = $(PWD)/$(dist_libdir)
+endif
+
+#####################################################
+#
+# The rules
+#
+#####################################################
+
+include $(topsrcdir)/config/rules.mk
+
+AIX_PRE_4_2 = 0
+ifeq ($(OS_ARCH),AIX)
+ifneq ($(OS_RELEASE),4.2)
+ifneq ($(USE_PTHREADS), 1)
+#AIX_PRE_4_2 = 1
+endif
+endif
+endif
+
+ifeq ($(AIX_PRE_4_2),1)
+
+# AIX releases prior to 4.2 need a special two-step linking hack
+# in order to both override the system select() and be able to 
+# get at the original system select().
+#
+# We use a pattern rule in ns/nspr20/config/rules.mk to generate
+# the .$(OBJ_SUFFIX) file from the .c source file, then do the
+# two-step linking hack below.
+
+$(OBJDIR)/%: $(OBJDIR)/%.$(OBJ_SUFFIX)
+	@$(MAKE_OBJDIR)
+	rm -f $@ $(AIX_TMP)
+	$(CC) $(AIX_LINK_OPTS) -o $(AIX_TMP) $< $(dist_libdir)/libnspr$(MOD_MAJOR_VERSION).a
+	$(CC) -o $@ $(AIX_TMP) $(AIX_WRAP)
+	rm -f $(AIX_TMP)
+
+else
+
+# All platforms that are not AIX pre-4.2.
+
+$(OBJDIR)/%$(PROG_SUFFIX): $(OBJDIR)/%.$(OBJ_SUFFIX)
+	@$(MAKE_OBJDIR)
+ifeq ($(OS_ARCH), WINNT)
+	link $(LDOPTS) $< $(LIBPR) $(LIBPRSTRMS) ws2_32.lib -out:$@
+else
+ifeq ($(OS_ARCH),OS2)
+	$(LINK) $(EXEFLAGS) $(LDOPTS) $< $(LIBPR) $(LIBPRSTRMS) $(OS_LIBS) $(EXTRA_LIBS)
+else
+	$(CCC) $(XCFLAGS) $< $(LDOPTS) $(LIBPR) $(LIBPRSTRMS) $(EXTRA_LIBS) -o $@
+endif
+endif
+endif
+
+export:: $(TARGETS)
+clean::
+	rm -f $(TARGETS)
+
+testlinker:
+	echo $(LINK)
diff --git a/lib/prstreams/tests/testprstrm/testprstrm.cpp b/lib/prstreams/tests/testprstrm/testprstrm.cpp
new file mode 100644
index 0000000..12011c8
--- /dev/null
+++ b/lib/prstreams/tests/testprstrm/testprstrm.cpp
@@ -0,0 +1,171 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "prstrms.h"
+
+#include "prinit.h"
+#include "prio.h"
+#include "prthread.h"
+
+#include <cstring>
+#include <iostream>
+
+#ifdef XP_UNIX
+#include <sys/stat.h>
+#endif
+
+using std::cout;
+using std::endl;
+using std::ios;
+
+const unsigned int MaxCnt = 1;
+
+typedef struct threadarg {
+    const char *mytag;
+} threadarg;
+
+void threadwork(threadarg *arg);
+
+void 
+threadmain(void *mytag)
+{
+    threadarg arg;
+
+    arg.mytag = static_cast<const char *>(mytag);
+
+    threadwork(&arg);
+}
+
+void
+threadwork(threadarg *arg)
+{
+	unsigned int i;
+
+	char fname1[256];
+	char fname2[256];
+
+	strcpy(fname1, arg->mytag);
+	strcpy(fname2, arg->mytag);
+	strcat(fname2, "2");
+	PR_Delete(fname1);
+	PR_Delete(fname2);
+
+	PRfilebuf *fb[MaxCnt];
+	PRifstream *ifs[MaxCnt];
+	PRofstream *ofs[MaxCnt];
+	int mode = 0;
+#ifdef XP_UNIX
+	mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH;
+#endif
+
+	//
+	// Allocate a bunch
+	cout << "Testing unused filebufs ----------------" << endl;
+	for (i=0; i < MaxCnt; i++){
+		fb[i] = new PRfilebuf;
+	}
+	// Delete them
+	for (i=0; i < MaxCnt; i++){
+		delete fb[i];
+	}
+	cout << "Unused filebufs complete ---------------" << endl;
+
+	//
+	// Allocate a bunch
+	cout << "Testing unused ifstream -----------------" << endl;
+	for (i=0; i < MaxCnt; i++){
+	  ifs[i] = new PRifstream;
+	}
+	//
+	// Delete them
+	for (i=0; i < MaxCnt; i++){
+	  delete ifs[i];
+	}
+	cout << "Unused ifstream complete ----------------" << endl;
+	//
+	// Allocate a bunch
+	cout << "Testing unused ofstream -----------------" << endl;
+	for (i=0; i < MaxCnt; i++){
+		ofs[i] = new PRofstream;
+	}
+	for (i=0; i < MaxCnt; i++){
+	  *(ofs[i]) << "A"; // Write a bit
+	  delete ofs[i]; // Delete it.
+	}
+	cout << "Unused ofstream complete ----------------" << endl;
+
+	cout << "Testing use of ofstream 1 (extra filebuf allocated) ---------" << endl;
+	PRofstream *aos = new PRofstream(fname1, ios::out|ios::ate, mode);
+	for (i=0; i < MaxCnt; i++){
+	  for (int j=0; j < 8192; j++)
+		*aos << "AaBbCcDdEeFfGg" << endl;
+		fb[i] = new PRfilebuf; // Allocate as we go to hack at the heap
+	}
+	//
+	// Delete the extra foo we allocated
+	for (i=0; i < MaxCnt; i++){
+	  delete fb[i];
+	}
+	aos->flush(); // Explicit flush
+	delete aos;
+	cout << "Testing use of ofstream 1 complete (extra filebuf deleted) --" << endl;
+	cout << "Testing use of ofstream 2 (extra filebuf allocated) ---------" << endl;
+	PRofstream *aos2 = new PRofstream(fname2, ios::out, mode);
+
+	for (i=0; i < MaxCnt; i++){
+	    *aos2 << "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz";
+	}
+	// Force flushing in the dtor
+	delete aos2;
+	cout << "Testing use of ofstream 2 complete (extra filebuf deleted) --" << endl;
+	char line[1024];
+	cout << "Testing use of ifstream 1 (stack allocation) -------------" << endl;
+	PRifstream ais(fname1);
+	for (i=0; i < MaxCnt; i++){
+		ais >> line;
+	}
+	cout << "Testing use of ifstream 1 complete -----------------------" << endl;
+	cout << "Testing use of ifstream 2 ----------------------" << endl;
+	PRifstream *ais2 = new PRifstream(fname2);
+	char achar;
+	for (i=0; i < MaxCnt*10; i++){
+		*ais2 >> achar;
+	}
+	delete ais2;
+	cout << "Testing use of ifstream 2 complete -------------" << endl;
+}
+
+#define STACKSIZE 1024*1024
+int
+main()
+{
+	PR_Init(PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 256);
+	threadmain(const_cast<char *>("TestFile"));
+	PRThread *thr1 = PR_CreateThread(PR_SYSTEM_THREAD, 
+					 threadmain, 
+					 const_cast<char *>("TestFile1"),
+					 PR_PRIORITY_NORMAL,
+					 PR_GLOBAL_THREAD,
+					 PR_JOINABLE_THREAD,
+					 STACKSIZE);
+	PRThread *thr2 = PR_CreateThread(PR_SYSTEM_THREAD, 
+					 threadmain, 
+					 const_cast<char *>("TestFile2"),
+					 PR_PRIORITY_NORMAL,
+					 PR_GLOBAL_THREAD,
+					 PR_JOINABLE_THREAD,
+					 STACKSIZE);
+	PRThread *thr3 = PR_CreateThread(PR_SYSTEM_THREAD, 
+					 threadmain, 
+					 const_cast<char *>("TestFile3"),
+					 PR_PRIORITY_NORMAL,
+					 PR_GLOBAL_THREAD,
+					 PR_JOINABLE_THREAD,
+					 STACKSIZE);
+	PR_JoinThread(thr1);
+	PR_JoinThread(thr2);
+	PR_JoinThread(thr3);
+	return 0;
+}
diff --git a/lib/tests/.cvsignore b/lib/tests/.cvsignore
new file mode 100644
index 0000000..f3c7a7c
--- /dev/null
+++ b/lib/tests/.cvsignore
@@ -0,0 +1 @@
+Makefile
diff --git a/lib/tests/Makefile.in b/lib/tests/Makefile.in
new file mode 100644
index 0000000..d8f595f
--- /dev/null
+++ b/lib/tests/Makefile.in
@@ -0,0 +1,178 @@
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#! gmake
+
+MOD_DEPTH	= ../..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+
+include $(MOD_DEPTH)/config/autoconf.mk
+
+include $(topsrcdir)/config/config.mk
+
+CSRCS = \
+	arena.c \
+	base64t.c \
+	getopt.c \
+	string.c
+
+ifeq (,$(filter-out WINCE WINNT OS2,$(OS_ARCH)))
+CSRCS += arena.c
+endif
+
+ifeq (,$(filter-out WINCE WINNT OS2,$(OS_ARCH)))
+PROG_SUFFIX = .exe
+else
+PROG_SUFFIX =
+endif
+
+PROGS = $(addprefix $(OBJDIR)/, $(CSRCS:.c=$(PROG_SUFFIX)))
+
+TARGETS = $(PROGS) $(OBJS)
+
+INCLUDES = -I$(dist_includedir)
+
+# Setting the variables LDOPTS and LIBPR.  We first initialize
+# them to the default values, then adjust them for some platforms.
+LDOPTS = -L$(dist_libdir)
+LIBPR = -lnspr$(MOD_MAJOR_VERSION)
+LIBPLC = -lplc$(MOD_MAJOR_VERSION)
+LIBPLDS = -lplds$(MOD_MAJOR_VERSION)
+
+ifeq (,$(filter-out WINCE WINNT, $(OS_ARCH)))
+  LDOPTS = -NOLOGO -DEBUG -INCREMENTAL:NO
+  ifeq (,$(filter-out WIN95 WINCE WINMO, $(OS_TARGET)))
+  LIBPR = $(dist_libdir)/nspr$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)
+  LIBPLC= $(dist_libdir)/plc$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)
+  LIBPLDS= $(dist_libdir)/plds$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)
+  else
+  LIBPR = $(dist_libdir)/libnspr$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)
+  LIBPLC= $(dist_libdir)/libplc$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)
+  LIBPLDS= $(dist_libdir)/libplds$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)
+  endif
+endif
+
+ifeq ($(OS_ARCH),OS2)
+LDOPTS += -Zomf -Zlinker /PM:VIO
+endif
+
+ifneq ($(OS_ARCH), WINNT)
+PWD = $(shell pwd)
+endif
+
+ifeq ($(OS_ARCH), IRIX)
+LDOPTS += -rpath $(PWD)/$(dist_libdir)
+endif
+
+ifeq ($(OS_ARCH), Linux)
+    ifeq ($(OS_RELEASE), 1.2)
+        EXTRA_LIBS = -ldl
+    else
+        LDOPTS += -Xlinker -rpath $(PWD)/$(dist_libdir)
+        ifeq ($(USE_PTHREADS),1)
+            EXTRA_LIBS = -lpthread
+        endif
+    endif
+endif
+
+ifeq (,$(filter-out OpenBSD,$(OS_ARCH)))
+    ifeq ($(USE_PTHREADS),1)
+        EXTRA_LIBS = -lpthread
+    endif
+endif
+
+ifeq ($(OS_ARCH), OSF1)
+LDOPTS += -rpath $(PWD)/$(dist_libdir) -lpthread
+endif
+
+ifeq ($(OS_ARCH), HP-UX)
+LDOPTS += -Wl,+s,+b,$(PWD)/$(dist_libdir)
+endif
+
+# AIX
+ifeq ($(OS_ARCH),AIX)
+LDOPTS += -blibpath:$(PWD)/$(dist_libdir):/usr/lib:/lib
+LIBPR = -lnspr$(MOD_MAJOR_VERSION)_shr
+LIBPLC = -lplc$(MOD_MAJOR_VERSION)_shr
+endif
+
+# Solaris
+ifeq ($(OS_ARCH), SunOS)
+ifdef NS_USE_GCC
+LDOPTS += -Xlinker -R -Xlinker $(PWD)/$(dist_libdir)
+else
+LDOPTS += -R $(PWD)/$(dist_libdir)
+endif
+
+# SunOS 5.5 needs to link with -lpthread, even though we already
+# linked with this system library when we built libnspr.so.
+ifeq ($(OS_RELEASE), 5.5)
+ifdef USE_PTHREADS
+EXTRA_LIBS = -lpthread
+endif
+endif
+endif # SunOS
+
+#####################################################
+#
+# The rules
+#
+#####################################################
+
+include $(topsrcdir)/config/rules.mk
+
+AIX_PRE_4_2 = 0
+ifeq ($(OS_ARCH),AIX)
+ifneq ($(OS_RELEASE),4.2)
+ifneq ($(USE_PTHREADS), 1)
+#AIX_PRE_4_2 = 1
+endif
+endif
+endif
+
+ifeq ($(AIX_PRE_4_2),1)
+
+# AIX releases prior to 4.2 need a special two-step linking hack
+# in order to both override the system select() and be able to 
+# get at the original system select().
+#
+# We use a pattern rule in ns/nspr20/config/rules.mk to generate
+# the .$(OBJ_SUFFIX) file from the .c source file, then do the
+# two-step linking hack below.
+
+$(OBJDIR)/%: $(OBJDIR)/%.$(OBJ_SUFFIX)
+	@$(MAKE_OBJDIR)
+	rm -f $@ $(AIX_TMP)
+	$(CC) $(AIX_LINK_OPTS) -o $(AIX_TMP) $< $(dist_libdir)/libnspr$(MOD_MAJOR_VERSION).a
+	$(CC) -o $@ $(AIX_TMP) $(AIX_WRAP)
+	rm -f $(AIX_TMP)
+
+else
+
+# All platforms that are not AIX pre-4.2.
+
+$(OBJDIR)/%$(PROG_SUFFIX): $(OBJDIR)/%.$(OBJ_SUFFIX)
+	@$(MAKE_OBJDIR)
+
+ifeq ($(OS_ARCH), WINNT)
+	link $(LDOPTS) $< $(LIBPLC) $(LIBPLDS) $(LIBPR) ws2_32.lib -out:$@
+else
+ifeq ($(OS_ARCH), WINCE)
+	$(LD) $(LDOPTS) $< $(LIBPLC) $(LIBPLDS) $(LIBPR) ws2.lib -out:$@
+else
+ifeq ($(OS_ARCH),OS2)
+	$(LINK) $(EXEFLAGS) $(LDOPTS) $< $(LIBPLC)  $(LIBPLDS) $(LIBPR) $(OS_LIBS) $(EXTRA_LIBS)
+else
+	$(CC) $(XCFLAGS) $< $(LDOPTS) $(LIBPLC) $(LIBPLDS) $(LIBPR) $(EXTRA_LIBS) -o $@
+endif
+endif
+endif
+endif
+
+export:: $(TARGETS)
+clean::
+	rm -f $(TARGETS)
diff --git a/lib/tests/arena.c b/lib/tests/arena.c
new file mode 100644
index 0000000..e82e4f8
--- /dev/null
+++ b/lib/tests/arena.c
@@ -0,0 +1,369 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** File:        arena.c
+** Description: Testing arenas
+**
+*/
+
+#include <string.h>
+#include <time.h>
+#include <stdlib.h>
+#include "nspr.h"
+#include "plarena.h"
+#include "plgetopt.h"
+
+PRLogModuleInfo *tLM;
+PRIntn  threadCount = 0;
+PRMonitor   *tMon;
+PRBool failed_already = PR_FALSE;
+
+/* Arguments from the command line with default values */
+PRIntn debug_mode = 0;
+PRIntn  poolMin = 4096;
+PRIntn  poolMax = (100 * 4096);
+PRIntn  arenaMin = 40;
+PRIntn  arenaMax = (100 * 40);
+PRIntn  stressIterations = 15;
+PRIntn  maxAlloc = (1024 * 1024);
+PRIntn  stressThreads = 4;
+
+void DumpAll( void )
+{
+	return;
+}
+
+/*
+** Test Arena allocation.
+*/
+static void ArenaAllocate( void )
+{
+    PLArenaPool ap;
+    void    *ptr;
+	PRInt32	i;
+
+    PL_InitArenaPool( &ap, "AllocArena", 2048, sizeof(double));
+    PR_LOG( tLM, PR_LOG_DEBUG, ("AA, InitPool -- Pool: %p. first: %p, current: %p, size: %d", 
+        &ap, ap.first, ap.current, ap.arenasize  ));
+
+	for( i = 0; i < 150; i++ )
+	{
+		PL_ARENA_ALLOCATE( ptr, &ap, 512 );
+        PR_LOG( tLM, PR_LOG_DEBUG,("AA, after alloc -- Pool: %p. first: %p, current: %p, size: %d", 
+               &ap, ap.first, ap.current, ap.arenasize  ));
+		PR_LOG( tLM, PR_LOG_DEBUG,(
+		    "AA -- Pool: %p. alloc: %p ", &ap, ptr ));
+	}
+
+    PL_FreeArenaPool( &ap );
+
+	for( i = 0; i < 221; i++ )
+	{
+		PL_ARENA_ALLOCATE( ptr, &ap, 512 );
+        PR_LOG( tLM, PR_LOG_DEBUG,("AA, after alloc -- Pool: %p. first: %p, current: %p, size: %d", 
+               &ap, ap.first, ap.current, ap.arenasize  ));
+		PR_LOG( tLM, PR_LOG_DEBUG,(
+		    "AA -- Pool: %p. alloc: %p ", &ap, ptr ));
+	}
+
+    PL_FreeArenaPool( &ap );
+    
+    return;
+} /* end ArenaGrow() */
+/*
+** Test Arena grow.
+*/
+static void ArenaGrow( void )
+{
+    PLArenaPool ap;
+    void    *ptr;
+	PRInt32	i;
+
+    PL_InitArenaPool( &ap, "TheArena", 4096, sizeof(double));
+    PL_ARENA_ALLOCATE( ptr, &ap, 512 );
+
+	PR_LOG( tLM, PR_LOG_DEBUG, ("Before growth -- Pool: %p. alloc: %p ", &ap, ptr ));
+
+	for( i = 0; i < 10; i++ )
+	{
+		PL_ARENA_GROW( ptr, &ap, 512, 7000 );
+		PR_LOG( tLM, PR_LOG_DEBUG, ("After growth -- Pool: %p. alloc: %p ", &ap, ptr ));
+	}
+
+
+    return;
+} /* end ArenaGrow() */
+
+
+/*
+** Test arena Mark and Release.
+*/
+static void MarkAndRelease( void )
+{
+    PLArenaPool ap;
+    void    *ptr = NULL;
+    void    *mark0, *mark1;
+    PRIntn  i;
+
+    PL_InitArenaPool( &ap, "TheArena", 4096, sizeof(double));
+    mark0 = PL_ARENA_MARK( &ap );
+    PR_LOG( tLM, PR_LOG_DEBUG,
+        ("mark0. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p, m0: %p", 
+            &ap, ap.first.next, ap.current, ap.arenasize, ptr, mark0 ));
+
+	for( i = 0; i < 201; i++ )
+	{
+		PL_ARENA_ALLOCATE( ptr, &ap, 512 );
+        PR_LOG( tLM, PR_LOG_DEBUG,
+            ("mr. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p", 
+                &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
+	}
+
+    mark1 = PL_ARENA_MARK( &ap );
+    PR_LOG( tLM, PR_LOG_DEBUG,
+        ("mark1. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p, m1: %p", 
+            &ap, ap.first.next, ap.current, ap.arenasize, ptr, mark1 ));
+
+
+	for( i = 0; i < 225; i++ )
+	{
+		PL_ARENA_ALLOCATE( ptr, &ap, 512 );
+        PR_LOG( tLM, PR_LOG_DEBUG,
+            ("mr. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p", 
+                &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
+	}
+
+    PL_ARENA_RELEASE( &ap, mark1 );
+    PR_LOG( tLM, PR_LOG_DEBUG,
+        ("Release-1: %p -- Pool: %p. first: %p, current: %p, size: %d", 
+               mark1, &ap, ap.first, ap.current, ap.arenasize  ));
+
+	for( i = 0; i < 20; i++ )
+	{
+		PL_ARENA_ALLOCATE( ptr, &ap, 512 );
+        PR_LOG( tLM, PR_LOG_DEBUG,
+            ("mr. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p", 
+                &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
+	}
+
+    PL_ARENA_RELEASE( &ap, mark1 );
+    PR_LOG( tLM, PR_LOG_DEBUG,
+        ("Release-1. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p", 
+            &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
+
+    PL_ARENA_RELEASE( &ap, mark0 );
+    PR_LOG( tLM, PR_LOG_DEBUG,
+        ("Release-0. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p", 
+            &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
+
+    PL_FreeArenaPool( &ap );
+    PR_LOG( tLM, PR_LOG_DEBUG,
+        ("Free. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p", 
+            &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
+    
+    PL_FinishArenaPool( &ap );
+    PR_LOG( tLM, PR_LOG_DEBUG,
+        ("Finish. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p", 
+            &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
+
+    return;
+} /* end MarkAndRelease() */
+
+/*
+** RandSize() returns a random number in the range 
+** min..max, rounded to the next doubleword
+**
+*/
+static PRIntn RandSize( PRIntn min, PRIntn max )
+{
+    PRIntn  sz = (rand() % (max -min)) + min + sizeof(double);
+
+    sz &= ~sizeof(double)-1;
+
+    return(sz);
+}
+
+
+/*
+** StressThread()
+** A bunch of these beat on individual arenas
+** This tests the free_list protection.
+**
+*/
+static void PR_CALLBACK StressThread( void *arg )
+{
+    PLArenaPool ap;
+    PRIntn i;
+    PRIntn sz;
+    void *ptr;
+    PRThread *tp = PR_GetCurrentThread();
+
+    PR_LOG( tLM, PR_LOG_DEBUG, ("Stress Thread %p started\n", PR_GetCurrentThread()));
+    PL_InitArenaPool( &ap, "TheArena", RandSize( poolMin, poolMax), sizeof(double));
+
+    for ( i = 0; i < stressIterations; i++ )
+    {
+        PRIntn allocated = 0;
+
+        while ( allocated < maxAlloc )
+        {
+            sz = RandSize( arenaMin, arenaMax );
+            PL_ARENA_ALLOCATE( ptr, &ap, sz );
+            if ( ptr == NULL )
+            {
+                PR_LOG( tLM, PR_LOG_ERROR, ("ARENA_ALLOCATE() returned NULL\n\tAllocated: %d\n", allocated));
+                break;
+            }
+            allocated += sz;
+        }
+        PR_LOG( tLM, PR_LOG_DEBUG, ("Stress thread %p finished one iteration\n", tp));
+        PL_FreeArenaPool( &ap );
+    }
+    PR_LOG( tLM, PR_LOG_DEBUG, ("Stress thread %p finished all iteration\n", tp));
+    PL_FinishArenaPool( &ap );
+    PR_LOG( tLM, PR_LOG_DEBUG, ("Stress thread %p after FinishArenaPool()\n", tp));
+
+    /* That's all folks! let's quit */
+    PR_EnterMonitor(tMon);
+    threadCount--;
+    PR_Notify(tMon);
+    PR_ExitMonitor(tMon);    
+    return;
+}    
+
+/*
+** Stress()
+** Flog the hell out of arenas multi-threaded.
+** Do NOT pass an individual arena to another thread.
+** 
+*/
+static void Stress( void )
+{
+    PRThread    *tt;
+    PRIntn      i;
+
+    tMon = PR_NewMonitor();
+
+    for ( i = 0 ; i < stressThreads ; i++ )
+    {
+        PR_EnterMonitor(tMon);
+        tt = PR_CreateThread(PR_USER_THREAD,
+               StressThread,
+               NULL,
+               PR_PRIORITY_NORMAL,
+               PR_GLOBAL_THREAD,
+               PR_UNJOINABLE_THREAD,
+               0);
+        threadCount++;
+        PR_ExitMonitor(tMon);
+    }
+
+    /* Wait for all threads to exit */
+    PR_EnterMonitor(tMon);
+    while ( threadCount != 0 ) 
+    {
+        PR_Wait(tMon, PR_INTERVAL_NO_TIMEOUT);
+    }
+    PR_ExitMonitor(tMon);
+	PR_DestroyMonitor(tMon);
+
+    return;
+} /* end Stress() */
+
+/*
+** EvaluateResults()
+** uses failed_already to display results and set program
+** exit code.
+*/
+static PRIntn  EvaluateResults(void)
+{
+    PRIntn rc = 0;
+
+    if ( failed_already == PR_TRUE )
+    {
+        PR_LOG( tLM, PR_LOG_DEBUG, ("FAIL\n"));
+        rc =1;
+    } 
+    else
+    {
+        PR_LOG( tLM, PR_LOG_DEBUG, ("PASS\n"));
+    }
+    return(rc);
+} /* EvaluateResults() */
+
+void Help( void )
+{
+    printf("arena [options]\n");
+    printf("where options are:\n");
+    printf("-p <n>   minimum size of an arena pool. Default(%d)\n", poolMin);
+    printf("-P <n>   maximum size of an arena pool. Default(%d)\n", poolMax);
+    printf("-a <n>   minimum size of an arena allocation. Default(%d)\n", arenaMin);
+    printf("-A <n>   maximum size of an arena allocation. Default(%d)\n", arenaMax);
+    printf("-i <n>   number of iterations in a stress thread. Default(%d)\n", stressIterations);
+    printf("-s <n>   maximum allocation for a single stress thread. Default(%d)\n", maxAlloc);
+    printf("-t <n>   number of stress threads. Default(%d)\n", stressThreads );
+    printf("-d       enable debug mode\n");
+    printf("\n");
+    exit(1);
+}    
+
+PRIntn main(PRIntn argc, char *argv[])
+{
+    PLOptStatus os;
+	PLOptState *opt = PL_CreateOptState(argc, argv, "dhp:P:a:A:i:s:t:");
+	while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+    {
+		if (PL_OPT_BAD == os) continue;
+        switch (opt->option)
+        {
+        case 'a':  /* arena Min size */
+            arenaMin = atol( opt->value );
+            break;
+        case 'A':  /* arena Max size  */
+            arenaMax = atol( opt->value );
+            break;
+        case 'p':  /* pool Min size */
+            poolMin = atol( opt->value );
+            break;
+        case 'P':  /* pool Max size */
+            poolMax = atol( opt->value );
+            break;
+        case 'i':  /* Iterations in stress tests */
+            stressIterations = atol( opt->value );
+            break;
+        case 's':  /* storage to get per iteration */
+            maxAlloc = atol( opt->value );
+            break;
+        case 't':  /* Number of stress threads to create */
+            stressThreads = atol( opt->value );
+            break;
+        case 'd':  /* debug mode */
+			debug_mode = 1;
+            break;
+        case 'h':  /* help */
+        default:
+            Help();
+        } /* end switch() */
+    } /* end while() */
+	PL_DestroyOptState(opt);
+
+    srand( (unsigned)time( NULL ) ); /* seed random number generator */
+    tLM = PR_NewLogModule("testcase");
+
+
+#if 0
+	ArenaAllocate();
+	ArenaGrow();
+#endif
+
+    MarkAndRelease();
+
+    Stress();
+
+    return(EvaluateResults());
+} /* end main() */
+
+/* arena.c */
diff --git a/lib/tests/base64t.c b/lib/tests/base64t.c
new file mode 100644
index 0000000..d225c65
--- /dev/null
+++ b/lib/tests/base64t.c
@@ -0,0 +1,3015 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "plbase64.h"
+#include "plstr.h"
+#include "nspr.h"
+
+#include <stdio.h>
+
+static unsigned char *base = (unsigned char *)"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+/* PL_Base64Encode, single characters */
+PRBool test_001(void)
+{
+    PRUint32 a, b;
+    unsigned char plain[ 4 ];
+    unsigned char cypher[ 5 ];
+    char result[ 8 ];
+    char *rv;
+
+    printf("Test 001 (PL_Base64Encode, single characters)                         ..."); fflush(stdout);
+
+    plain[1] = plain[2] = plain[3] = (unsigned char)0;
+    cypher[2] = cypher[3] = (unsigned char)'=';
+    cypher[4] = (unsigned char)0;
+
+    for( a = 0; a < 64; a++ )
+    {
+        cypher[0] = base[a];
+
+        for( b = 0; b < 4; b++ )
+        {
+            plain[0] = (unsigned char)(a * 4 + b);
+            cypher[1] = base[(b * 16)];
+
+            rv = PL_Base64Encode((char *)plain, 1, result);
+            if( rv != result )
+            {
+                printf("FAIL\n\t(%d, %d): return value\n", a, b);
+                return PR_FALSE;
+            }
+
+            if( 0 != PL_strncmp((char *)cypher, result, 4) )
+            {
+                printf("FAIL\n\t(%d, %d): expected \"%s,\" got \"%.4s.\"\n",
+                       a, b, cypher, result);
+                return PR_FALSE;
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_Base64Encode, double characters */
+PRBool test_002(void)
+{
+    PRUint32 a, b, c, d;
+    unsigned char plain[ 4 ];
+    unsigned char cypher[ 5 ];
+    char result[ 8 ];
+    char *rv;
+
+    printf("Test 002 (PL_Base64Encode, double characters)                         ..."); fflush(stdout);
+
+    plain[2] = plain[3] = (unsigned char)0;
+    cypher[3] = (unsigned char)'=';
+    cypher[4] = (unsigned char)0;
+
+    for( a = 0; a < 64; a++ )
+    {
+        cypher[0] = base[a];
+        for( b = 0; b < 4; b++ )
+        {
+            plain[0] = (a*4) + b;
+            for( c = 0; c < 16; c++ )
+            {
+                cypher[1] = base[b*16 + c];
+                for( d = 0; d < 16; d++ )
+                {
+                    plain[1] = c*16 + d;
+                    cypher[2] = base[d*4];
+
+                    rv = PL_Base64Encode((char *)plain, 2, result);
+                    if( rv != result )
+                    {
+                        printf("FAIL\n\t(%d, %d, %d, %d): return value\n", a, b, c, d);
+                        return PR_FALSE;
+                    }
+
+                    if( 0 != PL_strncmp((char *)cypher, result, 4) )
+                    {
+                        printf("FAIL\n\t(%d, %d, %d, %d): expected \"%s,\" got \"%.4s.\"\n",
+                               a, b, c, d, cypher, result);
+                        return PR_FALSE;
+                    }
+                }
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_Base64Encode, triple characters */
+PRBool test_003(void)
+{
+    PRUint32 a, b, c, d, e, f;
+    unsigned char plain[ 4 ];
+    unsigned char cypher[ 5 ];
+    char result[ 8 ];
+    char *rv;
+
+    printf("Test 003 (PL_Base64Encode, triple characters)                         ..."); fflush(stdout);
+
+    cypher[4] = (unsigned char)0;
+
+    for( a = 0; a < 64; a++ )
+    {
+        cypher[0] = base[a];
+        for( b = 0; b < 4; b++ )
+        {
+            plain[0] = (a*4) + b;
+            for( c = 0; c < 16; c++ )
+            {
+                cypher[1] = base[b*16 + c];
+                for( d = 0; d < 16; d++ )
+                {
+                    plain[1] = c*16 + d;
+                    for( e = 0; e < 4; e++ )
+                    {
+                        cypher[2] = base[d*4 + e];
+                        for( f = 0; f < 64; f++ )
+                        {
+                            plain[2] = e * 64 + f;
+                            cypher[3] = base[f];
+
+                            rv = PL_Base64Encode((char *)plain, 3, result);
+                            if( rv != result )
+                            {
+                                printf("FAIL\n\t(%d, %d, %d, %d, %d, %d): return value\n", a, b, c, d, e, f);
+                                return PR_FALSE;
+                            }
+
+                            if( 0 != PL_strncmp((char *)cypher, result, 4) )
+                            {
+                                printf("FAIL\n\t(%d, %d, %d, %d, %d, %d): expected \"%s,\" got \"%.4s.\"\n",
+                                       a, b, c, d, e, f, cypher, result);
+                                return PR_FALSE;
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+    static struct
+    {
+        const char *plaintext;
+        const char *cyphertext;
+    } array[] =
+      {
+          /* Cyphertexts generated with uuenview 0.5.13 */
+          { " ", "IA==" },
+          { ".", "Lg==" },
+          { "/", "Lw==" },
+          { "C", "Qw==" },
+          { "H", "SA==" },
+          { "S", "Uw==" },
+          { "^", "Xg==" },
+          { "a", "YQ==" },
+          { "o", "bw==" },
+          { "t", "dA==" },
+
+          { "AB", "QUI=" },
+          { "AH", "QUg=" },
+          { "AQ", "QVE=" },
+          { "BD", "QkQ=" },
+          { "CR", "Q1I=" },
+          { "CS", "Q1M=" },
+          { "DB", "REI=" },
+          { "DC", "REM=" },
+          { "EK", "RUs=" },
+          { "ET", "RVQ=" },
+          { "IM", "SU0=" },
+          { "JR", "SlI=" },
+          { "LO", "TE8=" },
+          { "LW", "TFc=" },
+          { "ML", "TUw=" },
+          { "SB", "U0I=" },
+          { "TO", "VE8=" },
+          { "VS", "VlM=" },
+          { "WP", "V1A=" },
+          /* legitimate two-letter words */
+          { "ad", "YWQ=" },
+          { "ah", "YWg=" },
+          { "am", "YW0=" },
+          { "an", "YW4=" },
+          { "as", "YXM=" },
+          { "at", "YXQ=" },
+          { "ax", "YXg=" },
+          { "be", "YmU=" },
+          { "by", "Ynk=" },
+          { "do", "ZG8=" },
+          { "go", "Z28=" },
+          { "he", "aGU=" },
+          { "hi", "aGk=" },
+          { "if", "aWY=" },
+          { "in", "aW4=" },
+          { "is", "aXM=" },
+          { "it", "aXQ=" },
+          { "me", "bWU=" },
+          { "my", "bXk=" },
+          { "no", "bm8=" },
+          { "of", "b2Y=" },
+          { "on", "b24=" },
+          { "or", "b3I=" },
+          { "ox", "b3g=" },
+          { "so", "c28=" },
+          { "to", "dG8=" },
+          { "up", "dXA=" },
+          { "us", "dXM=" },
+          { "we", "d2U=" },
+          /* all three-letter entries in /usr/dict/words */
+          { "1st", "MXN0" },
+          { "2nd", "Mm5k" },
+          { "3rd", "M3Jk" },
+          { "4th", "NHRo" },
+          { "5th", "NXRo" },
+          { "6th", "NnRo" },
+          { "7th", "N3Ro" },
+          { "8th", "OHRo" },
+          { "9th", "OXRo" },
+          { "AAA", "QUFB" },
+          { "AAU", "QUFV" },
+          { "ABA", "QUJB" },
+          { "abc", "YWJj" },
+          { "Abe", "QWJl" },
+          { "Abo", "QWJv" },
+          { "ace", "YWNl" },
+          { "ACM", "QUNN" },
+          { "ACS", "QUNT" },
+          { "act", "YWN0" },
+          { "Ada", "QWRh" },
+          { "add", "YWRk" },
+          { "ado", "YWRv" },
+          { "aft", "YWZ0" },
+          { "age", "YWdl" },
+          { "ago", "YWdv" },
+          { "aid", "YWlk" },
+          { "ail", "YWls" },
+          { "aim", "YWlt" },
+          { "air", "YWly" },
+          { "ala", "YWxh" },
+          { "alb", "YWxi" },
+          { "ale", "YWxl" },
+          { "Ali", "QWxp" },
+          { "all", "YWxs" },
+          { "alp", "YWxw" },
+          { "A&M", "QSZN" },
+          { "AMA", "QU1B" },
+          { "ami", "YW1p" },
+          { "amp", "YW1w" },
+          { "Amy", "QW15" },
+          { "amy", "YW15" },
+          { "ana", "YW5h" },
+          { "and", "YW5k" },
+          { "ani", "YW5p" },
+          { "Ann", "QW5u" },
+          { "ant", "YW50" },
+          { "any", "YW55" },
+          { "A&P", "QSZQ" },
+          { "ape", "YXBl" },
+          { "Apr", "QXBy" },
+          { "APS", "QVBT" },
+          { "apt", "YXB0" },
+          { "arc", "YXJj" },
+          { "are", "YXJl" },
+          { "ark", "YXJr" },
+          { "arm", "YXJt" },
+          { "art", "YXJ0" },
+          { "a's", "YSdz" },
+          { "ash", "YXNo" },
+          { "ask", "YXNr" },
+          { "ass", "YXNz" },
+          { "ate", "YXRl" },
+          { "Aug", "QXVn" },
+          { "auk", "YXVr" },
+          { "Ave", "QXZl" },
+          { "awe", "YXdl" },
+          { "awl", "YXds" },
+          { "awn", "YXdu" },
+          { "axe", "YXhl" },
+          { "aye", "YXll" },
+          { "bad", "YmFk" },
+          { "bag", "YmFn" },
+          { "bah", "YmFo" },
+          { "bam", "YmFt" },
+          { "ban", "YmFu" },
+          { "bar", "YmFy" },
+          { "bat", "YmF0" },
+          { "bay", "YmF5" },
+          { "bed", "YmVk" },
+          { "bee", "YmVl" },
+          { "beg", "YmVn" },
+          { "bel", "YmVs" },
+          { "Ben", "QmVu" },
+          { "bet", "YmV0" },
+          { "bey", "YmV5" },
+          { "bib", "Ymli" },
+          { "bid", "Ymlk" },
+          { "big", "Ymln" },
+          { "bin", "Ymlu" },
+          { "bit", "Yml0" },
+          { "biz", "Yml6" },
+          { "BMW", "Qk1X" },
+          { "boa", "Ym9h" },
+          { "bob", "Ym9i" },
+          { "bog", "Ym9n" },
+          { "bon", "Ym9u" },
+          { "boo", "Ym9v" },
+          { "bop", "Ym9w" },
+          { "bow", "Ym93" },
+          { "box", "Ym94" },
+          { "boy", "Ym95" },
+          { "b's", "Yidz" },
+          { "BTL", "QlRM" },
+          { "BTU", "QlRV" },
+          { "bub", "YnVi" },
+          { "bud", "YnVk" },
+          { "bug", "YnVn" },
+          { "bum", "YnVt" },
+          { "bun", "YnVu" },
+          { "bus", "YnVz" },
+          { "but", "YnV0" },
+          { "buy", "YnV5" },
+          { "bye", "Ynll" },
+          { "cab", "Y2Fi" },
+          { "Cal", "Q2Fs" },
+          { "cam", "Y2Ft" },
+          { "can", "Y2Fu" },
+          { "cap", "Y2Fw" },
+          { "car", "Y2Fy" },
+          { "cat", "Y2F0" },
+          { "caw", "Y2F3" },
+          { "CBS", "Q0JT" },
+          { "CDC", "Q0RD" },
+          { "CEQ", "Q0VR" },
+          { "chi", "Y2hp" },
+          { "CIA", "Q0lB" },
+          { "cit", "Y2l0" },
+          { "cod", "Y29k" },
+          { "cog", "Y29n" },
+          { "col", "Y29s" },
+          { "con", "Y29u" },
+          { "coo", "Y29v" },
+          { "cop", "Y29w" },
+          { "cos", "Y29z" },
+          { "cot", "Y290" },
+          { "cow", "Y293" },
+          { "cox", "Y294" },
+          { "coy", "Y295" },
+          { "CPA", "Q1BB" },
+          { "cpu", "Y3B1" },
+          { "CRT", "Q1JU" },
+          { "cry", "Y3J5" },
+          { "c's", "Yydz" },
+          { "cub", "Y3Vi" },
+          { "cud", "Y3Vk" },
+          { "cue", "Y3Vl" },
+          { "cup", "Y3Vw" },
+          { "cur", "Y3Vy" },
+          { "cut", "Y3V0" },
+          { "dab", "ZGFi" },
+          { "dad", "ZGFk" },
+          { "dam", "ZGFt" },
+          { "Dan", "RGFu" },
+          { "Dar", "RGFy" },
+          { "day", "ZGF5" },
+          { "Dec", "RGVj" },
+          { "Dee", "RGVl" },
+          { "Del", "RGVs" },
+          { "den", "ZGVu" },
+          { "Des", "RGVz" },
+          { "dew", "ZGV3" },
+          { "dey", "ZGV5" },
+          { "did", "ZGlk" },
+          { "die", "ZGll" },
+          { "dig", "ZGln" },
+          { "dim", "ZGlt" },
+          { "din", "ZGlu" },
+          { "dip", "ZGlw" },
+          { "Dis", "RGlz" },
+          { "DNA", "RE5B" },
+          { "DOD", "RE9E" },
+          { "doe", "ZG9l" },
+          { "dog", "ZG9n" },
+          { "don", "ZG9u" },
+          { "dot", "ZG90" },
+          { "Dow", "RG93" },
+          { "dry", "ZHJ5" },
+          { "d's", "ZCdz" },
+          { "dub", "ZHVi" },
+          { "dud", "ZHVk" },
+          { "due", "ZHVl" },
+          { "dug", "ZHVn" },
+          { "dun", "ZHVu" },
+          { "dye", "ZHll" },
+          { "ear", "ZWFy" },
+          { "eat", "ZWF0" },
+          { "ebb", "ZWJi" },
+          { "EDT", "RURU" },
+          { "eel", "ZWVs" },
+          { "eft", "ZWZ0" },
+          { "e.g", "ZS5n" },
+          { "egg", "ZWdn" },
+          { "ego", "ZWdv" },
+          { "eke", "ZWtl" },
+          { "Eli", "RWxp" },
+          { "elk", "ZWxr" },
+          { "ell", "ZWxs" },
+          { "elm", "ZWxt" },
+          { "Ely", "RWx5" },
+          { "end", "ZW5k" },
+          { "Eng", "RW5n" },
+          { "EPA", "RVBB" },
+          { "era", "ZXJh" },
+          { "ere", "ZXJl" },
+          { "erg", "ZXJn" },
+          { "err", "ZXJy" },
+          { "e's", "ZSdz" },
+          { "EST", "RVNU" },
+          { "eta", "ZXRh" },
+          { "etc", "ZXRj" },
+          { "Eva", "RXZh" },
+          { "eve", "ZXZl" },
+          { "ewe", "ZXdl" },
+          { "eye", "ZXll" },
+          { "FAA", "RkFB" },
+          { "fad", "ZmFk" },
+          { "fag", "ZmFn" },
+          { "fan", "ZmFu" },
+          { "far", "ZmFy" },
+          { "fat", "ZmF0" },
+          { "fay", "ZmF5" },
+          { "FBI", "RkJJ" },
+          { "FCC", "RkND" },
+          { "FDA", "RkRB" },
+          { "Feb", "RmVi" },
+          { "fed", "ZmVk" },
+          { "fee", "ZmVl" },
+          { "few", "ZmV3" },
+          { "fib", "Zmli" },
+          { "fig", "Zmln" },
+          { "fin", "Zmlu" },
+          { "fir", "Zmly" },
+          { "fit", "Zml0" },
+          { "fix", "Zml4" },
+          { "Flo", "Rmxv" },
+          { "flu", "Zmx1" },
+          { "fly", "Zmx5" },
+          { "FMC", "Rk1D" },
+          { "fob", "Zm9i" },
+          { "foe", "Zm9l" },
+          { "fog", "Zm9n" },
+          { "fop", "Zm9w" },
+          { "for", "Zm9y" },
+          { "fox", "Zm94" },
+          { "FPC", "RlBD" },
+          { "fro", "ZnJv" },
+          { "fry", "ZnJ5" },
+          { "f's", "Zidz" },
+          { "FTC", "RlRD" },
+          { "fum", "ZnVt" },
+          { "fun", "ZnVu" },
+          { "fur", "ZnVy" },
+          { "gab", "Z2Fi" },
+          { "gad", "Z2Fk" },
+          { "gag", "Z2Fn" },
+          { "gal", "Z2Fs" },
+          { "gam", "Z2Ft" },
+          { "GAO", "R0FP" },
+          { "gap", "Z2Fw" },
+          { "gar", "Z2Fy" },
+          { "gas", "Z2Fz" },
+          { "gay", "Z2F5" },
+          { "gee", "Z2Vl" },
+          { "gel", "Z2Vs" },
+          { "gem", "Z2Vt" },
+          { "get", "Z2V0" },
+          { "gig", "Z2ln" },
+          { "Gil", "R2ls" },
+          { "gin", "Z2lu" },
+          { "GMT", "R01U" },
+          { "GNP", "R05Q" },
+          { "gnu", "Z251" },
+          { "Goa", "R29h" },
+          { "gob", "Z29i" },
+          { "god", "Z29k" },
+          { "gog", "Z29n" },
+          { "GOP", "R09Q" },
+          { "got", "Z290" },
+          { "GPO", "R1BP" },
+          { "g's", "Zydz" },
+          { "GSA", "R1NB" },
+          { "gum", "Z3Vt" },
+          { "gun", "Z3Vu" },
+          { "Gus", "R3Vz" },
+          { "gut", "Z3V0" },
+          { "guy", "Z3V5" },
+          { "gym", "Z3lt" },
+          { "gyp", "Z3lw" },
+          { "had", "aGFk" },
+          { "Hal", "SGFs" },
+          { "ham", "aGFt" },
+          { "Han", "SGFu" },
+          { "hap", "aGFw" },
+          { "hat", "aGF0" },
+          { "haw", "aGF3" },
+          { "hay", "aGF5" },
+          { "hem", "aGVt" },
+          { "hen", "aGVu" },
+          { "her", "aGVy" },
+          { "hew", "aGV3" },
+          { "hex", "aGV4" },
+          { "hey", "aGV5" },
+          { "hid", "aGlk" },
+          { "him", "aGlt" },
+          { "hip", "aGlw" },
+          { "his", "aGlz" },
+          { "hit", "aGl0" },
+          { "hob", "aG9i" },
+          { "hoc", "aG9j" },
+          { "hoe", "aG9l" },
+          { "hog", "aG9n" },
+          { "hoi", "aG9p" },
+          { "Hom", "SG9t" },
+          { "hop", "aG9w" },
+          { "hot", "aG90" },
+          { "how", "aG93" },
+          { "hoy", "aG95" },
+          { "h's", "aCdz" },
+          { "hub", "aHVi" },
+          { "hue", "aHVl" },
+          { "hug", "aHVn" },
+          { "huh", "aHVo" },
+          { "hum", "aHVt" },
+          { "Hun", "SHVu" },
+          { "hut", "aHV0" },
+          { "Ian", "SWFu" },
+          { "IBM", "SUJN" },
+          { "Ibn", "SWJu" },
+          { "ICC", "SUND" },
+          { "ice", "aWNl" },
+          { "icy", "aWN5" },
+          { "I'd", "SSdk" },
+          { "Ida", "SWRh" },
+          { "i.e", "aS5l" },
+          { "iii", "aWlp" },
+          { "Ike", "SWtl" },
+          { "ill", "aWxs" },
+          { "I'm", "SSdt" },
+          { "imp", "aW1w" },
+          { "Inc", "SW5j" },
+          { "ink", "aW5r" },
+          { "inn", "aW5u" },
+          { "ion", "aW9u" },
+          { "Ira", "SXJh" },
+          { "ire", "aXJl" },
+          { "irk", "aXJr" },
+          { "IRS", "SVJT" },
+          { "i's", "aSdz" },
+          { "Ito", "SXRv" },
+          { "ITT", "SVRU" },
+          { "ivy", "aXZ5" },
+          { "jab", "amFi" },
+          { "jag", "amFn" },
+          { "jam", "amFt" },
+          { "Jan", "SmFu" },
+          { "jar", "amFy" },
+          { "jaw", "amF3" },
+          { "jay", "amF5" },
+          { "Jed", "SmVk" },
+          { "jet", "amV0" },
+          { "Jew", "SmV3" },
+          { "jig", "amln" },
+          { "Jim", "Smlt" },
+          { "job", "am9i" },
+          { "Joe", "Sm9l" },
+          { "jog", "am9n" },
+          { "Jon", "Sm9u" },
+          { "jot", "am90" },
+          { "joy", "am95" },
+          { "j's", "aidz" },
+          { "jug", "anVn" },
+          { "jut", "anV0" },
+          { "Kay", "S2F5" },
+          { "keg", "a2Vn" },
+          { "ken", "a2Vu" },
+          { "key", "a2V5" },
+          { "kid", "a2lk" },
+          { "Kim", "S2lt" },
+          { "kin", "a2lu" },
+          { "kit", "a2l0" },
+          { "k's", "aydz" },
+          { "lab", "bGFi" },
+          { "lac", "bGFj" },
+          { "lad", "bGFk" },
+          { "lag", "bGFn" },
+          { "lam", "bGFt" },
+          { "Lao", "TGFv" },
+          { "lap", "bGFw" },
+          { "law", "bGF3" },
+          { "lax", "bGF4" },
+          { "lay", "bGF5" },
+          { "lea", "bGVh" },
+          { "led", "bGVk" },
+          { "lee", "bGVl" },
+          { "leg", "bGVn" },
+          { "Len", "TGVu" },
+          { "Leo", "TGVv" },
+          { "let", "bGV0" },
+          { "Lev", "TGV2" },
+          { "Lew", "TGV3" },
+          { "lew", "bGV3" },
+          { "lid", "bGlk" },
+          { "lie", "bGll" },
+          { "lim", "bGlt" },
+          { "Lin", "TGlu" },
+          { "lip", "bGlw" },
+          { "lit", "bGl0" },
+          { "Liz", "TGl6" },
+          { "lob", "bG9i" },
+          { "log", "bG9n" },
+          { "lop", "bG9w" },
+          { "Los", "TG9z" },
+          { "lot", "bG90" },
+          { "Lou", "TG91" },
+          { "low", "bG93" },
+          { "loy", "bG95" },
+          { "l's", "bCdz" },
+          { "LSI", "TFNJ" },
+          { "Ltd", "THRk" },
+          { "LTV", "TFRW" },
+          { "lug", "bHVn" },
+          { "lux", "bHV4" },
+          { "lye", "bHll" },
+          { "Mac", "TWFj" },
+          { "mad", "bWFk" },
+          { "Mae", "TWFl" },
+          { "man", "bWFu" },
+          { "Mao", "TWFv" },
+          { "map", "bWFw" },
+          { "mar", "bWFy" },
+          { "mat", "bWF0" },
+          { "maw", "bWF3" },
+          { "Max", "TWF4" },
+          { "max", "bWF4" },
+          { "may", "bWF5" },
+          { "MBA", "TUJB" },
+          { "Meg", "TWVn" },
+          { "Mel", "TWVs" },
+          { "men", "bWVu" },
+          { "met", "bWV0" },
+          { "mew", "bWV3" },
+          { "mid", "bWlk" },
+          { "mig", "bWln" },
+          { "min", "bWlu" },
+          { "MIT", "TUlU" },
+          { "mix", "bWl4" },
+          { "mob", "bW9i" },
+          { "Moe", "TW9l" },
+          { "moo", "bW9v" },
+          { "mop", "bW9w" },
+          { "mot", "bW90" },
+          { "mow", "bW93" },
+          { "MPH", "TVBI" },
+          { "Mrs", "TXJz" },
+          { "m's", "bSdz" },
+          { "mud", "bXVk" },
+          { "mug", "bXVn" },
+          { "mum", "bXVt" },
+          { "nab", "bmFi" },
+          { "nag", "bmFn" },
+          { "Nan", "TmFu" },
+          { "nap", "bmFw" },
+          { "Nat", "TmF0" },
+          { "nay", "bmF5" },
+          { "NBC", "TkJD" },
+          { "NBS", "TkJT" },
+          { "NCO", "TkNP" },
+          { "NCR", "TkNS" },
+          { "Ned", "TmVk" },
+          { "nee", "bmVl" },
+          { "net", "bmV0" },
+          { "new", "bmV3" },
+          { "nib", "bmli" },
+          { "NIH", "TklI" },
+          { "nil", "bmls" },
+          { "nip", "bmlw" },
+          { "nit", "bml0" },
+          { "NNE", "Tk5F" },
+          { "NNW", "Tk5X" },
+          { "nob", "bm9i" },
+          { "nod", "bm9k" },
+          { "non", "bm9u" },
+          { "nor", "bm9y" },
+          { "not", "bm90" },
+          { "Nov", "Tm92" },
+          { "now", "bm93" },
+          { "NRC", "TlJD" },
+          { "n's", "bidz" },
+          { "NSF", "TlNG" },
+          { "nun", "bnVu" },
+          { "nut", "bnV0" },
+          { "NYC", "TllD" },
+          { "NYU", "TllV" },
+          { "oaf", "b2Fm" },
+          { "oak", "b2Fr" },
+          { "oar", "b2Fy" },
+          { "oat", "b2F0" },
+          { "Oct", "T2N0" },
+          { "odd", "b2Rk" },
+          { "ode", "b2Rl" },
+          { "off", "b2Zm" },
+          { "oft", "b2Z0" },
+          { "ohm", "b2ht" },
+          { "oil", "b2ls" },
+          { "old", "b2xk" },
+          { "one", "b25l" },
+          { "opt", "b3B0" },
+          { "orb", "b3Ji" },
+          { "ore", "b3Jl" },
+          { "Orr", "T3Jy" },
+          { "o's", "bydz" },
+          { "Ott", "T3R0" },
+          { "our", "b3Vy" },
+          { "out", "b3V0" },
+          { "ova", "b3Zh" },
+          { "owe", "b3dl" },
+          { "owl", "b3ds" },
+          { "own", "b3du" },
+          { "pad", "cGFk" },
+          { "pal", "cGFs" },
+          { "Pam", "UGFt" },
+          { "pan", "cGFu" },
+          { "pap", "cGFw" },
+          { "par", "cGFy" },
+          { "pat", "cGF0" },
+          { "paw", "cGF3" },
+          { "pax", "cGF4" },
+          { "pay", "cGF5" },
+          { "Paz", "UGF6" },
+          { "PBS", "UEJT" },
+          { "PDP", "UERQ" },
+          { "pea", "cGVh" },
+          { "pee", "cGVl" },
+          { "peg", "cGVn" },
+          { "pen", "cGVu" },
+          { "pep", "cGVw" },
+          { "per", "cGVy" },
+          { "pet", "cGV0" },
+          { "pew", "cGV3" },
+          { "PhD", "UGhE" },
+          { "phi", "cGhp" },
+          { "pie", "cGll" },
+          { "pig", "cGln" },
+          { "pin", "cGlu" },
+          { "pip", "cGlw" },
+          { "pit", "cGl0" },
+          { "ply", "cGx5" },
+          { "pod", "cG9k" },
+          { "Poe", "UG9l" },
+          { "poi", "cG9p" },
+          { "pol", "cG9s" },
+          { "pop", "cG9w" },
+          { "pot", "cG90" },
+          { "pow", "cG93" },
+          { "ppm", "cHBt" },
+          { "pro", "cHJv" },
+          { "pry", "cHJ5" },
+          { "p's", "cCdz" },
+          { "psi", "cHNp" },
+          { "PTA", "UFRB" },
+          { "pub", "cHVi" },
+          { "PUC", "UFVD" },
+          { "pug", "cHVn" },
+          { "pun", "cHVu" },
+          { "pup", "cHVw" },
+          { "pus", "cHVz" },
+          { "put", "cHV0" },
+          { "PVC", "UFZD" },
+          { "QED", "UUVE" },
+          { "q's", "cSdz" },
+          { "qua", "cXVh" },
+          { "quo", "cXVv" },
+          { "Rae", "UmFl" },
+          { "rag", "cmFn" },
+          { "raj", "cmFq" },
+          { "ram", "cmFt" },
+          { "ran", "cmFu" },
+          { "rap", "cmFw" },
+          { "rat", "cmF0" },
+          { "raw", "cmF3" },
+          { "ray", "cmF5" },
+          { "RCA", "UkNB" },
+          { "R&D", "UiZE" },
+          { "reb", "cmVi" },
+          { "red", "cmVk" },
+          { "rep", "cmVw" },
+          { "ret", "cmV0" },
+          { "rev", "cmV2" },
+          { "Rex", "UmV4" },
+          { "rho", "cmhv" },
+          { "rib", "cmli" },
+          { "rid", "cmlk" },
+          { "rig", "cmln" },
+          { "rim", "cmlt" },
+          { "Rio", "Umlv" },
+          { "rip", "cmlw" },
+          { "RNA", "Uk5B" },
+          { "rob", "cm9i" },
+          { "rod", "cm9k" },
+          { "roe", "cm9l" },
+          { "Ron", "Um9u" },
+          { "rot", "cm90" },
+          { "row", "cm93" },
+          { "Roy", "Um95" },
+          { "RPM", "UlBN" },
+          { "r's", "cidz" },
+          { "rub", "cnVi" },
+          { "rue", "cnVl" },
+          { "rug", "cnVn" },
+          { "rum", "cnVt" },
+          { "run", "cnVu" },
+          { "rut", "cnV0" },
+          { "rye", "cnll" },
+          { "sac", "c2Fj" },
+          { "sad", "c2Fk" },
+          { "sag", "c2Fn" },
+          { "Sal", "U2Fs" },
+          { "Sam", "U2Ft" },
+          { "San", "U2Fu" },
+          { "Sao", "U2Fv" },
+          { "sap", "c2Fw" },
+          { "sat", "c2F0" },
+          { "saw", "c2F3" },
+          { "sax", "c2F4" },
+          { "say", "c2F5" },
+          { "Sci", "U2Np" },
+          { "SCM", "U0NN" },
+          { "sea", "c2Vh" },
+          { "sec", "c2Vj" },
+          { "see", "c2Vl" },
+          { "sen", "c2Vu" },
+          { "seq", "c2Vx" },
+          { "set", "c2V0" },
+          { "sew", "c2V3" },
+          { "sex", "c2V4" },
+          { "she", "c2hl" },
+          { "Shu", "U2h1" },
+          { "shy", "c2h5" },
+          { "sib", "c2li" },
+          { "sic", "c2lj" },
+          { "sin", "c2lu" },
+          { "sip", "c2lw" },
+          { "sir", "c2ly" },
+          { "sis", "c2lz" },
+          { "sit", "c2l0" },
+          { "six", "c2l4" },
+          { "ski", "c2tp" },
+          { "sky", "c2t5" },
+          { "sly", "c2x5" },
+          { "sob", "c29i" },
+          { "Soc", "U29j" },
+          { "sod", "c29k" },
+          { "Sol", "U29s" },
+          { "son", "c29u" },
+          { "sop", "c29w" },
+          { "sou", "c291" },
+          { "sow", "c293" },
+          { "soy", "c295" },
+          { "spa", "c3Bh" },
+          { "spy", "c3B5" },
+          { "Sri", "U3Jp" },
+          { "s's", "cydz" },
+          { "SSE", "U1NF" },
+          { "SST", "U1NU" },
+          { "SSW", "U1NX" },
+          { "Stu", "U3R1" },
+          { "sub", "c3Vi" },
+          { "sud", "c3Vk" },
+          { "sue", "c3Vl" },
+          { "sum", "c3Vt" },
+          { "sun", "c3Vu" },
+          { "sup", "c3Vw" },
+          { "Sus", "U3Vz" },
+          { "tab", "dGFi" },
+          { "tad", "dGFk" },
+          { "tag", "dGFn" },
+          { "tam", "dGFt" },
+          { "tan", "dGFu" },
+          { "tao", "dGFv" },
+          { "tap", "dGFw" },
+          { "tar", "dGFy" },
+          { "tat", "dGF0" },
+          { "tau", "dGF1" },
+          { "tax", "dGF4" },
+          { "tea", "dGVh" },
+          { "Ted", "VGVk" },
+          { "ted", "dGVk" },
+          { "tee", "dGVl" },
+          { "Tel", "VGVs" },
+          { "ten", "dGVu" },
+          { "the", "dGhl" },
+          { "thy", "dGh5" },
+          { "tic", "dGlj" },
+          { "tid", "dGlk" },
+          { "tie", "dGll" },
+          { "til", "dGls" },
+          { "Tim", "VGlt" },
+          { "tin", "dGlu" },
+          { "tip", "dGlw" },
+          { "tit", "dGl0" },
+          { "TNT", "VE5U" },
+          { "toe", "dG9l" },
+          { "tog", "dG9n" },
+          { "Tom", "VG9t" },
+          { "ton", "dG9u" },
+          { "too", "dG9v" },
+          { "top", "dG9w" },
+          { "tor", "dG9y" },
+          { "tot", "dG90" },
+          { "tow", "dG93" },
+          { "toy", "dG95" },
+          { "TRW", "VFJX" },
+          { "try", "dHJ5" },
+          { "t's", "dCdz" },
+          { "TTL", "VFRM" },
+          { "TTY", "VFRZ" },
+          { "tub", "dHVi" },
+          { "tug", "dHVn" },
+          { "tum", "dHVt" },
+          { "tun", "dHVu" },
+          { "TVA", "VFZB" },
+          { "TWA", "VFdB" },
+          { "two", "dHdv" },
+          { "TWX", "VFdY" },
+          { "ugh", "dWdo" },
+          { "UHF", "VUhG" },
+          { "Uri", "VXJp" },
+          { "urn", "dXJu" },
+          { "U.S", "VS5T" },
+          { "u's", "dSdz" },
+          { "USA", "VVNB" },
+          { "USC", "VVND" },
+          { "use", "dXNl" },
+          { "USN", "VVNO" },
+          { "van", "dmFu" },
+          { "vat", "dmF0" },
+          { "vee", "dmVl" },
+          { "vet", "dmV0" },
+          { "vex", "dmV4" },
+          { "VHF", "VkhG" },
+          { "via", "dmlh" },
+          { "vie", "dmll" },
+          { "vii", "dmlp" },
+          { "vis", "dmlz" },
+          { "viz", "dml6" },
+          { "von", "dm9u" },
+          { "vow", "dm93" },
+          { "v's", "didz" },
+          { "WAC", "V0FD" },
+          { "wad", "d2Fk" },
+          { "wag", "d2Fn" },
+          { "wah", "d2Fo" },
+          { "wan", "d2Fu" },
+          { "war", "d2Fy" },
+          { "was", "d2Fz" },
+          { "wax", "d2F4" },
+          { "way", "d2F5" },
+          { "web", "d2Vi" },
+          { "wed", "d2Vk" },
+          { "wee", "d2Vl" },
+          { "Wei", "V2Vp" },
+          { "wet", "d2V0" },
+          { "who", "d2hv" },
+          { "why", "d2h5" },
+          { "wig", "d2ln" },
+          { "win", "d2lu" },
+          { "wit", "d2l0" },
+          { "woe", "d29l" },
+          { "wok", "d29r" },
+          { "won", "d29u" },
+          { "woo", "d29v" },
+          { "wop", "d29w" },
+          { "wow", "d293" },
+          { "wry", "d3J5" },
+          { "w's", "dydz" },
+          { "x's", "eCdz" },
+          { "yah", "eWFo" },
+          { "yak", "eWFr" },
+          { "yam", "eWFt" },
+          { "yap", "eWFw" },
+          { "yaw", "eWF3" },
+          { "yea", "eWVh" },
+          { "yen", "eWVu" },
+          { "yet", "eWV0" },
+          { "yin", "eWlu" },
+          { "yip", "eWlw" },
+          { "yon", "eW9u" },
+          { "you", "eW91" },
+          { "yow", "eW93" },
+          { "y's", "eSdz" },
+          { "yuh", "eXVo" },
+          { "zag", "emFn" },
+          { "Zan", "WmFu" },
+          { "zap", "emFw" },
+          { "Zen", "WmVu" },
+          { "zig", "emln" },
+          { "zip", "emlw" },
+          { "Zoe", "Wm9l" },
+          { "zoo", "em9v" },
+          { "z's", "eidz" },
+          /* the false rumors file */
+          { "\"So when I die, the first thing I will see in heaven is a score list?\"", 
+            "IlNvIHdoZW4gSSBkaWUsIHRoZSBmaXJzdCB0aGluZyBJIHdpbGwgc2VlIGluIGhlYXZlbiBpcyBhIHNjb3JlIGxpc3Q/Ig==" },
+          { "1st Law of Hacking: leaving is much more difficult than entering.", 
+            "MXN0IExhdyBvZiBIYWNraW5nOiBsZWF2aW5nIGlzIG11Y2ggbW9yZSBkaWZmaWN1bHQgdGhhbiBlbnRlcmluZy4=" },
+          { "2nd Law of Hacking: first in, first out.", 
+            "Mm5kIExhdyBvZiBIYWNraW5nOiBmaXJzdCBpbiwgZmlyc3Qgb3V0Lg==" },
+          { "3rd Law of Hacking: the last blow counts most.", 
+            "M3JkIExhdyBvZiBIYWNraW5nOiB0aGUgbGFzdCBibG93IGNvdW50cyBtb3N0Lg==" },
+          { "4th Law of Hacking: you will find the exit at the entrance.", 
+            "NHRoIExhdyBvZiBIYWNraW5nOiB5b3Ugd2lsbCBmaW5kIHRoZSBleGl0IGF0IHRoZSBlbnRyYW5jZS4=" },
+          { "A chameleon imitating a mail daemon often delivers scrolls of fire.", 
+            "QSBjaGFtZWxlb24gaW1pdGF0aW5nIGEgbWFpbCBkYWVtb24gb2Z0ZW4gZGVsaXZlcnMgc2Nyb2xscyBvZiBmaXJlLg==" },
+          { "A cockatrice corpse is guaranteed to be untainted!", 
+            "QSBjb2NrYXRyaWNlIGNvcnBzZSBpcyBndWFyYW50ZWVkIHRvIGJlIHVudGFpbnRlZCE=" },
+          { "A dead cockatrice is just a dead lizard.", 
+            "QSBkZWFkIGNvY2thdHJpY2UgaXMganVzdCBhIGRlYWQgbGl6YXJkLg==" },
+          { "A dragon is just a snake that ate a scroll of fire.", 
+            "QSBkcmFnb24gaXMganVzdCBhIHNuYWtlIHRoYXQgYXRlIGEgc2Nyb2xsIG9mIGZpcmUu" },
+          { "A fading corridor enlightens your insight.", 
+            "QSBmYWRpbmcgY29ycmlkb3IgZW5saWdodGVucyB5b3VyIGluc2lnaHQu" },
+          { "A glowing potion is too hot to drink.", 
+            "QSBnbG93aW5nIHBvdGlvbiBpcyB0b28gaG90IHRvIGRyaW5rLg==" },
+          { "A good amulet may protect you against guards.", 
+            "QSBnb29kIGFtdWxldCBtYXkgcHJvdGVjdCB5b3UgYWdhaW5zdCBndWFyZHMu" },
+          { "A lizard corpse is a good thing to turn undead.", 
+            "QSBsaXphcmQgY29ycHNlIGlzIGEgZ29vZCB0aGluZyB0byB0dXJuIHVuZGVhZC4=" },
+          { "A long worm can be defined recursively. So how should you attack it?", 
+            "QSBsb25nIHdvcm0gY2FuIGJlIGRlZmluZWQgcmVjdXJzaXZlbHkuIFNvIGhvdyBzaG91bGQgeW91IGF0dGFjayBpdD8=" },
+          { "A monstrous mind is a toy forever.", 
+            "QSBtb25zdHJvdXMgbWluZCBpcyBhIHRveSBmb3JldmVyLg==" },
+          { "A nymph will be very pleased if you call her by her real name: Lorelei.", 
+            "QSBueW1waCB3aWxsIGJlIHZlcnkgcGxlYXNlZCBpZiB5b3UgY2FsbCBoZXIgYnkgaGVyIHJlYWwgbmFtZTogTG9yZWxlaS4=" },
+          { "A ring of dungeon master control is a great find.", 
+            "QSByaW5nIG9mIGR1bmdlb24gbWFzdGVyIGNvbnRyb2wgaXMgYSBncmVhdCBmaW5kLg==" },
+          { "A ring of extra ring finger is useless if not enchanted.", 
+            "QSByaW5nIG9mIGV4dHJhIHJpbmcgZmluZ2VyIGlzIHVzZWxlc3MgaWYgbm90IGVuY2hhbnRlZC4=" },
+          { "A rope may form a trail in a maze.", 
+            "QSByb3BlIG1heSBmb3JtIGEgdHJhaWwgaW4gYSBtYXplLg==" },
+          { "A staff may recharge if you drop it for awhile.", 
+            "QSBzdGFmZiBtYXkgcmVjaGFyZ2UgaWYgeW91IGRyb3AgaXQgZm9yIGF3aGlsZS4=" },
+          { "A visit to the Zoo is very educational; you meet interesting animals.", 
+            "QSB2aXNpdCB0byB0aGUgWm9vIGlzIHZlcnkgZWR1Y2F0aW9uYWw7IHlvdSBtZWV0IGludGVyZXN0aW5nIGFuaW1hbHMu" },
+          { "A wand of deaf is a more dangerous weapon than a wand of sheep.", 
+            "QSB3YW5kIG9mIGRlYWYgaXMgYSBtb3JlIGRhbmdlcm91cyB3ZWFwb24gdGhhbiBhIHdhbmQgb2Ygc2hlZXAu" },
+          { "A wand of vibration might bring the whole cave crashing about your ears.", 
+            "QSB3YW5kIG9mIHZpYnJhdGlvbiBtaWdodCBicmluZyB0aGUgd2hvbGUgY2F2ZSBjcmFzaGluZyBhYm91dCB5b3VyIGVhcnMu" },
+          { "A winner never quits. A quitter never wins.", 
+            "QSB3aW5uZXIgbmV2ZXIgcXVpdHMuIEEgcXVpdHRlciBuZXZlciB3aW5zLg==" },
+          { "A wish? Okay, make me a fortune cookie!", 
+            "QSB3aXNoPyBPa2F5LCBtYWtlIG1lIGEgZm9ydHVuZSBjb29raWUh" },
+          { "Afraid of mimics? Try to wear a ring of true seeing.", 
+            "QWZyYWlkIG9mIG1pbWljcz8gVHJ5IHRvIHdlYXIgYSByaW5nIG9mIHRydWUgc2VlaW5nLg==" },
+          { "All monsters are created evil, but some are more evil than others.", 
+            "QWxsIG1vbnN0ZXJzIGFyZSBjcmVhdGVkIGV2aWwsIGJ1dCBzb21lIGFyZSBtb3JlIGV2aWwgdGhhbiBvdGhlcnMu" },
+          { "Always attack a floating eye from behind!", 
+            "QWx3YXlzIGF0dGFjayBhIGZsb2F0aW5nIGV5ZSBmcm9tIGJlaGluZCE=" },
+          { "An elven cloak is always the height of fashion.", 
+            "QW4gZWx2ZW4gY2xvYWsgaXMgYWx3YXlzIHRoZSBoZWlnaHQgb2YgZmFzaGlvbi4=" },
+          { "Any small object that is accidentally dropped will hide under a larger object.", 
+            "QW55IHNtYWxsIG9iamVjdCB0aGF0IGlzIGFjY2lkZW50YWxseSBkcm9wcGVkIHdpbGwgaGlkZSB1bmRlciBhIGxhcmdlciBvYmplY3Qu" },
+          { "Balrogs do not appear above level 20.", 
+            "QmFscm9ncyBkbyBub3QgYXBwZWFyIGFib3ZlIGxldmVsIDIwLg==" },
+          { "Banana peels work especially well against Keystone Kops.", 
+            "QmFuYW5hIHBlZWxzIHdvcmsgZXNwZWNpYWxseSB3ZWxsIGFnYWluc3QgS2V5c3RvbmUgS29wcy4=" },
+          { "Be careful when eating bananas. Monsters might slip on the peels.", 
+            "QmUgY2FyZWZ1bCB3aGVuIGVhdGluZyBiYW5hbmFzLiBNb25zdGVycyBtaWdodCBzbGlwIG9uIHRoZSBwZWVscy4=" },
+          { "Better leave the dungeon; otherwise you might get hurt badly.", 
+            "QmV0dGVyIGxlYXZlIHRoZSBkdW5nZW9uOyBvdGhlcndpc2UgeW91IG1pZ2h0IGdldCBodXJ0IGJhZGx5Lg==" },
+          { "Beware of the potion of nitroglycerin -- it's not for the weak of heart.", 
+            "QmV3YXJlIG9mIHRoZSBwb3Rpb24gb2Ygbml0cm9nbHljZXJpbiAtLSBpdCdzIG5vdCBmb3IgdGhlIHdlYWsgb2YgaGVhcnQu" },
+          { "Beware: there's always a chance that your wand explodes as you try to zap it!", 
+            "QmV3YXJlOiB0aGVyZSdzIGFsd2F5cyBhIGNoYW5jZSB0aGF0IHlvdXIgd2FuZCBleHBsb2RlcyBhcyB5b3UgdHJ5IHRvIHphcCBpdCE=" },
+          { "Beyond the 23rd level lies a happy retirement in a room of your own.", 
+            "QmV5b25kIHRoZSAyM3JkIGxldmVsIGxpZXMgYSBoYXBweSByZXRpcmVtZW50IGluIGEgcm9vbSBvZiB5b3VyIG93bi4=" },
+          { "Changing your suit without dropping your sword? You must be kidding!", 
+            "Q2hhbmdpbmcgeW91ciBzdWl0IHdpdGhvdXQgZHJvcHBpbmcgeW91ciBzd29yZD8gWW91IG11c3QgYmUga2lkZGluZyE=" },
+          { "Cockatrices might turn themselves to stone faced with a mirror.", 
+            "Q29ja2F0cmljZXMgbWlnaHQgdHVybiB0aGVtc2VsdmVzIHRvIHN0b25lIGZhY2VkIHdpdGggYSBtaXJyb3Iu" },
+          { "Consumption of home-made food is strictly forbidden in this dungeon.", 
+            "Q29uc3VtcHRpb24gb2YgaG9tZS1tYWRlIGZvb2QgaXMgc3RyaWN0bHkgZm9yYmlkZGVuIGluIHRoaXMgZHVuZ2Vvbi4=" },
+          { "Dark room? Your chance to develop your photographs!", 
+            "RGFyayByb29tPyBZb3VyIGNoYW5jZSB0byBkZXZlbG9wIHlvdXIgcGhvdG9ncmFwaHMh" },
+          { "Dark rooms are not *completely* dark: just wait and let your eyes adjust...", 
+            "RGFyayByb29tcyBhcmUgbm90ICpjb21wbGV0ZWx5KiBkYXJrOiBqdXN0IHdhaXQgYW5kIGxldCB5b3VyIGV5ZXMgYWRqdXN0Li4u" },
+          { "David London sez, \"Hey guys, *WIELD* a lizard corpse against a cockatrice!\"", 
+            "RGF2aWQgTG9uZG9uIHNleiwgIkhleSBndXlzLCAqV0lFTEQqIGEgbGl6YXJkIGNvcnBzZSBhZ2FpbnN0IGEgY29ja2F0cmljZSEi" },
+          { "Death is just life's way of telling you you've been fired.", 
+            "RGVhdGggaXMganVzdCBsaWZlJ3Mgd2F5IG9mIHRlbGxpbmcgeW91IHlvdSd2ZSBiZWVuIGZpcmVkLg==" },
+          { "Demi-gods don't need any help from the gods.", 
+            "RGVtaS1nb2RzIGRvbid0IG5lZWQgYW55IGhlbHAgZnJvbSB0aGUgZ29kcy4=" },
+          { "Demons *HATE* Priests and Priestesses.", 
+            "RGVtb25zICpIQVRFKiBQcmllc3RzIGFuZCBQcmllc3Rlc3Nlcy4=" },
+          { "Didn't you forget to pay?", 
+            "RGlkbid0IHlvdSBmb3JnZXQgdG8gcGF5Pw==" },
+          { "Didn't your mother tell you not to eat food off the floor?", 
+            "RGlkbid0IHlvdXIgbW90aGVyIHRlbGwgeW91IG5vdCB0byBlYXQgZm9vZCBvZmYgdGhlIGZsb29yPw==" },
+          { "Direct a direct hit on your direct opponent, directing in the right direction.", 
+            "RGlyZWN0IGEgZGlyZWN0IGhpdCBvbiB5b3VyIGRpcmVjdCBvcHBvbmVudCwgZGlyZWN0aW5nIGluIHRoZSByaWdodCBkaXJlY3Rpb24u" },
+          { "Do you want to make more money? Sure, we all do! Join the Fort Ludios guard!", 
+            "RG8geW91IHdhbnQgdG8gbWFrZSBtb3JlIG1vbmV5PyBTdXJlLCB3ZSBhbGwgZG8hIEpvaW4gdGhlIEZvcnQgTHVkaW9zIGd1YXJkIQ==" },
+          { "Don't eat too much: you might start hiccoughing!", 
+            "RG9uJ3QgZWF0IHRvbyBtdWNoOiB5b3UgbWlnaHQgc3RhcnQgaGljY291Z2hpbmch" },
+          { "Don't play hack at your work; your boss might hit you!", 
+            "RG9uJ3QgcGxheSBoYWNrIGF0IHlvdXIgd29yazsgeW91ciBib3NzIG1pZ2h0IGhpdCB5b3Uh" },
+          { "Don't tell a soul you found a secret door, otherwise it isn't a secret anymore.", 
+            "RG9uJ3QgdGVsbCBhIHNvdWwgeW91IGZvdW5kIGEgc2VjcmV0IGRvb3IsIG90aGVyd2lzZSBpdCBpc24ndCBhIHNlY3JldCBhbnltb3JlLg==" },
+          { "Drinking potions of booze may land you in jail if you are under 21.", 
+            "RHJpbmtpbmcgcG90aW9ucyBvZiBib296ZSBtYXkgbGFuZCB5b3UgaW4gamFpbCBpZiB5b3UgYXJlIHVuZGVyIDIxLg==" },
+          { "Drop your vanity and get rid of your jewels! Pickpockets about!", 
+            "RHJvcCB5b3VyIHZhbml0eSBhbmQgZ2V0IHJpZCBvZiB5b3VyIGpld2VscyEgUGlja3BvY2tldHMgYWJvdXQh" },
+          { "Eat 10 cloves of garlic and keep all humans at a two-square distance.", 
+            "RWF0IDEwIGNsb3ZlcyBvZiBnYXJsaWMgYW5kIGtlZXAgYWxsIGh1bWFucyBhdCBhIHR3by1zcXVhcmUgZGlzdGFuY2Uu" },
+          { "Eels hide under mud. Use a unicorn to clear the water and make them visible.", 
+            "RWVscyBoaWRlIHVuZGVyIG11ZC4gVXNlIGEgdW5pY29ybiB0byBjbGVhciB0aGUgd2F0ZXIgYW5kIG1ha2UgdGhlbSB2aXNpYmxlLg==" },
+          { "Engrave your wishes with a wand of wishing.", 
+            "RW5ncmF2ZSB5b3VyIHdpc2hlcyB3aXRoIGEgd2FuZCBvZiB3aXNoaW5nLg==" },
+          { "Eventually you will come to admire the swift elegance of a retreating nymph.", 
+            "RXZlbnR1YWxseSB5b3Ugd2lsbCBjb21lIHRvIGFkbWlyZSB0aGUgc3dpZnQgZWxlZ2FuY2Ugb2YgYSByZXRyZWF0aW5nIG55bXBoLg==" },
+          { "Ever heard hissing outside? I *knew* you hadn't!", 
+            "RXZlciBoZWFyZCBoaXNzaW5nIG91dHNpZGU/IEkgKmtuZXcqIHlvdSBoYWRuJ3Qh" },
+          { "Ever lifted a dragon corpse?", 
+            "RXZlciBsaWZ0ZWQgYSBkcmFnb24gY29ycHNlPw==" },
+          { "Ever seen a leocrotta dancing the tengu?", 
+            "RXZlciBzZWVuIGEgbGVvY3JvdHRhIGRhbmNpbmcgdGhlIHRlbmd1Pw==" },
+          { "Ever seen your weapon glow plaid?", 
+            "RXZlciBzZWVuIHlvdXIgd2VhcG9uIGdsb3cgcGxhaWQ/" },
+          { "Ever tamed a shopkeeper?", 
+            "RXZlciB0YW1lZCBhIHNob3BrZWVwZXI/" },
+          { "Ever tried digging through a Vault Guard?", 
+            "RXZlciB0cmllZCBkaWdnaW5nIHRocm91Z2ggYSBWYXVsdCBHdWFyZD8=" },
+          { "Ever tried enchanting a rope?", 
+            "RXZlciB0cmllZCBlbmNoYW50aW5nIGEgcm9wZT8=" },
+          { "Floating eyes can't stand Hawaiian shirts.", 
+            "RmxvYXRpbmcgZXllcyBjYW4ndCBzdGFuZCBIYXdhaWlhbiBzaGlydHMu" },
+          { "For any remedy there is a misery.", 
+            "Rm9yIGFueSByZW1lZHkgdGhlcmUgaXMgYSBtaXNlcnku" },
+          { "Giant bats turn into giant vampires.", 
+            "R2lhbnQgYmF0cyB0dXJuIGludG8gZ2lhbnQgdmFtcGlyZXMu" },
+          { "Good day for overcoming obstacles. Try a steeplechase.", 
+            "R29vZCBkYXkgZm9yIG92ZXJjb21pbmcgb2JzdGFjbGVzLiBUcnkgYSBzdGVlcGxlY2hhc2Uu" },
+          { "Half Moon tonight. (At least it's better than no Moon at all.)", 
+            "SGFsZiBNb29uIHRvbmlnaHQuIChBdCBsZWFzdCBpdCdzIGJldHRlciB0aGFuIG5vIE1vb24gYXQgYWxsLik=" },
+          { "Help! I'm being held prisoner in a fortune cookie factory!", 
+            "SGVscCEgSSdtIGJlaW5nIGhlbGQgcHJpc29uZXIgaW4gYSBmb3J0dW5lIGNvb2tpZSBmYWN0b3J5IQ==" },
+          { "Housecats have nine lives, kittens only one.", 
+            "SG91c2VjYXRzIGhhdmUgbmluZSBsaXZlcywga2l0dGVucyBvbmx5IG9uZS4=" },
+          { "How long can you tread water?", 
+            "SG93IGxvbmcgY2FuIHlvdSB0cmVhZCB3YXRlcj8=" },
+          { "Hungry? There is an abundance of food on the next level.", 
+            "SHVuZ3J5PyBUaGVyZSBpcyBhbiBhYnVuZGFuY2Ugb2YgZm9vZCBvbiB0aGUgbmV4dCBsZXZlbC4=" },
+          { "I guess you've never hit a mail daemon with the Amulet of Yendor...", 
+            "SSBndWVzcyB5b3UndmUgbmV2ZXIgaGl0IGEgbWFpbCBkYWVtb24gd2l0aCB0aGUgQW11bGV0IG9mIFllbmRvci4uLg==" },
+          { "If you are the shopkeeper, you can take things for free.", 
+            "SWYgeW91IGFyZSB0aGUgc2hvcGtlZXBlciwgeW91IGNhbiB0YWtlIHRoaW5ncyBmb3IgZnJlZS4=" },
+          { "If you can't learn to do it well, learn to enjoy doing it badly.", 
+            "SWYgeW91IGNhbid0IGxlYXJuIHRvIGRvIGl0IHdlbGwsIGxlYXJuIHRvIGVuam95IGRvaW5nIGl0IGJhZGx5Lg==" },
+          { "If you thought the Wizard was bad, just wait till you meet the Warlord!", 
+            "SWYgeW91IHRob3VnaHQgdGhlIFdpemFyZCB3YXMgYmFkLCBqdXN0IHdhaXQgdGlsbCB5b3UgbWVldCB0aGUgV2FybG9yZCE=" },
+          { "If you turn blind, don't expect your dog to be turned into a seeing-eye dog.", 
+            "SWYgeW91IHR1cm4gYmxpbmQsIGRvbid0IGV4cGVjdCB5b3VyIGRvZyB0byBiZSB0dXJuZWQgaW50byBhIHNlZWluZy1leWUgZG9nLg==" },
+          { "If you want to feel great, you must eat something real big.", 
+            "SWYgeW91IHdhbnQgdG8gZmVlbCBncmVhdCwgeW91IG11c3QgZWF0IHNvbWV0aGluZyByZWFsIGJpZy4=" },
+          { "If you want to float, you'd better eat a floating eye.", 
+            "SWYgeW91IHdhbnQgdG8gZmxvYXQsIHlvdSdkIGJldHRlciBlYXQgYSBmbG9hdGluZyBleWUu" },
+          { "If your ghost kills a player, it increases your score.", 
+            "SWYgeW91ciBnaG9zdCBraWxscyBhIHBsYXllciwgaXQgaW5jcmVhc2VzIHlvdXIgc2NvcmUu" },
+          { "Increase mindpower: Tame your own ghost!", 
+            "SW5jcmVhc2UgbWluZHBvd2VyOiBUYW1lIHlvdXIgb3duIGdob3N0IQ==" },
+          { "It furthers one to see the great man.", 
+            "SXQgZnVydGhlcnMgb25lIHRvIHNlZSB0aGUgZ3JlYXQgbWFuLg==" },
+          { "It's easy to overlook a monster in a wood.", 
+            "SXQncyBlYXN5IHRvIG92ZXJsb29rIGEgbW9uc3RlciBpbiBhIHdvb2Qu" },
+          { "Just below any trapdoor there may be another one. Just keep falling!", 
+            "SnVzdCBiZWxvdyBhbnkgdHJhcGRvb3IgdGhlcmUgbWF5IGJlIGFub3RoZXIgb25lLiBKdXN0IGtlZXAgZmFsbGluZyE=" },
+          { "Katanas are very sharp; watch you don't cut yourself.", 
+            "S2F0YW5hcyBhcmUgdmVyeSBzaGFycDsgd2F0Y2ggeW91IGRvbid0IGN1dCB5b3Vyc2VsZi4=" },
+          { "Keep a clear mind: quaff clear potions.", 
+            "S2VlcCBhIGNsZWFyIG1pbmQ6IHF1YWZmIGNsZWFyIHBvdGlvbnMu" },
+          { "Kicking the terminal doesn't hurt the monsters.", 
+            "S2lja2luZyB0aGUgdGVybWluYWwgZG9lc24ndCBodXJ0IHRoZSBtb25zdGVycy4=" },
+          { "Killer bees keep appearing till you kill their queen.", 
+            "S2lsbGVyIGJlZXMga2VlcCBhcHBlYXJpbmcgdGlsbCB5b3Uga2lsbCB0aGVpciBxdWVlbi4=" },
+          { "Killer bunnies can be tamed with carrots only.", 
+            "S2lsbGVyIGJ1bm5pZXMgY2FuIGJlIHRhbWVkIHdpdGggY2Fycm90cyBvbmx5Lg==" },
+          { "Latest news? Put `rec.games.roguelike.nethack' in your .newsrc!", 
+            "TGF0ZXN0IG5ld3M/IFB1dCBgcmVjLmdhbWVzLnJvZ3VlbGlrZS5uZXRoYWNrJyBpbiB5b3VyIC5uZXdzcmMh" },
+          { "Learn how to spell. Play NetHack!", 
+            "TGVhcm4gaG93IHRvIHNwZWxsLiBQbGF5IE5ldEhhY2sh" },
+          { "Leprechauns hide their gold in a secret room.", 
+            "TGVwcmVjaGF1bnMgaGlkZSB0aGVpciBnb2xkIGluIGEgc2VjcmV0IHJvb20u" },
+          { "Let your fingers do the walking on the yulkjhnb keys.", 
+            "TGV0IHlvdXIgZmluZ2VycyBkbyB0aGUgd2Fsa2luZyBvbiB0aGUgeXVsa2pobmIga2V5cy4=" },
+          { "Let's face it: this time you're not going to win.", 
+            "TGV0J3MgZmFjZSBpdDogdGhpcyB0aW1lIHlvdSdyZSBub3QgZ29pbmcgdG8gd2luLg==" },
+          { "Let's have a party, drink a lot of booze.", 
+            "TGV0J3MgaGF2ZSBhIHBhcnR5LCBkcmluayBhIGxvdCBvZiBib296ZS4=" },
+          { "Liquor sellers do not drink; they hate to see you twice.", 
+            "TGlxdW9yIHNlbGxlcnMgZG8gbm90IGRyaW5rOyB0aGV5IGhhdGUgdG8gc2VlIHlvdSB0d2ljZS4=" },
+          { "Lunar eclipse tonight. May as well quit now!", 
+            "THVuYXIgZWNsaXBzZSB0b25pZ2h0LiBNYXkgYXMgd2VsbCBxdWl0IG5vdyE=" },
+          { "Meeting your own ghost decreases your luck considerably!", 
+            "TWVldGluZyB5b3VyIG93biBnaG9zdCBkZWNyZWFzZXMgeW91ciBsdWNrIGNvbnNpZGVyYWJseSE=" },
+          { "Money to invest? Take it to the local branch of the Magic Memory Vault!", 
+            "TW9uZXkgdG8gaW52ZXN0PyBUYWtlIGl0IHRvIHRoZSBsb2NhbCBicmFuY2ggb2YgdGhlIE1hZ2ljIE1lbW9yeSBWYXVsdCE=" },
+          { "Monsters come from nowhere to hit you everywhere.", 
+            "TW9uc3RlcnMgY29tZSBmcm9tIG5vd2hlcmUgdG8gaGl0IHlvdSBldmVyeXdoZXJlLg==" },
+          { "Monsters sleep because you are boring, not because they ever get tired.", 
+            "TW9uc3RlcnMgc2xlZXAgYmVjYXVzZSB5b3UgYXJlIGJvcmluZywgbm90IGJlY2F1c2UgdGhleSBldmVyIGdldCB0aXJlZC4=" },
+          { "Most monsters prefer minced meat. That's why they are hitting you!", 
+            "TW9zdCBtb25zdGVycyBwcmVmZXIgbWluY2VkIG1lYXQuIFRoYXQncyB3aHkgdGhleSBhcmUgaGl0dGluZyB5b3Uh" },
+          { "Most of the bugs in NetHack are on the floor.", 
+            "TW9zdCBvZiB0aGUgYnVncyBpbiBOZXRIYWNrIGFyZSBvbiB0aGUgZmxvb3Iu" },
+          { "Much ado Nothing Happens.", 
+            "TXVjaCBhZG8gTm90aGluZyBIYXBwZW5zLg==" },
+          { "Multi-player NetHack is a myth.", 
+            "TXVsdGktcGxheWVyIE5ldEhhY2sgaXMgYSBteXRoLg==" },
+          { "NetHack is addictive. Too late, you're already hooked.", 
+            "TmV0SGFjayBpcyBhZGRpY3RpdmUuIFRvbyBsYXRlLCB5b3UncmUgYWxyZWFkeSBob29rZWQu" },
+          { "Never ask a shopkeeper for a price list.", 
+            "TmV2ZXIgYXNrIGEgc2hvcGtlZXBlciBmb3IgYSBwcmljZSBsaXN0Lg==" },
+          { "Never burn a tree, unless you like getting whacked with a +5 shovel.", 
+            "TmV2ZXIgYnVybiBhIHRyZWUsIHVubGVzcyB5b3UgbGlrZSBnZXR0aW5nIHdoYWNrZWQgd2l0aCBhICs1IHNob3ZlbC4=" },
+          { "Never eat with glowing hands!", 
+            "TmV2ZXIgZWF0IHdpdGggZ2xvd2luZyBoYW5kcyE=" },
+          { "Never mind the monsters hitting you: they just replace the charwomen.", 
+            "TmV2ZXIgbWluZCB0aGUgbW9uc3RlcnMgaGl0dGluZyB5b3U6IHRoZXkganVzdCByZXBsYWNlIHRoZSBjaGFyd29tZW4u" },
+          { "Never play leapfrog with a unicorn.", 
+            "TmV2ZXIgcGxheSBsZWFwZnJvZyB3aXRoIGEgdW5pY29ybi4=" },
+          { "Never step on a cursed engraving.", 
+            "TmV2ZXIgc3RlcCBvbiBhIGN1cnNlZCBlbmdyYXZpbmcu" },
+          { "Never swim with a camera: there's nothing to take pictures of.", 
+            "TmV2ZXIgc3dpbSB3aXRoIGEgY2FtZXJhOiB0aGVyZSdzIG5vdGhpbmcgdG8gdGFrZSBwaWN0dXJlcyBvZi4=" },
+          { "Never teach your pet rust monster to fetch.", 
+            "TmV2ZXIgdGVhY2ggeW91ciBwZXQgcnVzdCBtb25zdGVyIHRvIGZldGNoLg==" },
+          { "Never trust a random generator in magic fields.", 
+            "TmV2ZXIgdHJ1c3QgYSByYW5kb20gZ2VuZXJhdG9yIGluIG1hZ2ljIGZpZWxkcy4=" },
+          { "Never use a wand of death.", 
+            "TmV2ZXIgdXNlIGEgd2FuZCBvZiBkZWF0aC4=" },
+          { "No level contains two shops. The maze is no level. So...", 
+            "Tm8gbGV2ZWwgY29udGFpbnMgdHdvIHNob3BzLiBUaGUgbWF6ZSBpcyBubyBsZXZlbC4gU28uLi4=" },
+          { "No part of this fortune may be reproduced, stored in a retrieval system, ...", 
+            "Tm8gcGFydCBvZiB0aGlzIGZvcnR1bmUgbWF5IGJlIHJlcHJvZHVjZWQsIHN0b3JlZCBpbiBhIHJldHJpZXZhbCBzeXN0ZW0sIC4uLg==" },
+          { "Not all rumors are as misleading as this one.", 
+            "Tm90IGFsbCBydW1vcnMgYXJlIGFzIG1pc2xlYWRpbmcgYXMgdGhpcyBvbmUu" },
+          { "Nymphs and nurses like beautiful rings.", 
+            "TnltcGhzIGFuZCBudXJzZXMgbGlrZSBiZWF1dGlmdWwgcmluZ3Mu" },
+          { "Nymphs are blondes. Are you a gentleman?", 
+            "TnltcGhzIGFyZSBibG9uZGVzLiBBcmUgeW91IGEgZ2VudGxlbWFuPw==" },
+          { "Offering a unicorn a worthless piece of glass might prove to be fatal!", 
+            "T2ZmZXJpbmcgYSB1bmljb3JuIGEgd29ydGhsZXNzIHBpZWNlIG9mIGdsYXNzIG1pZ2h0IHByb3ZlIHRvIGJlIGZhdGFsIQ==" },
+          { "Old hackers never die: young ones do.", 
+            "T2xkIGhhY2tlcnMgbmV2ZXIgZGllOiB5b3VuZyBvbmVzIGRvLg==" },
+          { "One has to leave shops before closing time.", 
+            "T25lIGhhcyB0byBsZWF2ZSBzaG9wcyBiZWZvcmUgY2xvc2luZyB0aW1lLg==" },
+          { "One homunculus a day keeps the doctor away.", 
+            "T25lIGhvbXVuY3VsdXMgYSBkYXkga2VlcHMgdGhlIGRvY3RvciBhd2F5Lg==" },
+          { "One level further down somebody is getting killed, right now.", 
+            "T25lIGxldmVsIGZ1cnRoZXIgZG93biBzb21lYm9keSBpcyBnZXR0aW5nIGtpbGxlZCwgcmlnaHQgbm93Lg==" },
+          { "Only a wizard can use a magic whistle.", 
+            "T25seSBhIHdpemFyZCBjYW4gdXNlIGEgbWFnaWMgd2hpc3RsZS4=" },
+          { "Only adventurers of evil alignment think of killing their dog.", 
+            "T25seSBhZHZlbnR1cmVycyBvZiBldmlsIGFsaWdubWVudCB0aGluayBvZiBraWxsaW5nIHRoZWlyIGRvZy4=" },
+          { "Only chaotic evils kill sleeping monsters.", 
+            "T25seSBjaGFvdGljIGV2aWxzIGtpbGwgc2xlZXBpbmcgbW9uc3RlcnMu" },
+          { "Only real trappers escape traps.", 
+            "T25seSByZWFsIHRyYXBwZXJzIGVzY2FwZSB0cmFwcy4=" },
+          { "Only real wizards can write scrolls.", 
+            "T25seSByZWFsIHdpemFyZHMgY2FuIHdyaXRlIHNjcm9sbHMu" },
+          { "Operation OVERKILL has started now.", 
+            "T3BlcmF0aW9uIE9WRVJLSUxMIGhhcyBzdGFydGVkIG5vdy4=" },
+          { "PLEASE ignore previous rumor.", 
+            "UExFQVNFIGlnbm9yZSBwcmV2aW91cyBydW1vci4=" },
+          { "Polymorph into an ettin; meet your opponents face to face to face.", 
+            "UG9seW1vcnBoIGludG8gYW4gZXR0aW47IG1lZXQgeW91ciBvcHBvbmVudHMgZmFjZSB0byBmYWNlIHRvIGZhY2Uu" },
+          { "Praying will frighten demons.", 
+            "UHJheWluZyB3aWxsIGZyaWdodGVuIGRlbW9ucy4=" },
+          { "Row (3x) that boat gently down the stream, Charon (4x), death is but a dream.", 
+            "Um93ICgzeCkgdGhhdCBib2F0IGdlbnRseSBkb3duIHRoZSBzdHJlYW0sIENoYXJvbiAoNHgpLCBkZWF0aCBpcyBidXQgYSBkcmVhbS4=" },
+          { "Running is good for your legs.", 
+            "UnVubmluZyBpcyBnb29kIGZvciB5b3VyIGxlZ3Mu" },
+          { "Screw up your courage! You've screwed up everything else.", 
+            "U2NyZXcgdXAgeW91ciBjb3VyYWdlISBZb3UndmUgc2NyZXdlZCB1cCBldmVyeXRoaW5nIGVsc2Uu" },
+          { "Seepage? Leaky pipes? Rising damp? Summon the plumber!", 
+            "U2VlcGFnZT8gTGVha3kgcGlwZXM/IFJpc2luZyBkYW1wPyBTdW1tb24gdGhlIHBsdW1iZXIh" },
+          { "Segmentation fault (core dumped).", 
+            "U2VnbWVudGF0aW9uIGZhdWx0IChjb3JlIGR1bXBlZCku" },
+          { "Shopkeepers sometimes die from old age.", 
+            "U2hvcGtlZXBlcnMgc29tZXRpbWVzIGRpZSBmcm9tIG9sZCBhZ2Uu" },
+          { "Some mazes (especially small ones) have no solutions, says man 6 maze.", 
+            "U29tZSBtYXplcyAoZXNwZWNpYWxseSBzbWFsbCBvbmVzKSBoYXZlIG5vIHNvbHV0aW9ucywgc2F5cyBtYW4gNiBtYXplLg==" },
+          { "Some questions the Sphynx asks just *don't* have any answers.", 
+            "U29tZSBxdWVzdGlvbnMgdGhlIFNwaHlueCBhc2tzIGp1c3QgKmRvbid0KiBoYXZlIGFueSBhbnN3ZXJzLg==" },
+          { "Sometimes \"mu\" is the answer.", 
+            "U29tZXRpbWVzICJtdSIgaXMgdGhlIGFuc3dlci4=" },
+          { "Sorry, no fortune this time. Better luck next cookie!", 
+            "U29ycnksIG5vIGZvcnR1bmUgdGhpcyB0aW1lLiBCZXR0ZXIgbHVjayBuZXh0IGNvb2tpZSE=" },
+          { "Spare your scrolls of make-edible until it's really necessary!", 
+            "U3BhcmUgeW91ciBzY3JvbGxzIG9mIG1ha2UtZWRpYmxlIHVudGlsIGl0J3MgcmVhbGx5IG5lY2Vzc2FyeSE=" },
+          { "Suddenly, the dungeon will collapse...", 
+            "U3VkZGVubHksIHRoZSBkdW5nZW9uIHdpbGwgY29sbGFwc2UuLi4=" },
+          { "Taming a mail daemon may cause a system security violation.", 
+            "VGFtaW5nIGEgbWFpbCBkYWVtb24gbWF5IGNhdXNlIGEgc3lzdGVtIHNlY3VyaXR5IHZpb2xhdGlvbi4=" },
+          { "The crowd was so tough, the Stooges won't play the Dungeon anymore, nyuk nyuk.", 
+            "VGhlIGNyb3dkIHdhcyBzbyB0b3VnaCwgdGhlIFN0b29nZXMgd29uJ3QgcGxheSB0aGUgRHVuZ2VvbiBhbnltb3JlLCBueXVrIG55dWsu" },
+          { "The leprechauns hide their treasure in a small hidden room.", 
+            "VGhlIGxlcHJlY2hhdW5zIGhpZGUgdGhlaXIgdHJlYXN1cmUgaW4gYSBzbWFsbCBoaWRkZW4gcm9vbS4=" },
+          { "The longer the wand the better.", 
+            "VGhlIGxvbmdlciB0aGUgd2FuZCB0aGUgYmV0dGVyLg==" },
+          { "The magic word is \"XYZZY\".", 
+            "VGhlIG1hZ2ljIHdvcmQgaXMgIlhZWlpZIi4=" },
+          { "The meek shall inherit your bones files.", 
+            "VGhlIG1lZWsgc2hhbGwgaW5oZXJpdCB5b3VyIGJvbmVzIGZpbGVzLg==" },
+          { "The mines are dark and deep, and I have levels to go before I sleep.", 
+            "VGhlIG1pbmVzIGFyZSBkYXJrIGFuZCBkZWVwLCBhbmQgSSBoYXZlIGxldmVscyB0byBnbyBiZWZvcmUgSSBzbGVlcC4=" },
+          { "The use of dynamite is dangerous.", 
+            "VGhlIHVzZSBvZiBkeW5hbWl0ZSBpcyBkYW5nZXJvdXMu" },
+          { "There are no worms in the UNIX version.", 
+            "VGhlcmUgYXJlIG5vIHdvcm1zIGluIHRoZSBVTklYIHZlcnNpb24u" },
+          { "There is a trap on this level!", 
+            "VGhlcmUgaXMgYSB0cmFwIG9uIHRoaXMgbGV2ZWwh" },
+          { "They say that Demogorgon, Asmodeus, Orcus, Yeenoghu & Juiblex is no law firm.", 
+            "VGhleSBzYXkgdGhhdCBEZW1vZ29yZ29uLCBBc21vZGV1cywgT3JjdXMsIFllZW5vZ2h1ICYgSnVpYmxleCBpcyBubyBsYXcgZmlybS4=" },
+          { "They say that Geryon has an evil twin, beware!", 
+            "VGhleSBzYXkgdGhhdCBHZXJ5b24gaGFzIGFuIGV2aWwgdHdpbiwgYmV3YXJlIQ==" },
+          { "They say that Medusa would make a terrible pet.", 
+            "VGhleSBzYXkgdGhhdCBNZWR1c2Egd291bGQgbWFrZSBhIHRlcnJpYmxlIHBldC4=" },
+          { "They say that NetHack bugs are Seldon planned.", 
+            "VGhleSBzYXkgdGhhdCBOZXRIYWNrIGJ1Z3MgYXJlIFNlbGRvbiBwbGFubmVkLg==" },
+          { "They say that NetHack comes in 256 flavors.", 
+            "VGhleSBzYXkgdGhhdCBOZXRIYWNrIGNvbWVzIGluIDI1NiBmbGF2b3JzLg==" },
+          { "They say that NetHack is just a computer game.", 
+            "VGhleSBzYXkgdGhhdCBOZXRIYWNrIGlzIGp1c3QgYSBjb21wdXRlciBnYW1lLg==" },
+          { "They say that NetHack is more than just a computer game.", 
+            "VGhleSBzYXkgdGhhdCBOZXRIYWNrIGlzIG1vcmUgdGhhbiBqdXN0IGEgY29tcHV0ZXIgZ2FtZS4=" },
+          { "They say that NetHack is never what it used to be.", 
+            "VGhleSBzYXkgdGhhdCBOZXRIYWNrIGlzIG5ldmVyIHdoYXQgaXQgdXNlZCB0byBiZS4=" },
+          { "They say that a baby dragon is too small to hurt or help you.", 
+            "VGhleSBzYXkgdGhhdCBhIGJhYnkgZHJhZ29uIGlzIHRvbyBzbWFsbCB0byBodXJ0IG9yIGhlbHAgeW91Lg==" },
+          { "They say that a black pudding is simply a brown pudding gone bad.", 
+            "VGhleSBzYXkgdGhhdCBhIGJsYWNrIHB1ZGRpbmcgaXMgc2ltcGx5IGEgYnJvd24gcHVkZGluZyBnb25lIGJhZC4=" },
+          { "They say that a black sheep has 3 bags full of wool.", 
+            "VGhleSBzYXkgdGhhdCBhIGJsYWNrIHNoZWVwIGhhcyAzIGJhZ3MgZnVsbCBvZiB3b29sLg==" },
+          { "They say that a blank scroll is like a blank check.", 
+            "VGhleSBzYXkgdGhhdCBhIGJsYW5rIHNjcm9sbCBpcyBsaWtlIGEgYmxhbmsgY2hlY2su" },
+          { "They say that a cat named Morris has nine lives.", 
+            "VGhleSBzYXkgdGhhdCBhIGNhdCBuYW1lZCBNb3JyaXMgaGFzIG5pbmUgbGl2ZXMu" },
+          { "They say that a desperate shopper might pay any price in a shop.", 
+            "VGhleSBzYXkgdGhhdCBhIGRlc3BlcmF0ZSBzaG9wcGVyIG1pZ2h0IHBheSBhbnkgcHJpY2UgaW4gYSBzaG9wLg==" },
+          { "They say that a diamond dog is everybody's best friend.", 
+            "VGhleSBzYXkgdGhhdCBhIGRpYW1vbmQgZG9nIGlzIGV2ZXJ5Ym9keSdzIGJlc3QgZnJpZW5kLg==" },
+          { "They say that a dwarf lord can carry a pick-axe because his armor is light.", 
+            "VGhleSBzYXkgdGhhdCBhIGR3YXJmIGxvcmQgY2FuIGNhcnJ5IGEgcGljay1heGUgYmVjYXVzZSBoaXMgYXJtb3IgaXMgbGlnaHQu" },
+          { "They say that a floating eye can defeat Medusa.", 
+            "VGhleSBzYXkgdGhhdCBhIGZsb2F0aW5nIGV5ZSBjYW4gZGVmZWF0IE1lZHVzYS4=" },
+          { "They say that a fortune only has 1 line and you can't read between it.", 
+            "VGhleSBzYXkgdGhhdCBhIGZvcnR1bmUgb25seSBoYXMgMSBsaW5lIGFuZCB5b3UgY2FuJ3QgcmVhZCBiZXR3ZWVuIGl0Lg==" },
+          { "They say that a fortune only has 1 line, but you can read between it.", 
+            "VGhleSBzYXkgdGhhdCBhIGZvcnR1bmUgb25seSBoYXMgMSBsaW5lLCBidXQgeW91IGNhbiByZWFkIGJldHdlZW4gaXQu" },
+          { "They say that a fountain looks nothing like a regularly erupting geyser.", 
+            "VGhleSBzYXkgdGhhdCBhIGZvdW50YWluIGxvb2tzIG5vdGhpbmcgbGlrZSBhIHJlZ3VsYXJseSBlcnVwdGluZyBnZXlzZXIu" },
+          { "They say that a gold doubloon is worth more than its weight in gold.", 
+            "VGhleSBzYXkgdGhhdCBhIGdvbGQgZG91Ymxvb24gaXMgd29ydGggbW9yZSB0aGFuIGl0cyB3ZWlnaHQgaW4gZ29sZC4=" },
+          { "They say that a grid bug won't pay a shopkeeper for zapping you in a shop.", 
+            "VGhleSBzYXkgdGhhdCBhIGdyaWQgYnVnIHdvbid0IHBheSBhIHNob3BrZWVwZXIgZm9yIHphcHBpbmcgeW91IGluIGEgc2hvcC4=" },
+          { "They say that a gypsy could tell your fortune for a price.", 
+            "VGhleSBzYXkgdGhhdCBhIGd5cHN5IGNvdWxkIHRlbGwgeW91ciBmb3J0dW5lIGZvciBhIHByaWNlLg==" },
+          { "They say that a hacker named Alice once level teleported by using a mirror.", 
+            "VGhleSBzYXkgdGhhdCBhIGhhY2tlciBuYW1lZCBBbGljZSBvbmNlIGxldmVsIHRlbGVwb3J0ZWQgYnkgdXNpbmcgYSBtaXJyb3Iu" },
+          { "They say that a hacker named David once slew a giant with a sling and a rock.", 
+            "VGhleSBzYXkgdGhhdCBhIGhhY2tlciBuYW1lZCBEYXZpZCBvbmNlIHNsZXcgYSBnaWFudCB3aXRoIGEgc2xpbmcgYW5kIGEgcm9jay4=" },
+          { "They say that a hacker named Dorothy once rode a fog cloud to Oz.", 
+            "VGhleSBzYXkgdGhhdCBhIGhhY2tlciBuYW1lZCBEb3JvdGh5IG9uY2Ugcm9kZSBhIGZvZyBjbG91ZCB0byBPei4=" },
+          { "They say that a hacker named Mary once lost a white sheep in the mazes.", 
+            "VGhleSBzYXkgdGhhdCBhIGhhY2tlciBuYW1lZCBNYXJ5IG9uY2UgbG9zdCBhIHdoaXRlIHNoZWVwIGluIHRoZSBtYXplcy4=" },
+          { "They say that a helm of brilliance is not to be taken lightly.", 
+            "VGhleSBzYXkgdGhhdCBhIGhlbG0gb2YgYnJpbGxpYW5jZSBpcyBub3QgdG8gYmUgdGFrZW4gbGlnaHRseS4=" },
+          { "They say that a hot dog and a hell hound are the same thing.", 
+            "VGhleSBzYXkgdGhhdCBhIGhvdCBkb2cgYW5kIGEgaGVsbCBob3VuZCBhcmUgdGhlIHNhbWUgdGhpbmcu" },
+          { "They say that a lamp named Aladdin's Lamp contains a djinni with 3 wishes.", 
+            "VGhleSBzYXkgdGhhdCBhIGxhbXAgbmFtZWQgQWxhZGRpbidzIExhbXAgY29udGFpbnMgYSBkamlubmkgd2l0aCAzIHdpc2hlcy4=" },
+          { "They say that a large dog named Lassie will lead you to the amulet.", 
+            "VGhleSBzYXkgdGhhdCBhIGxhcmdlIGRvZyBuYW1lZCBMYXNzaWUgd2lsbCBsZWFkIHlvdSB0byB0aGUgYW11bGV0Lg==" },
+          { "They say that a long sword is not a light sword.", 
+            "VGhleSBzYXkgdGhhdCBhIGxvbmcgc3dvcmQgaXMgbm90IGEgbGlnaHQgc3dvcmQu" },
+          { "They say that a manes won't mince words with you.", 
+            "VGhleSBzYXkgdGhhdCBhIG1hbmVzIHdvbid0IG1pbmNlIHdvcmRzIHdpdGggeW91Lg==" },
+          { "They say that a mind is a terrible thing to waste.", 
+            "VGhleSBzYXkgdGhhdCBhIG1pbmQgaXMgYSB0ZXJyaWJsZSB0aGluZyB0byB3YXN0ZS4=" },
+          { "They say that a plain nymph will only wear a wire ring in one ear.", 
+            "VGhleSBzYXkgdGhhdCBhIHBsYWluIG55bXBoIHdpbGwgb25seSB3ZWFyIGEgd2lyZSByaW5nIGluIG9uZSBlYXIu" },
+          { "They say that a plumed hat could be a previously used crested helmet.", 
+            "VGhleSBzYXkgdGhhdCBhIHBsdW1lZCBoYXQgY291bGQgYmUgYSBwcmV2aW91c2x5IHVzZWQgY3Jlc3RlZCBoZWxtZXQu" },
+          { "They say that a potion of oil is difficult to grasp.", 
+            "VGhleSBzYXkgdGhhdCBhIHBvdGlvbiBvZiBvaWwgaXMgZGlmZmljdWx0IHRvIGdyYXNwLg==" },
+          { "They say that a potion of yogurt is a cancelled potion of sickness.", 
+            "VGhleSBzYXkgdGhhdCBhIHBvdGlvbiBvZiB5b2d1cnQgaXMgYSBjYW5jZWxsZWQgcG90aW9uIG9mIHNpY2tuZXNzLg==" },
+          { "They say that a purple worm is not a baby purple dragon.", 
+            "VGhleSBzYXkgdGhhdCBhIHB1cnBsZSB3b3JtIGlzIG5vdCBhIGJhYnkgcHVycGxlIGRyYWdvbi4=" },
+          { "They say that a quivering blob tastes different than a gelatinous cube.", 
+            "VGhleSBzYXkgdGhhdCBhIHF1aXZlcmluZyBibG9iIHRhc3RlcyBkaWZmZXJlbnQgdGhhbiBhIGdlbGF0aW5vdXMgY3ViZS4=" },
+          { "They say that a runed broadsword named Stormbringer attracts vortices.", 
+            "VGhleSBzYXkgdGhhdCBhIHJ1bmVkIGJyb2Fkc3dvcmQgbmFtZWQgU3Rvcm1icmluZ2VyIGF0dHJhY3RzIHZvcnRpY2VzLg==" },
+          { "They say that a scroll of summoning has other names.", 
+            "VGhleSBzYXkgdGhhdCBhIHNjcm9sbCBvZiBzdW1tb25pbmcgaGFzIG90aGVyIG5hbWVzLg==" },
+          { "They say that a shaman can bestow blessings but usually doesn't.", 
+            "VGhleSBzYXkgdGhhdCBhIHNoYW1hbiBjYW4gYmVzdG93IGJsZXNzaW5ncyBidXQgdXN1YWxseSBkb2Vzbid0Lg==" },
+          { "They say that a shaman will bless you for an eye of newt and wing of bat.", 
+            "VGhleSBzYXkgdGhhdCBhIHNoYW1hbiB3aWxsIGJsZXNzIHlvdSBmb3IgYW4gZXllIG9mIG5ld3QgYW5kIHdpbmcgb2YgYmF0Lg==" },
+          { "They say that a shimmering gold shield is not a polished silver shield.", 
+            "VGhleSBzYXkgdGhhdCBhIHNoaW1tZXJpbmcgZ29sZCBzaGllbGQgaXMgbm90IGEgcG9saXNoZWQgc2lsdmVyIHNoaWVsZC4=" },
+          { "They say that a spear will hit a neo-otyugh. (Do YOU know what that is?)", 
+            "VGhleSBzYXkgdGhhdCBhIHNwZWFyIHdpbGwgaGl0IGEgbmVvLW90eXVnaC4gKERvIFlPVSBrbm93IHdoYXQgdGhhdCBpcz8p" },
+          { "They say that a spotted dragon is the ultimate shape changer.", 
+            "VGhleSBzYXkgdGhhdCBhIHNwb3R0ZWQgZHJhZ29uIGlzIHRoZSB1bHRpbWF0ZSBzaGFwZSBjaGFuZ2VyLg==" },
+          { "They say that a stethoscope is no good if you can only hear your heartbeat.", 
+            "VGhleSBzYXkgdGhhdCBhIHN0ZXRob3Njb3BlIGlzIG5vIGdvb2QgaWYgeW91IGNhbiBvbmx5IGhlYXIgeW91ciBoZWFydGJlYXQu" },
+          { "They say that a succubus named Suzy will sometimes warn you of danger.", 
+            "VGhleSBzYXkgdGhhdCBhIHN1Y2N1YnVzIG5hbWVkIFN1enkgd2lsbCBzb21ldGltZXMgd2FybiB5b3Ugb2YgZGFuZ2VyLg==" },
+          { "They say that a wand of cancellation is not like a wand of polymorph.", 
+            "VGhleSBzYXkgdGhhdCBhIHdhbmQgb2YgY2FuY2VsbGF0aW9uIGlzIG5vdCBsaWtlIGEgd2FuZCBvZiBwb2x5bW9ycGgu" },
+          { "They say that a wood golem named Pinocchio would be easy to control.", 
+            "VGhleSBzYXkgdGhhdCBhIHdvb2QgZ29sZW0gbmFtZWQgUGlub2NjaGlvIHdvdWxkIGJlIGVhc3kgdG8gY29udHJvbC4=" },
+          { "They say that after killing a dragon it's time for a change of scenery.", 
+            "VGhleSBzYXkgdGhhdCBhZnRlciBraWxsaW5nIGEgZHJhZ29uIGl0J3MgdGltZSBmb3IgYSBjaGFuZ2Ugb2Ygc2NlbmVyeS4=" },
+          { "They say that an amulet of strangulation is worse than ring around the collar.", 
+            "VGhleSBzYXkgdGhhdCBhbiBhbXVsZXQgb2Ygc3RyYW5ndWxhdGlvbiBpcyB3b3JzZSB0aGFuIHJpbmcgYXJvdW5kIHRoZSBjb2xsYXIu" },
+          { "They say that an attic is the best place to hide your toys.", 
+            "VGhleSBzYXkgdGhhdCBhbiBhdHRpYyBpcyB0aGUgYmVzdCBwbGFjZSB0byBoaWRlIHlvdXIgdG95cy4=" },
+          { "They say that an axe named Cleaver once belonged to a hacker named Beaver.", 
+            "VGhleSBzYXkgdGhhdCBhbiBheGUgbmFtZWQgQ2xlYXZlciBvbmNlIGJlbG9uZ2VkIHRvIGEgaGFja2VyIG5hbWVkIEJlYXZlci4=" },
+          { "They say that an eye of newt and a wing of bat are double the trouble.", 
+            "VGhleSBzYXkgdGhhdCBhbiBleWUgb2YgbmV3dCBhbmQgYSB3aW5nIG9mIGJhdCBhcmUgZG91YmxlIHRoZSB0cm91YmxlLg==" },
+          { "They say that an incubus named Izzy sometimes makes women feel sensitive.", 
+            "VGhleSBzYXkgdGhhdCBhbiBpbmN1YnVzIG5hbWVkIEl6enkgc29tZXRpbWVzIG1ha2VzIHdvbWVuIGZlZWwgc2Vuc2l0aXZlLg==" },
+          { "They say that an opulent throne room is rarely a place to wish you'd be in.", 
+            "VGhleSBzYXkgdGhhdCBhbiBvcHVsZW50IHRocm9uZSByb29tIGlzIHJhcmVseSBhIHBsYWNlIHRvIHdpc2ggeW91J2QgYmUgaW4u" },
+          { "They say that an unlucky hacker once had a nose bleed at an altar and died.", 
+            "VGhleSBzYXkgdGhhdCBhbiB1bmx1Y2t5IGhhY2tlciBvbmNlIGhhZCBhIG5vc2UgYmxlZWQgYXQgYW4gYWx0YXIgYW5kIGRpZWQu" },
+          { "They say that and they say this but they never say never, never!", 
+            "VGhleSBzYXkgdGhhdCBhbmQgdGhleSBzYXkgdGhpcyBidXQgdGhleSBuZXZlciBzYXkgbmV2ZXIsIG5ldmVyIQ==" },
+          { "They say that any quantum mechanic knows that speed kills.", 
+            "VGhleSBzYXkgdGhhdCBhbnkgcXVhbnR1bSBtZWNoYW5pYyBrbm93cyB0aGF0IHNwZWVkIGtpbGxzLg==" },
+          { "They say that applying a unicorn horn means you've missed the point.", 
+            "VGhleSBzYXkgdGhhdCBhcHBseWluZyBhIHVuaWNvcm4gaG9ybiBtZWFucyB5b3UndmUgbWlzc2VkIHRoZSBwb2ludC4=" },
+          { "They say that blue stones are radioactive, beware.", 
+            "VGhleSBzYXkgdGhhdCBibHVlIHN0b25lcyBhcmUgcmFkaW9hY3RpdmUsIGJld2FyZS4=" },
+          { "They say that building a dungeon is a team effort.", 
+            "VGhleSBzYXkgdGhhdCBidWlsZGluZyBhIGR1bmdlb24gaXMgYSB0ZWFtIGVmZm9ydC4=" },
+          { "They say that chaotic characters never get a kick out of altars.", 
+            "VGhleSBzYXkgdGhhdCBjaGFvdGljIGNoYXJhY3RlcnMgbmV2ZXIgZ2V0IGEga2ljayBvdXQgb2YgYWx0YXJzLg==" },
+          { "They say that collapsing a dungeon often creates a panic.", 
+            "VGhleSBzYXkgdGhhdCBjb2xsYXBzaW5nIGEgZHVuZ2VvbiBvZnRlbiBjcmVhdGVzIGEgcGFuaWMu" },
+          { "They say that counting your eggs before they hatch shows that you care.", 
+            "VGhleSBzYXkgdGhhdCBjb3VudGluZyB5b3VyIGVnZ3MgYmVmb3JlIHRoZXkgaGF0Y2ggc2hvd3MgdGhhdCB5b3UgY2FyZS4=" },
+          { "They say that dipping a bag of tricks in a fountain won't make it an icebox.", 
+            "VGhleSBzYXkgdGhhdCBkaXBwaW5nIGEgYmFnIG9mIHRyaWNrcyBpbiBhIGZvdW50YWluIHdvbid0IG1ha2UgaXQgYW4gaWNlYm94Lg==" },
+          { "They say that dipping an eel and brown mold in hot water makes bouillabaisse.", 
+            "VGhleSBzYXkgdGhhdCBkaXBwaW5nIGFuIGVlbCBhbmQgYnJvd24gbW9sZCBpbiBob3Qgd2F0ZXIgbWFrZXMgYm91aWxsYWJhaXNzZS4=" },
+          { "They say that donating a doubloon is extremely pious charity.", 
+            "VGhleSBzYXkgdGhhdCBkb25hdGluZyBhIGRvdWJsb29uIGlzIGV4dHJlbWVseSBwaW91cyBjaGFyaXR5Lg==" },
+          { "They say that eating royal jelly attracts grizzly owlbears.", 
+            "VGhleSBzYXkgdGhhdCBlYXRpbmcgcm95YWwgamVsbHkgYXR0cmFjdHMgZ3JpenpseSBvd2xiZWFycy4=" },
+          { "They say that eggs, pancakes and juice are just a mundane breakfast.", 
+            "VGhleSBzYXkgdGhhdCBlZ2dzLCBwYW5jYWtlcyBhbmQganVpY2UgYXJlIGp1c3QgYSBtdW5kYW5lIGJyZWFrZmFzdC4=" },
+          { "They say that everyone knows why Medusa stands alone in the dark.", 
+            "VGhleSBzYXkgdGhhdCBldmVyeW9uZSBrbm93cyB3aHkgTWVkdXNhIHN0YW5kcyBhbG9uZSBpbiB0aGUgZGFyay4=" },
+          { "They say that everyone wanted rec.games.hack to undergo a name change.", 
+            "VGhleSBzYXkgdGhhdCBldmVyeW9uZSB3YW50ZWQgcmVjLmdhbWVzLmhhY2sgdG8gdW5kZXJnbyBhIG5hbWUgY2hhbmdlLg==" },
+          { "They say that finding a winning strategy is a deliberate move on your part.", 
+            "VGhleSBzYXkgdGhhdCBmaW5kaW5nIGEgd2lubmluZyBzdHJhdGVneSBpcyBhIGRlbGliZXJhdGUgbW92ZSBvbiB5b3VyIHBhcnQu" },
+          { "They say that finding worthless glass is worth something.", 
+            "VGhleSBzYXkgdGhhdCBmaW5kaW5nIHdvcnRobGVzcyBnbGFzcyBpcyB3b3J0aCBzb21ldGhpbmcu" },
+          { "They say that fortune cookies are food for thought.", 
+            "VGhleSBzYXkgdGhhdCBmb3J0dW5lIGNvb2tpZXMgYXJlIGZvb2QgZm9yIHRob3VnaHQu" },
+          { "They say that gold is only wasted on a pet dragon.", 
+            "VGhleSBzYXkgdGhhdCBnb2xkIGlzIG9ubHkgd2FzdGVkIG9uIGEgcGV0IGRyYWdvbi4=" },
+          { "They say that good things come to those that wait.", 
+            "VGhleSBzYXkgdGhhdCBnb29kIHRoaW5ncyBjb21lIHRvIHRob3NlIHRoYXQgd2FpdC4=" },
+          { "They say that greased objects will slip out of monsters' hands.", 
+            "VGhleSBzYXkgdGhhdCBncmVhc2VkIG9iamVjdHMgd2lsbCBzbGlwIG91dCBvZiBtb25zdGVycycgaGFuZHMu" },
+          { "They say that if you can't spell then you'll wish you had a spell book.", 
+            "VGhleSBzYXkgdGhhdCBpZiB5b3UgY2FuJ3Qgc3BlbGwgdGhlbiB5b3UnbGwgd2lzaCB5b3UgaGFkIGEgc3BlbGwgYm9vay4=" },
+          { "They say that if you live by the sword, you'll die by the sword.", 
+            "VGhleSBzYXkgdGhhdCBpZiB5b3UgbGl2ZSBieSB0aGUgc3dvcmQsIHlvdSdsbCBkaWUgYnkgdGhlIHN3b3JkLg==" },
+          { "They say that if you play like a monster you'll have a better game.", 
+            "VGhleSBzYXkgdGhhdCBpZiB5b3UgcGxheSBsaWtlIGEgbW9uc3RlciB5b3UnbGwgaGF2ZSBhIGJldHRlciBnYW1lLg==" },
+          { "They say that if you sleep with a demon you might awake with a headache.", 
+            "VGhleSBzYXkgdGhhdCBpZiB5b3Ugc2xlZXAgd2l0aCBhIGRlbW9uIHlvdSBtaWdodCBhd2FrZSB3aXRoIGEgaGVhZGFjaGUu" },
+          { "They say that if you step on a crack you could break your mother's back.", 
+            "VGhleSBzYXkgdGhhdCBpZiB5b3Ugc3RlcCBvbiBhIGNyYWNrIHlvdSBjb3VsZCBicmVhayB5b3VyIG1vdGhlcidzIGJhY2su" },
+          { "They say that if you're invisible you can still be heard!", 
+            "VGhleSBzYXkgdGhhdCBpZiB5b3UncmUgaW52aXNpYmxlIHlvdSBjYW4gc3RpbGwgYmUgaGVhcmQh" },
+          { "They say that if you're lucky you can feel the runes on a scroll.", 
+            "VGhleSBzYXkgdGhhdCBpZiB5b3UncmUgbHVja3kgeW91IGNhbiBmZWVsIHRoZSBydW5lcyBvbiBhIHNjcm9sbC4=" },
+          { "They say that in the big picture gold is only small change.", 
+            "VGhleSBzYXkgdGhhdCBpbiB0aGUgYmlnIHBpY3R1cmUgZ29sZCBpcyBvbmx5IHNtYWxsIGNoYW5nZS4=" },
+          { "They say that in the dungeon it's not what you know that really matters.", 
+            "VGhleSBzYXkgdGhhdCBpbiB0aGUgZHVuZ2VvbiBpdCdzIG5vdCB3aGF0IHlvdSBrbm93IHRoYXQgcmVhbGx5IG1hdHRlcnMu" },
+          { "They say that in the dungeon moon rocks are really dilithium crystals.", 
+            "VGhleSBzYXkgdGhhdCBpbiB0aGUgZHVuZ2VvbiBtb29uIHJvY2tzIGFyZSByZWFsbHkgZGlsaXRoaXVtIGNyeXN0YWxzLg==" },
+          { "They say that in the dungeon the boorish customer is never right.", 
+            "VGhleSBzYXkgdGhhdCBpbiB0aGUgZHVuZ2VvbiB0aGUgYm9vcmlzaCBjdXN0b21lciBpcyBuZXZlciByaWdodC4=" },
+          { "They say that in the dungeon you don't need a watch to tell time.", 
+            "VGhleSBzYXkgdGhhdCBpbiB0aGUgZHVuZ2VvbiB5b3UgZG9uJ3QgbmVlZCBhIHdhdGNoIHRvIHRlbGwgdGltZS4=" },
+          { "They say that in the dungeon you need something old, new, burrowed and blue.", 
+            "VGhleSBzYXkgdGhhdCBpbiB0aGUgZHVuZ2VvbiB5b3UgbmVlZCBzb21ldGhpbmcgb2xkLCBuZXcsIGJ1cnJvd2VkIGFuZCBibHVlLg==" },
+          { "They say that in the dungeon you should always count your blessings.", 
+            "VGhleSBzYXkgdGhhdCBpbiB0aGUgZHVuZ2VvbiB5b3Ugc2hvdWxkIGFsd2F5cyBjb3VudCB5b3VyIGJsZXNzaW5ncy4=" },
+          { "They say that iron golem plate mail isn't worth wishing for.", 
+            "VGhleSBzYXkgdGhhdCBpcm9uIGdvbGVtIHBsYXRlIG1haWwgaXNuJ3Qgd29ydGggd2lzaGluZyBmb3Iu" },
+          { "They say that it takes four quarterstaffs to make one staff.", 
+            "VGhleSBzYXkgdGhhdCBpdCB0YWtlcyBmb3VyIHF1YXJ0ZXJzdGFmZnMgdG8gbWFrZSBvbmUgc3RhZmYu" },
+          { "They say that it's not over till the fat ladies sing.", 
+            "VGhleSBzYXkgdGhhdCBpdCdzIG5vdCBvdmVyIHRpbGwgdGhlIGZhdCBsYWRpZXMgc2luZy4=" },
+          { "They say that it's not over till the fat lady shouts `Off with its head'.", 
+            "VGhleSBzYXkgdGhhdCBpdCdzIG5vdCBvdmVyIHRpbGwgdGhlIGZhdCBsYWR5IHNob3V0cyBgT2ZmIHdpdGggaXRzIGhlYWQnLg==" },
+          { "They say that kicking a heavy statue is really a dumb move.", 
+            "VGhleSBzYXkgdGhhdCBraWNraW5nIGEgaGVhdnkgc3RhdHVlIGlzIHJlYWxseSBhIGR1bWIgbW92ZS4=" },
+          { "They say that kicking a valuable gem doesn't seem to make sense.", 
+            "VGhleSBzYXkgdGhhdCBraWNraW5nIGEgdmFsdWFibGUgZ2VtIGRvZXNuJ3Qgc2VlbSB0byBtYWtlIHNlbnNlLg==" },
+          { "They say that leprechauns know Latin and you should too.", 
+            "VGhleSBzYXkgdGhhdCBsZXByZWNoYXVucyBrbm93IExhdGluIGFuZCB5b3Ugc2hvdWxkIHRvby4=" },
+          { "They say that minotaurs get lost outside of the mazes.", 
+            "VGhleSBzYXkgdGhhdCBtaW5vdGF1cnMgZ2V0IGxvc3Qgb3V0c2lkZSBvZiB0aGUgbWF6ZXMu" },
+          { "They say that most trolls are born again.", 
+            "VGhleSBzYXkgdGhhdCBtb3N0IHRyb2xscyBhcmUgYm9ybiBhZ2Fpbi4=" },
+          { "They say that naming your cat Garfield will make you more attractive.", 
+            "VGhleSBzYXkgdGhhdCBuYW1pbmcgeW91ciBjYXQgR2FyZmllbGQgd2lsbCBtYWtlIHlvdSBtb3JlIGF0dHJhY3RpdmUu" },
+          { "They say that no one knows everything about everything in the dungeon.", 
+            "VGhleSBzYXkgdGhhdCBubyBvbmUga25vd3MgZXZlcnl0aGluZyBhYm91dCBldmVyeXRoaW5nIGluIHRoZSBkdW5nZW9uLg==" },
+          { "They say that no one plays NetHack just for the fun of it.", 
+            "VGhleSBzYXkgdGhhdCBubyBvbmUgcGxheXMgTmV0SGFjayBqdXN0IGZvciB0aGUgZnVuIG9mIGl0Lg==" },
+          { "They say that no one really subscribes to rec.games.roguelike.nethack.", 
+            "VGhleSBzYXkgdGhhdCBubyBvbmUgcmVhbGx5IHN1YnNjcmliZXMgdG8gcmVjLmdhbWVzLnJvZ3VlbGlrZS5uZXRoYWNrLg==" },
+          { "They say that no one will admit to starting a rumor.", 
+            "VGhleSBzYXkgdGhhdCBubyBvbmUgd2lsbCBhZG1pdCB0byBzdGFydGluZyBhIHJ1bW9yLg==" },
+          { "They say that nurses sometimes carry scalpels and never use them.", 
+            "VGhleSBzYXkgdGhhdCBudXJzZXMgc29tZXRpbWVzIGNhcnJ5IHNjYWxwZWxzIGFuZCBuZXZlciB1c2UgdGhlbS4=" },
+          { "They say that once you've met one wizard you've met them all.", 
+            "VGhleSBzYXkgdGhhdCBvbmNlIHlvdSd2ZSBtZXQgb25lIHdpemFyZCB5b3UndmUgbWV0IHRoZW0gYWxsLg==" },
+          { "They say that one troll is worth 10,000 newts.", 
+            "VGhleSBzYXkgdGhhdCBvbmUgdHJvbGwgaXMgd29ydGggMTAsMDAwIG5ld3RzLg==" },
+          { "They say that only David can find the zoo!", 
+            "VGhleSBzYXkgdGhhdCBvbmx5IERhdmlkIGNhbiBmaW5kIHRoZSB6b28h" },
+          { "They say that only angels play their harps for their pets.", 
+            "VGhleSBzYXkgdGhhdCBvbmx5IGFuZ2VscyBwbGF5IHRoZWlyIGhhcnBzIGZvciB0aGVpciBwZXRzLg==" },
+          { "They say that only big spenders carry gold.", 
+            "VGhleSBzYXkgdGhhdCBvbmx5IGJpZyBzcGVuZGVycyBjYXJyeSBnb2xkLg==" },
+          { "They say that orc shamans are healthy, wealthy and wise.", 
+            "VGhleSBzYXkgdGhhdCBvcmMgc2hhbWFucyBhcmUgaGVhbHRoeSwgd2VhbHRoeSBhbmQgd2lzZS4=" },
+          { "They say that playing NetHack is like walking into a death trap.", 
+            "VGhleSBzYXkgdGhhdCBwbGF5aW5nIE5ldEhhY2sgaXMgbGlrZSB3YWxraW5nIGludG8gYSBkZWF0aCB0cmFwLg==" },
+          { "They say that problem breathing is best treated by a proper diet.", 
+            "VGhleSBzYXkgdGhhdCBwcm9ibGVtIGJyZWF0aGluZyBpcyBiZXN0IHRyZWF0ZWQgYnkgYSBwcm9wZXIgZGlldC4=" },
+          { "They say that quaffing many potions of levitation can give you a headache.", 
+            "VGhleSBzYXkgdGhhdCBxdWFmZmluZyBtYW55IHBvdGlvbnMgb2YgbGV2aXRhdGlvbiBjYW4gZ2l2ZSB5b3UgYSBoZWFkYWNoZS4=" },
+          { "They say that queen bees get that way by eating royal jelly.", 
+            "VGhleSBzYXkgdGhhdCBxdWVlbiBiZWVzIGdldCB0aGF0IHdheSBieSBlYXRpbmcgcm95YWwgamVsbHku" },
+          { "They say that reading a scare monster scroll is the same as saying Elbereth.", 
+            "VGhleSBzYXkgdGhhdCByZWFkaW5nIGEgc2NhcmUgbW9uc3RlciBzY3JvbGwgaXMgdGhlIHNhbWUgYXMgc2F5aW5nIEVsYmVyZXRoLg==" },
+          { "They say that real hackers always are controlled.", 
+            "VGhleSBzYXkgdGhhdCByZWFsIGhhY2tlcnMgYWx3YXlzIGFyZSBjb250cm9sbGVkLg==" },
+          { "They say that real hackers never sleep.", 
+            "VGhleSBzYXkgdGhhdCByZWFsIGhhY2tlcnMgbmV2ZXIgc2xlZXAu" },
+          { "They say that shopkeepers are insured by Croesus himself!", 
+            "VGhleSBzYXkgdGhhdCBzaG9wa2VlcGVycyBhcmUgaW5zdXJlZCBieSBDcm9lc3VzIGhpbXNlbGYh" },
+          { "They say that shopkeepers never carry more than 20 gold pieces, at night.", 
+            "VGhleSBzYXkgdGhhdCBzaG9wa2VlcGVycyBuZXZlciBjYXJyeSBtb3JlIHRoYW4gMjAgZ29sZCBwaWVjZXMsIGF0IG5pZ2h0Lg==" },
+          { "They say that shopkeepers never sell blessed potions of invisibility.", 
+            "VGhleSBzYXkgdGhhdCBzaG9wa2VlcGVycyBuZXZlciBzZWxsIGJsZXNzZWQgcG90aW9ucyBvZiBpbnZpc2liaWxpdHku" },
+          { "They say that soldiers wear kid gloves and silly helmets.", 
+            "VGhleSBzYXkgdGhhdCBzb2xkaWVycyB3ZWFyIGtpZCBnbG92ZXMgYW5kIHNpbGx5IGhlbG1ldHMu" },
+          { "They say that some Kops are on the take.", 
+            "VGhleSBzYXkgdGhhdCBzb21lIEtvcHMgYXJlIG9uIHRoZSB0YWtlLg==" },
+          { "They say that some guards' palms can be greased.", 
+            "VGhleSBzYXkgdGhhdCBzb21lIGd1YXJkcycgcGFsbXMgY2FuIGJlIGdyZWFzZWQu" },
+          { "They say that some monsters may kiss your boots to stop your drum playing.", 
+            "VGhleSBzYXkgdGhhdCBzb21lIG1vbnN0ZXJzIG1heSBraXNzIHlvdXIgYm9vdHMgdG8gc3RvcCB5b3VyIGRydW0gcGxheWluZy4=" },
+          { "They say that sometimes you can be the hit of the party when playing a horn.", 
+            "VGhleSBzYXkgdGhhdCBzb21ldGltZXMgeW91IGNhbiBiZSB0aGUgaGl0IG9mIHRoZSBwYXJ0eSB3aGVuIHBsYXlpbmcgYSBob3JuLg==" },
+          { "They say that the NetHack gods generally welcome your sacrifices.", 
+            "VGhleSBzYXkgdGhhdCB0aGUgTmV0SGFjayBnb2RzIGdlbmVyYWxseSB3ZWxjb21lIHlvdXIgc2FjcmlmaWNlcy4=" },
+          { "They say that the Three Rings are named Vilya, Nenya and Narya.", 
+            "VGhleSBzYXkgdGhhdCB0aGUgVGhyZWUgUmluZ3MgYXJlIG5hbWVkIFZpbHlhLCBOZW55YSBhbmQgTmFyeWEu" },
+          { "They say that the Wizard of Yendor has a death wish.", 
+            "VGhleSBzYXkgdGhhdCB0aGUgV2l6YXJkIG9mIFllbmRvciBoYXMgYSBkZWF0aCB3aXNoLg==" },
+          { "They say that the `hair of the dog' is sometimes an effective remedy.", 
+            "VGhleSBzYXkgdGhhdCB0aGUgYGhhaXIgb2YgdGhlIGRvZycgaXMgc29tZXRpbWVzIGFuIGVmZmVjdGl2ZSByZW1lZHku" },
+          { "They say that the best time to save your game is now before its too late.", 
+            "VGhleSBzYXkgdGhhdCB0aGUgYmVzdCB0aW1lIHRvIHNhdmUgeW91ciBnYW1lIGlzIG5vdyBiZWZvcmUgaXRzIHRvbyBsYXRlLg==" },
+          { "They say that the biggest obstacle in NetHack is your mind.", 
+            "VGhleSBzYXkgdGhhdCB0aGUgYmlnZ2VzdCBvYnN0YWNsZSBpbiBOZXRIYWNrIGlzIHlvdXIgbWluZC4=" },
+          { "They say that the gods are angry when they hit you with objects.", 
+            "VGhleSBzYXkgdGhhdCB0aGUgZ29kcyBhcmUgYW5ncnkgd2hlbiB0aGV5IGhpdCB5b3Ugd2l0aCBvYmplY3RzLg==" },
+          { "They say that the priesthood are specially favored by the gods.", 
+            "VGhleSBzYXkgdGhhdCB0aGUgcHJpZXN0aG9vZCBhcmUgc3BlY2lhbGx5IGZhdm9yZWQgYnkgdGhlIGdvZHMu" },
+          { "They say that the way to make a unicorn happy is to give it what it wants.", 
+            "VGhleSBzYXkgdGhhdCB0aGUgd2F5IHRvIG1ha2UgYSB1bmljb3JuIGhhcHB5IGlzIHRvIGdpdmUgaXQgd2hhdCBpdCB3YW50cy4=" },
+          { "They say that there are no black or white stones, only gray.", 
+            "VGhleSBzYXkgdGhhdCB0aGVyZSBhcmUgbm8gYmxhY2sgb3Igd2hpdGUgc3RvbmVzLCBvbmx5IGdyYXku" },
+          { "They say that there are no skeletons hence there are no skeleton keys.", 
+            "VGhleSBzYXkgdGhhdCB0aGVyZSBhcmUgbm8gc2tlbGV0b25zIGhlbmNlIHRoZXJlIGFyZSBubyBza2VsZXRvbiBrZXlzLg==" },
+          { "They say that there is a clever rogue in every hacker just dying to escape.", 
+            "VGhleSBzYXkgdGhhdCB0aGVyZSBpcyBhIGNsZXZlciByb2d1ZSBpbiBldmVyeSBoYWNrZXIganVzdCBkeWluZyB0byBlc2NhcGUu" },
+          { "They say that there is no such thing as free advice.", 
+            "VGhleSBzYXkgdGhhdCB0aGVyZSBpcyBubyBzdWNoIHRoaW5nIGFzIGZyZWUgYWR2aWNlLg==" },
+          { "They say that there is only one way to win at NetHack.", 
+            "VGhleSBzYXkgdGhhdCB0aGVyZSBpcyBvbmx5IG9uZSB3YXkgdG8gd2luIGF0IE5ldEhhY2su" },
+          { "They say that there once was a fearsome chaotic samurai named Luk No.", 
+            "VGhleSBzYXkgdGhhdCB0aGVyZSBvbmNlIHdhcyBhIGZlYXJzb21lIGNoYW90aWMgc2FtdXJhaSBuYW1lZCBMdWsgTm8u" },
+          { "They say that there was a time when cursed holy water wasn't water.", 
+            "VGhleSBzYXkgdGhhdCB0aGVyZSB3YXMgYSB0aW1lIHdoZW4gY3Vyc2VkIGhvbHkgd2F0ZXIgd2Fzbid0IHdhdGVyLg==" },
+          { "They say that there's no point in crying over a gray ooze.", 
+            "VGhleSBzYXkgdGhhdCB0aGVyZSdzIG5vIHBvaW50IGluIGNyeWluZyBvdmVyIGEgZ3JheSBvb3plLg==" },
+          { "They say that there's only hope left after you've opened Pandora's box.", 
+            "VGhleSBzYXkgdGhhdCB0aGVyZSdzIG9ubHkgaG9wZSBsZWZ0IGFmdGVyIHlvdSd2ZSBvcGVuZWQgUGFuZG9yYSdzIGJveC4=" },
+          { "They say that trapdoors should always be marked `Caution: Trap Door'.", 
+            "VGhleSBzYXkgdGhhdCB0cmFwZG9vcnMgc2hvdWxkIGFsd2F5cyBiZSBtYXJrZWQgYENhdXRpb246IFRyYXAgRG9vcicu" },
+          { "They say that using an amulet of change isn't a difficult operation.", 
+            "VGhleSBzYXkgdGhhdCB1c2luZyBhbiBhbXVsZXQgb2YgY2hhbmdlIGlzbid0IGEgZGlmZmljdWx0IG9wZXJhdGlvbi4=" },
+          { "They say that water walking boots are better if you are fast like Hermes.", 
+            "VGhleSBzYXkgdGhhdCB3YXRlciB3YWxraW5nIGJvb3RzIGFyZSBiZXR0ZXIgaWYgeW91IGFyZSBmYXN0IGxpa2UgSGVybWVzLg==" },
+          { "They say that when you wear a circular amulet you might resemble a troll.", 
+            "VGhleSBzYXkgdGhhdCB3aGVuIHlvdSB3ZWFyIGEgY2lyY3VsYXIgYW11bGV0IHlvdSBtaWdodCByZXNlbWJsZSBhIHRyb2xsLg==" },
+          { "They say that when you're hungry you can get a pizza in 30 moves or it's free.", 
+            "VGhleSBzYXkgdGhhdCB3aGVuIHlvdSdyZSBodW5ncnkgeW91IGNhbiBnZXQgYSBwaXp6YSBpbiAzMCBtb3ZlcyBvciBpdCdzIGZyZWUu" },
+          { "They say that when your god is angry you should try another one.", 
+            "VGhleSBzYXkgdGhhdCB3aGVuIHlvdXIgZ29kIGlzIGFuZ3J5IHlvdSBzaG91bGQgdHJ5IGFub3RoZXIgb25lLg==" },
+          { "They say that wielding a unicorn horn takes strength.", 
+            "VGhleSBzYXkgdGhhdCB3aWVsZGluZyBhIHVuaWNvcm4gaG9ybiB0YWtlcyBzdHJlbmd0aC4=" },
+          { "They say that with speed boots you never worry about hit and run accidents.", 
+            "VGhleSBzYXkgdGhhdCB3aXRoIHNwZWVkIGJvb3RzIHlvdSBuZXZlciB3b3JyeSBhYm91dCBoaXQgYW5kIHJ1biBhY2NpZGVudHMu" },
+          { "They say that you can defeat a killer bee with a unicorn horn.", 
+            "VGhleSBzYXkgdGhhdCB5b3UgY2FuIGRlZmVhdCBhIGtpbGxlciBiZWUgd2l0aCBhIHVuaWNvcm4gaG9ybi4=" },
+          { "They say that you can only cross the River Styx in Charon's boat.", 
+            "VGhleSBzYXkgdGhhdCB5b3UgY2FuIG9ubHkgY3Jvc3MgdGhlIFJpdmVyIFN0eXggaW4gQ2hhcm9uJ3MgYm9hdC4=" },
+          { "They say that you can only kill a lich once and then you'd better be careful.", 
+            "VGhleSBzYXkgdGhhdCB5b3UgY2FuIG9ubHkga2lsbCBhIGxpY2ggb25jZSBhbmQgdGhlbiB5b3UnZCBiZXR0ZXIgYmUgY2FyZWZ1bC4=" },
+          { "They say that you can only wish for things you've already had.", 
+            "VGhleSBzYXkgdGhhdCB5b3UgY2FuIG9ubHkgd2lzaCBmb3IgdGhpbmdzIHlvdSd2ZSBhbHJlYWR5IGhhZC4=" },
+          { "They say that you can train a cat by talking gently to it.", 
+            "VGhleSBzYXkgdGhhdCB5b3UgY2FuIHRyYWluIGEgY2F0IGJ5IHRhbGtpbmcgZ2VudGx5IHRvIGl0Lg==" },
+          { "They say that you can train a dog by talking firmly to it.", 
+            "VGhleSBzYXkgdGhhdCB5b3UgY2FuIHRyYWluIGEgZG9nIGJ5IHRhbGtpbmcgZmlybWx5IHRvIGl0Lg==" },
+          { "They say that you can trust your gold with the king.", 
+            "VGhleSBzYXkgdGhhdCB5b3UgY2FuIHRydXN0IHlvdXIgZ29sZCB3aXRoIHRoZSBraW5nLg==" },
+          { "They say that you can't wipe your greasy bare hands on a blank scroll.", 
+            "VGhleSBzYXkgdGhhdCB5b3UgY2FuJ3Qgd2lwZSB5b3VyIGdyZWFzeSBiYXJlIGhhbmRzIG9uIGEgYmxhbmsgc2Nyb2xsLg==" },
+          { "They say that you cannot trust scrolls of rumor.", 
+            "VGhleSBzYXkgdGhhdCB5b3UgY2Fubm90IHRydXN0IHNjcm9sbHMgb2YgcnVtb3Iu" },
+          { "They say that you could fall head over heels for an energy vortex.", 
+            "VGhleSBzYXkgdGhhdCB5b3UgY291bGQgZmFsbCBoZWFkIG92ZXIgaGVlbHMgZm9yIGFuIGVuZXJneSB2b3J0ZXgu" },
+          { "They say that you need a key in order to open locked doors.", 
+            "VGhleSBzYXkgdGhhdCB5b3UgbmVlZCBhIGtleSBpbiBvcmRlciB0byBvcGVuIGxvY2tlZCBkb29ycy4=" },
+          { "They say that you need a mirror to notice a mimic in an antique shop.", 
+            "VGhleSBzYXkgdGhhdCB5b3UgbmVlZCBhIG1pcnJvciB0byBub3RpY2UgYSBtaW1pYyBpbiBhbiBhbnRpcXVlIHNob3Au" },
+          { "They say that you really can use a pick-axe unless you really can't.", 
+            "VGhleSBzYXkgdGhhdCB5b3UgcmVhbGx5IGNhbiB1c2UgYSBwaWNrLWF4ZSB1bmxlc3MgeW91IHJlYWxseSBjYW4ndC4=" },
+          { "They say that you should always store your tools in the cellar.", 
+            "VGhleSBzYXkgdGhhdCB5b3Ugc2hvdWxkIGFsd2F5cyBzdG9yZSB5b3VyIHRvb2xzIGluIHRoZSBjZWxsYXIu" },
+          { "They say that you should be careful while climbing the ladder to success.", 
+            "VGhleSBzYXkgdGhhdCB5b3Ugc2hvdWxkIGJlIGNhcmVmdWwgd2hpbGUgY2xpbWJpbmcgdGhlIGxhZGRlciB0byBzdWNjZXNzLg==" },
+          { "They say that you should call your armor `rustproof'.", 
+            "VGhleSBzYXkgdGhhdCB5b3Ugc2hvdWxkIGNhbGwgeW91ciBhcm1vciBgcnVzdHByb29mJy4=" },
+          { "They say that you should name your dog Spuds to have a cool pet.", 
+            "VGhleSBzYXkgdGhhdCB5b3Ugc2hvdWxkIG5hbWUgeW91ciBkb2cgU3B1ZHMgdG8gaGF2ZSBhIGNvb2wgcGV0Lg==" },
+          { "They say that you should name your weapon after your first monster kill.", 
+            "VGhleSBzYXkgdGhhdCB5b3Ugc2hvdWxkIG5hbWUgeW91ciB3ZWFwb24gYWZ0ZXIgeW91ciBmaXJzdCBtb25zdGVyIGtpbGwu" },
+          { "They say that you should never introduce a rope golem to a succubus.", 
+            "VGhleSBzYXkgdGhhdCB5b3Ugc2hvdWxkIG5ldmVyIGludHJvZHVjZSBhIHJvcGUgZ29sZW0gdG8gYSBzdWNjdWJ1cy4=" },
+          { "They say that you should never sleep near invisible ring wraiths.", 
+            "VGhleSBzYXkgdGhhdCB5b3Ugc2hvdWxkIG5ldmVyIHNsZWVwIG5lYXIgaW52aXNpYmxlIHJpbmcgd3JhaXRocy4=" },
+          { "They say that you should never try to leave the dungeon with a bag of gems.", 
+            "VGhleSBzYXkgdGhhdCB5b3Ugc2hvdWxkIG5ldmVyIHRyeSB0byBsZWF2ZSB0aGUgZHVuZ2VvbiB3aXRoIGEgYmFnIG9mIGdlbXMu" },
+          { "They say that you should remove your armor before sitting on a throne.", 
+            "VGhleSBzYXkgdGhhdCB5b3Ugc2hvdWxkIHJlbW92ZSB5b3VyIGFybW9yIGJlZm9yZSBzaXR0aW5nIG9uIGEgdGhyb25lLg==" },
+          { "This fortune cookie is copy protected.", 
+            "VGhpcyBmb3J0dW5lIGNvb2tpZSBpcyBjb3B5IHByb3RlY3RlZC4=" },
+          { "This fortune cookie is the property of Fortune Cookies, Inc.", 
+            "VGhpcyBmb3J0dW5lIGNvb2tpZSBpcyB0aGUgcHJvcGVydHkgb2YgRm9ydHVuZSBDb29raWVzLCBJbmMu" },
+          { "Tired? Try a scroll of charging on yourself.", 
+            "VGlyZWQ/IFRyeSBhIHNjcm9sbCBvZiBjaGFyZ2luZyBvbiB5b3Vyc2VsZi4=" },
+          { "To achieve the next higher rating, you need 3 more points.", 
+            "VG8gYWNoaWV2ZSB0aGUgbmV4dCBoaWdoZXIgcmF0aW5nLCB5b3UgbmVlZCAzIG1vcmUgcG9pbnRzLg==" },
+          { "To reach heaven, escape the dungeon while wearing a ring of levitation.", 
+            "VG8gcmVhY2ggaGVhdmVuLCBlc2NhcGUgdGhlIGR1bmdlb24gd2hpbGUgd2VhcmluZyBhIHJpbmcgb2YgbGV2aXRhdGlvbi4=" },
+          { "Tourists wear shirts loud enough to wake the dead.", 
+            "VG91cmlzdHMgd2VhciBzaGlydHMgbG91ZCBlbm91Z2ggdG8gd2FrZSB0aGUgZGVhZC4=" },
+          { "Try calling your katana Moulinette.", 
+            "VHJ5IGNhbGxpbmcgeW91ciBrYXRhbmEgTW91bGluZXR0ZS4=" },
+          { "Ulch! That meat was painted!", 
+            "VWxjaCEgVGhhdCBtZWF0IHdhcyBwYWludGVkIQ==" },
+          { "Unfortunately, this message was left intentionally blank.", 
+            "VW5mb3J0dW5hdGVseSwgdGhpcyBtZXNzYWdlIHdhcyBsZWZ0IGludGVudGlvbmFsbHkgYmxhbmsu" },
+          { "Using a morning star in the evening has no effect.", 
+            "VXNpbmcgYSBtb3JuaW5nIHN0YXIgaW4gdGhlIGV2ZW5pbmcgaGFzIG5vIGVmZmVjdC4=" },
+          { "Want a hint? Zap a wand of make invisible on your weapon!", 
+            "V2FudCBhIGhpbnQ/IFphcCBhIHdhbmQgb2YgbWFrZSBpbnZpc2libGUgb24geW91ciB3ZWFwb24h" },
+          { "Want to ascend in a hurry? Apply at Gizmonic Institute.", 
+            "V2FudCB0byBhc2NlbmQgaW4gYSBodXJyeT8gQXBwbHkgYXQgR2l6bW9uaWMgSW5zdGl0dXRlLg==" },
+          { "Wanted: shopkeepers. Send a scroll of mail to Mage of Yendor/Level 35/Dungeon.", 
+            "V2FudGVkOiBzaG9wa2VlcGVycy4gU2VuZCBhIHNjcm9sbCBvZiBtYWlsIHRvIE1hZ2Ugb2YgWWVuZG9yL0xldmVsIDM1L0R1bmdlb24u" },
+          { "Warning: fortune reading can be hazardous to your health.", 
+            "V2FybmluZzogZm9ydHVuZSByZWFkaW5nIGNhbiBiZSBoYXphcmRvdXMgdG8geW91ciBoZWFsdGgu" },
+          { "We have new ways of detecting treachery...", 
+            "V2UgaGF2ZSBuZXcgd2F5cyBvZiBkZXRlY3RpbmcgdHJlYWNoZXJ5Li4u" },
+          { "Wet towels make great weapons!", 
+            "V2V0IHRvd2VscyBtYWtlIGdyZWF0IHdlYXBvbnMh" },
+          { "What a pity, you cannot read it!", 
+            "V2hhdCBhIHBpdHksIHlvdSBjYW5ub3QgcmVhZCBpdCE=" },
+          { "When a piercer drops in on you, you will be tempted to hit the ceiling!", 
+            "V2hlbiBhIHBpZXJjZXIgZHJvcHMgaW4gb24geW91LCB5b3Ugd2lsbCBiZSB0ZW1wdGVkIHRvIGhpdCB0aGUgY2VpbGluZyE=" },
+          { "When in a maze follow the right wall and you will never get lost.", 
+            "V2hlbiBpbiBhIG1hemUgZm9sbG93IHRoZSByaWdodCB3YWxsIGFuZCB5b3Ugd2lsbCBuZXZlciBnZXQgbG9zdC4=" },
+          { "When you have a key, you don't have to wait for the guard.", 
+            "V2hlbiB5b3UgaGF2ZSBhIGtleSwgeW91IGRvbid0IGhhdmUgdG8gd2FpdCBmb3IgdGhlIGd1YXJkLg==" },
+          { "Why are you wasting time reading fortunes?", 
+            "V2h5IGFyZSB5b3Ugd2FzdGluZyB0aW1lIHJlYWRpbmcgZm9ydHVuZXM/" },
+          { "Wish for a master key and open the Magic Memory Vault!", 
+            "V2lzaCBmb3IgYSBtYXN0ZXIga2V5IGFuZCBvcGVuIHRoZSBNYWdpYyBNZW1vcnkgVmF1bHQh" },
+          { "Wizard expects every monster to do its duty.", 
+            "V2l6YXJkIGV4cGVjdHMgZXZlcnkgbW9uc3RlciB0byBkbyBpdHMgZHV0eS4=" },
+          { "Wow! You could've had a potion of fruit juice!", 
+            "V293ISBZb3UgY291bGQndmUgaGFkIGEgcG90aW9uIG9mIGZydWl0IGp1aWNlIQ==" },
+          { "Yet Another Silly Message (YASM).", 
+            "WWV0IEFub3RoZXIgU2lsbHkgTWVzc2FnZSAoWUFTTSku" },
+          { "You are destined to be misled by a fortune.", 
+            "WW91IGFyZSBkZXN0aW5lZCB0byBiZSBtaXNsZWQgYnkgYSBmb3J0dW5lLg==" },
+          { "You can get a genuine Amulet of Yendor by doing the following: --More--", 
+            "WW91IGNhbiBnZXQgYSBnZW51aW5lIEFtdWxldCBvZiBZZW5kb3IgYnkgZG9pbmcgdGhlIGZvbGxvd2luZzogLS1Nb3JlLS0=" },
+          { "You can protect yourself from black dragons by doing the following: --More--", 
+            "WW91IGNhbiBwcm90ZWN0IHlvdXJzZWxmIGZyb20gYmxhY2sgZHJhZ29ucyBieSBkb2luZyB0aGUgZm9sbG93aW5nOiAtLU1vcmUtLQ==" },
+          { "You can't get by the snake.", 
+            "WW91IGNhbid0IGdldCBieSB0aGUgc25ha2Uu" },
+          { "You feel like someone is pulling your leg.", 
+            "WW91IGZlZWwgbGlrZSBzb21lb25lIGlzIHB1bGxpbmcgeW91ciBsZWcu" },
+          { "You have to outwit the Sphynx or pay her.", 
+            "WW91IGhhdmUgdG8gb3V0d2l0IHRoZSBTcGh5bnggb3IgcGF5IGhlci4=" },
+          { "You hear the fortune cookie's hissing!", 
+            "WW91IGhlYXIgdGhlIGZvcnR1bmUgY29va2llJ3MgaGlzc2luZyE=" },
+          { "You may get rich selling letters, but beware of being blackmailed!", 
+            "WW91IG1heSBnZXQgcmljaCBzZWxsaW5nIGxldHRlcnMsIGJ1dCBiZXdhcmUgb2YgYmVpbmcgYmxhY2ttYWlsZWQh" },
+          { "You offend Shai-Hulud by sheathing your crysknife without having drawn blood.", 
+            "WW91IG9mZmVuZCBTaGFpLUh1bHVkIGJ5IHNoZWF0aGluZyB5b3VyIGNyeXNrbmlmZSB3aXRob3V0IGhhdmluZyBkcmF3biBibG9vZC4=" },
+          { "You swallowed the fortune!", 
+            "WW91IHN3YWxsb3dlZCB0aGUgZm9ydHVuZSE=" },
+          { "You want to regain strength? Two levels ahead is a guesthouse!", 
+            "WW91IHdhbnQgdG8gcmVnYWluIHN0cmVuZ3RoPyBUd28gbGV2ZWxzIGFoZWFkIGlzIGEgZ3Vlc3Rob3VzZSE=" },
+          { "You will encounter a tall, dark, and gruesome creature...", 
+            "WW91IHdpbGwgZW5jb3VudGVyIGEgdGFsbCwgZGFyaywgYW5kIGdydWVzb21lIGNyZWF0dXJlLi4u" },
+
+          { "The End", "VGhlIEVuZA==" }
+      };
+
+/* PL_Base64Encode, random strings */
+PRBool test_004(void)
+{
+    int i;
+    char result[ 4096 ];
+
+    printf("Test 004 (PL_Base64Encode, random strings)                            ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        PRUint32 plen = PL_strlen(array[i].plaintext);
+        PRUint32 clen = ((plen + 2)/3)*4;
+
+        char *rv = PL_Base64Encode(array[i].plaintext, plen, result);
+
+        if( rv != result )
+        {
+            printf("FAIL\n\t(%d): return value\n", i);
+            return PR_FALSE;
+        }
+
+        if( 0 != PL_strncmp(result, array[i].cyphertext, clen) )
+        {
+            printf("FAIL\n\t(%d, \"%s\"): expected \n\"%s,\" got \n\"%.*s.\"\n", 
+                   i, array[i].plaintext, array[i].cyphertext, clen, result);
+            return PR_FALSE;
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_Base64Encode, single characters, malloc */
+PRBool test_005(void)
+{
+    PRUint32 a, b;
+    unsigned char plain[ 4 ];
+    unsigned char cypher[ 5 ];
+    char *rv;
+
+    printf("Test 005 (PL_Base64Encode, single characters, malloc)                 ..."); fflush(stdout);
+
+    plain[1] = plain[2] = plain[3] = (unsigned char)0;
+    cypher[2] = cypher[3] = (unsigned char)'=';
+    cypher[4] = (unsigned char)0;
+
+    for( a = 0; a < 64; a++ )
+    {
+        cypher[0] = base[a];
+
+        for( b = 0; b < 4; b++ )
+        {
+            plain[0] = (unsigned char)(a * 4 + b);
+            cypher[1] = base[(b * 16)];
+
+            rv = PL_Base64Encode((char *)plain, 1, (char *)0);
+            if( (char *)0 == rv )
+            {
+                printf("FAIL\n\t(%d, %d): no return value\n", a, b);
+                return PR_FALSE;
+            }
+
+            if( 0 != PL_strcmp((char *)cypher, rv) )
+            {
+                printf("FAIL\n\t(%d, %d): expected \"%s,\" got \"%s.\"\n",
+                       a, b, cypher, rv);
+                PR_DELETE(rv);
+                return PR_FALSE;
+            }
+
+            PR_DELETE(rv);
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_Base64Encode, double characters, malloc */
+PRBool test_006(void)
+{
+    PRUint32 a, b, c, d;
+    unsigned char plain[ 4 ];
+    unsigned char cypher[ 5 ];
+    char *rv;
+
+    printf("Test 006 (PL_Base64Encode, double characters, malloc)                 ..."); fflush(stdout);
+
+    plain[2] = plain[3] = (unsigned char)0;
+    cypher[3] = (unsigned char)'=';
+    cypher[4] = (unsigned char)0;
+
+    for( a = 0; a < 64; a++ )
+    {
+        cypher[0] = base[a];
+        for( b = 0; b < 4; b++ )
+        {
+            plain[0] = (a*4) + b;
+            for( c = 0; c < 16; c++ )
+            {
+                cypher[1] = base[b*16 + c];
+                for( d = 0; d < 16; d++ )
+                {
+                    plain[1] = c*16 + d;
+                    cypher[2] = base[d*4];
+
+                    rv = PL_Base64Encode((char *)plain, 2, (char *)0);
+                    if( (char *)0 == rv )
+                    {
+                        printf("FAIL\n\t(%d, %d, %d, %d): no return value\n", a, b, c, d);
+                        return PR_FALSE;
+                    }
+
+                    if( 0 != PL_strcmp((char *)cypher, rv) )
+                    {
+                        printf("FAIL\n\t(%d, %d, %d, %d): expected \"%s,\" got \"%s.\"\n",
+                               a, b, c, d, cypher, rv);
+                        PR_DELETE(rv);
+                        return PR_FALSE;
+                    }
+
+                    PR_DELETE(rv);
+                }
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_Base64Encode, triple characters, malloc */
+PRBool test_007(void)
+{
+    PRUint32 a, b, c, d, e, f;
+    unsigned char plain[ 4 ];
+    unsigned char cypher[ 5 ];
+    char *rv;
+
+    printf("Test 007 (PL_Base64Encode, triple characters, malloc)                 ..."); fflush(stdout);
+
+    cypher[4] = (unsigned char)0;
+
+    for( a = 0; a < 64; a++ )
+    {
+        cypher[0] = base[a];
+        for( b = 0; b < 4; b++ )
+        {
+            plain[0] = (a*4) + b;
+            for( c = 0; c < 16; c++ )
+            {
+                cypher[1] = base[b*16 + c];
+                for( d = 0; d < 16; d++ )
+                {
+                    plain[1] = c*16 + d;
+                    for( e = 0; e < 4; e++ )
+                    {
+                        cypher[2] = base[d*4 + e];
+                        for( f = 0; f < 64; f++ )
+                        {
+                            plain[2] = e * 64 + f;
+                            cypher[3] = base[f];
+
+                            rv = PL_Base64Encode((char *)plain, 3, (char *)0);
+                            if( (char *)0 == rv )
+                            {
+                                printf("FAIL\n\t(%d, %d, %d, %d, %d, %d): no return value\n", a, b, c, d, e, f);
+                                return PR_FALSE;
+                            }
+
+                            if( 0 != PL_strcmp((char *)cypher, rv) )
+                            {
+                                printf("FAIL\n\t(%d, %d, %d, %d, %d, %d): expected \"%s,\" got \"%.4s.\"\n",
+                                       a, b, c, d, e, f, cypher, rv);
+                                PR_DELETE(rv);
+                                return PR_FALSE;
+                            }
+
+                            PR_DELETE(rv);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_Base64Encode, random strings, malloc */
+PRBool test_008(void)
+{
+    int i;
+
+    printf("Test 008 (PL_Base64Encode, random strings, malloc)                    ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        PRUint32 plen = PL_strlen(array[i].plaintext);
+        PRUint32 clen = ((plen + 2)/3)*4;
+
+        char *rv = PL_Base64Encode(array[i].plaintext, plen, (char *)0);
+
+        if( (char *)0 == rv )
+        {
+            printf("FAIL\n\t(%d): no return value\n", i);
+            return PR_FALSE;
+        }
+
+        if( 0 != PL_strcmp(rv, array[i].cyphertext) )
+        {
+            printf("FAIL\n\t(%d, \"%s\"): expected \n\"%s,\" got \n\"%s.\"\n", 
+                   i, array[i].plaintext, array[i].cyphertext, rv);
+            return PR_FALSE;
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_Base64Decode, single characters */
+PRBool test_009(void)
+{
+    PRUint32 a, b;
+    unsigned char plain[ 4 ];
+    unsigned char cypher[ 5 ];
+    char result[ 8 ];
+    char *rv;
+
+    printf("Test 009 (PL_Base64Decode, single characters, equals)                 ..."); fflush(stdout);
+
+    plain[1] = plain[2] = plain[3] = (unsigned char)0;
+    cypher[2] = cypher[3] = (unsigned char)'=';
+    cypher[4] = (unsigned char)0;
+
+    for( a = 0; a < 64; a++ )
+    {
+        cypher[0] = base[a];
+
+        for( b = 0; b < 4; b++ )
+        {
+            plain[0] = (unsigned char)(a * 4 + b);
+            cypher[1] = base[(b * 16)];
+
+            rv = PL_Base64Decode((char *)cypher, 4, result);
+            if( rv != result )
+            {
+                printf("FAIL\n\t(%d, %d): return value\n", a, b);
+                return PR_FALSE;
+            }
+
+            if( 0 != PL_strncmp((char *)plain, result, 1) )
+            {
+                printf("FAIL\n\t(%d, %d): expected \"%s,\" got \"%.1s.\"\n",
+                       a, b, plain, result);
+                return PR_FALSE;
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_Base64Decode, single characters */
+PRBool test_010(void)
+{
+    PRUint32 a, b;
+    unsigned char plain[ 4 ];
+    unsigned char cypher[ 5 ];
+    char result[ 8 ];
+    char *rv;
+
+    printf("Test 010 (PL_Base64Decode, single characters, no equals)              ..."); fflush(stdout);
+
+    plain[1] = plain[2] = plain[3] = (unsigned char)0;
+    cypher[2] = cypher[3] = (unsigned char)0;
+    cypher[4] = (unsigned char)0;
+
+    for( a = 0; a < 64; a++ )
+    {
+        cypher[0] = base[a];
+
+        for( b = 0; b < 4; b++ )
+        {
+            plain[0] = (unsigned char)(a * 4 + b);
+            cypher[1] = base[(b * 16)];
+
+            rv = PL_Base64Decode((char *)cypher, 2, result);
+            if( rv != result )
+            {
+                printf("FAIL\n\t(%d, %d): return value\n", a, b);
+                return PR_FALSE;
+            }
+
+            if( 0 != PL_strncmp((char *)plain, result, 1) )
+            {
+                printf("FAIL\n\t(%d, %d): expected \"%s,\" got \"%.1s.\"\n",
+                       a, b, plain, result);
+                return PR_FALSE;
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_Base64Decode, double characters */
+PRBool test_011(void)
+{
+    PRUint32 a, b, c, d;
+    unsigned char plain[ 4 ];
+    unsigned char cypher[ 5 ];
+    char result[ 8 ];
+    char *rv;
+
+    printf("Test 011 (PL_Base64Decode, double characters, equals)                 ..."); fflush(stdout);
+
+    plain[2] = plain[3] = (unsigned char)0;
+    cypher[3] = (unsigned char)'=';
+    cypher[4] = (unsigned char)0;
+
+    for( a = 0; a < 64; a++ )
+    {
+        cypher[0] = base[a];
+        for( b = 0; b < 4; b++ )
+        {
+            plain[0] = (a*4) + b;
+            for( c = 0; c < 16; c++ )
+            {
+                cypher[1] = base[b*16 + c];
+                for( d = 0; d < 16; d++ )
+                {
+                    plain[1] = c*16 + d;
+                    cypher[2] = base[d*4];
+
+                    rv = PL_Base64Decode((char *)cypher, 4, result);
+                    if( rv != result )
+                    {
+                        printf("FAIL\n\t(%d, %d, %d, %d): return value\n", a, b, c, d);
+                        return PR_FALSE;
+                    }
+
+                    if( 0 != PL_strncmp((char *)plain, result, 2) )
+                    {
+                        printf("FAIL\n\t(%d, %d, %d, %d): expected \"%s,\" got \"%.2s.\"\n",
+                               a, b, c, d, plain, result);
+                        return PR_FALSE;
+                    }
+                }
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_Base64Decode, double characters */
+PRBool test_012(void)
+{
+    PRUint32 a, b, c, d;
+    unsigned char plain[ 4 ];
+    unsigned char cypher[ 5 ];
+    char result[ 8 ];
+    char *rv;
+
+    printf("Test 012 (PL_Base64Decode, double characters, no equals)              ..."); fflush(stdout);
+
+    plain[2] = plain[3] = (unsigned char)0;
+    cypher[3] = (unsigned char)0;
+    cypher[4] = (unsigned char)0;
+
+    for( a = 0; a < 64; a++ )
+    {
+        cypher[0] = base[a];
+        for( b = 0; b < 4; b++ )
+        {
+            plain[0] = (a*4) + b;
+            for( c = 0; c < 16; c++ )
+            {
+                cypher[1] = base[b*16 + c];
+                for( d = 0; d < 16; d++ )
+                {
+                    plain[1] = c*16 + d;
+                    cypher[2] = base[d*4];
+
+                    rv = PL_Base64Decode((char *)cypher, 3, result);
+                    if( rv != result )
+                    {
+                        printf("FAIL\n\t(%d, %d, %d, %d): return value\n", a, b, c, d);
+                        return PR_FALSE;
+                    }
+
+                    if( 0 != PL_strncmp((char *)plain, result, 2) )
+                    {
+                        printf("FAIL\n\t(%d, %d, %d, %d): expected \"%s,\" got \"%.2s.\"\n",
+                               a, b, c, d, cypher, result);
+                        return PR_FALSE;
+                    }
+                }
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_Base64Decode, triple characters */
+PRBool test_013(void)
+{
+    PRUint32 a, b, c, d, e, f;
+    unsigned char plain[ 4 ];
+    unsigned char cypher[ 5 ];
+    char result[ 8 ];
+    char *rv;
+
+    printf("Test 013 (PL_Base64Decode, triple characters)                         ..."); fflush(stdout);
+
+    cypher[4] = (unsigned char)0;
+
+    for( a = 0; a < 64; a++ )
+    {
+        cypher[0] = base[a];
+        for( b = 0; b < 4; b++ )
+        {
+            plain[0] = (a*4) + b;
+            for( c = 0; c < 16; c++ )
+            {
+                cypher[1] = base[b*16 + c];
+                for( d = 0; d < 16; d++ )
+                {
+                    plain[1] = c*16 + d;
+                    for( e = 0; e < 4; e++ )
+                    {
+                        cypher[2] = base[d*4 + e];
+                        for( f = 0; f < 64; f++ )
+                        {
+                            plain[2] = e * 64 + f;
+                            cypher[3] = base[f];
+
+                            rv = PL_Base64Decode((char *)cypher, 4, result);
+                            if( rv != result )
+                            {
+                                printf("FAIL\n\t(%d, %d, %d, %d, %d, %d): return value\n", a, b, c, d, e, f);
+                                return PR_FALSE;
+                            }
+
+                            if( 0 != PL_strncmp((char *)plain, result, 3) )
+                            {
+                                printf("FAIL\n\t(%d, %d, %d, %d, %d, %d): expected \"%s,\" got \"%.3s.\"\n",
+                                       a, b, c, d, e, f, plain, result);
+                                return PR_FALSE;
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_Base64Decode, random strings */
+PRBool test_014(void)
+{
+    int i;
+    char result[ 4096 ];
+
+    printf("Test 014 (PL_Base64Decode, random strings, equals)                    ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        PRUint32 clen = PL_strlen(array[i].cyphertext);
+        PRUint32 plen = (clen * 3) / 4;
+
+        char *rv = PL_Base64Decode(array[i].cyphertext, clen, result);
+
+        if( rv != result )
+        {
+            printf("FAIL\n\t(%d): return value\n", i);
+            return PR_FALSE;
+        }
+
+        if( 0 == (clen & 3) )
+        {
+            if( '=' == array[i].cyphertext[clen-1] )
+            {
+                if( '=' == array[i].cyphertext[clen-2] )
+                {
+                    plen -= 2;
+                }
+                else
+                {
+                    plen -= 1;
+                }
+            }
+        }
+
+        if( 0 != PL_strncmp(result, array[i].plaintext, plen) )
+        {
+            printf("FAIL\n\t(%d, \"%s\"): expected \n\"%s,\" got \n\"%.*s.\"\n", 
+                   i, array[i].cyphertext, array[i].plaintext, plen, result);
+            return PR_FALSE;
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_Base64Decode, random strings */
+PRBool test_015(void)
+{
+    int i;
+    char buffer[ 4096 ];
+    char result[ 4096 ];
+    char *rv;
+
+    printf("Test 015 (PL_Base64Decode, random strings, no equals)                 ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        PRUint32 clen, plen;
+
+        PL_strcpy(buffer, array[i].cyphertext);
+        clen = PL_strlen(buffer);
+
+        if( 0 == (clen & 3) )
+        {
+            if( '=' == buffer[clen-1] )
+            {
+                if( '=' == buffer[clen-2] )
+                {
+                    buffer[clen-2] = buffer[clen-1] = (char)0;
+                    clen -= 2;
+                }
+                else
+                {
+                    buffer[clen-1] = (char)0;
+                    clen -= 1;
+                }
+            }
+        }
+
+        plen = (clen * 3) / 4;
+
+        rv = PL_Base64Decode(buffer, clen, result);
+
+        if( rv != result )
+        {
+            printf("FAIL\n\t(%d): return value\n", i);
+            return PR_FALSE;
+        }
+
+        if( 0 != PL_strncmp(result, array[i].plaintext, plen) )
+        {
+            printf("FAIL\n\t(%d, \"%s\"): expected \n\"%s,\" got \n\"%.*s.\"\n", 
+                   i, array[i].cyphertext, array[i].plaintext, plen, result);
+            return PR_FALSE;
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_Base64Decode, single characters, malloc */
+PRBool test_016(void)
+{
+    PRUint32 a, b;
+    unsigned char plain[ 4 ];
+    unsigned char cypher[ 5 ];
+    char *rv;
+
+    printf("Test 016 (PL_Base64Decode, single characters, equals, malloc)         ..."); fflush(stdout);
+
+    plain[1] = plain[2] = plain[3] = (unsigned char)0;
+    cypher[2] = cypher[3] = (unsigned char)'=';
+    cypher[4] = (unsigned char)0;
+
+    for( a = 0; a < 64; a++ )
+    {
+        cypher[0] = base[a];
+
+        for( b = 0; b < 4; b++ )
+        {
+            plain[0] = (unsigned char)(a * 4 + b);
+            cypher[1] = base[(b * 16)];
+
+            rv = PL_Base64Decode((char *)cypher, 4, (char *)0);
+            if( (char *)0 == rv )
+            {
+                printf("FAIL\n\t(%d, %d): no return value\n", a, b);
+                return PR_FALSE;
+            }
+
+            if( 0 != PL_strcmp((char *)plain, rv) )
+            {
+                printf("FAIL\n\t(%d, %d): expected \"%s,\" got \"%s.\"\n",
+                       a, b, plain, rv);
+                PR_DELETE(rv);
+                return PR_FALSE;
+            }
+
+            PR_DELETE(rv);
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_Base64Decode, single characters, malloc */
+PRBool test_017(void)
+{
+    PRUint32 a, b;
+    unsigned char plain[ 4 ];
+    unsigned char cypher[ 5 ];
+    char *rv;
+
+    printf("Test 017 (PL_Base64Decode, single characters, no equals, malloc)      ..."); fflush(stdout);
+
+    plain[1] = plain[2] = plain[3] = (unsigned char)0;
+    cypher[2] = cypher[3] = (unsigned char)0;
+    cypher[4] = (unsigned char)0;
+
+    for( a = 0; a < 64; a++ )
+    {
+        cypher[0] = base[a];
+
+        for( b = 0; b < 4; b++ )
+        {
+            plain[0] = (unsigned char)(a * 4 + b);
+            cypher[1] = base[(b * 16)];
+
+            rv = PL_Base64Decode((char *)cypher, 2, (char *)0);
+            if( (char *)0 == rv )
+            {
+                printf("FAIL\n\t(%d, %d): no return value\n", a, b);
+                return PR_FALSE;
+            }
+
+            if( 0 != PL_strcmp((char *)plain, rv) )
+            {
+                printf("FAIL\n\t(%d, %d): expected \"%s,\" got \"%s.\"\n",
+                       a, b, plain, rv);
+                PR_DELETE(rv);
+                return PR_FALSE;
+            }
+
+            PR_DELETE(rv);
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_Base64Decode, double characters, malloc */
+PRBool test_018(void)
+{
+    PRUint32 a, b, c, d;
+    unsigned char plain[ 4 ];
+    unsigned char cypher[ 5 ];
+    char *rv;
+
+    printf("Test 018 (PL_Base64Decode, double characters, equals, malloc)         ..."); fflush(stdout);
+
+    plain[2] = plain[3] = (unsigned char)0;
+    cypher[3] = (unsigned char)'=';
+    cypher[4] = (unsigned char)0;
+
+    for( a = 0; a < 64; a++ )
+    {
+        cypher[0] = base[a];
+        for( b = 0; b < 4; b++ )
+        {
+            plain[0] = (a*4) + b;
+            for( c = 0; c < 16; c++ )
+            {
+                cypher[1] = base[b*16 + c];
+                for( d = 0; d < 16; d++ )
+                {
+                    plain[1] = c*16 + d;
+                    cypher[2] = base[d*4];
+
+                    rv = PL_Base64Decode((char *)cypher, 4, (char *)0);
+                    if( (char *)0 == rv )
+                    {
+                        printf("FAIL\n\t(%d, %d, %d, %d): no return value\n", a, b, c, d);
+                        return PR_FALSE;
+                    }
+
+                    if( 0 != PL_strcmp((char *)plain, rv) )
+                    {
+                        printf("FAIL\n\t(%d, %d, %d, %d): expected \"%s,\" got \"%s.\"\n",
+                               a, b, c, d, plain, rv);
+                        PR_DELETE(rv);
+                        return PR_FALSE;
+                    }
+
+                    PR_DELETE(rv);
+                }
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_Base64Decode, double characters, malloc */
+PRBool test_019(void)
+{
+    PRUint32 a, b, c, d;
+    unsigned char plain[ 4 ];
+    unsigned char cypher[ 5 ];
+    char *rv;
+
+    printf("Test 019 (PL_Base64Decode, double characters, no equals, malloc)      ..."); fflush(stdout);
+
+    plain[2] = plain[3] = (unsigned char)0;
+    cypher[3] = (unsigned char)0;
+    cypher[4] = (unsigned char)0;
+
+    for( a = 0; a < 64; a++ )
+    {
+        cypher[0] = base[a];
+        for( b = 0; b < 4; b++ )
+        {
+            plain[0] = (a*4) + b;
+            for( c = 0; c < 16; c++ )
+            {
+                cypher[1] = base[b*16 + c];
+                for( d = 0; d < 16; d++ )
+                {
+                    plain[1] = c*16 + d;
+                    cypher[2] = base[d*4];
+
+                    rv = PL_Base64Decode((char *)cypher, 3, (char *)0);
+                    if( (char *)0 == rv )
+                    {
+                        printf("FAIL\n\t(%d, %d, %d, %d): no return value\n", a, b, c, d);
+                        return PR_FALSE;
+                    }
+
+                    if( 0 != PL_strcmp((char *)plain, rv) )
+                    {
+                        printf("FAIL\n\t(%d, %d, %d, %d): expected \"%s,\" got \"%s.\"\n",
+                               a, b, c, d, cypher, rv);
+                        PR_DELETE(rv);
+                        return PR_FALSE;
+                    }
+
+                    PR_DELETE(rv);
+                }
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_Base64Decode, triple characters, malloc */
+PRBool test_020(void)
+{
+    PRUint32 a, b, c, d, e, f;
+    unsigned char plain[ 4 ];
+    unsigned char cypher[ 5 ];
+    char *rv;
+
+    printf("Test 020 (PL_Base64Decode, triple characters, malloc)                 ..."); fflush(stdout);
+
+    cypher[4] = (unsigned char)0;
+    plain[3] = (unsigned char)0;
+
+    for( a = 0; a < 64; a++ )
+    {
+        cypher[0] = base[a];
+        for( b = 0; b < 4; b++ )
+        {
+            plain[0] = (a*4) + b;
+            for( c = 0; c < 16; c++ )
+            {
+                cypher[1] = base[b*16 + c];
+                for( d = 0; d < 16; d++ )
+                {
+                    plain[1] = c*16 + d;
+                    for( e = 0; e < 4; e++ )
+                    {
+                        cypher[2] = base[d*4 + e];
+                        for( f = 0; f < 64; f++ )
+                        {
+                            plain[2] = e * 64 + f;
+                            cypher[3] = base[f];
+
+                            rv = PL_Base64Decode((char *)cypher, 4, (char *)0);
+                            if( (char *)0 == rv )
+                            {
+                                printf("FAIL\n\t(%d, %d, %d, %d, %d, %d): no return value\n", a, b, c, d, e, f);
+                                return PR_FALSE;
+                            }
+
+                            if( 0 != PL_strcmp((char *)plain, rv) )
+                            {
+                                printf("FAIL\n\t(%d, %d, %d, %d, %d, %d): expected \"%s,\" got \"%.3s.\"\n",
+                                       a, b, c, d, e, f, plain, rv);
+                                PR_DELETE(rv);
+                                return PR_FALSE;
+                            }
+
+                            PR_DELETE(rv);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_Base64Decode, random strings, malloc */
+PRBool test_021(void)
+{
+    int i;
+
+    printf("Test 021 (PL_Base64Decode, random strings, equals, malloc)            ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        PRUint32 clen = PL_strlen(array[i].cyphertext);
+
+        char *rv = PL_Base64Decode(array[i].cyphertext, clen, (char *)0);
+
+        if( (char *)0 == rv )
+        {
+            printf("FAIL\n\t(%d): no return value\n", i);
+            return PR_FALSE;
+        }
+
+        if( 0 != PL_strcmp(rv, array[i].plaintext) )
+        {
+            printf("FAIL\n\t(%d, \"%s\"): expected \n\"%s,\" got \n\"%s.\"\n", 
+                   i, array[i].cyphertext, array[i].plaintext, rv);
+            PR_DELETE(rv);
+            return PR_FALSE;
+        }
+
+        PR_DELETE(rv);
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_Base64Encode, random strings, malloc */
+PRBool test_022(void)
+{
+    int i;
+    char buffer[ 4096 ];
+    char *rv;
+
+    printf("Test 022 (PL_Base64Decode, random strings, no equals, malloc)         ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        PRUint32 clen;
+
+        PL_strcpy(buffer, array[i].cyphertext);
+        clen = PL_strlen(buffer);
+
+        if( 0 == (clen & 3) )
+        {
+            if( '=' == buffer[clen-1] )
+            {
+                if( '=' == buffer[clen-2] )
+                {
+                    buffer[clen-2] = buffer[clen-1] = (char)0;
+                    clen -= 2;
+                }
+                else
+                {
+                    buffer[clen-1] = (char)0;
+                    clen -= 1;
+                }
+            }
+        }
+
+        rv = PL_Base64Decode(buffer, clen, (char *)0);
+
+        if( (char *)0 == rv )
+        {
+            printf("FAIL\n\t(%d): no return value\n", i);
+            return PR_FALSE;
+        }
+
+        if( 0 != PL_strcmp(rv, array[i].plaintext) )
+        {
+            printf("FAIL\n\t(%d, \"%s\"): expected \n\"%s,\" got \n\"%s.\"\n", 
+                   i, array[i].cyphertext, array[i].plaintext, rv);
+            return PR_FALSE;
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_Base64Encode, random strings */
+PRBool test_023(void)
+{
+    int i;
+    char result[ 4096 ];
+
+    printf("Test 023 (PL_Base64Encode, random strings, strlen)                    ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        PRUint32 plen = PL_strlen(array[i].plaintext);
+        PRUint32 clen = ((plen + 2)/3)*4;
+
+        char *rv = PL_Base64Encode(array[i].plaintext, 0, result);
+
+        if( rv != result )
+        {
+            printf("FAIL\n\t(%d): return value\n", i);
+            return PR_FALSE;
+        }
+
+        if( 0 != PL_strncmp(result, array[i].cyphertext, clen) )
+        {
+            printf("FAIL\n\t(%d, \"%s\"): expected \n\"%s,\" got \n\"%.*s.\"\n", 
+                   i, array[i].plaintext, array[i].cyphertext, clen, result);
+            return PR_FALSE;
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_Base64Encode, random strings, malloc */
+PRBool test_024(void)
+{
+    int i;
+
+    printf("Test 024 (PL_Base64Encode, random strings, malloc, strlen)            ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        PRUint32 plen = PL_strlen(array[i].plaintext);
+        PRUint32 clen = ((plen + 2)/3)*4;
+
+        char *rv = PL_Base64Encode(array[i].plaintext, 0, (char *)0);
+
+        if( (char *)0 == rv )
+        {
+            printf("FAIL\n\t(%d): no return value\n", i);
+            return PR_FALSE;
+        }
+
+        if( 0 != PL_strcmp(rv, array[i].cyphertext) )
+        {
+            printf("FAIL\n\t(%d, \"%s\"): expected \n\"%s,\" got \n\"%s.\"\n", 
+                   i, array[i].plaintext, array[i].cyphertext, rv);
+            return PR_FALSE;
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_Base64Decode, random strings */
+PRBool test_025(void)
+{
+    int i;
+    char result[ 4096 ];
+
+    printf("Test 025 (PL_Base64Decode, random strings, equals, strlen)            ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        PRUint32 clen = PL_strlen(array[i].cyphertext);
+        PRUint32 plen = (clen * 3) / 4;
+
+        char *rv = PL_Base64Decode(array[i].cyphertext, 0, result);
+
+        if( rv != result )
+        {
+            printf("FAIL\n\t(%d): return value\n", i);
+            return PR_FALSE;
+        }
+
+        if( 0 == (clen & 3) )
+        {
+            if( '=' == array[i].cyphertext[clen-1] )
+            {
+                if( '=' == array[i].cyphertext[clen-2] )
+                {
+                    plen -= 2;
+                }
+                else
+                {
+                    plen -= 1;
+                }
+            }
+        }
+
+        if( 0 != PL_strncmp(result, array[i].plaintext, plen) )
+        {
+            printf("FAIL\n\t(%d, \"%s\"): expected \n\"%s,\" got \n\"%.*s.\"\n", 
+                   i, array[i].cyphertext, array[i].plaintext, plen, result);
+            return PR_FALSE;
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_Base64Decode, random strings */
+PRBool test_026(void)
+{
+    int i;
+    char buffer[ 4096 ];
+    char result[ 4096 ];
+    char *rv;
+
+    printf("Test 026 (PL_Base64Decode, random strings, no equals, strlen)         ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        PRUint32 clen, plen;
+
+        PL_strcpy(buffer, array[i].cyphertext);
+        clen = PL_strlen(buffer);
+
+        if( 0 == (clen & 3) )
+        {
+            if( '=' == buffer[clen-1] )
+            {
+                if( '=' == buffer[clen-2] )
+                {
+                    buffer[clen-2] = buffer[clen-1] = (char)0;
+                    clen -= 2;
+                }
+                else
+                {
+                    buffer[clen-1] = (char)0;
+                    clen -= 1;
+                }
+            }
+        }
+
+        plen = (clen * 3) / 4;
+
+        rv = PL_Base64Decode(buffer, 0, result);
+
+        if( rv != result )
+        {
+            printf("FAIL\n\t(%d): return value\n", i);
+            return PR_FALSE;
+        }
+
+        if( 0 != PL_strncmp(result, array[i].plaintext, plen) )
+        {
+            printf("FAIL\n\t(%d, \"%s\"): expected \n\"%s,\" got \n\"%.*s.\"\n", 
+                   i, array[i].cyphertext, array[i].plaintext, plen, result);
+            return PR_FALSE;
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_Base64Decode, random strings, malloc */
+PRBool test_027(void)
+{
+    int i;
+
+    printf("Test 027 (PL_Base64Decode, random strings, equals, malloc, strlen)    ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        PRUint32 clen = PL_strlen(array[i].cyphertext);
+
+        char *rv = PL_Base64Decode(array[i].cyphertext, 0, (char *)0);
+
+        if( (char *)0 == rv )
+        {
+            printf("FAIL\n\t(%d): no return value\n", i);
+            return PR_FALSE;
+        }
+
+        if( 0 != PL_strcmp(rv, array[i].plaintext) )
+        {
+            printf("FAIL\n\t(%d, \"%s\"): expected \n\"%s,\" got \n\"%s.\"\n", 
+                   i, array[i].cyphertext, array[i].plaintext, rv);
+            PR_DELETE(rv);
+            return PR_FALSE;
+        }
+
+        PR_DELETE(rv);
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_Base64Encode, random strings, malloc */
+PRBool test_028(void)
+{
+    int i;
+    char buffer[ 4096 ];
+    char *rv;
+
+    printf("Test 028 (PL_Base64Decode, random strings, no equals, malloc, strlen) ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        PRUint32 clen;
+
+        PL_strcpy(buffer, array[i].cyphertext);
+        clen = PL_strlen(buffer);
+
+        if( 0 == (clen & 3) )
+        {
+            if( '=' == buffer[clen-1] )
+            {
+                if( '=' == buffer[clen-2] )
+                {
+                    buffer[clen-2] = buffer[clen-1] = (char)0;
+                    clen -= 2;
+                }
+                else
+                {
+                    buffer[clen-1] = (char)0;
+                    clen -= 1;
+                }
+            }
+        }
+
+        rv = PL_Base64Decode(buffer, 0, (char *)0);
+
+        if( (char *)0 == rv )
+        {
+            printf("FAIL\n\t(%d): no return value\n", i);
+            return PR_FALSE;
+        }
+
+        if( 0 != PL_strcmp(rv, array[i].plaintext) )
+        {
+            printf("FAIL\n\t(%d, \"%s\"): expected \n\"%s,\" got \n\"%s.\"\n", 
+                   i, array[i].cyphertext, array[i].plaintext, rv);
+            return PR_FALSE;
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+int
+main
+(
+    int     argc,
+    char   *argv[]
+)
+{
+    printf("Testing the Portable Library base64 functions:\n");
+    printf("(warning: the \"triple characters\" tests are slow)\n");
+
+    if( 1
+        && test_001()
+        && test_002()
+        && test_003()
+        && test_004()
+        && test_005()
+        && test_006()
+        && test_007()
+        && test_008()
+        && test_009()
+        && test_010()
+        && test_011()
+        && test_012()
+        && test_013()
+        && test_014()
+        && test_015()
+        && test_016()
+        && test_017()
+        && test_018()
+        && test_019()
+        && test_020()
+        && test_021()
+        && test_022()
+        && test_023()
+        && test_024()
+        && test_025()
+        && test_026()
+        && test_027()
+        && test_028()
+      )
+    {
+        printf("Suite passed.\n");
+        return 0;
+    }
+    else
+    {
+        printf("Suite failed.\n");
+        return 1;
+    }
+
+    /*NOTREACHED*/
+}
diff --git a/lib/tests/getopt.c b/lib/tests/getopt.c
new file mode 100644
index 0000000..8737d81
--- /dev/null
+++ b/lib/tests/getopt.c
@@ -0,0 +1,44 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "nspr.h"
+#include "plgetopt.h"
+
+
+
+static const PLLongOpt optArray[] = {
+    { "longa", 'a'        , PR_TRUE  },
+    { "longb", 'b'        , PR_TRUE  },
+    { "longc", 'c'        , PR_FALSE },
+    { "longd", 'd' | 0x100, PR_TRUE  },
+    { "longe", 'e' | 0x100, PR_FALSE },
+    {    NULL,                       }
+};
+
+int
+main(int argc, char **argv) 
+{
+    PLOptState *opt;
+    PLOptStatus ostat;
+
+    opt = PL_CreateLongOptState(argc, argv, "a:b:c", optArray);
+
+    while (PL_OPT_OK == (ostat = PL_GetNextOpt(opt))) {
+	if (opt->option == 0 && opt->longOptIndex < 0) 
+	    printf("Positional parameter: \"%s\"\n", opt->value);
+	else
+	    printf("%s option: %x (\'%c\', index %d), argument: \"%s\"\n",
+		   (ostat == PL_OPT_BAD) ? "BAD" : "GOOD",
+		   opt->longOption, opt->option ? opt->option : ' ',
+		   opt->longOptIndex, opt->value);
+
+    }
+    printf("last result was %s\n", (ostat == PL_OPT_BAD) ? "BAD" : "EOL");
+    PL_DestroyOptState(opt);
+    return 0;
+}
diff --git a/lib/tests/string.c b/lib/tests/string.c
new file mode 100644
index 0000000..7e15d39
--- /dev/null
+++ b/lib/tests/string.c
@@ -0,0 +1,3084 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "plstr.h"
+#include "nspr.h"
+
+#include <stdio.h>
+
+/* PL_strlen */
+PRBool test_001(void)
+{
+    static struct
+    {
+        const char *str;
+        PRUint32    len;
+    } array[] =
+      {
+          { (const char *)0, 0 },
+          { "", 0 },
+          { "a", 1 },
+          { "abcdefg", 7 },
+          { "abcdefg\0hijk", 7 }
+      };
+
+    int i;
+
+    printf("Test 001 (PL_strlen)      ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        if( PL_strlen(array[i].str) != array[i].len )
+        {
+            printf("FAIL (%d: %s->%d, %d)\n", i, 
+                   array[i].str ? array[i].str : "(null)",
+                   PL_strlen(array[i].str), array[i].len);
+            return PR_FALSE;
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_strnlen */
+PRBool test_002(void)
+{
+    static struct
+    {
+        const char *str;
+        PRUint32    max;
+        PRUint32    len;
+    } array[] =
+      {
+          { (const char *)0, 0, 0 },
+          { (const char *)0, 12, 0 },
+          { "", 0, 0 },
+          { "", 12, 0 },
+          { "a", 0, 0 },
+          { "a", 1, 1 },
+          { "a", 12, 1 },
+          { "abcdefg", 0, 0 },
+          { "abcdefg", 1, 1 },
+          { "abcdefg", 7, 7 },
+          { "abcdefg", 12, 7 },
+          { "abcdefg\0hijk", 0, 0 },
+          { "abcdefg\0hijk", 1, 1 },
+          { "abcdefg\0hijk", 7, 7 },
+          { "abcdefg\0hijk", 12, 7 },
+      };
+
+    int i;
+
+    printf("Test 002 (PL_strnlen)     ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        if( PL_strnlen(array[i].str, array[i].max) != array[i].len )
+        {
+            printf("FAIL (%d: %s,%d->%d, %d)\n", i,
+                   array[i].str ? array[i].str : "(null)", array[i].max,
+                   PL_strnlen(array[i].str, array[i].max), array[i].len);
+            return PR_FALSE;
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_strcpy */
+PRBool test_003(void)
+{
+    static char buffer[ 1024 ];
+
+    static struct
+    {
+        const char *str;
+        char       *dest;
+        char       *rv;
+        PRBool      comp;
+    } array[] =
+      {
+          { (const char *)0, (char *)0, (char *)0, PR_FALSE },
+          { (const char *)0, buffer, (char *)0, PR_FALSE },
+          { "", (char *)0, (char *)0, PR_FALSE },
+          { "", buffer, buffer, PR_TRUE },
+          { "a", (char *)0, (char *)0, PR_FALSE },
+          { "a", buffer, buffer, PR_TRUE },
+          { "abcdefg", (char *)0, (char *)0, PR_FALSE },
+          { "abcdefg", buffer, buffer, PR_TRUE },
+          { "wxyz\0abcdefg", (char *)0, (char *)0, PR_FALSE },
+          { "wxyz\0abcdefg", buffer, buffer, PR_TRUE }
+      };
+
+    int i;
+
+    printf("Test 003 (PL_strcpy)      ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        char *rv;
+        const char *a = array[i].str;
+        const char *b = (const char *)array[i].dest;
+
+        rv = PL_strcpy(array[i].dest, array[i].str);
+        if( array[i].rv != rv )
+        {
+            printf("FAIL %d: (0x%x, %s)->0x%x\n", i, array[i].dest,
+                   array[i].str ? array[i].str : "(null)", rv);
+            return PR_FALSE;
+        }
+
+        if( array[i].comp )
+        {
+            while( 1 )
+            {
+                if( *a != *b )
+                {
+                    printf("FAIL %d: %s->%.32s\n", i, 
+                           array[i].str ? array[i].str : "(null)", 
+                           array[i].dest ? array[i].dest : "(null)");
+                    return PR_FALSE;
+                }
+
+                if( (char)0 == *a ) break;
+
+                a++;
+                b++;
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_strncpy */
+PRBool test_004(void)
+{
+    static char buffer[ 1024 ];
+
+    static struct
+    {
+        const char *str;
+        PRUint32    len;
+        char       *dest;
+        char       *rv;
+        PRBool      comp;
+        const char *result;
+        PRBool      nulled;
+    } array[] =
+      {
+          { (const char *)0, 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+          { (const char *)0, 0, buffer, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+          { (const char *)0, 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+          { (const char *)0, 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+          { (const char *)0, 1, buffer, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+          { (const char *)0, 7, buffer, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+          { "", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+          { "", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
+          { "", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+          { "", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+          { "", 1, buffer, buffer, PR_TRUE, "", PR_TRUE },
+          { "", 7, buffer, buffer, PR_TRUE, "", PR_TRUE },
+          { "a", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+          { "a", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
+          { "a", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+          { "a", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+          { "b", 1, buffer, buffer, PR_TRUE, "b", PR_FALSE },
+          { "c", 7, buffer, buffer, PR_TRUE, "c", PR_TRUE },
+          { "de", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+          { "de", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
+          { "de", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+          { "de", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+          { "fg", 1, buffer, buffer, PR_TRUE, "f", PR_FALSE },
+          { "hi", 7, buffer, buffer, PR_TRUE, "hi", PR_TRUE },
+          { "jklmnopq", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+          { "jklmnopq", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
+          { "jklmnopq", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+          { "jklmnopq", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+          { "rstuvwxy", 1, buffer, buffer, PR_TRUE, "r", PR_FALSE },
+          { "zABCDEFG", 7, buffer, buffer, PR_TRUE, "zABCDEF", PR_FALSE },
+          { "a\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+          { "a\0XXX", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
+          { "a\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+          { "a\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+          { "b\0XXX", 1, buffer, buffer, PR_TRUE, "b", PR_FALSE },
+          { "c\0XXX", 7, buffer, buffer, PR_TRUE, "c", PR_TRUE },
+          { "de\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+          { "de\0XXX", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
+          { "de\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+          { "de\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+          { "fg\0XXX", 1, buffer, buffer, PR_TRUE, "f", PR_FALSE },
+          { "hi\0XXX", 7, buffer, buffer, PR_TRUE, "hi", PR_TRUE },
+          { "jklmnopq\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+          { "jklmnopq\0XXX", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
+          { "jklmnopq\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+          { "jklmnopq\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+          { "rstuvwxy\0XXX", 1, buffer, buffer, PR_TRUE, "r", PR_FALSE },
+          { "zABCDEFG\0XXX", 7, buffer, buffer, PR_TRUE, "zABCDEF", PR_FALSE },
+      };
+
+    int i;
+
+    printf("Test 004 (PL_strncpy)     ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        char *rv;
+        int j;
+
+        for( j = 0; j < sizeof(buffer); j++ )
+            buffer[j] = '-';
+
+        rv = PL_strncpy(array[i].dest, array[i].str, array[i].len);
+        if( array[i].rv != rv )
+        {
+            printf("FAIL %d: (0x%x, %s, %lu)->0x%x\n", i, array[i].dest,
+                   array[i].str ? array[i].str : "(null)", array[i].len, rv);
+            return PR_FALSE;
+        }
+
+        if( array[i].comp )
+        {
+            const char *a = array[i].result;
+            const char *b = array[i].dest;
+
+            while( *a )
+            {
+                if( *a != *b )
+                {
+                    printf("FAIL %d: %s != %.32s\n", i, 
+                           array[i].result, array[i].dest);
+                    return PR_FALSE;
+                }
+
+                a++;
+                b++;
+            }
+
+            if( array[i].nulled )
+            {
+                if( *b != '\0' )
+                {
+                    printf("FAIL %d: not terminated\n", i);
+                    return PR_FALSE;
+                }
+            }
+            else
+            {
+                if( *b != '-' )
+                {
+                    printf("FAIL %d: overstepped\n", i);
+                    return PR_FALSE;
+                }
+            }
+        }
+    }
+                
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_strncpyz */
+PRBool test_005(void)
+{
+    static char buffer[ 1024 ];
+
+    static struct
+    {
+        const char *str;
+        PRUint32    len;
+        char       *dest;
+        char       *rv;
+        PRBool      comp;
+        const char *result;
+    } array[] =
+      {
+          { (const char *)0, 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+          { (const char *)0, 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
+          { (const char *)0, 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+          { (const char *)0, 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+          { (const char *)0, 1, buffer, (char *)0, PR_FALSE, (const char *)0 },
+          { (const char *)0, 7, buffer, (char *)0, PR_FALSE, (const char *)0 },
+          { "", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+          { "", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
+          { "", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+          { "", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+          { "", 1, buffer, buffer, PR_TRUE, "" },
+          { "", 7, buffer, buffer, PR_TRUE, "" },
+          { "a", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+          { "a", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
+          { "a", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+          { "a", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+          { "b", 1, buffer, buffer, PR_TRUE, "" },
+          { "c", 7, buffer, buffer, PR_TRUE, "c" },
+          { "de", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+          { "de", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
+          { "de", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+          { "de", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+          { "fg", 1, buffer, buffer, PR_TRUE, "" },
+          { "hi", 7, buffer, buffer, PR_TRUE, "hi" },
+          { "jklmnopq", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+          { "jklmnopq", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
+          { "jklmnopq", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+          { "jklmnopq", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+          { "rstuvwxy", 1, buffer, buffer, PR_TRUE, "" },
+          { "zABCDEFG", 7, buffer, buffer, PR_TRUE, "zABCDE" },
+          { "a\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+          { "a\0XXX", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
+          { "a\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+          { "a\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+          { "b\0XXX", 1, buffer, buffer, PR_TRUE, "" },
+          { "c\0XXX", 7, buffer, buffer, PR_TRUE, "c" },
+          { "de\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+          { "de\0XXX", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
+          { "de\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+          { "de\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+          { "fg\0XXX", 1, buffer, buffer, PR_TRUE, "" },
+          { "hi\0XXX", 7, buffer, buffer, PR_TRUE, "hi" },
+          { "jklmnopq\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+          { "jklmnopq\0XXX", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
+          { "jklmnopq\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+          { "jklmnopq\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+          { "rstuvwxy\0XXX", 1, buffer, buffer, PR_TRUE, "" },
+          { "zABCDEFG\0XXX", 7, buffer, buffer, PR_TRUE, "zABCDE" },
+      };
+
+    int i;
+
+    printf("Test 005 (PL_strncpyz)    ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        char *rv;
+        int j;
+
+        for( j = 0; j < sizeof(buffer); j++ )
+            buffer[j] = '-';
+
+        rv = PL_strncpyz(array[i].dest, array[i].str, array[i].len);
+        if( array[i].rv != rv )
+        {
+            printf("FAIL %d: (0x%x, %s, %lu)->0x%x\n", i, array[i].dest,
+                   array[i].str ? array[i].str : "(null)", array[i].len, rv);
+            return PR_FALSE;
+        }
+
+        if( array[i].comp )
+        {
+            const char *a = array[i].result;
+            const char *b = array[i].dest;
+
+            while( 1 )
+            {
+                if( *a != *b )
+                {
+                    printf("FAIL %d: %s != %.32s\n", i, 
+                           array[i].result, array[i].dest);
+                    return PR_FALSE;
+                }
+
+                if( (char)0 == *a ) break;
+
+                a++;
+                b++;
+            }
+        }
+    }
+                
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_strdup */
+PRBool test_006(void)
+{
+    static const char *array[] =
+    {
+        (const char *)0,
+        "",
+        "a",
+        "abcdefg"
+    };
+
+    int i;
+
+    printf("Test 006 (PL_strdup)      ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        char *rv = PL_strdup(array[i]);
+
+        if( (char *)0 == rv )
+        {
+            printf("FAIL %d: 0x%x -> 0\n", i, array[i]);
+            return PR_FALSE;
+        }
+
+        if( (const char *)0 == array[i] )
+        {
+            if( (char)0 != *rv )
+            {
+                printf("FAIL %d: (const char *)0 -> %.32s\n", i, rv);
+                return PR_FALSE;
+            }
+        }
+        else
+        {
+            const char *a = array[i];
+            const char *b = (const char *)rv;
+
+            while( 1 )
+            {
+                if( *a != *b )
+                {
+                    printf("FAIL %d: %s != %.32s\n", i, array[i], rv);
+                    return PR_FALSE;
+                }
+
+                if( (char)0 == *a ) break;
+
+                a++;
+                b++;
+            }
+
+        }
+        PL_strfree(rv);
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_strndup */
+PRBool test_007(void)
+{
+    static struct
+    {
+        const char *str;
+        PRUint32    len;
+        const char *result;
+    } array[] =
+      {
+          { (const char *)0, 0, "" },
+          { (const char *)0, 1, "" },
+          { (const char *)0, 7, "" },
+          { "", 0, "" },
+          { "", 1, "" },
+          { "", 7, "" },
+          { "a", 0, "" },
+          { "a", 1, "a" },
+          { "a", 7, "a" },
+          { "ab", 0, "" },
+          { "ab", 1, "a" },
+          { "ab", 7, "ab" },
+          { "abcdefg", 0, "" },
+          { "abcdefg", 1, "a" },
+          { "abcdefg", 7, "abcdefg" },
+          { "abcdefghijk", 0, "" },
+          { "abcdefghijk", 1, "a" },
+          { "abcdefghijk", 7, "abcdefg" },
+          { "abcdef\0ghijk", 0, "" },
+          { "abcdef\0ghijk", 1, "a" },
+          { "abcdef\0ghijk", 7, "abcdef" }
+      };
+
+    int i;
+
+    printf("Test 007 (PL_strndup)     ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        char *rv = PL_strndup(array[i].str, array[i].len);
+        const char *a;
+        const char *b;
+
+        if( (char *)0 == rv )
+        {
+            printf("FAIL %d: %s,%lu -> 0\n", i, 
+                   array[i].str ? array[i].str : "(null)", array[i].len);
+            return PR_FALSE;
+        }
+
+        a = array[i].result;
+        b = (const char *)rv;
+
+        while( 1 )
+        {
+            if( *a != *b )
+            {
+                printf("FAIL %d: %s != %.32s\n", i, array[i].result, rv);
+                return PR_FALSE;
+            }
+
+            if( (char)0 == *a ) break;
+
+            a++;
+            b++;
+        }
+
+        free(rv);
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_strcat */
+PRBool test_008(void)
+{
+    static struct
+    {
+        const char *first;
+        const char *second;
+        const char *result;
+    } array[] =
+      {
+          { (const char *)0, (const char *)0, (const char *)0 },
+          { (const char *)0, "xyz", (const char *)0 },
+          { "", (const char *)0, "" },
+          { "", "", "" },
+          { "ab", "", "ab" },
+          { "cd", "ef", "cdef" },
+          { "gh\0X", "", "gh" },
+          { "ij\0X", "kl", "ijkl" },
+          { "mn\0X", "op\0X", "mnop" },
+          { "qr", "st\0X", "qrst" },
+          { "uv\0X", "wx\0X", "uvwx" }
+      };
+
+    int i;
+
+    printf("Test 008 (PL_strcat)      ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        char buffer[ 1024 ];
+        int j;
+        char *rv;
+
+        for( j = 0; j < sizeof(buffer); j++ )
+            buffer[j] = '-';
+
+        if( (const char *)0 != array[i].first )
+            (void)PL_strcpy(buffer, array[i].first);
+
+        rv = PL_strcat(((const char *)0 == array[i].first) ? (char *)0 : buffer,
+                       array[i].second);
+
+        if( (const char *)0 == array[i].result )
+        {
+            if( (char *)0 != rv )
+            {
+                printf("FAIL %d: %s+%s -> %.32s, not zero\n", i,
+                       array[i].first ? array[i].first : "(null)",
+                       array[i].second ? array[i].second : "(null)",
+                       rv);
+                return PR_FALSE;
+            }
+        }
+        else
+        {
+            if( (char *)0 == rv )
+            {
+                printf("FAIL %d: %s+%s -> null, not %s\n", i,
+                       array[i].first ? array[i].first : "(null)",
+                       array[i].second ? array[i].second : "(null)",
+                       array[i].result);
+                return PR_FALSE;
+            }
+            else
+            {
+                const char *a = array[i].result;
+                const char *b = (const char *)rv;
+
+                while( 1 )
+                {
+                    if( *a != *b )
+                    {
+                        printf("FAIL %d: %s+%s -> %.32s, not %s\n", i,
+                               array[i].first ? array[i].first : "(null)",
+                               array[i].second ? array[i].second : "(null)",
+                               rv, array[i].result);
+                        return PR_FALSE;
+                    }
+
+                    if( (char)0 == *a ) break;
+
+                    a++;
+                    b++;
+                }
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_strncat */
+PRBool test_009(void)
+{
+    static struct
+    {
+        const char *first;
+        const char *second;
+        PRUint32    length;
+        PRBool      nulled;
+        const char *result;
+    } array[] = 
+      {
+          { (const char *)0, (const char *)0, 0, PR_FALSE, (const char *)0 },
+          { (const char *)0, (const char *)0, 1, PR_FALSE, (const char *)0 },
+          { (const char *)0, (const char *)0, 7, PR_FALSE, (const char *)0 },
+          { (const char *)0, "", 0, PR_FALSE, (const char *)0 },
+          { (const char *)0, "", 1, PR_FALSE, (const char *)0 },
+          { (const char *)0, "", 7, PR_FALSE, (const char *)0 },
+          { (const char *)0, "stuff", 0, PR_FALSE, (const char *)0 },
+          { (const char *)0, "stuff", 1, PR_FALSE, (const char *)0 },
+          { (const char *)0, "stuff", 7, PR_FALSE, (const char *)0 },
+          { "", (const char *)0, 0, PR_TRUE, "" },
+          { "", (const char *)0, 1, PR_TRUE, "" },
+          { "", (const char *)0, 7, PR_TRUE, "" },
+          { "", "", 0, PR_TRUE, "" },
+          { "", "", 1, PR_TRUE, "" },
+          { "", "", 7, PR_TRUE, "" },
+          { "", "abcdefgh", 0, PR_TRUE, "" },
+          { "", "abcdefgh", 1, PR_FALSE, "a" },
+          { "", "abcdefgh", 7, PR_FALSE, "abcdefg" },
+          { "xyz", (const char *)0, 0, PR_TRUE, "xyz" },
+          { "xyz", (const char *)0, 1, PR_TRUE, "xyz" },
+          { "xyz", (const char *)0, 7, PR_TRUE, "xyz" },
+          { "xyz", "", 0, PR_TRUE, "xyz" },
+          { "xyz", "", 1, PR_TRUE, "xyz" },
+          { "xyz", "", 7, PR_TRUE, "xyz" },
+          { "xyz", "abcdefgh", 0, PR_TRUE, "xyz" },
+          { "xyz", "abcdefgh", 1, PR_FALSE, "xyza" },
+          { "xyz", "abcdefgh", 7, PR_FALSE, "xyzabcdefg" }
+      };
+
+    int i;
+
+    printf("Test 009 (PL_strncat)     ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        char buffer[ 1024 ];
+        int j;
+        char *rv;
+
+        for( j = 0; j < sizeof(buffer); j++ )
+            buffer[j] = '-';
+
+        if( (const char *)0 != array[i].first )
+            (void)PL_strcpy(buffer, array[i].first);
+
+        rv = PL_strncat(((const char *)0 == array[i].first) ? (char *)0 : buffer,
+                         array[i].second, array[i].length);
+
+        if( (const char *)0 == array[i].result )
+        {
+            if( (char *)0 != rv )
+            {
+                printf("FAIL %d: %s+%s/%lu -> %.32s, not zero\n", i,
+                       array[i].first ? array[i].first : "(null)",
+                       array[i].second ? array[i].second : "(null)",
+                       array[i].length, rv);
+                return PR_FALSE;
+            }
+        }
+        else
+        {
+            if( (char *)0 == rv )
+            {
+                printf("FAIL %d: %s+%s/%lu -> null, not %s\n", i,
+                       array[i].first ? array[i].first : "(null)",
+                       array[i].second ? array[i].second : "(null)",
+                       array[i].length, array[i].result);
+                return PR_FALSE;
+            }
+            else
+            {
+                const char *a = array[i].result;
+                const char *b = (const char *)rv;
+
+                while( *a )
+                {
+                    if( *a != *b )
+                    {
+                        printf("FAIL %d: %s+%s/%lu -> %.32s, not %s\n", i,
+                               array[i].first ? array[i].first : "(null)",
+                               array[i].second ? array[i].second : "(null)",
+                               array[i].length, rv, array[i].result);
+                        return PR_FALSE;
+                    }
+
+                    a++;
+                    b++;
+                }
+
+                if( array[i].nulled )
+                {
+                    if( (char)0 != *b )
+                    {
+                        printf("FAIL %d: %s+%s/%lu -> not nulled\n", i,
+                               array[i].first ? array[i].first : "(null)",
+                               array[i].second ? array[i].second : "(null)",
+                               array[i].length);
+                        return PR_FALSE;
+                    }
+                }
+                else
+                {
+                    if( (char)0 == *b )
+                    {
+                        printf("FAIL %d: %s+%s/%lu -> overrun\n", i,
+                               array[i].first ? array[i].first : "(null)",
+                               array[i].second ? array[i].second : "(null)",
+                               array[i].length);
+                        return PR_FALSE;
+                    }
+                }
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_strcatn */
+PRBool test_010(void)
+{
+    static struct
+    {
+        const char *first;
+        const char *second;
+        PRUint32    length;
+        const char *result;
+    } array[] = 
+      {
+          { (const char *)0, (const char *)0, 0, (const char *)0 },
+          { (const char *)0, (const char *)0, 1, (const char *)0 },
+          { (const char *)0, (const char *)0, 7, (const char *)0 },
+          { (const char *)0, "", 0, (const char *)0 },
+          { (const char *)0, "", 1, (const char *)0 },
+          { (const char *)0, "", 7, (const char *)0 },
+          { (const char *)0, "stuff", 0, (const char *)0 },
+          { (const char *)0, "stuff", 1, (const char *)0 },
+          { (const char *)0, "stuff", 7, (const char *)0 },
+          { "", (const char *)0, 0, "" },
+          { "", (const char *)0, 1, "" },
+          { "", (const char *)0, 7, "" },
+          { "", "", 0, "" },
+          { "", "", 1, "" },
+          { "", "", 7, "" },
+          { "", "abcdefgh", 0, "" },
+          { "", "abcdefgh", 1, "" },
+          { "", "abcdefgh", 7, "abcdef" },
+          { "xyz", (const char *)0, 0, "xyz" },
+          { "xyz", (const char *)0, 1, "xyz" },
+          { "xyz", (const char *)0, 7, "xyz" },
+          { "xyz", "", 0, "xyz" },
+          { "xyz", "", 1, "xyz" },
+          { "xyz", "", 7, "xyz" },
+          { "xyz", "abcdefgh", 0, "xyz" },
+          { "xyz", "abcdefgh", 1, "xyz" },
+          { "xyz", "abcdefgh", 7, "xyzabc" }
+      };
+
+    int i;
+
+    printf("Test 010 (PL_strcatn)     ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        char buffer[ 1024 ];
+        int j;
+        char *rv;
+
+        for( j = 0; j < sizeof(buffer); j++ )
+            buffer[j] = '-';
+
+        if( (const char *)0 != array[i].first )
+            (void)PL_strcpy(buffer, array[i].first);
+
+        rv = PL_strcatn(((const char *)0 == array[i].first) ? (char *)0 : buffer,
+                        array[i].length, array[i].second);
+
+        if( (const char *)0 == array[i].result )
+        {
+            if( (char *)0 != rv )
+            {
+                printf("FAIL %d: %s+%s/%lu -> %.32s, not zero\n", i,
+                       array[i].first ? array[i].first : "(null)",
+                       array[i].second ? array[i].second : "(null)",
+                       array[i].length, rv);
+                return PR_FALSE;
+            }
+        }
+        else
+        {
+            if( (char *)0 == rv )
+            {
+                printf("FAIL %d: %s+%s/%lu -> null, not %s\n", i,
+                       array[i].first ? array[i].first : "(null)",
+                       array[i].second ? array[i].second : "(null)",
+                       array[i].length, array[i].result);
+                return PR_FALSE;
+            }
+            else
+            {
+                const char *a = array[i].result;
+                const char *b = (const char *)rv;
+
+                while( 1 )
+                {
+                    if( *a != *b )
+                    {
+                        printf("FAIL %d: %s+%s/%lu -> %.32s, not %s\n", i,
+                               array[i].first ? array[i].first : "(null)",
+                               array[i].second ? array[i].second : "(null)",
+                               array[i].length, rv, array[i].result);
+                        return PR_FALSE;
+                    }
+
+                    if( (char)0 == *a ) break;
+
+                    a++;
+                    b++;
+                }
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_strcmp */
+PRBool test_011(void)
+{
+    static struct
+    {
+        const char *one;
+        const char *two;
+        PRIntn      sign;
+    } array[] =
+      {
+          { (const char *)0, (const char *)0, 0 },
+          { (const char *)0, "word", -1 },
+          { "word", (const char *)0, 1 },
+          { "word", "word", 0 },
+          { "aZYXVUT", "bZYXVUT", -1 },
+          { "aZYXVUT", "bAAAAAA", -1 },
+          { "a", "aa", -1 },
+          { "a", "a", 0 },
+          { "a", "A", 1 },
+          { "aaaaa", "baaaa", -1 },
+          { "aaaaa", "abaaa", -1 },
+          { "aaaaa", "aabaa", -1 },
+          { "aaaaa", "aaaba", -1 },
+          { "aaaaa", "aaaab", -1 },
+          { "bZYXVUT", "aZYXVUT", 1 },
+          { "bAAAAAA", "aZYXVUT", 1 },
+          { "aa", "a", 1 },
+          { "A", "a", -1 },
+          { "baaaa", "aaaaa", 1 },
+          { "abaaa", "aaaaa", 1 },
+          { "aabaa", "aaaaa", 1 },
+          { "aaaba", "aaaaa", 1 },
+          { "aaaab", "aaaaa", 1 },
+          { "word", "Word", 1 },
+          { "word", "wOrd", 1 },
+          { "word", "woRd", 1 },
+          { "word", "worD", 1 },
+          { "WORD", "wORD", -1 },
+          { "WORD", "WoRD", -1 },
+          { "WORD", "WOrD", -1 },
+          { "WORD", "WORd", -1 }
+      };
+
+    int i;
+
+    printf("Test 011 (PL_strcmp)      ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        PRIntn rv = PL_strcmp(array[i].one, array[i].two);
+
+        switch( array[i].sign )
+        {
+            case -1:
+                if( rv < 0 ) continue;
+                break;
+            case 1:
+                if( rv > 0 ) continue;
+                break;
+            case 0:
+                if( 0 == rv ) continue;
+                break;
+            default:
+                PR_NOT_REACHED("static data inconsistancy");
+                break;
+        }
+
+        printf("FAIL %d: %s-%s -> %d, not %d\n", i,
+               array[i].one ? array[i].one : "(null)",
+               array[i].two ? array[i].two : "(null)",
+               rv, array[i].sign);
+        return PR_FALSE;
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_strncmp */
+PRBool test_012(void)
+{
+    static struct
+    {
+        const char *one;
+        const char *two;
+        PRUint32    max;
+        PRIntn      sign;
+    } array[] =
+      {
+          { (const char *)0, (const char *)0, 0, 0 },
+          { (const char *)0, (const char *)0, 1, 0 },
+          { (const char *)0, (const char *)0, 4, 0 },
+          { (const char *)0, "word", 0, -1 },
+          { (const char *)0, "word", 1, -1 },
+          { (const char *)0, "word", 4, -1 },
+          { "word", (const char *)0, 0, 1 },
+          { "word", (const char *)0, 1, 1 },
+          { "word", (const char *)0, 4, 1 },
+          { "word", "word", 0, 0 },
+          { "word", "word", 1, 0 },
+          { "word", "word", 3, 0 },
+          { "word", "word", 5, 0 },
+          { "aZYXVUT", "bZYXVUT", 0, 0 },
+          { "aZYXVUT", "bZYXVUT", 1, -1 },
+          { "aZYXVUT", "bZYXVUT", 4, -1 },
+          { "aZYXVUT", "bZYXVUT", 9, -1 },
+          { "aZYXVUT", "bAAAAAA", 0, 0 },
+          { "aZYXVUT", "bAAAAAA", 1, -1 },
+          { "aZYXVUT", "bAAAAAA", 4, -1 },
+          { "aZYXVUT", "bAAAAAA", 5, -1 },
+          { "a", "aa", 0, 0 },
+          { "a", "aa", 1, 0 },
+          { "a", "aa", 4, -1 },
+          { "a", "a", 0, 0 },
+          { "a", "a", 1, 0 },
+          { "a", "a", 4, 0 },
+          { "a", "A", 0, 0 },
+          { "a", "A", 1, 1 },
+          { "a", "A", 4, 1 },
+          { "aaaaa", "baaaa", 0, 0 },
+          { "aaaaa", "baaaa", 1, -1 },
+          { "aaaaa", "baaaa", 4, -1 },
+          { "aaaaa", "abaaa", 0, 0 },
+          { "aaaaa", "abaaa", 1, 0 },
+          { "aaaaa", "abaaa", 4, -1 },
+          { "aaaaa", "aabaa", 0, 0 },
+          { "aaaaa", "aabaa", 1, 0 },
+          { "aaaaa", "aabaa", 4, -1 },
+          { "aaaaa", "aaaba", 0, 0 },
+          { "aaaaa", "aaaba", 1, 0 },
+          { "aaaaa", "aaaba", 4, -1 },
+          { "aaaaa", "aaaab", 0, 0 },
+          { "aaaaa", "aaaab", 1, 0 },
+          { "aaaaa", "aaaab", 4, 0 },
+          { "bZYXVUT", "aZYXVUT", 0, 0 },
+          { "bZYXVUT", "aZYXVUT", 1, 1 },
+          { "bZYXVUT", "aZYXVUT", 4, 1 },
+          { "bAAAAAA", "aZYXVUT", 0, 0 },
+          { "bAAAAAA", "aZYXVUT", 1, 1 },
+          { "bAAAAAA", "aZYXVUT", 4, 1 },
+          { "aa", "a", 0, 0 },
+          { "aa", "a", 1, 0 },
+          { "aa", "a", 4, 1 },
+          { "A", "a", 0, 0 },
+          { "A", "a", 1, -1 },
+          { "A", "a", 4, -1 },
+          { "baaaa", "aaaaa", 0, 0 },
+          { "baaaa", "aaaaa", 1, 1 },
+          { "baaaa", "aaaaa", 4, 1 },
+          { "abaaa", "aaaaa", 0, 0 },
+          { "abaaa", "aaaaa", 1, 0 },
+          { "abaaa", "aaaaa", 4, 1 },
+          { "aabaa", "aaaaa", 0, 0 },
+          { "aabaa", "aaaaa", 1, 0 },
+          { "aabaa", "aaaaa", 4, 1 },
+          { "aaaba", "aaaaa", 0, 0 },
+          { "aaaba", "aaaaa", 1, 0 },
+          { "aaaba", "aaaaa", 4, 1 },
+          { "aaaab", "aaaaa", 0, 0 },
+          { "aaaab", "aaaaa", 1, 0 },
+          { "aaaab", "aaaaa", 4, 0 },
+          { "word", "Word", 0, 0 },
+          { "word", "Word", 1, 1 },
+          { "word", "Word", 3, 1 },
+          { "word", "wOrd", 0, 0 },
+          { "word", "wOrd", 1, 0 },
+          { "word", "wOrd", 3, 1 },
+          { "word", "woRd", 0, 0 },
+          { "word", "woRd", 1, 0 },
+          { "word", "woRd", 3, 1 },
+          { "word", "worD", 0, 0 },
+          { "word", "worD", 1, 0 },
+          { "word", "worD", 3, 0 },
+          { "WORD", "wORD", 0, 0 },
+          { "WORD", "wORD", 1, -1 },
+          { "WORD", "wORD", 3, -1 },
+          { "WORD", "WoRD", 0, 0 },
+          { "WORD", "WoRD", 1, 0 },
+          { "WORD", "WoRD", 3, -1 },
+          { "WORD", "WOrD", 0, 0 },
+          { "WORD", "WOrD", 1, 0 },
+          { "WORD", "WOrD", 3, -1 },
+          { "WORD", "WORd", 0, 0 },
+          { "WORD", "WORd", 1, 0 },
+          { "WORD", "WORd", 3, 0 }
+
+      };
+
+    int i;
+
+    printf("Test 012 (PL_strncmp)     ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        PRIntn rv = PL_strncmp(array[i].one, array[i].two, array[i].max);
+
+        switch( array[i].sign )
+        {
+            case -1:
+                if( rv < 0 ) continue;
+                break;
+            case 1:
+                if( rv > 0 ) continue;
+                break;
+            case 0:
+                if( 0 == rv ) continue;
+                break;
+            default:
+                PR_NOT_REACHED("static data inconsistancy");
+                break;
+        }
+
+        printf("FAIL %d: %s-%s/%ld -> %d, not %d\n", i,
+               array[i].one ? array[i].one : "(null)",
+               array[i].two ? array[i].two : "(null)",
+               array[i].max, rv, array[i].sign);
+        return PR_FALSE;
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_strcasecmp */
+PRBool test_013(void)
+{
+    static struct
+    {
+        const char *one;
+        const char *two;
+        PRIntn      sign;
+    } array[] =
+      {
+          { (const char *)0, (const char *)0, 0 },
+          { (const char *)0, "word", -1 },
+          { "word", (const char *)0, 1 },
+          { "word", "word", 0 },
+          { "aZYXVUT", "bZYXVUT", -1 },
+          { "aZYXVUT", "bAAAAAA", -1 },
+          { "a", "aa", -1 },
+          { "a", "a", 0 },
+          { "a", "A", 0 },
+          { "aaaaa", "baaaa", -1 },
+          { "aaaaa", "abaaa", -1 },
+          { "aaaaa", "aabaa", -1 },
+          { "aaaaa", "aaaba", -1 },
+          { "aaaaa", "aaaab", -1 },
+          { "bZYXVUT", "aZYXVUT", 1 },
+          { "bAAAAAA", "aZYXVUT", 1 },
+          { "aa", "a", 1 },
+          { "A", "a", 0 },
+          { "baaaa", "aaaaa", 1 },
+          { "abaaa", "aaaaa", 1 },
+          { "aabaa", "aaaaa", 1 },
+          { "aaaba", "aaaaa", 1 },
+          { "aaaab", "aaaaa", 1 },
+          { "word", "Word", 0 },
+          { "word", "wOrd", 0 },
+          { "word", "woRd", 0 },
+          { "word", "worD", 0 },
+          { "WORD", "wORD", 0 },
+          { "WORD", "WoRD", 0 },
+          { "WORD", "WOrD", 0 },
+          { "WORD", "WORd", 0 }
+      };
+
+    int i;
+
+    printf("Test 013 (PL_strcasecmp)  ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        PRIntn rv = PL_strcasecmp(array[i].one, array[i].two);
+
+        switch( array[i].sign )
+        {
+            case -1:
+                if( rv < 0 ) continue;
+                break;
+            case 1:
+                if( rv > 0 ) continue;
+                break;
+            case 0:
+                if( 0 == rv ) continue;
+                break;
+            default:
+                PR_NOT_REACHED("static data inconsistancy");
+                break;
+        }
+
+        printf("FAIL %d: %s-%s -> %d, not %d\n", i,
+               array[i].one ? array[i].one : "(null)",
+               array[i].two ? array[i].two : "(null)",
+               rv, array[i].sign);
+        return PR_FALSE;
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_strncasecmp */
+PRBool test_014(void)
+{
+    static struct
+    {
+        const char *one;
+        const char *two;
+        PRUint32    max;
+        PRIntn      sign;
+    } array[] =
+      {
+          { (const char *)0, (const char *)0, 0, 0 },
+          { (const char *)0, (const char *)0, 1, 0 },
+          { (const char *)0, (const char *)0, 4, 0 },
+          { (const char *)0, "word", 0, -1 },
+          { (const char *)0, "word", 1, -1 },
+          { (const char *)0, "word", 4, -1 },
+          { "word", (const char *)0, 0, 1 },
+          { "word", (const char *)0, 1, 1 },
+          { "word", (const char *)0, 4, 1 },
+          { "word", "word", 0, 0 },
+          { "word", "word", 1, 0 },
+          { "word", "word", 3, 0 },
+          { "word", "word", 5, 0 },
+          { "aZYXVUT", "bZYXVUT", 0, 0 },
+          { "aZYXVUT", "bZYXVUT", 1, -1 },
+          { "aZYXVUT", "bZYXVUT", 4, -1 },
+          { "aZYXVUT", "bZYXVUT", 9, -1 },
+          { "aZYXVUT", "bAAAAAA", 0, 0 },
+          { "aZYXVUT", "bAAAAAA", 1, -1 },
+          { "aZYXVUT", "bAAAAAA", 4, -1 },
+          { "aZYXVUT", "bAAAAAA", 5, -1 },
+          { "a", "aa", 0, 0 },
+          { "a", "aa", 1, 0 },
+          { "a", "aa", 4, -1 },
+          { "a", "a", 0, 0 },
+          { "a", "a", 1, 0 },
+          { "a", "a", 4, 0 },
+          { "a", "A", 0, 0 },
+          { "a", "A", 1, 0 },
+          { "a", "A", 4, 0 },
+          { "aaaaa", "baaaa", 0, 0 },
+          { "aaaaa", "baaaa", 1, -1 },
+          { "aaaaa", "baaaa", 4, -1 },
+          { "aaaaa", "abaaa", 0, 0 },
+          { "aaaaa", "abaaa", 1, 0 },
+          { "aaaaa", "abaaa", 4, -1 },
+          { "aaaaa", "aabaa", 0, 0 },
+          { "aaaaa", "aabaa", 1, 0 },
+          { "aaaaa", "aabaa", 4, -1 },
+          { "aaaaa", "aaaba", 0, 0 },
+          { "aaaaa", "aaaba", 1, 0 },
+          { "aaaaa", "aaaba", 4, -1 },
+          { "aaaaa", "aaaab", 0, 0 },
+          { "aaaaa", "aaaab", 1, 0 },
+          { "aaaaa", "aaaab", 4, 0 },
+          { "bZYXVUT", "aZYXVUT", 0, 0 },
+          { "bZYXVUT", "aZYXVUT", 1, 1 },
+          { "bZYXVUT", "aZYXVUT", 4, 1 },
+          { "bAAAAAA", "aZYXVUT", 0, 0 },
+          { "bAAAAAA", "aZYXVUT", 1, 1 },
+          { "bAAAAAA", "aZYXVUT", 4, 1 },
+          { "aa", "a", 0, 0 },
+          { "aa", "a", 1, 0 },
+          { "aa", "a", 4, 1 },
+          { "A", "a", 0, 0 },
+          { "A", "a", 1, 0 },
+          { "A", "a", 4, 0 },
+          { "baaaa", "aaaaa", 0, 0 },
+          { "baaaa", "aaaaa", 1, 1 },
+          { "baaaa", "aaaaa", 4, 1 },
+          { "abaaa", "aaaaa", 0, 0 },
+          { "abaaa", "aaaaa", 1, 0 },
+          { "abaaa", "aaaaa", 4, 1 },
+          { "aabaa", "aaaaa", 0, 0 },
+          { "aabaa", "aaaaa", 1, 0 },
+          { "aabaa", "aaaaa", 4, 1 },
+          { "aaaba", "aaaaa", 0, 0 },
+          { "aaaba", "aaaaa", 1, 0 },
+          { "aaaba", "aaaaa", 4, 1 },
+          { "aaaab", "aaaaa", 0, 0 },
+          { "aaaab", "aaaaa", 1, 0 },
+          { "aaaab", "aaaaa", 4, 0 },
+          { "word", "Word", 0, 0 },
+          { "word", "Word", 1, 0 },
+          { "word", "Word", 3, 0 },
+          { "word", "wOrd", 0, 0 },
+          { "word", "wOrd", 1, 0 },
+          { "word", "wOrd", 3, 0 },
+          { "word", "woRd", 0, 0 },
+          { "word", "woRd", 1, 0 },
+          { "word", "woRd", 3, 0 },
+          { "word", "worD", 0, 0 },
+          { "word", "worD", 1, 0 },
+          { "word", "worD", 3, 0 },
+          { "WORD", "wORD", 0, 0 },
+          { "WORD", "wORD", 1, 0 },
+          { "WORD", "wORD", 3, 0 },
+          { "WORD", "WoRD", 0, 0 },
+          { "WORD", "WoRD", 1, 0 },
+          { "WORD", "WoRD", 3, 0 },
+          { "WORD", "WOrD", 0, 0 },
+          { "WORD", "WOrD", 1, 0 },
+          { "WORD", "WOrD", 3, 0 },
+          { "WORD", "WORd", 0, 0 },
+          { "WORD", "WORd", 1, 0 },
+          { "WORD", "WORd", 3, 0 }
+      };
+
+    int i;
+
+    printf("Test 014 (PL_strncasecmp) ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        PRIntn rv = PL_strncasecmp(array[i].one, array[i].two, array[i].max);
+
+        switch( array[i].sign )
+        {
+            case -1:
+                if( rv < 0 ) continue;
+                break;
+            case 1:
+                if( rv > 0 ) continue;
+                break;
+            case 0:
+                if( 0 == rv ) continue;
+                break;
+            default:
+                PR_NOT_REACHED("static data inconsistancy");
+                break;
+        }
+
+        printf("FAIL %d: %s-%s/%ld -> %d, not %d\n", i,
+               array[i].one ? array[i].one : "(null)",
+               array[i].two ? array[i].two : "(null)",
+               array[i].max, rv, array[i].sign);
+        return PR_FALSE;
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_strchr */
+PRBool test_015(void)
+{
+    static struct
+    {
+        const char *str;
+        char        chr;
+        PRBool      ret;
+        PRUint32    off;
+    } array[] =
+      {
+          { (const char *)0, 'a', PR_FALSE, 0 },
+          { (const char *)0, '\0', PR_FALSE, 0 },
+          { "abcdefg", 'a', PR_TRUE, 0 },
+          { "abcdefg", 'b', PR_TRUE, 1 },
+          { "abcdefg", 'c', PR_TRUE, 2 },
+          { "abcdefg", 'd', PR_TRUE, 3 },
+          { "abcdefg", 'e', PR_TRUE, 4 },
+          { "abcdefg", 'f', PR_TRUE, 5 },
+          { "abcdefg", 'g', PR_TRUE, 6 },
+          { "abcdefg", 'h', PR_FALSE, 0 },
+          { "abcdefg", '\0', PR_TRUE, 7 },
+          { "abcdefg", 'A', PR_FALSE, 0 },
+          { "abcdefg", 'B', PR_FALSE, 0 },
+          { "abcdefg", 'C', PR_FALSE, 0 },
+          { "abcdefg", 'D', PR_FALSE, 0 },
+          { "abcdefg", 'E', PR_FALSE, 0 },
+          { "abcdefg", 'F', PR_FALSE, 0 },
+          { "abcdefg", 'G', PR_FALSE, 0 },
+          { "abcdefg", 'H', PR_FALSE, 0 },
+          { "abcdefgabcdefg", 'a', PR_TRUE, 0 },
+          { "abcdefgabcdefg", 'b', PR_TRUE, 1 },
+          { "abcdefgabcdefg", 'c', PR_TRUE, 2 },
+          { "abcdefgabcdefg", 'd', PR_TRUE, 3 },
+          { "abcdefgabcdefg", 'e', PR_TRUE, 4 },
+          { "abcdefgabcdefg", 'f', PR_TRUE, 5 },
+          { "abcdefgabcdefg", 'g', PR_TRUE, 6 },
+          { "abcdefgabcdefg", 'h', PR_FALSE, 0 },
+          { "abcdefgabcdefg", '\0', PR_TRUE, 14 }
+      };
+
+    int i;
+
+    printf("Test 015 (PL_strchr)      ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        char *rv = PL_strchr(array[i].str, array[i].chr);
+
+        if( PR_FALSE == array[i].ret )
+        {
+            if( (char *)0 != rv )
+            {
+                printf("FAIL %d: %s,%c -> %.32s, not zero\n", i, array[i].str,
+                       array[i].chr, rv);
+                return PR_FALSE;
+            }
+        }
+        else
+        {
+            if( (char *)0 == rv )
+            {
+                printf("FAIL %d: %s,%c -> null, not +%lu\n", i, array[i].str,
+                       array[i].chr, array[i].off);
+                return PR_FALSE;
+            }
+
+            if( &array[i].str[ array[i].off ] != rv )
+            {
+                printf("FAIL %d: %s,%c -> 0x%x, not 0x%x+%lu\n", i, array[i].str,
+                       array[i].chr, rv, array[i].str, array[i].off);
+                return PR_FALSE;
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_strrchr */
+PRBool test_016(void)
+{
+    static struct
+    {
+        const char *str;
+        char        chr;
+        PRBool      ret;
+        PRUint32    off;
+    } array[] =
+      {
+          { (const char *)0, 'a', PR_FALSE, 0 },
+          { (const char *)0, '\0', PR_FALSE, 0 },
+          { "abcdefg", 'a', PR_TRUE, 0 },
+          { "abcdefg", 'b', PR_TRUE, 1 },
+          { "abcdefg", 'c', PR_TRUE, 2 },
+          { "abcdefg", 'd', PR_TRUE, 3 },
+          { "abcdefg", 'e', PR_TRUE, 4 },
+          { "abcdefg", 'f', PR_TRUE, 5 },
+          { "abcdefg", 'g', PR_TRUE, 6 },
+          { "abcdefg", 'h', PR_FALSE, 0 },
+          { "abcdefg", '\0', PR_TRUE, 7 },
+          { "abcdefg", 'A', PR_FALSE, 0 },
+          { "abcdefg", 'B', PR_FALSE, 0 },
+          { "abcdefg", 'C', PR_FALSE, 0 },
+          { "abcdefg", 'D', PR_FALSE, 0 },
+          { "abcdefg", 'E', PR_FALSE, 0 },
+          { "abcdefg", 'F', PR_FALSE, 0 },
+          { "abcdefg", 'G', PR_FALSE, 0 },
+          { "abcdefg", 'H', PR_FALSE, 0 },
+          { "abcdefgabcdefg", 'a', PR_TRUE, 7 },
+          { "abcdefgabcdefg", 'b', PR_TRUE, 8 },
+          { "abcdefgabcdefg", 'c', PR_TRUE, 9 },
+          { "abcdefgabcdefg", 'd', PR_TRUE, 10 },
+          { "abcdefgabcdefg", 'e', PR_TRUE, 11 },
+          { "abcdefgabcdefg", 'f', PR_TRUE, 12 },
+          { "abcdefgabcdefg", 'g', PR_TRUE, 13 },
+          { "abcdefgabcdefg", 'h', PR_FALSE, 0 },
+          { "abcdefgabcdefg", '\0', PR_TRUE, 14 }
+      };
+
+    int i;
+
+    printf("Test 016 (PL_strrchr)     ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        char *rv = PL_strrchr(array[i].str, array[i].chr);
+
+        if( PR_FALSE == array[i].ret )
+        {
+            if( (char *)0 != rv )
+            {
+                printf("FAIL %d: %s,%c -> %.32s, not zero\n", i, array[i].str,
+                       array[i].chr, rv);
+                return PR_FALSE;
+            }
+        }
+        else
+        {
+            if( (char *)0 == rv )
+            {
+                printf("FAIL %d: %s,%c -> null, not +%lu\n", i, array[i].str,
+                       array[i].chr, array[i].off);
+                return PR_FALSE;
+            }
+
+            if( &array[i].str[ array[i].off ] != rv )
+            {
+                printf("FAIL %d: %s,%c -> 0x%x, not 0x%x+%lu\n", i, array[i].str,
+                       array[i].chr, rv, array[i].str, array[i].off);
+                return PR_FALSE;
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_strnchr */
+PRBool test_017(void)
+{
+    static struct
+    {
+        const char *str;
+        char        chr;
+        PRUint32    max;
+        PRBool      ret;
+        PRUint32    off;
+    } array[] =
+      {
+          { (const char *)0, 'a', 2, PR_FALSE, 0 },
+          { (const char *)0, '\0', 2, PR_FALSE, 0 },
+          { "abcdefg", 'a', 5, PR_TRUE, 0 },
+          { "abcdefg", 'b', 5, PR_TRUE, 1 },
+          { "abcdefg", 'c', 5, PR_TRUE, 2 },
+          { "abcdefg", 'd', 5, PR_TRUE, 3 },
+          { "abcdefg", 'e', 5, PR_TRUE, 4 },
+          { "abcdefg", 'f', 5, PR_FALSE, 0 },
+          { "abcdefg", 'g', 5, PR_FALSE, 0 },
+          { "abcdefg", 'h', 5, PR_FALSE, 0 },
+          { "abcdefg", '\0', 5, PR_FALSE, 0 },
+          { "abcdefg", '\0', 15, PR_TRUE, 7 },
+          { "abcdefg", 'A', 5, PR_FALSE, 0 },
+          { "abcdefg", 'B', 5, PR_FALSE, 0 },
+          { "abcdefg", 'C', 5, PR_FALSE, 0 },
+          { "abcdefg", 'D', 5, PR_FALSE, 0 },
+          { "abcdefg", 'E', 5, PR_FALSE, 0 },
+          { "abcdefg", 'F', 5, PR_FALSE, 0 },
+          { "abcdefg", 'G', 5, PR_FALSE, 0 },
+          { "abcdefg", 'H', 5, PR_FALSE, 0 },
+          { "abcdefgabcdefg", 'a', 10, PR_TRUE, 0 },
+          { "abcdefgabcdefg", 'b', 10, PR_TRUE, 1 },
+          { "abcdefgabcdefg", 'c', 10, PR_TRUE, 2 },
+          { "abcdefgabcdefg", 'd', 10, PR_TRUE, 3 },
+          { "abcdefgabcdefg", 'e', 10, PR_TRUE, 4 },
+          { "abcdefgabcdefg", 'f', 10, PR_TRUE, 5 },
+          { "abcdefgabcdefg", 'g', 10, PR_TRUE, 6 },
+          { "abcdefgabcdefg", 'h', 10, PR_FALSE, 0 },
+          { "abcdefgabcdefg", '\0', 10, PR_FALSE, 0 },
+          { "abcdefgabcdefg", '\0', 14, PR_FALSE, 0 },
+          { "abcdefgabcdefg", '\0', 15, PR_TRUE, 14 }
+      };
+
+    int i;
+
+    printf("Test 017 (PL_strnchr)     ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        char *rv = PL_strnchr(array[i].str, array[i].chr, array[i].max);
+
+        if( PR_FALSE == array[i].ret )
+        {
+            if( (char *)0 != rv )
+            {
+                printf("FAIL %d: %s,%c/%lu -> %.32s, not zero\n", i, array[i].str,
+                       array[i].chr, array[i].max, rv);
+                return PR_FALSE;
+            }
+        }
+        else
+        {
+            if( (char *)0 == rv )
+            {
+                printf("FAIL %d: %s,%c/%lu -> null, not +%lu\n", i, array[i].str,
+                       array[i].chr, array[i].max, array[i].off);
+                return PR_FALSE;
+            }
+
+            if( &array[i].str[ array[i].off ] != rv )
+            {
+                printf("FAIL %d: %s,%c/%lu -> 0x%x, not 0x%x+%lu\n", i, array[i].str,
+                       array[i].chr, array[i].max, rv, array[i].str, array[i].off);
+                return PR_FALSE;
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_strnrchr */
+PRBool test_018(void)
+{
+    static struct
+    {
+        const char *str;
+        char        chr;
+        PRUint32    max;
+        PRBool      ret;
+        PRUint32    off;
+    } array[] =
+      {
+          { (const char *)0, 'a', 2, PR_FALSE, 0 },
+          { (const char *)0, '\0', 2, PR_FALSE, 0 },
+          { "abcdefg", 'a', 5, PR_TRUE, 0 },
+          { "abcdefg", 'b', 5, PR_TRUE, 1 },
+          { "abcdefg", 'c', 5, PR_TRUE, 2 },
+          { "abcdefg", 'd', 5, PR_TRUE, 3 },
+          { "abcdefg", 'e', 5, PR_TRUE, 4 },
+          { "abcdefg", 'f', 5, PR_FALSE, 0 },
+          { "abcdefg", 'g', 5, PR_FALSE, 0 },
+          { "abcdefg", 'h', 5, PR_FALSE, 0 },
+          { "abcdefg", '\0', 5, PR_FALSE, 0 },
+          { "abcdefg", '\0', 15, PR_TRUE, 7 },
+          { "abcdefg", 'A', 5, PR_FALSE, 0 },
+          { "abcdefg", 'B', 5, PR_FALSE, 0 },
+          { "abcdefg", 'C', 5, PR_FALSE, 0 },
+          { "abcdefg", 'D', 5, PR_FALSE, 0 },
+          { "abcdefg", 'E', 5, PR_FALSE, 0 },
+          { "abcdefg", 'F', 5, PR_FALSE, 0 },
+          { "abcdefg", 'G', 5, PR_FALSE, 0 },
+          { "abcdefg", 'H', 5, PR_FALSE, 0 },
+          { "abcdefgabcdefg", 'a', 10, PR_TRUE, 7 },
+          { "abcdefgabcdefg", 'b', 10, PR_TRUE, 8 },
+          { "abcdefgabcdefg", 'c', 10, PR_TRUE, 9 },
+          { "abcdefgabcdefg", 'd', 10, PR_TRUE, 3 },
+          { "abcdefgabcdefg", 'e', 10, PR_TRUE, 4 },
+          { "abcdefgabcdefg", 'f', 10, PR_TRUE, 5 },
+          { "abcdefgabcdefg", 'g', 10, PR_TRUE, 6 },
+          { "abcdefgabcdefg", 'h', 10, PR_FALSE, 0 },
+          { "abcdefgabcdefg", '\0', 10, PR_FALSE, 0 },
+          { "abcdefgabcdefg", '\0', 14, PR_FALSE, 0 },
+          { "abcdefgabcdefg", '\0', 15, PR_TRUE, 14 }
+      };
+
+    int i;
+
+    printf("Test 018 (PL_strnrchr)    ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        char *rv = PL_strnrchr(array[i].str, array[i].chr, array[i].max);
+
+        if( PR_FALSE == array[i].ret )
+        {
+            if( (char *)0 != rv )
+            {
+                printf("FAIL %d: %s,%c/%lu -> %.32s, not zero\n", i, array[i].str,
+                       array[i].chr, array[i].max, rv);
+                return PR_FALSE;
+            }
+        }
+        else
+        {
+            if( (char *)0 == rv )
+            {
+                printf("FAIL %d: %s,%c/%lu -> null, not +%lu\n", i, array[i].str,
+                       array[i].chr, array[i].max, array[i].off);
+                return PR_FALSE;
+            }
+
+            if( &array[i].str[ array[i].off ] != rv )
+            {
+                printf("FAIL %d: %s,%c/%lu -> 0x%x, not 0x%x+%lu\n", i, array[i].str,
+                       array[i].chr, array[i].max, rv, array[i].str, array[i].off);
+                return PR_FALSE;
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_strpbrk */
+PRBool test_019(void)
+{
+    static struct
+    {
+        const char *str;
+        const char *chrs;
+        PRBool      ret;
+        PRUint32    off;
+    } array[] =
+      {
+          { (const char *)0, (const char *)0, PR_FALSE, 0 },
+          { (const char *)0, "abc", PR_FALSE, 0 },
+          { "abc", (const char *)0, PR_FALSE, 0 },
+          { "abcdefg", "", PR_FALSE, 0 },
+          { "", "aeiou", PR_FALSE, 0 },
+          { "abcdefg", "ae", PR_TRUE, 0 },
+          { "abcdefg", "ei", PR_TRUE, 4 },
+          { "abcdefg", "io", PR_FALSE, 0 },
+          { "abcdefg", "bcd", PR_TRUE, 1 },
+          { "abcdefg", "cbd", PR_TRUE, 1 },
+          { "abcdefg", "dbc", PR_TRUE, 1 },
+          { "abcdefg", "ghi", PR_TRUE, 6 },
+          { "abcdefg", "AE", PR_FALSE, 0 },
+          { "abcdefg", "EI", PR_FALSE, 0 },
+          { "abcdefg", "IO", PR_FALSE, 0 },
+          { "abcdefg", "BCD", PR_FALSE, 0 },
+          { "abcdefg", "CBD", PR_FALSE, 0 },
+          { "abcdefg", "DBC", PR_FALSE, 0 },
+          { "abcdefg", "GHI", PR_FALSE, 0 },
+          { "abcdefgabcdefg", "ae", PR_TRUE, 0 },
+          { "abcdefgabcdefg", "ei", PR_TRUE, 4 },
+          { "abcdefgabcdefg", "io", PR_FALSE, 0 },
+          { "abcdefgabcdefg", "bcd", PR_TRUE, 1 },
+          { "abcdefgabcdefg", "cbd", PR_TRUE, 1 },
+          { "abcdefgabcdefg", "dbc", PR_TRUE, 1 },
+          { "abcdefgabcdefg", "ghi", PR_TRUE, 6 },
+          { "abcdefgabcdefg", "AE", PR_FALSE, 0 },
+          { "abcdefgabcdefg", "EI", PR_FALSE, 0 },
+          { "abcdefgabcdefg", "IO", PR_FALSE, 0 },
+          { "abcdefgabcdefg", "BCD", PR_FALSE, 0 },
+          { "abcdefgabcdefg", "CBD", PR_FALSE, 0 },
+          { "abcdefgabcdefg", "DBC", PR_FALSE, 0 },
+          { "abcdefgabcdefg", "GHI", PR_FALSE, 0 }
+      };
+
+    int i;
+
+    printf("Test 019 (PL_strpbrk)     ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        char *rv = PL_strpbrk(array[i].str, array[i].chrs);
+
+        if( PR_FALSE == array[i].ret )
+        {
+            if( (char *)0 != rv )
+            {
+                printf("FAIL %d: %s,%s -> %.32s, not null\n", i, 
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].chrs ? array[i].chrs : "(null)", 
+                       rv);
+                return PR_FALSE;
+            }
+        }
+        else
+        {
+            if( (char *)0 == rv )
+            {
+                printf("FAIL %d: %s,%s -> null, not +%lu\n", i,
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].chrs ? array[i].chrs : "(null)", 
+                       array[i].off);
+                return PR_FALSE;
+            }
+
+            if( &array[i].str[ array[i].off ] != rv )
+            {
+                printf("FAIL %d: %s,%s -> 0x%x, not 0x%x+%lu\n", i,
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].chrs ? array[i].chrs : "(null)", 
+                       rv, array[i].str, array[i].off);
+                return PR_FALSE;
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_strprbrk */
+PRBool test_020(void)
+{
+    static struct
+    {
+        const char *str;
+        const char *chrs;
+        PRBool      ret;
+        PRUint32    off;
+    } array[] =
+      {
+          { (const char *)0, (const char *)0, PR_FALSE, 0 },
+          { (const char *)0, "abc", PR_FALSE, 0 },
+          { "abc", (const char *)0, PR_FALSE, 0 },
+          { "abcdefg", "", PR_FALSE, 0 },
+          { "", "aeiou", PR_FALSE, 0 },
+          { "abcdefg", "ae", PR_TRUE, 4 },
+          { "abcdefg", "ei", PR_TRUE, 4 },
+          { "abcdefg", "io", PR_FALSE, 0 },
+          { "abcdefg", "bcd", PR_TRUE, 3 },
+          { "abcdefg", "cbd", PR_TRUE, 3 },
+          { "abcdefg", "dbc", PR_TRUE, 3 },
+          { "abcdefg", "ghi", PR_TRUE, 6 },
+          { "abcdefg", "AE", PR_FALSE, 0 },
+          { "abcdefg", "EI", PR_FALSE, 0 },
+          { "abcdefg", "IO", PR_FALSE, 0 },
+          { "abcdefg", "BCD", PR_FALSE, 0 },
+          { "abcdefg", "CBD", PR_FALSE, 0 },
+          { "abcdefg", "DBC", PR_FALSE, 0 },
+          { "abcdefg", "GHI", PR_FALSE, 0 },
+          { "abcdefgabcdefg", "ae", PR_TRUE, 11 },
+          { "abcdefgabcdefg", "ei", PR_TRUE, 11 },
+          { "abcdefgabcdefg", "io", PR_FALSE, 0 },
+          { "abcdefgabcdefg", "bcd", PR_TRUE, 10 },
+          { "abcdefgabcdefg", "cbd", PR_TRUE, 10 },
+          { "abcdefgabcdefg", "dbc", PR_TRUE, 10 },
+          { "abcdefgabcdefg", "ghi", PR_TRUE, 13 },
+          { "abcdefgabcdefg", "AE", PR_FALSE, 0 },
+          { "abcdefgabcdefg", "EI", PR_FALSE, 0 },
+          { "abcdefgabcdefg", "IO", PR_FALSE, 0 },
+          { "abcdefgabcdefg", "BCD", PR_FALSE, 0 },
+          { "abcdefgabcdefg", "CBD", PR_FALSE, 0 },
+          { "abcdefgabcdefg", "DBC", PR_FALSE, 0 },
+          { "abcdefgabcdefg", "GHI", PR_FALSE, 0 }
+      };
+
+    int i;
+
+    printf("Test 020 (PL_strprbrk)    ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        char *rv = PL_strprbrk(array[i].str, array[i].chrs);
+
+        if( PR_FALSE == array[i].ret )
+        {
+            if( (char *)0 != rv )
+            {
+                printf("FAIL %d: %s,%s -> %.32s, not null\n", i, 
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].chrs ? array[i].chrs : "(null)", 
+                       rv);
+                return PR_FALSE;
+            }
+        }
+        else
+        {
+            if( (char *)0 == rv )
+            {
+                printf("FAIL %d: %s,%s -> null, not +%lu\n", i,
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].chrs ? array[i].chrs : "(null)", 
+                       array[i].off);
+                return PR_FALSE;
+            }
+
+            if( &array[i].str[ array[i].off ] != rv )
+            {
+                printf("FAIL %d: %s,%s -> 0x%x, not 0x%x+%lu\n", i,
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].chrs ? array[i].chrs : "(null)", 
+                       rv, array[i].str, array[i].off);
+                return PR_FALSE;
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+                       
+/* PL_strnpbrk */
+PRBool test_021(void)
+{
+    static struct
+    {
+        const char *str;
+        const char *chrs;
+        PRUint32    max;
+        PRBool      ret;
+        PRUint32    off;
+    } array[] =
+      {
+          { (const char *)0, (const char *)0, 3, PR_FALSE, 0 },
+          { (const char *)0, "abc", 3, PR_FALSE, 0 },
+          { "abc", (const char *)0, 3, PR_FALSE, 0 },
+          { "abcdefg", "", 3, PR_FALSE, 0 },
+          { "", "aeiou", 3, PR_FALSE, 0 },
+          { "abcdefg", "ae", 0, PR_FALSE, 0 },
+          { "abcdefg", "ae", 1, PR_TRUE, 0 },
+          { "abcdefg", "ae", 4, PR_TRUE, 0 },
+          { "abcdefg", "ae", 5, PR_TRUE, 0 },
+          { "abcdefg", "ae", 6, PR_TRUE, 0 },
+          { "abcdefg", "ei", 4, PR_FALSE, 0 },
+          { "abcdefg", "io", 10, PR_FALSE, 0 },
+          { "abcdefg", "bcd", 2, PR_TRUE, 1 },
+          { "abcdefg", "cbd", 2, PR_TRUE, 1 },
+          { "abcdefg", "dbc", 2, PR_TRUE, 1 },
+          { "abcdefg", "ghi", 6, PR_FALSE, 0 },
+          { "abcdefg", "ghi", 7, PR_TRUE, 6 },
+          { "abcdefg", "AE", 9, PR_FALSE, 0 },
+          { "abcdefg", "EI", 9, PR_FALSE, 0 },
+          { "abcdefg", "IO", 9, PR_FALSE, 0 },
+          { "abcdefg", "BCD", 9, PR_FALSE, 0 },
+          { "abcdefg", "CBD", 9, PR_FALSE, 0 },
+          { "abcdefg", "DBC", 9, PR_FALSE, 0 },
+          { "abcdefg", "GHI", 9, PR_FALSE, 0 },
+          { "abcdefgabcdefg", "ae", 10, PR_TRUE, 0 },
+          { "abcdefgabcdefg", "ei", 10, PR_TRUE, 4 },
+          { "abcdefgabcdefg", "io", 10, PR_FALSE, 0 },
+          { "abcdefgabcdefg", "bcd", 10, PR_TRUE, 1 },
+          { "abcdefgabcdefg", "cbd", 10, PR_TRUE, 1 },
+          { "abcdefgabcdefg", "dbc", 10, PR_TRUE, 1 },
+          { "abcdefgabcdefg", "ghi", 10, PR_TRUE, 6 },
+          { "abcdefgabcdefg", "AE", 10, PR_FALSE, 0 },
+          { "abcdefgabcdefg", "EI", 10, PR_FALSE, 0 },
+          { "abcdefgabcdefg", "IO", 10, PR_FALSE, 0 },
+          { "abcdefgabcdefg", "BCD", 10, PR_FALSE, 0 },
+          { "abcdefgabcdefg", "CBD", 10, PR_FALSE, 0 },
+          { "abcdefgabcdefg", "DBC", 10, PR_FALSE, 0 },
+          { "abcdefgabcdefg", "GHI", 10, PR_FALSE, 0 }
+      };
+
+    int i;
+
+    printf("Test 021 (PL_strnpbrk)    ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        char *rv = PL_strnpbrk(array[i].str, array[i].chrs, array[i].max);
+
+        if( PR_FALSE == array[i].ret )
+        {
+            if( (char *)0 != rv )
+            {
+                printf("FAIL %d: %s,%s/%lu -> %.32s, not null\n", i, 
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].chrs ? array[i].chrs : "(null)", 
+                       array[i].max, rv);
+                return PR_FALSE;
+            }
+        }
+        else
+        {
+            if( (char *)0 == rv )
+            {
+                printf("FAIL %d: %s,%s/%lu -> null, not +%lu\n", i,
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].chrs ? array[i].chrs : "(null)", 
+                       array[i].max, array[i].off);
+                return PR_FALSE;
+            }
+
+            if( &array[i].str[ array[i].off ] != rv )
+            {
+                printf("FAIL %d: %s,%s/%lu -> 0x%x, not 0x%x+%lu\n", i,
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].chrs ? array[i].chrs : "(null)", 
+                       array[i].max, rv, array[i].str, array[i].off);
+                return PR_FALSE;
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_strnprbrk */
+PRBool test_022(void)
+{
+    static struct
+    {
+        const char *str;
+        const char *chrs;
+        PRUint32    max;
+        PRBool      ret;
+        PRUint32    off;
+    } array[] =
+      {
+          { (const char *)0, (const char *)0, 3, PR_FALSE, 0 },
+          { (const char *)0, "abc", 3, PR_FALSE, 0 },
+          { "abc", (const char *)0, 3, PR_FALSE, 0 },
+          { "abcdefg", "", 3, PR_FALSE, 0 },
+          { "", "aeiou", 3, PR_FALSE, 0 },
+          { "abcdefg", "ae", 0, PR_FALSE, 0 },
+          { "abcdefg", "ae", 1, PR_TRUE, 0 },
+          { "abcdefg", "ae", 4, PR_TRUE, 0 },
+          { "abcdefg", "ae", 5, PR_TRUE, 4 },
+          { "abcdefg", "ae", 6, PR_TRUE,  4 },
+          { "abcdefg", "ei", 4, PR_FALSE, 0 },
+          { "abcdefg", "io", 10, PR_FALSE, 0 },
+          { "abcdefg", "bcd", 2, PR_TRUE, 1 },
+          { "abcdefg", "cbd", 2, PR_TRUE, 1 },
+          { "abcdefg", "dbc", 2, PR_TRUE, 1 },
+          { "abcdefg", "bcd", 3, PR_TRUE, 2 },
+          { "abcdefg", "cbd", 3, PR_TRUE, 2 },
+          { "abcdefg", "dbc", 3, PR_TRUE, 2 },
+          { "abcdefg", "bcd", 5, PR_TRUE, 3 },
+          { "abcdefg", "cbd", 5, PR_TRUE, 3 },
+          { "abcdefg", "dbc", 5, PR_TRUE, 3 },
+          { "abcdefg", "bcd", 15, PR_TRUE, 3 },
+          { "abcdefg", "cbd", 15, PR_TRUE, 3 },
+          { "abcdefg", "dbc", 15, PR_TRUE, 3 },
+          { "abcdefg", "ghi", 6, PR_FALSE, 0 },
+          { "abcdefg", "ghi", 7, PR_TRUE, 6 },
+          { "abcdefg", "AE", 9, PR_FALSE, 0 },
+          { "abcdefg", "EI", 9, PR_FALSE, 0 },
+          { "abcdefg", "IO", 9, PR_FALSE, 0 },
+          { "abcdefg", "BCD", 9, PR_FALSE, 0 },
+          { "abcdefg", "CBD", 9, PR_FALSE, 0 },
+          { "abcdefg", "DBC", 9, PR_FALSE, 0 },
+          { "abcdefg", "GHI", 9, PR_FALSE, 0 },
+          { "abcdefgabcdefg", "ae", 10, PR_TRUE, 7 },
+          { "abcdefgabcdefg", "ei", 10, PR_TRUE, 4 },
+          { "abcdefgabcdefg", "io", 10, PR_FALSE, 0 },
+          { "abcdefgabcdefg", "bcd", 10, PR_TRUE, 9 },
+          { "abcdefgabcdefg", "cbd", 10, PR_TRUE, 9 },
+          { "abcdefgabcdefg", "dbc", 10, PR_TRUE, 9 },
+          { "abcdefgabcdefg", "ghi", 10, PR_TRUE, 6 },
+          { "abcdefgabcdefg", "AE", 10, PR_FALSE, 0 },
+          { "abcdefgabcdefg", "EI", 10, PR_FALSE, 0 },
+          { "abcdefgabcdefg", "IO", 10, PR_FALSE, 0 },
+          { "abcdefgabcdefg", "BCD", 10, PR_FALSE, 0 },
+          { "abcdefgabcdefg", "CBD", 10, PR_FALSE, 0 },
+          { "abcdefgabcdefg", "DBC", 10, PR_FALSE, 0 },
+          { "abcdefgabcdefg", "GHI", 10, PR_FALSE, 0 }
+      };
+
+    int i;
+
+    printf("Test 022 (PL_strnprbrk)   ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        char *rv = PL_strnprbrk(array[i].str, array[i].chrs, array[i].max);
+
+        if( PR_FALSE == array[i].ret )
+        {
+            if( (char *)0 != rv )
+            {
+                printf("FAIL %d: %s,%s/%lu -> %.32s, not null\n", i, 
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].chrs ? array[i].chrs : "(null)", 
+                       array[i].max, rv);
+                return PR_FALSE;
+            }
+        }
+        else
+        {
+            if( (char *)0 == rv )
+            {
+                printf("FAIL %d: %s,%s/%lu -> null, not +%lu\n", i,
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].chrs ? array[i].chrs : "(null)", 
+                       array[i].max, array[i].off);
+                return PR_FALSE;
+            }
+
+            if( &array[i].str[ array[i].off ] != rv )
+            {
+                printf("FAIL %d: %s,%s/%lu -> 0x%x, not 0x%x+%lu\n", i,
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].chrs ? array[i].chrs : "(null)", 
+                       array[i].max, rv, array[i].str, array[i].off);
+                return PR_FALSE;
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_strstr */
+PRBool test_023(void)
+{
+    static struct
+    {
+        const char *str;
+        const char *sub;
+        PRBool      ret;
+        PRUint32    off;
+    } array[] =
+      {
+          { (const char *)0, (const char *)0, PR_FALSE, 0 },
+          { (const char *)0, "blah", PR_FALSE, 0 },
+          { "blah-de-blah", (const char *)0, PR_FALSE, 0 },
+          { "blah-de-blah", "blah", PR_TRUE, 0 },
+          { "", "blah", PR_FALSE, 0 },
+          { "blah-de-blah", "", PR_FALSE, 0 },
+          { "abcdefg", "a", PR_TRUE, 0 },
+          { "abcdefg", "c", PR_TRUE, 2 },
+          { "abcdefg", "e", PR_TRUE, 4 },
+          { "abcdefg", "g", PR_TRUE, 6 },
+          { "abcdefg", "i", PR_FALSE, 0 },
+          { "abcdefg", "ab", PR_TRUE, 0 },
+          { "abcdefg", "cd", PR_TRUE, 2 },
+          { "abcdefg", "ef", PR_TRUE, 4 },
+          { "abcdefg", "gh", PR_FALSE, 0 },
+          { "abcdabc", "bc", PR_TRUE, 1 },
+          { "abcdefg", "abcdefg", PR_TRUE, 0 },
+          { "abcdefgabcdefg", "a", PR_TRUE, 0 },
+          { "abcdefgabcdefg", "c", PR_TRUE, 2 },
+          { "abcdefgabcdefg", "e", PR_TRUE, 4 },
+          { "abcdefgabcdefg", "g", PR_TRUE, 6 },
+          { "abcdefgabcdefg", "i", PR_FALSE, 0 },
+          { "abcdefgabcdefg", "ab", PR_TRUE, 0 },
+          { "abcdefgabcdefg", "cd", PR_TRUE, 2 },
+          { "abcdefgabcdefg", "ef", PR_TRUE, 4 },
+          { "abcdefgabcdefg", "gh", PR_FALSE, 0 },
+          { "abcdabcabcdabc", "bc", PR_TRUE, 1 },
+          { "abcdefgabcdefg", "abcdefg", PR_TRUE, 0 },
+          { "ABCDEFG", "a", PR_FALSE, 0 },
+          { "ABCDEFG", "c", PR_FALSE, 0 },
+          { "ABCDEFG", "e", PR_FALSE, 0 },
+          { "ABCDEFG", "g", PR_FALSE, 0 },
+          { "ABCDEFG", "i", PR_FALSE, 0 },
+          { "ABCDEFG", "ab", PR_FALSE, 0 },
+          { "ABCDEFG", "cd", PR_FALSE, 0 },
+          { "ABCDEFG", "ef", PR_FALSE, 0 },
+          { "ABCDEFG", "gh", PR_FALSE, 0 },
+          { "ABCDABC", "bc", PR_FALSE, 0 },
+          { "ABCDEFG", "abcdefg", PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "a", PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "c", PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "e", PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "g", PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "i", PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "ab", PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "cd", PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "ef", PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "gh", PR_FALSE, 0 },
+          { "ABCDABCABCDABC", "bc", PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "abcdefg", PR_FALSE, 0 }
+      };
+
+    int i;
+
+    printf("Test 023 (PL_strstr)      ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        char *rv = PL_strstr(array[i].str, array[i].sub);
+
+        if( PR_FALSE == array[i].ret )
+        {
+            if( (char *)0 != rv )
+            {
+                printf("FAIL %d: %s,%s -> %.32s, not null\n", i,
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].sub ? array[i].sub : "(null)",
+                       rv);
+                return PR_FALSE;
+            }
+        }
+        else
+        {
+            if( (char *)0 == rv )
+            {
+                printf("FAIL %d: %s,%s -> null, not 0x%x+%lu\n", i,
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].sub ? array[i].sub : "(null)",
+                       array[i].str, array[i].off);
+                return PR_FALSE;
+            }
+
+            if( &array[i].str[ array[i].off ] != rv )
+            {
+                printf("FAIL %d: %s,%s -> 0x%x, not 0x%x+%lu\n", i, 
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].sub ? array[i].sub : "(null)",
+                       rv, array[i].str, array[i].off);
+                return PR_FALSE;
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_strrstr */
+PRBool test_024(void)
+{
+    static struct
+    {
+        const char *str;
+        const char *sub;
+        PRBool      ret;
+        PRUint32    off;
+    } array[] =
+      {
+          { (const char *)0, (const char *)0, PR_FALSE, 0 },
+          { (const char *)0, "blah", PR_FALSE, 0 },
+          { "blah-de-blah", (const char *)0, PR_FALSE, 0 },
+          { "blah-de-blah", "blah", PR_TRUE, 8 },
+          { "", "blah", PR_FALSE, 0 },
+          { "blah-de-blah", "", PR_FALSE, 0 },
+          { "abcdefg", "a", PR_TRUE, 0 },
+          { "abcdefg", "c", PR_TRUE, 2 },
+          { "abcdefg", "e", PR_TRUE, 4 },
+          { "abcdefg", "g", PR_TRUE, 6 },
+          { "abcdefg", "i", PR_FALSE, 0 },
+          { "abcdefg", "ab", PR_TRUE, 0 },
+          { "abcdefg", "cd", PR_TRUE, 2 },
+          { "abcdefg", "ef", PR_TRUE, 4 },
+          { "abcdefg", "gh", PR_FALSE, 0 },
+          { "abcdabc", "bc", PR_TRUE, 5 },
+          { "abcdefg", "abcdefg", PR_TRUE, 0 },
+          { "abcdefgabcdefg", "a", PR_TRUE, 7 },
+          { "abcdefgabcdefg", "c", PR_TRUE, 9 },
+          { "abcdefgabcdefg", "e", PR_TRUE, 11 },
+          { "abcdefgabcdefg", "g", PR_TRUE, 13 },
+          { "abcdefgabcdefg", "i", PR_FALSE, 0 },
+          { "abcdefgabcdefg", "ab", PR_TRUE, 7 },
+          { "abcdefgabcdefg", "cd", PR_TRUE, 9 },
+          { "abcdefgabcdefg", "ef", PR_TRUE, 11 },
+          { "abcdefgabcdefg", "gh", PR_FALSE, 0 },
+          { "abcdabcabcdabc", "bc", PR_TRUE, 12 },
+          { "abcdefgabcdefg", "abcdefg", PR_TRUE, 7 },
+          { "ABCDEFG", "a", PR_FALSE, 0 },
+          { "ABCDEFG", "c", PR_FALSE, 0 },
+          { "ABCDEFG", "e", PR_FALSE, 0 },
+          { "ABCDEFG", "g", PR_FALSE, 0 },
+          { "ABCDEFG", "i", PR_FALSE, 0 },
+          { "ABCDEFG", "ab", PR_FALSE, 0 },
+          { "ABCDEFG", "cd", PR_FALSE, 0 },
+          { "ABCDEFG", "ef", PR_FALSE, 0 },
+          { "ABCDEFG", "gh", PR_FALSE, 0 },
+          { "ABCDABC", "bc", PR_FALSE, 0 },
+          { "ABCDEFG", "abcdefg", PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "a", PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "c", PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "e", PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "g", PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "i", PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "ab", PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "cd", PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "ef", PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "gh", PR_FALSE, 0 },
+          { "ABCDABCABCDABC", "bc", PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "abcdefg", PR_FALSE, 0 }
+      };
+
+    int i;
+
+    printf("Test 024 (PL_strrstr)     ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        char *rv = PL_strrstr(array[i].str, array[i].sub);
+
+        if( PR_FALSE == array[i].ret )
+        {
+            if( (char *)0 != rv )
+            {
+                printf("FAIL %d: %s,%s -> %.32s, not null\n", i,
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].sub ? array[i].sub : "(null)",
+                       rv);
+                return PR_FALSE;
+            }
+        }
+        else
+        {
+            if( (char *)0 == rv )
+            {
+                printf("FAIL %d: %s,%s -> null, not 0x%x+%lu\n", i,
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].sub ? array[i].sub : "(null)",
+                       array[i].str, array[i].off);
+                return PR_FALSE;
+            }
+
+            if( &array[i].str[ array[i].off ] != rv )
+            {
+                printf("FAIL %d: %s,%s -> 0x%x, not 0x%x+%lu\n", i, 
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].sub ? array[i].sub : "(null)",
+                       rv, array[i].str, array[i].off);
+                return PR_FALSE;
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_strnstr */
+PRBool test_025(void)
+{
+    static struct
+    {
+        const char *str;
+        const char *sub;
+        PRUint32    max;
+        PRBool      ret;
+        PRUint32    off;
+    } array[] =
+      {
+          { (const char *)0, (const char *)0, 12, PR_FALSE, 0 },
+          { (const char *)0, "blah", 12, PR_FALSE, 0 },
+          { "blah-de-blah", (const char *)0, 12, PR_FALSE, 0 },
+          { "blah-de-blah", "blah", 0, PR_FALSE, 0 },
+          { "blah-de-blah", "blah", 2, PR_FALSE, 0 },
+          { "blah-de-blah", "blah", 3, PR_FALSE, 0 },
+          { "blah-de-blah", "blah", 4, PR_TRUE, 0 },
+          { "blah-de-blah", "blah", 5, PR_TRUE, 0 },
+          { "blah-de-blah", "blah", 12, PR_TRUE, 0 },
+          { "", "blah", 12, PR_FALSE, 0 },
+          { "blah-de-blah", "", 12, PR_FALSE, 0 },
+          { "abcdefg", "a", 5, PR_TRUE, 0 },
+          { "abcdefg", "c", 5, PR_TRUE, 2 },
+          { "abcdefg", "e", 5, PR_TRUE, 4 },
+          { "abcdefg", "g", 5, PR_FALSE, 0 },
+          { "abcdefg", "i", 5, PR_FALSE, 0 },
+          { "abcdefg", "ab", 5, PR_TRUE, 0 },
+          { "abcdefg", "cd", 5, PR_TRUE, 2 },
+          { "abcdefg", "ef", 5, PR_FALSE, 0 },
+          { "abcdefg", "gh", 5, PR_FALSE, 0 },
+          { "abcdabc", "bc", 5, PR_TRUE, 1 },
+          { "abcdabc", "bc", 6, PR_TRUE, 1 },
+          { "abcdabc", "bc", 7, PR_TRUE, 1 },
+          { "abcdefg", "abcdefg", 6, PR_FALSE, 0 },
+          { "abcdefg", "abcdefg", 7, PR_TRUE, 0 },
+          { "abcdefg", "abcdefg", 8, PR_TRUE, 0 },
+          { "abcdefgabcdefg", "a", 12, PR_TRUE, 0 },
+          { "abcdefgabcdefg", "c", 12, PR_TRUE, 2 },
+          { "abcdefgabcdefg", "e", 12, PR_TRUE, 4 },
+          { "abcdefgabcdefg", "g", 12, PR_TRUE, 6 },
+          { "abcdefgabcdefg", "i", 12, PR_FALSE, 0 },
+          { "abcdefgabcdefg", "ab", 12, PR_TRUE, 0 },
+          { "abcdefgabcdefg", "cd", 12, PR_TRUE, 2 },
+          { "abcdefgabcdefg", "ef", 12, PR_TRUE, 4 },
+          { "abcdefgabcdefg", "gh", 12, PR_FALSE, 0 },
+          { "abcdabcabcdabc", "bc", 5, PR_TRUE, 1 },
+          { "abcdabcabcdabc", "bc", 6, PR_TRUE, 1 },
+          { "abcdabcabcdabc", "bc", 7, PR_TRUE, 1 },
+          { "abcdefgabcdefg", "abcdefg", 6, PR_FALSE, 0 },
+          { "abcdefgabcdefg", "abcdefg", 7, PR_TRUE, 0 },
+          { "abcdefgabcdefg", "abcdefg", 8, PR_TRUE, 0 },
+          { "ABCDEFG", "a", 5, PR_FALSE, 0 },
+          { "ABCDEFG", "c", 5, PR_FALSE, 0 },
+          { "ABCDEFG", "e", 5, PR_FALSE, 0 },
+          { "ABCDEFG", "g", 5, PR_FALSE, 0 },
+          { "ABCDEFG", "i", 5, PR_FALSE, 0 },
+          { "ABCDEFG", "ab", 5, PR_FALSE, 0 },
+          { "ABCDEFG", "cd", 5, PR_FALSE, 0 },
+          { "ABCDEFG", "ef", 5, PR_FALSE, 0 },
+          { "ABCDEFG", "gh", 5, PR_FALSE, 0 },
+          { "ABCDABC", "bc", 5, PR_FALSE, 0 },
+          { "ABCDABC", "bc", 6, PR_FALSE, 0 },
+          { "ABCDABC", "bc", 7, PR_FALSE, 0 },
+          { "ABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
+          { "ABCDEFG", "abcdefg", 7, PR_FALSE, 0 },
+          { "ABCDEFG", "abcdefg", 8, PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "a", 12, PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "c", 12, PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "e", 12, PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "g", 12, PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "i", 12, PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "ab", 12, PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "cd", 12, PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "ef", 12, PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "gh", 12, PR_FALSE, 0 },
+          { "ABCDABCABCDABC", "bc", 5, PR_FALSE, 0 },
+          { "ABCDABCABCDABC", "bc", 6, PR_FALSE, 0 },
+          { "ABCDABCABCDABC", "bc", 7, PR_FALSE,  },
+          { "ABCDEFGABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "abcdefg", 7, PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "abcdefg", 8, PR_FALSE, 0 }
+      };
+
+    int i;
+
+    printf("Test 025 (PL_strnstr)     ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        char *rv = PL_strnstr(array[i].str, array[i].sub, array[i].max);
+
+        if( PR_FALSE == array[i].ret )
+        {
+            if( (char *)0 != rv )
+            {
+                printf("FAIL %d: %s,%s/%lu -> %.32s, not null\n", i,
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].sub ? array[i].sub : "(null)",
+                       array[i].max, rv);
+                return PR_FALSE;
+            }
+        }
+        else
+        {
+            if( (char *)0 == rv )
+            {
+                printf("FAIL %d: %s,%s/%lu -> null, not 0x%x+%lu\n", i,
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].sub ? array[i].sub : "(null)",
+                       array[i].max, array[i].str, array[i].off);
+                return PR_FALSE;
+            }
+
+            if( &array[i].str[ array[i].off ] != rv )
+            {
+                printf("FAIL %d: %s,%s/%lu -> 0x%x, not 0x%x+%lu\n", i, 
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].sub ? array[i].sub : "(null)",
+                       array[i].max, rv, array[i].str, array[i].off);
+                return PR_FALSE;
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_strnrstr */
+PRBool test_026(void)
+{
+    static struct
+    {
+        const char *str;
+        const char *sub;
+        PRUint32    max;
+        PRBool      ret;
+        PRUint32    off;
+    } array[] =
+      {
+          { (const char *)0, (const char *)0, 12, PR_FALSE, 0 },
+          { (const char *)0, "blah", 12, PR_FALSE, 0 },
+          { "blah-de-blah", (const char *)0, 12, PR_FALSE, 0 },
+          { "blah-de-blah", "blah", 0, PR_FALSE, 0 },
+          { "blah-de-blah", "blah", 2, PR_FALSE, 0 },
+          { "blah-de-blah", "blah", 3, PR_FALSE, 0 },
+          { "blah-de-blah", "blah", 4, PR_TRUE, 0 },
+          { "blah-de-blah", "blah", 5, PR_TRUE, 0 },
+          { "blah-de-blah", "blah", 11, PR_TRUE, 0 },
+          { "blah-de-blah", "blah", 12, PR_TRUE, 8 },
+          { "blah-de-blah", "blah", 13, PR_TRUE, 8 },
+          { "", "blah", 12, PR_FALSE, 0 },
+          { "blah-de-blah", "", 12, PR_FALSE, 0 },
+          { "abcdefg", "a", 5, PR_TRUE, 0 },
+          { "abcdefg", "c", 5, PR_TRUE, 2 },
+          { "abcdefg", "e", 5, PR_TRUE, 4 },
+          { "abcdefg", "g", 5, PR_FALSE, 0 },
+          { "abcdefg", "i", 5, PR_FALSE, 0 },
+          { "abcdefg", "ab", 5, PR_TRUE, 0 },
+          { "abcdefg", "cd", 5, PR_TRUE, 2 },
+          { "abcdefg", "ef", 5, PR_FALSE, 0 },
+          { "abcdefg", "gh", 5, PR_FALSE, 0 },
+          { "abcdabc", "bc", 5, PR_TRUE, 1 },
+          { "abcdabc", "bc", 6, PR_TRUE, 1 },
+          { "abcdabc", "bc", 7, PR_TRUE, 5 },
+          { "abcdefg", "abcdefg", 6, PR_FALSE, 0 },
+          { "abcdefg", "abcdefg", 7, PR_TRUE, 0 },
+          { "abcdefg", "abcdefg", 8, PR_TRUE, 0 },
+          { "abcdefgabcdefg", "a", 12, PR_TRUE, 7 },
+          { "abcdefgabcdefg", "c", 12, PR_TRUE, 9 },
+          { "abcdefgabcdefg", "e", 12, PR_TRUE, 11 },
+          { "abcdefgabcdefg", "g", 12, PR_TRUE, 6 },
+          { "abcdefgabcdefg", "i", 12, PR_FALSE, 0 },
+          { "abcdefgabcdefg", "ab", 12, PR_TRUE, 7 },
+          { "abcdefgabcdefg", "cd", 12, PR_TRUE, 9 },
+          { "abcdefgabcdefg", "ef", 12, PR_TRUE, 4 },
+          { "abcdefgabcdefg", "gh", 12, PR_FALSE, 0 },
+          { "abcdabcabcdabc", "bc", 12, PR_TRUE, 8 },
+          { "abcdabcabcdabc", "bc", 13, PR_TRUE, 8 },
+          { "abcdabcabcdabc", "bc", 14, PR_TRUE, 12 },
+          { "abcdefgabcdefg", "abcdefg", 13, PR_TRUE, 0 },
+          { "abcdefgabcdefg", "abcdefg", 14, PR_TRUE, 7 },
+          { "abcdefgabcdefg", "abcdefg", 15, PR_TRUE, 7 },
+          { "ABCDEFG", "a", 5, PR_FALSE, 0 },
+          { "ABCDEFG", "c", 5, PR_FALSE, 0 },
+          { "ABCDEFG", "e", 5, PR_FALSE, 0 },
+          { "ABCDEFG", "g", 5, PR_FALSE, 0 },
+          { "ABCDEFG", "i", 5, PR_FALSE, 0 },
+          { "ABCDEFG", "ab", 5, PR_FALSE, 0 },
+          { "ABCDEFG", "cd", 5, PR_FALSE, 0 },
+          { "ABCDEFG", "ef", 5, PR_FALSE, 0 },
+          { "ABCDEFG", "gh", 5, PR_FALSE, 0 },
+          { "ABCDABC", "bc", 5, PR_FALSE, 0 },
+          { "ABCDABC", "bc", 6, PR_FALSE, 0 },
+          { "ABCDABC", "bc", 7, PR_FALSE, 0 },
+          { "ABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
+          { "ABCDEFG", "abcdefg", 7, PR_FALSE, 0 },
+          { "ABCDEFG", "abcdefg", 8, PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "a", 12, PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "c", 12, PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "e", 12, PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "g", 12, PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "i", 12, PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "ab", 12, PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "cd", 12, PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "ef", 12, PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "gh", 12, PR_FALSE, 0 },
+          { "ABCDABCABCDABC", "bc", 12, PR_FALSE, 0 },
+          { "ABCDABCABCDABC", "bc", 13, PR_FALSE, 0 },
+          { "ABCDABCABCDABC", "bc", 14, PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "abcdefg", 13, PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "abcdefg", 14, PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "abcdefg", 15, PR_FALSE, 0 }
+      };
+
+    int i;
+
+    printf("Test 026 (PL_strnrstr)    ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        char *rv = PL_strnrstr(array[i].str, array[i].sub, array[i].max);
+
+        if( PR_FALSE == array[i].ret )
+        {
+            if( (char *)0 != rv )
+            {
+                printf("FAIL %d: %s,%s/%lu -> %.32s, not null\n", i,
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].sub ? array[i].sub : "(null)",
+                       array[i].max, rv);
+                return PR_FALSE;
+            }
+        }
+        else
+        {
+            if( (char *)0 == rv )
+            {
+                printf("FAIL %d: %s,%s/%lu -> null, not 0x%x+%lu\n", i,
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].sub ? array[i].sub : "(null)",
+                       array[i].max, array[i].str, array[i].off);
+                return PR_FALSE;
+            }
+
+            if( &array[i].str[ array[i].off ] != rv )
+            {
+                printf("FAIL %d: %s,%s/%lu -> 0x%x, not 0x%x+%lu\n", i, 
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].sub ? array[i].sub : "(null)",
+                       array[i].max, rv, array[i].str, array[i].off);
+                return PR_FALSE;
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_strcasestr */
+PRBool test_027(void)
+{
+    static struct
+    {
+        const char *str;
+        const char *sub;
+        PRBool      ret;
+        PRUint32    off;
+    } array[] =
+      {
+          { (const char *)0, (const char *)0, PR_FALSE, 0 },
+          { (const char *)0, "blah", PR_FALSE, 0 },
+          { "blah-de-blah", (const char *)0, PR_FALSE, 0 },
+          { "blah-de-blah", "blah", PR_TRUE, 0 },
+          { "", "blah", PR_FALSE, 0 },
+          { "blah-de-blah", "", PR_FALSE, 0 },
+          { "abcdefg", "a", PR_TRUE, 0 },
+          { "abcdefg", "c", PR_TRUE, 2 },
+          { "abcdefg", "e", PR_TRUE, 4 },
+          { "abcdefg", "g", PR_TRUE, 6 },
+          { "abcdefg", "i", PR_FALSE, 0 },
+          { "abcdefg", "ab", PR_TRUE, 0 },
+          { "abcdefg", "cd", PR_TRUE, 2 },
+          { "abcdefg", "ef", PR_TRUE, 4 },
+          { "abcdefg", "gh", PR_FALSE, 0 },
+          { "abcdabc", "bc", PR_TRUE, 1 },
+          { "abcdefg", "abcdefg", PR_TRUE, 0 },
+          { "abcdefgabcdefg", "a", PR_TRUE, 0 },
+          { "abcdefgabcdefg", "c", PR_TRUE, 2 },
+          { "abcdefgabcdefg", "e", PR_TRUE, 4 },
+          { "abcdefgabcdefg", "g", PR_TRUE, 6 },
+          { "abcdefgabcdefg", "i", PR_FALSE, 0 },
+          { "abcdefgabcdefg", "ab", PR_TRUE, 0 },
+          { "abcdefgabcdefg", "cd", PR_TRUE, 2 },
+          { "abcdefgabcdefg", "ef", PR_TRUE, 4 },
+          { "abcdefgabcdefg", "gh", PR_FALSE, 0 },
+          { "abcdabcabcdabc", "bc", PR_TRUE, 1 },
+          { "abcdefgabcdefg", "abcdefg", PR_TRUE, 0 },
+          { "ABCDEFG", "a", PR_TRUE, 0 },
+          { "ABCDEFG", "c", PR_TRUE, 2 },
+          { "ABCDEFG", "e", PR_TRUE, 4 },
+          { "ABCDEFG", "g", PR_TRUE, 6 },
+          { "ABCDEFG", "i", PR_FALSE, 0 },
+          { "ABCDEFG", "ab", PR_TRUE, 0 },
+          { "ABCDEFG", "cd", PR_TRUE, 2 },
+          { "ABCDEFG", "ef", PR_TRUE, 4 },
+          { "ABCDEFG", "gh", PR_FALSE, 0 },
+          { "ABCDABC", "bc", PR_TRUE, 1 },
+          { "ABCDEFG", "abcdefg", PR_TRUE, 0 },
+          { "ABCDEFGABCDEFG", "a", PR_TRUE, 0 },
+          { "ABCDEFGABCDEFG", "c", PR_TRUE, 2 },
+          { "ABCDEFGABCDEFG", "e", PR_TRUE, 4 },
+          { "ABCDEFGABCDEFG", "g", PR_TRUE, 6 },
+          { "ABCDEFGABCDEFG", "i", PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "ab", PR_TRUE, 0 },
+          { "ABCDEFGABCDEFG", "cd", PR_TRUE, 2 },
+          { "ABCDEFGABCDEFG", "ef", PR_TRUE, 4 },
+          { "ABCDEFGABCDEFG", "gh", PR_FALSE, 0 },
+          { "ABCDABCABCDABC", "bc", PR_TRUE, 1 },
+          { "ABCDEFGABCDEFG", "abcdefg", PR_TRUE, 0 }
+      };
+
+    int i;
+
+    printf("Test 027 (PL_strcasestr)  ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        char *rv = PL_strcasestr(array[i].str, array[i].sub);
+
+        if( PR_FALSE == array[i].ret )
+        {
+            if( (char *)0 != rv )
+            {
+                printf("FAIL %d: %s,%s -> %.32s, not null\n", i,
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].sub ? array[i].sub : "(null)",
+                       rv);
+                return PR_FALSE;
+            }
+        }
+        else
+        {
+            if( (char *)0 == rv )
+            {
+                printf("FAIL %d: %s,%s -> null, not 0x%x+%lu\n", i,
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].sub ? array[i].sub : "(null)",
+                       array[i].str, array[i].off);
+                return PR_FALSE;
+            }
+
+            if( &array[i].str[ array[i].off ] != rv )
+            {
+                printf("FAIL %d: %s,%s -> 0x%x, not 0x%x+%lu\n", i, 
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].sub ? array[i].sub : "(null)",
+                       rv, array[i].str, array[i].off);
+                return PR_FALSE;
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_strcaserstr */
+PRBool test_028(void)
+{
+    static struct
+    {
+        const char *str;
+        const char *sub;
+        PRBool      ret;
+        PRUint32    off;
+    } array[] =
+      {
+          { (const char *)0, (const char *)0, PR_FALSE, 0 },
+          { (const char *)0, "blah", PR_FALSE, 0 },
+          { "blah-de-blah", (const char *)0, PR_FALSE, 0 },
+          { "blah-de-blah", "blah", PR_TRUE, 8 },
+          { "", "blah", PR_FALSE, 0 },
+          { "blah-de-blah", "", PR_FALSE, 0 },
+          { "abcdefg", "a", PR_TRUE, 0 },
+          { "abcdefg", "c", PR_TRUE, 2 },
+          { "abcdefg", "e", PR_TRUE, 4 },
+          { "abcdefg", "g", PR_TRUE, 6 },
+          { "abcdefg", "i", PR_FALSE, 0 },
+          { "abcdefg", "ab", PR_TRUE, 0 },
+          { "abcdefg", "cd", PR_TRUE, 2 },
+          { "abcdefg", "ef", PR_TRUE, 4 },
+          { "abcdefg", "gh", PR_FALSE, 0 },
+          { "abcdabc", "bc", PR_TRUE, 5 },
+          { "abcdefg", "abcdefg", PR_TRUE, 0 },
+          { "abcdefgabcdefg", "a", PR_TRUE, 7 },
+          { "abcdefgabcdefg", "c", PR_TRUE, 9 },
+          { "abcdefgabcdefg", "e", PR_TRUE, 11 },
+          { "abcdefgabcdefg", "g", PR_TRUE, 13 },
+          { "abcdefgabcdefg", "i", PR_FALSE, 0 },
+          { "abcdefgabcdefg", "ab", PR_TRUE, 7 },
+          { "abcdefgabcdefg", "cd", PR_TRUE, 9 },
+          { "abcdefgabcdefg", "ef", PR_TRUE, 11 },
+          { "abcdefgabcdefg", "gh", PR_FALSE, 0 },
+          { "abcdabcabcdabc", "bc", PR_TRUE, 12 },
+          { "abcdefgabcdefg", "abcdefg", PR_TRUE, 7 },
+          { "ABCDEFG", "a", PR_TRUE, 0 },
+          { "ABCDEFG", "c", PR_TRUE, 2 },
+          { "ABCDEFG", "e", PR_TRUE, 4 },
+          { "ABCDEFG", "g", PR_TRUE, 6 },
+          { "ABCDEFG", "i", PR_FALSE, 0 },
+          { "ABCDEFG", "ab", PR_TRUE, 0 },
+          { "ABCDEFG", "cd", PR_TRUE, 2 },
+          { "ABCDEFG", "ef", PR_TRUE, 4 },
+          { "ABCDEFG", "gh", PR_FALSE, 0 },
+          { "ABCDABC", "bc", PR_TRUE, 5 },
+          { "ABCDEFG", "abcdefg", PR_TRUE, 0 },
+          { "ABCDEFGABCDEFG", "a", PR_TRUE, 7 },
+          { "ABCDEFGABCDEFG", "c", PR_TRUE, 9 },
+          { "ABCDEFGABCDEFG", "e", PR_TRUE, 11 },
+          { "ABCDEFGABCDEFG", "g", PR_TRUE, 13 },
+          { "ABCDEFGABCDEFG", "i", PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "ab", PR_TRUE, 7 },
+          { "ABCDEFGABCDEFG", "cd", PR_TRUE, 9 },
+          { "ABCDEFGABCDEFG", "ef", PR_TRUE, 11 },
+          { "ABCDEFGABCDEFG", "gh", PR_FALSE, 0 },
+          { "ABCDABCABCDABC", "bc", PR_TRUE, 12 },
+          { "ABCDEFGABCDEFG", "abcdefg", PR_TRUE, 7 }
+      };
+
+    int i;
+
+    printf("Test 028 (PL_strcaserstr) ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        char *rv = PL_strcaserstr(array[i].str, array[i].sub);
+
+        if( PR_FALSE == array[i].ret )
+        {
+            if( (char *)0 != rv )
+            {
+                printf("FAIL %d: %s,%s -> %.32s, not null\n", i,
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].sub ? array[i].sub : "(null)",
+                       rv);
+                return PR_FALSE;
+            }
+        }
+        else
+        {
+            if( (char *)0 == rv )
+            {
+                printf("FAIL %d: %s,%s -> null, not 0x%x+%lu\n", i,
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].sub ? array[i].sub : "(null)",
+                       array[i].str, array[i].off);
+                return PR_FALSE;
+            }
+
+            if( &array[i].str[ array[i].off ] != rv )
+            {
+                printf("FAIL %d: %s,%s -> 0x%x, not 0x%x+%lu\n", i, 
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].sub ? array[i].sub : "(null)",
+                       rv, array[i].str, array[i].off);
+                return PR_FALSE;
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_strncasestr */
+PRBool test_029(void)
+{
+    static struct
+    {
+        const char *str;
+        const char *sub;
+        PRUint32    max;
+        PRBool      ret;
+        PRUint32    off;
+    } array[] =
+      {
+          { (const char *)0, (const char *)0, 12, PR_FALSE, 0 },
+          { (const char *)0, "blah", 12, PR_FALSE, 0 },
+          { "blah-de-blah", (const char *)0, 12, PR_FALSE, 0 },
+          { "blah-de-blah", "blah", 0, PR_FALSE, 0 },
+          { "blah-de-blah", "blah", 2, PR_FALSE, 0 },
+          { "blah-de-blah", "blah", 3, PR_FALSE, 0 },
+          { "blah-de-blah", "blah", 4, PR_TRUE, 0 },
+          { "blah-de-blah", "blah", 5, PR_TRUE, 0 },
+          { "blah-de-blah", "blah", 12, PR_TRUE, 0 },
+          { "", "blah", 12, PR_FALSE, 0 },
+          { "blah-de-blah", "", 12, PR_FALSE, 0 },
+          { "abcdefg", "a", 5, PR_TRUE, 0 },
+          { "abcdefg", "c", 5, PR_TRUE, 2 },
+          { "abcdefg", "e", 5, PR_TRUE, 4 },
+          { "abcdefg", "g", 5, PR_FALSE, 0 },
+          { "abcdefg", "i", 5, PR_FALSE, 0 },
+          { "abcdefg", "ab", 5, PR_TRUE, 0 },
+          { "abcdefg", "cd", 5, PR_TRUE, 2 },
+          { "abcdefg", "ef", 5, PR_FALSE, 0 },
+          { "abcdefg", "gh", 5, PR_FALSE, 0 },
+          { "abcdabc", "bc", 5, PR_TRUE, 1 },
+          { "abcdabc", "bc", 6, PR_TRUE, 1 },
+          { "abcdabc", "bc", 7, PR_TRUE, 1 },
+          { "abcdefg", "abcdefg", 6, PR_FALSE, 0 },
+          { "abcdefg", "abcdefg", 7, PR_TRUE, 0 },
+          { "abcdefg", "abcdefg", 8, PR_TRUE, 0 },
+          { "abcdefgabcdefg", "a", 12, PR_TRUE, 0 },
+          { "abcdefgabcdefg", "c", 12, PR_TRUE, 2 },
+          { "abcdefgabcdefg", "e", 12, PR_TRUE, 4 },
+          { "abcdefgabcdefg", "g", 12, PR_TRUE, 6 },
+          { "abcdefgabcdefg", "i", 12, PR_FALSE, 0 },
+          { "abcdefgabcdefg", "ab", 12, PR_TRUE, 0 },
+          { "abcdefgabcdefg", "cd", 12, PR_TRUE, 2 },
+          { "abcdefgabcdefg", "ef", 12, PR_TRUE, 4 },
+          { "abcdefgabcdefg", "gh", 12, PR_FALSE, 0 },
+          { "abcdabcabcdabc", "bc", 5, PR_TRUE, 1 },
+          { "abcdabcabcdabc", "bc", 6, PR_TRUE, 1 },
+          { "abcdabcabcdabc", "bc", 7, PR_TRUE, 1 },
+          { "abcdefgabcdefg", "abcdefg", 6, PR_FALSE, 0 },
+          { "abcdefgabcdefg", "abcdefg", 7, PR_TRUE, 0 },
+          { "abcdefgabcdefg", "abcdefg", 8, PR_TRUE, 0 },
+          { "ABCDEFG", "a", 5, PR_TRUE, 0 },
+          { "ABCDEFG", "c", 5, PR_TRUE, 2 },
+          { "ABCDEFG", "e", 5, PR_TRUE, 4 },
+          { "ABCDEFG", "g", 5, PR_FALSE, 0 },
+          { "ABCDEFG", "i", 5, PR_FALSE, 0 },
+          { "ABCDEFG", "ab", 5, PR_TRUE, 0 },
+          { "ABCDEFG", "cd", 5, PR_TRUE, 2 },
+          { "ABCDEFG", "ef", 5, PR_FALSE, 0 },
+          { "ABCDEFG", "gh", 5, PR_FALSE, 0 },
+          { "ABCDABC", "bc", 5, PR_TRUE, 1 },
+          { "ABCDABC", "bc", 6, PR_TRUE, 1 },
+          { "ABCDABC", "bc", 7, PR_TRUE, 1 },
+          { "ABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
+          { "ABCDEFG", "abcdefg", 7, PR_TRUE, 0 },
+          { "ABCDEFG", "abcdefg", 8, PR_TRUE, 0 },
+          { "ABCDEFGABCDEFG", "a", 12, PR_TRUE, 0 },
+          { "ABCDEFGABCDEFG", "c", 12, PR_TRUE, 2 },
+          { "ABCDEFGABCDEFG", "e", 12, PR_TRUE, 4 },
+          { "ABCDEFGABCDEFG", "g", 12, PR_TRUE, 6 },
+          { "ABCDEFGABCDEFG", "i", 12, PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "ab", 12, PR_TRUE, 0 },
+          { "ABCDEFGABCDEFG", "cd", 12, PR_TRUE, 2 },
+          { "ABCDEFGABCDEFG", "ef", 12, PR_TRUE, 4 },
+          { "ABCDEFGABCDEFG", "gh", 12, PR_FALSE, 0 },
+          { "ABCDABCABCDABC", "bc", 5, PR_TRUE, 1 },
+          { "ABCDABCABCDABC", "bc", 6, PR_TRUE, 1 },
+          { "ABCDABCABCDABC", "bc", 7, PR_TRUE, 1 },
+          { "ABCDEFGABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "abcdefg", 7, PR_TRUE, 0 },
+          { "ABCDEFGABCDEFG", "abcdefg", 8, PR_TRUE, 0 }
+      };
+
+    int i;
+
+    printf("Test 029 (PL_strncasestr) ..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        char *rv = PL_strncasestr(array[i].str, array[i].sub, array[i].max);
+
+        if( PR_FALSE == array[i].ret )
+        {
+            if( (char *)0 != rv )
+            {
+                printf("FAIL %d: %s,%s/%lu -> %.32s, not null\n", i,
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].sub ? array[i].sub : "(null)",
+                       array[i].max, rv);
+                return PR_FALSE;
+            }
+        }
+        else
+        {
+            if( (char *)0 == rv )
+            {
+                printf("FAIL %d: %s,%s/%lu -> null, not 0x%x+%lu\n", i,
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].sub ? array[i].sub : "(null)",
+                       array[i].max, array[i].str, array[i].off);
+                return PR_FALSE;
+            }
+
+            if( &array[i].str[ array[i].off ] != rv )
+            {
+                printf("FAIL %d: %s,%s/%lu -> 0x%x, not 0x%x+%lu\n", i, 
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].sub ? array[i].sub : "(null)",
+                       array[i].max, rv, array[i].str, array[i].off);
+                return PR_FALSE;
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_strncaserstr */
+PRBool test_030(void)
+{
+    static struct
+    {
+        const char *str;
+        const char *sub;
+        PRUint32    max;
+        PRBool      ret;
+        PRUint32    off;
+    } array[] =
+      {
+          { (const char *)0, (const char *)0, 12, PR_FALSE, 0 },
+          { (const char *)0, "blah", 12, PR_FALSE, 0 },
+          { "blah-de-blah", (const char *)0, 12, PR_FALSE, 0 },
+          { "blah-de-blah", "blah", 0, PR_FALSE, 0 },
+          { "blah-de-blah", "blah", 2, PR_FALSE, 0 },
+          { "blah-de-blah", "blah", 3, PR_FALSE, 0 },
+          { "blah-de-blah", "blah", 4, PR_TRUE, 0 },
+          { "blah-de-blah", "blah", 5, PR_TRUE, 0 },
+          { "blah-de-blah", "blah", 11, PR_TRUE, 0 },
+          { "blah-de-blah", "blah", 12, PR_TRUE, 8 },
+          { "blah-de-blah", "blah", 13, PR_TRUE, 8 },
+          { "", "blah", 12, PR_FALSE, 0 },
+          { "blah-de-blah", "", 12, PR_FALSE, 0 },
+          { "abcdefg", "a", 5, PR_TRUE, 0 },
+          { "abcdefg", "c", 5, PR_TRUE, 2 },
+          { "abcdefg", "e", 5, PR_TRUE, 4 },
+          { "abcdefg", "g", 5, PR_FALSE, 0 },
+          { "abcdefg", "i", 5, PR_FALSE, 0 },
+          { "abcdefg", "ab", 5, PR_TRUE, 0 },
+          { "abcdefg", "cd", 5, PR_TRUE, 2 },
+          { "abcdefg", "ef", 5, PR_FALSE, 0 },
+          { "abcdefg", "gh", 5, PR_FALSE, 0 },
+          { "abcdabc", "bc", 5, PR_TRUE, 1 },
+          { "abcdabc", "bc", 6, PR_TRUE, 1 },
+          { "abcdabc", "bc", 7, PR_TRUE, 5 },
+          { "abcdefg", "abcdefg", 6, PR_FALSE, 0 },
+          { "abcdefg", "abcdefg", 7, PR_TRUE, 0 },
+          { "abcdefg", "abcdefg", 8, PR_TRUE, 0 },
+          { "abcdefgabcdefg", "a", 12, PR_TRUE, 7 },
+          { "abcdefgabcdefg", "c", 12, PR_TRUE, 9 },
+          { "abcdefgabcdefg", "e", 12, PR_TRUE, 11 },
+          { "abcdefgabcdefg", "g", 12, PR_TRUE, 6 },
+          { "abcdefgabcdefg", "i", 12, PR_FALSE, 0 },
+          { "abcdefgabcdefg", "ab", 12, PR_TRUE, 7 },
+          { "abcdefgabcdefg", "cd", 12, PR_TRUE, 9 },
+          { "abcdefgabcdefg", "ef", 12, PR_TRUE, 4 },
+          { "abcdefgabcdefg", "gh", 12, PR_FALSE, 0 },
+          { "abcdabcabcdabc", "bc", 12, PR_TRUE, 8 },
+          { "abcdabcabcdabc", "bc", 13, PR_TRUE, 8 },
+          { "abcdabcabcdabc", "bc", 14, PR_TRUE, 12 },
+          { "abcdefgabcdefg", "abcdefg", 13, PR_TRUE, 0 },
+          { "abcdefgabcdefg", "abcdefg", 14, PR_TRUE, 7 },
+          { "abcdefgabcdefg", "abcdefg", 15, PR_TRUE, 7 },
+          { "ABCDEFG", "a", 5, PR_TRUE, 0 },
+          { "ABCDEFG", "c", 5, PR_TRUE, 2 },
+          { "ABCDEFG", "e", 5, PR_TRUE, 4 },
+          { "ABCDEFG", "g", 5, PR_FALSE, 0 },
+          { "ABCDEFG", "i", 5, PR_FALSE, 0 },
+          { "ABCDEFG", "ab", 5, PR_TRUE, 0 },
+          { "ABCDEFG", "cd", 5, PR_TRUE, 2 },
+          { "ABCDEFG", "ef", 5, PR_FALSE, 0 },
+          { "ABCDEFG", "gh", 5, PR_FALSE, 0 },
+          { "ABCDABC", "bc", 5, PR_TRUE, 1 },
+          { "ABCDABC", "bc", 6, PR_TRUE, 1 },
+          { "ABCDABC", "bc", 7, PR_TRUE, 5 },
+          { "ABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
+          { "ABCDEFG", "abcdefg", 7, PR_TRUE, 0 },
+          { "ABCDEFG", "abcdefg", 8, PR_TRUE, 0 },
+          { "ABCDEFGABCDEFG", "a", 12, PR_TRUE, 7 },
+          { "ABCDEFGABCDEFG", "c", 12, PR_TRUE, 9 },
+          { "ABCDEFGABCDEFG", "e", 12, PR_TRUE, 11 },
+          { "ABCDEFGABCDEFG", "g", 12, PR_TRUE, 6 },
+          { "ABCDEFGABCDEFG", "i", 12, PR_FALSE, 0 },
+          { "ABCDEFGABCDEFG", "ab", 12, PR_TRUE, 7 },
+          { "ABCDEFGABCDEFG", "cd", 12, PR_TRUE, 9 },
+          { "ABCDEFGABCDEFG", "ef", 12, PR_TRUE, 4 },
+          { "ABCDEFGABCDEFG", "gh", 12, PR_FALSE, 0 },
+          { "ABCDABCABCDABC", "bc", 12, PR_TRUE, 8 },
+          { "ABCDABCABCDABC", "bc", 13, PR_TRUE, 8 },
+          { "ABCDABCABCDABC", "bc", 14, PR_TRUE, 12 },
+          { "ABCDEFGABCDEFG", "abcdefg", 13, PR_TRUE, 0 },
+          { "ABCDEFGABCDEFG", "abcdefg", 14, PR_TRUE, 7 },
+          { "ABCDEFGABCDEFG", "abcdefg", 15, PR_TRUE, 7 }
+      };
+
+    int i;
+
+    printf("Test 030 (PL_strncaserstr)..."); fflush(stdout);
+
+    for( i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
+    {
+        char *rv = PL_strncaserstr(array[i].str, array[i].sub, array[i].max);
+
+        if( PR_FALSE == array[i].ret )
+        {
+            if( (char *)0 != rv )
+            {
+                printf("FAIL %d: %s,%s/%lu -> %.32s, not null\n", i,
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].sub ? array[i].sub : "(null)",
+                       array[i].max, rv);
+                return PR_FALSE;
+            }
+        }
+        else
+        {
+            if( (char *)0 == rv )
+            {
+                printf("FAIL %d: %s,%s/%lu -> null, not 0x%x+%lu\n", i,
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].sub ? array[i].sub : "(null)",
+                       array[i].max, array[i].str, array[i].off);
+                return PR_FALSE;
+            }
+
+            if( &array[i].str[ array[i].off ] != rv )
+            {
+                printf("FAIL %d: %s,%s/%lu -> 0x%x, not 0x%x+%lu\n", i, 
+                       array[i].str ? array[i].str : "(null)",
+                       array[i].sub ? array[i].sub : "(null)",
+                       array[i].max, rv, array[i].str, array[i].off);
+                return PR_FALSE;
+            }
+        }
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+/* PL_strtok_r */
+PRBool test_031(void)
+{
+    static const char *tokens[] = {
+        "wtc", "relyea", "nelsonb", "jpierre", "nicolson",
+        "ian.mcgreer", "kirk.erickson", "sonja.mirtitsch", "mhein"
+    };
+
+    static const char *seps[] = {
+        ", ", ",", " ", "\t", ",,,", " ,", "    ", " \t\t", ","
+    };
+
+    static const char s2[] = ", \t";
+
+    char string[ 1024 ];
+    char *s1;
+    char *token;
+    char *lasts;
+    unsigned int i;
+
+    printf("Test 031 (PL_strtok_r)    ..."); fflush(stdout);
+
+    /* Build the string. */
+    string[0] = '\0';
+    for( i = 0; i < sizeof(tokens)/sizeof(tokens[0]); i++ )
+    {
+        PL_strcat(string, tokens[i]);
+        PL_strcat(string, seps[i]);
+    }
+    
+    /* Scan the string for tokens. */
+    i = 0;
+    s1 = string;
+    while( (token = PL_strtok_r(s1, s2, &lasts)) != NULL)
+    {
+        if( PL_strcmp(token, tokens[i]) != 0 )
+        {
+            printf("FAIL wrong token scanned\n");
+            return PR_FALSE;
+        }
+        i++;
+        s1 = NULL;
+    }
+    if( i != sizeof(tokens)/sizeof(tokens[0]) )
+    {
+        printf("FAIL wrong number of tokens scanned\n");
+        return PR_FALSE;
+    }
+
+    printf("PASS\n");
+    return PR_TRUE;
+}
+
+int
+main
+(
+    int     argc,
+    char   *argv[]
+)
+{
+    printf("Testing the Portable Library string functions:\n");
+
+    if( 1
+        && test_001()
+        && test_001()
+        && test_002()
+        && test_003()
+        && test_004()
+        && test_005()
+        && test_006()
+        && test_007()
+        && test_008()
+        && test_009()
+        && test_010()
+        && test_011()
+        && test_012()
+        && test_013()
+        && test_014()
+        && test_015()
+        && test_016()
+        && test_017()
+        && test_018()
+        && test_019()
+        && test_020()
+        && test_021()
+        && test_022()
+        && test_023()
+        && test_024()
+        && test_025()
+        && test_026()
+        && test_027()
+        && test_028()
+        && test_029()
+        && test_030()
+        && test_031()
+      )
+    {
+        printf("Suite passed.\n");
+        return 0;
+    }
+    else
+    {
+        printf("Suite failed.\n");
+        return 1;
+    }
+
+    /*NOTREACHED*/
+}
diff --git a/pkg/Makefile.in b/pkg/Makefile.in
new file mode 100644
index 0000000..69830da
--- /dev/null
+++ b/pkg/Makefile.in
@@ -0,0 +1,29 @@
+# 
+# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#! gmake
+
+MOD_DEPTH	= ..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+
+include $(MOD_DEPTH)/config/autoconf.mk
+
+DIRS = 
+ifeq ($(OS_TARGET),Linux)
+DIRS = linux
+endif
+ifeq ($(OS_TARGET),SunOS)
+DIRS = solaris
+endif
+
+publish::
+	+$(LOOP_OVER_DIRS)
+
+include $(topsrcdir)/config/rules.mk
diff --git a/pkg/linux/Makefile.in b/pkg/linux/Makefile.in
new file mode 100644
index 0000000..63fa750
--- /dev/null
+++ b/pkg/linux/Makefile.in
@@ -0,0 +1,80 @@
+# 
+# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#ident	"$Id$"
+#
+
+MOD_DEPTH = ../..
+topsrcdir   = @top_srcdir@
+srcdir	    = @srcdir@
+VPATH	    = @srcdir@
+
+NAME        = sun-nspr
+ifndef RPM_RELEASE
+RPM_RELEASE = 1
+endif
+TOPDIR      = /usr/src/redhat
+VERSION     = `grep PR_VERSION $(dist_includedir)/prinit.h \
+                  | sed -e 's/"$$//' -e 's/.*"//' -e 's/ .*//'`
+
+SPECFILE    = $(NAME).spec
+
+include $(MOD_DEPTH)/config/autoconf.mk
+
+# Force i386 for non 64 bit build
+ifneq ($(USE_64),1)
+	RPMTARGET = "--target=i386"
+	RPMLIBDIR = lib
+else
+	RPMLIBDIR = lib64
+endif
+
+publish:
+	$(MAKE) clean
+	mkdir -p SOURCES SRPMS RPMS BUILD
+	(cd $(dist_libdir) && tar cphf - libnspr4.so libplds4.so libplc4.so) \
+	| (mkdir -p opt/sun/private/$(RPMLIBDIR) && cd opt/sun/private/$(RPMLIBDIR) && tar xvfBp -)
+	(cd $(dist_includedir) && tar cphf - .) \
+	| (mkdir -p opt/sun/private/include/nspr && cd opt/sun/private/include/nspr && tar xvfBp -)
+	(cd opt/sun/private/include/nspr && \
+		rm -rf md)
+	tar czvf SOURCES/$(NAME)-$(VERSION).tar.gz opt
+	echo "%define name $(NAME)" >$(SPECFILE)
+	echo "%define version $(VERSION)" >>$(SPECFILE)
+	echo "%define release $(RPM_RELEASE)" >>$(SPECFILE)
+	echo "%define buildroot `pwd`/$(NAME)-root" >>$(SPECFILE)
+	echo "%define _topdir `pwd`" >>$(SPECFILE)
+	echo "%define _unpackaged_files_terminate_build 0" >>$(SPECFILE)
+	cat $(srcdir)/$(NAME).spec >>$(SPECFILE)
+	echo "" >>$(SPECFILE)
+	echo "%files" >>$(SPECFILE)
+	echo "%defattr(-,root,root)" >>$(SPECFILE)
+	echo "%dir /opt" >>$(SPECFILE)
+	echo "%dir /opt/sun" >>$(SPECFILE)
+	echo "%dir /opt/sun/private" >>$(SPECFILE)
+	echo "%dir /opt/sun/private/$(RPMLIBDIR)" >>$(SPECFILE)
+	find opt \( -name "*.so" \) | sed -e "s-^-/-" >>$(SPECFILE)
+	echo "" >>$(SPECFILE)
+	echo "%files devel" >>$(SPECFILE)
+	echo "%defattr(-,root,root)" >>$(SPECFILE)
+	echo "%dir /opt" >>$(SPECFILE)
+	echo "%dir /opt/sun" >>$(SPECFILE)
+	echo "%dir /opt/sun/private" >>$(SPECFILE)
+	echo "%dir /opt/sun/private/include" >>$(SPECFILE)
+	echo "%dir /opt/sun/private/include/nspr" >>$(SPECFILE)
+	echo "%dir /opt/sun/private/include/nspr/obsolete" >>$(SPECFILE)
+	echo "%dir /opt/sun/private/include/nspr/private" >>$(SPECFILE)
+	find opt -type f \( -name "*.h" \) \
+		| sed -e "s-^-/-" >>$(SPECFILE)
+	rpmbuild $(RPMTARGET) -bb $(SPECFILE)
+
+clean:
+	rm -rf $(TOPDIR)/BUILD/$(NAME)
+	rm -rf SOURCES SRPMS RPMS BUILD
+	rm -rf RPMS SRPMS opt
+	rm -f $(NAME)-$(VERSION).tar.gz
diff --git a/pkg/linux/sun-nspr.spec b/pkg/linux/sun-nspr.spec
new file mode 100644
index 0000000..fccac5a
--- /dev/null
+++ b/pkg/linux/sun-nspr.spec
@@ -0,0 +1,49 @@
+Summary: Netscape Portable Runtime
+Name: %{name}
+Vendor: Sun Microsystems, Inc.
+Version: %{version}
+Release: %{release}
+Copyright: Copyright 2005 Sun Microsystems, Inc.  All rights reserved.  Use is subject to license terms.  Also under other license(s) as shown at the Description field.
+Distribution: Sun Java(TM) Enterprise System
+URL: http://www.sun.com
+Group: System Environment/Base
+Source: %{name}-%{version}.tar.gz
+ExclusiveOS: Linux
+BuildRoot: /var/tmp/%{name}-root
+        
+%description
+
+NSPR provides platform independence for non-GUI operating system
+facilities. These facilities include threads, thread synchronization,
+normal file and network I/O, interval timing and calendar time, basic
+memory management (malloc and free) and shared library linking. 
+
+See: http://www.mozilla.org/projects/nspr/about-nspr.html
+
+This Source Code Form is subject to the terms of the Mozilla Public
+License, v. 2.0. If a copy of the MPL was not distributed with this
+file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+%package devel
+Summary: Development Libraries for the Netscape Portable Runtime
+Group: Development/Libraries
+Requires: %{name} = %{version}-%{release}
+
+%description devel
+Header files for doing development with the Netscape Portable Runtime.
+
+Under "MPL/GPL" license.
+
+%prep
+%setup -c
+
+%build
+
+%install
+rm -rf $RPM_BUILD_ROOT
+mkdir $RPM_BUILD_ROOT
+cd $RPM_BUILD_ROOT
+tar xvzf $RPM_SOURCE_DIR/%{name}-%{version}.tar.gz
+
+%clean
+rm -rf $RPM_BUILD_ROOT
diff --git a/pkg/solaris/Makefile-devl.com b/pkg/solaris/Makefile-devl.com
new file mode 100755
index 0000000..86eab39
--- /dev/null
+++ b/pkg/solaris/Makefile-devl.com
@@ -0,0 +1,34 @@
+# 
+# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#ident	"$Id$"
+#
+
+MACH = $(shell mach)
+
+PUBLISH_ROOT = $(DIST)
+ifeq ($(MOD_DEPTH),../..)
+ROOT = ROOT
+else
+ROOT = $(subst ../../,,$(MOD_DEPTH))/ROOT
+endif
+
+PKGARCHIVE = $(dist_prefix)/pkgarchive
+DATAFILES = copyright
+FILES = $(DATAFILES) pkginfo
+
+PACKAGE = $(shell basename `pwd`)
+
+PRODUCT_VERSION = "$(MOD_VERSION).$(MOD_MINOR).$(MOD_PATCH)$(MOD_BETA)"
+LN = /usr/bin/ln
+
+CLOBBERFILES = $(FILES)
+
+include $(topsrcdir)/config/rules.mk
+
+# vim: ft=make
diff --git a/pkg/solaris/Makefile-devl.targ b/pkg/solaris/Makefile-devl.targ
new file mode 100755
index 0000000..210b501
--- /dev/null
+++ b/pkg/solaris/Makefile-devl.targ
@@ -0,0 +1,34 @@
+# 
+# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#ident	"$Id$"
+#
+
+include $(srcdir)/../proto64.mk
+
+pkginfo: pkginfo.tmpl ../awk_pkginfo
+	$(RM) $@; nawk -f ../awk_pkginfo $(srcdir)/$@.tmpl > $@
+
+pkg: $(PKGARCHIVE)
+	cat $(srcdir)/prototype | sed $(sed_proto64) > prototype
+	cp $(srcdir)/depend .
+	pkgmk -f prototype -d $(PKGARCHIVE) -r $(ROOT) -o $(PACKAGE)
+
+$(PKGARCHIVE):
+	[ -d $(PKGARCHIVE) ] || mkdir -p $(PKGARCHIVE)
+
+$(DATAFILES): %: $(srcdir)/../common_files/%
+	$(RM) $@; cp $(srcdir)/../common_files/$@ $@
+
+$(MACHDATAFILES): %: $(srcdir)/../common_files/%_$(MACH)
+	$(RM) $@; cp $(srcdir)/../common_files/$@_$(MACH) $@
+
+clobber clean::
+	-$(RM) $(CLOBBERFILES) $(CLEANFILES)
+
+.PHONY: pkg
diff --git a/pkg/solaris/Makefile.com b/pkg/solaris/Makefile.com
new file mode 100644
index 0000000..d4da887
--- /dev/null
+++ b/pkg/solaris/Makefile.com
@@ -0,0 +1,37 @@
+# 
+# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#ident	"$Id$"
+#
+
+MACH = $(shell mach)
+
+PUBLISH_ROOT = $(DIST)
+ifeq ($(MOD_DEPTH),../..)
+ROOT = ROOT
+else
+ROOT = $(subst ../../,,$(MOD_DEPTH))/ROOT
+endif
+
+PKGARCHIVE = $(dist_prefix)/pkgarchive
+DATAFILES = copyright
+FILES = $(DATAFILES) pkginfo
+
+PACKAGE = $(shell basename `pwd`)
+
+PRODUCT_VERSION = $(shell grep PR_VERSION $(dist_includedir)/prinit.h \
+		   | sed -e 's/"$$//' -e 's/.*"//' -e 's/ .*//')
+
+LN = /usr/bin/ln
+CP = /usr/bin/cp
+
+CLOBBERFILES = $(FILES)
+
+include $(topsrcdir)/config/rules.mk
+
+# vim: ft=make
diff --git a/pkg/solaris/Makefile.in b/pkg/solaris/Makefile.in
new file mode 100644
index 0000000..b34a23a
--- /dev/null
+++ b/pkg/solaris/Makefile.in
@@ -0,0 +1,89 @@
+# 
+# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#ident	"$Id$"
+#
+
+MOD_DEPTH = ../..
+topsrcdir   = @top_srcdir@
+srcdir	    = @srcdir@
+VPATH	    = @srcdir@
+
+include $(MOD_DEPTH)/config/autoconf.mk
+
+abs_dist_libdir := $(shell (cd $(dist_libdir);pwd))
+abs_dist_includedir := $(shell (cd $(dist_includedir);pwd))
+
+%: %.ksh
+	$(RM) $@
+	cp $< $@
+	chmod +x $@
+
+DIRS = \
+	SUNWpr \
+	SUNWprd
+
+include $(srcdir)/Makefile.com
+
+PROTO = \
+	$(ROOT) \
+	$(ROOT)/usr/lib/mps \
+	$(ROOT)/usr/include/mps
+
+ifeq ($(MACH), sparc)
+	PROTO += $(ROOT)/usr/lib/mps/cpu/sparcv8plus
+endif
+
+ifeq ($(USE_64), 1)
+ifeq ($(MACH), sparc)
+# Sparc
+	PROTO += $(ROOT)/usr/lib/mps/sparcv9
+else
+# AMD64
+	PROTO += $(ROOT)/usr/lib/mps/amd64
+endif
+	abs_dist64_libdir = $(abs_dist_libdir)
+	abs_dist32_libdir = $(shell echo $(abs_dist_libdir) | sed -e "s|_64_OPT|_OPT|g" -e "s|_64_DBG|_DBG|g")
+	abs_dist64_includedir = $(abs_dist_includedir)
+	abs_dist32_includedir = $(shell echo $(abs_dist_includedir) | sed -e "s|_64_OPT|_OPT|g" -e "s|_64_DBG|_DBG|g")
+else
+	abs_dist32_libdir = $(abs_dist_libdir)
+	abs_dist64_libdir = $(shell echo $(abs_dist_libdir) | sed -e "s|_OPT|_64_OPT|g" -e "s|_DBG|_64_DBG|g")
+	abs_dist32_includedir = $(abs_dist_includedir)
+	abs_dist64_includedir = $(shell echo $(abs_dist_includedir) | sed -e "s|_OPT|_64_OPT|g" -e "s|_DBG|_64_DBG|g")
+endif
+
+awk_pkginfo: bld_awk_pkginfo
+	./bld_awk_pkginfo -m $(MACH) -p "$(PRODUCT_VERSION)" -o $@ -v $(PRODUCT_VERSION)
+
+all:: awk_pkginfo $(PROTO)
+publish: awk_pkginfo $(PROTO)
+	+$(LOOP_OVER_DIRS)
+
+clean clobber::
+	$(RM) awk_pkginfo bld_awk_pkginfo
+	$(RM) -r $(ROOT)
+
+$(ROOT):
+	mkdir -p $@
+
+$(ROOT)/usr/lib/mps/sparcv9:
+	mkdir -p $@
+	$(CP) -r $(abs_dist64_libdir)/*.so $@
+$(ROOT)/usr/lib/mps/amd64:
+	mkdir -p $@
+	$(CP) -r $(abs_dist64_libdir)/*.so $@
+$(ROOT)/usr/lib/mps:
+	mkdir -p $@
+	$(CP) -r $(abs_dist32_libdir)/*.so $@
+$(ROOT)/usr/lib/mps/cpu/sparcv8plus:
+	mkdir -p $@
+	$(CP) -r $(abs_dist32_libdir)/cpu/sparcv8plus/*.so $@
+$(ROOT)/usr/include/mps:
+	mkdir -p $@
+	$(CP) -r $(abs_dist32_includedir)/* $@
diff --git a/pkg/solaris/Makefile.targ b/pkg/solaris/Makefile.targ
new file mode 100644
index 0000000..742ee93
--- /dev/null
+++ b/pkg/solaris/Makefile.targ
@@ -0,0 +1,32 @@
+# 
+# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#ident	"$Id$"
+#
+
+include $(srcdir)/../proto64.mk
+
+pkginfo: pkginfo.tmpl ../awk_pkginfo
+	$(RM) $@; nawk -f ../awk_pkginfo $< > $@
+
+pkg: $(PKGARCHIVE) prototype_$(MACH)
+	cp $(srcdir)/prototype_com .
+	cat $(srcdir)/prototype_$(MACH) | sed $(sed_proto64) > prototype_$(MACH)
+	cp $(srcdir)/depend .
+	pkgmk -f prototype_$(MACH) -d $(PKGARCHIVE) -r $(ROOT) -o $(PACKAGE)
+
+$(PKGARCHIVE):
+	[ -d $(PKGARCHIVE) ] || mkdir -p $(PKGARCHIVE)
+
+$(DATAFILES): %: $(srcdir)/../common_files/%
+	$(RM) $@; cp $(srcdir)/../common_files/$@ $@
+
+clobber clean::
+	-$(RM) $(CLOBBERFILES) $(CLEANFILES)
+
+.PHONY: pkg
diff --git a/pkg/solaris/SUNWpr/Makefile.in b/pkg/solaris/SUNWpr/Makefile.in
new file mode 100644
index 0000000..9fe1f0a
--- /dev/null
+++ b/pkg/solaris/SUNWpr/Makefile.in
@@ -0,0 +1,26 @@
+# 
+# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#ident	"$Id$"
+#
+
+MOD_DEPTH = ../../..
+topsrcdir   = @top_srcdir@
+srcdir	    = @srcdir@
+VPATH	    = @srcdir@
+
+include $(MOD_DEPTH)/config/autoconf.mk
+
+include $(srcdir)/../Makefile.com
+
+DATAFILES += 
+
+all:: $(FILES)
+publish:: all pkg
+
+include $(srcdir)/../Makefile.targ
diff --git a/pkg/solaris/SUNWpr/depend b/pkg/solaris/SUNWpr/depend
new file mode 100644
index 0000000..4dd09c5
--- /dev/null
+++ b/pkg/solaris/SUNWpr/depend
@@ -0,0 +1,32 @@
+# 
+# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#	$Id$
+#
+# This package information file defines software dependencies associated
+# with the pkg.  You can define three types of pkg dependencies with this file:
+#	 P indicates a prerequisite for installation
+#	 I indicates an incompatible package
+#	 R indicates a reverse dependency
+# <pkg.abbr> see pkginfo(4), PKG parameter
+# <name> see pkginfo(4), NAME parameter
+# <version> see pkginfo(4), VERSION parameter
+# <arch> see pkginfo(4), ARCH parameter
+# <type> <pkg.abbr> <name>
+# 	(<arch>)<version>
+# 	(<arch>)<version>
+# 	...
+# <type> <pkg.abbr> <name>
+# ...
+
+P SUNWcar	Core Architecture, (Root)
+P SUNWkvm	Core Architecture, (Kvm)
+P SUNWcsr	Core Solaris, (Root)
+P SUNWcsu	Core Solaris, (Usr)
+P SUNWcsd	Core Solaris Devices
+P SUNWcsl	Core Solaris Libraries
diff --git a/pkg/solaris/SUNWpr/pkginfo.tmpl b/pkg/solaris/SUNWpr/pkginfo.tmpl
new file mode 100644
index 0000000..3c1a107
--- /dev/null
+++ b/pkg/solaris/SUNWpr/pkginfo.tmpl
@@ -0,0 +1,38 @@
+# 
+# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#ident	"$Id$"
+#
+#
+# This required package information file describes characteristics of the
+# package, such as package abbreviation, full package name, package version,
+# and package architecture.
+#
+PKG="SUNWpr"
+NAME="Netscape Portable Runtime"
+ARCH="ISA"
+VERSION="NSPRVERS,REV=0.0.0"
+SUNW_PRODNAME="Netscape Portable Runtime"
+SUNW_PRODVERS="NSPRVERS"
+SUNW_PKGTYPE="usr"
+MAXINST="1000"
+CATEGORY="system"
+DESC="Netscape Portable Runtime Interface"
+VENDOR="Sun Microsystems, Inc."
+HOTLINE="Please contact your local service provider"
+EMAIL=""
+CLASSES="none"
+BASEDIR=/
+SUNW_PKGVERS="1.0"
+#VSTOCK="<reserved by Release Engineering for package part #>"
+#ISTATES="<developer defined>"
+#RSTATES='<developer defined>'
+#ULIMIT="<developer defined>"
+#ORDER="<developer defined>"
+#PSTAMP="<developer defined>"
+#INTONLY="<developer defined>"
diff --git a/pkg/solaris/SUNWpr/prototype_com b/pkg/solaris/SUNWpr/prototype_com
new file mode 100644
index 0000000..4b994ea
--- /dev/null
+++ b/pkg/solaris/SUNWpr/prototype_com
@@ -0,0 +1,39 @@
+# 
+# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#ident	"$Id$"
+#
+# This required package information file contains a list of package contents.
+# The 'pkgmk' command uses this file to identify the contents of a package
+# and their location on the development machine when building the package.
+# Can be created via a text editor or through use of the 'pkgproto' command.
+
+#!search <pathname pathname ...>	# where to find pkg objects
+#!include <filename>			# include another 'prototype' file
+#!default <mode> <owner> <group>	# default used if not specified on entry
+#!<param>=<value>			# puts parameter in pkg environment
+
+# packaging files
+i copyright
+i pkginfo
+i depend
+#
+# source locations relative to the prototype file
+#
+# SUNWpr
+#
+d none usr 755 root sys
+d none usr/lib 755 root bin
+d none usr/lib/mps 755 root bin
+d none usr/lib/mps/secv1 755 root bin
+f none usr/lib/mps/libnspr4.so 755 root bin
+f none usr/lib/mps/libplc4.so 755 root bin
+f none usr/lib/mps/libplds4.so 755 root bin
+s none usr/lib/mps/secv1/libnspr4.so=../libnspr4.so
+s none usr/lib/mps/secv1/libplc4.so=../libplc4.so
+s none usr/lib/mps/secv1/libplds4.so=../libplds4.so
diff --git a/pkg/solaris/SUNWpr/prototype_i386 b/pkg/solaris/SUNWpr/prototype_i386
new file mode 100644
index 0000000..e2f7a2f
--- /dev/null
+++ b/pkg/solaris/SUNWpr/prototype_i386
@@ -0,0 +1,45 @@
+# 
+# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#ident	"$Id$"
+#
+# This required package information file contains a list of package contents.
+# The 'pkgmk' command uses this file to identify the contents of a package
+# and their location on the development machine when building the package.
+# Can be created via a text editor or through use of the 'pkgproto' command.
+
+#!search <pathname pathname ...>	# where to find pkg objects
+#!include <filename>			# include another 'prototype' file
+#!default <mode> <owner> <group>	# default used if not specified on entry
+#!<param>=<value>			# puts parameter in pkg environment
+
+#
+# Include ISA independent files (prototype_com)
+#
+!include prototype_com
+#
+#
+#
+# List files which are i386 specific here
+#
+# source locations relative to the prototype file
+#
+#
+# SUNWpr
+#
+#64#s none usr/lib/mps/64=amd64
+#64#s none usr/lib/mps/secv1/64=amd64
+#64#d none usr/lib/mps/amd64 755 root bin
+#64#d none usr/lib/mps/secv1/amd64 755 root bin
+#64#f none usr/lib/mps/amd64/libnspr4.so 755 root bin
+#64#f none usr/lib/mps/amd64/libplc4.so 755 root bin
+#64#f none usr/lib/mps/amd64/libplds4.so 755 root bin
+#64#s none usr/lib/mps/secv1/amd64/libnspr4.so=../../amd64/libnspr4.so
+#64#s none usr/lib/mps/secv1/amd64/libplc4.so=../../amd64/libplc4.so
+#64#s none usr/lib/mps/secv1/amd64/libplds4.so=../../amd64/libplds4.so
+
diff --git a/pkg/solaris/SUNWpr/prototype_sparc b/pkg/solaris/SUNWpr/prototype_sparc
new file mode 100644
index 0000000..aae5f18
--- /dev/null
+++ b/pkg/solaris/SUNWpr/prototype_sparc
@@ -0,0 +1,51 @@
+# 
+# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#ident	"$Id$"
+#
+# This required package information file contains a list of package contents.
+# The 'pkgmk' command uses this file to identify the contents of a package
+# and their location on the development machine when building the package.
+# Can be created via a text editor or through use of the 'pkgproto' command.
+
+#!search <pathname pathname ...>	# where to find pkg objects
+#!include <filename>			# include another 'prototype' file
+#!default <mode> <owner> <group>	# default used if not specified on entry
+#!<param>=<value>			# puts parameter in pkg environment
+
+#
+# Include ISA independent files (prototype_com)
+#
+!include prototype_com
+#
+#
+#
+# List files which are SPARC specific here
+#
+# source locations relative to the prototype file
+#
+#
+# SUNWpr
+#
+d none usr/lib/mps/cpu 755 root bin
+d none usr/lib/mps/cpu/sparcv8plus 755 root bin
+d none usr/lib/mps/secv1/cpu 755 root bin
+d none usr/lib/mps/secv1/cpu/sparcv8plus 755 root bin
+f none usr/lib/mps/cpu/sparcv8plus/libnspr_flt4.so 755 root bin
+s none usr/lib/mps/secv1/cpu/sparcv8plus/libnspr_flt4.so=../../../cpu/sparcv8plus/libnspr_flt4.so
+#64#s none usr/lib/mps/64=sparcv9
+#64#s none usr/lib/mps/secv1/64=sparcv9
+#64#d none usr/lib/mps/sparcv9 755 root bin
+#64#d none usr/lib/mps/secv1/sparcv9 755 root bin
+#64#f none usr/lib/mps/sparcv9/libnspr4.so 755 root bin
+#64#f none usr/lib/mps/sparcv9/libplc4.so 755 root bin
+#64#f none usr/lib/mps/sparcv9/libplds4.so 755 root bin
+#64#s none usr/lib/mps/secv1/sparcv9/libnspr4.so=../../sparcv9/libnspr4.so
+#64#s none usr/lib/mps/secv1/sparcv9/libplc4.so=../../sparcv9/libplc4.so
+#64#s none usr/lib/mps/secv1/sparcv9/libplds4.so=../../sparcv9/libplds4.so
+
diff --git a/pkg/solaris/SUNWprd/Makefile.in b/pkg/solaris/SUNWprd/Makefile.in
new file mode 100755
index 0000000..0cb4c28
--- /dev/null
+++ b/pkg/solaris/SUNWprd/Makefile.in
@@ -0,0 +1,26 @@
+# 
+# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#ident	"$Id$"
+#
+
+MOD_DEPTH = ../../..
+topsrcdir   = @top_srcdir@
+srcdir      = @srcdir@
+VPATH       = @srcdir@
+
+include $(MOD_DEPTH)/config/autoconf.mk
+
+include $(srcdir)/../Makefile-devl.com
+
+DATAFILES += 
+
+all:: $(FILES)
+publish:: all pkg
+
+include $(srcdir)/../Makefile-devl.targ
diff --git a/pkg/solaris/SUNWprd/depend b/pkg/solaris/SUNWprd/depend
new file mode 100755
index 0000000..2415c54
--- /dev/null
+++ b/pkg/solaris/SUNWprd/depend
@@ -0,0 +1,27 @@
+# 
+# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#	$Id$
+#
+# This package information file defines software dependencies associated
+# with the pkg.  You can define three types of pkg dependencies with this file:
+#	 P indicates a prerequisite for installation
+#	 I indicates an incompatible package
+#	 R indicates a reverse dependency
+# <pkg.abbr> see pkginfo(4), PKG parameter
+# <name> see pkginfo(4), NAME parameter
+# <version> see pkginfo(4), VERSION parameter
+# <arch> see pkginfo(4), ARCH parameter
+# <type> <pkg.abbr> <name>
+# 	(<arch>)<version>
+# 	(<arch>)<version>
+# 	...
+# <type> <pkg.abbr> <name>
+# ...
+
+P SUNWpr	Netscape Portable Runtime
diff --git a/pkg/solaris/SUNWprd/pkginfo.tmpl b/pkg/solaris/SUNWprd/pkginfo.tmpl
new file mode 100755
index 0000000..5003122
--- /dev/null
+++ b/pkg/solaris/SUNWprd/pkginfo.tmpl
@@ -0,0 +1,38 @@
+# 
+# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#ident	"$Id$"
+#
+#
+# This required package information file describes characteristics of the
+# package, such as package abbreviation, full package name, package version,
+# and package architecture.
+#
+PKG="SUNWprd"
+NAME="Netscape Portable Runtime Development"
+ARCH="ISA"
+VERSION="NSPRVERS,REV=0.0.0"
+SUNW_PRODNAME="Netscape Portable Runtime Development"
+SUNW_PRODVERS="NSPRVERS"
+SUNW_PKGTYPE="usr"
+MAXINST="1000"
+CATEGORY="system"
+DESC="Netscape Portable Runtime Interface Files for Development"
+VENDOR="Sun Microsystems, Inc."
+HOTLINE="Please contact your local service provider"
+EMAIL=""
+CLASSES="none"
+BASEDIR=/
+SUNW_PKGVERS="1.0"
+#VSTOCK="<reserved by Release Engineering for package part #>"
+#ISTATES="<developer defined>"
+#RSTATES='<developer defined>'
+#ULIMIT="<developer defined>"
+#ORDER="<developer defined>"
+#PSTAMP="<developer defined>"
+#INTONLY="<developer defined>"
diff --git a/pkg/solaris/SUNWprd/prototype b/pkg/solaris/SUNWprd/prototype
new file mode 100755
index 0000000..44f52ba
--- /dev/null
+++ b/pkg/solaris/SUNWprd/prototype
@@ -0,0 +1,89 @@
+# 
+# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#ident  "$Id$"
+#
+# This required package information file contains a list of package contents.
+# The 'pkgmk' command uses this file to identify the contents of a package
+# and their location on the development machine when building the package.
+# Can be created via a text editor or through use of the 'pkgproto' command.
+
+#!search <pathname pathname ...>        # where to find pkg objects
+#!include <filename>                    # include another 'prototype' file
+#!default <mode> <owner> <group>        # default used if not specified on entry
+#!<param>=<value>                       # puts parameter in pkg environment
+
+# packaging files
+i copyright
+i pkginfo
+i depend
+#
+# source locations relative to .h 0644 root bine prototype file
+#
+# SUNWprd
+#
+d none usr 0755 root sys
+d none usr/include 0755 root bin
+d none usr/include/mps 0755 root bin
+d none usr/include/mps/obsolete 0755 root bin
+d none usr/include/mps/private 0755 root bin
+f none usr/include/mps/obsolete/pralarm.h 0644 root bin
+f none usr/include/mps/obsolete/probslet.h 0644 root bin
+f none usr/include/mps/obsolete/protypes.h 0644 root bin
+f none usr/include/mps/obsolete/prsem.h 0644 root bin
+f none usr/include/mps/prcpucfg.h 0644 root bin
+f none usr/include/mps/nspr.h 0644 root bin
+f none usr/include/mps/pratom.h 0644 root bin
+f none usr/include/mps/prbit.h 0644 root bin
+f none usr/include/mps/prclist.h 0644 root bin
+f none usr/include/mps/prcmon.h 0644 root bin
+f none usr/include/mps/prcountr.h 0644 root bin
+f none usr/include/mps/prcvar.h 0644 root bin
+f none usr/include/mps/prdtoa.h 0644 root bin
+f none usr/include/mps/prenv.h 0644 root bin
+f none usr/include/mps/prerr.h 0644 root bin
+f none usr/include/mps/prerror.h 0644 root bin
+f none usr/include/mps/prinet.h 0644 root bin
+f none usr/include/mps/prinit.h 0644 root bin
+f none usr/include/mps/prinrval.h 0644 root bin
+f none usr/include/mps/prio.h 0644 root bin
+f none usr/include/mps/pripcsem.h 0644 root bin
+f none usr/include/mps/private/pprio.h 0644 root bin
+f none usr/include/mps/private/pprthred.h 0644 root bin
+f none usr/include/mps/private/prpriv.h 0644 root bin
+f none usr/include/mps/prlink.h 0644 root bin
+f none usr/include/mps/prlock.h 0644 root bin
+f none usr/include/mps/prlog.h 0644 root bin
+f none usr/include/mps/prlong.h 0644 root bin
+f none usr/include/mps/prmem.h 0644 root bin
+f none usr/include/mps/prmon.h 0644 root bin
+f none usr/include/mps/prmwait.h 0644 root bin
+f none usr/include/mps/prnetdb.h 0644 root bin
+f none usr/include/mps/prolock.h 0644 root bin
+f none usr/include/mps/prpdce.h 0644 root bin
+f none usr/include/mps/prprf.h 0644 root bin
+f none usr/include/mps/prproces.h 0644 root bin
+f none usr/include/mps/prrng.h 0644 root bin
+f none usr/include/mps/prrwlock.h 0644 root bin
+f none usr/include/mps/prshm.h 0644 root bin
+f none usr/include/mps/prshma.h 0644 root bin
+f none usr/include/mps/prsystem.h 0644 root bin
+f none usr/include/mps/prthread.h 0644 root bin
+f none usr/include/mps/prtime.h 0644 root bin
+f none usr/include/mps/prtpool.h 0644 root bin
+f none usr/include/mps/prtrace.h 0644 root bin
+f none usr/include/mps/prtypes.h 0644 root bin
+f none usr/include/mps/prvrsion.h 0644 root bin
+f none usr/include/mps/prwin16.h 0644 root bin
+f none usr/include/mps/plarenas.h 0644 root bin
+f none usr/include/mps/plarena.h 0644 root bin
+f none usr/include/mps/plbase64.h 0644 root bin
+f none usr/include/mps/plerror.h 0644 root bin
+f none usr/include/mps/plgetopt.h 0644 root bin
+f none usr/include/mps/plhash.h 0644 root bin
+f none usr/include/mps/plstr.h 0644 root bin
diff --git a/pkg/solaris/bld_awk_pkginfo.ksh b/pkg/solaris/bld_awk_pkginfo.ksh
new file mode 100644
index 0000000..67f1df7
--- /dev/null
+++ b/pkg/solaris/bld_awk_pkginfo.ksh
@@ -0,0 +1,109 @@
+#!/usr/bin/ksh -p
+# 
+# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#ident	"$Id$"
+#
+# Simple script which builds the awk_pkginfo awk script.  This awk script
+# is used to convert the pkginfo.tmpl files into pkginfo files
+# for the build.
+#
+
+usage()
+{
+   cat <<-EOF
+usage: bld_awk_pkginfo -p <prodver> -m <mach> -o <awk_script> [-v <version>]
+EOF
+}
+
+#
+# Awk strings
+#
+# two VERSION patterns: one for Dewey decimal, one for Dewey plus ,REV=n
+# the first has one '=' the second has two or more '='
+#
+VERSION1="VERSION=[^=]*$"
+VERSION2="VERSION=[^=]*=.*$"
+PRODVERS="^SUNW_PRODVERS="
+ARCH='ARCH=\"ISA\"'
+
+#
+# parse command line
+#
+mach=""
+prodver=""
+awk_script=""
+version="NSPRVERS"
+
+while getopts o:p:m:v: c
+do
+   case $c in
+   o)
+      awk_script=$OPTARG
+      ;;
+   m)
+      mach=$OPTARG
+      ;;
+   p)
+      prodver=$OPTARG
+      ;;
+   v)
+      version=$OPTARG
+      ;;
+   \?)
+      usage
+      exit 1
+      ;;
+   esac
+done
+
+if [[ ( -z $prodver ) || ( -z $mach ) || ( -z $awk_script ) ]]
+then
+   usage
+   exit 1
+fi
+
+if [[ -f $awk_script ]]
+then
+	rm -f $awk_script
+fi
+
+#
+# Build REV= field based on date
+#
+rev=$(date "+%Y.%m.%d.%H.%M")
+
+#
+# Build awk script which will process all the
+# pkginfo.tmpl files.
+#
+# the first VERSION pattern is replaced with a leading quotation mark
+#
+rm -f $awk_script
+cat << EOF > $awk_script
+/$VERSION1/ {
+      sub(/\=[^=]*$/,"=\"$rev\"")
+      print
+      next
+   }
+/$VERSION2/ {
+      sub(/\=[^=]*$/,"=$rev\"")
+      sub(/NSPRVERS/,"$version")
+      print
+      next
+   }
+/$PRODVERS/ { 
+      printf "SUNW_PRODVERS=\"%s\"\n", "$prodver" 
+      next
+   }
+/$ARCH/ {
+      printf "ARCH=\"%s\"\n", "$mach"
+      next
+   }
+{ print }
+EOF
diff --git a/pkg/solaris/common_files/copyright b/pkg/solaris/common_files/copyright
new file mode 100644
index 0000000..c553490
--- /dev/null
+++ b/pkg/solaris/common_files/copyright
@@ -0,0 +1,6 @@
+Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+Use is subject to license terms.
+
+This Source Code Form is subject to the terms of the Mozilla Public
+License, v. 2.0. If a copy of the MPL was not distributed with this
+file, You can obtain one at http://mozilla.org/MPL/2.0/.
diff --git a/pkg/solaris/proto64.mk b/pkg/solaris/proto64.mk
new file mode 100644
index 0000000..69bb1fc
--- /dev/null
+++ b/pkg/solaris/proto64.mk
@@ -0,0 +1,18 @@
+# 
+# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#ident  "$Id$"
+#
+
+ifeq ($(USE_64), 1)
+  # Remove 64 tag
+  sed_proto64='s/\#64\#//g'
+else
+  # Strip 64 lines
+  sed_proto64='/\#64\#/d'
+endif
diff --git a/pr/.cvsignore b/pr/.cvsignore
new file mode 100644
index 0000000..f3c7a7c
--- /dev/null
+++ b/pr/.cvsignore
@@ -0,0 +1 @@
+Makefile
diff --git a/pr/Makefile.in b/pr/Makefile.in
new file mode 100644
index 0000000..f7af402
--- /dev/null
+++ b/pr/Makefile.in
@@ -0,0 +1,17 @@
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#! gmake
+
+MOD_DEPTH	= ..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+
+include $(MOD_DEPTH)/config/autoconf.mk
+
+DIRS = include src
+
+include $(topsrcdir)/config/rules.mk
diff --git a/pr/include/.cvsignore b/pr/include/.cvsignore
new file mode 100644
index 0000000..f3c7a7c
--- /dev/null
+++ b/pr/include/.cvsignore
@@ -0,0 +1 @@
+Makefile
diff --git a/pr/include/Makefile.in b/pr/include/Makefile.in
new file mode 100644
index 0000000..9cc425a
--- /dev/null
+++ b/pr/include/Makefile.in
@@ -0,0 +1,27 @@
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#! gmake
+
+MOD_DEPTH	= ../..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+
+include $(MOD_DEPTH)/config/autoconf.mk
+
+DIRS = md private obsolete
+
+include $(topsrcdir)/config/config.mk
+
+HEADERS = $(wildcard $(srcdir)/*.h)
+
+RELEASE_HEADERS = $(HEADERS)
+RELEASE_HEADERS_DEST = $(RELEASE_INCLUDE_DIR)
+
+include $(topsrcdir)/config/rules.mk
+
+export:: $(RELEASE_HEADERS)
+	$(INSTALL) -m 444 $(RELEASE_HEADERS) $(dist_includedir)
diff --git a/pr/include/gencfg.c b/pr/include/gencfg.c
new file mode 100644
index 0000000..54c07ba
--- /dev/null
+++ b/pr/include/gencfg.c
@@ -0,0 +1,265 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <stdio.h>
+
+#if defined(sgi)
+#ifndef IRIX
+	error - IRIX is not defined
+#endif
+#endif
+
+#if defined(__sun)
+#ifndef SOLARIS
+	error - SOLARIS is not defined
+#endif
+#endif
+
+#if defined(__hpux)
+#ifndef HPUX
+	error - HPUX is not defined
+#endif
+#endif
+
+#if defined(__alpha) 
+#if !(defined(_WIN32)) && !(defined(OSF1)) && !(defined(__linux)) && !(defined(__FreeBSD__))
+	error - None of OSF1, _WIN32, __linux, or __FreeBSD__ is defined
+#endif
+#endif
+
+#if defined(_IBMR2)
+#ifndef AIX
+	error - AIX is not defined
+#endif
+#endif
+
+#if defined(linux)
+#ifndef LINUX
+	error - LINUX is not defined
+#endif
+#endif
+
+#if defined(bsdi)
+#ifndef BSDI
+	error - BSDI is not defined
+#endif
+#endif
+
+#if defined(M_UNIX)
+#ifndef SCO
+      error - SCO is not defined
+#endif
+#endif
+#if !defined(M_UNIX) && defined(_USLC_)
+#ifndef UNIXWARE
+      error - UNIXWARE is not defined
+#endif
+#endif
+
+#if defined(__APPLE__)
+#ifndef DARWIN
+      error - DARWIN is not defined
+#endif
+#endif
+
+/************************************************************************/
+
+/* Generate cpucfg.h */
+
+#ifdef XP_PC
+#ifdef WIN32
+#define INT64	_PRInt64
+#else
+#define INT64	long
+#endif
+#else
+#if defined(HPUX) || defined(SCO) || defined(UNIXWARE)
+#define INT64	long
+#else
+#define INT64	long long
+#endif
+#endif
+
+struct align_short {
+    char c;
+    short a;
+};
+struct align_int {
+    char c;
+    int a;
+};
+struct align_long {
+    char c;
+    long a;
+};
+struct align_PRInt64 {
+    char c;
+    INT64 a;
+};
+struct align_fakelonglong {
+    char c;
+    struct {
+	long hi, lo;
+    } a;
+};
+struct align_float {
+    char c;
+    float a;
+};
+struct align_double {
+    char c;
+    double a;
+};
+struct align_pointer {
+    char c;
+    void *a;
+};
+
+#define ALIGN_OF(type) \
+    (((char*)&(((struct align_##type *)0)->a)) - ((char*)0))
+
+int bpb;
+
+/* Used if shell doesn't support redirection. By default, assume it does. */
+FILE *stream;
+
+static int Log2(int n)
+{
+    int log2 = 0;
+
+    if (n & (n-1))
+	log2++;
+    if (n >> 16)
+	log2 += 16, n >>= 16;
+    if (n >> 8)
+	log2 += 8, n >>= 8;
+    if (n >> 4)
+	log2 += 4, n >>= 4;
+    if (n >> 2)
+	log2 += 2, n >>= 2;
+    if (n >> 1)
+	log2++;
+    return log2;
+}
+
+/* We assume that int's are 32 bits */
+static void do64(void)
+{
+    union {
+	int i;
+	char c[4];
+    } u;
+
+    u.i = 0x01020304;
+    if (u.c[0] == 0x01) {
+	fprintf(stream, "#undef  IS_LITTLE_ENDIAN\n");
+	fprintf(stream, "#define IS_BIG_ENDIAN 1\n\n");
+    } else {
+	fprintf(stream, "#define IS_LITTLE_ENDIAN 1\n");
+	fprintf(stream, "#undef  IS_BIG_ENDIAN\n\n");
+    }
+}
+
+static void do32(void)
+{
+    union {
+	long i;
+	char c[4];
+    } u;
+
+    u.i = 0x01020304;
+    if (u.c[0] == 0x01) {
+	fprintf(stream, "#undef  IS_LITTLE_ENDIAN\n");
+	fprintf(stream, "#define IS_BIG_ENDIAN 1\n\n");
+    } else {
+	fprintf(stream, "#define IS_LITTLE_ENDIAN 1\n");
+	fprintf(stream, "#undef  IS_BIG_ENDIAN\n\n");
+    }
+}
+
+/*
+** Concievably this could actually be used; but there is lots of code out
+** there with and's and shift's in it that assumes a byte is 8 bits, so
+** forget about porting THIS code to those non 8 bit byte machines.
+*/
+static void BitsPerByte(void)
+{
+    bpb = 8;
+}
+
+int main(int argc, char **argv)
+{
+    BitsPerByte();
+
+    /* If we got a command line argument, try to use it as the stream. */
+    ++argv;
+    if(*argv) {
+        if(!(stream = fopen ( *argv, "wt" ))) {
+            fprintf(stderr, "Could not write to output file %s.\n", *argv);
+            return 1;
+        }
+    } else {
+		stream = stdout;
+	}
+
+    fprintf(stream, "#ifndef nspr_cpucfg___\n");
+    fprintf(stream, "#define nspr_cpucfg___\n\n");
+
+    fprintf(stream, "/* AUTOMATICALLY GENERATED - DO NOT EDIT */\n\n");
+
+    if (sizeof(long) == 8) {
+	do64();
+    } else {
+	do32();
+    }
+    fprintf(stream, "#define PR_BYTES_PER_BYTE   %d\n", sizeof(char));
+    fprintf(stream, "#define PR_BYTES_PER_SHORT  %d\n", sizeof(short));
+    fprintf(stream, "#define PR_BYTES_PER_INT    %d\n", sizeof(int));
+    fprintf(stream, "#define PR_BYTES_PER_INT64  %d\n", 8);
+    fprintf(stream, "#define PR_BYTES_PER_LONG   %d\n", sizeof(long));
+    fprintf(stream, "#define PR_BYTES_PER_FLOAT  %d\n", sizeof(float));
+    fprintf(stream, "#define PR_BYTES_PER_DOUBLE %d\n\n", sizeof(double));
+
+    fprintf(stream, "#define PR_BITS_PER_BYTE    %d\n", bpb);
+    fprintf(stream, "#define PR_BITS_PER_SHORT   %d\n", bpb * sizeof(short));
+    fprintf(stream, "#define PR_BITS_PER_INT     %d\n", bpb * sizeof(int));
+    fprintf(stream, "#define PR_BITS_PER_INT64   %d\n", bpb * 8);
+    fprintf(stream, "#define PR_BITS_PER_LONG    %d\n", bpb * sizeof(long));
+    fprintf(stream, "#define PR_BITS_PER_FLOAT   %d\n", bpb * sizeof(float));
+    fprintf(stream, "#define PR_BITS_PER_DOUBLE  %d\n\n", 
+            bpb * sizeof(double));
+
+    fprintf(stream, "#define PR_BITS_PER_BYTE_LOG2   %d\n", Log2(bpb));
+    fprintf(stream, "#define PR_BITS_PER_SHORT_LOG2  %d\n", 
+            Log2(bpb * sizeof(short)));
+    fprintf(stream, "#define PR_BITS_PER_INT_LOG2    %d\n", 
+            Log2(bpb * sizeof(int)));
+    fprintf(stream, "#define PR_BITS_PER_INT64_LOG2  %d\n", 6);
+    fprintf(stream, "#define PR_BITS_PER_LONG_LOG2   %d\n", 
+            Log2(bpb * sizeof(long)));
+    fprintf(stream, "#define PR_BITS_PER_FLOAT_LOG2  %d\n", 
+            Log2(bpb * sizeof(float)));
+    fprintf(stream, "#define PR_BITS_PER_DOUBLE_LOG2 %d\n\n", 
+            Log2(bpb * sizeof(double)));
+
+    fprintf(stream, "#define PR_ALIGN_OF_SHORT   %d\n", ALIGN_OF(short));
+    fprintf(stream, "#define PR_ALIGN_OF_INT     %d\n", ALIGN_OF(int));
+    fprintf(stream, "#define PR_ALIGN_OF_LONG    %d\n", ALIGN_OF(long));
+    if (sizeof(INT64) < 8) {
+	/* this machine doesn't actually support PRInt64's */
+	fprintf(stream, "#define PR_ALIGN_OF_INT64   %d\n", 
+                ALIGN_OF(fakelonglong));
+    } else {
+	fprintf(stream, "#define PR_ALIGN_OF_INT64   %d\n", ALIGN_OF(PRInt64));
+    }
+    fprintf(stream, "#define PR_ALIGN_OF_FLOAT   %d\n", ALIGN_OF(float));
+    fprintf(stream, "#define PR_ALIGN_OF_DOUBLE  %d\n", ALIGN_OF(double));
+    fprintf(stream, "#define PR_ALIGN_OF_POINTER %d\n\n", ALIGN_OF(pointer));
+
+    fprintf(stream, "#endif /* nspr_cpucfg___ */\n");
+    fclose(stream);
+
+    return 0;
+}
diff --git a/pr/include/md/.cvsignore b/pr/include/md/.cvsignore
new file mode 100644
index 0000000..f3c7a7c
--- /dev/null
+++ b/pr/include/md/.cvsignore
@@ -0,0 +1 @@
+Makefile
diff --git a/pr/include/md/Makefile.in b/pr/include/md/Makefile.in
new file mode 100644
index 0000000..383c092
--- /dev/null
+++ b/pr/include/md/Makefile.in
@@ -0,0 +1,42 @@
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#! gmake
+
+MOD_DEPTH	= ../../..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+
+include $(MOD_DEPTH)/config/autoconf.mk
+
+# The .cfg files need to be exported and installed to support
+# cross-compilation.
+CONFIGS = $(wildcard $(srcdir)/*.cfg)
+
+include $(topsrcdir)/config/rules.mk
+
+export:: $(MDCPUCFG_H)
+	$(INSTALL) -m 444 $(CONFIGS) $(dist_includedir)/md
+	$(INSTALL) -m 444 $(srcdir)/$(MDCPUCFG_H) $(dist_includedir)
+	mv -f $(dist_includedir)/$(MDCPUCFG_H) $(dist_includedir)/prcpucfg.h
+
+install::
+	$(NSINSTALL) -D $(DESTDIR)$(includedir)/md
+	$(NSINSTALL) -t -m 644 $(CONFIGS) $(DESTDIR)$(includedir)/md
+	$(NSINSTALL) -t -m 644 $(srcdir)/$(MDCPUCFG_H) $(DESTDIR)$(includedir)
+	mv -f $(DESTDIR)$(includedir)/$(MDCPUCFG_H) $(DESTDIR)$(includedir)/prcpucfg.h
+
+release:: export
+	@echo "Copying machine-dependent prcpucfg.h"
+	@if test -z "$(BUILD_NUMBER)"; then \
+		echo "BUILD_NUMBER must be defined"; \
+		false; \
+	fi
+	@if test ! -d $(RELEASE_INCLUDE_DIR); then \
+		rm -rf $(RELEASE_INCLUDE_DIR); \
+		$(NSINSTALL) -D $(RELEASE_INCLUDE_DIR);\
+	fi
+	cp $(srcdir)/$(MDCPUCFG_H) $(RELEASE_INCLUDE_DIR)/prcpucfg.h
diff --git a/pr/include/md/_aix.h b/pr/include/md/_aix.h
new file mode 100644
index 0000000..3daf14f
--- /dev/null
+++ b/pr/include/md/_aix.h
@@ -0,0 +1,225 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_aix_defs_h___
+#define nspr_aix_defs_h___
+
+#include <sys/types.h>
+#if defined(_PR_PTHREADS) || defined(PTHREADS_USER)
+#include <pthread.h>
+#endif
+
+/*
+ * To pick up fd_set and the poll events.
+ */
+#include <sys/select.h>
+#include <sys/poll.h>
+
+/*
+ * Internal configuration macros
+ */
+
+#define PR_LINKER_ARCH          "aix"
+#define _PR_SI_SYSNAME		    "AIX"
+#define _PR_SI_ARCHITECTURE	    "rs6000"
+#define PR_DLL_SUFFIX		    ".so"
+
+#define _PR_VMBASE	 	        0x30000000
+#define _PR_STACK_VMBASE	    0x50000000
+#define _MD_DEFAULT_STACK_SIZE	(2*65536L)
+#define _MD_MINIMUM_STACK_SIZE	(2*65536L)
+#define _MD_MMAP_FLAGS		    MAP_PRIVATE
+
+#define NEED_TIME_R
+#undef  HAVE_STACK_GROWING_UP
+#undef	HAVE_WEAK_IO_SYMBOLS
+#undef	HAVE_WEAK_MALLOC_SYMBOLS
+#define	HAVE_DLL
+#define	USE_DLFCN
+#define _PR_HAVE_SOCKADDR_LEN
+#define _PR_POLL_AVAILABLE
+#define _PR_USE_POLL
+#define _PR_STAT_HAS_ONLY_ST_ATIME
+#ifdef _PR_INET6
+#define _PR_HAVE_INET_NTOP
+#define _PR_HAVE_GETHOSTBYNAME2
+#ifdef _AIX51 /* AIX 4.3.3 does not have AI_NUMERICHOST. */
+#define _PR_HAVE_GETADDRINFO
+#endif
+#endif
+#define _PR_HAVE_SYSV_SEMAPHORES
+#define PR_HAVE_SYSV_NAMED_SHARED_MEMORY
+#define _PR_ACCEPT_INHERIT_NONBLOCK
+
+/* Timer operations */
+#if defined(AIX_TIMERS)
+#define _MD_INTERVAL_INIT()
+
+extern PRIntervalTime _MD_AixGetInterval(void);
+#define _MD_GET_INTERVAL _MD_AixGetInterval
+
+extern PRIntervalTime _MD_AixIntervalPerSec(void);
+#define _MD_INTERVAL_PER_SEC _MD_AixIntervalPerSec
+
+#else  /* defined(AIX_TIMERS) */
+#define _MD_INTERVAL_USE_GTOD
+#endif  /* defined(AIX_TIMERS) */
+
+#ifdef AIX_HAVE_ATOMIC_OP_H
+/* The atomic operations */
+#include <sys/atomic_op.h>
+#define _PR_HAVE_ATOMIC_OPS
+#ifndef IS_64
+#define _PR_HAVE_ATOMIC_CAS
+#endif
+#define _MD_INIT_ATOMIC()
+#define _MD_ATOMIC_INCREMENT(val)   ((PRInt32)fetch_and_add((atomic_p)val, 1) + 1)
+#define _MD_ATOMIC_ADD(ptr, val)   ((PRInt32)fetch_and_add((atomic_p)ptr, val) + val)
+#define _MD_ATOMIC_DECREMENT(val)   ((PRInt32)fetch_and_add((atomic_p)val, -1) - 1)
+#define _MD_ATOMIC_SET(val, newval) _AIX_AtomicSet(val, newval)
+#endif /* AIX_HAVE_ATOMIC_OP_H */
+
+#define USE_SETJMP
+
+#include <setjmp.h>
+
+#define _MD_GET_SP(_t)				(_t)->md.jb[3]
+#define _MD_SET_THR_SP(_t, _sp)		((_t)->md.jb[3] = (int) (_sp - 2 * 64))
+#define PR_NUM_GCREGS				_JBLEN
+
+#define CONTEXT(_th) 				((_th)->md.jb)
+#define SAVE_CONTEXT(_th)			_setjmp(CONTEXT(_th))
+#define GOTO_CONTEXT(_th)			_longjmp(CONTEXT(_th), 1)
+
+#ifdef PTHREADS_USER
+#include "_nspr_pthread.h"
+#else
+
+/*
+** Initialize the thread context preparing it to execute _main.
+*/
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)	      \
+    PR_BEGIN_MACRO				      \
+        *status = PR_TRUE;              \
+	if (setjmp(CONTEXT(_thread))) {	\
+	    (*_main)();			\
+	}				\
+	_MD_GET_SP(_thread) = (int) (_sp - 2 * 64);		\
+    PR_END_MACRO
+
+#define _MD_SWITCH_CONTEXT(_thread)  \
+    if (!setjmp(CONTEXT(_thread))) { \
+	(_thread)->md.errcode = errno;  \
+	_PR_Schedule();		     \
+    }
+
+/*
+** Restore a thread context, saved by _MD_SWITCH_CONTEXT
+*/
+#define _MD_RESTORE_CONTEXT(_thread) \
+{				     \
+    errno = (_thread)->md.errcode; \
+    _MD_SET_CURRENT_THREAD(_thread); \
+    longjmp(CONTEXT(_thread), 1); \
+}
+
+/* Machine-dependent (MD) data structures */
+
+struct _MDThread {
+    jmp_buf jb;
+    int id;
+    int errcode;
+};
+
+struct _MDThreadStack {
+    PRInt8 notused;
+};
+
+struct _MDLock {
+    PRInt8 notused;
+};
+
+struct _MDSemaphore {
+    PRInt8 notused;
+};
+
+struct _MDCVar {
+    PRInt8 notused;
+};
+
+struct _MDSegment {
+    PRInt8 notused;
+};
+
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
+struct _MDCPU {
+    struct _MDCPU_Unix md_unix;
+};
+
+#if !defined(_PR_PTHREADS)
+#define _MD_INIT_LOCKS()
+#endif
+
+#define _MD_NEW_LOCK(lock) PR_SUCCESS
+#define _MD_FREE_LOCK(lock)
+#define _MD_LOCK(lock)
+#define _MD_UNLOCK(lock)
+#define _MD_INIT_IO()
+#define _MD_IOQ_LOCK()
+#define _MD_IOQ_UNLOCK()
+
+#define _MD_EARLY_INIT          	_MD_EarlyInit
+#define _MD_FINAL_INIT			_PR_UnixInit
+#define _MD_INIT_RUNNING_CPU(cpu)	_MD_unix_init_running_cpu(cpu)
+#define _MD_INIT_THREAD			_MD_InitializeThread
+#define _MD_EXIT_THREAD(thread)
+#define	_MD_SUSPEND_THREAD(thread)
+#define	_MD_RESUME_THREAD(thread)
+#define _MD_CLEAN_THREAD(_thread)
+#endif /* PTHREADS_USER */
+
+#ifdef AIX_RENAME_SELECT
+#define _MD_SELECT	select
+#define _MD_POLL	poll
+#endif
+
+extern void _MD_aix_map_sendfile_error(int err);
+
+#endif /* nspr_aix_defs_h___ */
diff --git a/pr/include/md/_aix32.cfg b/pr/include/md/_aix32.cfg
new file mode 100644
index 0000000..23a3f51
--- /dev/null
+++ b/pr/include/md/_aix32.cfg
@@ -0,0 +1,115 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef XP_UNIX
+#define XP_UNIX
+#endif
+
+#ifndef AIX
+#define AIX
+#endif
+
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN 1
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2	5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  4
+#define PR_ALIGN_OF_POINTER 4
+
+#ifndef HAVE_LONG_LONG
+#define	HAVE_LONG_LONG
+#endif
+#undef	HAVE_ALIGNED_DOUBLES
+#undef	HAVE_ALIGNED_LONGLONGS
+
+#define PR_AF_INET6 24  /* same as AF_INET6 */
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
+#define BYTES_PER_INT 		PR_BYTES_PER_INT
+#define BYTES_PER_INT64		PR_BYTES_PER_INT64
+#define BYTES_PER_LONG		PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE	PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD		PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD		PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE		PR_BITS_PER_BYTE
+#define BITS_PER_SHORT		PR_BITS_PER_SHORT
+#define BITS_PER_INT		PR_BITS_PER_INT
+#define BITS_PER_INT64		PR_BITS_PER_INT64
+#define BITS_PER_LONG		PR_BITS_PER_LONG
+#define BITS_PER_FLOAT		PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE		PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD		PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2	PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2	PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2	PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2	PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2	PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2	PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2 	PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2	PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT		PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT		PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG		PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64		PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT		PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE		PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER	PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD		PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
+
+/* used by protypes.h only */
+#define _PR_AIX_HAVE_BSD_INT_TYPES
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
diff --git a/pr/include/md/_aix64.cfg b/pr/include/md/_aix64.cfg
new file mode 100644
index 0000000..7efe896
--- /dev/null
+++ b/pr/include/md/_aix64.cfg
@@ -0,0 +1,116 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef XP_UNIX
+#define XP_UNIX
+#endif
+
+#ifndef AIX
+#define AIX
+#endif
+
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN 1
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BYTES_PER_WORD_LOG2   3
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2	6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  4
+#define PR_ALIGN_OF_POINTER 8
+
+#ifndef HAVE_LONG_LONG
+#define	HAVE_LONG_LONG
+#endif
+#undef	HAVE_ALIGNED_DOUBLES
+#undef	HAVE_ALIGNED_LONGLONGS
+
+#define PR_AF_INET6 24  /* same as AF_INET6 */
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
+#define BYTES_PER_INT 		PR_BYTES_PER_INT
+#define BYTES_PER_INT64		PR_BYTES_PER_INT64
+#define BYTES_PER_LONG		PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE	PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD		PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD		PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE		PR_BITS_PER_BYTE
+#define BITS_PER_SHORT		PR_BITS_PER_SHORT
+#define BITS_PER_INT		PR_BITS_PER_INT
+#define BITS_PER_INT64		PR_BITS_PER_INT64
+#define BITS_PER_LONG		PR_BITS_PER_LONG
+#define BITS_PER_FLOAT		PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE		PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD		PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2	PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2	PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2	PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2	PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2	PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2	PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2 	PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2	PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT		PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT		PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG		PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64		PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT		PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE		PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER	PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD		PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
+
+/* used by protypes.h only */
+#define _PR_AIX_HAVE_BSD_INT_TYPES
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
diff --git a/pr/include/md/_beos.cfg b/pr/include/md/_beos.cfg
new file mode 100644
index 0000000..5a3c569
--- /dev/null
+++ b/pr/include/md/_beos.cfg
@@ -0,0 +1,120 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef XP_BEOS
+#define XP_BEOS
+#undef XP_UNIX
+#endif
+
+#ifndef BEOS
+#define BEOS
+#endif
+
+#define PR_AF_INET6 5  /* same as AF_INET6 */
+
+#ifdef __powerpc__
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN 1
+#else
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#endif
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   4
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  4
+#define PR_ALIGN_OF_POINTER 4
+
+#ifndef HAVE_LONG_LONG
+#define	HAVE_LONG_LONG
+#endif
+/*
+ * XXX These two macros need to be investigated for different architectures.
+ */
+#define	HAVE_ALIGNED_DOUBLES
+#define	HAVE_ALIGNED_LONGLONGS
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
+#define BYTES_PER_INT 		PR_BYTES_PER_INT
+#define BYTES_PER_INT64		PR_BYTES_PER_INT64
+#define BYTES_PER_LONG		PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE	PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD		PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD		PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE		PR_BITS_PER_BYTE
+#define BITS_PER_SHORT		PR_BITS_PER_SHORT
+#define BITS_PER_INT		PR_BITS_PER_INT
+#define BITS_PER_INT64		PR_BITS_PER_INT64
+#define BITS_PER_LONG		PR_BITS_PER_LONG
+#define BITS_PER_FLOAT		PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE		PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD		PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2	PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2	PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2	PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2	PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2	PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2	PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2 	PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2	PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT		PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT		PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG		PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64		PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT		PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE		PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER	PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD		PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
diff --git a/pr/include/md/_beos.h b/pr/include/md/_beos.h
new file mode 100644
index 0000000..78469dd
--- /dev/null
+++ b/pr/include/md/_beos.h
@@ -0,0 +1,583 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_beos_defs_h___
+#define nspr_beos_defs_h___
+
+#include "prtypes.h"
+#include "prio.h"
+#include "prthread.h"
+#include "prproces.h"
+#include "prmem.h"
+#include "obsolete/prsem.h"
+#include <errno.h>
+
+#include <support/SupportDefs.h>
+#include <kernel/OS.h>
+#include <dirent.h>
+
+/*
+ * Internal configuration macros
+ */
+
+#ifdef BONE_VERSION
+#define _PR_HAVE_SOCKADDR_LEN
+#define HAVE_NETINET_TCP_H
+#endif
+
+#define PR_LINKER_ARCH	"beos"
+#define _PR_SI_SYSNAME  "BEOS"
+#ifdef __powerpc__
+#define _PR_SI_ARCHITECTURE "ppc"
+#else
+#define _PR_SI_ARCHITECTURE "x86"
+#endif
+#define PR_DLL_SUFFIX		".so"
+
+#define _PR_VMBASE              0x30000000
+#define _PR_STACK_VMBASE	0x50000000
+#define _MD_DEFAULT_STACK_SIZE	65536L
+#define _MD_MMAP_FLAGS          MAP_PRIVATE
+
+#undef	HAVE_STACK_GROWING_UP
+#define HAVE_DLL
+#define _PR_NO_CLOCK_TIMER
+
+/*
+ * The Atomic operations
+ */
+
+#define _PR_HAVE_ATOMIC_OPS
+#define _MD_INIT_ATOMIC _MD_AtomicInit
+#define _MD_ATOMIC_INCREMENT _MD_AtomicIncrement
+#define _MD_ATOMIC_ADD _MD_AtomicAdd
+#define _MD_ATOMIC_DECREMENT _MD_AtomicDecrement
+#define _MD_ATOMIC_SET _MD_AtomicSet
+
+#define HAVE_CVAR_BUILT_ON_SEM
+#define _PR_GLOBAL_THREADS_ONLY
+#define _PR_BTHREADS
+#define _PR_NEED_FAKE_POLL
+#define _PR_HAVE_PEEK_BUFFER
+#define _PR_PEEK_BUFFER_MAX (16 * 1024)
+#define _PR_FD_NEED_EMULATE_MSG_PEEK(fd) 1
+#define _PR_CONNECT_DOES_NOT_BIND
+#define _PR_HAVE_O_APPEND
+
+/* Define threading functions and objects as native BeOS */
+struct _MDThread {
+    thread_id	tid;	/* BeOS thread handle */
+	sem_id		joinSem;	/* sems used to synchronzie joining */
+	PRBool	is_joining;	/* TRUE if someone is currently waiting to
+						   join this thread */
+};
+
+struct _MDThreadStack {
+    PRInt8	notused;
+};
+
+/*
+ * Lock and Semaphore related definitions
+ */
+
+struct _MDLock {
+    sem_id semaphoreID;
+    int32  benaphoreCount;
+};
+
+struct _MDCVar {
+    sem_id sem1;
+    sem_id sem2;
+    int16  count;
+};
+
+struct _MDSemaphore {
+    sem_id sid;
+};
+
+/*
+** CPU-related definitions
+*/
+struct _MDCPU {
+    int8		unused;
+};
+
+/*
+** Process-related definitions
+*/
+struct _MDProcess {
+    pid_t pid;
+};
+
+struct _MDSegment {
+    PRInt8 notused;
+};
+
+/*
+** File- and directory-related definitions
+*/
+
+#ifndef BONE_VERSION
+#define BE_SOCK_SHUTDOWN_READ	0x01
+#define BE_SOCK_SHUTDOWN_WRITE	0x02
+#endif
+
+struct _MDFileDesc {
+    PRInt32	osfd;
+    PRInt32	sock_state;
+    PRBool	accepted_socket;
+    PRNetAddr	peer_addr;
+#ifndef BONE_VERSION
+    PRBool	connectValueValid;
+    int		connectReturnValue;
+    int		connectReturnError;
+#endif
+};
+
+struct _MDDir {
+    DIR		*d;
+};
+
+#define PR_DIRECTORY_SEPARATOR		'/'
+#define PR_DIRECTORY_SEPARATOR_STR	"/"
+#define PR_PATH_SEPARATOR		':'
+#define PR_PATH_SEPARATOR_STR		":"
+
+#define GETTIMEOFDAY(tp)	gettimeofday((tp), NULL)
+
+/* --- Memory-mapped files stuff --- not implemented on BeOS */
+
+struct _MDFileMap {
+    PRInt8 unused;
+};
+
+/*
+ * Network related definitions.
+ */
+
+#ifndef BONE_VERSION
+#define IPPROTO_IP 0
+#define AF_UNIX 2
+#define TCP_NODELAY SO_NONBLOCK
+#define SO_LINGER -1
+#define SO_ERROR 4
+#endif
+
+#define _PR_INTERRUPT_CHECK_INTERVAL_SECS 5
+
+#ifndef BONE_VERSION
+/* these aren't actually used. if they are, we're screwed */
+struct  protoent {
+    char    *p_name;        /* official protocol name */
+    char    **p_aliases;    /* alias list */
+    int     p_proto;        /* protocol # */
+};
+
+struct protoent* getprotobyname(const char* name);
+struct protoent* getprotobynumber(int number);
+#endif
+
+/*
+ * malloc() related definitions.
+ */
+
+#undef _PR_OVERRIDE_MALLOC
+
+/* Miscellaneous */
+
+#define _MD_ERRNO()             (errno)
+
+#define _MD_CLEANUP_BEFORE_EXIT _MD_cleanup_before_exit
+#define _MD_EXIT _MD_exit
+
+#define _MD_GET_ENV getenv
+#define _MD_PUT_ENV putenv
+
+#define _MD_EARLY_INIT _MD_early_init
+#define _MD_FINAL_INIT _MD_final_init
+#define _MD_EARLY_CLEANUP()
+
+/* CPU Stuff */
+
+#define _MD_INIT_CPUS _MD_init_cpus
+#define _MD_WAKEUP_CPUS _MD_wakeup_cpus
+#define _MD_START_INTERRUPTS _MD_start_interrupts
+#define _MD_STOP_INTERRUPTS _MD_stop_interrupts
+#define _MD_DISABLE_CLOCK_INTERRUPTS _MD_disable_clock_interrupts
+#define _MD_BLOCK_CLOCK_INTERRUPTS _MD_block_clock_interrupts
+#define _MD_UNBLOCK_CLOCK_INTERRUPTS _MD_unblock_clock_interrupts
+#define _MD_CLOCK_INTERRUPT _MD_clock_interrupt
+#define _MD_INIT_STACK _MD_init_stack
+#define _MD_CLEAR_STACK _MD_clear_stack
+// #define _MD_GET_INTSOFF _MD_get_intsoff
+// #define _MD_SET_INTSOFF _MD_set_intsoff
+#define _MD_CURRENT_CPU _MD_current_cpu
+#define _MD_SET_CURRENT_CPU _MD_set_current_cpu
+#define _MD_INIT_RUNNING_CPU _MD_init_running_cpu
+#define _MD_PAUSE_CPU _MD_pause_cpu
+
+/* Thread stuff */
+
+#define _MD_CURRENT_THREAD() PR_GetCurrentThread()
+// #define _MD_GET_ATTACHED_THREAD _MD_get_attached_thread
+#define _MD_LAST_THREAD _MD_last_thread
+#define _MD_SET_CURRENT_THREAD _MD_set_current_THREAD
+#define _MD_SET_LAST_THREAD _MD_set_last_thread
+#define _MD_INIT_THREAD _MD_init_thread
+#define _MD_EXIT_THREAD _MD_exit_thread
+#define _MD_INIT_ATTACHED_THREAD _MD_init_attached_thread
+
+#define _MD_SUSPEND_THREAD _MD_suspend_thread
+#define _MD_RESUME_THREAD _MD_resume_thread
+#define _MD_SUSPEND_CPU _MD_suspend_cpu
+#define _MD_RESUME_CPU _MD_resume_cpu
+#define _MD_BEGIN_SUSPEND_ALL _MD_begin_suspend_all
+#define _MD_END_SUSPEND_ALL _MD_end_suspend_all
+#define _MD_BEGIN_RESUME_ALL _MD_begin_resume_all
+#define _MD_END_RESUME_ALL _MD_end_resume_all
+
+#define _MD_GET_SP _MD_get_sp
+
+#define _MD_CLEAN_THREAD _MD_clean_thread
+#define _MD_CREATE_PRIMORDIAL_USER_THREAD _MD_create_primordial_user_thread
+#define _MD_CREATE_USER_THREAD _MD_create_user_thread
+#define _MD_INIT_PRIMORDIAL_THREAD _MD_init_primordial_thread
+#define _MD_CREATE_THREAD _MD_create_thread
+#define _MD_YIELD _MD_yield
+#define _MD_SET_PRIORITY _MD_set_priority
+
+#define _MD_SUSPENDALL _MD_suspendall
+#define _MD_RESUMEALL _MD_resumeall
+
+#define _MD_SWITCH_CONTEXT _MD_switch_context
+#define _MD_RESTORE_CONTEXT _MD_restore_context
+
+#define _MD_WAIT _MD_wait
+#define _MD_WAKEUP_WAITER _MD_wakeup_waiter
+
+#define _MD_SETTHREADAFFINITYMASK _MD_setthreadaffinitymask
+#define _MD_GETTHREADAFFINITYMASK _MD_getthreadaffinitymask
+
+/* Thread Synchronization */
+
+#define _MD_INIT_LOCKS _MD_init_locks
+#define _MD_NEW_LOCK _MD_new_lock
+#define _MD_FREE_LOCK _MD_free_lock
+#define _MD_LOCK _MD_lock
+#define _MD_TEST_AND_LOCK _MD_test_and_lock
+#define _MD_UNLOCK _MD_unlock
+#define _MD_IOQ_LOCK _MD_ioq_lock
+#define _MD_IOQ_UNLOCK _MD_ioq_unlock
+#define _MD_NEW_SEM _MD_new_sem
+#define _MD_DESTROY_SEM _MD_destroy_sem
+#define _MD_TIMED_WAIT_SEM _MD_timed_wait_sem
+#define _MD_WAIT_SEM _MD_wait_sem
+#define _MD_POST_SEM _MD_post_sem
+// #define _MD_NEW_CV _MD_new_cv
+// #define _MD_FREE_CV _MD_free_cv
+// #define _MD_WAIT_CV _MD_wait_cv
+// #define _MD_NOTIFY_CV _MD_notify_cv
+// #define _MD_NOTIFYALL_CV _MD_notifyall_cv
+
+/* File I/O */
+
+/* don't need any I/O initializations */
+#define _MD_INIT_IO()
+#define _MD_INIT_FILEDESC(fd)
+
+#define _MD_OPEN_DIR _MD_open_dir
+#define _MD_READ_DIR _MD_read_dir
+#define _MD_CLOSE_DIR _MD_close_dir
+#define _MD_MAKE_NONBLOCK _MD_make_nonblock
+#define _MD_SET_FD_INHERITABLE _MD_set_fd_inheritable
+#define _MD_INIT_FD_INHERITABLE _MD_init_fd_inheritable
+#define _MD_QUERY_FD_INHERITABLE _MD_query_fd_inheritable
+#define _MD_OPEN _MD_open
+#define _MD_OPEN_FILE _MD_open
+#define _MD_CLOSE_FILE _MD_close_file
+#define _MD_READ _MD_read
+#define _MD_WRITE _MD_write
+#define _MD_WRITEV _MD_writev
+#define _MD_LSEEK _MD_lseek
+#define _MD_LSEEK64 _MD_lseek64
+#define _MD_FSYNC _MD_fsync
+#define _MD_DELETE _MD_delete
+#define _MD_GETFILEINFO _MD_getfileinfo
+#define _MD_GETFILEINFO64 _MD_getfileinfo64
+#define _MD_GETOPENFILEINFO _MD_getopenfileinfo
+#define _MD_GETOPENFILEINFO64 _MD_getopenfileinfo64
+#define _MD_RENAME _MD_rename
+#define _MD_ACCESS _MD_access
+#define _MD_STAT stat
+#define _MD_MKDIR _MD_mkdir
+#define _MD_MAKE_DIR _MD_mkdir
+#define _MD_RMDIR _MD_rmdir
+#define _MD_PR_POLL _MD_pr_poll
+
+/* Network I/O */
+
+#define _MD_CLOSE_SOCKET _MD_close_socket
+#define _MD_CONNECT _MD_connect
+#define _MD_ACCEPT _MD_accept
+#define _MD_BIND _MD_bind
+#define _MD_LISTEN _MD_listen
+#define _MD_SHUTDOWN _MD_shutdown
+#define _MD_RECV _MD_recv
+#define _MD_SEND _MD_send
+#define _MD_ACCEPT_READ _MD_accept_read
+#define _MD_GETSOCKNAME _MD_getsockname
+#define _MD_GETPEERNAME _MD_getpeername
+#define _MD_GETSOCKOPT _MD_getsockopt
+#define _MD_SETSOCKOPT _MD_setsockopt
+#define _MD_RECVFROM _MD_recvfrom
+#define _MD_SENDTO _MD_sendto
+#define _MD_SOCKETPAIR _MD_socketpair
+#define _MD_SOCKET _MD_socket
+#define _MD_SOCKETAVAILABLE _MD_socketavailable
+#define _MD_PIPEAVAILABLE _MD_socketavailable
+
+#define _MD_GET_SOCKET_ERROR()	(errno)
+#define _MD_GETHOSTNAME _MD_gethostname
+
+#define _MD_SELECT select
+
+/* Process management */
+
+#define _MD_CREATE_PROCESS _MD_create_process
+#define _MD_DETACH_PROCESS _MD_detach_process
+#define _MD_WAIT_PROCESS _MD_wait_process
+#define _MD_KILL_PROCESS _MD_kill_process
+
+/* Atomic data operations */
+
+// #define _MD_INIT_ATOMIC _MD_init_atomic
+// #define _MD_ATOMIC_INCREMENT _MD_atomic_increment
+// #define _MD_ATOMIC_DECREMENT _MD_atomic_decrement
+// #define _MD_ATOMIC_SET _MD_atomic_set
+
+/* memory management */
+
+#define _MD_INIT_SEGS _MD_init_segs
+#define _MD_ALLOC_SEGMENT _MD_alloc_segment
+#define _MD_FREE_SEGMENT _MD_free_segment
+
+/* Memory mapped file I/O */
+
+#define _MD_CREATE_FILE_MAP _MD_create_file_map
+#define _MD_GET_MEM_MAP_ALIGNMENT _MD_get_mem_map_alignment
+#define _MD_MEM_MAP _MD_mem_map
+#define _MD_MEM_UNMAP _MD_mem_unmap
+#define _MD_CLOSE_FILE_MAP _MD_close_file_map
+
+/* Time related */
+
+#define _MD_NOW _MD_now
+#define _MD_INTERVAL_INIT _MD_interval_init
+#define _MD_GET_INTERVAL _MD_get_interval
+#define _MD_INTERVAL_PER_SEC _MD_interval_per_sec
+
+/* File locking */
+
+#define _MD_LOCKFILE _MD_lockfile
+#define _MD_TLOCKFILE _MD_tlockfile
+#define _MD_UNLOCKFILE _MD_unlockfile
+
+/**
+ * Prototypes for machine dependent function implementations. (Too bad
+ * NSPR's MD system blows so much that we have to reiterate every stinking
+ * thing we implement here in our MD header file.)
+ */
+
+/* Miscellaneous */
+
+NSPR_API(void) _MD_cleanup_before_exit(void);
+NSPR_API(void) _MD_exit(PRIntn status);
+
+NSPR_API(char*) _MD_get_env(const char *name);
+NSPR_API(PRIntn) _MD_put_env(const char *name);
+
+NSPR_API(void) _MD_early_init(void);
+NSPR_API(void) _MD_final_init(void);
+
+/* CPU Stuff */
+
+NSPR_API(void) _MD_init_cpus();
+NSPR_API(void) _MD_wakeup_cpus();
+NSPR_API(void) _MD_start_interrupts(void);
+NSPR_API(void) _MD_stop_interrupts(void);
+NSPR_API(void) _MD_disable_clock_interrupts(void);
+NSPR_API(void) _MD_block_clock_interrupts(void);
+NSPR_API(void) _MD_unblock_clock_interrupts(void);
+NSPR_API(void) _MD_clock_interrupt(void);
+// NSPR_API(void) _MD_init_stack(PRThreadStack *ts, PRIntn redzone);
+// NSPR_API(void) _MD_clear_stack(PRThreadStack* ts);
+// NSPR_API(PRInt32) _MD_get_intsoff(void);
+// NSPR_API(void) _MD_set_intsoff(PRInt32 _val);
+// NSPR_API(_PRCPU*) _MD_current_cpu(void);
+// NSPR_API(void) _MD_set_current_cpu(_PRCPU *cpu);
+// NSPR_API(void) _MD_init_running_cpu(_PRCPU *cpu);
+NSPR_API(PRInt32) _MD_pause_cpu(PRIntervalTime timeout);
+
+/* Thread stuff */
+
+// NSPR_API(PRThread*) _MD_current_thread(void);
+NSPR_API(PRThread*) _MD_get_attached_thread(void);
+NSPR_API(PRThread*) _MD_last_thread(void);
+NSPR_API(void) _MD_set_current_thread(PRThread *thread);
+NSPR_API(void) _MD_set_last_thread(PRThread *thread);
+NSPR_API(PRStatus) _MD_init_thread(PRThread *thread);
+NSPR_API(void) _MD_exit_thread(PRThread *thread);
+NSPR_API(PRStatus) _MD_init_attached_thread(PRThread *thread);
+
+NSPR_API(void) _MD_suspend_thread(PRThread *thread);
+NSPR_API(void) _MD_resume_thread(PRThread *thread);
+// NSPR_API(void) _MD_suspend_cpu(_PRCPU  *cpu);
+// NSPR_API(void) _MD_resume_cpu(_PRCPU  *cpu);
+NSPR_API(void) _MD_begin_suspend_all(void);
+NSPR_API(void) _MD_end_suspend_all(void);
+NSPR_API(void) _MD_begin_resume_all(void);
+NSPR_API(void) _MD_end_resume_all(void);
+
+NSPR_API(void *) _MD_get_sp(PRThread *thread);
+
+NSPR_API(void) _MD_clean_thread(PRThread *thread);
+NSPR_API(void) _MD_create_primordial_user_thread(PRThread *);
+NSPR_API(PRThread*) _MD_create_user_thread(PRUint32 stacksize, void (*start)(void *), void *arg);
+NSPR_API(void) _MD_init_primordial_thread(PRThread *thread);
+NSPR_API(PRStatus) _MD_create_thread(PRThread *thread, void (*start)(void *), PRThreadPriority priority, PRThreadScope scope, PRThreadState state, PRUint32 stackSize);
+NSPR_API(void) _MD_yield(void);
+NSPR_API(void) _MD_set_priority(struct _MDThread *md, PRThreadPriority newPri);
+
+NSPR_API(void) _MD_suspendall(void);
+NSPR_API(void) _MD_resumeall(void);
+
+NSPR_API(void) _MD_init_context(PRThread *thread, char *top, void (*start) (void), PRBool *status);
+NSPR_API(void) _MD_switch_context(PRThread *thread);
+NSPR_API(void) _MD_restore_context(PRThread *thread);
+
+NSPR_API(PRStatus) _MD_wait(PRThread *, PRIntervalTime timeout);
+NSPR_API(PRStatus) _MD_wakeup_waiter(PRThread *);
+
+NSPR_API(PRInt32) _MD_setthreadaffinitymask(PRThread *thread, PRUint32 mask );
+NSPR_API(PRInt32) _MD_getthreadaffinitymask(PRThread *thread, PRUint32 *mask);
+
+/* Thread Synchronization */
+
+NSPR_API(void) _MD_init_locks(void);
+NSPR_API(PRStatus) _MD_new_lock(struct _MDLock *md);
+NSPR_API(void) _MD_free_lock(struct _MDLock *md);
+NSPR_API(void) _MD_lock(struct _MDLock *md);
+NSPR_API(PRIntn) _MD_test_and_lock(struct _MDLock *md);
+NSPR_API(void) _MD_unlock(struct _MDLock *md);
+NSPR_API(void) _MD_ioq_lock(void);
+NSPR_API(void) _MD_ioq_unlock(void);
+NSPR_API(void) _MD_new_sem(struct _MDSemaphore *md, PRUintn value);
+NSPR_API(void) _MD_destroy_sem(struct _MDSemaphore *md);
+NSPR_API(PRStatus) _MD_timed_wait_sem(struct _MDSemaphore *md, PRIntervalTime timeout);
+NSPR_API(PRStatus) _MD_wait_sem(struct _MDSemaphore *md);
+NSPR_API(void) _MD_post_sem(struct _MDSemaphore *md);
+// NSPR_API(PRInt32) _MD_new_cv(struct _MDCVar *md);
+// NSPR_API(void) _MD_free_cv(struct _MDCVar *md);
+// NSPR_API(void) _MD_wait_cv(struct _MDCVar *mdCVar, struct _MDLock *mdLock, PRIntervalTime timeout);
+// NSPR_API(void) _MD_notify_cv(struct _MDCVar *md, struct _MDLock *lock);
+// NSPR_API(void) _MD_notifyall_cv(struct _MDCVar *md, struct _MDLock *lock);
+
+/* File I/O */
+
+// NSPR_API(void) _MD_init_io(void);
+NSPR_API(PRStatus) _MD_open_dir(struct _MDDir *md,const char *name);
+NSPR_API(char *) _MD_read_dir(struct _MDDir *md, PRIntn flags);
+NSPR_API(PRInt32) _MD_close_dir(struct _MDDir *md);
+NSPR_API(void) _MD_make_nonblock(PRFileDesc *fd);
+NSPR_API(void) _MD_init_fd_inheritable(PRFileDesc *fd, PRBool imported);
+NSPR_API(void) _MD_query_fd_inheritable(PRFileDesc *fd);
+NSPR_API(PRInt32) _MD_open(const char *name, PRIntn osflags, PRIntn mode);
+NSPR_API(PRInt32) _MD_close_file(PRInt32 osfd);
+NSPR_API(PRInt32) _MD_read(PRFileDesc *fd, void *buf, PRInt32 amount);
+NSPR_API(PRInt32) _MD_write(PRFileDesc *fd, const void *buf, PRInt32 amount);
+NSPR_API(PRInt32) _MD_writev(PRFileDesc *fd, const PRIOVec *iov, PRInt32 iov_size, PRIntervalTime timeout);
+NSPR_API(PRInt32) _MD_lseek(PRFileDesc *fd, PRInt32 offset, int whence);
+NSPR_API(PRInt64) _MD_lseek64(PRFileDesc *fd, PRInt64 offset, int whence);
+NSPR_API(PRInt32) _MD_fsync(PRFileDesc *fd);
+NSPR_API(PRInt32) _MD_delete(const char *name);
+NSPR_API(PRInt32) _MD_getfileinfo(const char *fn, PRFileInfo *info);
+NSPR_API(PRInt32) _MD_getfileinfo64(const char *fn, PRFileInfo64 *info);
+NSPR_API(PRInt32) _MD_getopenfileinfo(const PRFileDesc *fd, PRFileInfo *info);
+NSPR_API(PRInt32) _MD_getopenfileinfo64(const PRFileDesc *fd, PRFileInfo64 *info);
+NSPR_API(PRInt32) _MD_rename(const char *from, const char *to);
+NSPR_API(PRInt32) _MD_access(const char *name, PRIntn how);
+NSPR_API(PRInt32) _MD_stat(const char *name, struct stat *buf);
+NSPR_API(PRInt32) _MD_mkdir(const char *name, PRIntn mode);
+NSPR_API(PRInt32) _MD_rmdir(const char *name);
+NSPR_API(PRInt32) _MD_pr_poll(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout);
+
+/* Network I/O */
+NSPR_API(PRInt32) _MD_close_socket(PRInt32 osfd);
+NSPR_API(PRInt32) _MD_connect(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen, PRIntervalTime timeout);
+NSPR_API(PRInt32) _MD_accept(PRFileDesc *fd, PRNetAddr *addr, PRUint32 *addrlen, PRIntervalTime timeout);
+NSPR_API(PRInt32) _MD_bind(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen);
+NSPR_API(PRInt32) _MD_listen(PRFileDesc *fd, PRIntn backlog);
+NSPR_API(PRInt32) _MD_shutdown(PRFileDesc *fd, PRIntn how);
+NSPR_API(PRInt32) _MD_recv(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags, PRIntervalTime timeout);
+NSPR_API(PRInt32) _MD_send(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags, PRIntervalTime timeout);
+NSPR_API(PRInt32) _MD_accept_read(PRFileDesc *sd, PRInt32 *newSock, PRNetAddr **raddr, void *buf, PRInt32 amount, PRIntervalTime timeout);
+// NSPR_API(PRInt32) _MD_fast_accept(PRFileDesc *fd, PRNetAddr *addr, PRUint32 *addrlen, PRIntervalTime timeout, PRBool fast, _PR_AcceptTimeoutCallback callback, void *callbackArg);
+// NSPR_API(PRInt32) _MD_fast_accept_read(PRFileDesc *sd, PRInt32 *newSock, PRNetAddr **raddr, void *buf, PRInt32 amount, PRIntervalTime timeout, PRBool fast, _PR_AcceptTimeoutCallback callback, void *callbackArg);
+// NSPR_API(void) _MD_update_accept_context(PRInt32 s, PRInt32 ls);
+NSPR_API(PRStatus) _MD_getsockname(PRFileDesc *fd, PRNetAddr *addr, PRUint32 *addrlen);
+NSPR_API(PRStatus) _MD_getpeername(PRFileDesc *fd, PRNetAddr *addr, PRUint32 *addrlen);
+NSPR_API(PRStatus) _MD_getsockopt(PRFileDesc *fd, PRInt32 level, PRInt32 optname, char* optval, PRInt32* optlen);
+NSPR_API(PRStatus) _MD_setsockopt(PRFileDesc *fd, PRInt32 level, PRInt32 optname, const char* optval, PRInt32 optlen);
+NSPR_API(PRInt32) _MD_recvfrom(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags, PRNetAddr *addr, PRUint32 *addrlen, PRIntervalTime timeout);
+NSPR_API(PRInt32) _MD_sendto(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags, const PRNetAddr *addr, PRUint32 addrlen, PRIntervalTime timeout);
+NSPR_API(PRInt32) _MD_socketpair(int af, int type, int flags, PRInt32 *osfd);
+NSPR_API(PRInt32) _MD_socket(int af, int type, int flags);
+NSPR_API(PRInt32) _MD_socketavailable(PRFileDesc *fd);
+
+// NSPR_API(PRInt32) _MD_get_socket_error(void);
+NSPR_API(PRStatus) _MD_gethostname(char *name, PRUint32 namelen);
+
+/* Process management */
+
+NSPR_API(PRProcess *) _MD_create_process(const char *path, char *const *argv, char *const *envp, const PRProcessAttr *attr);
+NSPR_API(PRStatus) _MD_detach_process(PRProcess *process);
+NSPR_API(PRStatus) _MD_wait_process(PRProcess *process, PRInt32 *exitCode);
+NSPR_API(PRStatus) _MD_kill_process(PRProcess *process);
+
+/* Atomic data operations */
+
+// NSPR_API(void) _MD_init_atomic(void);
+// NSPR_API(PRInt32) _MD_atomic_increment(PRInt32 *);
+// NSPR_API(PRInt32) _MD_atomic_decrement(PRInt32 *);
+// NSPR_API(PRInt32) _MD_atomic_set(PRInt32 *, PRInt32);
+
+/* Memory management */
+
+NSPR_API(void) _MD_init_segs(void);
+NSPR_API(PRStatus) _MD_alloc_segment(PRSegment *seg, PRUint32 size, void *vaddr);
+NSPR_API(void) _MD_free_segment(PRSegment *seg);
+
+/* Memory mapped file I/O */
+
+NSPR_API(PRStatus) _MD_create_file_map(PRFileMap *fmap, PRInt64 size);
+NSPR_API(PRInt32) _MD_get_mem_map_alignment(void);
+NSPR_API(void *) _MD_mem_map(PRFileMap *fmap, PRInt64 offset, PRUint32 len);
+NSPR_API(PRStatus) _MD_mem_unmap(void *addr, PRUint32 size);
+NSPR_API(PRStatus) _MD_close_file_map(PRFileMap *fmap);
+
+/* Time related */
+
+NSPR_API(PRTime) _MD_now(void);
+NSPR_API(void) _MD_interval_init(void);
+NSPR_API(PRIntervalTime) _MD_get_interval(void);
+NSPR_API(PRIntervalTime) _MD_interval_per_sec(void);
+
+/* File locking */
+
+NSPR_API(PRStatus) _MD_lockfile(PRInt32 osfd);
+NSPR_API(PRStatus) _MD_tlockfile(PRInt32 osfd);
+NSPR_API(PRStatus) _MD_unlockfile(PRInt32 osfd);
+
+#endif /* _nspr_beos_defs_h___*/
diff --git a/pr/include/md/_bsdi.cfg b/pr/include/md/_bsdi.cfg
new file mode 100644
index 0000000..130cf82
--- /dev/null
+++ b/pr/include/md/_bsdi.cfg
@@ -0,0 +1,170 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef XP_UNIX
+#define XP_UNIX
+#endif
+
+#ifndef BSDI
+#define BSDI
+#endif
+
+#define PR_AF_INET6 24  /* same as AF_INET6 */
+
+#if defined(__i386__)
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#ifndef HAVE_LONG_LONG
+#define HAVE_LONG_LONG
+#endif
+#undef	HAVE_ALIGNED_DOUBLES
+#undef	HAVE_ALIGNED_LONGLONGS
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   4
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  4
+#define PR_ALIGN_OF_POINTER 4
+#define PR_ALIGN_OF_WORD    4
+
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#elif defined(__sparc__)
+
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN 1
+#ifndef HAVE_LONG_LONG
+#define HAVE_LONG_LONG
+#endif
+#define	HAVE_ALIGNED_DOUBLES
+#define	HAVE_ALIGNED_LONGLONGS
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 4
+#define PR_ALIGN_OF_WORD    4
+
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#else
+
+#error "Unknown CPU architecture"
+
+#endif
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
+#define BYTES_PER_INT 		PR_BYTES_PER_INT
+#define BYTES_PER_INT64		PR_BYTES_PER_INT64
+#define BYTES_PER_LONG		PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE	PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD		PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD		PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE		PR_BITS_PER_BYTE
+#define BITS_PER_SHORT		PR_BITS_PER_SHORT
+#define BITS_PER_INT		PR_BITS_PER_INT
+#define BITS_PER_INT64		PR_BITS_PER_INT64
+#define BITS_PER_LONG		PR_BITS_PER_LONG
+#define BITS_PER_FLOAT		PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE		PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD		PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2	PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2	PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2	PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2	PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2	PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2	PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2 	PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2	PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT		PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT		PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG		PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64		PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT		PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE		PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER	PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD		PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
diff --git a/pr/include/md/_bsdi.h b/pr/include/md/_bsdi.h
new file mode 100644
index 0000000..dbd0ec3
--- /dev/null
+++ b/pr/include/md/_bsdi.h
@@ -0,0 +1,181 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_bsdi_defs_h___
+#define nspr_bsdi_defs_h___
+
+/*
+ * Internal configuration macros
+ */
+
+#include <sys/param.h>	/* for _BSDI_VERSION */
+
+#define PR_LINKER_ARCH	"bsdi"
+#define _PR_SI_SYSNAME "BSDI"
+#if defined(__i386__)
+#define _PR_SI_ARCHITECTURE "x86"
+#elif defined(__sparc__)
+#define _PR_SI_ARCHITECTURE "sparc"
+#else
+#error "Unknown CPU architecture"
+#endif
+#define PR_DLL_SUFFIX		".so"
+
+#define _PR_STACK_VMBASE	0x50000000
+#define _MD_DEFAULT_STACK_SIZE	65536L
+#define _MD_MMAP_FLAGS          MAP_PRIVATE
+
+#define HAVE_BSD_FLOCK
+#define NEED_TIME_R
+#define _PR_HAVE_SOCKADDR_LEN
+#define _PR_NO_LARGE_FILES
+
+#define USE_SETJMP
+
+/* BSD/OS 4.3 and newer all have IPv6 support */
+#if _BSDI_VERSION >= 200105
+#define _PR_INET6
+#define _PR_HAVE_INET_NTOP
+#define _PR_HAVE_GETIPNODEBYNAME
+#define _PR_HAVE_GETIPNODEBYADDR
+#define _PR_HAVE_GETADDRINFO
+#define _PR_INET6_PROBE
+#endif
+
+#ifndef _PR_PTHREADS
+
+#include <setjmp.h>
+
+#if defined(_PR_BSDI_JMPBUF_IS_ARRAY)
+#define _MD_GET_SP(_t)    (_t)->md.context[2] 
+#elif defined(_PR_BSDI_JMPBUF_IS_STRUCT)
+#define _MD_GET_SP(_t)    (_t)->md.context[0].jb_esp
+#else
+#error "Unknown BSDI jmp_buf type"
+#endif
+
+#define PR_NUM_GCREGS	_JBLEN
+#define PR_CONTEXT_TYPE	jmp_buf
+
+#define CONTEXT(_th) ((_th)->md.context)
+
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)	  \
+{								  \
+    *status = PR_TRUE; \
+    if (setjmp(CONTEXT(_thread))) {				  \
+	_main();					  \
+    }								  \
+    _MD_GET_SP(_thread) = (int) (_sp - 64); \
+}
+
+#define _MD_SWITCH_CONTEXT(_thread)  \
+    if (!setjmp(CONTEXT(_thread))) { \
+	(_thread)->md.errcode = errno;  \
+	_PR_Schedule();		     \
+    }
+
+/*
+** Restore a thread context, saved by _MD_SWITCH_CONTEXT
+*/
+#define _MD_RESTORE_CONTEXT(_thread) \
+{				     \
+    errno = (_thread)->md.errcode;	     \
+    _MD_SET_CURRENT_THREAD(_thread); \
+    longjmp(CONTEXT(_thread), 1);    \
+}
+
+/* Machine-dependent (MD) data structures */
+
+struct _MDThread {
+    PR_CONTEXT_TYPE context;
+    int id;
+    int errcode;
+};
+
+struct _MDThreadStack {
+    PRInt8 notused;
+};
+
+struct _MDLock {
+    PRInt8 notused;
+};
+
+struct _MDSemaphore {
+    PRInt8 notused;
+};
+
+struct _MDCVar {
+    PRInt8 notused;
+};
+
+struct _MDSegment {
+    PRInt8 notused;
+};
+
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
+struct _MDCPU {
+	struct _MDCPU_Unix md_unix;
+};
+
+#define _MD_INIT_LOCKS()
+#define _MD_NEW_LOCK(lock) PR_SUCCESS
+#define _MD_FREE_LOCK(lock)
+#define _MD_LOCK(lock)
+#define _MD_UNLOCK(lock)
+#define _MD_INIT_IO()
+#define _MD_IOQ_LOCK()
+#define _MD_IOQ_UNLOCK()
+
+#define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
+#define _MD_INIT_THREAD         _MD_InitializeThread
+#define _MD_EXIT_THREAD(thread)
+#define _MD_CLEAN_THREAD(_thread)
+
+#endif /* ! _PR_PTHREADS */
+
+#define _MD_EARLY_INIT          _MD_EarlyInit
+#define _MD_FINAL_INIT			_PR_UnixInit
+
+#include <sys/syscall.h>
+#define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
+
+#define _MD_INTERVAL_USE_GTOD
+
+#endif /* nspr_bsdi_defs_h___ */
diff --git a/pr/include/md/_darwin.cfg b/pr/include/md/_darwin.cfg
new file mode 100644
index 0000000..5e11893
--- /dev/null
+++ b/pr/include/md/_darwin.cfg
@@ -0,0 +1,165 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef XP_UNIX
+#define XP_UNIX
+#endif
+
+#define PR_AF_INET6 30  /* same as AF_INET6 */
+
+#ifdef __LITTLE_ENDIAN__
+#undef IS_BIG_ENDIAN
+#define  IS_LITTLE_ENDIAN 1
+#else
+#undef IS_LITTLE_ENDIAN
+#define  IS_BIG_ENDIAN 1
+#endif
+
+#ifdef __LP64__
+#define IS_64
+#endif
+
+#ifndef HAVE_LONG_LONG
+#define	HAVE_LONG_LONG
+#endif
+#undef	HAVE_ALIGNED_DOUBLES
+#define	HAVE_ALIGNED_LONGLONGS 1
+
+#ifdef IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+#define PR_BITS_PER_DWORD   64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   6
+#define PR_BITS_PER_DWORD_LOG2  6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+#define PR_ALIGN_OF_WORD    8
+#define PR_ALIGN_OF_DWORD   8
+
+#else /* IS_64 */
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+#define PR_BITS_PER_DWORD   64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   4
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  4
+#define PR_ALIGN_OF_POINTER 4
+#define PR_ALIGN_OF_WORD    4
+
+#endif /* IS_64 */
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
+#define BYTES_PER_INT 		PR_BYTES_PER_INT
+#define BYTES_PER_INT64		PR_BYTES_PER_INT64
+#define BYTES_PER_LONG		PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE	PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD		PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD		PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE		PR_BITS_PER_BYTE
+#define BITS_PER_SHORT		PR_BITS_PER_SHORT
+#define BITS_PER_INT		PR_BITS_PER_INT
+#define BITS_PER_INT64		PR_BITS_PER_INT64
+#define BITS_PER_LONG		PR_BITS_PER_LONG
+#define BITS_PER_FLOAT		PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE		PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD		PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2	PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2	PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2	PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2	PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2	PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2	PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2 	PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2	PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT		PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT		PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG		PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64		PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT		PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE		PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER	PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD		PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
+
diff --git a/pr/include/md/_darwin.h b/pr/include/md/_darwin.h
new file mode 100644
index 0000000..d321023
--- /dev/null
+++ b/pr/include/md/_darwin.h
@@ -0,0 +1,303 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_darwin_defs_h___
+#define nspr_darwin_defs_h___
+
+#include "prthread.h"
+
+#include <libkern/OSAtomic.h>
+#include <sys/syscall.h>
+
+#ifdef __APPLE__
+#include <AvailabilityMacros.h>
+#include <TargetConditionals.h>
+#endif
+
+#define PR_LINKER_ARCH	"darwin"
+#define _PR_SI_SYSNAME  "DARWIN"
+#ifdef __i386__
+#define _PR_SI_ARCHITECTURE "x86"
+#elif defined(__x86_64__)
+#define _PR_SI_ARCHITECTURE "x86-64"
+#elif defined(__ppc__)
+#define _PR_SI_ARCHITECTURE "ppc"
+#elif defined(__arm__)
+#define _PR_SI_ARCHITECTURE "arm"
+#elif defined(__aarch64__)
+#define _PR_SI_ARCHITECTURE "aarch64"
+#else
+#error "Unknown CPU architecture"
+#endif
+#define PR_DLL_SUFFIX		".dylib"
+
+#define _PR_VMBASE              0x30000000
+#define _PR_STACK_VMBASE	0x50000000
+#define _MD_DEFAULT_STACK_SIZE	65536L
+#define _MD_MMAP_FLAGS          MAP_PRIVATE
+
+#undef  HAVE_STACK_GROWING_UP
+#define HAVE_DLL
+#if defined(__x86_64__) || TARGET_OS_IPHONE
+#define USE_DLFCN
+#else
+#define USE_MACH_DYLD
+#endif
+#define _PR_HAVE_SOCKADDR_LEN  
+#define _PR_STAT_HAS_ST_ATIMESPEC
+#define _PR_HAVE_LARGE_OFF_T
+#define _PR_HAVE_SYSV_SEMAPHORES
+#define PR_HAVE_SYSV_NAMED_SHARED_MEMORY
+
+#define _PR_INET6
+/*
+ * I'd prefer to use getipnodebyname and getipnodebyaddr but the
+ * getipnodebyname(3) man page on Mac OS X 10.2 says they are not
+ * thread-safe.  AI_V4MAPPED|AI_ADDRCONFIG doesn't work either.
+ */
+#define _PR_HAVE_GETHOSTBYNAME2
+#define _PR_HAVE_GETADDRINFO
+/*
+ * On Mac OS X 10.2, gethostbyaddr fails with h_errno=NO_RECOVERY
+ * if you pass an IPv4-mapped IPv6 address to it.
+ */
+#define _PR_GHBA_DISALLOW_V4MAPPED
+#ifdef __APPLE__
+#if !defined(MAC_OS_X_VERSION_10_3) || \
+    MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_3
+/*
+ * socket(AF_INET6) fails with EPROTONOSUPPORT on Mac OS X 10.1.
+ * IPv6 under OS X 10.2 and below is not complete (see bug 222031).
+ */
+#define _PR_INET6_PROBE
+#endif /* DT < 10.3 */
+#if defined(MAC_OS_X_VERSION_10_2) && \
+    MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_2
+/* Mac OS X 10.2 has inet_ntop and inet_pton. */
+#define _PR_HAVE_INET_NTOP
+#endif /* DT >= 10.2 */
+#endif /* __APPLE__ */
+#define _PR_IPV6_V6ONLY_PROBE
+/* The IPV6_V6ONLY socket option is not defined on Mac OS X 10.1. */
+#ifndef IPV6_V6ONLY
+#define IPV6_V6ONLY 27
+#endif
+
+#ifdef __ppc__
+#define _PR_HAVE_ATOMIC_OPS
+#define _MD_INIT_ATOMIC()
+extern PRInt32 _PR_DarwinPPC_AtomicIncrement(PRInt32 *val);
+#define _MD_ATOMIC_INCREMENT(val)   _PR_DarwinPPC_AtomicIncrement(val)
+extern PRInt32 _PR_DarwinPPC_AtomicDecrement(PRInt32 *val);
+#define _MD_ATOMIC_DECREMENT(val)   _PR_DarwinPPC_AtomicDecrement(val)
+extern PRInt32 _PR_DarwinPPC_AtomicSet(PRInt32 *val, PRInt32 newval);
+#define _MD_ATOMIC_SET(val, newval) _PR_DarwinPPC_AtomicSet(val, newval)
+extern PRInt32 _PR_DarwinPPC_AtomicAdd(PRInt32 *ptr, PRInt32 val);
+#define _MD_ATOMIC_ADD(ptr, val)    _PR_DarwinPPC_AtomicAdd(ptr, val)
+#endif /* __ppc__ */
+
+#ifdef __i386__
+#define _PR_HAVE_ATOMIC_OPS
+#define _MD_INIT_ATOMIC()
+extern PRInt32 _PR_Darwin_x86_AtomicIncrement(PRInt32 *val);
+#define _MD_ATOMIC_INCREMENT(val)   _PR_Darwin_x86_AtomicIncrement(val)
+extern PRInt32 _PR_Darwin_x86_AtomicDecrement(PRInt32 *val);
+#define _MD_ATOMIC_DECREMENT(val)   _PR_Darwin_x86_AtomicDecrement(val)
+extern PRInt32 _PR_Darwin_x86_AtomicSet(PRInt32 *val, PRInt32 newval);
+#define _MD_ATOMIC_SET(val, newval) _PR_Darwin_x86_AtomicSet(val, newval)
+extern PRInt32 _PR_Darwin_x86_AtomicAdd(PRInt32 *ptr, PRInt32 val);
+#define _MD_ATOMIC_ADD(ptr, val)    _PR_Darwin_x86_AtomicAdd(ptr, val)
+#endif /* __i386__ */
+
+#ifdef __x86_64__
+#define _PR_HAVE_ATOMIC_OPS
+#define _MD_INIT_ATOMIC()
+extern PRInt32 _PR_Darwin_x86_64_AtomicIncrement(PRInt32 *val);
+#define _MD_ATOMIC_INCREMENT(val)   _PR_Darwin_x86_64_AtomicIncrement(val)
+extern PRInt32 _PR_Darwin_x86_64_AtomicDecrement(PRInt32 *val);
+#define _MD_ATOMIC_DECREMENT(val)   _PR_Darwin_x86_64_AtomicDecrement(val)
+extern PRInt32 _PR_Darwin_x86_64_AtomicSet(PRInt32 *val, PRInt32 newval);
+#define _MD_ATOMIC_SET(val, newval) _PR_Darwin_x86_64_AtomicSet(val, newval)
+extern PRInt32 _PR_Darwin_x86_64_AtomicAdd(PRInt32 *ptr, PRInt32 val);
+#define _MD_ATOMIC_ADD(ptr, val)    _PR_Darwin_x86_64_AtomicAdd(ptr, val)
+#endif /* __x86_64__ */
+
+#if defined(__arm__) || defined(__aarch64__)
+#define _PR_HAVE_ATOMIC_OPS
+#define _MD_INIT_ATOMIC()
+#define _MD_ATOMIC_INCREMENT(val)   OSAtomicIncrement32(val)
+#define _MD_ATOMIC_DECREMENT(val)   OSAtomicDecrement32(val)
+static inline PRInt32 _MD_ATOMIC_SET(PRInt32 *val, PRInt32 newval)
+{
+    PRInt32 oldval;
+    do {
+        oldval = *val;
+    } while (!OSAtomicCompareAndSwap32(oldval, newval, val));
+    return oldval;
+}
+#define _MD_ATOMIC_ADD(ptr, val)    OSAtomicAdd32(val, ptr)
+#endif /* __arm__ || __aarch64__ */
+
+#define USE_SETJMP
+
+#if !defined(_PR_PTHREADS)
+
+#include <setjmp.h>
+
+#define PR_CONTEXT_TYPE	jmp_buf
+
+#define CONTEXT(_th)       ((_th)->md.context)
+#define _MD_GET_SP(_th)    (((struct sigcontext *) (_th)->md.context)->sc_onstack)
+#define PR_NUM_GCREGS	    _JBLEN
+
+/*
+** Initialize a thread context to run "_main()" when started
+*/
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
+{  \
+    *status = PR_TRUE;  \
+    if (setjmp(CONTEXT(_thread))) {  \
+        _main();  \
+    }  \
+    _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 64); \
+}
+
+#define _MD_SWITCH_CONTEXT(_thread)  \
+    if (!setjmp(CONTEXT(_thread))) {  \
+	(_thread)->md.errcode = errno;  \
+	_PR_Schedule();  \
+    }
+
+/*
+** Restore a thread context, saved by _MD_SWITCH_CONTEXT
+*/
+#define _MD_RESTORE_CONTEXT(_thread) \
+{   \
+    errno = (_thread)->md.errcode;  \
+    _MD_SET_CURRENT_THREAD(_thread);  \
+    longjmp(CONTEXT(_thread), 1);  \
+}
+
+/* Machine-dependent (MD) data structures */
+
+struct _MDThread {
+    PR_CONTEXT_TYPE context;
+    int id;
+    int errcode;
+};
+
+struct _MDThreadStack {
+    PRInt8 notused;
+};
+
+struct _MDLock {
+    PRInt8 notused;
+};
+
+struct _MDSemaphore {
+    PRInt8 notused;
+};
+
+struct _MDCVar {
+    PRInt8 notused;
+};
+
+struct _MDSegment {
+    PRInt8 notused;
+};
+
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
+struct _MDCPU {
+	struct _MDCPU_Unix md_unix;
+};
+
+#define _MD_INIT_LOCKS()
+#define _MD_NEW_LOCK(lock) PR_SUCCESS
+#define _MD_FREE_LOCK(lock)
+#define _MD_LOCK(lock)
+#define _MD_UNLOCK(lock)
+#define _MD_INIT_IO()
+#define _MD_IOQ_LOCK()
+#define _MD_IOQ_UNLOCK()
+
+extern PRStatus _MD_InitializeThread(PRThread *thread);
+
+#define _MD_INIT_RUNNING_CPU(cpu)       _MD_unix_init_running_cpu(cpu)
+#define _MD_INIT_THREAD                 _MD_InitializeThread
+#define _MD_EXIT_THREAD(thread)
+#define _MD_SUSPEND_THREAD(thread)      _MD_suspend_thread
+#define _MD_RESUME_THREAD(thread)       _MD_resume_thread
+#define _MD_CLEAN_THREAD(_thread)
+
+extern PRStatus _MD_CREATE_THREAD(
+    PRThread *thread,
+    void (*start) (void *),
+    PRThreadPriority priority,
+    PRThreadScope scope,
+    PRThreadState state,
+    PRUint32 stackSize);
+extern void _MD_SET_PRIORITY(struct _MDThread *thread, PRUintn newPri);
+extern PRStatus _MD_WAIT(PRThread *, PRIntervalTime timeout);
+extern PRStatus _MD_WAKEUP_WAITER(PRThread *);
+extern void _MD_YIELD(void);
+
+#endif /* ! _PR_PTHREADS */
+
+#define _MD_EARLY_INIT          _MD_EarlyInit
+#define _MD_FINAL_INIT			_PR_UnixInit
+#define _MD_INTERVAL_INIT       _PR_Mach_IntervalInit
+#define _MD_GET_INTERVAL        _PR_Mach_GetInterval
+#define _MD_INTERVAL_PER_SEC    _PR_Mach_TicksPerSecond
+
+extern void             _MD_EarlyInit(void);
+extern void             _PR_Mach_IntervalInit(void);
+extern PRIntervalTime   _PR_Mach_GetInterval(void);
+extern PRIntervalTime   _PR_Mach_TicksPerSecond(void);
+
+/*
+ * We wrapped the select() call.  _MD_SELECT refers to the built-in,
+ * unwrapped version.
+ */
+#define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
+
+/* For writev() */
+#include <sys/uio.h>
+
+#endif /* nspr_darwin_defs_h___ */
diff --git a/pr/include/md/_dgux.cfg b/pr/include/md/_dgux.cfg
new file mode 100644
index 0000000..8c9e3de
--- /dev/null
+++ b/pr/include/md/_dgux.cfg
@@ -0,0 +1,108 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef XP_UNIX
+#define XP_UNIX
+#endif
+
+#ifndef DGUX
+#define DGUX
+#endif
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#ifndef HAVE_LONG_LONG
+#define HAVE_LONG_LONG
+#endif
+#undef	HAVE_ALIGNED_DOUBLES
+#undef	HAVE_ALIGNED_LONGLONGS
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   4
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  4
+#define PR_ALIGN_OF_POINTER 4
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
+#define BYTES_PER_INT 		PR_BYTES_PER_INT
+#define BYTES_PER_INT64		PR_BYTES_PER_INT64
+#define BYTES_PER_LONG		PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE	PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD		PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD		PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE		PR_BITS_PER_BYTE
+#define BITS_PER_SHORT		PR_BITS_PER_SHORT
+#define BITS_PER_INT		PR_BITS_PER_INT
+#define BITS_PER_INT64		PR_BITS_PER_INT64
+#define BITS_PER_LONG		PR_BITS_PER_LONG
+#define BITS_PER_FLOAT		PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE		PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD		PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2	PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2	PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2	PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2	PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2	PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2	PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2 	PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2	PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT		PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT		PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG		PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64		PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT		PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE		PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER	PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD		PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
diff --git a/pr/include/md/_dgux.h b/pr/include/md/_dgux.h
new file mode 100644
index 0000000..66bf931
--- /dev/null
+++ b/pr/include/md/_dgux.h
@@ -0,0 +1,188 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_dgux_defs_h___
+#define nspr_dgux_defs_h___
+
+/*
+ * Internal configuration macros
+ */
+
+#define PR_LINKER_ARCH	"dgux"
+#define _PR_SI_SYSNAME		"DGUX"
+#define _PR_SI_ARCHITECTURE	"x86"
+#define PR_DLL_SUFFIX		".so"
+
+#define _PR_VMBASE	 	0x30000000
+#define _PR_STACK_VMBASE	0x50000000
+#define _MD_DEFAULT_STACK_SIZE	65536L
+#define _MD_MMAP_FLAGS          MAP_PRIVATE
+
+#ifndef	HAVE_WEAK_IO_SYMBOLS
+#define	HAVE_WEAK_IO_SYMBOLS
+#endif
+
+#undef  HAVE_STACK_GROWING_UP
+#define HAVE_NETCONFIG
+#define	HAVE_DLL
+#define	USE_DLFCN
+#define NEED_STRFTIME_LOCK
+#define NEED_TIME_R
+#define _PR_NEED_STRCASECMP
+#define _PR_POLL_AVAILABLE
+#define _PR_USE_POLL
+#define _PR_NO_LARGE_FILES
+#define _PR_STAT_HAS_ONLY_ST_ATIME
+
+#define USE_SETJMP
+
+#include <setjmp.h>
+
+#define _SETJMP setjmp
+#define _LONGJMP longjmp
+#define _PR_CONTEXT_TYPE         jmp_buf
+#define _MD_GET_SP(_t)           (_t)->md.context[4]
+#define _PR_NUM_GCREGS	_JBLEN
+
+#define CONTEXT(_th) ((_th)->md.context)
+
+/*
+** Initialize the thread context preparing it to execute _main.
+*/
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
+{								  \
+    *status = PR_TRUE; \
+    if(_SETJMP(CONTEXT(_thread))) (*_main)(); \
+    _MD_GET_SP(_thread) = (int) ((_sp) - 128); \
+}
+
+#define _MD_SWITCH_CONTEXT(_thread)  \
+    if (!_SETJMP(CONTEXT(_thread))) { \
+	(_thread)->md.errcode = errno;  \
+	_PR_Schedule();		     \
+    }
+
+/*
+** Restore a thread context, saved by _MD_SWITCH_CONTEXT
+*/
+#define _MD_RESTORE_CONTEXT(_thread) \
+{				     \
+    errno = (_thread)->md.errcode;	     \
+    _MD_SET_CURRENT_THREAD(_thread); \
+    _LONGJMP(CONTEXT(_thread), 1);    \
+}
+
+/* Machine-dependent (MD) data structures.
+ * Don't use SVR4 native threads (yet). 
+ */
+
+struct _MDThread {
+    _PR_CONTEXT_TYPE context;
+    int id;
+    int errcode;
+};
+
+struct _MDThreadStack {
+    PRInt8 notused;
+};
+
+struct _MDLock {
+    PRInt8 notused;
+};
+
+struct _MDSemaphore {
+    PRInt8 notused;
+};
+
+struct _MDCVar {
+    PRInt8 notused;
+};
+
+struct _MDSegment {
+    PRInt8 notused;
+};
+
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+                fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+    struct pollfd *ioq_pollfds;
+    int ioq_pollfds_size;
+#endif  /* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)               ((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)       ((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)       ((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)      ((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)      ((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)  ((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)  ((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)       ((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)      ((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)      ((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)       ((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)  ((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)  32
+
+struct _MDCPU {
+    struct _MDCPU_Unix md_unix;
+};
+
+#define _MD_INIT_LOCKS()
+#define _MD_NEW_LOCK(lock) PR_SUCCESS
+#define _MD_FREE_LOCK(lock)
+#define _MD_LOCK(lock)
+#define _MD_UNLOCK(lock)
+#define _MD_INIT_IO()
+#define _MD_IOQ_LOCK()
+#define _MD_IOQ_UNLOCK()
+
+/*
+ * The following are copied from _sunos.h, _aix.h.  This means
+ * some of them should probably be moved into _unixos.h.  But
+ * _irix.h seems to be quite different in regard to these macros.
+ */
+#define _MD_INTERVAL_USE_GTOD
+
+#define _MD_EARLY_INIT		_MD_EarlyInit
+#define _MD_FINAL_INIT		_PR_UnixInit
+#define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
+#define _MD_INIT_THREAD         _MD_InitializeThread
+#define _MD_EXIT_THREAD(thread)
+#define	_MD_SUSPEND_THREAD(thread)
+#define	_MD_RESUME_THREAD(thread)
+#define _MD_CLEAN_THREAD(_thread)
+
+/*
+ * We wrapped the select() call.  _MD_SELECT refers to the built-in,
+ * unwrapped version.
+ */
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/time.h>
+extern int _select(int nfds, fd_set *readfds, fd_set *writefds,
+	fd_set *execptfds, struct timeval *timeout);
+#define _MD_SELECT _select
+
+#define _MD_POLL _poll
+#include <poll.h>
+#include <stropts.h>
+extern int _poll(struct pollfd *fds, unsigned long nfds, int timeout);
+
+#endif /* nspr_dgux_defs_h___ */
diff --git a/pr/include/md/_freebsd.cfg b/pr/include/md/_freebsd.cfg
new file mode 100644
index 0000000..1d1039a
--- /dev/null
+++ b/pr/include/md/_freebsd.cfg
@@ -0,0 +1,594 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef XP_UNIX
+#define XP_UNIX
+#endif
+
+#ifndef FREEBSD
+#define FREEBSD
+#endif
+
+#define PR_AF_INET6 28  /* same as AF_INET6 */
+
+#ifndef HAVE_LONG_LONG
+#define HAVE_LONG_LONG
+#endif
+
+#if defined(__i386__)
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#undef	HAVE_ALIGNED_DOUBLES
+#undef	HAVE_ALIGNED_LONGLONGS
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   4
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  4
+#define PR_ALIGN_OF_POINTER 4
+
+#elif defined(__alpha__)
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#define	HAVE_ALIGNED_DOUBLES
+#define	HAVE_ALIGNED_LONGLONGS
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+#define PR_BYTES_PER_WORD_LOG2   3
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+
+#elif defined(__sparc__)
+
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN 1
+#define	HAVE_ALIGNED_DOUBLES
+#define	HAVE_ALIGNED_LONGLONGS
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+#define PR_BYTES_PER_WORD_LOG2   3
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+
+#elif defined(__ia64__)
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#define	HAVE_ALIGNED_DOUBLES
+#define	HAVE_ALIGNED_LONGLONGS
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+#define PR_BYTES_PER_WORD_LOG2   3
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+#define PR_ALIGN_OF_WORD    8
+
+#elif defined(__amd64__)
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#define	HAVE_ALIGNED_DOUBLES
+#define	HAVE_ALIGNED_LONGLONGS
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+#define PR_BYTES_PER_WORD_LOG2   3
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+#define PR_ALIGN_OF_WORD    8
+
+#elif defined(__powerpc64__)
+
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN    1
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+#define PR_ALIGN_OF_WORD    8
+
+#define PR_BYTES_PER_WORD_LOG2   3
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#elif defined(__powerpc__)
+
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN    1
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 4
+#define PR_ALIGN_OF_WORD    4
+
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#elif defined(__aarch64__)
+
+#undef  IS_BIG_ENDIAN
+#define IS_LITTLE_ENDIAN 1
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+#define PR_ALIGN_OF_WORD    8
+
+#define PR_BYTES_PER_WORD_LOG2  3
+#define PR_BYTES_PER_DWORD_LOG2 3
+
+#elif defined(__arm__)
+
+#if defined(__ARMEB__) || defined(__ARM_BIG_ENDIAN__)
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN    1
+#else
+#undef  IS_BIG_ENDIAN
+#define IS_LITTLE_ENDIAN 1
+#endif
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 4
+#define PR_ALIGN_OF_WORD    4
+
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#elif defined(__mips64__)
+
+#if defined(__MIPSEB__) || defined(_MIPSEB)
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN    1
+#else
+#undef  IS_BIG_ENDIAN
+#define IS_LITTLE_ENDIAN 1
+#endif
+
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+#define PR_ALIGN_OF_WORD    8
+
+#define PR_BYTES_PER_WORD_LOG2   3
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#elif defined(__mips__)
+
+#if defined(__MIPSEB__) || defined(_MIPSEB)
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN    1
+#else
+#undef  IS_BIG_ENDIAN
+#define IS_LITTLE_ENDIAN 1
+#endif
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 4
+#define PR_ALIGN_OF_WORD    4
+
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#else
+
+#error "Unknown CPU architecture"
+
+#endif
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
+#define BYTES_PER_INT 		PR_BYTES_PER_INT
+#define BYTES_PER_INT64		PR_BYTES_PER_INT64
+#define BYTES_PER_LONG		PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE	PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD		PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD		PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE		PR_BITS_PER_BYTE
+#define BITS_PER_SHORT		PR_BITS_PER_SHORT
+#define BITS_PER_INT		PR_BITS_PER_INT
+#define BITS_PER_INT64		PR_BITS_PER_INT64
+#define BITS_PER_LONG		PR_BITS_PER_LONG
+#define BITS_PER_FLOAT		PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE		PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD		PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2	PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2	PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2	PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2	PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2	PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2	PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2 	PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2	PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT		PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT		PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG		PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64		PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT		PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE		PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER	PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD		PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
diff --git a/pr/include/md/_freebsd.h b/pr/include/md/_freebsd.h
new file mode 100644
index 0000000..9a179bc
--- /dev/null
+++ b/pr/include/md/_freebsd.h
@@ -0,0 +1,255 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_freebsd_defs_h___
+#define nspr_freebsd_defs_h___
+
+#include "prthread.h"
+
+#if __FreeBSD__ >= 2
+#include <osreldate.h>  /* for __FreeBSD_version */
+#endif
+#include <sys/syscall.h>
+
+#define PR_LINKER_ARCH	"freebsd"
+#define _PR_SI_SYSNAME  "FREEBSD"
+#if defined(__i386__)
+#define _PR_SI_ARCHITECTURE "x86"
+#elif defined(__alpha__)
+#define _PR_SI_ARCHITECTURE "alpha"
+#elif defined(__sparc__)
+#define _PR_SI_ARCHITECTURE "sparc"
+#elif defined(__ia64__)
+#define _PR_SI_ARCHITECTURE "ia64"
+#elif defined(__amd64__)
+#define _PR_SI_ARCHITECTURE "amd64"
+#elif defined(__powerpc64__)
+#define _PR_SI_ARCHITECTURE "powerpc64"
+#elif defined(__powerpc__)
+#define _PR_SI_ARCHITECTURE "powerpc"
+#elif defined(__aarch64__)
+#define _PR_SI_ARCHITECTURE "aarch64"
+#elif defined(__arm__)
+#define _PR_SI_ARCHITECTURE "arm"
+#elif defined(__mips64__)
+#define _PR_SI_ARCHITECTURE "mips64"
+#elif defined(__mips__)
+#define _PR_SI_ARCHITECTURE "mips"
+#else
+#error "Unknown CPU architecture"
+#endif
+#if defined(__ELF__)
+#define PR_DLL_SUFFIX          ".so"
+#else
+#define PR_DLL_SUFFIX          ".so.1.0"
+#endif
+
+#define _PR_VMBASE              0x30000000
+#define _PR_STACK_VMBASE	0x50000000
+#define _MD_DEFAULT_STACK_SIZE	65536L
+#define _MD_MMAP_FLAGS          MAP_PRIVATE
+
+#undef  HAVE_STACK_GROWING_UP
+#define HAVE_DLL
+#define USE_DLFCN
+#define _PR_HAVE_SOCKADDR_LEN
+#define _PR_STAT_HAS_ST_ATIMESPEC
+#define _PR_HAVE_LARGE_OFF_T
+
+#if defined(_PR_PTHREADS)
+#if __FreeBSD_version >= 400008
+/*
+ * libc_r before this version of FreeBSD doesn't have poll().
+ * Although libc has poll(), it is not thread-safe so we can't
+ * use it in the pthreads version.
+ */
+#define _PR_POLL_AVAILABLE
+#endif
+#else
+#if __FreeBSD_version >= 300000
+#define _PR_POLL_AVAILABLE
+#define _PR_USE_POLL
+#endif
+#endif
+
+#define _PR_HAVE_SYSV_SEMAPHORES
+#define PR_HAVE_SYSV_NAMED_SHARED_MEMORY
+
+#if __FreeBSD_version >= 400014
+#define _PR_INET6
+#define _PR_HAVE_INET_NTOP
+#define _PR_HAVE_GETHOSTBYNAME2
+#define _PR_HAVE_GETADDRINFO
+#define _PR_INET6_PROBE
+#define _PR_IPV6_V6ONLY_PROBE
+#endif
+
+#define USE_SETJMP
+
+#ifndef _PR_PTHREADS
+#include <setjmp.h>
+
+#define PR_CONTEXT_TYPE	sigjmp_buf
+
+#define CONTEXT(_th) ((_th)->md.context)
+
+#define _MD_GET_SP(_th)    (_th)->md.context[0]._sjb[2]
+#define PR_NUM_GCREGS	_JBLEN
+
+/*
+** Initialize a thread context to run "_main()" when started
+*/
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
+{  \
+    *status = PR_TRUE;  \
+    if (sigsetjmp(CONTEXT(_thread), 1)) {  \
+        _main();  \
+    }  \
+    _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 64); \
+}
+
+#define _MD_SWITCH_CONTEXT(_thread)  \
+    if (!sigsetjmp(CONTEXT(_thread), 1)) {  \
+	(_thread)->md.errcode = errno;  \
+	_PR_Schedule();  \
+    }
+
+/*
+** Restore a thread context, saved by _MD_SWITCH_CONTEXT
+*/
+#define _MD_RESTORE_CONTEXT(_thread) \
+{   \
+    errno = (_thread)->md.errcode;  \
+    _MD_SET_CURRENT_THREAD(_thread);  \
+    siglongjmp(CONTEXT(_thread), 1);  \
+}
+
+/* Machine-dependent (MD) data structures */
+
+struct _MDThread {
+    PR_CONTEXT_TYPE context;
+    int id;
+    int errcode;
+};
+
+struct _MDThreadStack {
+    PRInt8 notused;
+};
+
+struct _MDLock {
+    PRInt8 notused;
+};
+
+struct _MDSemaphore {
+    PRInt8 notused;
+};
+
+struct _MDCVar {
+    PRInt8 notused;
+};
+
+struct _MDSegment {
+    PRInt8 notused;
+};
+
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
+struct _MDCPU {
+	struct _MDCPU_Unix md_unix;
+};
+
+#define _MD_INIT_LOCKS()
+#define _MD_NEW_LOCK(lock) PR_SUCCESS
+#define _MD_FREE_LOCK(lock)
+#define _MD_LOCK(lock)
+#define _MD_UNLOCK(lock)
+#define _MD_INIT_IO()
+#define _MD_IOQ_LOCK()
+#define _MD_IOQ_UNLOCK()
+
+extern PRStatus _MD_InitializeThread(PRThread *thread);
+
+#define _MD_INIT_RUNNING_CPU(cpu)       _MD_unix_init_running_cpu(cpu)
+#define _MD_INIT_THREAD                 _MD_InitializeThread
+#define _MD_EXIT_THREAD(thread)
+#define _MD_SUSPEND_THREAD(thread)      _MD_suspend_thread
+#define _MD_RESUME_THREAD(thread)       _MD_resume_thread
+#define _MD_CLEAN_THREAD(_thread)
+
+extern PRStatus _MD_CREATE_THREAD(
+    PRThread *thread,
+    void (*start) (void *),
+    PRThreadPriority priority,
+    PRThreadScope scope,
+    PRThreadState state,
+    PRUint32 stackSize);
+extern void _MD_SET_PRIORITY(struct _MDThread *thread, PRUintn newPri);
+extern PRStatus _MD_WAIT(PRThread *, PRIntervalTime timeout);
+extern PRStatus _MD_WAKEUP_WAITER(PRThread *);
+extern void _MD_YIELD(void);
+
+#endif /* ! _PR_PTHREADS */
+
+extern void _MD_EarlyInit(void);
+
+#define _MD_EARLY_INIT                  _MD_EarlyInit
+#define _MD_FINAL_INIT			_PR_UnixInit
+#define _PR_HAVE_CLOCK_MONOTONIC
+
+/*
+ * We wrapped the select() call.  _MD_SELECT refers to the built-in,
+ * unwrapped version.
+ */
+#define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
+
+#if defined(_PR_POLL_AVAILABLE)
+#include <poll.h>
+#define _MD_POLL(fds,nfds,timeout) syscall(SYS_poll,fds,nfds,timeout)
+#endif
+
+/* freebsd has INADDR_LOOPBACK defined, but in /usr/include/rpc/types.h, and I didn't
+   want to be including that.. */
+#ifndef INADDR_LOOPBACK
+#define INADDR_LOOPBACK         (u_long)0x7F000001
+#endif
+
+/* For writev() */
+#include <sys/uio.h>
+
+#endif /* nspr_freebsd_defs_h___ */
diff --git a/pr/include/md/_hpux.h b/pr/include/md/_hpux.h
new file mode 100644
index 0000000..ff5243d
--- /dev/null
+++ b/pr/include/md/_hpux.h
@@ -0,0 +1,288 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_xhppa_defs_h___
+#define nspr_xhppa_defs_h___
+
+/*
+ * Internal configuration macros
+ */
+
+#define PR_LINKER_ARCH    "hpux"
+#define _PR_SI_SYSNAME   "HPUX"
+#ifdef __ia64
+#define _PR_SI_ARCHITECTURE "ia64"
+#define PR_DLL_SUFFIX        ".so"
+#else
+/*
+ * _PR_SI_ARCHITECTURE must be "hppa1.1" for backward compatibility.
+ * It was changed to "hppa" in NSPR 4.6.2, but was changed back in
+ * NSPR 4.6.4.
+ */
+#define _PR_SI_ARCHITECTURE "hppa1.1"
+#define PR_DLL_SUFFIX        ".sl"
+#endif
+
+#define _PR_VMBASE        0x30000000 
+#define _PR_STACK_VMBASE    0x50000000
+/*
+ * _USE_BIG_FDS increases the size of fd_set from 256 bytes to
+ * about 7500 bytes.  PR_Poll allocates three fd_sets on the
+ * stack, so it is safer to also increase the default thread
+ * stack size.
+ */
+#define _MD_DEFAULT_STACK_SIZE    (2*65536L)
+#define _MD_MINIMUM_STACK_SIZE    (2*65536L)
+#define _MD_MMAP_FLAGS          MAP_PRIVATE
+
+#define NEED_TIME_R
+
+#define HAVE_STACK_GROWING_UP
+#undef	HAVE_WEAK_IO_SYMBOLS
+#undef	HAVE_WEAK_MALLOC_SYMBOLS
+#define	HAVE_DLL
+#ifdef IS_64
+#define USE_DLFCN
+#else
+#define USE_HPSHL
+#endif
+#ifndef HAVE_STRERROR
+#define HAVE_STRERROR
+#endif
+#define _PR_POLL_AVAILABLE
+#define _PR_USE_POLL
+#define _PR_STAT_HAS_ONLY_ST_ATIME
+#define _PR_HAVE_POSIX_SEMAPHORES
+#define PR_HAVE_POSIX_NAMED_SHARED_MEMORY
+#define _PR_ACCEPT_INHERIT_NONBLOCK
+
+#if defined(__ia64)
+#define _PR_HAVE_ATOMIC_OPS
+#define _MD_INIT_ATOMIC()
+extern PRInt32 _PR_ia64_AtomicIncrement(PRInt32 *val);
+#define _MD_ATOMIC_INCREMENT          _PR_ia64_AtomicIncrement
+extern PRInt32 _PR_ia64_AtomicDecrement(PRInt32 *val);
+#define _MD_ATOMIC_DECREMENT          _PR_ia64_AtomicDecrement
+extern PRInt32 _PR_ia64_AtomicAdd(PRInt32 *ptr, PRInt32 val);
+#define _MD_ATOMIC_ADD                _PR_ia64_AtomicAdd
+extern PRInt32 _PR_ia64_AtomicSet(PRInt32 *val, PRInt32 newval);
+#define _MD_ATOMIC_SET                _PR_ia64_AtomicSet
+#endif
+
+#define _PR_HAVE_GETIPNODEBYNAME
+#define _PR_HAVE_GETIPNODEBYADDR
+#define _PR_HAVE_GETADDRINFO
+#ifdef _PR_INET6
+#define _PR_HAVE_INET_NTOP
+#else
+#define _PR_INET6_PROBE
+
+/* for HP-UX 11.11 without IPv6 */
+#ifndef AF_INET6
+#define AF_INET6       22
+#define AI_CANONNAME   2
+#define AI_NUMERICHOST 4
+#define AI_NUMERICSERV 8
+#define AI_V4MAPPED    0x00000010
+#define AI_ADDRCONFIG  0x00000040
+#define AI_ALL         0x00000020
+#define AI_DEFAULT     (AI_V4MAPPED|AI_ADDRCONFIG)
+#define NI_NUMERICHOST 2
+struct addrinfo {
+    int        ai_flags;    /* AI_PASSIVE, AI_CANONNAME */
+    int        ai_family;   /* PF_xxx */
+    int        ai_socktype; /* SOCK_xxx */
+    int        ai_protocol; /* IPPROTO_xxx for IPv4 and IPv6 */
+    socklen_t  ai_addrlen;  /* length of ai_addr */
+    char            *ai_canonname;    /* canonical name for host */
+    struct sockaddr *ai_addr;     /* binary address */
+    struct addrinfo *ai_next;     /* next structure in linked list */
+};
+#endif    /* for HP-UX 11.11 without IPv6 */
+
+#define _PR_HAVE_MD_SOCKADDR_IN6
+/* isomorphic to struct in6_addr on HP-UX B.11.23 */
+struct _md_in6_addr {
+    union {
+        PRUint8   _S6_u8[16];
+        PRUint16  _S6_u16[8];
+        PRUint32  _S6_u32[4];
+        PRUint32  __S6_align;
+    } _s6_un;
+};
+/* isomorphic to struct sockaddr_in6 on HP-UX B.11.23 */
+struct _md_sockaddr_in6 {
+    PRUint16 sin6_family;
+    PRUint16 sin6_port;
+    PRUint32 sin6_flowinfo;
+    struct _md_in6_addr sin6_addr;
+    PRUint32 sin6_scope_id;
+};
+#endif
+
+#if !defined(_PR_PTHREADS)
+
+#include <syscall.h>
+#include <setjmp.h>
+
+#define USE_SETJMP
+
+#define _MD_GET_SP(_t) (*((int *)((_t)->md.jb) + 1))
+#define PR_NUM_GCREGS _JBLEN
+/* Caveat: This makes jmp_buf full of doubles. */
+#define CONTEXT(_th) ((_th)->md.jb)
+
+    /* Stack needs two frames (64 bytes) at the bottom */ \
+#define _MD_SET_THR_SP(_t, _sp)     ((_MD_GET_SP(_t)) = (int) (_sp + 64 *2))
+#define SAVE_CONTEXT(_th)           _setjmp(CONTEXT(_th))
+#define GOTO_CONTEXT(_th)           _longjmp(CONTEXT(_th), 1)
+
+#if !defined(PTHREADS_USER)
+
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
+{ \
+    *(status) = PR_TRUE; \
+    if (_setjmp(CONTEXT(_thread))) (*_main)(); \
+    /* Stack needs two frames (64 bytes) at the bottom */ \
+    (_MD_GET_SP(_thread)) = (int) ((_sp) + 64*2); \
+}
+
+#define _MD_SWITCH_CONTEXT(_thread) \
+    if (!_setjmp(CONTEXT(_thread))) { \
+    (_thread)->md.errcode = errno; \
+    _PR_Schedule(); \
+    }
+
+/*
+** Restore a thread context, saved by _MD_SWITCH_CONTEXT
+*/
+#define _MD_RESTORE_CONTEXT(_thread) \
+{ \
+    errno = (_thread)->md.errcode; \
+    _MD_SET_CURRENT_THREAD(_thread); \
+    _longjmp(CONTEXT(_thread), 1); \
+}
+
+/* Machine-dependent (MD) data structures.  HP-UX has no native threads. */
+
+struct _MDThread {
+    jmp_buf jb;
+    int id;
+    int errcode;
+};
+
+struct _MDThreadStack {
+    PRInt8 notused;
+};
+
+struct _MDLock {
+    PRInt8 notused;
+};
+
+struct _MDSemaphore {
+    PRInt8 notused;
+};
+
+struct _MDCVar {
+    PRInt8 notused;
+};
+
+struct _MDSegment {
+    PRInt8 notused;
+};
+
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
+struct _MDCPU {
+    struct _MDCPU_Unix md_unix;
+};
+
+#define _MD_INIT_LOCKS()
+#define _MD_NEW_LOCK(lock) PR_SUCCESS
+#define _MD_FREE_LOCK(lock)
+#define _MD_LOCK(lock)
+#define _MD_UNLOCK(lock)
+#define _MD_INIT_IO()
+#define _MD_IOQ_LOCK()
+#define _MD_IOQ_UNLOCK()
+
+#define _MD_INIT_RUNNING_CPU(cpu)       _MD_unix_init_running_cpu(cpu)
+#define _MD_INIT_THREAD                 _MD_InitializeThread
+#define _MD_EXIT_THREAD(thread)
+#define _MD_SUSPEND_THREAD(thread)      _MD_suspend_thread
+#define _MD_RESUME_THREAD(thread)       _MD_resume_thread
+#define _MD_CLEAN_THREAD(_thread)
+
+#else /* PTHREADS_USER	*/
+
+#include "_nspr_pthread.h"
+
+#endif /* PTHREADS_USER	*/
+
+#endif  /* !defined(_PR_PTHREADS) */
+
+#if !defined(PTHREADS_USER)
+#define _MD_EARLY_INIT                 	_MD_EarlyInit
+#define _MD_FINAL_INIT					_PR_UnixInit
+#endif 
+
+#if defined(HPUX_LW_TIMER)
+extern void _PR_HPUX_LW_IntervalInit(void);
+extern PRIntervalTime _PR_HPUX_LW_GetInterval(void);
+#define _MD_INTERVAL_INIT                 _PR_HPUX_LW_IntervalInit
+#define _MD_GET_INTERVAL                  _PR_HPUX_LW_GetInterval
+#define _MD_INTERVAL_PER_SEC()            1000
+#else
+#define _MD_INTERVAL_USE_GTOD
+#endif
+
+/*
+ * We wrapped the select() call.  _MD_SELECT refers to the built-in,
+ * unwrapped version.
+ */
+#define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
+
+#include <poll.h>
+#define _MD_POLL(fds,nfds,timeout) syscall(SYS_poll,fds,nfds,timeout)
+
+#ifdef HPUX11
+extern void _MD_hpux_map_sendfile_error(int err);
+#endif /* HPUX11 */
+
+#endif /* nspr_xhppa_defs_h___ */
diff --git a/pr/include/md/_hpux32.cfg b/pr/include/md/_hpux32.cfg
new file mode 100644
index 0000000..08950cb
--- /dev/null
+++ b/pr/include/md/_hpux32.cfg
@@ -0,0 +1,112 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef XP_UNIX
+#define XP_UNIX
+#endif
+
+#ifndef HPUX
+#define HPUX
+#endif
+
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN 1
+
+#define PR_AF_INET6 22  /* same as AF_INET6 */
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BYTES_PER_WORD_LOG2 2
+#define PR_BYTES_PER_DWORD_LOG2 3
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   4
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 4
+
+#ifndef HAVE_LONG_LONG
+#define	HAVE_LONG_LONG
+#endif
+#define	HAVE_ALIGNED_DOUBLES
+#define	HAVE_ALIGNED_LONGLONGS
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
+#define BYTES_PER_INT 		PR_BYTES_PER_INT
+#define BYTES_PER_INT64		PR_BYTES_PER_INT64
+#define BYTES_PER_LONG		PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE	PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD		PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD		PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE		PR_BITS_PER_BYTE
+#define BITS_PER_SHORT		PR_BITS_PER_SHORT
+#define BITS_PER_INT		PR_BITS_PER_INT
+#define BITS_PER_INT64		PR_BITS_PER_INT64
+#define BITS_PER_LONG		PR_BITS_PER_LONG
+#define BITS_PER_FLOAT		PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE		PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD		PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2	PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2	PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2	PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2	PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2	PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2	PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2 	PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2	PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT		PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT		PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG		PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64		PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT		PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE		PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER	PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD		PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
diff --git a/pr/include/md/_hpux64.cfg b/pr/include/md/_hpux64.cfg
new file mode 100644
index 0000000..028a034
--- /dev/null
+++ b/pr/include/md/_hpux64.cfg
@@ -0,0 +1,113 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef XP_UNIX
+#define XP_UNIX
+#endif
+
+#ifndef HPUX
+#define HPUX
+#endif
+
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN 1
+#define IS_64
+
+#define PR_AF_INET6 22  /* same as AF_INET6 */
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BYTES_PER_WORD_LOG2 3
+#define PR_BYTES_PER_DWORD_LOG2 3
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+
+#ifndef HAVE_LONG_LONG
+#define	HAVE_LONG_LONG
+#endif
+#define	HAVE_ALIGNED_DOUBLES
+#define	HAVE_ALIGNED_LONGLONGS
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
+#define BYTES_PER_INT 		PR_BYTES_PER_INT
+#define BYTES_PER_INT64		PR_BYTES_PER_INT64
+#define BYTES_PER_LONG		PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE	PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD		PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD		PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE		PR_BITS_PER_BYTE
+#define BITS_PER_SHORT		PR_BITS_PER_SHORT
+#define BITS_PER_INT		PR_BITS_PER_INT
+#define BITS_PER_INT64		PR_BITS_PER_INT64
+#define BITS_PER_LONG		PR_BITS_PER_LONG
+#define BITS_PER_FLOAT		PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE		PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD		PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2	PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2	PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2	PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2	PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2	PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2	PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2 	PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2	PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT		PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT		PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG		PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64		PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT		PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE		PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER	PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD		PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
diff --git a/pr/include/md/_irix.h b/pr/include/md/_irix.h
new file mode 100644
index 0000000..04413b9
--- /dev/null
+++ b/pr/include/md/_irix.h
@@ -0,0 +1,438 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_irix_defs_h___
+#define nspr_irix_defs_h___
+
+#define _PR_HAVE_ATOMIC_CAS
+
+/*
+ * MipsPro assembler defines _LANGUAGE_ASSEMBLY
+ */
+#ifndef _LANGUAGE_ASSEMBLY
+
+#include "prclist.h"
+#include "prthread.h"
+#include <sys/ucontext.h>
+
+/*
+ * Internal configuration macros
+ */
+
+#define PR_LINKER_ARCH          "irix"
+#define _PR_SI_SYSNAME          "IRIX"
+#define _PR_SI_ARCHITECTURE     "mips"
+#define PR_DLL_SUFFIX		".so"
+
+#define _PR_VMBASE              0x30000000
+#define _PR_STACK_VMBASE        0x50000000
+#define _PR_NUM_GCREGS          9
+#define _MD_MMAP_FLAGS          MAP_PRIVATE
+
+#define _MD_DEFAULT_STACK_SIZE  65536L
+#define _MD_MIN_STACK_SIZE      16384L
+
+#undef  HAVE_STACK_GROWING_UP
+#define HAVE_WEAK_IO_SYMBOLS
+#define HAVE_WEAK_MALLOC_SYMBOLS
+#define HAVE_DLL
+#define USE_DLFCN
+#define _PR_HAVE_ATOMIC_OPS
+#define _PR_POLL_AVAILABLE
+#define _PR_USE_POLL
+#define _PR_STAT_HAS_ST_ATIM
+#define _PR_HAVE_OFF64_T
+#define HAVE_POINTER_LOCALTIME_R
+#define _PR_HAVE_POSIX_SEMAPHORES
+#define PR_HAVE_POSIX_NAMED_SHARED_MEMORY
+#define _PR_ACCEPT_INHERIT_NONBLOCK
+
+#ifdef _PR_INET6
+#define _PR_HAVE_INET_NTOP
+#define _PR_HAVE_GETIPNODEBYNAME
+#define _PR_HAVE_GETIPNODEBYADDR
+#define _PR_HAVE_GETADDRINFO
+#endif
+
+/* Initialization entry points */
+NSPR_API(void) _MD_EarlyInit(void);
+#define _MD_EARLY_INIT _MD_EarlyInit
+
+NSPR_API(void) _MD_IrixInit(void);
+#define _MD_FINAL_INIT _MD_IrixInit
+
+#define _MD_INIT_IO()
+
+/* Timer operations */
+NSPR_API(PRIntervalTime) _MD_IrixGetInterval(void);
+#define _MD_GET_INTERVAL _MD_IrixGetInterval
+
+NSPR_API(PRIntervalTime) _MD_IrixIntervalPerSec(void);
+#define _MD_INTERVAL_PER_SEC _MD_IrixIntervalPerSec
+
+/* GC operations */
+NSPR_API(void *) _MD_GetSP(PRThread *thread);
+#define    _MD_GET_SP _MD_GetSP
+
+/* The atomic operations */
+#include <mutex.h>
+#define _MD_INIT_ATOMIC()
+#define _MD_ATOMIC_INCREMENT(val) add_then_test((unsigned long*)val, 1)
+#define _MD_ATOMIC_ADD(ptr, val) add_then_test((unsigned long*)ptr, (unsigned long)val)
+#define _MD_ATOMIC_DECREMENT(val) add_then_test((unsigned long*)val, 0xffffffff)
+#define _MD_ATOMIC_SET(val, newval) test_and_set((unsigned long*)val, newval)
+
+#if defined(_PR_PTHREADS)
+#else /* defined(_PR_PTHREADS) */
+
+/************************************************************************/
+
+#include <setjmp.h>
+#include <errno.h>
+#include <unistd.h>
+#include <bstring.h>
+#include <sys/time.h>
+#include <ulocks.h>
+#include <sys/prctl.h>
+
+
+/*
+ * Data region private to each sproc. This region is setup by calling
+ * mmap(...,MAP_LOCAL,...). The private data is mapped at the same
+ * address in every sproc, but every sproc gets a private mapping.
+ *
+ * Just make sure that this structure fits in a page, as only one page
+ * is allocated for the private region.
+ */
+struct sproc_private_data {
+    struct PRThread *me;
+    struct _PRCPU *cpu;
+    struct PRThread *last;
+    PRUintn intsOff;
+	int		sproc_pid;
+};
+
+extern char *_nspr_sproc_private;
+
+#define _PR_PRDA() ((struct sproc_private_data *) _nspr_sproc_private)
+#define _MD_SET_CURRENT_THREAD(_thread) _PR_PRDA()->me = (_thread)
+#define _MD_THIS_THREAD() (_PR_PRDA()->me)
+#define _MD_LAST_THREAD() (_PR_PRDA()->last)
+#define _MD_SET_LAST_THREAD(_thread) _PR_PRDA()->last = (_thread)
+#define _MD_CURRENT_CPU() (_PR_PRDA()->cpu)
+#define _MD_SET_CURRENT_CPU(_cpu) _PR_PRDA()->cpu = (_cpu)
+#define _MD_SET_INTSOFF(_val) (_PR_PRDA()->intsOff = _val)
+#define _MD_GET_INTSOFF() (_PR_PRDA()->intsOff)
+
+#define _MD_SET_SPROC_PID(_val) (_PR_PRDA()->sproc_pid = _val)
+#define _MD_GET_SPROC_PID() (_PR_PRDA()->sproc_pid)
+
+NSPR_API(struct PRThread*) _MD_get_attached_thread(void);
+NSPR_API(struct PRThread*) _MD_get_current_thread(void);
+#define _MD_GET_ATTACHED_THREAD()	_MD_get_attached_thread()
+#define _MD_CURRENT_THREAD()	_MD_get_current_thread()
+
+#define _MD_CHECK_FOR_EXIT() {					\
+		if (_pr_irix_exit_now) {				\
+			_PR_POST_SEM(_pr_irix_exit_sem);	\
+			_MD_Wakeup_CPUs();					\
+			_exit(0);							\
+		}										\
+	}
+		
+#define _MD_ATTACH_THREAD(threadp)
+
+#define _MD_SAVE_ERRNO(_thread)			(_thread)->md.errcode = errno;
+#define _MD_RESTORE_ERRNO(_thread)		errno = (_thread)->md.errcode;
+
+extern struct _PRCPU  *_pr_primordialCPU;
+extern usema_t *_pr_irix_exit_sem;
+extern PRInt32 _pr_irix_exit_now;
+extern int _pr_irix_primoridal_cpu_fd[];
+extern PRInt32 _pr_irix_process_exit;
+extern PRInt32 _pr_irix_process_exit_code;
+
+/* Thread operations */
+#define _PR_LOCK_HEAP()	{						\
+			PRIntn _is;					\
+				if (_pr_primordialCPU) {		\
+				if (_MD_GET_ATTACHED_THREAD() && 		\
+					!_PR_IS_NATIVE_THREAD( 		\
+					_MD_GET_ATTACHED_THREAD()))	\
+						_PR_INTSOFF(_is); 	\
+					_PR_LOCK(_pr_heapLock);		\
+				}
+
+#define _PR_UNLOCK_HEAP() 	if (_pr_primordialCPU)	{		\
+					_PR_UNLOCK(_pr_heapLock);	\
+				if (_MD_GET_ATTACHED_THREAD() && 		\
+					!_PR_IS_NATIVE_THREAD( 		\
+					_MD_GET_ATTACHED_THREAD()))	\
+						_PR_INTSON(_is);	\
+				}					\
+			  }
+
+#define _PR_OPEN_POLL_SEM(_sem)  usopenpollsema(_sem, 0666)
+#define _PR_WAIT_SEM(_sem) uspsema(_sem)
+#define _PR_POST_SEM(_sem) usvsema(_sem)
+
+#define _MD_CVAR_POST_SEM(threadp)	usvsema((threadp)->md.cvar_pollsem)
+
+#define _MD_IOQ_LOCK()
+#define _MD_IOQ_UNLOCK()
+
+struct _MDLock {
+    ulock_t lock;
+	usptr_t *arena;
+};
+
+/*
+ * disable pre-emption for the LOCAL threads when calling the arena lock
+ * routines
+ */
+
+#define _PR_LOCK(lock) {						\
+		PRIntn _is;						\
+		PRThread *me = _MD_GET_ATTACHED_THREAD();			\
+		if (me && !_PR_IS_NATIVE_THREAD(me))			\
+			_PR_INTSOFF(_is); 				\
+		ussetlock(lock);					\
+		if (me && !_PR_IS_NATIVE_THREAD(me))			\
+			_PR_FAST_INTSON(_is); 				\
+	}
+
+#define _PR_UNLOCK(lock) {						\
+		PRIntn _is;						\
+		PRThread *me = _MD_GET_ATTACHED_THREAD();			\
+		if (me && !_PR_IS_NATIVE_THREAD(me))			\
+			_PR_INTSOFF(_is); 				\
+		usunsetlock(lock);					\
+		if (me && !_PR_IS_NATIVE_THREAD(me))			\
+			_PR_FAST_INTSON(_is); 				\
+	}
+
+NSPR_API(PRStatus) _MD_NEW_LOCK(struct _MDLock *md);
+NSPR_API(void) _MD_FREE_LOCK(struct _MDLock *lockp);
+
+#define _MD_LOCK(_lockp) _PR_LOCK((_lockp)->lock)
+#define _MD_UNLOCK(_lockp) _PR_UNLOCK((_lockp)->lock)
+#define _MD_TEST_AND_LOCK(_lockp) (uscsetlock((_lockp)->lock, 1) == 0)
+
+extern ulock_t _pr_heapLock;
+
+struct _MDThread {
+    jmp_buf jb;
+    usptr_t     *pollsem_arena;
+    usema_t     *cvar_pollsem;
+    PRInt32     cvar_pollsemfd;
+    PRInt32     cvar_pollsem_select;    /* acquire sem by calling select */
+    PRInt32     cvar_wait;              /* if 1, thread is waiting on cvar Q */
+    PRInt32	id;
+    PRInt32	suspending_id;
+    int errcode;
+};
+
+struct _MDThreadStack {
+    PRInt8 notused;
+};
+
+struct _MDSemaphore {
+    usema_t *sem;
+};
+
+struct _MDCVar {
+    ulock_t mdcvar_lock;
+};
+
+struct _MDSegment {
+    PRInt8 notused;
+};
+
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
+
+struct _MDCPU {
+    PRInt32 id;
+    PRInt32 suspending_id;
+    struct _MDCPU_Unix md_unix;
+};
+
+/*
+** Initialize the thread context preparing it to execute _main.
+*/
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)	      \
+    PR_BEGIN_MACRO				      \
+	int *jb = (_thread)->md.jb;		      \
+    *status = PR_TRUE;              \
+	(void) setjmp(jb);			      \
+	(_thread)->md.jb[JB_SP] = (int) ((_sp) - 64); \
+	(_thread)->md.jb[JB_PC] = (int) _main;	      \
+	_thread->no_sched = 0; \
+    PR_END_MACRO
+
+/*
+** Switch away from the current thread context by saving its state and
+** calling the thread scheduler. Reload cpu when we come back from the
+** context switch because it might have changed.
+*
+*  XXX RUNQ lock needed before clearing _PR_NO_SCHED flag, because the
+*      thread may be unr RUNQ?
+*/
+#define _MD_SWITCH_CONTEXT(_thread) \
+    PR_BEGIN_MACRO    \
+    PR_ASSERT(_thread->no_sched); \
+    if (!setjmp(_thread->md.jb)) { \
+        _MD_SAVE_ERRNO(_thread) \
+        _MD_SET_LAST_THREAD(_thread); \
+        _PR_Schedule(); \
+    } else {      \
+        PR_ASSERT(_MD_LAST_THREAD() !=_MD_CURRENT_THREAD()); \
+            _MD_LAST_THREAD()->no_sched = 0;			\
+    }             \
+    PR_END_MACRO
+
+/*
+** Restore a thread context that was saved by _MD_SWITCH_CONTEXT or
+** initialized by _MD_INIT_CONTEXT.
+*/
+#define _MD_RESTORE_CONTEXT(_newThread) \
+    PR_BEGIN_MACRO \
+    int *jb = (_newThread)->md.jb; \
+    _MD_RESTORE_ERRNO(_newThread) \
+    _MD_SET_CURRENT_THREAD(_newThread); \
+    _newThread->no_sched = 1;		\
+    longjmp(jb, 1); \
+    PR_END_MACRO
+
+NSPR_API(PRStatus) _MD_InitThread(struct PRThread *thread,
+								PRBool wakeup_parent);
+NSPR_API(PRStatus) _MD_InitAttachedThread(struct PRThread *thread,
+									PRBool wakeup_parent);
+#define _MD_INIT_THREAD(thread) 			_MD_InitThread(thread, PR_TRUE)
+#define _MD_INIT_ATTACHED_THREAD(thread)		\
+						_MD_InitAttachedThread(thread, PR_FALSE)
+
+NSPR_API(void) _MD_ExitThread(struct PRThread *thread);
+#define _MD_EXIT_THREAD _MD_ExitThread
+
+NSPR_API(void) _MD_SuspendThread(struct PRThread *thread);
+#define _MD_SUSPEND_THREAD _MD_SuspendThread
+
+NSPR_API(void) _MD_ResumeThread(struct PRThread *thread);
+#define _MD_RESUME_THREAD _MD_ResumeThread
+
+NSPR_API(void) _MD_SuspendCPU(struct _PRCPU *thread);
+#define _MD_SUSPEND_CPU _MD_SuspendCPU
+
+NSPR_API(void) _MD_ResumeCPU(struct _PRCPU *thread);
+#define _MD_RESUME_CPU _MD_ResumeCPU
+
+#define _MD_BEGIN_SUSPEND_ALL()
+#define _MD_END_SUSPEND_ALL()
+#define _MD_BEGIN_RESUME_ALL()
+#define _MD_END_RESUME_ALL()
+
+NSPR_API(void) _MD_InitLocks(void);
+#define _MD_INIT_LOCKS _MD_InitLocks
+
+NSPR_API(void) _MD_CleanThread(struct PRThread *thread);
+#define _MD_CLEAN_THREAD _MD_CleanThread
+
+#define _MD_YIELD()    sginap(0)
+
+/* The _PR_MD_WAIT_LOCK and _PR_MD_WAKEUP_WAITER functions put to sleep and
+ * awaken a thread which is waiting on a lock or cvar.
+ */
+NSPR_API(PRStatus) _MD_wait(struct PRThread *, PRIntervalTime timeout);
+#define _MD_WAIT _MD_wait
+
+NSPR_API(void) _PR_MD_primordial_cpu();
+NSPR_API(void) _PR_MD_WAKEUP_PRIMORDIAL_CPU();
+
+NSPR_API(PRStatus) _MD_WakeupWaiter(struct PRThread *);
+#define _MD_WAKEUP_WAITER _MD_WakeupWaiter
+
+NSPR_API(void ) _MD_exit(PRIntn status);
+#define _MD_EXIT	_MD_exit
+
+#include "prthread.h"
+
+NSPR_API(void) _MD_SetPriority(struct _MDThread *thread,
+	PRThreadPriority newPri);
+#define _MD_SET_PRIORITY _MD_SetPriority
+
+NSPR_API(PRStatus) _MD_CreateThread(
+                        struct PRThread *thread,
+                        void (*start) (void *),
+                        PRThreadPriority priority,
+                        PRThreadScope scope,
+                        PRThreadState state,
+                        PRUint32 stackSize);
+#define _MD_CREATE_THREAD _MD_CreateThread
+
+extern void _MD_CleanupBeforeExit(void);
+#define _MD_CLEANUP_BEFORE_EXIT _MD_CleanupBeforeExit
+
+NSPR_API(void) _PR_MD_PRE_CLEANUP(PRThread *me);
+
+
+/* The following defines the unwrapped versions of select() and poll(). */
+extern int _select(int nfds, fd_set *readfds, fd_set *writefds,
+	fd_set *exceptfds, struct timeval *timeout);
+#define _MD_SELECT	_select
+
+#include <stropts.h>
+#include <poll.h>
+#define _MD_POLL _poll
+extern int _poll(struct pollfd *fds, unsigned long nfds, int timeout);
+
+
+#define HAVE_THREAD_AFFINITY 1
+
+NSPR_API(PRInt32) _MD_GetThreadAffinityMask(PRThread *unused, PRUint32 *mask);
+#define _MD_GETTHREADAFFINITYMASK _MD_GetThreadAffinityMask
+
+NSPR_API(void) _MD_InitRunningCPU(struct _PRCPU *cpu);
+#define    _MD_INIT_RUNNING_CPU _MD_InitRunningCPU
+
+#endif  /* defined(_PR_PTHREADS) */
+
+#endif /* _LANGUAGE_ASSEMBLY */
+
+#endif /* nspr_irix_defs_h___ */
diff --git a/pr/include/md/_irix32.cfg b/pr/include/md/_irix32.cfg
new file mode 100644
index 0000000..3a5005c
--- /dev/null
+++ b/pr/include/md/_irix32.cfg
@@ -0,0 +1,119 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef _SGI_MP_SOURCE
+#define _SGI_MP_SOURCE
+#endif
+
+#ifndef XP_UNIX
+#define XP_UNIX
+#endif
+
+#ifndef IRIX
+#define IRIX
+#endif
+
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN 1
+
+#define PR_AF_INET6 24  /* same as AF_INET6 */
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_BYTES_PER_WORD_LOG2  2
+#define PR_BYTES_PER_DWORD_LOG2 3
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 4
+#define PR_ALIGN_OF_WORD    4
+
+#ifndef HAVE_LONG_LONG
+#define HAVE_LONG_LONG
+#endif
+#define HAVE_ALIGNED_DOUBLES
+#define HAVE_ALIGNED_LONGLONGS
+
+#define _PR_POLL_BACKCOMPAT
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
+#define BYTES_PER_INT 		PR_BYTES_PER_INT
+#define BYTES_PER_INT64		PR_BYTES_PER_INT64
+#define BYTES_PER_LONG		PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE	PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD		PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD		PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE		PR_BITS_PER_BYTE
+#define BITS_PER_SHORT		PR_BITS_PER_SHORT
+#define BITS_PER_INT		PR_BITS_PER_INT
+#define BITS_PER_INT64		PR_BITS_PER_INT64
+#define BITS_PER_LONG		PR_BITS_PER_LONG
+#define BITS_PER_FLOAT		PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE		PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD		PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2	PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2	PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2	PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2	PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2	PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2	PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2 	PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2	PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT		PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT		PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG		PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64		PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT		PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE		PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER	PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD		PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
diff --git a/pr/include/md/_irix64.cfg b/pr/include/md/_irix64.cfg
new file mode 100644
index 0000000..e6f29e3
--- /dev/null
+++ b/pr/include/md/_irix64.cfg
@@ -0,0 +1,118 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef _SGI_MP_SOURCE
+#define _SGI_MP_SOURCE
+#endif
+
+#ifndef XP_UNIX
+#define XP_UNIX
+#endif
+
+#ifndef IRIX
+#define IRIX
+#endif
+
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN 1
+#define IS_64
+
+#define PR_AF_INET6 24  /* same as AF_INET6 */
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   6
+
+#define PR_BYTES_PER_WORD_LOG2  3
+#define PR_BYTES_PER_DWORD_LOG2 3
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 4
+#define PR_ALIGN_OF_WORD    4
+
+#ifndef HAVE_LONG_LONG
+#define HAVE_LONG_LONG
+#endif
+#define HAVE_ALIGNED_DOUBLES
+#define HAVE_ALIGNED_LONGLONGS
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
+#define BYTES_PER_INT 		PR_BYTES_PER_INT
+#define BYTES_PER_INT64		PR_BYTES_PER_INT64
+#define BYTES_PER_LONG		PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE	PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD		PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD		PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE		PR_BITS_PER_BYTE
+#define BITS_PER_SHORT		PR_BITS_PER_SHORT
+#define BITS_PER_INT		PR_BITS_PER_INT
+#define BITS_PER_INT64		PR_BITS_PER_INT64
+#define BITS_PER_LONG		PR_BITS_PER_LONG
+#define BITS_PER_FLOAT		PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE		PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD		PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2	PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2	PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2	PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2	PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2	PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2	PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2 	PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2	PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT		PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT		PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG		PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64		PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT		PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE		PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER	PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD		PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
diff --git a/pr/include/md/_linux.cfg b/pr/include/md/_linux.cfg
new file mode 100644
index 0000000..8cbf0cb
--- /dev/null
+++ b/pr/include/md/_linux.cfg
@@ -0,0 +1,1081 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+ * This file is used by not only Linux but also other glibc systems
+ * such as GNU/Hurd and GNU/k*BSD.
+ */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef XP_UNIX
+#define XP_UNIX
+#endif
+
+#if !defined(LINUX) && defined(__linux__)
+#define LINUX
+#endif
+
+#ifdef __FreeBSD_kernel__
+#define PR_AF_INET6 28  /* same as AF_INET6 */
+#elif defined(__GNU__)
+#define PR_AF_INET6 26  /* same as AF_INET6 */
+#else
+#define PR_AF_INET6 10  /* same as AF_INET6 */
+#endif
+
+#ifdef __powerpc64__
+
+#ifdef __LITTLE_ENDIAN__
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#else
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN    1
+#endif
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+#define PR_ALIGN_OF_WORD    8
+
+#define PR_BYTES_PER_WORD_LOG2   3
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#elif defined(__powerpc__)
+
+#ifdef __LITTLE_ENDIAN__
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#else
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN    1
+#endif
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 4
+#define PR_ALIGN_OF_WORD    4
+
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#elif defined(__alpha)
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+#define PR_ALIGN_OF_WORD    8
+
+#define PR_BYTES_PER_WORD_LOG2  3
+#define PR_BYTES_PER_DWORD_LOG2 3
+
+#elif defined(__ia64__)
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+#define PR_ALIGN_OF_WORD    8
+
+#define PR_BYTES_PER_WORD_LOG2  3
+#define PR_BYTES_PER_DWORD_LOG2 3
+
+#elif defined(__x86_64__)
+
+#ifdef __ILP32__
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 4
+#define PR_ALIGN_OF_WORD    4
+
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#else
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+#define PR_ALIGN_OF_WORD    8
+
+#define PR_BYTES_PER_WORD_LOG2  3
+#define PR_BYTES_PER_DWORD_LOG2 3
+
+#endif
+
+#elif defined(__mc68000__)
+
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN 1
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     2
+#define PR_ALIGN_OF_LONG    2
+#define PR_ALIGN_OF_INT64   2
+#define PR_ALIGN_OF_FLOAT   2
+#define PR_ALIGN_OF_DOUBLE  2
+#define PR_ALIGN_OF_POINTER 2
+#define PR_ALIGN_OF_WORD    2
+
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#elif defined(__sparc__) && defined (__arch64__)
+
+#undef	IS_LITTLE_ENDIAN
+#define	IS_BIG_ENDIAN 1
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+#define PR_ALIGN_OF_WORD    8
+
+#define PR_BYTES_PER_WORD_LOG2   3
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#elif defined(__sparc__)
+
+#undef	IS_LITTLE_ENDIAN
+#define	IS_BIG_ENDIAN 1
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 4
+#define PR_ALIGN_OF_WORD    4
+
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#elif defined(__i386__)
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   4
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  4
+#define PR_ALIGN_OF_POINTER 4
+#define PR_ALIGN_OF_WORD    4
+
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#elif defined(__mips__)
+
+#ifdef __MIPSEB__
+#define IS_BIG_ENDIAN 1
+#undef  IS_LITTLE_ENDIAN
+#elif defined(__MIPSEL__)
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#else
+#error "Unknown MIPS endianness."
+#endif
+
+#if _MIPS_SIM == _ABI64
+
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+#define PR_ALIGN_OF_WORD    8
+
+#define PR_BYTES_PER_WORD_LOG2   3
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#else /* _ABI64 */
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 4
+#define PR_ALIGN_OF_WORD    4
+
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#endif /* _ABI64 */
+
+#elif defined(__arm__)
+
+#ifdef __ARMEB__
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN 1
+#elif defined(__ARMEL__)
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#else
+#error "Unknown ARM endianness."
+#endif
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   4
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  4
+#define PR_ALIGN_OF_POINTER 4
+#define PR_ALIGN_OF_WORD    4
+
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#elif defined(__aarch64__)
+
+#ifdef __AARCH64EB__
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN 1
+#elif defined(__AARCH64EL__)
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#else
+#error "Unknown Aarch64 endianness."
+#endif
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+#define PR_ALIGN_OF_WORD    8
+
+#define PR_BYTES_PER_WORD_LOG2  3
+#define PR_BYTES_PER_DWORD_LOG2 3
+
+#elif defined(__hppa__)
+
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN    1
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 4
+#define PR_ALIGN_OF_WORD    4
+
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#elif defined(__s390x__)
+
+#define IS_BIG_ENDIAN 1
+#undef  IS_LITTLE_ENDIAN
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+#define PR_ALIGN_OF_WORD    8
+
+#define PR_BYTES_PER_WORD_LOG2   3
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#elif defined(__s390__)
+
+#define IS_BIG_ENDIAN 1
+#undef  IS_LITTLE_ENDIAN
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   4
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  4
+#define PR_ALIGN_OF_POINTER 4
+#define PR_ALIGN_OF_WORD    4
+
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#elif defined(__sh__)
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   4
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  4
+#define PR_ALIGN_OF_POINTER 4
+#define PR_ALIGN_OF_WORD    4
+
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#elif defined(__avr32__)
+
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN 1
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   4
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  4
+#define PR_ALIGN_OF_POINTER 4
+#define PR_ALIGN_OF_WORD    4
+
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#elif defined(__m32r__)
+
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN 1
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   4
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  4
+#define PR_ALIGN_OF_POINTER 4
+#define PR_ALIGN_OF_WORD    4
+
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#elif defined(__or1k__)
+
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN 1
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   4
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  4
+#define PR_ALIGN_OF_POINTER 4
+#define PR_ALIGN_OF_WORD    4
+
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#else
+
+#error "Unknown CPU architecture"
+
+#endif
+
+#ifndef HAVE_LONG_LONG
+#define	HAVE_LONG_LONG
+#endif
+#if PR_ALIGN_OF_DOUBLE == 8
+#define HAVE_ALIGNED_DOUBLES
+#endif
+#if PR_ALIGN_OF_INT64 == 8
+#define HAVE_ALIGNED_LONGLONGS
+#endif
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
+#define BYTES_PER_INT 		PR_BYTES_PER_INT
+#define BYTES_PER_INT64		PR_BYTES_PER_INT64
+#define BYTES_PER_LONG		PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE	PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD		PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD		PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE		PR_BITS_PER_BYTE
+#define BITS_PER_SHORT		PR_BITS_PER_SHORT
+#define BITS_PER_INT		PR_BITS_PER_INT
+#define BITS_PER_INT64		PR_BITS_PER_INT64
+#define BITS_PER_LONG		PR_BITS_PER_LONG
+#define BITS_PER_FLOAT		PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE		PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD		PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2	PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2	PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2	PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2	PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2	PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2	PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2 	PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2	PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT		PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT		PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG		PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64		PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT		PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE		PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER	PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD		PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
diff --git a/pr/include/md/_linux.h b/pr/include/md/_linux.h
new file mode 100644
index 0000000..b4b298b
--- /dev/null
+++ b/pr/include/md/_linux.h
@@ -0,0 +1,694 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+ * This file is used by not only Linux but also other glibc systems
+ * such as GNU/Hurd and GNU/k*BSD.
+ */
+
+#ifndef nspr_linux_defs_h___
+#define nspr_linux_defs_h___
+
+#include "prthread.h"
+
+/*
+ * Internal configuration macros
+ */
+
+#define PR_LINKER_ARCH	"linux"
+#define _PR_SI_SYSNAME  "LINUX"
+#ifdef __powerpc64__
+#define _PR_SI_ARCHITECTURE "ppc64"
+#elif defined(__powerpc__)
+#define _PR_SI_ARCHITECTURE "ppc"
+#elif defined(__alpha)
+#define _PR_SI_ARCHITECTURE "alpha"
+#elif defined(__ia64__)
+#define _PR_SI_ARCHITECTURE "ia64"
+#elif defined(__x86_64__)
+#define _PR_SI_ARCHITECTURE "x86-64"
+#elif defined(__mc68000__)
+#define _PR_SI_ARCHITECTURE "m68k"
+#elif defined(__sparc__) && defined(__arch64__)
+#define _PR_SI_ARCHITECTURE "sparc64"
+#elif defined(__sparc__)
+#define _PR_SI_ARCHITECTURE "sparc"
+#elif defined(__i386__)
+#define _PR_SI_ARCHITECTURE "x86"
+#elif defined(__mips__)
+#define _PR_SI_ARCHITECTURE "mips"
+#elif defined(__arm__)
+#define _PR_SI_ARCHITECTURE "arm"
+#elif defined(__aarch64__)
+#define _PR_SI_ARCHITECTURE "aarch64"
+#elif defined(__hppa__)
+#define _PR_SI_ARCHITECTURE "hppa"
+#elif defined(__s390x__)
+#define _PR_SI_ARCHITECTURE "s390x"
+#elif defined(__s390__)
+#define _PR_SI_ARCHITECTURE "s390"
+#elif defined(__sh__)
+#define _PR_SI_ARCHITECTURE "sh"
+#elif defined(__avr32__)
+#define _PR_SI_ARCHITECTURE "avr32"
+#elif defined(__m32r__)
+#define _PR_SI_ARCHITECTURE "m32r"
+#elif defined(__or1k__)
+#define _PR_SI_ARCHITECTURE "or1k"
+#else
+#error "Unknown CPU architecture"
+#endif
+#define PR_DLL_SUFFIX		".so"
+
+#define _PR_VMBASE              0x30000000
+#define _PR_STACK_VMBASE	0x50000000
+#define _MD_DEFAULT_STACK_SIZE	65536L
+#define _MD_MMAP_FLAGS          MAP_PRIVATE
+
+#if defined(__aarch64__) || defined(__mips__)
+#define _MD_MINIMUM_STACK_SIZE  0x20000
+#endif
+
+#undef	HAVE_STACK_GROWING_UP
+
+/*
+ * Elf linux supports dl* functions
+ */
+#define HAVE_DLL
+#define USE_DLFCN
+#if defined(ANDROID)
+#define NO_DLOPEN_NULL
+#endif
+
+#if defined(__FreeBSD_kernel__) || defined(__GNU__)
+#define _PR_HAVE_SOCKADDR_LEN
+#endif
+
+#if defined(__i386__)
+#define _PR_HAVE_ATOMIC_OPS
+#define _MD_INIT_ATOMIC()
+extern PRInt32 _PR_x86_AtomicIncrement(PRInt32 *val);
+#define _MD_ATOMIC_INCREMENT          _PR_x86_AtomicIncrement
+extern PRInt32 _PR_x86_AtomicDecrement(PRInt32 *val);
+#define _MD_ATOMIC_DECREMENT          _PR_x86_AtomicDecrement
+extern PRInt32 _PR_x86_AtomicAdd(PRInt32 *ptr, PRInt32 val);
+#define _MD_ATOMIC_ADD                _PR_x86_AtomicAdd
+extern PRInt32 _PR_x86_AtomicSet(PRInt32 *val, PRInt32 newval);
+#define _MD_ATOMIC_SET                _PR_x86_AtomicSet
+#endif
+
+#if defined(__ia64__)
+#define _PR_HAVE_ATOMIC_OPS
+#define _MD_INIT_ATOMIC()
+extern PRInt32 _PR_ia64_AtomicIncrement(PRInt32 *val);
+#define _MD_ATOMIC_INCREMENT          _PR_ia64_AtomicIncrement
+extern PRInt32 _PR_ia64_AtomicDecrement(PRInt32 *val);
+#define _MD_ATOMIC_DECREMENT          _PR_ia64_AtomicDecrement
+extern PRInt32 _PR_ia64_AtomicAdd(PRInt32 *ptr, PRInt32 val);
+#define _MD_ATOMIC_ADD                _PR_ia64_AtomicAdd
+extern PRInt32 _PR_ia64_AtomicSet(PRInt32 *val, PRInt32 newval);
+#define _MD_ATOMIC_SET                _PR_ia64_AtomicSet
+#endif
+
+#if defined(__x86_64__)
+#define _PR_HAVE_ATOMIC_OPS
+#define _MD_INIT_ATOMIC()
+extern PRInt32 _PR_x86_64_AtomicIncrement(PRInt32 *val);
+#define _MD_ATOMIC_INCREMENT          _PR_x86_64_AtomicIncrement
+extern PRInt32 _PR_x86_64_AtomicDecrement(PRInt32 *val);
+#define _MD_ATOMIC_DECREMENT          _PR_x86_64_AtomicDecrement
+extern PRInt32 _PR_x86_64_AtomicAdd(PRInt32 *ptr, PRInt32 val);
+#define _MD_ATOMIC_ADD                _PR_x86_64_AtomicAdd
+extern PRInt32 _PR_x86_64_AtomicSet(PRInt32 *val, PRInt32 newval);
+#define _MD_ATOMIC_SET                _PR_x86_64_AtomicSet
+#endif
+
+#if defined(__or1k__)
+#if defined(__GNUC__)
+/* Use GCC built-in functions */
+#define _PR_HAVE_ATOMIC_OPS
+#define _MD_INIT_ATOMIC()
+#define _MD_ATOMIC_INCREMENT(ptr) __sync_add_and_fetch(ptr, 1)
+#define _MD_ATOMIC_DECREMENT(ptr) __sync_sub_and_fetch(ptr, 1)
+#define _MD_ATOMIC_ADD(ptr, i) __sync_add_and_fetch(ptr, i)
+#define _MD_ATOMIC_SET(ptr, nv) __sync_lock_test_and_set(ptr, nv)
+#endif
+#endif
+
+#if defined(__powerpc__) && !defined(__powerpc64__)
+#define _PR_HAVE_ATOMIC_OPS
+#define _MD_INIT_ATOMIC()
+extern PRInt32 _PR_ppc_AtomicIncrement(PRInt32 *val);
+#define _MD_ATOMIC_INCREMENT          _PR_ppc_AtomicIncrement
+extern PRInt32 _PR_ppc_AtomicDecrement(PRInt32 *val);
+#define _MD_ATOMIC_DECREMENT          _PR_ppc_AtomicDecrement
+extern PRInt32 _PR_ppc_AtomicAdd(PRInt32 *ptr, PRInt32 val);
+#define _MD_ATOMIC_ADD                _PR_ppc_AtomicAdd
+extern PRInt32 _PR_ppc_AtomicSet(PRInt32 *val, PRInt32 newval);
+#define _MD_ATOMIC_SET                _PR_ppc_AtomicSet
+#endif
+
+#if defined(__powerpc64__)
+#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
+/* Use GCC built-in functions */
+#define _PR_HAVE_ATOMIC_OPS
+#define _MD_INIT_ATOMIC()
+#define _MD_ATOMIC_INCREMENT(ptr) __sync_add_and_fetch(ptr, 1)
+#define _MD_ATOMIC_DECREMENT(ptr) __sync_sub_and_fetch(ptr, 1)
+#define _MD_ATOMIC_ADD(ptr, i) __sync_add_and_fetch(ptr, i)
+#define _MD_ATOMIC_SET(ptr, nv) __sync_lock_test_and_set(ptr, nv)
+#endif
+#endif
+
+#if defined(__mips__) && defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
+/* Use GCC built-in functions */
+#define _PR_HAVE_ATOMIC_OPS
+#define _MD_INIT_ATOMIC()
+#define _MD_ATOMIC_INCREMENT(ptr) __sync_add_and_fetch(ptr, 1)
+#define _MD_ATOMIC_DECREMENT(ptr) __sync_sub_and_fetch(ptr, 1)
+#define _MD_ATOMIC_ADD(ptr, i) __sync_add_and_fetch(ptr, i)
+#define _MD_ATOMIC_SET(ptr, nv) __sync_lock_test_and_set(ptr, nv)
+#endif
+
+#if defined(__alpha)
+#define _PR_HAVE_ATOMIC_OPS
+#define _MD_INIT_ATOMIC()
+#define _MD_ATOMIC_ADD(ptr, i) ({               \
+    PRInt32 __atomic_tmp, __atomic_ret;   \
+    __asm__ __volatile__(                       \
+    "1: ldl_l   %[ret], %[val]          \n"     \
+    "   addl    %[ret], %[inc], %[tmp]  \n"     \
+    "   addl    %[ret], %[inc], %[ret]  \n"     \
+    "   stl_c   %[tmp], %[val]          \n"     \
+    "   beq     %[tmp], 2f              \n"     \
+    ".subsection 2                      \n"     \
+    "2: br      1b                      \n"     \
+    ".previous"                                 \
+    : [ret] "=&r" (__atomic_ret),               \
+      [tmp] "=&r" (__atomic_tmp),               \
+      [val] "=m" (*ptr)                         \
+    : [inc] "Ir" (i), "m" (*ptr));              \
+    __atomic_ret;                               \
+})
+#define _MD_ATOMIC_INCREMENT(ptr) _MD_ATOMIC_ADD(ptr, 1)
+#define _MD_ATOMIC_DECREMENT(ptr) ({            \
+    PRInt32 __atomic_tmp, __atomic_ret;   \
+    __asm__ __volatile__(                       \
+    "1: ldl_l   %[ret], %[val]          \n"     \
+    "   subl    %[ret], 1, %[tmp]       \n"     \
+    "   subl    %[ret], 1, %[ret]       \n"     \
+    "   stl_c   %[tmp], %[val]          \n"     \
+    "   beq     %[tmp], 2f              \n"     \
+    ".subsection 2                      \n"     \
+    "2: br      1b                      \n"     \
+    ".previous"                                 \
+    : [ret] "=&r" (__atomic_ret),               \
+      [tmp] "=&r" (__atomic_tmp),               \
+      [val] "=m" (*ptr)                         \
+    : "m" (*ptr));                              \
+    __atomic_ret;                               \
+})
+#define _MD_ATOMIC_SET(ptr, n) ({               \
+    PRInt32 __atomic_tmp, __atomic_ret;   \
+    __asm__ __volatile__(                       \
+    "1: ldl_l   %[ret], %[val]          \n"     \
+    "   mov     %[newval], %[tmp]       \n"     \
+    "   stl_c   %[tmp], %[val]          \n"     \
+    "   beq     %[tmp], 2f              \n"     \
+    ".subsection 2                      \n"     \
+    "2: br      1b                      \n"     \
+    ".previous"                                 \
+    : [ret] "=&r" (__atomic_ret),               \
+      [tmp] "=&r"(__atomic_tmp),                \
+      [val] "=m" (*ptr)                         \
+    : [newval] "Ir" (n), "m" (*ptr));           \
+    __atomic_ret;                               \
+})
+#endif
+
+#if defined(__arm__) || defined(__aarch64__)
+#if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
+/* Use GCC built-in functions */
+#define _PR_HAVE_ATOMIC_OPS
+#define _MD_INIT_ATOMIC()
+
+#define _MD_ATOMIC_INCREMENT(ptr) __sync_add_and_fetch(ptr, 1)
+#define _MD_ATOMIC_DECREMENT(ptr) __sync_sub_and_fetch(ptr, 1)
+#define _MD_ATOMIC_SET(ptr, nv) __sync_lock_test_and_set(ptr, nv)
+#define _MD_ATOMIC_ADD(ptr, i) __sync_add_and_fetch(ptr, i)
+
+#elif defined(_PR_ARM_KUSER)
+#define _PR_HAVE_ATOMIC_OPS
+#define _MD_INIT_ATOMIC()
+
+/*
+ * The kernel provides this helper function at a fixed address with a fixed
+ * ABI signature, directly callable from user space.
+ *
+ * Definition:
+ * Atomically store newval in *ptr if *ptr is equal to oldval.
+ * Return zero if *ptr was changed or non-zero if no exchange happened.
+ */
+typedef int (__kernel_cmpxchg_t)(int oldval, int newval, volatile int *ptr);
+#define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0)
+
+#define _MD_ATOMIC_INCREMENT(ptr) _MD_ATOMIC_ADD(ptr, 1)
+#define _MD_ATOMIC_DECREMENT(ptr) _MD_ATOMIC_ADD(ptr, -1)
+
+static inline PRInt32 _MD_ATOMIC_ADD(PRInt32 *ptr, PRInt32 n)
+{
+    PRInt32 ov, nv;
+    volatile PRInt32 *vp = ptr;
+
+    do {
+        ov = *vp;
+        nv = ov + n;
+    } while (__kernel_cmpxchg(ov, nv, vp));
+
+    return nv;
+}
+
+static inline PRInt32 _MD_ATOMIC_SET(PRInt32 *ptr, PRInt32 nv)
+{
+    PRInt32 ov;
+    volatile PRInt32 *vp = ptr;
+
+    do {
+        ov = *vp;
+    } while (__kernel_cmpxchg(ov, nv, vp));
+
+    return ov;
+}
+#endif
+#endif /* __arm__ */
+
+#define USE_SETJMP
+#if (defined(__GLIBC__) && __GLIBC__ >= 2) || defined(ANDROID)
+#define _PR_POLL_AVAILABLE
+#endif
+#undef _PR_USE_POLL
+#define _PR_STAT_HAS_ONLY_ST_ATIME
+#if defined(__alpha) || defined(__ia64__)
+#define _PR_HAVE_LARGE_OFF_T
+#elif (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) \
+    || defined(ANDROID)
+#define _PR_HAVE_OFF64_T
+#else
+#define _PR_NO_LARGE_FILES
+#endif
+#if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) \
+    || defined(ANDROID)
+#define _PR_INET6
+#define _PR_HAVE_INET_NTOP
+#define _PR_HAVE_GETHOSTBYNAME2
+#define _PR_HAVE_GETADDRINFO
+#define _PR_INET6_PROBE
+#endif
+#ifndef ANDROID
+#define _PR_HAVE_SYSV_SEMAPHORES
+#define PR_HAVE_SYSV_NAMED_SHARED_MEMORY
+#endif
+/* Android has gethostbyname_r but not gethostbyaddr_r or gethostbyname2_r. */
+#if (__GLIBC__ >= 2) && defined(_PR_PTHREADS)
+#define _PR_HAVE_GETHOST_R
+#define _PR_HAVE_GETHOST_R_INT
+#endif
+
+#ifdef _PR_PTHREADS
+
+extern void _MD_CleanupBeforeExit(void);
+#define _MD_CLEANUP_BEFORE_EXIT _MD_CleanupBeforeExit
+
+#else  /* ! _PR_PTHREADS */
+
+#include <setjmp.h>
+
+#define PR_CONTEXT_TYPE	sigjmp_buf
+
+#define CONTEXT(_th) ((_th)->md.context)
+
+#ifdef __powerpc__
+/*
+ * PowerPC based MkLinux
+ *
+ * On the PowerPC, the new style jmp_buf isn't used until glibc
+ * 2.1.
+ */
+#if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1)
+#define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_GPR1]
+#else
+#define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__misc[0]
+#endif /* glibc 2.1 or later */
+#define _MD_SET_FP(_t, val)
+#define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
+#define _MD_GET_FP_PTR(_t) ((void *) 0)
+/* aix = 64, macos = 70 */
+#define PR_NUM_GCREGS  64
+
+#elif defined(__alpha)
+/* Alpha based Linux */
+
+#if defined(__GLIBC__) && __GLIBC__ >= 2
+#define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_SP]
+#define _MD_SET_FP(_t, val)
+#define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
+#define _MD_GET_FP_PTR(_t) ((void *) 0)
+#define _MD_SP_TYPE long int
+#else
+#define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp
+#define _MD_SET_FP(_t, val)
+#define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
+#define _MD_GET_FP_PTR(_t) ((void *) 0)
+#define _MD_SP_TYPE __ptr_t
+#endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
+
+/* XXX not sure if this is correct, or maybe it should be 17? */
+#define PR_NUM_GCREGS 9
+
+#elif defined(__ia64__)
+
+#define _MD_GET_SP(_t)      ((long *)((_t)->md.context[0].__jmpbuf)[0])
+#define _MD_SET_FP(_t, val)
+#define _MD_GET_SP_PTR(_t)  &(_MD_GET_SP(_t))
+#define _MD_GET_FP_PTR(_t)  ((void *) 0)
+#define _MD_SP_TYPE         long int
+
+#define PR_NUM_GCREGS       _JBLEN
+
+#elif defined(__mc68000__)
+/* m68k based Linux */
+
+/*
+ * On the m68k, glibc still uses the old style sigjmp_buf, even
+ * in glibc 2.0.7.
+ */
+#if defined(__GLIBC__) && __GLIBC__ >= 2
+#define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp
+#define _MD_SET_FP(_t, val)
+#define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
+#define _MD_GET_FP_PTR(_t) ((void *) 0)
+#define _MD_SP_TYPE int
+#else
+#define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp
+#define _MD_SET_FP(_t, val)
+#define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
+#define _MD_GET_FP_PTR(_t) ((void *) 0)
+#define _MD_SP_TYPE __ptr_t
+#endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
+
+/* XXX not sure if this is correct, or maybe it should be 17? */
+#define PR_NUM_GCREGS 9
+
+#elif defined(__sparc__)
+/* Sparc */
+#if defined(__GLIBC__) && __GLIBC__ >= 2
+/*
+ * You need glibc2-2.0.7-25 or later. The libraries that came with
+ * Red Hat 5.1 are not new enough, but they are in 5.2.
+ */
+#define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_SP]
+#define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[JB_FP] = val)
+#define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
+#define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[JB_FP])
+#define _MD_SP_TYPE int
+#else
+#define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__fp
+#define _MD_SET_FP(_t, val)
+#define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
+#define _MD_GET_FP_PTR(_t) ((void *) 0)
+#define _MD_SP_TYPE __ptr_t
+#endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
+
+#elif defined(__i386__)
+/* Intel based Linux */
+#if defined(__GLIBC__) && __GLIBC__ >= 2
+#define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[JB_SP]
+#define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[JB_BP] = val)
+#define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
+#define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[JB_BP])
+#define _MD_SP_TYPE int
+#else
+#define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp
+#define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[0].__bp = val)
+#define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
+#define _MD_GET_FP_PTR(_t) &((_t)->md.context[0].__jmpbuf[0].__bp)
+#define _MD_SP_TYPE __ptr_t
+#endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
+#define PR_NUM_GCREGS   6
+
+#elif defined(__mips__)
+/* Linux/MIPS */
+#if defined(__GLIBC__) && __GLIBC__ >= 2
+#define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__sp
+#define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[0].__fp = (val))
+#define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
+#define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[0].__fp)
+#define _MD_SP_TYPE __ptr_t
+#else
+#error "Linux/MIPS pre-glibc2 not supported yet"
+#endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
+
+#elif defined(__arm__)
+/* ARM/Linux */
+#if defined(__GLIBC__) && __GLIBC__ >= 2
+#ifdef __ARM_EABI__
+/* EABI */
+#define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[8]
+#define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[7] = (val))
+#define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
+#define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[7])
+#define _MD_SP_TYPE __ptr_t
+#else /* __ARM_EABI__ */
+/* old ABI */
+#define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[20]
+#define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[19] = (val))
+#define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
+#define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[19])
+#define _MD_SP_TYPE __ptr_t
+#endif /* __ARM_EABI__ */
+#else
+#error "ARM/Linux pre-glibc2 not supported yet"
+#endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
+
+#elif defined(__sh__)
+/* SH/Linux */
+#if defined(__GLIBC__) && __GLIBC__ >= 2
+#define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[7]
+#define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[6] = (val))
+#define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
+#define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[6])
+#define _MD_SP_TYPE __ptr_t
+#else
+#error "SH/Linux pre-glibc2 not supported yet"
+#endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
+
+#elif defined(__m32r__)
+/* Linux/M32R */
+#if defined(__GLIBC__) && __GLIBC__ >= 2
+#define _MD_GET_SP(_t) (_t)->md.context[0].__jmpbuf[0].__regs[JB_SP]
+#define _MD_SET_FP(_t, val) ((_t)->md.context[0].__jmpbuf[0].__regs[JB_FP] = (val))
+#define _MD_GET_SP_PTR(_t) &(_MD_GET_SP(_t))
+#define _MD_GET_FP_PTR(_t) (&(_t)->md.context[0].__jmpbuf[0].__regs[JB_FP])
+#define _MD_SP_TYPE __ptr_t
+#else
+#error "Linux/M32R pre-glibc2 not supported yet"
+#endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
+
+#else
+
+#error "Unknown CPU architecture"
+
+#endif /*__powerpc__*/
+
+/*
+** Initialize a thread context to run "_main()" when started
+*/
+#ifdef __powerpc__
+
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
+{  \
+    *status = PR_TRUE;  \
+    if (sigsetjmp(CONTEXT(_thread), 1)) {  \
+        _main();  \
+    }  \
+    _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 128); \
+    _thread->md.sp = _MD_GET_SP_PTR(_thread); \
+    _thread->md.fp = _MD_GET_FP_PTR(_thread); \
+    _MD_SET_FP(_thread, 0); \
+}
+
+#elif defined(__mips__)
+
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
+{  \
+    *status = PR_TRUE;  \
+    (void) sigsetjmp(CONTEXT(_thread), 1);  \
+    _thread->md.context[0].__jmpbuf[0].__pc = (__ptr_t) _main;  \
+    _MD_GET_SP(_thread) = (_MD_SP_TYPE) ((_sp) - 64); \
+    _thread->md.sp = _MD_GET_SP_PTR(_thread); \
+    _thread->md.fp = _MD_GET_FP_PTR(_thread); \
+    _MD_SET_FP(_thread, 0); \
+}
+
+#else
+
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
+{  \
+    *status = PR_TRUE;  \
+    if (sigsetjmp(CONTEXT(_thread), 1)) {  \
+        _main();  \
+    }  \
+    _MD_GET_SP(_thread) = (_MD_SP_TYPE) ((_sp) - 64); \
+    _thread->md.sp = _MD_GET_SP_PTR(_thread); \
+    _thread->md.fp = _MD_GET_FP_PTR(_thread); \
+    _MD_SET_FP(_thread, 0); \
+}
+
+#endif /*__powerpc__*/
+
+#define _MD_SWITCH_CONTEXT(_thread)  \
+    if (!sigsetjmp(CONTEXT(_thread), 1)) {  \
+	(_thread)->md.errcode = errno;  \
+	_PR_Schedule();  \
+    }
+
+/*
+** Restore a thread context, saved by _MD_SWITCH_CONTEXT
+*/
+#define _MD_RESTORE_CONTEXT(_thread) \
+{   \
+    errno = (_thread)->md.errcode;  \
+    _MD_SET_CURRENT_THREAD(_thread);  \
+    siglongjmp(CONTEXT(_thread), 1);  \
+}
+
+/* Machine-dependent (MD) data structures */
+
+struct _MDThread {
+    PR_CONTEXT_TYPE context;
+    void *sp;
+    void *fp;
+    int id;
+    int errcode;
+};
+
+struct _MDThreadStack {
+    PRInt8 notused;
+};
+
+struct _MDLock {
+    PRInt8 notused;
+};
+
+struct _MDSemaphore {
+    PRInt8 notused;
+};
+
+struct _MDCVar {
+    PRInt8 notused;
+};
+
+struct _MDSegment {
+    PRInt8 notused;
+};
+
+/*
+ * md-specific cpu structure field
+ */
+#include <sys/time.h>  /* for FD_SETSIZE */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+            fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+    struct pollfd *ioq_pollfds;
+    int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
+struct _MDCPU {
+    struct _MDCPU_Unix md_unix;
+};
+
+#define _MD_INIT_LOCKS()
+#define _MD_NEW_LOCK(lock) PR_SUCCESS
+#define _MD_FREE_LOCK(lock)
+#define _MD_LOCK(lock)
+#define _MD_UNLOCK(lock)
+#define _MD_INIT_IO()
+#define _MD_IOQ_LOCK()
+#define _MD_IOQ_UNLOCK()
+
+extern PRStatus _MD_InitializeThread(PRThread *thread);
+
+#define _MD_INIT_RUNNING_CPU(cpu)       _MD_unix_init_running_cpu(cpu)
+#define _MD_INIT_THREAD                 _MD_InitializeThread
+#define _MD_EXIT_THREAD(thread)
+#define _MD_SUSPEND_THREAD(thread)      _MD_suspend_thread
+#define _MD_RESUME_THREAD(thread)       _MD_resume_thread
+#define _MD_CLEAN_THREAD(_thread)
+
+extern PRStatus _MD_CREATE_THREAD(
+    PRThread *thread,
+    void (*start) (void *),
+    PRThreadPriority priority,
+    PRThreadScope scope,
+    PRThreadState state,
+    PRUint32 stackSize);
+extern void _MD_SET_PRIORITY(struct _MDThread *thread, PRUintn newPri);
+extern PRStatus _MD_WAIT(PRThread *, PRIntervalTime timeout);
+extern PRStatus _MD_WAKEUP_WAITER(PRThread *);
+extern void _MD_YIELD(void);
+
+#endif /* ! _PR_PTHREADS */
+
+extern void _MD_EarlyInit(void);
+
+#define _MD_EARLY_INIT                  _MD_EarlyInit
+#define _MD_FINAL_INIT                  _PR_UnixInit
+#define _PR_HAVE_CLOCK_MONOTONIC
+
+/*
+ * We wrapped the select() call.  _MD_SELECT refers to the built-in,
+ * unwrapped version.
+ */
+#define _MD_SELECT __select
+
+#ifdef _PR_POLL_AVAILABLE
+#include <sys/poll.h>
+extern int __syscall_poll(struct pollfd *ufds, unsigned long int nfds,
+	int timeout);
+#define _MD_POLL __syscall_poll
+#endif
+
+/* For writev() */
+#include <sys/uio.h>
+
+extern void _MD_linux_map_sendfile_error(int err);
+
+#endif /* nspr_linux_defs_h___ */
diff --git a/pr/include/md/_netbsd.cfg b/pr/include/md/_netbsd.cfg
new file mode 100644
index 0000000..1326556
--- /dev/null
+++ b/pr/include/md/_netbsd.cfg
@@ -0,0 +1,351 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef XP_UNIX
+#define XP_UNIX
+#endif
+
+#ifndef NETBSD
+#define NETBSD
+#endif
+
+#define PR_AF_INET6 24  /* same as AF_INET6 */
+
+#ifndef HAVE_LONG_LONG
+#define HAVE_LONG_LONG
+#endif
+
+#if defined(__i386__) || defined(__arm32__) || defined(__ARMEL__) || \
+	defined(__MIPSEL__)
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#undef	HAVE_ALIGNED_DOUBLES
+#undef	HAVE_ALIGNED_LONGLONGS
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   4
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  4
+#define PR_ALIGN_OF_POINTER 4
+
+#elif defined(__sparc_v9__)
+
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN 1
+#define HAVE_ALIGNED_DOUBLES
+#define HAVE_ALIGNED_LONGLONGS
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+#define PR_BYTES_PER_WORD_LOG2   3
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_INT64   8 
+#define PR_ALIGN_OF_FLOAT   4 
+#define PR_ALIGN_OF_DOUBLE  8 
+#define PR_ALIGN_OF_POINTER 8 
+
+#elif defined(__sparc__) || defined(__MIPSEB__) || defined(__ARMEB__)
+
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN 1
+#define HAVE_ALIGNED_DOUBLES
+#define HAVE_ALIGNED_LONGLONGS
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 4
+
+#elif defined(__alpha__)
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#define	HAVE_ALIGNED_DOUBLES
+#define	HAVE_ALIGNED_LONGLONGS
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+
+#define PR_BYTES_PER_WORD_LOG2  3
+#define PR_BYTES_PER_DWORD_LOG2 3
+
+#elif defined(__amd64__)
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#define HAVE_ALIGNED_DOUBLES
+#define HAVE_ALIGNED_LONGLONGS
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+#define PR_ALIGN_OF_WORD    8
+
+#define PR_BYTES_PER_WORD_LOG2  3
+#define PR_BYTES_PER_DWORD_LOG2 3
+
+#elif defined(__powerpc__) || defined(__m68k__)
+
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN    1
+#undef	HAVE_ALIGNED_DOUBLES
+#undef	HAVE_ALIGNED_LONGLONGS
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   4
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  4
+#define PR_ALIGN_OF_POINTER 4
+
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#else
+
+#error Must define constants for type sizes here.
+
+#endif
+
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
+#define BYTES_PER_INT 		PR_BYTES_PER_INT
+#define BYTES_PER_INT64		PR_BYTES_PER_INT64
+#define BYTES_PER_LONG		PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE	PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD		PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD		PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE		PR_BITS_PER_BYTE
+#define BITS_PER_SHORT		PR_BITS_PER_SHORT
+#define BITS_PER_INT		PR_BITS_PER_INT
+#define BITS_PER_INT64		PR_BITS_PER_INT64
+#define BITS_PER_LONG		PR_BITS_PER_LONG
+#define BITS_PER_FLOAT		PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE		PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD		PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2	PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2	PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2	PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2	PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2	PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2	PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2 	PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2	PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT		PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT		PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG		PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64		PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT		PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE		PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER	PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD		PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
diff --git a/pr/include/md/_netbsd.h b/pr/include/md/_netbsd.h
new file mode 100644
index 0000000..945d94f
--- /dev/null
+++ b/pr/include/md/_netbsd.h
@@ -0,0 +1,230 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_netbsd_defs_h___
+#define nspr_netbsd_defs_h___
+
+#include <sys/syscall.h>
+#include <sys/param.h>  /* for __NetBSD_Version__ */
+
+#define PR_LINKER_ARCH	"netbsd"
+#define _PR_SI_SYSNAME  "NetBSD"
+#if defined(__i386__)
+#define _PR_SI_ARCHITECTURE "x86"
+#elif defined(__alpha__)
+#define _PR_SI_ARCHITECTURE "alpha"
+#elif defined(__amd64__)
+#define _PR_SI_ARCHITECTURE "amd64"
+#elif defined(__m68k__)
+#define _PR_SI_ARCHITECTURE "m68k"
+#elif defined(__powerpc__)
+#define _PR_SI_ARCHITECTURE "powerpc"
+#elif defined(__sparc_v9__)
+#define _PR_SI_ARCHITECTURE "sparc64"
+#elif defined(__sparc__)
+#define _PR_SI_ARCHITECTURE "sparc"
+#elif defined(__mips__)
+#define _PR_SI_ARCHITECTURE "mips"
+#elif defined(__arm32__) || defined(__arm__) || defined(__armel__) \
+    || defined(__armeb__)
+#define _PR_SI_ARCHITECTURE "arm"
+#endif
+
+#if defined(__ELF__)
+#define PR_DLL_SUFFIX		".so"
+#else
+#define PR_DLL_SUFFIX		".so.1.0"
+#endif
+
+#define _PR_VMBASE              0x30000000
+#define _PR_STACK_VMBASE	0x50000000
+#define _MD_DEFAULT_STACK_SIZE	65536L
+#define _MD_MMAP_FLAGS          MAP_PRIVATE
+
+#undef  HAVE_STACK_GROWING_UP
+#define HAVE_DLL
+#define USE_DLFCN
+#define _PR_HAVE_SOCKADDR_LEN
+#define _PR_NO_LARGE_FILES
+#define _PR_STAT_HAS_ST_ATIMESPEC
+#define _PR_POLL_AVAILABLE
+#define _PR_USE_POLL
+#define _PR_HAVE_SYSV_SEMAPHORES
+#define PR_HAVE_SYSV_NAMED_SHARED_MEMORY
+
+#if __NetBSD_Version__ >= 105000000
+#define _PR_INET6
+#define _PR_HAVE_INET_NTOP
+#define _PR_HAVE_GETHOSTBYNAME2
+#define _PR_HAVE_GETADDRINFO
+#define _PR_INET6_PROBE
+#endif
+
+#define USE_SETJMP
+
+#ifndef _PR_PTHREADS
+#include <setjmp.h>
+
+#define PR_CONTEXT_TYPE	sigjmp_buf
+
+#define CONTEXT(_th) ((_th)->md.context)
+
+#if defined(__i386__) || defined(__sparc__) || defined(__m68k__) || defined(__powerpc__)
+#define JB_SP_INDEX 2
+#elif defined(__mips__)
+#define JB_SP_INDEX 4
+#elif defined(__alpha__)
+#define JB_SP_INDEX 34
+#elif defined(__arm32__)
+/*
+ * On the arm32, the jmpbuf regs underwent a name change after NetBSD 1.3.
+ */
+#ifdef JMPBUF_REG_R13
+#define JB_SP_INDEX JMPBUF_REG_R13
+#else
+#define JB_SP_INDEX _JB_REG_R13
+#endif
+#else
+#error "Need to define SP index in jmp_buf here"
+#endif
+#define _MD_GET_SP(_th)    (_th)->md.context[JB_SP_INDEX]
+
+#define PR_NUM_GCREGS	_JBLEN
+
+/*
+** Initialize a thread context to run "_main()" when started
+*/
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
+{  \
+    *status = PR_TRUE;  \
+    if (sigsetjmp(CONTEXT(_thread), 1)) {  \
+        _main();  \
+    }  \
+    _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 64); \
+}
+
+#define _MD_SWITCH_CONTEXT(_thread)  \
+    if (!sigsetjmp(CONTEXT(_thread), 1)) {  \
+        (_thread)->md.errcode = errno;  \
+        _PR_Schedule();  \
+    }
+
+/*
+** Restore a thread context, saved by _MD_SWITCH_CONTEXT
+*/
+#define _MD_RESTORE_CONTEXT(_thread) \
+{   \
+    errno = (_thread)->md.errcode;  \
+    _MD_SET_CURRENT_THREAD(_thread);  \
+    siglongjmp(CONTEXT(_thread), 1);  \
+}
+
+/* Machine-dependent (MD) data structures */
+
+struct _MDThread {
+    PR_CONTEXT_TYPE context;
+    int id;
+    int errcode;
+};
+
+struct _MDThreadStack {
+    PRInt8 notused;
+};
+
+struct _MDLock {
+    PRInt8 notused;
+};
+
+struct _MDSemaphore {
+    PRInt8 notused;
+};
+
+struct _MDCVar {
+    PRInt8 notused;
+};
+
+struct _MDSegment {
+    PRInt8 notused;
+};
+
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
+struct _MDCPU {
+    struct _MDCPU_Unix md_unix;
+};
+
+#define _MD_INIT_LOCKS()
+#define _MD_NEW_LOCK(lock) PR_SUCCESS
+#define _MD_FREE_LOCK(lock)
+#define _MD_LOCK(lock)
+#define _MD_UNLOCK(lock)
+#define _MD_INIT_IO()
+#define _MD_IOQ_LOCK()
+#define _MD_IOQ_UNLOCK()
+
+#define _MD_INIT_RUNNING_CPU(cpu)       _MD_unix_init_running_cpu(cpu)
+#define _MD_INIT_THREAD                 _MD_InitializeThread
+#define _MD_EXIT_THREAD(thread)
+#define _MD_SUSPEND_THREAD(thread)      _MD_suspend_thread
+#define _MD_RESUME_THREAD(thread)       _MD_resume_thread
+#define _MD_CLEAN_THREAD(_thread)
+
+#endif /* ! _PR_PTHREADS */
+
+extern void _MD_EarlyInit(void);
+
+#define _MD_EARLY_INIT                  _MD_EarlyInit
+#define _MD_FINAL_INIT			_PR_UnixInit
+#define _PR_HAVE_CLOCK_MONOTONIC
+
+/*
+ * We wrapped the select() call.  _MD_SELECT refers to the built-in,
+ * unwrapped version.
+ */
+#define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
+#if defined(_PR_POLL_AVAILABLE)
+#include <poll.h>
+#define _MD_POLL(fds,nfds,timeout) syscall(SYS_poll,fds,nfds,timeout)
+#endif
+
+#if NetBSD1_3 == 1L
+typedef unsigned int nfds_t;
+#endif
+
+#endif /* nspr_netbsd_defs_h___ */
diff --git a/pr/include/md/_nspr_pthread.h b/pr/include/md/_nspr_pthread.h
new file mode 100644
index 0000000..7af442c
--- /dev/null
+++ b/pr/include/md/_nspr_pthread.h
@@ -0,0 +1,251 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_pthread_defs_h___
+#define nspr_pthread_defs_h___
+
+#include <pthread.h>
+#include "prthread.h"
+
+#if defined(PTHREADS_USER)
+/*
+** Thread Local Storage 
+*/
+extern pthread_key_t current_thread_key;
+extern pthread_key_t current_cpu_key;
+extern pthread_key_t last_thread_key;
+extern pthread_key_t intsoff_key;
+
+#define _MD_CURRENT_THREAD() 			\
+			((struct PRThread *) pthread_getspecific(current_thread_key))
+#define _MD_CURRENT_CPU() 				\
+			((struct _PRCPU *) pthread_getspecific(current_cpu_key))
+#define _MD_LAST_THREAD()				\
+			((struct PRThread *) pthread_getspecific(last_thread_key))
+	
+#define _MD_SET_CURRENT_THREAD(newval) 			\
+	pthread_setspecific(current_thread_key, (void *)newval)
+
+#define _MD_SET_CURRENT_CPU(newval) 			\
+	pthread_setspecific(current_cpu_key, (void *)newval)
+
+#define _MD_SET_LAST_THREAD(newval)	 			\
+	pthread_setspecific(last_thread_key, (void *)newval)
+
+#define _MD_SET_INTSOFF(_val)
+#define _MD_GET_INTSOFF()	1
+	
+/*
+** Initialize the thread context preparing it to execute _main.
+*/
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)			\
+    PR_BEGIN_MACRO				      							\
+        *status = PR_TRUE;              						\
+		if (SAVE_CONTEXT(_thread)) {							\
+	    	(*_main)();											\
+		}														\
+		_MD_SET_THR_SP(_thread, _sp);							\
+		_thread->no_sched = 0; 									\
+    PR_END_MACRO
+
+#define _MD_SWITCH_CONTEXT(_thread)  								\
+    PR_BEGIN_MACRO 													\
+	PR_ASSERT(_thread->no_sched);									\
+	if (!SAVE_CONTEXT(_thread)) {									\
+		(_thread)->md.errcode = errno;  							\
+		_MD_SET_LAST_THREAD(_thread);								\
+		_PR_Schedule();		     									\
+    } else {														\
+		 (_MD_LAST_THREAD())->no_sched = 0;							\
+	}																\
+    PR_END_MACRO
+
+/*
+** Restore a thread context, saved by _MD_SWITCH_CONTEXT
+*/
+#define _MD_RESTORE_CONTEXT(_thread)								\
+    PR_BEGIN_MACRO 													\
+    errno = (_thread)->md.errcode; 									\
+    _MD_SET_CURRENT_THREAD(_thread); 								\
+	_thread->no_sched = 1;											\
+    GOTO_CONTEXT(_thread); 											\
+    PR_END_MACRO
+
+
+/* Machine-dependent (MD) data structures */
+
+struct _MDThread {
+    jmp_buf 		jb;
+    int				id;
+    int				errcode;
+	pthread_t		pthread;
+	pthread_mutex_t	pthread_mutex;
+	pthread_cond_t	pthread_cond;
+	int				wait;
+};
+
+struct _MDThreadStack {
+    PRInt8 notused;
+};
+
+struct _MDLock {
+	pthread_mutex_t mutex;
+};
+
+struct _MDSemaphore {
+    PRInt8 notused;
+};
+
+struct _MDCVar {
+	pthread_mutex_t mutex;
+};
+
+struct _MDSegment {
+    PRInt8 notused;
+};
+
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
+struct _MDCPU {
+    jmp_buf 			jb;
+	pthread_t 			pthread;
+	struct _MDCPU_Unix 	md_unix;
+};
+
+/*
+#define _MD_NEW_LOCK(lock) PR_SUCCESS
+#define _MD_FREE_LOCK(lock)
+#define _MD_LOCK(lock)
+#define _MD_UNLOCK(lock)
+*/
+
+extern pthread_mutex_t _pr_heapLock;
+
+#define _PR_LOCK(lock) pthread_mutex_lock(lock)
+
+#define _PR_UNLOCK(lock) pthread_mutex_unlock(lock)
+
+
+#define _PR_LOCK_HEAP()	{									\
+				if (_pr_primordialCPU) {					\
+					_PR_LOCK(_pr_heapLock);					\
+				}
+
+#define _PR_UNLOCK_HEAP() 	if (_pr_primordialCPU)	{		\
+					_PR_UNLOCK(_pr_heapLock);				\
+				}											\
+			  }
+
+NSPR_API(PRStatus) _MD_NEW_LOCK(struct _MDLock *md);
+NSPR_API(void) _MD_FREE_LOCK(struct _MDLock *lockp);
+
+#define _MD_LOCK(_lockp) _PR_LOCK(&(_lockp)->mutex)
+#define _MD_UNLOCK(_lockp) _PR_UNLOCK(&(_lockp)->mutex)
+
+#define _MD_INIT_IO()
+#define _MD_IOQ_LOCK()
+#define _MD_IOQ_UNLOCK()
+#define _MD_CHECK_FOR_EXIT()
+
+NSPR_API(PRStatus) _MD_InitThread(struct PRThread *thread);
+#define _MD_INIT_THREAD _MD_InitThread
+#define _MD_INIT_ATTACHED_THREAD _MD_InitThread
+
+NSPR_API(void) _MD_ExitThread(struct PRThread *thread);
+#define _MD_EXIT_THREAD _MD_ExitThread
+
+NSPR_API(void) _MD_SuspendThread(struct PRThread *thread);
+#define _MD_SUSPEND_THREAD _MD_SuspendThread
+
+NSPR_API(void) _MD_ResumeThread(struct PRThread *thread);
+#define _MD_RESUME_THREAD _MD_ResumeThread
+
+NSPR_API(void) _MD_SuspendCPU(struct _PRCPU *thread);
+#define _MD_SUSPEND_CPU _MD_SuspendCPU
+
+NSPR_API(void) _MD_ResumeCPU(struct _PRCPU *thread);
+#define _MD_RESUME_CPU _MD_ResumeCPU
+
+#define _MD_BEGIN_SUSPEND_ALL()
+#define _MD_END_SUSPEND_ALL()
+#define _MD_BEGIN_RESUME_ALL()
+#define _MD_END_RESUME_ALL()
+
+NSPR_API(void) _MD_EarlyInit(void);
+#define _MD_EARLY_INIT _MD_EarlyInit
+
+#define _MD_FINAL_INIT _PR_UnixInit
+
+NSPR_API(void) _MD_InitLocks(void);
+#define _MD_INIT_LOCKS _MD_InitLocks
+
+NSPR_API(void) _MD_CleanThread(struct PRThread *thread);
+#define _MD_CLEAN_THREAD _MD_CleanThread
+
+NSPR_API(PRStatus) _MD_CreateThread(
+                        struct PRThread *thread,
+                        void (*start) (void *),
+                        PRThreadPriority priority,
+                        PRThreadScope scope,
+                        PRThreadState state,
+                        PRUint32 stackSize);
+#define _MD_CREATE_THREAD _MD_CreateThread
+
+extern void _MD_CleanupBeforeExit(void);
+#define _MD_CLEANUP_BEFORE_EXIT _MD_CleanupBeforeExit
+
+NSPR_API(void) _MD_InitRunningCPU(struct _PRCPU *cpu);
+#define    _MD_INIT_RUNNING_CPU _MD_InitRunningCPU
+
+/* The _PR_MD_WAIT_LOCK and _PR_MD_WAKEUP_WAITER functions put to sleep and
+ * awaken a thread which is waiting on a lock or cvar.
+ */
+NSPR_API(PRStatus) _MD_wait(struct PRThread *, PRIntervalTime timeout);
+#define _MD_WAIT _MD_wait
+
+NSPR_API(PRStatus) _MD_WakeupWaiter(struct PRThread *);
+#define _MD_WAKEUP_WAITER _MD_WakeupWaiter
+
+NSPR_API(void) _MD_SetPriority(struct _MDThread *thread,
+	PRThreadPriority newPri);
+#define _MD_SET_PRIORITY _MD_SetPriority
+
+#endif /* PTHREADS_USER */
+
+#endif /* nspr_pthread_defs_h___ */
diff --git a/pr/include/md/_nto.cfg b/pr/include/md/_nto.cfg
new file mode 100644
index 0000000..b76a560
--- /dev/null
+++ b/pr/include/md/_nto.cfg
@@ -0,0 +1,120 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef XP_UNIX
+#define XP_UNIX
+#endif
+
+#ifndef NTO
+#define NTO
+#endif
+
+#define PR_AF_INET6 24  /* same as AF_INET6 */
+
+#ifdef __i386__
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+
+#define PR_BYTES_PER_BYTE   1L
+#define PR_BYTES_PER_SHORT  2L
+#define PR_BYTES_PER_INT    4L
+#define PR_BYTES_PER_INT64  8L
+#define PR_BYTES_PER_LONG   4L
+#define PR_BYTES_PER_FLOAT  4L
+#define PR_BYTES_PER_DOUBLE 8L
+#define PR_BYTES_PER_WORD   4L
+#define PR_BYTES_PER_DWORD  8L
+
+#define PR_BITS_PER_BYTE    8L
+#define PR_BITS_PER_SHORT   16L
+#define PR_BITS_PER_INT     32L
+#define PR_BITS_PER_INT64   64L
+#define PR_BITS_PER_LONG    32L
+#define PR_BITS_PER_FLOAT   32L
+#define PR_BITS_PER_DOUBLE  64L
+#define PR_BITS_PER_WORD    32L
+
+#define PR_BITS_PER_BYTE_LOG2   3L
+#define PR_BITS_PER_SHORT_LOG2  4L
+#define PR_BITS_PER_INT_LOG2    5L
+#define PR_BITS_PER_INT64_LOG2  6L
+#define PR_BITS_PER_LONG_LOG2   5L
+#define PR_BITS_PER_FLOAT_LOG2  5L
+#define PR_BITS_PER_DOUBLE_LOG2 6L
+#define PR_BITS_PER_WORD_LOG2   5L
+
+#define PR_ALIGN_OF_SHORT   2L
+#define PR_ALIGN_OF_INT     4L
+#define PR_ALIGN_OF_LONG    4L
+#define PR_ALIGN_OF_INT64   4L
+#define PR_ALIGN_OF_FLOAT   4L
+#define PR_ALIGN_OF_DOUBLE  4L
+#define PR_ALIGN_OF_POINTER 4L
+#define PR_ALIGN_OF_WORD    4L
+
+#define PR_BYTES_PER_WORD_LOG2   2L
+#define PR_BYTES_PER_DWORD_LOG2  3L
+#define PR_WORDS_PER_DWORD_LOG2  1L
+
+#else
+
+#error Undefined CPU Architecture
+
+#endif
+
+#ifndef HAVE_LONG_LONG
+#define HAVE_LONG_LONG
+#endif
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
+#define BYTES_PER_INT 		PR_BYTES_PER_INT
+#define BYTES_PER_INT64		PR_BYTES_PER_INT64
+#define BYTES_PER_LONG		PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE	PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD		PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD		PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE		PR_BITS_PER_BYTE
+#define BITS_PER_SHORT		PR_BITS_PER_SHORT
+#define BITS_PER_INT		PR_BITS_PER_INT
+#define BITS_PER_INT64		PR_BITS_PER_INT64
+#define BITS_PER_LONG		PR_BITS_PER_LONG
+#define BITS_PER_FLOAT		PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE		PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD		PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2	PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2	PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2	PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2	PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2	PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2	PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2 	PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2	PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT		PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT		PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG		PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64		PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT		PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE		PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER	PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD		PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
diff --git a/pr/include/md/_nto.h b/pr/include/md/_nto.h
new file mode 100644
index 0000000..9530975
--- /dev/null
+++ b/pr/include/md/_nto.h
@@ -0,0 +1,188 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_nto_defs_h___
+#define nspr_nto_defs_h___
+
+/*
+** Internal configuration macros
+*/
+#define PR_LINKER_ARCH		"nto"
+#define _PR_SI_SYSNAME		"NTO"
+#define _PR_SI_ARCHITECTURE	"x86"
+#define PR_DLL_SUFFIX		".so"
+
+#define _PR_VMBASE		0x30000000
+#define _PR_STACK_VMBASE	0x50000000
+#define _MD_DEFAULT_STACK_SIZE	65536L
+#define _MD_MINIMUM_STACK_SIZE	131072L
+#define _MD_MMAP_FLAGS		MAP_PRIVATE
+
+#ifndef	HAVE_WEAK_IO_SYMBOLS
+#define	HAVE_WEAK_IO_SYMBOLS
+#endif
+
+#undef  _PR_POLL_AVAILABLE
+#undef  _PR_USE_POLL
+#define _PR_HAVE_SOCKADDR_LEN
+#undef  HAVE_BSD_FLOCK
+#define HAVE_FCNTL_FILE_LOCKING
+#define _PR_NO_LARGE_FILES
+#define _PR_STAT_HAS_ONLY_ST_ATIME
+#define PR_HAVE_POSIX_NAMED_SHARED_MEMORY
+#define _PR_HAVE_POSIX_SEMAPHORES
+
+#undef FD_SETSIZE
+#define FD_SETSIZE	4096
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/select.h>
+
+#undef  HAVE_STACK_GROWING_UP
+#define	HAVE_DLL
+#define	USE_DLFCN
+#define NEED_STRFTIME_LOCK
+#define NEED_TIME_R
+#define _PR_NEED_STRCASECMP
+
+#ifndef HAVE_STRERROR
+#define HAVE_STRERROR
+#endif
+
+#define USE_SETJMP
+
+#include <setjmp.h>
+
+#define _SETJMP			setjmp
+#define _LONGJMP		longjmp
+#define _PR_CONTEXT_TYPE	jmp_buf
+#define _PR_NUM_GCREGS		_JBLEN
+#define _MD_GET_SP(_t)		(_t)->md.context[7]
+
+#define CONTEXT(_th)		((_th)->md.context)
+
+
+/*
+** Initialize the thread context preparing it to execute _main.
+*/
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)	\
+{							\
+    *status = PR_TRUE;					\
+    if(_SETJMP(CONTEXT(_thread))) (*_main)();		\
+    _MD_GET_SP(_thread) = (int) ((_sp) - 128);		\
+}
+
+#define _MD_SWITCH_CONTEXT(_thread)	\
+    if (!_SETJMP(CONTEXT(_thread))) {	\
+	(_thread)->md.errcode = errno;	\
+	_PR_Schedule();			\
+    }
+
+/*
+** Restore a thread context, saved by _MD_SWITCH_CONTEXT
+*/
+#define _MD_RESTORE_CONTEXT(_thread)	\
+{					\
+    errno = (_thread)->md.errcode;	\
+    _MD_SET_CURRENT_THREAD(_thread);	\
+    _LONGJMP(CONTEXT(_thread), 1);	\
+}
+
+/*
+** Machine-dependent (MD) data structures.
+*/
+struct _MDThread {
+    _PR_CONTEXT_TYPE context;
+    int id;
+    int errcode;
+};
+
+struct _MDThreadStack {
+    PRInt8 notused;
+};
+
+struct _MDLock {
+    PRInt8 notused;
+};
+
+struct _MDSemaphore {
+    PRInt8 notused;
+};
+
+struct _MDCVar {
+    PRInt8 notused;
+};
+
+struct _MDSegment {
+    PRInt8 notused;
+};
+
+/*
+** md-specific cpu structure field
+*/
+#define _PR_MD_MAX_OSFD		FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD], fd_write_cnt[_PR_MD_MAX_OSFD], fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+    struct pollfd *ioq_pollfds;
+    int ioq_pollfds_size;
+#endif
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu)	PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
+struct _MDCPU {
+	struct _MDCPU_Unix md_unix;
+};
+
+#define _MD_INIT_LOCKS()
+#define _MD_NEW_LOCK(lock)		PR_SUCCESS
+#define _MD_FREE_LOCK(lock)
+#define _MD_LOCK(lock)
+#define _MD_UNLOCK(lock)
+#define _MD_INIT_IO()
+#define _MD_IOQ_LOCK()
+#define _MD_IOQ_UNLOCK()
+
+#define _MD_INTERVAL_USE_GTOD
+#define _MD_EARLY_INIT			_MD_EarlyInit
+#define _MD_FINAL_INIT			_PR_UnixInit
+#define _MD_INIT_RUNNING_CPU(cpu)	_MD_unix_init_running_cpu(cpu)
+#define _MD_INIT_THREAD			_MD_InitializeThread
+#define _MD_EXIT_THREAD(thread)
+#define	_MD_SUSPEND_THREAD(thread)
+#define	_MD_RESUME_THREAD(thread)
+#define _MD_CLEAN_THREAD(_thread)
+
+/*
+** We wrapped the select() call.  _MD_SELECT refers to the built-in,
+** unwrapped version.
+*/
+#define _MD_SELECT		select
+
+#define SA_RESTART 0
+
+#endif /* nspr_nto_defs_h___ */
diff --git a/pr/include/md/_openbsd.cfg b/pr/include/md/_openbsd.cfg
new file mode 100644
index 0000000..b68d6e9
--- /dev/null
+++ b/pr/include/md/_openbsd.cfg
@@ -0,0 +1,353 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef XP_UNIX
+#define XP_UNIX
+#endif
+
+#ifndef OPENBSD
+#define OPENBSD
+#endif
+
+#define PR_AF_INET6 24  /* same as AF_INET6 */
+
+#ifndef HAVE_LONG_LONG
+#define HAVE_LONG_LONG
+#endif
+
+#if defined(__i386__) || defined(__arm__)
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#undef	HAVE_ALIGNED_DOUBLES
+#undef	HAVE_ALIGNED_LONGLONGS
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   4
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  4
+#define PR_ALIGN_OF_POINTER 4
+
+#elif defined(__amd64__)
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+#define PR_ALIGN_OF_WORD    8
+
+#define PR_BYTES_PER_WORD_LOG2  3
+#define PR_BYTES_PER_DWORD_LOG2 3
+
+#define HAVE_ALIGNED_DOUBLES
+#define HAVE_ALIGNED_LONGLONGS
+
+#elif defined(__sparc_v9__)
+
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN 1
+#define HAVE_ALIGNED_DOUBLES
+#define HAVE_ALIGNED_LONGLONGS
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+
+#define PR_BYTES_PER_WORD_LOG2  3
+#define PR_BYTES_PER_DWORD_LOG2 3
+
+#elif defined(__sparc__)
+
+#undef IS_LITTLE_ENDIAN
+#define  IS_BIG_ENDIAN 1
+#define  HAVE_ALIGNED_DOUBLES
+#define  HAVE_ALIGNED_LONGLONGS
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 4
+
+#elif defined(__alpha__)
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#define	HAVE_ALIGNED_DOUBLES
+#define	HAVE_ALIGNED_LONGLONGS
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+
+#define PR_BYTES_PER_WORD_LOG2  3
+#define PR_BYTES_PER_DWORD_LOG2 3
+
+#elif defined(__powerpc__) || defined(__m68k__)
+
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN    1
+#undef	HAVE_ALIGNED_DOUBLES
+#undef	HAVE_ALIGNED_LONGLONGS
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   4
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  4
+#define PR_ALIGN_OF_POINTER 4
+
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#else
+
+#error Must define constants for type sizes here.
+
+#endif
+
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
+#define BYTES_PER_INT 		PR_BYTES_PER_INT
+#define BYTES_PER_INT64		PR_BYTES_PER_INT64
+#define BYTES_PER_LONG		PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE	PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD		PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD		PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE		PR_BITS_PER_BYTE
+#define BITS_PER_SHORT		PR_BITS_PER_SHORT
+#define BITS_PER_INT		PR_BITS_PER_INT
+#define BITS_PER_INT64		PR_BITS_PER_INT64
+#define BITS_PER_LONG		PR_BITS_PER_LONG
+#define BITS_PER_FLOAT		PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE		PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD		PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2	PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2	PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2	PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2	PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2	PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2	PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2 	PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2	PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT		PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT		PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG		PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64		PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT		PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE		PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER	PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD		PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
diff --git a/pr/include/md/_openbsd.h b/pr/include/md/_openbsd.h
new file mode 100644
index 0000000..666c177
--- /dev/null
+++ b/pr/include/md/_openbsd.h
@@ -0,0 +1,209 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_openbsd_defs_h___
+#define nspr_openbsd_defs_h___
+
+#include <sys/syscall.h>
+
+#define PR_LINKER_ARCH	"openbsd"
+#define _PR_SI_SYSNAME  "OPENBSD"
+#if defined(__i386__)
+#define _PR_SI_ARCHITECTURE "x86"
+#elif defined(__alpha__)
+#define _PR_SI_ARCHITECTURE "alpha"
+#elif defined(__amd64__)
+#define _PR_SI_ARCHITECTURE "amd64"
+#elif defined(__m68k__)
+#define _PR_SI_ARCHITECTURE "m68k"
+#elif defined(__powerpc__)
+#define _PR_SI_ARCHITECTURE "powerpc"
+#elif defined(__sparc__)
+#define _PR_SI_ARCHITECTURE "sparc"
+#elif defined(__arm__)
+#define _PR_SI_ARCHITECTURE "arm"
+#endif
+
+#define PR_DLL_SUFFIX		".so"
+
+#define _PR_VMBASE              0x30000000
+#define _PR_STACK_VMBASE	0x50000000
+#define _MD_DEFAULT_STACK_SIZE	65536L
+#define _MD_MMAP_FLAGS          MAP_PRIVATE
+
+#undef  HAVE_STACK_GROWING_UP
+#define HAVE_DLL
+#define USE_DLFCN
+#define _PR_HAVE_SOCKADDR_LEN
+#define _PR_HAVE_LARGE_OFF_T
+#define _PR_STAT_HAS_ST_ATIMESPEC
+#define _PR_POLL_AVAILABLE
+#define _PR_USE_POLL
+#define _PR_HAVE_SYSV_SEMAPHORES
+#define PR_HAVE_SYSV_NAMED_SHARED_MEMORY
+
+#define _PR_INET6
+#define _PR_HAVE_INET_NTOP
+#define _PR_HAVE_GETHOSTBYNAME2
+#define _PR_HAVE_GETADDRINFO
+#define _PR_INET6_PROBE
+
+#define USE_SETJMP
+
+#ifndef _PR_PTHREADS
+#include <setjmp.h>
+
+#define PR_CONTEXT_TYPE	sigjmp_buf
+
+#define CONTEXT(_th) ((_th)->md.context)
+
+#if defined(__i386__) || defined(__sparc__) || defined(__m68k__)
+#define JB_SP_INDEX 2
+#elif defined(__powerpc__)
+#define JB_SP_INDEX 1
+#elif defined(__alpha__)
+#define JB_SP_INDEX 34
+#elif defined(__amd64__)
+#define JB_SP_INDEX 6
+#elif defined(__arm__)
+#define JB_SP_INDEX 23
+#else
+#error "Need to define SP index in jmp_buf here"
+#endif
+#define _MD_GET_SP(_th)    (_th)->md.context[JB_SP_INDEX]
+
+#define PR_NUM_GCREGS	_JBLEN
+
+/*
+** Initialize a thread context to run "_main()" when started
+*/
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)  \
+{  \
+    *status = PR_TRUE;  \
+    if (sigsetjmp(CONTEXT(_thread), 1)) {  \
+        _main();  \
+    }  \
+    _MD_GET_SP(_thread) = (unsigned char*) ((_sp) - 64); \
+}
+
+#define _MD_SWITCH_CONTEXT(_thread)  \
+    if (!sigsetjmp(CONTEXT(_thread), 1)) {  \
+        (_thread)->md.errcode = errno;  \
+        _PR_Schedule();  \
+    }
+
+/*
+** Restore a thread context, saved by _MD_SWITCH_CONTEXT
+*/
+#define _MD_RESTORE_CONTEXT(_thread) \
+{   \
+    errno = (_thread)->md.errcode;  \
+    _MD_SET_CURRENT_THREAD(_thread);  \
+    siglongjmp(CONTEXT(_thread), 1);  \
+}
+
+/* Machine-dependent (MD) data structures */
+
+struct _MDThread {
+    PR_CONTEXT_TYPE context;
+    int id;
+    int errcode;
+};
+
+struct _MDThreadStack {
+    PRInt8 notused;
+};
+
+struct _MDLock {
+    PRInt8 notused;
+};
+
+struct _MDSemaphore {
+    PRInt8 notused;
+};
+
+struct _MDCVar {
+    PRInt8 notused;
+};
+
+struct _MDSegment {
+    PRInt8 notused;
+};
+
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
+struct _MDCPU {
+    struct _MDCPU_Unix md_unix;
+};
+
+#define _MD_INIT_LOCKS()
+#define _MD_NEW_LOCK(lock) PR_SUCCESS
+#define _MD_FREE_LOCK(lock)
+#define _MD_LOCK(lock)
+#define _MD_UNLOCK(lock)
+#define _MD_INIT_IO()
+#define _MD_IOQ_LOCK()
+#define _MD_IOQ_UNLOCK()
+
+#define _MD_INIT_RUNNING_CPU(cpu)       _MD_unix_init_running_cpu(cpu)
+#define _MD_INIT_THREAD                 _MD_InitializeThread
+#define _MD_EXIT_THREAD(thread)
+#define _MD_SUSPEND_THREAD(thread)      _MD_suspend_thread
+#define _MD_RESUME_THREAD(thread)       _MD_resume_thread
+#define _MD_CLEAN_THREAD(_thread)
+
+#endif /* ! _PR_PTHREADS */
+
+#define _MD_EARLY_INIT                  _MD_EarlyInit
+#define _MD_FINAL_INIT			_PR_UnixInit
+#define _PR_HAVE_CLOCK_MONOTONIC
+
+/*
+ * We wrapped the select() call.  _MD_SELECT refers to the built-in,
+ * unwrapped version.
+ */
+#define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
+#include <poll.h>
+#define _MD_POLL(fds,nfds,timeout) syscall(SYS_poll,fds,nfds,timeout)
+
+#if OpenBSD1_3 == 1L
+typedef unsigned int nfds_t;
+#endif
+
+#endif /* nspr_openbsd_defs_h___ */
diff --git a/pr/include/md/_os2.cfg b/pr/include/md/_os2.cfg
new file mode 100644
index 0000000..67c2ded
--- /dev/null
+++ b/pr/include/md/_os2.cfg
@@ -0,0 +1,121 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef XP_PC
+#define XP_PC
+#endif
+
+#ifndef XP_OS2
+#define XP_OS2
+#endif
+
+#ifndef OS2
+#define OS2
+#endif
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#ifdef NO_LONG_LONG
+#undef HAVE_LONG_LONG
+#else
+#ifndef HAVE_LONG_LONG
+#define HAVE_LONG_LONG 1
+#endif
+#endif
+
+#define PR_AF_INET6 24  /* same as AF_INET6 */
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD       4
+#define PR_BYTES_PER_DWORD	8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_WORD	32
+#define PR_BITS_PER_DWORD	64
+#define PR_BITS_PER_DOUBLE  64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_WORD_LOG2	5
+#define PR_BITS_PER_DWORD_LOG2	6
+#define PR_BITS_PER_DOUBLE_LOG2 6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   4
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  4
+#define PR_ALIGN_OF_WORD	4
+#define PR_ALIGN_OF_DWORD	8
+#define PR_ALIGN_OF_POINTER 4
+
+#define PR_BYTES_PER_WORD_LOG2	2
+#define PR_BYTES_PER_DWORD_LOG2	2
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE      PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT     PR_BYTES_PER_SHORT
+#define BYTES_PER_INT       PR_BYTES_PER_INT
+#define BYTES_PER_INT64     PR_BYTES_PER_INT64
+#define BYTES_PER_LONG      PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT     PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE    PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD      PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD     PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE       PR_BITS_PER_BYTE
+#define BITS_PER_SHORT      PR_BITS_PER_SHORT
+#define BITS_PER_INT        PR_BITS_PER_INT
+#define BITS_PER_INT64      PR_BITS_PER_INT64
+#define BITS_PER_LONG       PR_BITS_PER_LONG
+#define BITS_PER_FLOAT      PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE     PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD       PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2  PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2 PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2   PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2 PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2  PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2 PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2    PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2  PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT      PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT        PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG       PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64      PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT      PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE     PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER    PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD       PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2		PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2    PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2    PR_WORDS_PER_DWORD_LOG2
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
diff --git a/pr/include/md/_os2.h b/pr/include/md/_os2.h
new file mode 100644
index 0000000..330b291
--- /dev/null
+++ b/pr/include/md/_os2.h
@@ -0,0 +1,504 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_os2_defs_h___
+#define nspr_os2_defs_h___
+
+#ifndef NO_LONG_LONG
+#define INCL_LONGLONG
+#endif
+#define INCL_DOS
+#define INCL_DOSPROCESS
+#define INCL_DOSERRORS
+#define INCL_WIN
+#define INCL_WPS
+#include <os2.h>
+#include <sys/select.h>
+
+#include "prio.h"
+
+#include <errno.h>
+
+/*
+ * Internal configuration macros
+ */
+
+#define PR_LINKER_ARCH      "os2"
+#define _PR_SI_SYSNAME        "OS2"
+#define _PR_SI_ARCHITECTURE   "x86"    /* XXXMB hardcode for now */
+
+#define HAVE_DLL
+#define _PR_GLOBAL_THREADS_ONLY
+#undef  HAVE_THREAD_AFFINITY
+#define _PR_HAVE_THREADSAFE_GETHOST
+#define _PR_HAVE_ATOMIC_OPS
+#define HAVE_NETINET_TCP_H
+
+#define HANDLE unsigned long
+#define HINSTANCE HMODULE
+
+/* --- Common User-Thread/Native-Thread Definitions --------------------- */
+
+/* --- Globals --- */
+extern struct PRLock                      *_pr_schedLock;
+
+/* --- Typedefs --- */
+typedef void (*FiberFunc)(void *);
+
+#define PR_NUM_GCREGS           8
+typedef PRInt32	                PR_CONTEXT_TYPE[PR_NUM_GCREGS];
+#define GC_VMBASE               0x40000000
+#define GC_VMLIMIT              0x00FFFFFF
+typedef int (*FARPROC)();
+
+#define _MD_MAGIC_THREAD	0x22222222
+#define _MD_MAGIC_THREADSTACK	0x33333333
+#define _MD_MAGIC_SEGMENT	0x44444444
+#define _MD_MAGIC_DIR		0x55555555
+#define _MD_MAGIC_CV        0x66666666
+
+struct _MDSemaphore {
+   HEV sem;
+};
+
+struct _MDCPU {
+    int              unused;
+}; 
+
+struct _MDThread {
+    HEV              blocked_sema;      /* Threads block on this when waiting
+                                         * for IO or CondVar.
+                                         */
+    PRBool           inCVWaitQueue;     /* PR_TRUE if the thread is in the
+                                         * wait queue of some cond var.
+                                         * PR_FALSE otherwise.  */
+    TID              handle;            /* OS/2 thread handle */
+    void            *sp;                /* only valid when suspended */
+    PRUint32         magic;             /* for debugging */
+    PR_CONTEXT_TYPE  gcContext;         /* Thread context for GC */
+    struct PRThread *prev, *next;       /* used by the cvar wait queue to
+                                         * chain the PRThread structures
+                                         * together */
+};
+
+struct _MDThreadStack {
+    PRUint32           magic;          /* for debugging */
+};
+
+struct _MDSegment {
+    PRUint32           magic;          /* for debugging */
+};
+
+#undef PROFILE_LOCKS
+
+struct _MDDir {
+    HDIR           d_hdl;
+    union {
+        FILEFINDBUF3  small;
+        FILEFINDBUF3L large;
+    } d_entry;
+    PRBool           firstEntry;     /* Is this the entry returned
+                                      * by FindFirstFile()? */
+    PRUint32         magic;          /* for debugging */
+};
+
+struct _MDCVar {
+    PRUint32 magic;
+    struct PRThread *waitHead, *waitTail;  /* the wait queue: a doubly-
+                                            * linked list of threads
+                                            * waiting on this condition
+                                            * variable */
+    PRIntn nwait;                          /* number of threads in the
+                                            * wait queue */
+};
+
+#define _MD_CV_NOTIFIED_LENGTH 6
+typedef struct _MDNotified _MDNotified;
+struct _MDNotified {
+    PRIntn length;                     /* # of used entries in this
+                                        * structure */
+    struct {
+        struct _MDCVar *cv;            /* the condition variable notified */
+        PRIntn times;                  /* and the number of times notified */
+        struct PRThread *notifyHead;   /* list of threads to wake up */
+    } cv[_MD_CV_NOTIFIED_LENGTH];
+    _MDNotified *link;                 /* link to another of these, or NULL */
+};
+
+struct _MDLock {
+    HMTX mutex;                        /* this is recursive on OS/2 */
+
+    /*
+     * When notifying cvars, there is no point in actually
+     * waking up the threads waiting on the cvars until we've
+     * released the lock.  So, we temporarily record the cvars.
+     * When doing an unlock, we'll then wake up the waiting threads.
+     */
+    struct _MDNotified notified;     /* array of conditions notified */
+#ifdef PROFILE_LOCKS
+    PRInt32 hitcount;
+    PRInt32 misscount;
+#endif
+};
+
+struct _MDFileDesc {
+    PRInt32 osfd;    /* The osfd can come from one of three spaces:
+                      * - For stdin, stdout, and stderr, we are using
+                      *   the libc file handle (0, 1, 2), which is an int.
+                      * - For files and pipes, we are using OS/2 handles,
+                      *   which is a void*.
+                      * - For sockets, we are using int
+                      */
+};
+
+struct _MDProcess {
+   PID pid;
+};
+
+/* --- Misc stuff --- */
+#define _MD_GET_SP(thread)            (thread)->md.gcContext[6]
+
+/* --- IO stuff --- */
+
+#define _MD_OPEN                      (_PR_MD_OPEN)
+#define _MD_OPEN_FILE                 (_PR_MD_OPEN)
+#define _MD_READ                      (_PR_MD_READ)
+#define _MD_WRITE                     (_PR_MD_WRITE)
+#define _MD_WRITEV                    (_PR_MD_WRITEV)
+#define _MD_LSEEK                     (_PR_MD_LSEEK)
+#define _MD_LSEEK64                   (_PR_MD_LSEEK64)
+extern PRInt32 _MD_CloseFile(PRInt32 osfd);
+#define _MD_CLOSE_FILE                _MD_CloseFile
+#define _MD_GETFILEINFO               (_PR_MD_GETFILEINFO)
+#define _MD_GETFILEINFO64             (_PR_MD_GETFILEINFO64)
+#define _MD_GETOPENFILEINFO           (_PR_MD_GETOPENFILEINFO)
+#define _MD_GETOPENFILEINFO64         (_PR_MD_GETOPENFILEINFO64)
+#define _MD_STAT                      (_PR_MD_STAT)
+#define _MD_RENAME                    (_PR_MD_RENAME)
+#define _MD_ACCESS                    (_PR_MD_ACCESS)
+#define _MD_DELETE                    (_PR_MD_DELETE)
+#define _MD_MKDIR                     (_PR_MD_MKDIR)
+#define _MD_MAKE_DIR                  (_PR_MD_MKDIR)
+#define _MD_RMDIR                     (_PR_MD_RMDIR)
+#define _MD_LOCKFILE                  (_PR_MD_LOCKFILE)
+#define _MD_TLOCKFILE                 (_PR_MD_TLOCKFILE)
+#define _MD_UNLOCKFILE                (_PR_MD_UNLOCKFILE)
+
+/* --- Socket IO stuff --- */
+
+/* The ones that don't map directly may need to be re-visited... */
+#define _MD_EACCES                EACCES
+#define _MD_EADDRINUSE            EADDRINUSE
+#define _MD_EADDRNOTAVAIL         EADDRNOTAVAIL
+#define _MD_EAFNOSUPPORT          EAFNOSUPPORT
+#define _MD_EAGAIN                EWOULDBLOCK
+#define _MD_EALREADY              EALREADY
+#define _MD_EBADF                 EBADF
+#define _MD_ECONNREFUSED          ECONNREFUSED
+#define _MD_ECONNRESET            ECONNRESET
+#define _MD_EFAULT                SOCEFAULT
+#define _MD_EINPROGRESS           EINPROGRESS
+#define _MD_EINTR                 EINTR
+#define _MD_EINVAL                EINVAL
+#define _MD_EISCONN               EISCONN
+#define _MD_ENETUNREACH           ENETUNREACH
+#define _MD_ENOENT                ENOENT
+#define _MD_ENOTCONN              ENOTCONN
+#define _MD_ENOTSOCK              ENOTSOCK
+#define _MD_EOPNOTSUPP            EOPNOTSUPP
+#define _MD_EWOULDBLOCK           EWOULDBLOCK
+#define _MD_GET_SOCKET_ERROR()    sock_errno()
+#ifndef INADDR_LOOPBACK /* For some reason this is not defined in OS2 tcpip */
+/*  #define INADDR_LOOPBACK         INADDR_ANY */
+#endif  
+
+#define _MD_INIT_FILEDESC(fd)
+extern void _MD_MakeNonblock(PRFileDesc *f);
+#define _MD_MAKE_NONBLOCK             _MD_MakeNonblock
+#define _MD_INIT_FD_INHERITABLE       (_PR_MD_INIT_FD_INHERITABLE)
+#define _MD_QUERY_FD_INHERITABLE      (_PR_MD_QUERY_FD_INHERITABLE)
+#define _MD_SHUTDOWN                  (_PR_MD_SHUTDOWN)
+#define _MD_LISTEN                    _PR_MD_LISTEN
+extern PRInt32 _MD_CloseSocket(PRInt32 osfd);
+#define _MD_CLOSE_SOCKET              _MD_CloseSocket
+#define _MD_SENDTO                    (_PR_MD_SENDTO)
+#define _MD_RECVFROM                  (_PR_MD_RECVFROM)
+#define _MD_SOCKETPAIR                (_PR_MD_SOCKETPAIR)
+#define _MD_GETSOCKNAME               (_PR_MD_GETSOCKNAME)
+#define _MD_GETPEERNAME               (_PR_MD_GETPEERNAME)
+#define _MD_GETSOCKOPT                (_PR_MD_GETSOCKOPT)
+#define _MD_SETSOCKOPT                (_PR_MD_SETSOCKOPT)
+
+#define _MD_FSYNC                     _PR_MD_FSYNC
+#define _MD_SET_FD_INHERITABLE        (_PR_MD_SET_FD_INHERITABLE)
+
+#ifdef _PR_HAVE_ATOMIC_OPS
+#define _MD_INIT_ATOMIC()
+#define _MD_ATOMIC_INCREMENT          _PR_MD_ATOMIC_INCREMENT
+#define _MD_ATOMIC_ADD                _PR_MD_ATOMIC_ADD
+#define _MD_ATOMIC_DECREMENT          _PR_MD_ATOMIC_DECREMENT
+#define _MD_ATOMIC_SET                _PR_MD_ATOMIC_SET
+#endif
+
+#define _MD_INIT_IO                   (_PR_MD_INIT_IO)
+#define _MD_PR_POLL                   (_PR_MD_PR_POLL)
+
+#define _MD_SOCKET                    (_PR_MD_SOCKET)
+extern PRInt32 _MD_SocketAvailable(PRFileDesc *fd);
+#define _MD_SOCKETAVAILABLE           _MD_SocketAvailable
+#define _MD_PIPEAVAILABLE             _MD_SocketAvailable
+#define _MD_CONNECT                   (_PR_MD_CONNECT)
+extern PRInt32 _MD_Accept(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
+        PRIntervalTime timeout);
+#define _MD_ACCEPT                    _MD_Accept
+#define _MD_BIND                      (_PR_MD_BIND)
+#define _MD_RECV                      (_PR_MD_RECV)
+#define _MD_SEND                      (_PR_MD_SEND)
+
+/* --- Scheduler stuff --- */
+/* #define _MD_PAUSE_CPU                 _PR_MD_PAUSE_CPU */
+#define _MD_PAUSE_CPU
+
+/* --- DIR stuff --- */
+#define PR_DIRECTORY_SEPARATOR        '\\'
+#define PR_DIRECTORY_SEPARATOR_STR    "\\"
+#define PR_PATH_SEPARATOR		';'
+#define PR_PATH_SEPARATOR_STR		";"
+#define _MD_ERRNO()                   errno
+#define _MD_OPEN_DIR                  (_PR_MD_OPEN_DIR)
+#define _MD_CLOSE_DIR                 (_PR_MD_CLOSE_DIR)
+#define _MD_READ_DIR                  (_PR_MD_READ_DIR)
+
+/* --- Segment stuff --- */
+#define _MD_INIT_SEGS()
+#define _MD_ALLOC_SEGMENT(seg, size, vaddr)   0
+#define _MD_FREE_SEGMENT(seg)
+
+/* --- Environment Stuff --- */
+#define _MD_GET_ENV                 (_PR_MD_GET_ENV)
+#define _MD_PUT_ENV                 (_PR_MD_PUT_ENV)
+
+/* --- Threading Stuff --- */
+#define _MD_DEFAULT_STACK_SIZE      65536L
+#define _MD_INIT_THREAD             (_PR_MD_INIT_THREAD)
+#define _MD_INIT_ATTACHED_THREAD    (_PR_MD_INIT_THREAD)
+#define _MD_CREATE_THREAD           (_PR_MD_CREATE_THREAD)
+#define _MD_YIELD                   (_PR_MD_YIELD)
+#define _MD_SET_PRIORITY            (_PR_MD_SET_PRIORITY)
+#define _MD_CLEAN_THREAD            (_PR_MD_CLEAN_THREAD)
+#define _MD_SETTHREADAFFINITYMASK   (_PR_MD_SETTHREADAFFINITYMASK)
+#define _MD_GETTHREADAFFINITYMASK   (_PR_MD_GETTHREADAFFINITYMASK)
+#define _MD_EXIT_THREAD             (_PR_MD_EXIT_THREAD)
+#define _MD_SUSPEND_THREAD          (_PR_MD_SUSPEND_THREAD)
+#define _MD_RESUME_THREAD           (_PR_MD_RESUME_THREAD)
+#define _MD_SUSPEND_CPU             (_PR_MD_SUSPEND_CPU)
+#define _MD_RESUME_CPU              (_PR_MD_RESUME_CPU)
+#define _MD_WAKEUP_CPUS             (_PR_MD_WAKEUP_CPUS)
+#define _MD_BEGIN_SUSPEND_ALL()
+#define _MD_BEGIN_RESUME_ALL()
+#define _MD_END_SUSPEND_ALL()
+#define _MD_END_RESUME_ALL()
+
+/* --- Lock stuff --- */
+#define _PR_LOCK                      _MD_LOCK
+#define _PR_UNLOCK					  _MD_UNLOCK
+
+#define _MD_NEW_LOCK                  (_PR_MD_NEW_LOCK)
+#define _MD_FREE_LOCK(lock)           (DosCloseMutexSem((lock)->mutex))
+#define _MD_LOCK(lock)                (DosRequestMutexSem((lock)->mutex, SEM_INDEFINITE_WAIT))
+#define _MD_TEST_AND_LOCK(lock)       (DosRequestMutexSem((lock)->mutex, SEM_INDEFINITE_WAIT),0)
+#define _MD_UNLOCK                    (_PR_MD_UNLOCK)
+
+/* --- lock and cv waiting --- */
+#define _MD_WAIT                      (_PR_MD_WAIT)
+#define _MD_WAKEUP_WAITER             (_PR_MD_WAKEUP_WAITER)
+
+/* --- CVar ------------------- */
+#define _MD_WAIT_CV					  (_PR_MD_WAIT_CV)
+#define _MD_NEW_CV					  (_PR_MD_NEW_CV)
+#define _MD_FREE_CV					  (_PR_MD_FREE_CV)
+#define _MD_NOTIFY_CV				  (_PR_MD_NOTIFY_CV	)
+#define _MD_NOTIFYALL_CV			  (_PR_MD_NOTIFYALL_CV)
+
+   /* XXXMB- the IOQ stuff is certainly not working correctly yet. */
+/* extern  struct _MDLock              _pr_ioq_lock; */
+#define _MD_IOQ_LOCK()                
+#define _MD_IOQ_UNLOCK()              
+
+
+/* --- Initialization stuff --- */
+#define _MD_START_INTERRUPTS()
+#define _MD_STOP_INTERRUPTS()
+#define _MD_DISABLE_CLOCK_INTERRUPTS()
+#define _MD_ENABLE_CLOCK_INTERRUPTS()
+#define _MD_BLOCK_CLOCK_INTERRUPTS()
+#define _MD_UNBLOCK_CLOCK_INTERRUPTS()
+#define _MD_EARLY_INIT                (_PR_MD_EARLY_INIT)
+#define _MD_FINAL_INIT()
+#define _MD_EARLY_CLEANUP()
+#define _MD_INIT_CPUS()
+#define _MD_INIT_RUNNING_CPU(cpu)
+
+struct PRProcess;
+struct PRProcessAttr;
+
+#define _MD_CREATE_PROCESS _PR_CreateOS2Process
+extern struct PRProcess * _PR_CreateOS2Process(
+    const char *path,
+    char *const *argv,
+    char *const *envp,
+    const struct PRProcessAttr *attr
+);
+
+#define _MD_DETACH_PROCESS _PR_DetachOS2Process
+extern PRStatus _PR_DetachOS2Process(struct PRProcess *process);
+
+/* --- Wait for a child process to terminate --- */
+#define _MD_WAIT_PROCESS _PR_WaitOS2Process
+extern PRStatus _PR_WaitOS2Process(struct PRProcess *process, 
+    PRInt32 *exitCode);
+
+#define _MD_KILL_PROCESS _PR_KillOS2Process
+extern PRStatus _PR_KillOS2Process(struct PRProcess *process);
+
+#define _MD_CLEANUP_BEFORE_EXIT()
+#define _MD_EXIT                          (_PR_MD_EXIT)
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
+    PR_BEGIN_MACRO \
+    *status = PR_TRUE; \
+    PR_END_MACRO
+#define _MD_SWITCH_CONTEXT
+#define _MD_RESTORE_CONTEXT
+
+/* --- Intervals --- */
+#define _MD_INTERVAL_INIT                 (_PR_MD_INTERVAL_INIT)
+#define _MD_GET_INTERVAL                  (_PR_MD_GET_INTERVAL)
+#define _MD_INTERVAL_PER_SEC              (_PR_MD_INTERVAL_PER_SEC)
+#define _MD_INTERVAL_PER_MILLISEC()       (_PR_MD_INTERVAL_PER_SEC() / 1000)
+#define _MD_INTERVAL_PER_MICROSEC()       (_PR_MD_INTERVAL_PER_SEC() / 1000000)
+
+/* --- Native-Thread Specific Definitions ------------------------------- */
+
+typedef struct __NSPR_TLS
+{
+    struct PRThread  *_pr_thread_last_run;
+    struct PRThread  *_pr_currentThread;
+    struct _PRCPU    *_pr_currentCPU;
+} _NSPR_TLS;
+
+extern _NSPR_TLS*  pThreadLocalStorage;
+NSPR_API(void) _PR_MD_ENSURE_TLS(void);
+
+#define _MD_GET_ATTACHED_THREAD() pThreadLocalStorage->_pr_currentThread
+extern struct PRThread * _MD_CURRENT_THREAD(void);
+#define _MD_SET_CURRENT_THREAD(_thread) _PR_MD_ENSURE_TLS(); pThreadLocalStorage->_pr_currentThread = (_thread)
+
+#define _MD_LAST_THREAD() pThreadLocalStorage->_pr_thread_last_run
+#define _MD_SET_LAST_THREAD(_thread) _PR_MD_ENSURE_TLS(); pThreadLocalStorage->_pr_thread_last_run = (_thread)
+
+#define _MD_CURRENT_CPU() pThreadLocalStorage->_pr_currentCPU
+#define _MD_SET_CURRENT_CPU(_cpu) _PR_MD_ENSURE_TLS(); pThreadLocalStorage->_pr_currentCPU = (_cpu)
+
+/* lth. #define _MD_SET_INTSOFF(_val) (_pr_ints_off = (_val)) */
+/* lth. #define _MD_GET_INTSOFF() _pr_ints_off */
+/* lth. #define _MD_INCREMENT_INTSOFF() (_pr_ints_off++) */
+/* lth. #define _MD_DECREMENT_INTSOFF() (_pr_ints_off--) */
+
+/* --- Scheduler stuff --- */
+#define LOCK_SCHEDULER()                 0
+#define UNLOCK_SCHEDULER()               0
+#define _PR_LockSched()                	 0
+#define _PR_UnlockSched()                0
+
+/* --- Initialization stuff --- */
+#define _MD_INIT_LOCKS()
+
+/* --- Stack stuff --- */
+#define _MD_INIT_STACK(stack, redzone)
+#define _MD_CLEAR_STACK(stack)
+
+/* --- Memory-mapped files stuff --- */
+/* ReadOnly and WriteCopy modes are simulated on OS/2;
+ * ReadWrite mode is not supported.
+ */
+struct _MDFileMap {
+    PROffset64  maxExtent;
+};
+
+extern PRStatus _MD_CreateFileMap(struct PRFileMap *fmap, PRInt64 size);
+#define _MD_CREATE_FILE_MAP _MD_CreateFileMap
+
+extern PRInt32 _MD_GetMemMapAlignment(void);
+#define _MD_GET_MEM_MAP_ALIGNMENT _MD_GetMemMapAlignment
+
+extern void * _MD_MemMap(struct PRFileMap *fmap, PRInt64 offset,
+        PRUint32 len);
+#define _MD_MEM_MAP _MD_MemMap
+
+extern PRStatus _MD_MemUnmap(void *addr, PRUint32 size);
+#define _MD_MEM_UNMAP _MD_MemUnmap
+
+extern PRStatus _MD_CloseFileMap(struct PRFileMap *fmap);
+#define _MD_CLOSE_FILE_MAP _MD_CloseFileMap
+
+/* Some stuff for setting up thread contexts */
+typedef ULONG DWORD, *PDWORD;
+
+/* The following definitions and two structures are new in OS/2 Warp 4.0.
+ */
+#ifndef CONTEXT_CONTROL
+#define CONTEXT_CONTROL        0x00000001
+#define CONTEXT_INTEGER        0x00000002
+#define CONTEXT_SEGMENTS       0x00000004
+#define CONTEXT_FLOATING_POINT 0x00000008
+#define CONTEXT_FULL           0x0000000F
+
+#pragma pack(2)
+typedef struct _FPREG {
+    ULONG      losig;    /*  Low 32-bits of the significand. */
+    ULONG      hisig;    /*  High 32-bits of the significand. */
+    USHORT     signexp;  /*  Sign and exponent. */
+} FPREG;
+typedef struct _CONTEXTRECORD {
+    ULONG     ContextFlags;
+    ULONG     ctx_env[7];
+    FPREG     ctx_stack[8];
+    ULONG     ctx_SegGs;     /*  GS register. */
+    ULONG     ctx_SegFs;     /*  FS register. */
+    ULONG     ctx_SegEs;     /*  ES register. */
+    ULONG     ctx_SegDs;     /*  DS register. */
+    ULONG     ctx_RegEdi;    /*  EDI register. */
+    ULONG     ctx_RegEsi;    /*  ESI register. */
+    ULONG     ctx_RegEax;    /*  EAX register. */
+    ULONG     ctx_RegEbx;    /*  EBX register. */
+    ULONG     ctx_RegEcx;    /*  ECX register. */
+    ULONG     ctx_RegEdx;    /*  EDX register. */
+    ULONG     ctx_RegEbp;    /*  EBP register. */
+    ULONG     ctx_RegEip;    /*  EIP register. */
+    ULONG     ctx_SegCs;     /*  CS register. */
+    ULONG     ctx_EFlags;    /*  EFLAGS register. */
+    ULONG     ctx_RegEsp;    /*  ESP register. */
+    ULONG     ctx_SegSs;     /*  SS register. */
+} CONTEXTRECORD, *PCONTEXTRECORD;
+#pragma pack()
+#endif
+
+extern APIRET (* APIENTRY QueryThreadContext)(TID, ULONG, PCONTEXTRECORD);
+
+/*
+#define _pr_tid            (((PTIB2)_getTIBvalue(offsetof(TIB, tib_ptib2)))->tib2_ultid)
+#define _pr_current_Thread (_system_tls[_pr_tid-1].__pr_current_thread)
+*/
+
+/* Some simple mappings of Windows API's to OS/2 API's to make our lives a
+ * little bit easier.  Only add one here if it is a DIRECT mapping.  We are
+ * not emulating anything.  Just mapping.
+ */
+#define FreeLibrary(x) DosFreeModule((HMODULE)x)
+#define OutputDebugStringA(x)
+                               
+extern int _MD_os2_get_nonblocking_connect_error(int osfd);
+
+#endif /* nspr_os2_defs_h___ */
diff --git a/pr/include/md/_os2_errors.h b/pr/include/md/_os2_errors.h
new file mode 100644
index 0000000..fa96554
--- /dev/null
+++ b/pr/include/md/_os2_errors.h
@@ -0,0 +1,128 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_os2_errors_h___
+#define nspr_os2_errors_h___
+
+#include "md/_os2.h"
+#ifndef assert
+  #include <assert.h>
+#endif  
+
+NSPR_API(void) _MD_os2_map_default_error(PRInt32 err);
+#define	_PR_MD_MAP_DEFAULT_ERROR	_MD_os2_map_default_error
+
+NSPR_API(void) _MD_os2_map_opendir_error(PRInt32 err);
+#define	_PR_MD_MAP_OPENDIR_ERROR	_MD_os2_map_opendir_error
+
+NSPR_API(void) _MD_os2_map_closedir_error(PRInt32 err);
+#define	_PR_MD_MAP_CLOSEDIR_ERROR	_MD_os2_map_closedir_error
+
+NSPR_API(void) _MD_os2_readdir_error(PRInt32 err);
+#define	_PR_MD_MAP_READDIR_ERROR	_MD_os2_readdir_error
+
+NSPR_API(void) _MD_os2_map_delete_error(PRInt32 err);
+#define	_PR_MD_MAP_DELETE_ERROR	_MD_os2_map_delete_error
+
+NSPR_API(void) _MD_os2_map_stat_error(PRInt32 err);
+#define	_PR_MD_MAP_STAT_ERROR	_MD_os2_map_stat_error
+
+NSPR_API(void) _MD_os2_map_fstat_error(PRInt32 err);
+#define	_PR_MD_MAP_FSTAT_ERROR	_MD_os2_map_fstat_error
+
+NSPR_API(void) _MD_os2_map_rename_error(PRInt32 err);
+#define	_PR_MD_MAP_RENAME_ERROR	_MD_os2_map_rename_error
+
+NSPR_API(void) _MD_os2_map_access_error(PRInt32 err);
+#define	_PR_MD_MAP_ACCESS_ERROR	_MD_os2_map_access_error
+
+NSPR_API(void) _MD_os2_map_mkdir_error(PRInt32 err);
+#define	_PR_MD_MAP_MKDIR_ERROR	_MD_os2_map_mkdir_error
+
+NSPR_API(void) _MD_os2_map_rmdir_error(PRInt32 err);
+#define	_PR_MD_MAP_RMDIR_ERROR	_MD_os2_map_rmdir_error
+
+NSPR_API(void) _MD_os2_map_read_error(PRInt32 err);
+#define	_PR_MD_MAP_READ_ERROR	_MD_os2_map_read_error
+
+NSPR_API(void) _MD_os2_map_transmitfile_error(PRInt32 err);
+#define	_PR_MD_MAP_TRANSMITFILE_ERROR	_MD_os2_map_transmitfile_error
+
+NSPR_API(void) _MD_os2_map_write_error(PRInt32 err);
+#define	_PR_MD_MAP_WRITE_ERROR	_MD_os2_map_write_error
+
+NSPR_API(void) _MD_os2_map_lseek_error(PRInt32 err);
+#define	_PR_MD_MAP_LSEEK_ERROR	_MD_os2_map_lseek_error
+
+NSPR_API(void) _MD_os2_map_fsync_error(PRInt32 err);
+#define	_PR_MD_MAP_FSYNC_ERROR	_MD_os2_map_fsync_error
+
+NSPR_API(void) _MD_os2_map_close_error(PRInt32 err);
+#define	_PR_MD_MAP_CLOSE_ERROR	_MD_os2_map_close_error
+
+NSPR_API(void) _MD_os2_map_socket_error(PRInt32 err);
+#define	_PR_MD_MAP_SOCKET_ERROR	_MD_os2_map_socket_error
+
+NSPR_API(void) _MD_os2_map_recv_error(PRInt32 err);
+#define	_PR_MD_MAP_RECV_ERROR	_MD_os2_map_recv_error
+
+NSPR_API(void) _MD_os2_map_recvfrom_error(PRInt32 err);
+#define	_PR_MD_MAP_RECVFROM_ERROR	_MD_os2_map_recvfrom_error
+
+NSPR_API(void) _MD_os2_map_send_error(PRInt32 err);
+#define	_PR_MD_MAP_SEND_ERROR	_MD_os2_map_send_error
+
+NSPR_API(void) _MD_os2_map_sendto_error(PRInt32 err);
+#define	_PR_MD_MAP_SENDTO_ERROR	_MD_os2_map_sendto_error
+
+NSPR_API(void) _MD_os2_map_writev_error(int err);
+#define	_PR_MD_MAP_WRITEV_ERROR	_MD_os2_map_writev_error
+
+NSPR_API(void) _MD_os2_map_accept_error(PRInt32 err);
+#define	_PR_MD_MAP_ACCEPT_ERROR	_MD_os2_map_accept_error
+
+NSPR_API(void) _MD_os2_map_acceptex_error(PRInt32 err);
+#define	_PR_MD_MAP_ACCEPTEX_ERROR	_MD_os2_map_acceptex_error
+
+NSPR_API(void) _MD_os2_map_connect_error(PRInt32 err);
+#define	_PR_MD_MAP_CONNECT_ERROR	_MD_os2_map_connect_error
+
+NSPR_API(void) _MD_os2_map_bind_error(PRInt32 err);
+#define	_PR_MD_MAP_BIND_ERROR	_MD_os2_map_bind_error
+
+NSPR_API(void) _MD_os2_map_listen_error(PRInt32 err);
+#define	_PR_MD_MAP_LISTEN_ERROR	_MD_os2_map_listen_error
+
+NSPR_API(void) _MD_os2_map_shutdown_error(PRInt32 err);
+#define	_PR_MD_MAP_SHUTDOWN_ERROR	_MD_os2_map_shutdown_error
+
+NSPR_API(void) _MD_os2_map_socketpair_error(int err);
+#define	_PR_MD_MAP_SOCKETPAIR_ERROR	_MD_os2_map_socketpair_error
+
+NSPR_API(void) _MD_os2_map_getsockname_error(PRInt32 err);
+#define	_PR_MD_MAP_GETSOCKNAME_ERROR	_MD_os2_map_getsockname_error
+
+NSPR_API(void) _MD_os2_map_getpeername_error(PRInt32 err);
+#define	_PR_MD_MAP_GETPEERNAME_ERROR	_MD_os2_map_getpeername_error
+
+NSPR_API(void) _MD_os2_map_getsockopt_error(PRInt32 err);
+#define	_PR_MD_MAP_GETSOCKOPT_ERROR	_MD_os2_map_getsockopt_error
+
+NSPR_API(void) _MD_os2_map_setsockopt_error(PRInt32 err);
+#define	_PR_MD_MAP_SETSOCKOPT_ERROR	_MD_os2_map_setsockopt_error
+
+NSPR_API(void) _MD_os2_map_open_error(PRInt32 err);
+#define	_PR_MD_MAP_OPEN_ERROR	_MD_os2_map_open_error
+
+NSPR_API(void) _MD_os2_map_gethostname_error(PRInt32 err);
+#define	_PR_MD_MAP_GETHOSTNAME_ERROR	_MD_os2_map_gethostname_error
+
+NSPR_API(void) _MD_os2_map_select_error(PRInt32 err);
+#define	_PR_MD_MAP_SELECT_ERROR	_MD_os2_map_select_error
+
+NSPR_API(void) _MD_os2_map_lockf_error(int err);
+#define _PR_MD_MAP_LOCKF_ERROR  _MD_os2_map_lockf_error
+
+#endif /* nspr_os2_errors_h___ */
diff --git a/pr/include/md/_osf1.cfg b/pr/include/md/_osf1.cfg
new file mode 100644
index 0000000..7999402
--- /dev/null
+++ b/pr/include/md/_osf1.cfg
@@ -0,0 +1,116 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef XP_UNIX
+#define XP_UNIX
+#endif
+
+#ifndef OSF1
+#define OSF1
+#endif
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#ifndef HAVE_LONG_LONG
+#define	HAVE_LONG_LONG
+#endif
+#define HAVE_ALIGNED_DOUBLES
+#define HAVE_ALIGNED_LONGLONGS
+#ifndef IS_64
+#define IS_64
+#endif
+
+#define PR_AF_INET6 26  /* same as AF_INET6 */
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   6
+
+#define PR_BYTES_PER_WORD_LOG2  3
+#define PR_BYTES_PER_DWORD_LOG2 3
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+
+#define _PR_POLL_BACKCOMPAT
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
+#define BYTES_PER_INT 		PR_BYTES_PER_INT
+#define BYTES_PER_INT64		PR_BYTES_PER_INT64
+#define BYTES_PER_LONG		PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE	PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD		PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD		PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE		PR_BITS_PER_BYTE
+#define BITS_PER_SHORT		PR_BITS_PER_SHORT
+#define BITS_PER_INT		PR_BITS_PER_INT
+#define BITS_PER_INT64		PR_BITS_PER_INT64
+#define BITS_PER_LONG		PR_BITS_PER_LONG
+#define BITS_PER_FLOAT		PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE		PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD		PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2	PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2	PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2	PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2	PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2	PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2	PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2 	PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2	PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT		PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT		PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG		PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64		PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT		PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE		PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER	PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD		PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
diff --git a/pr/include/md/_osf1.h b/pr/include/md/_osf1.h
new file mode 100644
index 0000000..57445f7
--- /dev/null
+++ b/pr/include/md/_osf1.h
@@ -0,0 +1,222 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_osf1_defs_h___
+#define nspr_osf1_defs_h___
+
+/*
+ * Internal configuration macros
+ */
+
+#define PR_LINKER_ARCH	"osf"
+#define _PR_SI_SYSNAME	"OSF"
+#define _PR_SI_ARCHITECTURE "alpha"
+#define PR_DLL_SUFFIX		".so"
+
+#define _PR_VMBASE              0x30000000
+#define _PR_STACK_VMBASE        0x50000000
+#define _MD_DEFAULT_STACK_SIZE  131072L
+#define _MD_MMAP_FLAGS          MAP_PRIVATE
+
+#undef  HAVE_STACK_GROWING_UP
+#undef 	HAVE_WEAK_IO_SYMBOLS
+#undef 	HAVE_WEAK_MALLOC_SYMBOLS
+#define HAVE_DLL
+#define HAVE_BSD_FLOCK
+
+#define NEED_TIME_R
+#define USE_DLFCN
+
+#define _PR_POLL_AVAILABLE
+#define _PR_USE_POLL
+#define _PR_STAT_HAS_ONLY_ST_ATIME
+#define _PR_HAVE_LARGE_OFF_T
+#define _PR_HAVE_GETIPNODEBYNAME
+#define _PR_HAVE_GETIPNODEBYADDR
+#define _PR_HAVE_GETADDRINFO
+#define _PR_INET6_PROBE
+#ifdef _PR_INET6
+#define _PR_HAVE_INET_NTOP
+#else
+#define AF_INET6 26
+#ifndef AI_CANONNAME
+#define AI_CANONNAME 0x00000002
+struct addrinfo {
+    int              ai_flags;
+    int              ai_family;
+    int              ai_socktype;
+    int              ai_protocol;
+    size_t           ai_addrlen;
+    char            *ai_canonname;
+    struct sockaddr *ai_addr;
+    struct addrinfo *ai_next;
+};
+#endif
+#define AI_V4MAPPED 0x00000010
+#define AI_ALL      0x00000008
+#define AI_ADDRCONFIG 0x00000020
+#endif
+#define _PR_HAVE_POSIX_SEMAPHORES
+#define PR_HAVE_POSIX_NAMED_SHARED_MEMORY
+
+#define USE_SETJMP
+
+#include <setjmp.h>
+
+/*
+ * A jmp_buf is actually a struct sigcontext.  The sc_sp field of
+ * struct sigcontext is the stack pointer.
+ */
+#define _MD_GET_SP(_t) (((struct sigcontext *) (_t)->md.context)->sc_sp)
+#define PR_NUM_GCREGS _JBLEN
+#define CONTEXT(_th) ((_th)->md.context)
+
+/*
+** Initialize a thread context to run "_main()" when started
+*/
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)	      \
+{									  \
+        *status = PR_TRUE;              \
+    if (setjmp(CONTEXT(_thread))) {				\
+	(*_main)();						\
+    }								\
+    _MD_GET_SP(_thread) = (long) ((_sp) - 64);			\
+    _MD_GET_SP(_thread) &= ~15;					\
+}
+
+#define _MD_SWITCH_CONTEXT(_thread)  \
+    if (!setjmp(CONTEXT(_thread))) { \
+	(_thread)->md.errcode = errno;  \
+	_PR_Schedule();		     \
+    }
+
+/*
+** Restore a thread context, saved by _MD_SWITCH_CONTEXT
+*/
+#define _MD_RESTORE_CONTEXT(_thread) \
+{				     \
+    errno = (_thread)->md.errcode;     \
+    _MD_SET_CURRENT_THREAD(_thread);	\
+    longjmp(CONTEXT(_thread), 1);    \
+}
+
+/* Machine-dependent (MD) data structures */
+
+struct _MDThread {
+    jmp_buf context;
+    int id;
+    int errcode;
+};
+
+struct _MDThreadStack {
+    PRInt8 notused;
+};
+
+struct _MDLock {
+    PRInt8 notused;
+};
+
+struct _MDSemaphore {
+    PRInt8 notused;
+};
+
+struct _MDCVar {
+    PRInt8 notused;
+};
+
+struct _MDSegment {
+    PRInt8 notused;
+};
+
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
+struct _MDCPU {
+	struct _MDCPU_Unix md_unix;
+};
+
+#ifndef _PR_PTHREADS
+#define _MD_INIT_LOCKS()
+#endif
+#define _MD_NEW_LOCK(lock) PR_SUCCESS
+#define _MD_FREE_LOCK(lock)
+#define _MD_LOCK(lock)
+#define _MD_UNLOCK(lock)
+#define _MD_INIT_IO()
+#define _MD_IOQ_LOCK()
+#define _MD_IOQ_UNLOCK()
+
+/*
+ * The following are copied from _sunos.h, _aix.h.  This means
+ * some of them should probably be moved into _unixos.h.  But
+ * _irix.h seems to be quite different in regard to these macros.
+ */
+#define _MD_INTERVAL_USE_GTOD
+
+#define _MD_EARLY_INIT		_MD_EarlyInit
+#define _MD_FINAL_INIT		_PR_UnixInit
+#define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
+#define _MD_INIT_THREAD         _MD_InitializeThread
+#define _MD_EXIT_THREAD(thread)
+#define	_MD_SUSPEND_THREAD(thread)
+#define	_MD_RESUME_THREAD(thread)
+#define _MD_CLEAN_THREAD(_thread)
+
+/* The following defines unwrapped versions of select() and poll(). */
+#include <sys/time.h>
+extern int __select (int, fd_set *, fd_set *, fd_set *, struct timeval *);
+#define _MD_SELECT              __select
+
+#include <sys/poll.h>
+#define _MD_POLL __poll
+extern int __poll(struct pollfd filedes[], unsigned int nfds, int timeout);
+
+/*
+ * Atomic operations
+ */
+#ifdef OSF1_HAVE_MACHINE_BUILTINS_H
+#include <machine/builtins.h>
+#define _PR_HAVE_ATOMIC_OPS
+#define _MD_INIT_ATOMIC()
+#define _MD_ATOMIC_INCREMENT(val) (__ATOMIC_INCREMENT_LONG(val) + 1)
+#define _MD_ATOMIC_ADD(ptr, val)  (__ATOMIC_ADD_LONG(ptr, val) + val)
+#define _MD_ATOMIC_DECREMENT(val) (__ATOMIC_DECREMENT_LONG(val) - 1)
+#define _MD_ATOMIC_SET(val, newval) __ATOMIC_EXCH_LONG(val, newval)
+#endif /* OSF1_HAVE_MACHINE_BUILTINS_H */
+
+#endif /* nspr_osf1_defs_h___ */
diff --git a/pr/include/md/_pcos.h b/pr/include/md/_pcos.h
new file mode 100644
index 0000000..3b4f205
--- /dev/null
+++ b/pr/include/md/_pcos.h
@@ -0,0 +1,51 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef prpcos_h___
+#define prpcos_h___
+
+#define PR_DLL_SUFFIX		".dll"
+
+#include <stdlib.h>
+
+#define DIRECTORY_SEPARATOR         '\\'
+#define DIRECTORY_SEPARATOR_STR     "\\"
+#define PATH_SEPARATOR              ';'
+
+/*
+** Routines for processing command line arguments
+*/
+PR_BEGIN_EXTERN_C
+#ifndef XP_OS2
+extern char *optarg;
+extern int optind;
+extern int getopt(int argc, char **argv, char *spec);
+#endif
+PR_END_EXTERN_C
+
+
+/*
+** Definitions of directory structures amd functions
+** These definitions are from:
+**      <dirent.h>
+*/
+#ifdef XP_OS2
+#include <sys/types.h>
+#endif
+#include <sys/stat.h>
+#include <io.h>
+#include <fcntl.h>          /* O_BINARY */
+
+#ifdef OS2
+extern PRStatus _MD_OS2GetHostName(char *name, PRUint32 namelen);
+#define _MD_GETHOSTNAME _MD_OS2GetHostName
+#else
+extern PRStatus _MD_WindowsGetHostName(char *name, PRUint32 namelen);
+#define _MD_GETHOSTNAME _MD_WindowsGetHostName
+extern PRStatus _MD_WindowsGetSysInfo(PRSysInfo cmd, char *name, PRUint32 namelen);
+#define _MD_GETSYSINFO _MD_WindowsGetSysInfo
+#endif
+
+#endif /* prpcos_h___ */
diff --git a/pr/include/md/_pth.h b/pr/include/md/_pth.h
new file mode 100644
index 0000000..eeeef04
--- /dev/null
+++ b/pr/include/md/_pth.h
@@ -0,0 +1,270 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_pth_defs_h_
+#define nspr_pth_defs_h_
+
+/*
+** Appropriate definitions of entry points not used in a pthreads world
+*/
+#define _PR_MD_BLOCK_CLOCK_INTERRUPTS()
+#define _PR_MD_UNBLOCK_CLOCK_INTERRUPTS()
+#define _PR_MD_DISABLE_CLOCK_INTERRUPTS()
+#define _PR_MD_ENABLE_CLOCK_INTERRUPTS()
+
+/* In good standards fashion, the DCE threads (based on posix-4) are not
+ * quite the same as newer posix implementations.  These are mostly name
+ * changes and small differences, so macros usually do the trick
+ */
+#ifdef _PR_DCETHREADS
+#define _PT_PTHREAD_MUTEXATTR_INIT        pthread_mutexattr_create
+#define _PT_PTHREAD_MUTEXATTR_DESTROY     pthread_mutexattr_delete
+#define _PT_PTHREAD_MUTEX_INIT(m, a)      pthread_mutex_init(&(m), a)
+#define _PT_PTHREAD_MUTEX_IS_LOCKED(m)    (0 == pthread_mutex_trylock(&(m)))
+#define _PT_PTHREAD_CONDATTR_INIT         pthread_condattr_create
+#define _PT_PTHREAD_COND_INIT(m, a)       pthread_cond_init(&(m), a)
+#define _PT_PTHREAD_CONDATTR_DESTROY      pthread_condattr_delete
+
+/* Notes about differences between DCE threads and pthreads 10:
+ *   1. pthread_mutex_trylock returns 1 when it locks the mutex
+ *      0 when it does not.  The latest pthreads has a set of errno-like
+ *      return values.
+ *   2. return values from pthread_cond_timedwait are different.
+ *
+ *
+ *
+ */
+#elif defined(BSDI)
+/*
+ * Mutex and condition attributes are not supported.  The attr
+ * argument to pthread_mutex_init() and pthread_cond_init() must
+ * be passed as NULL.
+ *
+ * The memset calls in _PT_PTHREAD_MUTEX_INIT and _PT_PTHREAD_COND_INIT
+ * are to work around BSDI's using a single bit to indicate a mutex
+ * or condition variable is initialized.  This entire BSDI section
+ * will go away when BSDI releases updated threads libraries for
+ * BSD/OS 3.1 and 4.0.
+ */
+#define _PT_PTHREAD_MUTEXATTR_INIT(x)     0
+#define _PT_PTHREAD_MUTEXATTR_DESTROY(x)  /* */
+#define _PT_PTHREAD_MUTEX_INIT(m, a)      (memset(&(m), 0, sizeof(m)), \
+                                      pthread_mutex_init(&(m), NULL))
+#define _PT_PTHREAD_MUTEX_IS_LOCKED(m)    (EBUSY == pthread_mutex_trylock(&(m)))
+#define _PT_PTHREAD_CONDATTR_INIT(x)      0
+#define _PT_PTHREAD_CONDATTR_DESTROY(x)   /* */
+#define _PT_PTHREAD_COND_INIT(m, a)       (memset(&(m), 0, sizeof(m)), \
+                                      pthread_cond_init(&(m), NULL))
+#else
+#define _PT_PTHREAD_MUTEXATTR_INIT        pthread_mutexattr_init
+#define _PT_PTHREAD_MUTEXATTR_DESTROY     pthread_mutexattr_destroy
+#define _PT_PTHREAD_MUTEX_INIT(m, a)      pthread_mutex_init(&(m), &(a))
+#if defined(FREEBSD)
+#define _PT_PTHREAD_MUTEX_IS_LOCKED(m)    pt_pthread_mutex_is_locked(&(m))
+#else
+#define _PT_PTHREAD_MUTEX_IS_LOCKED(m)    (EBUSY == pthread_mutex_trylock(&(m)))
+#endif
+#if defined(ANDROID)
+/* Conditional attribute init and destroy aren't implemented in bionic. */
+#define _PT_PTHREAD_CONDATTR_INIT(x)      0
+#define _PT_PTHREAD_CONDATTR_DESTROY(x)   /* */
+#else
+#define _PT_PTHREAD_CONDATTR_INIT         pthread_condattr_init
+#define _PT_PTHREAD_CONDATTR_DESTROY      pthread_condattr_destroy
+#endif
+#define _PT_PTHREAD_COND_INIT(m, a)       pthread_cond_init(&(m), &(a))
+#endif
+
+/* The pthreads standard does not specify an invalid value for the
+ * pthread_t handle.  (0 is usually an invalid pthread identifier
+ * but there are exceptions, for example, DG/UX.)  These macros
+ * define a way to set the handle to or compare the handle with an
+ * invalid identifier.  These macros are not portable and may be
+ * more of a problem as we adapt to more pthreads implementations.
+ * They are only used in the PRMonitor functions.  Do not use them
+ * in new code.
+ *
+ * Unfortunately some of our clients depend on certain properties
+ * of our PRMonitor implementation, preventing us from replacing
+ * it by a portable implementation.
+ * - High-performance servers like the fact that PR_EnterMonitor
+ *   only calls PR_Lock and PR_ExitMonitor only calls PR_Unlock.
+ *   (A portable implementation would use a PRLock and a PRCondVar
+ *   to implement the recursive lock in a monitor and call both
+ *   PR_Lock and PR_Unlock in PR_EnterMonitor and PR_ExitMonitor.)
+ *   Unfortunately this forces us to read the monitor owner field
+ *   without holding a lock.
+ * - One way to make it safe to read the monitor owner field
+ *   without holding a lock is to make that field a PRThread*
+ *   (one should be able to read a pointer with a single machine
+ *   instruction).  However, PR_GetCurrentThread calls calloc if
+ *   it is called by a thread that was not created by NSPR.  The
+ *   malloc tracing tools in the Mozilla client use PRMonitor for
+ *   locking in their malloc, calloc, and free functions.  If
+ *   PR_EnterMonitor calls any of these functions, infinite
+ *   recursion ensues.
+ */
+#if defined(_PR_DCETHREADS)
+#define _PT_PTHREAD_INVALIDATE_THR_HANDLE(t) \
+	memset(&(t), 0, sizeof(pthread_t))
+#define _PT_PTHREAD_THR_HANDLE_IS_INVALID(t) \
+	(!memcmp(&(t), &pt_zero_tid, sizeof(pthread_t)))
+#define _PT_PTHREAD_COPY_THR_HANDLE(st, dt)   (dt) = (st)
+#elif defined(IRIX) || defined(OSF1) || defined(AIX) || defined(SOLARIS) \
+	|| defined(LINUX) || defined(__GNU__) || defined(__GLIBC__) \
+	|| defined(HPUX) || defined(FREEBSD) \
+	|| defined(NETBSD) || defined(OPENBSD) || defined(BSDI) \
+	|| defined(NTO) || defined(DARWIN) \
+	|| defined(UNIXWARE) || defined(RISCOS)	|| defined(SYMBIAN)
+#define _PT_PTHREAD_INVALIDATE_THR_HANDLE(t)  (t) = 0
+#define _PT_PTHREAD_THR_HANDLE_IS_INVALID(t)  (t) == 0
+#define _PT_PTHREAD_COPY_THR_HANDLE(st, dt)   (dt) = (st)
+#else 
+#error "pthreads is not supported for this architecture"
+#endif
+
+#if defined(_PR_DCETHREADS)
+#define _PT_PTHREAD_ATTR_INIT            pthread_attr_create
+#define _PT_PTHREAD_ATTR_DESTROY         pthread_attr_delete
+#define _PT_PTHREAD_CREATE(t, a, f, r)   pthread_create(t, a, f, r) 
+#define _PT_PTHREAD_KEY_CREATE           pthread_keycreate
+#define _PT_PTHREAD_ATTR_SETSCHEDPOLICY  pthread_attr_setsched
+#define _PT_PTHREAD_ATTR_GETSTACKSIZE(a, s) \
+                                     (*(s) = pthread_attr_getstacksize(*(a)), 0)
+#define _PT_PTHREAD_GETSPECIFIC(k, r) \
+		pthread_getspecific((k), (pthread_addr_t *) &(r))
+#elif defined(_PR_PTHREADS)
+#define _PT_PTHREAD_ATTR_INIT            pthread_attr_init
+#define _PT_PTHREAD_ATTR_DESTROY         pthread_attr_destroy
+#define _PT_PTHREAD_CREATE(t, a, f, r)   pthread_create(t, &a, f, r) 
+#define _PT_PTHREAD_KEY_CREATE           pthread_key_create
+#define _PT_PTHREAD_ATTR_SETSCHEDPOLICY  pthread_attr_setschedpolicy
+#define _PT_PTHREAD_ATTR_GETSTACKSIZE(a, s) pthread_attr_getstacksize(a, s)
+#define _PT_PTHREAD_GETSPECIFIC(k, r)    (r) = pthread_getspecific(k)
+#else
+#error "Cannot determine pthread strategy"
+#endif
+
+#if defined(_PR_DCETHREADS)
+#define _PT_PTHREAD_EXPLICIT_SCHED      _PT_PTHREAD_DEFAULT_SCHED
+#endif
+
+/*
+ * pthread_mutex_trylock returns different values in DCE threads and
+ * pthreads.
+ */
+#if defined(_PR_DCETHREADS)
+#define PT_TRYLOCK_SUCCESS 1
+#define PT_TRYLOCK_BUSY    0
+#else
+#define PT_TRYLOCK_SUCCESS 0
+#define PT_TRYLOCK_BUSY    EBUSY
+#endif
+
+/*
+ * These platforms don't have sigtimedwait()
+ */
+#if (defined(AIX) && !defined(AIX4_3_PLUS)) \
+	|| defined(LINUX) || defined(__GNU__)|| defined(__GLIBC__) \
+	|| defined(FREEBSD) || defined(NETBSD) || defined(OPENBSD) \
+	|| defined(BSDI) || defined(UNIXWARE) \
+	|| defined(DARWIN) || defined(SYMBIAN)
+#define PT_NO_SIGTIMEDWAIT
+#endif
+
+#if defined(OSF1)
+#define PT_PRIO_MIN            PRI_OTHER_MIN
+#define PT_PRIO_MAX            PRI_OTHER_MAX
+#elif defined(IRIX)
+#include <sys/sched.h>
+#define PT_PRIO_MIN            PX_PRIO_MIN
+#define PT_PRIO_MAX            PX_PRIO_MAX
+#elif defined(AIX)
+#include <sys/priv.h>
+#include <sys/sched.h>
+#ifndef PTHREAD_CREATE_JOINABLE
+#define PTHREAD_CREATE_JOINABLE     PTHREAD_CREATE_UNDETACHED
+#endif
+#define PT_PRIO_MIN            DEFAULT_PRIO
+#define PT_PRIO_MAX            DEFAULT_PRIO
+#elif defined(HPUX)
+
+#if defined(_PR_DCETHREADS)
+#define PT_PRIO_MIN            PRI_OTHER_MIN
+#define PT_PRIO_MAX            PRI_OTHER_MAX
+#else /* defined(_PR_DCETHREADS) */
+#include <sys/sched.h>
+#define PT_PRIO_MIN            sched_get_priority_min(SCHED_OTHER)
+#define PT_PRIO_MAX            sched_get_priority_max(SCHED_OTHER)
+#endif /* defined(_PR_DCETHREADS) */
+
+#elif defined(LINUX) || defined(__GNU__) || defined(__GLIBC__) \
+	|| defined(FREEBSD) || defined(SYMBIAN)
+#define PT_PRIO_MIN            sched_get_priority_min(SCHED_OTHER)
+#define PT_PRIO_MAX            sched_get_priority_max(SCHED_OTHER)
+#elif defined(NTO)
+/*
+ * Neutrino has functions that return the priority range but
+ * they return invalid numbers, so I just hard coded these here
+ * for now.  Jerry.Kirk@Nexarecorp.com
+ */
+#define PT_PRIO_MIN            0
+#define PT_PRIO_MAX            30
+#elif defined(SOLARIS)
+/*
+ * Solaris doesn't seem to have macros for the min/max priorities.
+ * The range of 0-127 is mentioned in the pthread_setschedparam(3T)
+ * man pages, and pthread_setschedparam indeed allows 0-127.  However,
+ * pthread_attr_setschedparam does not allow 0; it allows 1-127.
+ */
+#define PT_PRIO_MIN            1
+#define PT_PRIO_MAX            127
+#elif defined(OPENBSD)
+#define PT_PRIO_MIN            0
+#define PT_PRIO_MAX            31
+#elif defined(NETBSD) \
+	|| defined(BSDI) || defined(DARWIN) || defined(UNIXWARE) \
+	|| defined(RISCOS) /* XXX */
+#define PT_PRIO_MIN            0
+#define PT_PRIO_MAX            126
+#else
+#error "pthreads is not supported for this architecture"
+#endif
+
+/*
+ * The _PT_PTHREAD_YIELD function is called from a signal handler.
+ * Needed for garbage collection -- Look at PR_Suspend/PR_Resume
+ * implementation.
+ */
+#if defined(_PR_DCETHREADS)
+#define _PT_PTHREAD_YIELD()            	pthread_yield()
+#elif defined(OSF1)
+/*
+ * sched_yield can't be called from a signal handler.  Must use
+ * the _np version.
+ */
+#define _PT_PTHREAD_YIELD()            	pthread_yield_np()
+#elif defined(AIX)
+extern int (*_PT_aix_yield_fcn)();
+#define _PT_PTHREAD_YIELD()			(*_PT_aix_yield_fcn)()
+#elif defined(IRIX)
+#include <time.h>
+#define _PT_PTHREAD_YIELD() \
+    PR_BEGIN_MACRO               				\
+		struct timespec onemillisec = {0};		\
+		onemillisec.tv_nsec = 1000000L;			\
+        nanosleep(&onemillisec,NULL);			\
+    PR_END_MACRO
+#elif defined(HPUX) || defined(SOLARIS) \
+	|| defined(LINUX) || defined(__GNU__) || defined(__GLIBC__) \
+	|| defined(FREEBSD) || defined(NETBSD) || defined(OPENBSD) \
+	|| defined(BSDI) || defined(NTO) || defined(DARWIN) \
+	|| defined(UNIXWARE) || defined(RISCOS) || defined(SYMBIAN)
+#define _PT_PTHREAD_YIELD()            	sched_yield()
+#else
+#error "Need to define _PT_PTHREAD_YIELD for this platform"
+#endif
+
+#endif /* nspr_pth_defs_h_ */
diff --git a/pr/include/md/_qnx.cfg b/pr/include/md/_qnx.cfg
new file mode 100644
index 0000000..a459b8c
--- /dev/null
+++ b/pr/include/md/_qnx.cfg
@@ -0,0 +1,64 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef XP_UNIX
+#define XP_UNIX
+#endif
+
+#ifndef QNX
+#define QNX
+#endif
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#undef  HAVE_LONG_LONG
+#undef	HAVE_ALIGNED_DOUBLES
+#undef	HAVE_ALIGNED_LONGLONGS
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   1
+#define PR_ALIGN_OF_INT     1
+#define PR_ALIGN_OF_LONG    1
+#define PR_ALIGN_OF_INT64   1
+#define PR_ALIGN_OF_FLOAT   1
+#define PR_ALIGN_OF_DOUBLE  1
+#define PR_ALIGN_OF_POINTER 1
+#define PR_ALIGN_OF_WORD    1
+
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+#define PR_WORDS_PER_DWORD_LOG2  1
+
+#endif /* nspr_cpucfg___ */
diff --git a/pr/include/md/_qnx.h b/pr/include/md/_qnx.h
new file mode 100644
index 0000000..d3bba6d
--- /dev/null
+++ b/pr/include/md/_qnx.h
@@ -0,0 +1,182 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_qnx_defs_h___
+#define nspr_qnx_defs_h___
+
+/*
+** Internal configuration macros
+*/
+#define PR_LINKER_ARCH		"qnx"
+#define _PR_SI_SYSNAME		"QNX"
+#define _PR_SI_ARCHITECTURE	"x86"
+#define PR_DLL_SUFFIX		".so"
+
+#define _PR_VMBASE		0x30000000
+#define _PR_STACK_VMBASE	0x50000000
+#define _MD_DEFAULT_STACK_SIZE	65536L
+#define _MD_MMAP_FLAGS		MAP_PRIVATE
+
+#ifndef	HAVE_WEAK_IO_SYMBOLS
+#define	HAVE_WEAK_IO_SYMBOLS
+#endif
+
+#undef _PR_POLL_AVAILABLE
+#undef _PR_USE_POLL
+#define _PR_HAVE_SOCKADDR_LEN
+#define HAVE_BSD_FLOCK
+#define _PR_NO_LARGE_FILES
+#define _PR_STAT_HAS_ONLY_ST_ATIME
+
+#include <sys/select.h>
+
+#undef  HAVE_STACK_GROWING_UP
+#undef	HAVE_DLL
+#undef	USE_DLFCN
+#define NEED_STRFTIME_LOCK
+#define NEED_TIME_R
+#define _PR_NEED_STRCASECMP
+
+#ifndef HAVE_STRERROR
+#define HAVE_STRERROR
+#endif
+
+#define USE_SETJMP
+
+#include <setjmp.h>
+
+#define _SETJMP			setjmp
+#define _LONGJMP		longjmp
+#define _PR_CONTEXT_TYPE	jmp_buf
+#define _PR_NUM_GCREGS		_JBLEN
+#define _MD_GET_SP(_t)		(_t)->md.context[7]
+
+#define CONTEXT(_th)		((_th)->md.context)
+
+/*
+** Initialize the thread context preparing it to execute _main.
+*/
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)	\
+{							\
+    *status = PR_TRUE;					\
+    if(_SETJMP(CONTEXT(_thread))) (*_main)();		\
+    _MD_GET_SP(_thread) = (int) ((_sp) - 128);		\
+}
+
+#define _MD_SWITCH_CONTEXT(_thread)	\
+    if (!_SETJMP(CONTEXT(_thread))) {	\
+	(_thread)->md.errcode = errno;	\
+	_PR_Schedule();			\
+    }
+
+/*
+** Restore a thread context, saved by _MD_SWITCH_CONTEXT
+*/
+#define _MD_RESTORE_CONTEXT(_thread)	\
+{					\
+    errno = (_thread)->md.errcode;	\
+    _MD_SET_CURRENT_THREAD(_thread);	\
+    _LONGJMP(CONTEXT(_thread), 1);	\
+}
+
+/*
+** Machine-dependent (MD) data structures.
+*/
+struct _MDThread {
+    _PR_CONTEXT_TYPE context;
+    int id;
+    int errcode;
+};
+
+struct _MDThreadStack {
+    PRInt8 notused;
+};
+
+struct _MDLock {
+    PRInt8 notused;
+};
+
+struct _MDSemaphore {
+    PRInt8 notused;
+};
+
+struct _MDCVar {
+    PRInt8 notused;
+};
+
+struct _MDSegment {
+    PRInt8 notused;
+};
+
+/*
+** md-specific cpu structure field
+*/
+#define _PR_MD_MAX_OSFD		FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD], fd_write_cnt[_PR_MD_MAX_OSFD], fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+    struct pollfd *ioq_pollfds;
+    int ioq_pollfds_size;
+#endif
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu)	PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
+struct _MDCPU {
+	struct _MDCPU_Unix md_unix;
+};
+
+#define _MD_INIT_LOCKS()
+#define _MD_NEW_LOCK(lock)		PR_SUCCESS
+#define _MD_FREE_LOCK(lock)
+#define _MD_LOCK(lock)
+#define _MD_UNLOCK(lock)
+#define _MD_INIT_IO()
+#define _MD_IOQ_LOCK()
+#define _MD_IOQ_UNLOCK()
+
+#define _MD_INTERVAL_USE_GTOD
+#define _MD_EARLY_INIT			_MD_EarlyInit
+#define _MD_FINAL_INIT			_PR_UnixInit
+#define _MD_INIT_RUNNING_CPU(cpu)	_MD_unix_init_running_cpu(cpu)
+#define _MD_INIT_THREAD			_MD_InitializeThread
+#define _MD_EXIT_THREAD(thread)
+#define	_MD_SUSPEND_THREAD(thread)
+#define	_MD_RESUME_THREAD(thread)
+#define _MD_CLEAN_THREAD(_thread)
+
+/*
+** We wrapped the select() call.  _MD_SELECT refers to the built-in,
+** unwrapped version.
+*/
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/select.h>
+#define _MD_SELECT		select
+
+#define SA_RESTART 0
+
+#endif /* nspr_qnx_defs_h___ */
diff --git a/pr/include/md/_riscos.cfg b/pr/include/md/_riscos.cfg
new file mode 100644
index 0000000..c7adf2e
--- /dev/null
+++ b/pr/include/md/_riscos.cfg
@@ -0,0 +1,111 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef XP_UNIX
+#define XP_UNIX
+#endif
+
+#ifndef RISCOS
+#define RISCOS
+#endif
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#ifndef HAVE_LONG_LONG
+#define HAVE_LONG_LONG
+#endif
+#undef  HAVE_ALIGNED_DOUBLES
+#undef  HAVE_ALIGNED_LONGLONGS
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   4
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  4
+#define PR_ALIGN_OF_POINTER 4
+#define PR_ALIGN_OF_WORD    4
+
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+#define PR_WORDS_PER_DWORD_LOG2  1
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
+#define BYTES_PER_INT 		PR_BYTES_PER_INT
+#define BYTES_PER_INT64		PR_BYTES_PER_INT64
+#define BYTES_PER_LONG		PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE	PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD		PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD		PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE		PR_BITS_PER_BYTE
+#define BITS_PER_SHORT		PR_BITS_PER_SHORT
+#define BITS_PER_INT		PR_BITS_PER_INT
+#define BITS_PER_INT64		PR_BITS_PER_INT64
+#define BITS_PER_LONG		PR_BITS_PER_LONG
+#define BITS_PER_FLOAT		PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE		PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD		PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2	PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2	PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2	PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2	PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2	PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2	PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2 	PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2	PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT		PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT		PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG		PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64		PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT		PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE		PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER	PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD		PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
diff --git a/pr/include/md/_riscos.h b/pr/include/md/_riscos.h
new file mode 100644
index 0000000..f62d668
--- /dev/null
+++ b/pr/include/md/_riscos.h
@@ -0,0 +1,176 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_riscos_defs_h___
+#define nspr_riscos_defs_h___
+
+/*
+** Internal configuration macros
+*/
+#define PR_LINKER_ARCH		"riscos"
+#define _PR_SI_SYSNAME		"RISCOS"
+#define _PR_SI_ARCHITECTURE	"arm"
+#define PR_DLL_SUFFIX		".so"
+
+#define _PR_POLL_AVAILABLE
+#define _PR_USE_POLL
+#define _PR_HAVE_SOCKADDR_LEN
+#undef HAVE_BSD_FLOCK
+#define _PR_NO_LARGE_FILES
+#define _PR_STAT_HAS_ONLY_ST_ATIME
+#define _PR_HAVE_POSIX_SEMAPHORES
+
+#include <sys/select.h>
+#include <sys/poll.h>
+#include <kernel.h>
+
+
+#undef  HAVE_STACK_GROWING_UP
+#define HAVE_DLL
+#define USE_DLFCN
+#define NEED_STRFTIME_LOCK
+#define NEED_TIME_R
+#define PT_NO_SIGTIMEDWAIT
+
+#ifndef HAVE_STRERROR
+#define HAVE_STRERROR
+#endif
+
+#define USE_SETJMP
+
+#include <setjmp.h>
+
+#define _SETJMP			setjmp
+#define _LONGJMP		longjmp
+#define _PR_CONTEXT_TYPE	jmp_buf
+#define _PR_NUM_GCREGS		_JBLEN
+#define _MD_GET_SP(_t)		(_t)->md.context[7]
+
+#define CONTEXT(_th)		((_th)->md.context)
+
+
+/*
+** Initialize the thread context preparing it to execute _main.
+*/
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)	\
+{							\
+    *status = PR_TRUE;					\
+    if(_SETJMP(CONTEXT(_thread))) (*_main)();		\
+    _MD_GET_SP(_thread) = (int) ((_sp) - 128);		\
+}
+
+#define _MD_SWITCH_CONTEXT(_thread)	\
+    if (!_SETJMP(CONTEXT(_thread))) {	\
+	(_thread)->md.errcode = errno;	\
+	_PR_Schedule();			\
+    }
+
+/*
+** Restore a thread context, saved by _MD_SWITCH_CONTEXT
+*/
+#define _MD_RESTORE_CONTEXT(_thread)	\
+{					\
+    errno = (_thread)->md.errcode;	\
+    _MD_SET_CURRENT_THREAD(_thread);	\
+    _LONGJMP(CONTEXT(_thread), 1);	\
+}
+
+/*
+** Machine-dependent (MD) data structures.
+*/
+struct _MDThread {
+    _PR_CONTEXT_TYPE context;
+    int id;
+    int errcode;
+};
+
+struct _MDThreadStack {
+    PRInt8 notused;
+};
+
+struct _MDLock {
+    PRInt8 notused;
+};
+
+struct _MDSemaphore {
+    PRInt8 notused;
+};
+
+struct _MDCVar {
+    PRInt8 notused;
+};
+
+struct _MDSegment {
+    PRInt8 notused;
+};
+
+/*
+** md-specific cpu structure field
+*/
+#define _PR_MD_MAX_OSFD		FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD], fd_write_cnt[_PR_MD_MAX_OSFD], fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+    struct pollfd *ioq_pollfds;
+    int ioq_pollfds_size;
+#endif
+};
+
+#define _PR_IOQ(_cpu)	/*	*/	((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu)	PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
+struct _MDCPU {
+	struct _MDCPU_Unix md_unix;
+};
+
+#define _MD_INIT_LOCKS()
+#define _MD_NEW_LOCK(lock)		PR_SUCCESS
+#define _MD_FREE_LOCK(lock)
+#define _MD_LOCK(lock)
+#define _MD_UNLOCK(lock)
+#define _MD_INIT_IO()
+#define _MD_IOQ_LOCK()
+#define _MD_IOQ_UNLOCK()
+
+#define _MD_INTERVAL_USE_GTOD
+#define _MD_EARLY_INIT			_MD_EarlyInit
+#define _MD_FINAL_INIT			_PR_UnixInit
+#define _MD_INIT_RUNNING_CPU(cpu)	_MD_unix_init_running_cpu(cpu)
+#define _MD_INIT_THREAD			_MD_InitializeThread
+#define _MD_EXIT_THREAD(thread)
+#define	_MD_SUSPEND_THREAD(thread)
+#define	_MD_RESUME_THREAD(thread)
+#define _MD_CLEAN_THREAD(_thread)
+
+/*
+** We wrapped the select() call.  _MD_SELECT refers to the built-in,
+** unwrapped version.
+*/
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/select.h>
+#define _MD_SELECT		select
+
+#endif /* nspr_riscos_defs_h___ */
diff --git a/pr/include/md/_scoos.cfg b/pr/include/md/_scoos.cfg
new file mode 100644
index 0000000..70cc6b7
--- /dev/null
+++ b/pr/include/md/_scoos.cfg
@@ -0,0 +1,108 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef XP_UNIX
+#define XP_UNIX
+#endif
+
+#ifndef SCO
+#define SCO
+#endif
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#undef	HAVE_LONG_LONG
+#undef	HAVE_ALIGNED_DOUBLES
+#undef	HAVE_ALIGNED_LONGLONGS
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   4
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  4
+#define PR_ALIGN_OF_POINTER 4
+
+#define _PR_POLL_BACKCOMPAT
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
+#define BYTES_PER_INT 		PR_BYTES_PER_INT
+#define BYTES_PER_INT64		PR_BYTES_PER_INT64
+#define BYTES_PER_LONG		PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE	PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD		PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD		PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE		PR_BITS_PER_BYTE
+#define BITS_PER_SHORT		PR_BITS_PER_SHORT
+#define BITS_PER_INT		PR_BITS_PER_INT
+#define BITS_PER_INT64		PR_BITS_PER_INT64
+#define BITS_PER_LONG		PR_BITS_PER_LONG
+#define BITS_PER_FLOAT		PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE		PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD		PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2	PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2	PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2	PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2	PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2	PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2	PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2 	PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2	PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT		PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT		PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG		PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64		PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT		PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE		PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER	PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD		PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
diff --git a/pr/include/md/_scoos.h b/pr/include/md/_scoos.h
new file mode 100644
index 0000000..c444dcd
--- /dev/null
+++ b/pr/include/md/_scoos.h
@@ -0,0 +1,171 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_scoos5_defs_h___
+#define nspr_scoos5_defs_h___
+
+/*
+ * Internal configuration macros
+ */
+
+#define PR_LINKER_ARCH	"scoos5"
+#define PR_DLL_SUFFIX		".so"
+
+#define _PR_SI_SYSNAME      "SCO"
+#define _PR_SI_ARCHITECTURE "x86"
+#define _PR_STACK_VMBASE    0x50000000
+
+#define _MD_DEFAULT_STACK_SIZE	65536L
+#define _MD_MMAP_FLAGS          MAP_PRIVATE
+
+#undef  HAVE_STACK_GROWING_UP
+#define	HAVE_DLL
+#define	USE_DLFCN
+
+#if !defined (HAVE_STRERROR)
+#define HAVE_STRERROR
+#endif
+
+#ifndef	HAVE_WEAK_IO_SYMBOLS
+#define	HAVE_WEAK_IO_SYMBOLS
+#endif
+
+#define _PR_POLL_AVAILABLE
+#define _PR_USE_POLL
+#define _PR_NO_LARGE_FILES
+#define _PR_STAT_HAS_ONLY_ST_ATIME
+
+#define NEED_STRFTIME_LOCK
+#define NEED_TIME_R
+#define _PR_RECV_BROKEN /* recv doesn't work on Unix Domain Sockets */
+
+#define USE_SETJMP
+
+#ifdef _PR_LOCAL_THREADS_ONLY
+#include <setjmp.h>
+
+#define _MD_GET_SP(_t)  (_t)->md.jb[4]
+#define PR_NUM_GCREGS	_SIGJBLEN
+#define PR_CONTEXT_TYPE	sigjmp_buf
+
+#define CONTEXT(_th) ((_th)->md.jb)
+
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)				\
+{								  									\
+	*status = PR_TRUE;												\
+    if (sigsetjmp(CONTEXT(_thread),1)) {				  			\
+		(*_main)(); 												\
+    }								  								\
+    _MD_GET_SP(_thread) = (int) ((_sp) - 64);	\
+}
+
+#define _MD_SWITCH_CONTEXT(_thread)  								\
+    if (!sigsetjmp(CONTEXT(_thread), 1)) { 							\
+		(_thread)->md.errcode = errno;  							\
+		_PR_Schedule();		     									\
+    }
+
+/*
+** Restore a thread context, saved by _MD_SWITCH_CONTEXT
+*/
+#define _MD_RESTORE_CONTEXT(_thread)								\
+{				     												\
+    errno = (_thread)->osErrorCode;	     							\
+	_MD_SET_CURRENT_THREAD(_thread);								\
+    siglongjmp(CONTEXT(_thread), 1);    							\
+}
+
+#endif /* _PR_LOCAL_THREADS_ONLY */
+
+struct _MDThread {
+    jmp_buf jb;
+    int id;
+    int errcode;
+};
+
+struct _MDThreadStack {
+    PRInt8 notused;
+};
+
+struct _MDLock {
+    PRInt8 notused;
+};
+
+struct _MDSemaphore {
+    PRInt8 notused;
+};
+
+struct _MDCVar {
+    PRInt8 notused;
+};
+
+struct _MDSegment {
+    PRInt8 notused;
+};
+
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
+struct _MDCPU {
+    struct _MDCPU_Unix md_unix;
+};
+
+#define _MD_INIT_LOCKS()
+#define _MD_NEW_LOCK(lock) PR_SUCCESS
+#define _MD_FREE_LOCK(lock)
+#define _MD_LOCK(lock)
+#define _MD_UNLOCK(lock)
+#define _MD_INIT_IO()
+#define _MD_IOQ_LOCK()
+#define _MD_IOQ_UNLOCK()
+
+#define _MD_EARLY_INIT          	_MD_EarlyInit
+#define _MD_FINAL_INIT				_PR_UnixInit
+#define _MD_INIT_RUNNING_CPU(cpu) 	_MD_unix_init_running_cpu(cpu)
+#define _MD_INIT_THREAD         	_MD_InitializeThread
+#define _MD_EXIT_THREAD(thread)
+#define	_MD_SUSPEND_THREAD(thread)
+#define	_MD_RESUME_THREAD(thread)
+#define _MD_CLEAN_THREAD(_thread)
+
+#define _MD_INTERVAL_USE_GTOD
+
+#define _MD_SELECT		_select
+#define _MD_POLL		_poll
+
+#endif /* nspr_scoos5_defs_h___ */
diff --git a/pr/include/md/_solaris.cfg b/pr/include/md/_solaris.cfg
new file mode 100644
index 0000000..6745637
--- /dev/null
+++ b/pr/include/md/_solaris.cfg
@@ -0,0 +1,171 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef XP_UNIX
+#define XP_UNIX
+#endif
+
+#ifndef SOLARIS
+#define SOLARIS
+#endif
+
+#define PR_AF_INET6 26  /* same as AF_INET6 */
+
+#if defined(sparc) || defined(__sparc)
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN 1
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_DOUBLE  8
+#if defined(__sparcv9)
+#define IS_64
+#endif
+#elif defined(__x86_64)
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_DOUBLE  8
+#define IS_64
+#elif defined(i386) || defined(__i386)
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#define PR_ALIGN_OF_INT64   4
+#define PR_ALIGN_OF_DOUBLE  4
+#else
+#error unknown processor
+#endif
+
+#ifdef IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+#define PR_BYTES_PER_WORD_LOG2   3
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_POINTER 8
+
+#else /* IS_64 */
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_POINTER 4
+
+#endif /* IS_64 */
+
+#ifndef HAVE_LONG_LONG
+#define	HAVE_LONG_LONG
+#endif
+#define	HAVE_ALIGNED_DOUBLES
+#define	HAVE_ALIGNED_LONGLONGS
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
+#define BYTES_PER_INT 		PR_BYTES_PER_INT
+#define BYTES_PER_INT64		PR_BYTES_PER_INT64
+#define BYTES_PER_LONG		PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE	PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD		PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD		PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE		PR_BITS_PER_BYTE
+#define BITS_PER_SHORT		PR_BITS_PER_SHORT
+#define BITS_PER_INT		PR_BITS_PER_INT
+#define BITS_PER_INT64		PR_BITS_PER_INT64
+#define BITS_PER_LONG		PR_BITS_PER_LONG
+#define BITS_PER_FLOAT		PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE		PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD		PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2	PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2	PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2	PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2	PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2	PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2	PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2 	PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2	PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT		PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT		PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG		PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64		PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT		PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE		PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER	PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD		PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* ifndef nspr_cpucfg___ */
diff --git a/pr/include/md/_solaris.h b/pr/include/md/_solaris.h
new file mode 100644
index 0000000..495ce4c
--- /dev/null
+++ b/pr/include/md/_solaris.h
@@ -0,0 +1,493 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_solaris_defs_h___
+#define nspr_solaris_defs_h___
+
+/*
+ * Internal configuration macros
+ */
+
+#define PR_LINKER_ARCH	"solaris"
+#define _PR_SI_SYSNAME	"SOLARIS"
+#ifdef sparc
+#define _PR_SI_ARCHITECTURE	"sparc"
+#elif defined(__x86_64)
+#define _PR_SI_ARCHITECTURE	"x86-64"
+#elif defined(i386)
+#define _PR_SI_ARCHITECTURE	"x86"
+#else
+#error unknown processor
+#endif
+#define PR_DLL_SUFFIX		".so"
+
+#define _PR_VMBASE		0x30000000
+#define _PR_STACK_VMBASE	0x50000000
+#define _MD_DEFAULT_STACK_SIZE	(2*65536L)
+#define _MD_MMAP_FLAGS          MAP_SHARED
+
+#undef  HAVE_STACK_GROWING_UP
+
+#ifndef HAVE_WEAK_IO_SYMBOLS
+#define	HAVE_WEAK_IO_SYMBOLS
+#endif
+
+#undef	HAVE_WEAK_MALLOC_SYMBOLS
+#define	HAVE_DLL
+#define	USE_DLFCN
+#define NEED_STRFTIME_LOCK
+
+/*
+ * Intel x86 has atomic instructions.
+ *
+ * Sparc v8 does not have instructions to efficiently implement
+ * atomic increment/decrement operations.  We use the default
+ * atomic routine implementation in pratom.c.
+ *
+ * 64-bit Solaris requires sparc v9, which has atomic instructions.
+ */
+#if defined(i386) || defined(IS_64)
+#define _PR_HAVE_ATOMIC_OPS
+#endif
+
+#define _PR_POLL_AVAILABLE
+#define _PR_USE_POLL
+#define _PR_STAT_HAS_ST_ATIM
+#ifdef SOLARIS2_5
+#define _PR_HAVE_SYSV_SEMAPHORES
+#define PR_HAVE_SYSV_NAMED_SHARED_MEMORY
+#else
+#define _PR_HAVE_POSIX_SEMAPHORES
+#define PR_HAVE_POSIX_NAMED_SHARED_MEMORY
+#endif
+#define _PR_HAVE_GETIPNODEBYNAME
+#define _PR_HAVE_GETIPNODEBYADDR
+#define _PR_HAVE_GETADDRINFO
+#define _PR_INET6_PROBE
+#define _PR_ACCEPT_INHERIT_NONBLOCK
+#ifdef _PR_INET6
+#define _PR_HAVE_INET_NTOP
+#else
+#define AF_INET6 26
+struct addrinfo {
+    int ai_flags;
+    int ai_family;
+    int ai_socktype;
+    int ai_protocol;
+    size_t ai_addrlen;
+    char *ai_canonname;
+    struct sockaddr *ai_addr;
+    struct addrinfo *ai_next;
+};
+#define AI_CANONNAME 0x0010
+#define AI_V4MAPPED 0x0001 
+#define AI_ALL      0x0002
+#define AI_ADDRCONFIG   0x0004
+#define _PR_HAVE_MD_SOCKADDR_IN6
+/* isomorphic to struct in6_addr on Solaris 8 */
+struct _md_in6_addr {
+    union {
+        PRUint8  _S6_u8[16];
+        PRUint32 _S6_u32[4];
+        PRUint32 __S6_align;
+    } _S6_un;
+};
+/* isomorphic to struct sockaddr_in6 on Solaris 8 */
+struct _md_sockaddr_in6 {
+    PRUint16 sin6_family;
+    PRUint16 sin6_port;
+    PRUint32 sin6_flowinfo;
+    struct _md_in6_addr sin6_addr;
+    PRUint32 sin6_scope_id;
+    PRUint32 __sin6_src_id;
+};
+#endif
+#if defined(_PR_PTHREADS)
+#define _PR_HAVE_GETHOST_R
+#define _PR_HAVE_GETHOST_R_POINTER
+#endif
+
+#include "prinrval.h"
+#define _MD_INTERVAL_INIT()
+NSPR_API(PRIntervalTime) _MD_Solaris_GetInterval(void);
+#define _MD_GET_INTERVAL                  _MD_Solaris_GetInterval
+NSPR_API(PRIntervalTime) _MD_Solaris_TicksPerSecond(void);
+#define _MD_INTERVAL_PER_SEC              _MD_Solaris_TicksPerSecond
+
+#if defined(_PR_HAVE_ATOMIC_OPS)
+/*
+** Atomic Operations
+*/
+#define _MD_INIT_ATOMIC()
+
+NSPR_API(PRInt32) _MD_AtomicIncrement(PRInt32 *val);
+#define _MD_ATOMIC_INCREMENT _MD_AtomicIncrement
+
+NSPR_API(PRInt32) _MD_AtomicAdd(PRInt32 *ptr, PRInt32 val);
+#define _MD_ATOMIC_ADD _MD_AtomicAdd
+
+NSPR_API(PRInt32) _MD_AtomicDecrement(PRInt32 *val);
+#define _MD_ATOMIC_DECREMENT _MD_AtomicDecrement
+
+NSPR_API(PRInt32) _MD_AtomicSet(PRInt32 *val, PRInt32 newval);
+#define _MD_ATOMIC_SET _MD_AtomicSet
+#endif /* _PR_HAVE_ATOMIC_OPS */
+
+#if defined(_PR_PTHREADS)
+
+NSPR_API(void)		_MD_EarlyInit(void);
+
+#define _MD_EARLY_INIT		_MD_EarlyInit
+#define _MD_FINAL_INIT		_PR_UnixInit
+
+#else /* _PR_PTHREADS */
+
+/*
+ * _PR_LOCAL_THREADS_ONLY implementation on Solaris
+ */
+
+#include "prthread.h"
+
+#include <errno.h>
+#include <ucontext.h>
+#include <sys/stack.h>
+#include <synch.h>
+
+/*
+** Initialization Related definitions
+*/
+
+NSPR_API(void)				_MD_EarlyInit(void);
+NSPR_API(void)				_MD_SolarisInit();
+#define _MD_EARLY_INIT		_MD_EarlyInit
+#define _MD_FINAL_INIT		_MD_SolarisInit
+#define	_MD_INIT_THREAD		_MD_InitializeThread
+
+#ifdef USE_SETJMP
+
+#include <setjmp.h>
+
+#define _PR_CONTEXT_TYPE	jmp_buf
+
+#ifdef sparc
+#define _MD_GET_SP(_t)		(_t)->md.context[2]
+#else
+#define _MD_GET_SP(_t)		(_t)->md.context[4]
+#endif
+
+#define PR_NUM_GCREGS		_JBLEN
+#define CONTEXT(_thread)	(_thread)->md.context
+
+#else  /* ! USE_SETJMP */
+
+#ifdef sparc
+#define	_PR_CONTEXT_TYPE	ucontext_t
+#define _MD_GET_SP(_t)		(_t)->md.context.uc_mcontext.gregs[REG_SP]
+/*
+** Sparc's use register windows. the _MD_GetRegisters for the sparc's
+** doesn't actually store anything into the argument buffer; instead the
+** register windows are homed to the stack. I assume that the stack
+** always has room for the registers to spill to...
+*/
+#define PR_NUM_GCREGS		0
+#else
+#define _PR_CONTEXT_TYPE	unsigned int edi; sigset_t oldMask, blockMask; ucontext_t
+#define _MD_GET_SP(_t)		(_t)->md.context.uc_mcontext.gregs[USP]
+#define PR_NUM_GCREGS		_JBLEN
+#endif
+
+#define CONTEXT(_thread)	(&(_thread)->md.context)
+
+#endif /* ! USE_SETJMP */
+
+#include <time.h>
+/* 
+ * Because clock_gettime() on Solaris/x86 always generates a
+ * segmentation fault, we use an emulated version _pr_solx86_clock_gettime(),
+ * which is implemented using gettimeofday().
+ */
+#ifdef i386
+#define GETTIME(tt) _pr_solx86_clock_gettime(CLOCK_REALTIME, (tt))
+#else
+#define GETTIME(tt) clock_gettime(CLOCK_REALTIME, (tt))
+#endif  /* i386 */
+
+#define _MD_SAVE_ERRNO(_thread)			(_thread)->md.errcode = errno;
+#define _MD_RESTORE_ERRNO(_thread)		errno = (_thread)->md.errcode;
+
+#ifdef sparc
+
+#ifdef USE_SETJMP
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)	      \
+    PR_BEGIN_MACRO				      \
+	int *context = (_thread)->md.context;	      \
+    *status = PR_TRUE;              \
+	(void) setjmp(context);			      \
+	(_thread)->md.context[1] = (int) ((_sp) - 64); \
+	(_thread)->md.context[2] = (int) _main;	      \
+	(_thread)->md.context[3] = (int) _main + 4; \
+    _thread->no_sched = 0; \
+    PR_END_MACRO
+
+#define _MD_SWITCH_CONTEXT(_thread)    \
+    if (!setjmp(CONTEXT(_thread))) { \
+	_MD_SAVE_ERRNO(_thread)    \
+	_MD_SET_LAST_THREAD(_thread);	 \
+    _MD_SET_CURRENT_THREAD(_thread);	 \
+	_PR_Schedule();		     \
+    }
+
+#define _MD_RESTORE_CONTEXT(_newThread)	    \
+{				     \
+	_MD_RESTORE_ERRNO(_newThread)	    \
+	_MD_SET_CURRENT_THREAD(_newThread); \
+    longjmp(CONTEXT(_newThread), 1);    \
+}
+
+#else
+/*
+** Initialize the thread context preparing it to execute _main.
+*/
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)					\
+    PR_BEGIN_MACRO				      									\
+    ucontext_t *uc = CONTEXT(_thread);									\
+    *status = PR_TRUE;													\
+    getcontext(uc);														\
+    uc->uc_stack.ss_sp = (char *) ((unsigned long)(_sp - WINDOWSIZE - SA(MINFRAME)) & 0xfffffff8);	\
+    uc->uc_stack.ss_size = _thread->stack->stackSize; 					\
+    uc->uc_stack.ss_flags = 0; 				/* ? */		        		\
+    uc->uc_mcontext.gregs[REG_SP] = (unsigned int) uc->uc_stack.ss_sp;	\
+    uc->uc_mcontext.gregs[REG_PC] = (unsigned int) _main;				\
+    uc->uc_mcontext.gregs[REG_nPC] = (unsigned int) ((char*)_main)+4;	\
+    uc->uc_flags = UC_ALL;												\
+    _thread->no_sched = 0;												\
+    PR_END_MACRO
+
+/*
+** Switch away from the current thread context by saving its state and
+** calling the thread scheduler. Reload cpu when we come back from the
+** context switch because it might have changed.
+*/
+#define _MD_SWITCH_CONTEXT(_thread)    				\
+    PR_BEGIN_MACRO                     				\
+		if (!getcontext(CONTEXT(_thread))) { 		\
+			_MD_SAVE_ERRNO(_thread);    			\
+			_MD_SET_LAST_THREAD(_thread);	 		\
+			_PR_Schedule();			 				\
+		}					 						\
+    PR_END_MACRO
+
+/*
+** Restore a thread context that was saved by _MD_SWITCH_CONTEXT or
+** initialized by _MD_INIT_CONTEXT.
+*/
+#define _MD_RESTORE_CONTEXT(_newThread)	    				\
+    PR_BEGIN_MACRO			    							\
+    	ucontext_t *uc = CONTEXT(_newThread); 				\
+    	uc->uc_mcontext.gregs[11] = 1;     					\
+		_MD_RESTORE_ERRNO(_newThread);	    				\
+		_MD_SET_CURRENT_THREAD(_newThread); 				\
+    	setcontext(uc);		       							\
+    PR_END_MACRO
+#endif
+
+#else  /* x86 solaris */
+
+#ifdef USE_SETJMP
+
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
+    PR_BEGIN_MACRO \
+    *status = PR_TRUE; \
+    if (setjmp(CONTEXT(_thread))) _main(); \
+    _MD_GET_SP(_thread) = (int) ((_sp) - 64); \
+    PR_END_MACRO
+
+#define _MD_SWITCH_CONTEXT(_thread) \
+    if (!setjmp(CONTEXT(_thread))) { \
+        _MD_SAVE_ERRNO(_thread) \
+        _PR_Schedule();	\
+    }
+
+#define _MD_RESTORE_CONTEXT(_newThread) \
+{ \
+    _MD_RESTORE_ERRNO(_newThread) \
+    _MD_SET_CURRENT_THREAD(_newThread); \
+    longjmp(CONTEXT(_newThread), 1); \
+}
+
+#else /* USE_SETJMP */
+
+#define WINDOWSIZE		0
+ 
+int getedi(void);
+void setedi(int);
+ 
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)	      \
+	PR_BEGIN_MACRO					\
+	ucontext_t *uc = CONTEXT(_thread);		\
+        *status = PR_TRUE;              \
+	getcontext(uc);					\
+	/* Force sp to be double aligned! */		\
+    	uc->uc_mcontext.gregs[USP] = (int) ((unsigned long)(_sp - WINDOWSIZE - SA(MINFRAME)) & 0xfffffff8);	\
+	uc->uc_mcontext.gregs[PC] = (int) _main;	\
+	(_thread)->no_sched = 0; \
+	PR_END_MACRO
+
+/* getcontext() may return 1, contrary to what the man page says */
+#define _MD_SWITCH_CONTEXT(_thread)			\
+	PR_BEGIN_MACRO					\
+	ucontext_t *uc = CONTEXT(_thread);		\
+	PR_ASSERT(_thread->no_sched);			\
+	sigfillset(&((_thread)->md.blockMask));		\
+	sigprocmask(SIG_BLOCK, &((_thread)->md.blockMask),	\
+		&((_thread)->md.oldMask));		\
+	(_thread)->md.edi = getedi();			\
+	if (! getcontext(uc)) {				\
+		sigprocmask(SIG_SETMASK, &((_thread)->md.oldMask), NULL); \
+		uc->uc_mcontext.gregs[EDI] = (_thread)->md.edi;	\
+		_MD_SAVE_ERRNO(_thread)    		\
+	        _MD_SET_LAST_THREAD(_thread);	        \
+		_PR_Schedule();				\
+	} else {					\
+		sigprocmask(SIG_SETMASK, &((_thread)->md.oldMask), NULL); \
+		setedi((_thread)->md.edi);		\
+		PR_ASSERT(_MD_LAST_THREAD() !=_MD_CURRENT_THREAD()); \
+		_MD_LAST_THREAD()->no_sched = 0;	\
+	}						\
+	PR_END_MACRO
+
+/*
+** Restore a thread context, saved by _PR_SWITCH_CONTEXT
+*/
+#define _MD_RESTORE_CONTEXT(_newthread)			\
+	PR_BEGIN_MACRO					\
+	ucontext_t *uc = CONTEXT(_newthread);		\
+	uc->uc_mcontext.gregs[EAX] = 1;			\
+	_MD_RESTORE_ERRNO(_newthread)  			\
+	_MD_SET_CURRENT_THREAD(_newthread);		\
+	(_newthread)->no_sched = 1;			\
+	setcontext(uc);					\
+	PR_END_MACRO
+#endif /* USE_SETJMP */
+
+#endif /* sparc */
+
+struct _MDLock {
+	PRInt8 notused;
+};
+
+struct _MDCVar {
+	PRInt8 notused;
+};
+
+struct _MDSemaphore {
+	PRInt8 notused;
+};
+
+struct _MDThread {
+    _PR_CONTEXT_TYPE context;
+    int errcode;
+    int id;
+};
+
+struct _MDThreadStack {
+    PRInt8 notused;
+};
+
+struct _MDSegment {
+    PRInt8 notused;
+};
+
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
+struct _MDCPU {
+	struct _MDCPU_Unix md_unix;
+};
+
+#define _MD_INIT_LOCKS()
+#define _MD_NEW_LOCK(lock)				PR_SUCCESS
+#define _MD_FREE_LOCK(lock)
+#define _MD_LOCK(lock)
+#define _MD_UNLOCK(lock)
+#define _MD_INIT_IO()
+#define _MD_IOQ_LOCK()
+#define _MD_IOQ_UNLOCK()
+
+#define _MD_INIT_RUNNING_CPU(cpu)		_MD_unix_init_running_cpu(cpu)
+#define _MD_INIT_THREAD					_MD_InitializeThread
+#define _MD_EXIT_THREAD(thread)
+#define _MD_SUSPEND_THREAD(thread)
+#define _MD_RESUME_THREAD(thread)
+#define _MD_CLEAN_THREAD(_thread)
+
+extern PRStatus _MD_WAIT(struct PRThread *, PRIntervalTime timeout);
+extern PRStatus _MD_WAKEUP_WAITER(struct PRThread *);
+extern void     _MD_YIELD(void);
+extern PRStatus _MD_InitializeThread(PRThread *thread);
+extern void     _MD_SET_PRIORITY(struct _MDThread *thread,
+	PRThreadPriority newPri);
+extern PRStatus _MD_CREATE_THREAD(PRThread *thread, void (*start) (void *),
+	PRThreadPriority priority, PRThreadScope scope, PRThreadState state,
+        PRUint32 stackSize);
+
+/* The following defines the unwrapped versions of select() and poll(). */
+extern int _select(int nfds, fd_set *readfds, fd_set *writefds,
+	fd_set *exceptfds, struct timeval *timeout);
+#define _MD_SELECT	_select
+
+#include <stropts.h>
+#include <poll.h>
+#define _MD_POLL _poll
+extern int _poll(struct pollfd *fds, unsigned long nfds, int timeout);
+
+PR_BEGIN_EXTERN_C
+
+/*
+** Missing function prototypes
+*/
+extern int gethostname (char *name, int namelen);
+
+PR_END_EXTERN_C
+
+#endif /* _PR_PTHREADS */
+
+extern void _MD_solaris_map_sendfile_error(int err);
+
+#endif /* nspr_solaris_defs_h___ */
+
diff --git a/pr/include/md/_symbian.cfg b/pr/include/md/_symbian.cfg
new file mode 100644
index 0000000..4d49797
--- /dev/null
+++ b/pr/include/md/_symbian.cfg
@@ -0,0 +1,170 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef XP_UNIX
+#define XP_UNIX
+#endif
+
+#ifndef SYMBIAN
+#define SYMBIAN
+#endif
+
+#define PR_AF_INET6 0x0806  /* same as AF_INET6 */
+
+#ifdef __arm__
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_POINTER 4
+#define PR_ALIGN_OF_WORD    4
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_DOUBLE  8
+
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#elif defined(__WINS__)
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_POINTER 4
+#define PR_ALIGN_OF_WORD    4
+#define PR_ALIGN_OF_INT64   4
+#define PR_ALIGN_OF_DOUBLE  4
+
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#else
+
+#error "Unknown CPU architecture"
+
+#endif
+
+#ifndef HAVE_LONG_LONG
+#define	HAVE_LONG_LONG
+#endif
+#if PR_ALIGN_OF_DOUBLE == 8
+#define HAVE_ALIGNED_DOUBLES
+#endif
+#if PR_ALIGN_OF_INT64 == 8
+#define HAVE_ALIGNED_LONGLONGS
+#endif
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
+#define BYTES_PER_INT 		PR_BYTES_PER_INT
+#define BYTES_PER_INT64		PR_BYTES_PER_INT64
+#define BYTES_PER_LONG		PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE	PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD		PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD		PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE		PR_BITS_PER_BYTE
+#define BITS_PER_SHORT		PR_BITS_PER_SHORT
+#define BITS_PER_INT		PR_BITS_PER_INT
+#define BITS_PER_INT64		PR_BITS_PER_INT64
+#define BITS_PER_LONG		PR_BITS_PER_LONG
+#define BITS_PER_FLOAT		PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE		PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD		PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2	PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2	PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2	PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2	PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2	PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2	PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2 	PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2	PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT		PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT		PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG		PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64		PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT		PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE		PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER	PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD		PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
diff --git a/pr/include/md/_symbian.h b/pr/include/md/_symbian.h
new file mode 100644
index 0000000..f88bd38
--- /dev/null
+++ b/pr/include/md/_symbian.h
@@ -0,0 +1,50 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_symbian_defs_h___
+#define nspr_symbian_defs_h___
+
+#include "prthread.h"
+
+/*
+ * Internal configuration macros
+ */
+
+#define _PR_SI_SYSNAME  "SYMBIAN"
+#if defined(__WINS__)
+#define _PR_SI_ARCHITECTURE "i386"
+#elif defined(__arm__)
+#define _PR_SI_ARCHITECTURE "arm"
+#else
+#error "Unknown CPU architecture"
+#endif
+#define PR_DLL_SUFFIX		".dll"
+
+#undef	HAVE_STACK_GROWING_UP
+
+#ifdef DYNAMIC_LIBRARY
+#define HAVE_DLL
+#define USE_DLFCN
+#endif
+
+#define _PR_STAT_HAS_ONLY_ST_ATIME
+#define _PR_NO_LARGE_FILES
+#define _PR_HAVE_SYSV_SEMAPHORES
+#define PR_HAVE_SYSV_NAMED_SHARED_MEMORY
+
+#ifndef _PR_PTHREADS
+#error "Classic NSPR is not implemented"
+#endif
+
+extern void _MD_EarlyInit(void);
+
+#define _MD_EARLY_INIT                  _MD_EarlyInit
+#define _MD_FINAL_INIT                  _PR_UnixInit
+#define _MD_INTERVAL_USE_GTOD
+
+/* For writev() */
+#include <sys/uio.h>
+
+#endif /* nspr_symbian_defs_h___ */
diff --git a/pr/include/md/_unix_errors.h b/pr/include/md/_unix_errors.h
new file mode 100644
index 0000000..96d72db
--- /dev/null
+++ b/pr/include/md/_unix_errors.h
@@ -0,0 +1,139 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef prunixerrors_h___
+#define prunixerrors_h___
+
+#include <unistd.h>
+#include <stddef.h>
+
+PR_BEGIN_EXTERN_C
+
+extern void _MD_unix_map_default_error(int err);
+#define	_PR_MD_MAP_DEFAULT_ERROR	_MD_unix_map_default_error
+
+extern void _MD_unix_map_opendir_error(int err);
+#define	_PR_MD_MAP_OPENDIR_ERROR	_MD_unix_map_opendir_error
+
+extern void _MD_unix_map_closedir_error(int err);
+#define	_PR_MD_MAP_CLOSEDIR_ERROR	_MD_unix_map_closedir_error
+
+extern void _MD_unix_readdir_error(int err);
+#define	_PR_MD_MAP_READDIR_ERROR	_MD_unix_readdir_error
+
+extern void _MD_unix_map_unlink_error(int err);
+#define	_PR_MD_MAP_UNLINK_ERROR	_MD_unix_map_unlink_error
+
+extern void _MD_unix_map_stat_error(int err);
+#define	_PR_MD_MAP_STAT_ERROR	_MD_unix_map_stat_error
+
+extern void _MD_unix_map_fstat_error(int err);
+#define	_PR_MD_MAP_FSTAT_ERROR	_MD_unix_map_fstat_error
+
+extern void _MD_unix_map_rename_error(int err);
+#define	_PR_MD_MAP_RENAME_ERROR	_MD_unix_map_rename_error
+
+extern void _MD_unix_map_access_error(int err);
+#define	_PR_MD_MAP_ACCESS_ERROR	_MD_unix_map_access_error
+
+extern void _MD_unix_map_mkdir_error(int err);
+#define	_PR_MD_MAP_MKDIR_ERROR	_MD_unix_map_mkdir_error
+
+extern void _MD_unix_map_rmdir_error(int err);
+#define	_PR_MD_MAP_RMDIR_ERROR	_MD_unix_map_rmdir_error
+
+extern void _MD_unix_map_read_error(int err);
+#define	_PR_MD_MAP_READ_ERROR	_MD_unix_map_read_error
+
+extern void _MD_unix_map_write_error(int err);
+#define	_PR_MD_MAP_WRITE_ERROR	_MD_unix_map_write_error
+
+extern void _MD_unix_map_lseek_error(int err);
+#define	_PR_MD_MAP_LSEEK_ERROR	_MD_unix_map_lseek_error
+
+extern void _MD_unix_map_fsync_error(int err);
+#define	_PR_MD_MAP_FSYNC_ERROR	_MD_unix_map_fsync_error
+
+extern void _MD_unix_map_close_error(int err);
+#define	_PR_MD_MAP_CLOSE_ERROR	_MD_unix_map_close_error
+
+extern void _MD_unix_map_socket_error(int err);
+#define	_PR_MD_MAP_SOCKET_ERROR	_MD_unix_map_socket_error
+
+extern void _MD_unix_map_socketavailable_error(int err);
+#define	_PR_MD_MAP_SOCKETAVAILABLE_ERROR	_MD_unix_map_socketavailable_error
+
+extern void _MD_unix_map_recv_error(int err);
+#define	_PR_MD_MAP_RECV_ERROR	_MD_unix_map_recv_error
+
+extern void _MD_unix_map_recvfrom_error(int err);
+#define	_PR_MD_MAP_RECVFROM_ERROR	_MD_unix_map_recvfrom_error
+
+extern void _MD_unix_map_send_error(int err);
+#define	_PR_MD_MAP_SEND_ERROR	_MD_unix_map_send_error
+
+extern void _MD_unix_map_sendto_error(int err);
+#define	_PR_MD_MAP_SENDTO_ERROR	_MD_unix_map_sendto_error
+
+extern void _MD_unix_map_writev_error(int err);
+#define	_PR_MD_MAP_WRITEV_ERROR	_MD_unix_map_writev_error
+
+extern void _MD_unix_map_accept_error(int err);
+#define	_PR_MD_MAP_ACCEPT_ERROR	_MD_unix_map_accept_error
+
+extern void _MD_unix_map_connect_error(int err);
+#define	_PR_MD_MAP_CONNECT_ERROR	_MD_unix_map_connect_error
+
+extern void _MD_unix_map_bind_error(int err);
+#define	_PR_MD_MAP_BIND_ERROR	_MD_unix_map_bind_error
+
+extern void _MD_unix_map_listen_error(int err);
+#define	_PR_MD_MAP_LISTEN_ERROR	_MD_unix_map_listen_error
+
+extern void _MD_unix_map_shutdown_error(int err);
+#define	_PR_MD_MAP_SHUTDOWN_ERROR	_MD_unix_map_shutdown_error
+
+extern void _MD_unix_map_socketpair_error(int err);
+#define	_PR_MD_MAP_SOCKETPAIR_ERROR	_MD_unix_map_socketpair_error
+
+extern void _MD_unix_map_getsockname_error(int err);
+#define	_PR_MD_MAP_GETSOCKNAME_ERROR	_MD_unix_map_getsockname_error
+
+extern void _MD_unix_map_getpeername_error(int err);
+#define	_PR_MD_MAP_GETPEERNAME_ERROR	_MD_unix_map_getpeername_error
+
+extern void _MD_unix_map_getsockopt_error(int err);
+#define	_PR_MD_MAP_GETSOCKOPT_ERROR	_MD_unix_map_getsockopt_error
+
+extern void _MD_unix_map_setsockopt_error(int err);
+#define	_PR_MD_MAP_SETSOCKOPT_ERROR	_MD_unix_map_setsockopt_error
+
+extern void _MD_unix_map_open_error(int err);
+#define	_PR_MD_MAP_OPEN_ERROR	_MD_unix_map_open_error
+
+extern void _MD_unix_map_mmap_error(int err);
+#define	_PR_MD_MAP_MMAP_ERROR	_MD_unix_map_mmap_error
+
+extern void _MD_unix_map_gethostname_error(int err);
+#define	_PR_MD_MAP_GETHOSTNAME_ERROR	_MD_unix_map_gethostname_error
+
+extern void _MD_unix_map_select_error(int err);
+#define	_PR_MD_MAP_SELECT_ERROR	_MD_unix_map_select_error
+
+extern void _MD_unix_map_poll_error(int err);
+#define _PR_MD_MAP_POLL_ERROR _MD_unix_map_poll_error
+
+extern void _MD_unix_map_poll_revents_error(int err);
+#define _PR_MD_MAP_POLL_REVENTS_ERROR _MD_unix_map_poll_revents_error
+
+extern void _MD_unix_map_flock_error(int err);
+#define	_PR_MD_MAP_FLOCK_ERROR	_MD_unix_map_flock_error
+
+extern void _MD_unix_map_lockf_error(int err);
+#define	_PR_MD_MAP_LOCKF_ERROR	_MD_unix_map_lockf_error
+
+PR_END_EXTERN_C
+
+#endif /* prunixerrors_h___ */
diff --git a/pr/include/md/_unixos.h b/pr/include/md/_unixos.h
new file mode 100644
index 0000000..ea46b3a
--- /dev/null
+++ b/pr/include/md/_unixos.h
@@ -0,0 +1,624 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef prunixos_h___
+#define prunixos_h___
+
+/*
+ * If FD_SETSIZE is not defined on the command line, set the default value
+ * before include select.h
+ */
+/*
+ * Linux: FD_SETSIZE is defined in /usr/include/sys/select.h and should
+ * not be redefined.
+ */
+#if !defined(LINUX) && !defined(__GNU__) && !defined(__GLIBC__) \
+    && !defined(DARWIN)
+#ifndef FD_SETSIZE
+#define FD_SETSIZE  4096
+#endif
+#endif
+
+#include <unistd.h>
+#include <stddef.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <errno.h>
+
+#include "prio.h"
+#include "prmem.h"
+#include "prclist.h"
+
+/*
+ * For select(), fd_set, and struct timeval.
+ *
+ * In The Single UNIX(R) Specification, Version 2,
+ * the header file for select() is <sys/time.h>.
+ * In Version 3, the header file for select() is
+ * changed to <sys/select.h>.
+ *
+ * fd_set is defined in <sys/types.h>.  Usually
+ * <sys/time.h> includes <sys/types.h>, but on some
+ * older systems <sys/time.h> does not include
+ * <sys/types.h>, so we include it explicitly.
+ */
+#include <sys/time.h>
+#include <sys/types.h>
+#if defined(AIX) || defined(SYMBIAN)
+#include <sys/select.h>
+#endif
+
+#ifndef SYMBIAN
+#define HAVE_NETINET_TCP_H
+#endif
+
+#define _PR_HAVE_O_APPEND
+
+#define PR_DIRECTORY_SEPARATOR		'/'
+#define PR_DIRECTORY_SEPARATOR_STR	"/"
+#define PR_PATH_SEPARATOR		':'
+#define PR_PATH_SEPARATOR_STR		":"
+typedef int (*FARPROC)();
+
+/*
+ * intervals at which GLOBAL threads wakeup to check for pending interrupt
+ */
+#define _PR_INTERRUPT_CHECK_INTERVAL_SECS 5
+extern PRIntervalTime intr_timeout_ticks;
+
+/*
+ * The bit flags for the in_flags and out_flags fields
+ * of _PR_UnixPollDesc
+ */
+#ifdef _PR_USE_POLL
+#define _PR_UNIX_POLL_READ    POLLIN
+#define _PR_UNIX_POLL_WRITE   POLLOUT
+#define _PR_UNIX_POLL_EXCEPT  POLLPRI
+#define _PR_UNIX_POLL_ERR     POLLERR
+#define _PR_UNIX_POLL_NVAL    POLLNVAL
+#define _PR_UNIX_POLL_HUP     POLLHUP
+#else /* _PR_USE_POLL */
+#define _PR_UNIX_POLL_READ    0x1
+#define _PR_UNIX_POLL_WRITE   0x2
+#define _PR_UNIX_POLL_EXCEPT  0x4
+#define _PR_UNIX_POLL_ERR     0x8
+#define _PR_UNIX_POLL_NVAL    0x10
+#define _PR_UNIX_POLL_HUP     0x20
+#endif /* _PR_USE_POLL */
+
+typedef struct _PRUnixPollDesc {
+	PRInt32 osfd;
+	PRInt16 in_flags;
+	PRInt16 out_flags;
+} _PRUnixPollDesc;
+
+typedef struct PRPollQueue {
+    PRCList links;        /* for linking PRPollQueue's together */
+    _PRUnixPollDesc *pds;        /* array of poll descriptors */
+    PRUintn npds;            /* length of the array */
+    PRPackedBool on_ioq;    /* is this on the async i/o work q? */
+    PRIntervalTime timeout;        /* timeout, in ticks */
+    struct PRThread *thr;
+} PRPollQueue;
+
+#define _PR_POLLQUEUE_PTR(_qp) \
+    ((PRPollQueue*) ((char*) (_qp) - offsetof(PRPollQueue,links)))
+
+
+extern PRInt32 _PR_WaitForMultipleFDs(
+    _PRUnixPollDesc *unixpds,
+    PRInt32 pdcnt,
+    PRIntervalTime timeout);
+extern void _PR_Unblock_IO_Wait(struct PRThread *thr);
+
+#if defined(_PR_LOCAL_THREADS_ONLY) || defined(_PR_GLOBAL_THREADS_ONLY)
+#define _MD_CHECK_FOR_EXIT()
+#endif
+
+extern fd_set _pr_md_read_set, _pr_md_write_set, _pr_md_exception_set;
+extern PRInt16 _pr_md_read_cnt[], _pr_md_write_cnt[], _pr_md_exception_cnt[];
+extern PRInt32 _pr_md_ioq_max_osfd;
+extern PRUint32 _pr_md_ioq_timeout;
+
+struct _MDFileDesc {
+    int osfd;
+#if defined(LINUX) && defined(_PR_PTHREADS)
+    int tcp_nodelay;  /* used by pt_LinuxSendFile */
+#endif
+};
+
+struct _MDDir {
+	DIR *d;
+};
+
+struct _PRCPU;
+extern void _MD_unix_init_running_cpu(struct _PRCPU *cpu);
+
+/*
+** Make a redzone at both ends of the stack segment. Disallow access
+** to those pages of memory. It's ok if the mprotect call's don't
+** work - it just means that we don't really have a functional
+** redzone.
+*/
+#include <sys/mman.h>
+#ifndef PROT_NONE
+#define PROT_NONE 0x0
+#endif
+
+#if defined(DEBUG) && !defined(DARWIN)
+#if !defined(SOLARIS)	
+#include <string.h>  /* for memset() */
+#define _MD_INIT_STACK(ts,REDZONE)					\
+    PR_BEGIN_MACRO                 					\
+	(void) mprotect((void*)ts->seg->vaddr, REDZONE, PROT_NONE);	\
+	(void) mprotect((void*) ((char*)ts->seg->vaddr + REDZONE + ts->stackSize),\
+			REDZONE, PROT_NONE);				\
+    /*									\
+    ** Fill stack memory with something that turns into an illegal	\
+    ** pointer value. This will sometimes find runtime references to	\
+    ** uninitialized pointers. We don't do this for solaris because we	\
+    ** can use purify instead.						\
+    */									\
+    if (_pr_debugStacks) {						\
+	memset(ts->allocBase + REDZONE, 0xf7, ts->stackSize);		\
+    }									\
+    PR_END_MACRO
+#else	/* !SOLARIS	*/
+#define _MD_INIT_STACK(ts,REDZONE)					\
+    PR_BEGIN_MACRO                 					\
+	(void) mprotect((void*)ts->seg->vaddr, REDZONE, PROT_NONE);	\
+	(void) mprotect((void*) ((char*)ts->seg->vaddr + REDZONE + ts->stackSize),\
+			REDZONE, PROT_NONE);				\
+    PR_END_MACRO
+#endif	/* !SOLARIS	*/
+
+/*
+ * _MD_CLEAR_STACK
+ *	Allow access to the redzone pages; the access was turned off in
+ *	_MD_INIT_STACK.
+ */
+#define _MD_CLEAR_STACK(ts)						\
+    PR_BEGIN_MACRO                 					\
+	(void) mprotect((void*)ts->seg->vaddr, REDZONE, PROT_READ|PROT_WRITE);\
+	(void) mprotect((void*) ((char*)ts->seg->vaddr + REDZONE + ts->stackSize),\
+			REDZONE, PROT_READ|PROT_WRITE);			\
+    PR_END_MACRO
+
+#else	/* DEBUG */
+
+#define _MD_INIT_STACK(ts,REDZONE)
+#define _MD_CLEAR_STACK(ts)
+
+#endif	/* DEBUG */
+
+#if !defined(SOLARIS) 
+
+#define PR_SET_INTSOFF(newval)
+
+#endif
+
+/************************************************************************/
+
+extern void _PR_UnixInit(void);
+
+extern void _PR_UnixCleanup(void);
+#define _MD_EARLY_CLEANUP _PR_UnixCleanup
+
+/************************************************************************/
+
+struct _MDProcess {
+    pid_t pid;
+};
+
+struct PRProcess;
+struct PRProcessAttr;
+
+/* Create a new process (fork() + exec()) */
+#define _MD_CREATE_PROCESS _MD_CreateUnixProcess
+extern struct PRProcess * _MD_CreateUnixProcess(
+    const char *path,
+    char *const *argv,
+    char *const *envp,
+    const struct PRProcessAttr *attr
+);
+
+#define _MD_DETACH_PROCESS _MD_DetachUnixProcess
+extern PRStatus _MD_DetachUnixProcess(struct PRProcess *process);
+
+/* Wait for a child process to terminate */
+#define _MD_WAIT_PROCESS _MD_WaitUnixProcess
+extern PRStatus _MD_WaitUnixProcess(struct PRProcess *process,
+    PRInt32 *exitCode);
+
+#define _MD_KILL_PROCESS _MD_KillUnixProcess
+extern PRStatus _MD_KillUnixProcess(struct PRProcess *process);
+
+/************************************************************************/
+
+extern void _MD_EnableClockInterrupts(void);
+extern void _MD_DisableClockInterrupts(void);
+
+#define _MD_START_INTERRUPTS			_MD_StartInterrupts
+#define _MD_STOP_INTERRUPTS				_MD_StopInterrupts
+#define _MD_DISABLE_CLOCK_INTERRUPTS	_MD_DisableClockInterrupts
+#define _MD_ENABLE_CLOCK_INTERRUPTS		_MD_EnableClockInterrupts
+#define _MD_BLOCK_CLOCK_INTERRUPTS		_MD_BlockClockInterrupts
+#define _MD_UNBLOCK_CLOCK_INTERRUPTS	_MD_UnblockClockInterrupts
+
+/************************************************************************/
+
+extern void		_MD_InitCPUS(void);
+#define _MD_INIT_CPUS           _MD_InitCPUS
+
+extern void		_MD_Wakeup_CPUs(void);
+#define _MD_WAKEUP_CPUS _MD_Wakeup_CPUs
+
+#define _MD_PAUSE_CPU			_MD_PauseCPU
+
+#if defined(_PR_LOCAL_THREADS_ONLY) || defined(_PR_GLOBAL_THREADS_ONLY)
+#define _MD_CLEANUP_BEFORE_EXIT()
+#endif
+
+#ifndef IRIX
+#define _MD_EXIT(status)		_exit(status)
+#endif
+
+/************************************************************************/
+
+#define _MD_GET_ENV				getenv
+#define _MD_PUT_ENV				putenv
+
+/************************************************************************/
+
+#define _MD_INIT_FILEDESC(fd)
+
+extern void		_MD_MakeNonblock(PRFileDesc *fd);
+#define _MD_MAKE_NONBLOCK			_MD_MakeNonblock		
+
+/************************************************************************/
+
+#if !defined(_PR_PTHREADS)
+
+extern void		_MD_InitSegs(void);
+extern PRStatus	_MD_AllocSegment(PRSegment *seg, PRUint32 size,
+				void *vaddr);
+extern void		_MD_FreeSegment(PRSegment *seg);
+
+#define _MD_INIT_SEGS			_MD_InitSegs
+#define _MD_ALLOC_SEGMENT		_MD_AllocSegment
+#define _MD_FREE_SEGMENT		_MD_FreeSegment
+
+#endif /* !defined(_PR_PTHREADS) */
+
+/************************************************************************/
+
+#ifdef _MD_INTERVAL_USE_GTOD
+extern PRIntervalTime   _PR_UNIX_GetInterval(void);
+extern PRIntervalTime   _PR_UNIX_TicksPerSecond(void);
+#define _MD_INTERVAL_INIT()
+#define _MD_GET_INTERVAL		_PR_UNIX_GetInterval
+#define _MD_INTERVAL_PER_SEC		_PR_UNIX_TicksPerSecond
+#endif
+
+#ifdef _PR_HAVE_CLOCK_MONOTONIC
+extern PRIntervalTime   _PR_UNIX_GetInterval2(void);
+extern PRIntervalTime   _PR_UNIX_TicksPerSecond2(void);
+#define _MD_INTERVAL_INIT()
+#define _MD_GET_INTERVAL		_PR_UNIX_GetInterval2
+#define _MD_INTERVAL_PER_SEC		_PR_UNIX_TicksPerSecond2
+#endif
+
+#define _MD_INTERVAL_PER_MILLISEC()	(_PR_MD_INTERVAL_PER_SEC() / 1000)
+#define _MD_INTERVAL_PER_MICROSEC()	(_PR_MD_INTERVAL_PER_SEC() / 1000000)
+
+/************************************************************************/
+
+#define _MD_ERRNO()             	(errno)
+#define _MD_GET_SOCKET_ERROR()		(errno)
+
+/************************************************************************/
+
+extern PRInt32 _MD_AvailableSocket(PRInt32 osfd);
+
+extern void _MD_StartInterrupts(void);
+extern void _MD_StopInterrupts(void);
+extern void _MD_DisableClockInterrupts(void);
+extern void _MD_BlockClockInterrupts(void);
+extern void _MD_UnblockClockInterrupts(void);
+extern void _MD_PauseCPU(PRIntervalTime timeout);
+
+extern PRStatus _MD_open_dir(struct _MDDir *, const char *);
+extern PRInt32  _MD_close_dir(struct _MDDir *);
+extern char *   _MD_read_dir(struct _MDDir *, PRIntn);
+extern PRInt32  _MD_open(const char *name, PRIntn osflags, PRIntn mode);
+extern PRInt32	_MD_delete(const char *name);
+extern PRInt32	_MD_getfileinfo(const char *fn, PRFileInfo *info);
+extern PRInt32  _MD_getfileinfo64(const char *fn, PRFileInfo64 *info);
+extern PRInt32  _MD_getopenfileinfo(const PRFileDesc *fd, PRFileInfo *info);
+extern PRInt32  _MD_getopenfileinfo64(const PRFileDesc *fd, PRFileInfo64 *info);
+extern PRInt32	_MD_rename(const char *from, const char *to);
+extern PRInt32	_MD_access(const char *name, PRAccessHow how);
+extern PRInt32	_MD_mkdir(const char *name, PRIntn mode);
+extern PRInt32	_MD_rmdir(const char *name);
+extern PRInt32	_MD_accept_read(PRInt32 sock, PRInt32 *newSock,
+				PRNetAddr **raddr, void *buf, PRInt32 amount);
+extern PRInt32 	_PR_UnixSendFile(PRFileDesc *sd, PRSendFileData *sfd,
+			PRTransmitFileFlags flags, PRIntervalTime timeout);
+
+extern PRStatus _MD_LockFile(PRInt32 osfd);
+extern PRStatus _MD_TLockFile(PRInt32 osfd);
+extern PRStatus _MD_UnlockFile(PRInt32 osfd);
+
+#define _MD_OPEN_DIR(dir, name)		    _MD_open_dir(dir, name)
+#define _MD_CLOSE_DIR(dir)		        _MD_close_dir(dir)
+#define _MD_READ_DIR(dir, flags)	    _MD_read_dir(dir, flags)
+#define _MD_OPEN(name, osflags, mode)	_MD_open(name, osflags, mode)
+#define _MD_OPEN_FILE(name, osflags, mode)	_MD_open(name, osflags, mode)
+extern PRInt32 _MD_read(PRFileDesc *fd, void *buf, PRInt32 amount);
+#define _MD_READ(fd,buf,amount)		    _MD_read(fd,buf,amount)
+extern PRInt32 _MD_write(PRFileDesc *fd, const void *buf, PRInt32 amount);
+#define _MD_WRITE(fd,buf,amount)	    _MD_write(fd,buf,amount)
+#define _MD_DELETE(name)		        _MD_delete(name)
+#define _MD_GETFILEINFO(fn, info)	    _MD_getfileinfo(fn, info)
+#define _MD_GETFILEINFO64(fn, info)	    _MD_getfileinfo64(fn, info)
+#define _MD_GETOPENFILEINFO(fd, info)	_MD_getopenfileinfo(fd, info)
+#define _MD_GETOPENFILEINFO64(fd, info)	_MD_getopenfileinfo64(fd, info)
+#define _MD_RENAME(from, to)		    _MD_rename(from, to)
+#define _MD_ACCESS(name, how)		    _MD_access(name, how)
+#define _MD_MKDIR(name, mode)		    _MD_mkdir(name, mode)
+#define _MD_MAKE_DIR(name, mode)		_MD_mkdir(name, mode)
+#define _MD_RMDIR(name)			        _MD_rmdir(name)
+#define _MD_ACCEPT_READ(sock, newSock, raddr, buf, amount)	_MD_accept_read(sock, newSock, raddr, buf, amount)
+
+#define _MD_LOCKFILE _MD_LockFile
+#define _MD_TLOCKFILE _MD_TLockFile
+#define _MD_UNLOCKFILE _MD_UnlockFile
+
+
+extern PRInt32		_MD_socket(int af, int type, int flags);
+#define _MD_SOCKET	_MD_socket
+extern PRInt32		_MD_connect(PRFileDesc *fd, const PRNetAddr *addr,
+								PRUint32 addrlen, PRIntervalTime timeout);
+#define _MD_CONNECT	_MD_connect
+extern PRInt32		_MD_accept(PRFileDesc *fd, PRNetAddr *addr, PRUint32 *addrlen,
+													PRIntervalTime timeout);
+#define _MD_ACCEPT	_MD_accept
+extern PRInt32		_MD_bind(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen);
+#define _MD_BIND	_MD_bind
+extern PRInt32		_MD_listen(PRFileDesc *fd, PRIntn backlog);
+#define _MD_LISTEN	_MD_listen
+extern PRInt32		_MD_shutdown(PRFileDesc *fd, PRIntn how);
+#define _MD_SHUTDOWN	_MD_shutdown
+
+extern PRInt32		_MD_recv(PRFileDesc *fd, void *buf, PRInt32 amount, 
+                               PRIntn flags, PRIntervalTime timeout);
+#define _MD_RECV	_MD_recv
+extern PRInt32		_MD_send(PRFileDesc *fd, const void *buf, PRInt32 amount,
+									PRIntn flags, PRIntervalTime timeout);
+#define _MD_SEND	_MD_send
+extern PRInt32		_MD_recvfrom(PRFileDesc *fd, void *buf, PRInt32 amount,
+						PRIntn flags, PRNetAddr *addr, PRUint32 *addrlen,
+											PRIntervalTime timeout);
+#define _MD_RECVFROM	_MD_recvfrom
+extern PRInt32 _MD_sendto(PRFileDesc *fd, const void *buf, PRInt32 amount,
+							PRIntn flags, const PRNetAddr *addr, PRUint32 addrlen,
+												PRIntervalTime timeout);
+#define _MD_SENDTO	_MD_sendto
+extern PRInt32		_MD_writev(PRFileDesc *fd, const struct PRIOVec *iov,
+								PRInt32 iov_size, PRIntervalTime timeout);
+#define _MD_WRITEV	_MD_writev
+
+extern PRInt32		_MD_socketavailable(PRFileDesc *fd);
+#define	_MD_SOCKETAVAILABLE		_MD_socketavailable
+extern PRInt64		_MD_socketavailable64(PRFileDesc *fd);
+#define	_MD_SOCKETAVAILABLE64		_MD_socketavailable64
+
+#define	_MD_PIPEAVAILABLE		_MD_socketavailable
+
+extern PRInt32 _MD_pr_poll(PRPollDesc *pds, PRIntn npds,
+												PRIntervalTime timeout);
+#define _MD_PR_POLL		_MD_pr_poll
+
+extern PRInt32		_MD_close(PRInt32 osfd);
+#define _MD_CLOSE_FILE	_MD_close
+extern PRInt32		_MD_lseek(PRFileDesc*, PRInt32, PRSeekWhence);
+#define _MD_LSEEK	_MD_lseek
+extern PRInt64		_MD_lseek64(PRFileDesc*, PRInt64, PRSeekWhence);
+#define _MD_LSEEK64	_MD_lseek64
+extern PRInt32		_MD_fsync(PRFileDesc *fd);
+#define _MD_FSYNC	_MD_fsync
+
+extern PRInt32 _MD_socketpair(int af, int type, int flags, PRInt32 *osfd);
+#define _MD_SOCKETPAIR		_MD_socketpair
+
+#define _MD_CLOSE_SOCKET	_MD_close
+
+#ifndef NO_NSPR_10_SUPPORT
+#define _MD_STAT	stat
+#endif
+
+extern PRStatus _MD_getpeername(PRFileDesc *fd, PRNetAddr *addr,
+											PRUint32 *addrlen);
+#define _MD_GETPEERNAME _MD_getpeername
+extern PRStatus _MD_getsockname(PRFileDesc *fd, PRNetAddr *addr,
+											PRUint32 *addrlen);
+#define _MD_GETSOCKNAME _MD_getsockname
+
+extern PRStatus _MD_getsockopt(PRFileDesc *fd, PRInt32 level,
+						PRInt32 optname, char* optval, PRInt32* optlen);
+#define _MD_GETSOCKOPT		_MD_getsockopt
+extern PRStatus _MD_setsockopt(PRFileDesc *fd, PRInt32 level,
+					PRInt32 optname, const char* optval, PRInt32 optlen);
+#define _MD_SETSOCKOPT		_MD_setsockopt
+
+extern PRStatus _MD_set_fd_inheritable(PRFileDesc *fd, PRBool inheritable);
+#define _MD_SET_FD_INHERITABLE _MD_set_fd_inheritable
+
+extern void _MD_init_fd_inheritable(PRFileDesc *fd, PRBool imported);
+#define _MD_INIT_FD_INHERITABLE _MD_init_fd_inheritable
+
+extern void _MD_query_fd_inheritable(PRFileDesc *fd);
+#define _MD_QUERY_FD_INHERITABLE _MD_query_fd_inheritable
+
+extern PRStatus _MD_gethostname(char *name, PRUint32 namelen);
+#define _MD_GETHOSTNAME		_MD_gethostname
+
+extern PRStatus _MD_getsysinfo(PRSysInfo cmd, char *name, PRUint32 namelen);
+#define _MD_GETSYSINFO		_MD_getsysinfo
+
+extern int _MD_unix_get_nonblocking_connect_error(int osfd);
+
+/* Memory-mapped files */
+
+struct _MDFileMap {
+    PRIntn prot;
+    PRIntn flags;
+    PRBool isAnonFM; /* when true, PR_CloseFileMap() must close the related fd */
+};
+
+extern PRStatus _MD_CreateFileMap(struct PRFileMap *fmap, PRInt64 size);
+#define _MD_CREATE_FILE_MAP _MD_CreateFileMap
+
+#define _MD_GET_MEM_MAP_ALIGNMENT() PR_GetPageSize()
+
+extern void * _MD_MemMap(struct PRFileMap *fmap, PRInt64 offset,
+        PRUint32 len);
+#define _MD_MEM_MAP _MD_MemMap
+
+extern PRStatus _MD_MemUnmap(void *addr, PRUint32 size);
+#define _MD_MEM_UNMAP _MD_MemUnmap
+
+extern PRStatus _MD_CloseFileMap(struct PRFileMap *fmap);
+#define _MD_CLOSE_FILE_MAP _MD_CloseFileMap
+
+extern PRStatus _MD_SyncMemMap(
+    PRFileDesc *fd,
+    void *addr,
+    PRUint32 len);
+#define _MD_SYNC_MEM_MAP _MD_SyncMemMap
+
+/*
+ * The standard (XPG4) gettimeofday() (from BSD) takes two arguments.
+ * On some SVR4 derivatives, gettimeofday() takes only one argument.
+ * The GETTIMEOFDAY macro is intended to hide this difference.
+ */
+#ifdef HAVE_SVID_GETTOD
+#define GETTIMEOFDAY(tp) gettimeofday(tp)
+#else
+#define GETTIMEOFDAY(tp) gettimeofday((tp), NULL)
+#endif
+
+#if defined(_PR_PTHREADS) && !defined(_PR_POLL_AVAILABLE)
+#define _PR_NEED_FAKE_POLL
+#endif
+
+#if defined(_PR_NEED_FAKE_POLL)
+
+/*
+ * Some platforms don't have poll(), but our pthreads code calls poll().
+ * As a temporary measure, I implemented a fake poll() using select().
+ * Here are the struct and macro definitions copied from sys/poll.h
+ * on Solaris 2.5.
+ */
+
+struct pollfd {
+    int fd;
+    short events;
+    short revents;
+};
+
+/* poll events */
+
+#define	POLLIN		0x0001		/* fd is readable */
+#define	POLLPRI		0x0002		/* high priority info at fd */
+#define	POLLOUT		0x0004		/* fd is writeable (won't block) */
+#define	POLLRDNORM	0x0040		/* normal data is readable */
+#define	POLLWRNORM	POLLOUT
+#define	POLLRDBAND	0x0080		/* out-of-band data is readable */
+#define	POLLWRBAND	0x0100		/* out-of-band data is writeable */
+
+#define	POLLNORM	POLLRDNORM
+
+#define	POLLERR		0x0008		/* fd has error condition */
+#define	POLLHUP		0x0010		/* fd has been hung up on */
+#define	POLLNVAL	0x0020		/* invalid pollfd entry */
+
+extern int poll(struct pollfd *, unsigned long, int);
+
+#endif /* _PR_NEED_FAKE_POLL */
+
+/*
+** A vector of the UNIX I/O calls we use. These are here to smooth over
+** the rough edges needed for large files. All of NSPR's implmentaions
+** go through this vector using syntax of the form
+**      result = _md_iovector.xxx64(args);
+*/
+
+#if defined(SOLARIS2_5)
+/*
+** Special case: Solaris 2.5.1
+** Solaris starts to have 64-bit file I/O in 2.6.  We build on Solaris
+** 2.5.1 so that we can use the same binaries on both Solaris 2.5.1 and
+** 2.6.  At run time, we detect whether 64-bit file I/O is available by
+** looking up the 64-bit file function symbols in libc.  At build time,
+** we need to define the 64-bit file I/O datatypes that are compatible
+** with their definitions on Solaris 2.6.
+*/
+typedef PRInt64 off64_t;
+typedef PRUint64 ino64_t;
+typedef PRInt64 blkcnt64_t;
+struct stat64 {
+    dev_t st_dev;
+    long st_pad1[3];
+    ino64_t st_ino;
+    mode_t st_mode;
+    nlink_t st_nlink;
+    uid_t st_uid;
+    gid_t st_gid;
+    dev_t st_rdev;
+    long t_pad2[2];
+    off64_t st_size;
+    timestruc_t st_atim;
+    timestruc_t st_mtim;
+    timestruc_t st_ctim;
+    long st_blksize;
+    blkcnt64_t st_blocks;
+    char st_fstype[_ST_FSTYPSZ];
+    long st_pad4[8];
+};
+typedef struct stat64 _MDStat64;
+typedef off64_t _MDOff64_t;
+
+#elif defined(_PR_HAVE_OFF64_T)
+typedef struct stat64 _MDStat64;
+typedef off64_t _MDOff64_t;
+#elif defined(_PR_HAVE_LARGE_OFF_T)
+typedef struct stat _MDStat64;
+typedef off_t _MDOff64_t;
+#elif defined(_PR_NO_LARGE_FILES)
+typedef struct stat _MDStat64;
+typedef PRInt64 _MDOff64_t;
+#else
+#error "I don't know yet"
+#endif
+
+typedef PRIntn (*_MD_Fstat64)(PRIntn osfd, _MDStat64 *buf);
+typedef PRIntn (*_MD_Open64)(const char *path, int oflag, ...);
+typedef PRIntn (*_MD_Stat64)(const char *path, _MDStat64 *buf);
+typedef _MDOff64_t (*_MD_Lseek64)(PRIntn osfd, _MDOff64_t, PRIntn whence);
+typedef void* (*_MD_Mmap64)(
+    void *addr, PRSize len, PRIntn prot, PRIntn flags,
+    PRIntn fildes, _MDOff64_t offset);
+struct _MD_IOVector
+{
+    _MD_Open64 _open64;
+    _MD_Mmap64 _mmap64;
+    _MD_Stat64 _stat64;
+    _MD_Fstat64 _fstat64;
+    _MD_Lseek64 _lseek64;
+};
+extern struct _MD_IOVector _md_iovector;
+
+#endif /* prunixos_h___ */
diff --git a/pr/include/md/_unixware.cfg b/pr/include/md/_unixware.cfg
new file mode 100644
index 0000000..0fa8dfc
--- /dev/null
+++ b/pr/include/md/_unixware.cfg
@@ -0,0 +1,108 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef XP_UNIX
+#define XP_UNIX
+#endif
+
+#ifndef UNIXWARE
+#define UNIXWARE
+#endif
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#undef	HAVE_LONG_LONG
+#undef	HAVE_ALIGNED_DOUBLES
+#undef	HAVE_ALIGNED_LONGLONGS
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   4
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  4
+#define PR_ALIGN_OF_POINTER 4
+
+#define _PR_POLL_BACKCOMPAT
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
+#define BYTES_PER_INT 		PR_BYTES_PER_INT
+#define BYTES_PER_INT64		PR_BYTES_PER_INT64
+#define BYTES_PER_LONG		PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE	PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD		PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD		PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE		PR_BITS_PER_BYTE
+#define BITS_PER_SHORT		PR_BITS_PER_SHORT
+#define BITS_PER_INT		PR_BITS_PER_INT
+#define BITS_PER_INT64		PR_BITS_PER_INT64
+#define BITS_PER_LONG		PR_BITS_PER_LONG
+#define BITS_PER_FLOAT		PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE		PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD		PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2	PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2	PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2	PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2	PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2	PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2	PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2 	PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2	PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT		PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT		PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG		PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64		PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT		PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE		PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER	PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD		PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
diff --git a/pr/include/md/_unixware.h b/pr/include/md/_unixware.h
new file mode 100644
index 0000000..ef76f5a
--- /dev/null
+++ b/pr/include/md/_unixware.h
@@ -0,0 +1,186 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_unixware_defs_h___
+#define nspr_unixware_defs_h___
+
+/*
+ * Internal configuration macros
+ */
+
+#define PR_LINKER_ARCH	"unixware"
+#define _PR_SI_SYSNAME		"UnixWare"
+#define _PR_SI_ARCHITECTURE	"x86"
+#define PR_DLL_SUFFIX		".so"
+
+#define _PR_VMBASE	 	0x30000000
+#define _PR_STACK_VMBASE	0x50000000
+#define _MD_DEFAULT_STACK_SIZE	65536L
+#define _MD_MMAP_FLAGS          MAP_PRIVATE
+
+#ifndef	HAVE_WEAK_IO_SYMBOLS
+#define	HAVE_WEAK_IO_SYMBOLS
+#endif
+#define _PR_POLL_AVAILABLE
+#define _PR_USE_POLL
+#define _PR_STAT_HAS_ST_ATIM_UNION
+
+#undef  HAVE_STACK_GROWING_UP
+#define HAVE_NETCONFIG
+#define	HAVE_DLL
+#define	USE_DLFCN
+#define HAVE_STRERROR
+#define NEED_STRFTIME_LOCK
+#define NEED_TIME_R
+#define _PR_NEED_STRCASECMP
+
+#define USE_SETJMP
+
+#include <setjmp.h>
+
+#define _SETJMP setjmp
+#define _LONGJMP longjmp
+#define _PR_CONTEXT_TYPE         jmp_buf
+#define _MD_GET_SP(_t)           (_t)->md.context[4]
+#define _PR_NUM_GCREGS	_JBLEN
+
+#define CONTEXT(_th) ((_th)->md.context)
+
+/*
+** Initialize the thread context preparing it to execute _main.
+*/
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
+{								  \
+    *status = PR_TRUE; \
+    if(_SETJMP(CONTEXT(_thread))) (*_main)(); \
+    _MD_GET_SP(_thread) = (int) ((_sp) - 128); \
+}
+
+#define _MD_SWITCH_CONTEXT(_thread)  \
+    if (!_SETJMP(CONTEXT(_thread))) { \
+	(_thread)->md.errcode = errno;  \
+	_PR_Schedule();		     \
+    }
+
+/*
+** Restore a thread context, saved by _MD_SWITCH_CONTEXT
+*/
+#define _MD_RESTORE_CONTEXT(_thread) \
+{				     \
+    errno = (_thread)->md.errcode;	     \
+    _MD_SET_CURRENT_THREAD(_thread); \
+    _LONGJMP(CONTEXT(_thread), 1);    \
+}
+
+/* Machine-dependent (MD) data structures.
+ * Don't use SVR4 native threads (yet). 
+ */
+
+struct _MDThread {
+    _PR_CONTEXT_TYPE context;
+    int id;
+    int errcode;
+};
+
+struct _MDThreadStack {
+    PRInt8 notused;
+};
+
+struct _MDLock {
+    PRInt8 notused;
+};
+
+struct _MDSemaphore {
+    PRInt8 notused;
+};
+
+struct _MDCVar {
+    PRInt8 notused;
+};
+
+struct _MDSegment {
+    PRInt8 notused;
+};
+
+/*
+ * md-specific cpu structure field
+ */
+#define _PR_MD_MAX_OSFD FD_SETSIZE
+
+struct _MDCPU_Unix {
+    PRCList ioQ;
+    PRUint32 ioq_timeout;
+    PRInt32 ioq_max_osfd;
+    PRInt32 ioq_osfd_cnt;
+#ifndef _PR_USE_POLL
+    fd_set fd_read_set, fd_write_set, fd_exception_set;
+    PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
+				fd_exception_cnt[_PR_MD_MAX_OSFD];
+#else
+	struct pollfd *ioq_pollfds;
+	int ioq_pollfds_size;
+#endif	/* _PR_USE_POLL */
+};
+
+#define _PR_IOQ(_cpu)			((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu)		((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu)		((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu)		((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu)		((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu)	((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu)	((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu)		((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu)		((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu)		((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu)		((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu)	((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu)	32
+
+struct _MDCPU {
+	struct _MDCPU_Unix md_unix;
+};
+
+#define _MD_INIT_LOCKS()
+#define _MD_NEW_LOCK(lock) PR_SUCCESS
+#define _MD_FREE_LOCK(lock)
+#define _MD_LOCK(lock)
+#define _MD_UNLOCK(lock)
+#define _MD_INIT_IO()
+#define _MD_IOQ_LOCK()
+#define _MD_IOQ_UNLOCK()
+
+/*
+ * The following are copied from _sunos.h, _aix.h.  This means
+ * some of them should probably be moved into _unixos.h.  But
+ * _irix.h seems to be quite different in regard to these macros.
+ */
+#define _MD_INTERVAL_USE_GTOD
+
+#define _MD_EARLY_INIT		_MD_EarlyInit
+#define _MD_FINAL_INIT		_PR_UnixInit
+#define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
+#define _MD_INIT_THREAD         _MD_InitializeThread
+#define _MD_EXIT_THREAD(thread)
+#define	_MD_SUSPEND_THREAD(thread)
+#define	_MD_RESUME_THREAD(thread)
+#define _MD_CLEAN_THREAD(_thread)
+
+/*
+ * We wrapped the select() call.  _MD_SELECT refers to the built-in,
+ * unwrapped version.
+ */
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/select.h>
+extern int _select(int nfds, fd_set *readfds, fd_set *writefds,
+	fd_set *execptfds, struct timeval *timeout);
+#define _MD_SELECT _select
+
+#define _MD_POLL _poll
+extern int _poll(struct pollfd *fds, unsigned long nfds, int timeout);
+
+#endif /* nspr_unixware_defs_h___ */
diff --git a/pr/include/md/_unixware7.cfg b/pr/include/md/_unixware7.cfg
new file mode 100644
index 0000000..33ce83b
--- /dev/null
+++ b/pr/include/md/_unixware7.cfg
@@ -0,0 +1,112 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef XP_UNIX
+#define XP_UNIX
+#endif
+
+#ifndef UNIXWARE
+#define UNIXWARE
+#endif
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#ifndef HAVE_LONG_LONG
+#define HAVE_LONG_LONG
+#endif
+#undef	HAVE_ALIGNED_DOUBLES
+#undef	HAVE_ALIGNED_LONGLONGS
+
+#define PR_AF_INET6 27  /* same as AF_INET6 */
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+#define PR_BYTES_PER_WORD_LOG2   2
+#define PR_BYTES_PER_DWORD_LOG2  3
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    32
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   5
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   4
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  4
+#define PR_ALIGN_OF_POINTER 4
+
+#define _PR_POLL_BACKCOMPAT
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE		PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT 	PR_BYTES_PER_SHORT
+#define BYTES_PER_INT 		PR_BYTES_PER_INT
+#define BYTES_PER_INT64		PR_BYTES_PER_INT64
+#define BYTES_PER_LONG		PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT		PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE	PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD		PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD		PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE		PR_BITS_PER_BYTE
+#define BITS_PER_SHORT		PR_BITS_PER_SHORT
+#define BITS_PER_INT		PR_BITS_PER_INT
+#define BITS_PER_INT64		PR_BITS_PER_INT64
+#define BITS_PER_LONG		PR_BITS_PER_LONG
+#define BITS_PER_FLOAT		PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE		PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD		PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2	PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2	PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2	PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2	PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2	PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2	PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2 	PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2	PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT		PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT		PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG		PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64		PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT		PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE		PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER	PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD		PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2	PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2	PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2	PR_WORDS_PER_DWORD_LOG2
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
diff --git a/pr/include/md/_win32_errors.h b/pr/include/md/_win32_errors.h
new file mode 100644
index 0000000..1c96237
--- /dev/null
+++ b/pr/include/md/_win32_errors.h
@@ -0,0 +1,122 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_win32_errors_h___
+#define nspr_win32_errors_h___
+
+#include <windows.h>
+#include <winsock.h>
+#include <errno.h>
+
+
+extern void _MD_win32_map_default_error(PRInt32 err);
+#define _PR_MD_MAP_DEFAULT_ERROR	_MD_win32_map_default_error
+
+extern void _MD_win32_map_opendir_error(PRInt32 err);
+#define	_PR_MD_MAP_OPENDIR_ERROR	_MD_win32_map_opendir_error
+
+extern void _MD_win32_map_closedir_error(PRInt32 err);
+#define	_PR_MD_MAP_CLOSEDIR_ERROR	_MD_win32_map_closedir_error
+
+extern void _MD_unix_readdir_error(PRInt32 err);
+#define	_PR_MD_MAP_READDIR_ERROR	_MD_unix_readdir_error
+
+extern void _MD_win32_map_delete_error(PRInt32 err);
+#define	_PR_MD_MAP_DELETE_ERROR	_MD_win32_map_delete_error
+
+extern void _MD_win32_map_stat_error(PRInt32 err);
+#define	_PR_MD_MAP_STAT_ERROR	_MD_win32_map_stat_error
+
+extern void _MD_win32_map_fstat_error(PRInt32 err);
+#define	_PR_MD_MAP_FSTAT_ERROR	_MD_win32_map_fstat_error
+
+extern void _MD_win32_map_rename_error(PRInt32 err);
+#define	_PR_MD_MAP_RENAME_ERROR	_MD_win32_map_rename_error
+
+extern void _MD_win32_map_access_error(PRInt32 err);
+#define	_PR_MD_MAP_ACCESS_ERROR	_MD_win32_map_access_error
+
+extern void _MD_win32_map_mkdir_error(PRInt32 err);
+#define	_PR_MD_MAP_MKDIR_ERROR	_MD_win32_map_mkdir_error
+
+extern void _MD_win32_map_rmdir_error(PRInt32 err);
+#define	_PR_MD_MAP_RMDIR_ERROR	_MD_win32_map_rmdir_error
+
+extern void _MD_win32_map_read_error(PRInt32 err);
+#define	_PR_MD_MAP_READ_ERROR	_MD_win32_map_read_error
+
+extern void _MD_win32_map_transmitfile_error(PRInt32 err);
+#define	_PR_MD_MAP_TRANSMITFILE_ERROR	_MD_win32_map_transmitfile_error
+
+extern void _MD_win32_map_write_error(PRInt32 err);
+#define	_PR_MD_MAP_WRITE_ERROR	_MD_win32_map_write_error
+
+extern void _MD_win32_map_lseek_error(PRInt32 err);
+#define	_PR_MD_MAP_LSEEK_ERROR	_MD_win32_map_lseek_error
+
+extern void _MD_win32_map_fsync_error(PRInt32 err);
+#define	_PR_MD_MAP_FSYNC_ERROR	_MD_win32_map_fsync_error
+
+extern void _MD_win32_map_close_error(PRInt32 err);
+#define	_PR_MD_MAP_CLOSE_ERROR	_MD_win32_map_close_error
+
+extern void _MD_win32_map_socket_error(PRInt32 err);
+#define	_PR_MD_MAP_SOCKET_ERROR	_MD_win32_map_socket_error
+
+extern void _MD_win32_map_recv_error(PRInt32 err);
+#define	_PR_MD_MAP_RECV_ERROR	_MD_win32_map_recv_error
+
+extern void _MD_win32_map_recvfrom_error(PRInt32 err);
+#define	_PR_MD_MAP_RECVFROM_ERROR	_MD_win32_map_recvfrom_error
+
+extern void _MD_win32_map_send_error(PRInt32 err);
+#define	_PR_MD_MAP_SEND_ERROR	_MD_win32_map_send_error
+
+extern void _MD_win32_map_sendto_error(PRInt32 err);
+#define	_PR_MD_MAP_SENDTO_ERROR	_MD_win32_map_sendto_error
+
+extern void _MD_win32_map_accept_error(PRInt32 err);
+#define	_PR_MD_MAP_ACCEPT_ERROR	_MD_win32_map_accept_error
+
+extern void _MD_win32_map_acceptex_error(PRInt32 err);
+#define	_PR_MD_MAP_ACCEPTEX_ERROR	_MD_win32_map_acceptex_error
+
+extern PRInt32 _MD_win32_map_connect_error(PRInt32 err);
+#define	_PR_MD_MAP_CONNECT_ERROR	_MD_win32_map_connect_error
+
+extern void _MD_win32_map_bind_error(PRInt32 err);
+#define	_PR_MD_MAP_BIND_ERROR	_MD_win32_map_bind_error
+
+extern void _MD_win32_map_listen_error(PRInt32 err);
+#define	_PR_MD_MAP_LISTEN_ERROR	_MD_win32_map_listen_error
+
+extern void _MD_win32_map_shutdown_error(PRInt32 err);
+#define	_PR_MD_MAP_SHUTDOWN_ERROR	_MD_win32_map_shutdown_error
+
+extern void _MD_win32_map_getsockname_error(PRInt32 err);
+#define	_PR_MD_MAP_GETSOCKNAME_ERROR	_MD_win32_map_getsockname_error
+
+extern void _MD_win32_map_getpeername_error(PRInt32 err);
+#define	_PR_MD_MAP_GETPEERNAME_ERROR	_MD_win32_map_getpeername_error
+
+extern void _MD_win32_map_getsockopt_error(PRInt32 err);
+#define	_PR_MD_MAP_GETSOCKOPT_ERROR	_MD_win32_map_getsockopt_error
+
+extern void _MD_win32_map_setsockopt_error(PRInt32 err);
+#define	_PR_MD_MAP_SETSOCKOPT_ERROR	_MD_win32_map_setsockopt_error
+
+extern void _MD_win32_map_open_error(PRInt32 err);
+#define	_PR_MD_MAP_OPEN_ERROR	_MD_win32_map_open_error
+
+extern void _MD_win32_map_gethostname_error(PRInt32 err);
+#define	_PR_MD_MAP_GETHOSTNAME_ERROR	_MD_win32_map_gethostname_error
+
+extern void _MD_win32_map_select_error(PRInt32 err);
+#define	_PR_MD_MAP_SELECT_ERROR	_MD_win32_map_select_error
+
+extern void _MD_win32_map_lockf_error(int err);
+#define _PR_MD_MAP_LOCKF_ERROR  _MD_win32_map_lockf_error
+
+#endif /* nspr_win32_errors_h___ */
diff --git a/pr/include/md/_win95.cfg b/pr/include/md/_win95.cfg
new file mode 100644
index 0000000..1e693cc
--- /dev/null
+++ b/pr/include/md/_win95.cfg
@@ -0,0 +1,272 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef XP_PC
+#define XP_PC
+#endif
+
+#ifndef WIN32
+#define WIN32
+#endif
+
+#ifndef WIN95
+#define WIN95
+#endif
+
+#define PR_AF_INET6 23  /* same as AF_INET6 */
+
+#if defined(_M_IX86) || defined(_X86_)
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_WORD	4
+#define PR_BYTES_PER_DWORD	8
+#define PR_BYTES_PER_DOUBLE 8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_WORD	32
+#define PR_BITS_PER_DWORD	64
+#define PR_BITS_PER_DOUBLE  64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_WORD_LOG2	5
+#define PR_BITS_PER_DWORD_LOG2	6
+#define PR_BITS_PER_DOUBLE_LOG2 6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_WORD	4
+#define PR_ALIGN_OF_DWORD	8
+#define PR_ALIGN_OF_DOUBLE  4
+#define PR_ALIGN_OF_POINTER 4
+
+#define PR_BYTES_PER_WORD_LOG2	2
+#define PR_BYTES_PER_DWORD_LOG2	3
+
+#elif defined(_M_X64) || defined(_M_AMD64) || defined(_AMD64_)
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_WORD	8
+#define PR_BYTES_PER_DWORD	8
+#define PR_BYTES_PER_DOUBLE 8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_WORD	64
+#define PR_BITS_PER_DWORD	64
+#define PR_BITS_PER_DOUBLE  64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_WORD_LOG2	6
+#define PR_BITS_PER_DWORD_LOG2	6
+#define PR_BITS_PER_DOUBLE_LOG2 6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_WORD	8
+#define PR_ALIGN_OF_DWORD	8
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+
+#define PR_BYTES_PER_WORD_LOG2	3
+#define PR_BYTES_PER_DWORD_LOG2	3
+
+#elif defined(_M_IA64) || defined(_IA64_)
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_WORD	8
+#define PR_BYTES_PER_DWORD	8
+#define PR_BYTES_PER_DOUBLE 8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_WORD	64
+#define PR_BITS_PER_DWORD	64
+#define PR_BITS_PER_DOUBLE  64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_WORD_LOG2	6
+#define PR_BITS_PER_DWORD_LOG2	6
+#define PR_BITS_PER_DOUBLE_LOG2 6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_WORD	8
+#define PR_ALIGN_OF_DWORD	8
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+
+#define PR_BYTES_PER_WORD_LOG2	3
+#define PR_BYTES_PER_DWORD_LOG2	3
+
+#elif defined(_M_ARM) || defined(_ARM_)
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_WORD   4
+#define PR_BYTES_PER_DWORD  8
+#define PR_BYTES_PER_DOUBLE 8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_WORD    32
+#define PR_BITS_PER_DWORD   64
+#define PR_BITS_PER_DOUBLE  64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_WORD_LOG2   5
+#define PR_BITS_PER_DWORD_LOG2  6
+#define PR_BITS_PER_DOUBLE_LOG2 6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_WORD    4
+#define PR_ALIGN_OF_DWORD   8
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 4
+
+#define PR_BYTES_PER_WORD_LOG2  2
+#define PR_BYTES_PER_DWORD_LOG2 3
+
+#else /* defined(_M_IX86) || defined(_X86_) */
+
+#error unknown processor architecture
+
+#endif /* defined(_M_IX86) || defined(_X86_) */
+
+#ifndef HAVE_LONG_LONG
+#define HAVE_LONG_LONG
+#endif
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE      PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT     PR_BYTES_PER_SHORT
+#define BYTES_PER_INT       PR_BYTES_PER_INT
+#define BYTES_PER_INT64     PR_BYTES_PER_INT64
+#define BYTES_PER_LONG      PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT     PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE    PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD      PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD     PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE       PR_BITS_PER_BYTE
+#define BITS_PER_SHORT      PR_BITS_PER_SHORT
+#define BITS_PER_INT        PR_BITS_PER_INT
+#define BITS_PER_INT64      PR_BITS_PER_INT64
+#define BITS_PER_LONG       PR_BITS_PER_LONG
+#define BITS_PER_FLOAT      PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE     PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD       PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2  PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2 PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2   PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2 PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2  PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2 PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2    PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2  PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT      PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT        PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG       PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64      PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT      PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE     PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER    PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD       PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2		PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2    PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2    PR_WORDS_PER_DWORD_LOG2
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
diff --git a/pr/include/md/_win95.h b/pr/include/md/_win95.h
new file mode 100644
index 0000000..d65e264
--- /dev/null
+++ b/pr/include/md/_win95.h
@@ -0,0 +1,544 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_win95_defs_h___
+#define nspr_win95_defs_h___
+
+#include "prio.h"
+
+#include <windows.h>
+#include <winsock.h>
+#include <errno.h>
+
+/*
+ * Internal configuration macros
+ */
+
+#define PR_LINKER_ARCH      "win32"
+#define _PR_SI_SYSNAME        "WIN95"
+#if defined(_M_IX86) || defined(_X86_)
+#define _PR_SI_ARCHITECTURE   "x86"
+#elif defined(_M_X64) || defined(_M_AMD64) || defined(_AMD64_)
+#define _PR_SI_ARCHITECTURE   "x86-64"
+#elif defined(_M_IA64) || defined(_IA64_)
+#define _PR_SI_ARCHITECTURE   "ia64"
+#elif defined(_M_ARM) || defined(_ARM_)
+#define _PR_SI_ARCHITECTURE   "arm"
+#else
+#error unknown processor architecture
+#endif
+
+#define HAVE_DLL
+#undef  HAVE_THREAD_AFFINITY
+#define _PR_HAVE_GETADDRINFO
+#define _PR_INET6_PROBE
+#ifndef _PR_INET6
+#define AF_INET6 23
+/* newer ws2tcpip.h provides these */
+#ifndef AI_CANONNAME
+#define AI_CANONNAME 0x2
+#define AI_NUMERICHOST 0x4
+#define NI_NUMERICHOST 0x02
+struct addrinfo {
+    int ai_flags;
+    int ai_family;
+    int ai_socktype;
+    int ai_protocol;
+    size_t ai_addrlen;
+    char *ai_canonname;
+    struct sockaddr *ai_addr;
+    struct addrinfo *ai_next;
+};
+#endif
+#define _PR_HAVE_MD_SOCKADDR_IN6
+/* isomorphic to struct in6_addr on Windows */
+struct _md_in6_addr {
+    union {
+        PRUint8  _S6_u8[16];
+        PRUint16 _S6_u16[8];
+    } _S6_un;
+};
+/* isomorphic to struct sockaddr_in6 on Windows */
+struct _md_sockaddr_in6 {
+    PRInt16 sin6_family;
+    PRUint16 sin6_port;
+    PRUint32 sin6_flowinfo;
+    struct _md_in6_addr sin6_addr;
+    PRUint32 sin6_scope_id;
+};
+#endif
+#define _PR_HAVE_THREADSAFE_GETHOST
+#define _PR_HAVE_ATOMIC_OPS
+#define PR_HAVE_WIN32_NAMED_SHARED_MEMORY
+
+/* --- Common User-Thread/Native-Thread Definitions --------------------- */
+
+/* --- Globals --- */
+extern struct PRLock                      *_pr_schedLock;
+
+/* --- Typedefs --- */
+typedef void (*FiberFunc)(void *);
+
+#define PR_NUM_GCREGS           8
+typedef PRInt32	                PR_CONTEXT_TYPE[PR_NUM_GCREGS];
+#define GC_VMBASE               0x40000000
+#define GC_VMLIMIT              0x00FFFFFF
+
+#define _MD_MAGIC_THREAD	0x22222222
+#define _MD_MAGIC_THREADSTACK	0x33333333
+#define _MD_MAGIC_SEGMENT	0x44444444
+#define _MD_MAGIC_DIR		0x55555555
+#define _MD_MAGIC_CV        0x66666666
+
+struct _MDCPU {
+    int              unused;
+};
+
+struct _MDThread {
+    HANDLE           blocked_sema;      /* Threads block on this when waiting
+                                         * for IO or CondVar.
+                                         */
+    PRBool           inCVWaitQueue;     /* PR_TRUE if the thread is in the
+                                         * wait queue of some cond var.
+                                         * PR_FALSE otherwise.  */
+    HANDLE           handle;            /* Win32 thread handle */
+    PRUint32         id;
+    void            *sp;                /* only valid when suspended */
+    PRUint32         magic;             /* for debugging */
+    PR_CONTEXT_TYPE  gcContext;         /* Thread context for GC */
+    struct PRThread *prev, *next;       /* used by the cvar wait queue to
+                                         * chain the PRThread structures
+                                         * together */
+    void (*start)(void *);              /* used by _PR_MD_CREATE_THREAD to
+                                         * pass its 'start' argument to
+                                         * pr_root. */
+};
+
+struct _MDThreadStack {
+    PRUint32           magic;          /* for debugging */
+};
+
+struct _MDSegment {
+    PRUint32           magic;          /* for debugging */
+};
+
+#undef PROFILE_LOCKS
+
+struct _MDDir {
+    HANDLE           d_hdl;
+    WIN32_FIND_DATAA d_entry;
+    PRBool           firstEntry;     /* Is this the entry returned
+                                      * by FindFirstFile()? */
+    PRUint32         magic;          /* for debugging */
+};
+
+#ifdef MOZ_UNICODE
+struct _MDDirUTF16 {
+    HANDLE           d_hdl;
+    WIN32_FIND_DATAW d_entry;
+    PRBool           firstEntry;     /* Is this the entry returned
+                                      * by FindFirstFileW()? */
+    PRUint32         magic;          /* for debugging */
+};
+#endif /* MOZ_UNICODE */
+
+struct _MDCVar {
+    PRUint32 magic;
+    struct PRThread *waitHead, *waitTail;  /* the wait queue: a doubly-
+                                            * linked list of threads
+                                            * waiting on this condition
+                                            * variable */
+    PRIntn nwait;                          /* number of threads in the
+                                            * wait queue */
+};
+
+#define _MD_CV_NOTIFIED_LENGTH 6
+typedef struct _MDNotified _MDNotified;
+struct _MDNotified {
+    PRIntn length;                     /* # of used entries in this
+                                        * structure */
+    struct {
+        struct _MDCVar *cv;            /* the condition variable notified */
+        PRIntn times;                  /* and the number of times notified */
+        struct PRThread *notifyHead;   /* list of threads to wake up */
+    } cv[_MD_CV_NOTIFIED_LENGTH];
+    _MDNotified *link;                 /* link to another of these, or NULL */
+};
+
+struct _MDLock {
+    CRITICAL_SECTION mutex;          /* this is recursive on NT */
+
+    /*
+     * When notifying cvars, there is no point in actually
+     * waking up the threads waiting on the cvars until we've
+     * released the lock.  So, we temporarily record the cvars.
+     * When doing an unlock, we'll then wake up the waiting threads.
+     */
+    struct _MDNotified notified;     /* array of conditions notified */
+#ifdef PROFILE_LOCKS
+    PRInt32 hitcount;
+    PRInt32 misscount;
+#endif
+};
+
+struct _MDSemaphore {
+    HANDLE           sem;
+};
+
+struct _MDFileDesc {
+    PROsfd osfd;     /* The osfd can come from one of three spaces:
+                      * - For stdin, stdout, and stderr, we are using
+                      *   the libc file handle (0, 1, 2), which is an int.
+                      * - For files and pipes, we are using Win32 HANDLE,
+                      *   which is a void*.
+                      * - For sockets, we are using Winsock SOCKET, which
+                      *   is a u_int.
+                      */
+};
+
+struct _MDProcess {
+    HANDLE handle;
+    DWORD id;
+};
+
+/* --- Misc stuff --- */
+#define _MD_GET_SP(thread)            (thread)->md.gcContext[6]
+
+/* --- NT security stuff --- */
+
+extern void _PR_NT_InitSids(void);
+extern void _PR_NT_FreeSids(void);
+extern PRStatus _PR_NT_MakeSecurityDescriptorACL(
+    PRIntn mode,
+    DWORD accessTable[],
+    PSECURITY_DESCRIPTOR *resultSD,
+    PACL *resultACL
+);
+extern void _PR_NT_FreeSecurityDescriptorACL(
+    PSECURITY_DESCRIPTOR pSD, PACL pACL);
+
+/* --- IO stuff --- */
+
+#define _MD_OPEN                      _PR_MD_OPEN
+#define _MD_OPEN_FILE                 _PR_MD_OPEN_FILE
+#define _MD_READ                      _PR_MD_READ
+#define _MD_WRITE                     _PR_MD_WRITE
+#define _MD_WRITEV                    _PR_MD_WRITEV
+#define _MD_LSEEK                     _PR_MD_LSEEK
+#define _MD_LSEEK64                   _PR_MD_LSEEK64
+extern PRInt32 _MD_CloseFile(PROsfd osfd);
+#define _MD_CLOSE_FILE                _MD_CloseFile
+#define _MD_GETFILEINFO               _PR_MD_GETFILEINFO
+#define _MD_GETFILEINFO64             _PR_MD_GETFILEINFO64
+#define _MD_GETOPENFILEINFO           _PR_MD_GETOPENFILEINFO
+#define _MD_GETOPENFILEINFO64         _PR_MD_GETOPENFILEINFO64
+#define _MD_STAT                      _PR_MD_STAT
+#define _MD_RENAME                    _PR_MD_RENAME     
+#define _MD_ACCESS                    _PR_MD_ACCESS     
+#define _MD_DELETE                    _PR_MD_DELETE     
+#define _MD_MKDIR                     _PR_MD_MKDIR      
+#define _MD_MAKE_DIR                  _PR_MD_MAKE_DIR
+#define _MD_RMDIR                     _PR_MD_RMDIR      
+#define _MD_LOCKFILE                  _PR_MD_LOCKFILE
+#define _MD_TLOCKFILE                 _PR_MD_TLOCKFILE
+#define _MD_UNLOCKFILE                _PR_MD_UNLOCKFILE
+
+/* --- UTF16 IO stuff --- */
+#ifdef MOZ_UNICODE
+#define _MD_OPEN_FILE_UTF16           _PR_MD_OPEN_FILE_UTF16
+#define _MD_OPEN_DIR_UTF16            _PR_MD_OPEN_DIR_UTF16
+#define _MD_READ_DIR_UTF16            _PR_MD_READ_DIR_UTF16
+#define _MD_CLOSE_DIR_UTF16           _PR_MD_CLOSE_DIR_UTF16
+#define _MD_GETFILEINFO64_UTF16       _PR_MD_GETFILEINFO64_UTF16
+#endif /* MOZ_UNICODE */
+
+/* --- Socket IO stuff --- */
+extern void _PR_MD_InitSockets(void);
+extern void _PR_MD_CleanupSockets(void);
+#define _MD_EACCES                WSAEACCES
+#define _MD_EADDRINUSE            WSAEADDRINUSE
+#define _MD_EADDRNOTAVAIL         WSAEADDRNOTAVAIL
+#define _MD_EAFNOSUPPORT          WSAEAFNOSUPPORT
+#define _MD_EAGAIN                WSAEWOULDBLOCK
+#define _MD_EALREADY              WSAEALREADY
+#define _MD_EBADF                 WSAEBADF
+#define _MD_ECONNREFUSED          WSAECONNREFUSED
+#define _MD_ECONNRESET            WSAECONNRESET
+#define _MD_EFAULT                WSAEFAULT
+#define _MD_EINPROGRESS           WSAEINPROGRESS
+#define _MD_EINTR                 WSAEINTR
+#define _MD_EINVAL                EINVAL
+#define _MD_EISCONN               WSAEISCONN
+#define _MD_ENETUNREACH           WSAENETUNREACH
+#define _MD_ENOENT                ENOENT
+#define _MD_ENOTCONN              WSAENOTCONN
+#define _MD_ENOTSOCK              WSAENOTSOCK
+#define _MD_EOPNOTSUPP            WSAEOPNOTSUPP
+#define _MD_EWOULDBLOCK           WSAEWOULDBLOCK
+#define _MD_GET_SOCKET_ERROR()    WSAGetLastError()
+#define _MD_SET_SOCKET_ERROR(_err) WSASetLastError(_err)
+
+#define _MD_INIT_FILEDESC(fd)
+extern void _MD_MakeNonblock(PRFileDesc *f);
+#define _MD_MAKE_NONBLOCK             _MD_MakeNonblock
+#define _MD_INIT_FD_INHERITABLE       _PR_MD_INIT_FD_INHERITABLE
+#define _MD_QUERY_FD_INHERITABLE      _PR_MD_QUERY_FD_INHERITABLE
+#define _MD_SHUTDOWN                  _PR_MD_SHUTDOWN
+#define _MD_LISTEN                    _PR_MD_LISTEN
+extern PRInt32 _MD_CloseSocket(PROsfd osfd);
+#define _MD_CLOSE_SOCKET              _MD_CloseSocket
+#define _MD_SENDTO                    _PR_MD_SENDTO
+#define _MD_RECVFROM                  _PR_MD_RECVFROM
+#define _MD_SOCKETPAIR(s, type, proto, sv) -1
+#define _MD_GETSOCKNAME               _PR_MD_GETSOCKNAME
+#define _MD_GETPEERNAME               _PR_MD_GETPEERNAME
+#define _MD_GETSOCKOPT                _PR_MD_GETSOCKOPT
+#define _MD_SETSOCKOPT                _PR_MD_SETSOCKOPT
+#define _MD_SET_FD_INHERITABLE        _PR_MD_SET_FD_INHERITABLE
+#define _MD_SELECT                    select
+#define _MD_FSYNC                     _PR_MD_FSYNC
+#define READ_FD                       1
+#define WRITE_FD                      2
+
+#define _MD_INIT_ATOMIC()
+#if defined(_M_IX86) || defined(_X86_)
+#define _MD_ATOMIC_INCREMENT          _PR_MD_ATOMIC_INCREMENT
+#define _MD_ATOMIC_ADD          	  _PR_MD_ATOMIC_ADD
+#define _MD_ATOMIC_DECREMENT          _PR_MD_ATOMIC_DECREMENT
+#else /* non-x86 processors */
+#define _MD_ATOMIC_INCREMENT(x)       InterlockedIncrement((PLONG)x)
+#define _MD_ATOMIC_ADD(ptr,val)    (InterlockedExchangeAdd((PLONG)ptr, (LONG)val) + val)
+#define _MD_ATOMIC_DECREMENT(x)       InterlockedDecrement((PLONG)x)
+#endif /* x86 */
+#define _MD_ATOMIC_SET(x,y)           InterlockedExchange((PLONG)x, (LONG)y)
+
+#define _MD_INIT_IO                   _PR_MD_INIT_IO
+
+
+/* win95 doesn't have async IO */
+#define _MD_SOCKET                    _PR_MD_SOCKET
+extern PRInt32 _MD_SocketAvailable(PRFileDesc *fd);
+#define _MD_SOCKETAVAILABLE           _MD_SocketAvailable
+#define _MD_PIPEAVAILABLE             _PR_MD_PIPEAVAILABLE
+#define _MD_CONNECT                   _PR_MD_CONNECT
+extern PROsfd _MD_Accept(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
+        PRIntervalTime timeout);
+#define _MD_ACCEPT                    _MD_Accept
+#define _MD_BIND                      _PR_MD_BIND
+#define _MD_RECV                      _PR_MD_RECV
+#define _MD_SEND                      _PR_MD_SEND
+#define _MD_PR_POLL                   _PR_MD_PR_POLL
+
+/* --- Scheduler stuff --- */
+// #define _MD_PAUSE_CPU                 _PR_MD_PAUSE_CPU
+#define _MD_PAUSE_CPU
+
+/* --- DIR stuff --- */
+#define PR_DIRECTORY_SEPARATOR        '\\'
+#define PR_DIRECTORY_SEPARATOR_STR    "\\"
+#define PR_PATH_SEPARATOR		';'
+#define PR_PATH_SEPARATOR_STR		";"
+#define _MD_ERRNO()                   GetLastError()
+#define _MD_OPEN_DIR                  _PR_MD_OPEN_DIR
+#define _MD_CLOSE_DIR                 _PR_MD_CLOSE_DIR
+#define _MD_READ_DIR                  _PR_MD_READ_DIR
+
+/* --- Segment stuff --- */
+#define _MD_INIT_SEGS()
+#define _MD_ALLOC_SEGMENT(seg, size, vaddr)   0
+#define _MD_FREE_SEGMENT(seg)
+
+/* --- Environment Stuff --- */
+#define _MD_GET_ENV                 _PR_MD_GET_ENV
+#define _MD_PUT_ENV                 _PR_MD_PUT_ENV
+
+/* --- Threading Stuff --- */
+#define _MD_DEFAULT_STACK_SIZE            0
+#define _MD_INIT_THREAD             _PR_MD_INIT_THREAD
+#define _MD_INIT_ATTACHED_THREAD    _PR_MD_INIT_THREAD
+#define _MD_CREATE_THREAD           _PR_MD_CREATE_THREAD
+#define _MD_YIELD                   _PR_MD_YIELD
+#define _MD_SET_PRIORITY            _PR_MD_SET_PRIORITY
+#define _MD_SET_CURRENT_THREAD_NAME _PR_MD_SET_CURRENT_THREAD_NAME
+#define _MD_CLEAN_THREAD            _PR_MD_CLEAN_THREAD
+#define _MD_SETTHREADAFFINITYMASK   _PR_MD_SETTHREADAFFINITYMASK
+#define _MD_GETTHREADAFFINITYMASK   _PR_MD_GETTHREADAFFINITYMASK
+#define _MD_EXIT_THREAD             _PR_MD_EXIT_THREAD
+#define _MD_EXIT                    _PR_MD_EXIT
+#define _MD_SUSPEND_THREAD          _PR_MD_SUSPEND_THREAD
+#define _MD_RESUME_THREAD           _PR_MD_RESUME_THREAD
+#define _MD_SUSPEND_CPU             _PR_MD_SUSPEND_CPU
+#define _MD_RESUME_CPU              _PR_MD_RESUME_CPU
+#define _MD_BEGIN_SUSPEND_ALL()
+#define _MD_BEGIN_RESUME_ALL()
+#define _MD_END_SUSPEND_ALL()
+#define _MD_END_RESUME_ALL()
+
+/* --- Lock stuff --- */
+#define _PR_LOCK                      _MD_LOCK
+#define _PR_UNLOCK                    _MD_UNLOCK
+
+#define _MD_NEW_LOCK                  _PR_MD_NEW_LOCK
+#define _MD_FREE_LOCK(lock)           DeleteCriticalSection(&((lock)->mutex))
+#define _MD_LOCK(lock)                EnterCriticalSection(&((lock)->mutex))
+#define _MD_TEST_AND_LOCK(lock)       (EnterCriticalSection(&((lock)->mutex)),0)
+#define _MD_UNLOCK                    _PR_MD_UNLOCK
+
+/* --- lock and cv waiting --- */
+#define _MD_WAIT                      _PR_MD_WAIT
+#define _MD_WAKEUP_WAITER             _PR_MD_WAKEUP_WAITER
+
+/* --- CVar ------------------- */
+#define _MD_WAIT_CV					  _PR_MD_WAIT_CV
+#define _MD_NEW_CV					  _PR_MD_NEW_CV
+#define _MD_FREE_CV					  _PR_MD_FREE_CV
+#define _MD_NOTIFY_CV				  _PR_MD_NOTIFY_CV	
+#define _MD_NOTIFYALL_CV			  _PR_MD_NOTIFYALL_CV
+
+   /* XXXMB- the IOQ stuff is certainly not working correctly yet. */
+// extern  struct _MDLock              _pr_ioq_lock;
+#define _MD_IOQ_LOCK()                
+#define _MD_IOQ_UNLOCK()              
+
+
+/* --- Initialization stuff --- */
+#define _MD_START_INTERRUPTS()
+#define _MD_STOP_INTERRUPTS()
+#define _MD_DISABLE_CLOCK_INTERRUPTS()
+#define _MD_ENABLE_CLOCK_INTERRUPTS()
+#define _MD_BLOCK_CLOCK_INTERRUPTS()
+#define _MD_UNBLOCK_CLOCK_INTERRUPTS()
+#define _MD_EARLY_INIT                _PR_MD_EARLY_INIT
+#define _MD_FINAL_INIT()
+#define _MD_EARLY_CLEANUP()
+#define _MD_INIT_CPUS()
+#define _MD_INIT_RUNNING_CPU(cpu)
+
+struct PRProcess;
+struct PRProcessAttr;
+
+#define _MD_CREATE_PROCESS _PR_CreateWindowsProcess
+extern struct PRProcess * _PR_CreateWindowsProcess(
+    const char *path,
+    char *const *argv,
+    char *const *envp,
+    const struct PRProcessAttr *attr
+);
+
+#define _MD_DETACH_PROCESS _PR_DetachWindowsProcess
+extern PRStatus _PR_DetachWindowsProcess(struct PRProcess *process);
+
+/* --- Wait for a child process to terminate --- */
+#define _MD_WAIT_PROCESS _PR_WaitWindowsProcess
+extern PRStatus _PR_WaitWindowsProcess(struct PRProcess *process, 
+    PRInt32 *exitCode);
+
+#define _MD_KILL_PROCESS _PR_KillWindowsProcess
+extern PRStatus _PR_KillWindowsProcess(struct PRProcess *process);
+
+#define _MD_CLEANUP_BEFORE_EXIT           _PR_MD_CLEANUP_BEFORE_EXIT
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
+    PR_BEGIN_MACRO \
+    *status = PR_TRUE; \
+    PR_END_MACRO
+#define _MD_SWITCH_CONTEXT
+#define _MD_RESTORE_CONTEXT
+
+/* --- Intervals --- */
+#define _MD_INTERVAL_INIT                 _PR_MD_INTERVAL_INIT
+#define _MD_GET_INTERVAL                  _PR_MD_GET_INTERVAL
+#define _MD_INTERVAL_PER_SEC              _PR_MD_INTERVAL_PER_SEC
+#define _MD_INTERVAL_PER_MILLISEC()       (_PR_MD_INTERVAL_PER_SEC() / 1000)
+#define _MD_INTERVAL_PER_MICROSEC()       (_PR_MD_INTERVAL_PER_SEC() / 1000000)
+
+/* --- Time --- */
+extern void _PR_FileTimeToPRTime(const FILETIME *filetime, PRTime *prtm);
+
+#ifdef WINCE
+extern void _MD_InitTime(void);
+extern void _MD_CleanupTime(void);
+#endif
+
+/* --- Native-Thread Specific Definitions ------------------------------- */
+
+extern struct PRThread * _MD_CURRENT_THREAD(void);
+
+#ifdef _PR_USE_STATIC_TLS
+extern __declspec(thread) struct PRThread *_pr_currentThread;
+#define _MD_GET_ATTACHED_THREAD() _pr_currentThread
+#define _MD_SET_CURRENT_THREAD(_thread) (_pr_currentThread = (_thread))
+
+extern __declspec(thread) struct PRThread *_pr_thread_last_run;
+#define _MD_LAST_THREAD() _pr_thread_last_run
+#define _MD_SET_LAST_THREAD(_thread) (_pr_thread_last_run = 0)
+
+extern __declspec(thread) struct _PRCPU *_pr_currentCPU;
+#define _MD_CURRENT_CPU() _pr_currentCPU
+#define _MD_SET_CURRENT_CPU(_cpu) (_pr_currentCPU = 0)
+#else /* _PR_USE_STATIC_TLS */
+extern DWORD _pr_currentThreadIndex;
+#define _MD_GET_ATTACHED_THREAD() ((PRThread *) TlsGetValue(_pr_currentThreadIndex))
+#define _MD_SET_CURRENT_THREAD(_thread) TlsSetValue(_pr_currentThreadIndex, (_thread))
+
+extern DWORD _pr_lastThreadIndex;
+#define _MD_LAST_THREAD() ((PRThread *) TlsGetValue(_pr_lastThreadIndex))
+#define _MD_SET_LAST_THREAD(_thread) TlsSetValue(_pr_lastThreadIndex, 0)
+
+extern DWORD _pr_currentCPUIndex;
+#define _MD_CURRENT_CPU() ((struct _PRCPU *) TlsGetValue(_pr_currentCPUIndex))
+#define _MD_SET_CURRENT_CPU(_cpu) TlsSetValue(_pr_currentCPUIndex, 0)
+#endif /* _PR_USE_STATIC_TLS */
+
+/* --- Scheduler stuff --- */
+#define LOCK_SCHEDULER()                 0
+#define UNLOCK_SCHEDULER()               0
+#define _PR_LockSched()                	 0
+#define _PR_UnlockSched()                0
+
+/* --- Initialization stuff --- */
+#define _MD_INIT_LOCKS                   _PR_MD_INIT_LOCKS
+
+/* --- Stack stuff --- */
+#define _MD_INIT_STACK(stack, redzone)
+#define _MD_CLEAR_STACK(stack)
+
+/* --- Memory-mapped files stuff --- */
+
+struct _MDFileMap {
+    HANDLE hFileMap;
+    DWORD dwAccess;
+};
+
+extern PRStatus _MD_CreateFileMap(struct PRFileMap *fmap, PRInt64 size);
+#define _MD_CREATE_FILE_MAP _MD_CreateFileMap
+
+extern PRInt32 _MD_GetMemMapAlignment(void);
+#define _MD_GET_MEM_MAP_ALIGNMENT _MD_GetMemMapAlignment
+
+extern void * _MD_MemMap(struct PRFileMap *fmap, PRInt64 offset,
+        PRUint32 len);
+#define _MD_MEM_MAP _MD_MemMap
+
+extern PRStatus _MD_MemUnmap(void *addr, PRUint32 size);
+#define _MD_MEM_UNMAP _MD_MemUnmap
+
+extern PRStatus _MD_CloseFileMap(struct PRFileMap *fmap);
+#define _MD_CLOSE_FILE_MAP _MD_CloseFileMap
+
+extern PRStatus _MD_SyncMemMap(
+    PRFileDesc *fd,
+    void *addr,
+    PRUint32 len);
+#define _MD_SYNC_MEM_MAP _MD_SyncMemMap
+
+/* --- Named semaphores stuff --- */
+#define _PR_HAVE_NAMED_SEMAPHORES
+#define _MD_OPEN_SEMAPHORE            _PR_MD_OPEN_SEMAPHORE
+#define _MD_WAIT_SEMAPHORE            _PR_MD_WAIT_SEMAPHORE
+#define _MD_POST_SEMAPHORE            _PR_MD_POST_SEMAPHORE
+#define _MD_CLOSE_SEMAPHORE           _PR_MD_CLOSE_SEMAPHORE
+#define _MD_DELETE_SEMAPHORE(name)    PR_SUCCESS  /* no op */
+
+#endif /* nspr_win32_defs_h___ */
diff --git a/pr/include/md/_winnt.cfg b/pr/include/md/_winnt.cfg
new file mode 100644
index 0000000..e2a277f
--- /dev/null
+++ b/pr/include/md/_winnt.cfg
@@ -0,0 +1,224 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#ifndef nspr_cpucfg___
+#define nspr_cpucfg___
+
+#ifndef XP_PC
+#define XP_PC
+#endif
+
+#ifndef WIN32
+#define WIN32
+#endif
+
+#ifndef WINNT
+#define WINNT
+#endif
+
+#define PR_AF_INET6 23  /* same as AF_INET6 */
+
+#if defined(_M_IX86) || defined(_X86_)
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_WORD	4
+#define PR_BYTES_PER_DWORD	8
+#define PR_BYTES_PER_DOUBLE 8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_WORD	32
+#define PR_BITS_PER_DWORD	64
+#define PR_BITS_PER_DOUBLE  64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_WORD_LOG2	5
+#define PR_BITS_PER_DWORD_LOG2	6
+#define PR_BITS_PER_DOUBLE_LOG2 6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_WORD	4
+#define PR_ALIGN_OF_DWORD	8
+#define PR_ALIGN_OF_DOUBLE  4
+#define PR_ALIGN_OF_POINTER 4
+
+#define PR_BYTES_PER_WORD_LOG2	2
+#define PR_BYTES_PER_DWORD_LOG2	2
+
+#elif defined(_M_X64) || defined(_M_AMD64) || defined(_AMD64_)
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+#define PR_BYTES_PER_DOUBLE 8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_WORD    64
+#define PR_BITS_PER_DWORD   64
+#define PR_BITS_PER_DOUBLE  64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_WORD_LOG2	6
+#define PR_BITS_PER_DWORD_LOG2	6
+#define PR_BITS_PER_DOUBLE_LOG2 6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_WORD    8
+#define PR_ALIGN_OF_DWORD   8
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+
+#define PR_BYTES_PER_WORD_LOG2	3
+#define PR_BYTES_PER_DWORD_LOG2	3
+
+#elif defined(_M_IA64) || defined(_IA64_)
+
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   4
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+#define PR_BYTES_PER_DOUBLE 8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    32
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_WORD    64
+#define PR_BITS_PER_DWORD   64
+#define PR_BITS_PER_DOUBLE  64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   5
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_WORD_LOG2	6
+#define PR_BITS_PER_DWORD_LOG2	6
+#define PR_BITS_PER_DOUBLE_LOG2 6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    4
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_WORD    8
+#define PR_ALIGN_OF_DWORD   8
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+
+#define PR_BYTES_PER_WORD_LOG2	3
+#define PR_BYTES_PER_DWORD_LOG2	3
+
+#else /* defined(_M_IX86) || defined(_X86_) */
+
+#error unknown processor architecture
+
+#endif /* defined(_M_IX86) || defined(_X86_) */
+
+#ifndef HAVE_LONG_LONG
+#define HAVE_LONG_LONG
+#endif
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#define BYTES_PER_BYTE      PR_BYTES_PER_BYTE
+#define BYTES_PER_SHORT     PR_BYTES_PER_SHORT
+#define BYTES_PER_INT       PR_BYTES_PER_INT
+#define BYTES_PER_INT64     PR_BYTES_PER_INT64
+#define BYTES_PER_LONG      PR_BYTES_PER_LONG
+#define BYTES_PER_FLOAT     PR_BYTES_PER_FLOAT
+#define BYTES_PER_DOUBLE    PR_BYTES_PER_DOUBLE
+#define BYTES_PER_WORD      PR_BYTES_PER_WORD
+#define BYTES_PER_DWORD     PR_BYTES_PER_DWORD
+
+#define BITS_PER_BYTE       PR_BITS_PER_BYTE
+#define BITS_PER_SHORT      PR_BITS_PER_SHORT
+#define BITS_PER_INT        PR_BITS_PER_INT
+#define BITS_PER_INT64      PR_BITS_PER_INT64
+#define BITS_PER_LONG       PR_BITS_PER_LONG
+#define BITS_PER_FLOAT      PR_BITS_PER_FLOAT
+#define BITS_PER_DOUBLE     PR_BITS_PER_DOUBLE
+#define BITS_PER_WORD       PR_BITS_PER_WORD
+
+#define BITS_PER_BYTE_LOG2  PR_BITS_PER_BYTE_LOG2
+#define BITS_PER_SHORT_LOG2 PR_BITS_PER_SHORT_LOG2
+#define BITS_PER_INT_LOG2   PR_BITS_PER_INT_LOG2
+#define BITS_PER_INT64_LOG2 PR_BITS_PER_INT64_LOG2
+#define BITS_PER_LONG_LOG2  PR_BITS_PER_LONG_LOG2
+#define BITS_PER_FLOAT_LOG2 PR_BITS_PER_FLOAT_LOG2
+#define BITS_PER_DOUBLE_LOG2    PR_BITS_PER_DOUBLE_LOG2
+#define BITS_PER_WORD_LOG2  PR_BITS_PER_WORD_LOG2
+
+#define ALIGN_OF_SHORT      PR_ALIGN_OF_SHORT
+#define ALIGN_OF_INT        PR_ALIGN_OF_INT
+#define ALIGN_OF_LONG       PR_ALIGN_OF_LONG
+#define ALIGN_OF_INT64      PR_ALIGN_OF_INT64
+#define ALIGN_OF_FLOAT      PR_ALIGN_OF_FLOAT
+#define ALIGN_OF_DOUBLE     PR_ALIGN_OF_DOUBLE
+#define ALIGN_OF_POINTER    PR_ALIGN_OF_POINTER
+#define ALIGN_OF_WORD       PR_ALIGN_OF_WORD
+
+#define BYTES_PER_WORD_LOG2		PR_BYTES_PER_WORD_LOG2
+#define BYTES_PER_DWORD_LOG2    PR_BYTES_PER_DWORD_LOG2
+#define WORDS_PER_DWORD_LOG2    PR_WORDS_PER_DWORD_LOG2
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#endif /* nspr_cpucfg___ */
diff --git a/pr/include/md/_winnt.h b/pr/include/md/_winnt.h
new file mode 100644
index 0000000..7e5477f
--- /dev/null
+++ b/pr/include/md/_winnt.h
@@ -0,0 +1,599 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_win32_defs_h___
+#define nspr_win32_defs_h___
+
+/* Need to force service-pack 3 extensions to be defined by
+** setting _WIN32_WINNT to NT 4.0 for winsock.h, winbase.h, winnt.h.
+*/ 
+#ifndef  _WIN32_WINNT
+    #define _WIN32_WINNT 0x0400
+#elif   (_WIN32_WINNT < 0x0400)
+    #undef  _WIN32_WINNT
+    #define _WIN32_WINNT 0x0400
+#endif /* _WIN32_WINNT */
+
+#include <windows.h>
+#include <winsock.h>
+#ifdef __MINGW32__
+#include <mswsock.h>
+#endif
+#include <errno.h>
+
+#include "prio.h"
+#include "prclist.h"
+
+/*
+ * Internal configuration macros
+ */
+
+#define PR_LINKER_ARCH      "win32"
+#define _PR_SI_SYSNAME        "WINNT"
+#if defined(_M_IX86) || defined(_X86_)
+#define _PR_SI_ARCHITECTURE   "x86"
+#elif defined(_M_X64) || defined(_M_AMD64) || defined(_AMD64_)
+#define _PR_SI_ARCHITECTURE   "x86-64"
+#elif defined(_M_IA64) || defined(_IA64_)
+#define _PR_SI_ARCHITECTURE   "ia64"
+#else
+#error unknown processor architecture
+#endif
+
+#define HAVE_DLL
+#define HAVE_CUSTOM_USER_THREADS
+#define HAVE_THREAD_AFFINITY
+#define _PR_HAVE_GETADDRINFO
+#define _PR_INET6_PROBE
+#ifndef _PR_INET6
+#define AF_INET6 23
+/* newer ws2tcpip.h provides these */
+#ifndef AI_CANONNAME
+#define AI_CANONNAME 0x2
+#define AI_NUMERICHOST 0x4
+#define NI_NUMERICHOST 0x02
+struct addrinfo {
+    int ai_flags;
+    int ai_family;
+    int ai_socktype;
+    int ai_protocol;
+    size_t ai_addrlen;
+    char *ai_canonname;
+    struct sockaddr *ai_addr;
+    struct addrinfo *ai_next;
+};
+#endif
+#define _PR_HAVE_MD_SOCKADDR_IN6
+/* isomorphic to struct in6_addr on Windows */
+struct _md_in6_addr {
+    union {
+        PRUint8  _S6_u8[16];
+        PRUint16 _S6_u16[8];
+    } _S6_un;
+};
+/* isomorphic to struct sockaddr_in6 on Windows */
+struct _md_sockaddr_in6 {
+    PRInt16 sin6_family;
+    PRUint16 sin6_port;
+    PRUint32 sin6_flowinfo;
+    struct _md_in6_addr sin6_addr;
+    PRUint32 sin6_scope_id;
+};
+#endif
+#define _PR_HAVE_THREADSAFE_GETHOST
+#define _PR_HAVE_ATOMIC_OPS
+#if defined(_M_IX86) || defined(_X86_)
+#define _PR_HAVE_ATOMIC_CAS
+#endif
+#define PR_HAVE_WIN32_NAMED_SHARED_MEMORY
+#define _PR_HAVE_PEEK_BUFFER
+#define _PR_PEEK_BUFFER_MAX (32 * 1024)
+#define _PR_FD_NEED_EMULATE_MSG_PEEK(fd) \
+    (!(fd)->secret->nonblocking && (fd)->secret->inheritable != _PR_TRI_TRUE)
+#define _PR_NEED_SECRET_AF
+
+/* --- Common User-Thread/Native-Thread Definitions --------------------- */
+
+/* --- Globals --- */
+extern struct PRLock                      *_pr_schedLock;
+
+/* --- Typedefs --- */
+typedef void (*FiberFunc)(void *);
+
+#define PR_NUM_GCREGS           8
+typedef PRInt32	                PR_CONTEXT_TYPE[PR_NUM_GCREGS];
+#define GC_VMBASE               0x40000000
+#define GC_VMLIMIT              0x00FFFFFF
+
+#define _MD_MAGIC_THREAD	0x22222222
+#define _MD_MAGIC_THREADSTACK	0x33333333
+#define _MD_MAGIC_SEGMENT	0x44444444
+#define _MD_MAGIC_DIR		0x55555555
+
+struct _MDCPU {
+    int              unused;
+};
+
+enum _MDIOModel {
+    _MD_BlockingIO = 0x38,
+    _MD_MultiWaitIO = 0x49
+};
+
+typedef struct _MDOverlapped {
+    OVERLAPPED overlapped;              /* Used for async I/O */
+
+    enum _MDIOModel ioModel;            /* The I/O model to implement
+                                         * using overlapped I/O.
+                                         */
+    union {
+        struct _MDThread *mdThread;     /* For blocking I/O, this structure
+                                         * is embedded in the _MDThread
+                                         * structure.
+                                         */
+        struct {
+            PRCList links;              /* for group->io_ready list */
+            struct PRRecvWait *desc;    /* For multiwait I/O, this structure
+                                         * is associated with a PRRecvWait
+                                         * structure.
+                                         */
+            struct PRWaitGroup *group;
+            struct TimerEvent *timer;
+            DWORD error;
+        } mw;
+    } data;
+} _MDOverlapped;
+
+struct _MDThread {
+        /* The overlapped structure must be first! */
+    struct _MDOverlapped overlapped;    /* Used for async IO for this thread */
+    void            *acceptex_buf;      /* Used for AcceptEx() */
+    TRANSMIT_FILE_BUFFERS *xmit_bufs;   /* Used for TransmitFile() */
+    HANDLE           blocked_sema;      /* Threads block on this when waiting
+                                         * for IO or CondVar.
+                                         */
+    PRInt32          blocked_io_status; /* Status of the completed IO */
+    PRInt32          blocked_io_bytes;  /* Bytes transferred for completed IO */
+    PRInt32          blocked_io_error;  /* Save error if status is FALSE */
+    HANDLE           handle;
+    PRUint32         id;
+    void            *sp;                /* only valid when suspended */
+    PRUint32         magic;             /* for debugging */
+    PR_CONTEXT_TYPE  gcContext;         /* Thread context for GC */
+	struct _PRCPU    *thr_bound_cpu;		/* thread bound to cpu */
+	PRBool   		 interrupt_disabled;/* thread cannot be interrupted */
+	HANDLE 			 thr_event;			/* For native-threads-only support,
+											thread blocks on this event		*/
+
+    /* The following are used only if this is a fiber */
+    void            *fiber_id;          /* flag whether or not this is a fiber*/
+    FiberFunc        fiber_fn;          /* main fiber routine */
+    void            *fiber_arg;         /* arg to main fiber routine */
+    PRUint32         fiber_stacksize;   /* stacksize for fiber */
+    PRInt32          fiber_last_error;  /* last error for the fiber */
+    void (*start)(void *);              /* used by _PR_MD_CREATE_THREAD to
+                                         * pass its 'start' argument to
+                                         * pr_root. */
+};
+
+struct _MDThreadStack {
+    PRUint32           magic;          /* for debugging */
+};
+
+struct _MDSegment {
+    PRUint32           magic;          /* for debugging */
+};
+
+#undef PROFILE_LOCKS
+
+struct _MDLock {
+    CRITICAL_SECTION mutex;          /* this is recursive on NT */
+#ifdef PROFILE_LOCKS
+    PRInt32 hitcount;
+    PRInt32 misscount;
+#endif
+};
+
+struct _MDDir {
+    HANDLE           d_hdl;
+    WIN32_FIND_DATA  d_entry;
+    PRBool           firstEntry;     /* Is this the entry returned
+                                      * by FindFirstFile()? */
+    PRUint32         magic;          /* for debugging */
+};
+
+struct _MDCVar {
+    PRUint32         unused;
+};
+
+struct _MDSemaphore {
+    HANDLE           sem;
+};
+
+struct _MDFileDesc {
+    PROsfd osfd;     /* The osfd can come from one of three spaces:
+                      * - For stdin, stdout, and stderr, we are using
+                      *   the libc file handle (0, 1, 2), which is an int.
+                      * - For files and pipes, we are using Win32 HANDLE,
+                      *   which is a void*.
+                      * - For sockets, we are using Winsock SOCKET, which
+                      *   is a u_int.
+                      */
+    PRBool io_model_committed;  /* The io model (blocking or nonblocking)
+                                 * for this osfd has been committed and
+                                 * cannot be changed.  The osfd has been
+                                 * either associated with the io
+                                 * completion port or made nonblocking. */
+    PRBool sync_file_io;        /* Use synchronous file I/O on the osfd
+                                 * (a file handle) */
+    PRBool accepted_socket;     /* Is this an accepted socket (on the
+                                 * server side)? */
+    PRNetAddr peer_addr;        /* If this is an accepted socket, cache
+                                 * the peer's address returned by
+                                 * AcceptEx().  This is to work around
+                                 * the bug that getpeername() on an
+                                 * socket accepted by AcceptEx() returns
+                                 * an all-zero net address. */
+};
+
+struct _MDProcess {
+    HANDLE handle;
+    DWORD id;
+};
+
+
+/* --- Misc stuff --- */
+#define _MD_GET_SP(thread)            (thread)->md.gcContext[6]
+
+/* --- NT security stuff --- */
+
+extern void _PR_NT_InitSids(void);
+extern void _PR_NT_FreeSids(void);
+extern PRStatus _PR_NT_MakeSecurityDescriptorACL(
+    PRIntn mode,
+    DWORD accessTable[],
+    PSECURITY_DESCRIPTOR *resultSD,
+    PACL *resultACL
+);
+extern void _PR_NT_FreeSecurityDescriptorACL(
+    PSECURITY_DESCRIPTOR pSD, PACL pACL);
+
+/* --- IO stuff --- */
+
+extern PRInt32 _md_Associate(HANDLE);
+extern PRInt32 _PR_MD_CLOSE(PROsfd osfd, PRBool socket);
+
+#define _MD_OPEN                      _PR_MD_OPEN
+#define _MD_OPEN_FILE                 _PR_MD_OPEN_FILE
+#define _MD_READ                      _PR_MD_READ
+#define _MD_WRITE                     _PR_MD_WRITE
+#define _MD_WRITEV                    _PR_MD_WRITEV
+#define _MD_LSEEK                     _PR_MD_LSEEK
+#define _MD_LSEEK64                   _PR_MD_LSEEK64
+#define _MD_CLOSE_FILE(f)             _PR_MD_CLOSE(f, PR_FALSE)
+#define _MD_GETFILEINFO               _PR_MD_GETFILEINFO
+#define _MD_GETFILEINFO64             _PR_MD_GETFILEINFO64
+#define _MD_GETOPENFILEINFO           _PR_MD_GETOPENFILEINFO
+#define _MD_GETOPENFILEINFO64         _PR_MD_GETOPENFILEINFO64
+#define _MD_STAT                      _PR_MD_STAT
+#define _MD_RENAME                    _PR_MD_RENAME     
+#define _MD_ACCESS                    _PR_MD_ACCESS     
+#define _MD_DELETE                    _PR_MD_DELETE     
+#define _MD_MKDIR                     _PR_MD_MKDIR      
+#define _MD_MAKE_DIR                  _PR_MD_MAKE_DIR
+#define _MD_RMDIR                     _PR_MD_RMDIR      
+#define _MD_LOCKFILE                  _PR_MD_LOCKFILE
+#define _MD_TLOCKFILE                 _PR_MD_TLOCKFILE
+#define _MD_UNLOCKFILE                _PR_MD_UNLOCKFILE
+
+/* --- Socket IO stuff --- */
+#define _MD_GET_SOCKET_ERROR()    WSAGetLastError()
+#define _MD_SET_SOCKET_ERROR(_err) WSASetLastError(_err)
+
+#define _MD_INIT_FILEDESC(fd)
+#define _MD_MAKE_NONBLOCK             _PR_MD_MAKE_NONBLOCK
+#define _MD_INIT_FD_INHERITABLE       _PR_MD_INIT_FD_INHERITABLE
+#define _MD_QUERY_FD_INHERITABLE      _PR_MD_QUERY_FD_INHERITABLE
+#define _MD_SHUTDOWN                  _PR_MD_SHUTDOWN
+#define _MD_LISTEN                    _PR_MD_LISTEN
+#define _MD_CLOSE_SOCKET(s)           _PR_MD_CLOSE(s, PR_TRUE)
+#define _MD_SENDTO                    _PR_MD_SENDTO
+#define _MD_RECVFROM                  _PR_MD_RECVFROM
+#define _MD_SOCKETPAIR(s, type, proto, sv) -1
+#define _MD_GETSOCKNAME               _PR_MD_GETSOCKNAME
+#define _MD_GETPEERNAME               _PR_MD_GETPEERNAME
+#define _MD_GETSOCKOPT                _PR_MD_GETSOCKOPT
+#define _MD_SETSOCKOPT                _PR_MD_SETSOCKOPT
+#define _MD_SELECT                    select
+extern int _PR_NTFiberSafeSelect(int, fd_set *, fd_set *, fd_set *,
+    const struct timeval *);
+#define _MD_FSYNC                     _PR_MD_FSYNC
+#define _MD_SOCKETAVAILABLE           _PR_MD_SOCKETAVAILABLE
+#define _MD_PIPEAVAILABLE             _PR_MD_PIPEAVAILABLE
+#define _MD_SET_FD_INHERITABLE        _PR_MD_SET_FD_INHERITABLE
+
+#define _MD_INIT_ATOMIC()
+#if defined(_M_IX86) || defined(_X86_)
+#define _MD_ATOMIC_INCREMENT          _PR_MD_ATOMIC_INCREMENT
+#define _MD_ATOMIC_ADD          	  _PR_MD_ATOMIC_ADD
+#define _MD_ATOMIC_DECREMENT          _PR_MD_ATOMIC_DECREMENT
+#else /* non-x86 processors */
+#define _MD_ATOMIC_INCREMENT(x)       InterlockedIncrement((PLONG)x)
+#define _MD_ATOMIC_ADD(ptr,val)    (InterlockedExchangeAdd((PLONG)ptr, (LONG)val) + val)
+#define _MD_ATOMIC_DECREMENT(x)       InterlockedDecrement((PLONG)x)
+#endif /* x86 */
+#define _MD_ATOMIC_SET(x,y)           InterlockedExchange((PLONG)x, (LONG)y)
+
+#define _MD_INIT_IO                   _PR_MD_INIT_IO
+#define _MD_SOCKET                    _PR_MD_SOCKET
+#define _MD_CONNECT                   _PR_MD_CONNECT
+
+#define _MD_ACCEPT(s, a, l, to)       \
+        _MD_FAST_ACCEPT(s, a, l, to, PR_FALSE, NULL, NULL)
+#define _MD_FAST_ACCEPT(s, a, l, to, fast, cb, cba) \
+        _PR_MD_FAST_ACCEPT(s, a, l, to, fast, cb, cba)
+#define _MD_ACCEPT_READ(s, ns, ra, buf, l, t) \
+        _MD_FAST_ACCEPT_READ(s, ns, ra, buf, l, t, PR_FALSE, NULL, NULL)
+#define _MD_FAST_ACCEPT_READ(s, ns, ra, buf, l, t, fast, cb, cba) \
+        _PR_MD_FAST_ACCEPT_READ(s, ns, ra, buf, l, t, fast, cb, cba)
+#define _MD_UPDATE_ACCEPT_CONTEXT     _PR_MD_UPDATE_ACCEPT_CONTEXT
+
+#define _MD_BIND                      _PR_MD_BIND
+#define _MD_RECV                      _PR_MD_RECV
+#define _MD_SEND                      _PR_MD_SEND
+#define _MD_SENDFILE              	  _PR_MD_SENDFILE
+#define _MD_PR_POLL                   _PR_MD_PR_POLL
+
+/* --- Scheduler stuff --- */
+#define _MD_PAUSE_CPU                   _PR_MD_PAUSE_CPU
+
+/* --- DIR stuff --- */
+#define PR_DIRECTORY_SEPARATOR        '\\'
+#define PR_DIRECTORY_SEPARATOR_STR    "\\"
+#define PR_PATH_SEPARATOR		';'
+#define PR_PATH_SEPARATOR_STR		";"
+#define _MD_ERRNO()                   GetLastError()
+#define _MD_OPEN_DIR                  _PR_MD_OPEN_DIR
+#define _MD_CLOSE_DIR                 _PR_MD_CLOSE_DIR
+#define _MD_READ_DIR                  _PR_MD_READ_DIR
+
+/* --- Segment stuff --- */
+#define _MD_INIT_SEGS()
+#define _MD_ALLOC_SEGMENT(seg, size, vaddr)   0
+#define _MD_FREE_SEGMENT(seg)
+
+/* --- Environment Stuff --- */
+#define _MD_GET_ENV                 _PR_MD_GET_ENV
+#define _MD_PUT_ENV                 _PR_MD_PUT_ENV
+
+/* --- Threading Stuff --- */
+#define _MD_DEFAULT_STACK_SIZE            0
+#define _MD_INIT_THREAD             _PR_MD_INIT_THREAD
+#define _MD_INIT_ATTACHED_THREAD    _PR_MD_INIT_THREAD
+#define _MD_CREATE_THREAD           _PR_MD_CREATE_THREAD
+#define _MD_JOIN_THREAD             _PR_MD_JOIN_THREAD
+#define _MD_END_THREAD              _PR_MD_END_THREAD
+#define _MD_YIELD                   _PR_MD_YIELD
+#define _MD_SET_PRIORITY            _PR_MD_SET_PRIORITY
+#define _MD_SET_CURRENT_THREAD_NAME _PR_MD_SET_CURRENT_THREAD_NAME
+#define _MD_CLEAN_THREAD            _PR_MD_CLEAN_THREAD
+#define _MD_SETTHREADAFFINITYMASK   _PR_MD_SETTHREADAFFINITYMASK
+#define _MD_GETTHREADAFFINITYMASK   _PR_MD_GETTHREADAFFINITYMASK
+#define _MD_EXIT_THREAD             _PR_MD_EXIT_THREAD
+#define _MD_SUSPEND_THREAD          _PR_MD_SUSPEND_THREAD
+#define _MD_RESUME_THREAD           _PR_MD_RESUME_THREAD
+#define _MD_SUSPEND_CPU             _PR_MD_SUSPEND_CPU
+#define _MD_RESUME_CPU              _PR_MD_RESUME_CPU
+#define _MD_BEGIN_SUSPEND_ALL()
+#define _MD_BEGIN_RESUME_ALL()
+#define _MD_END_SUSPEND_ALL()
+#define _MD_END_RESUME_ALL()
+
+extern void _PR_Unblock_IO_Wait(PRThread *thr);
+
+/* --- Lock stuff --- */
+#define _MD_NEW_LOCK(lock)            (InitializeCriticalSection(&((lock)->mutex)),PR_SUCCESS)
+#define _MD_FREE_LOCK(lock)           DeleteCriticalSection(&((lock)->mutex))
+#ifndef PROFILE_LOCKS
+#define _MD_LOCK(lock)                EnterCriticalSection(&((lock)->mutex))
+#define _MD_TEST_AND_LOCK(lock)       (TryEnterCriticalSection(&((lock)->mutex))== FALSE)
+#define _MD_UNLOCK(lock)              LeaveCriticalSection(&((lock)->mutex))
+#else
+#define _MD_LOCK(lock)                 \
+    PR_BEGIN_MACRO \
+    BOOL rv = TryEnterCriticalSection(&((lock)->mutex)); \
+    if (rv == TRUE) { \
+        InterlockedIncrement(&((lock)->hitcount)); \
+    } else { \
+        InterlockedIncrement(&((lock)->misscount)); \
+        EnterCriticalSection(&((lock)->mutex)); \
+    } \
+    PR_END_MACRO
+#define _MD_TEST_AND_LOCK(lock)       0  /* XXXMB */
+#define _MD_UNLOCK(lock)              LeaveCriticalSection(&((lock)->mutex))
+#endif
+#define _PR_LOCK                      _MD_LOCK
+#define _PR_UNLOCK					  _MD_UNLOCK
+
+/* --- lock and cv waiting --- */
+#define _MD_WAIT                      _PR_MD_WAIT
+#define _MD_WAKEUP_WAITER             _PR_MD_WAKEUP_WAITER
+
+   /* XXXMB- the IOQ stuff is certainly not working correctly yet. */
+extern  struct _MDLock              _pr_ioq_lock;
+#define _MD_IOQ_LOCK()                _MD_LOCK(&_pr_ioq_lock)
+#define _MD_IOQ_UNLOCK()              _MD_UNLOCK(&_pr_ioq_lock)
+
+
+/* --- Initialization stuff --- */
+#define _MD_START_INTERRUPTS()
+#define _MD_STOP_INTERRUPTS()
+#define _MD_DISABLE_CLOCK_INTERRUPTS()
+#define _MD_ENABLE_CLOCK_INTERRUPTS()
+#define _MD_BLOCK_CLOCK_INTERRUPTS()
+#define _MD_UNBLOCK_CLOCK_INTERRUPTS()
+#define _MD_EARLY_INIT                _PR_MD_EARLY_INIT
+#define _MD_FINAL_INIT()
+#define _MD_EARLY_CLEANUP()
+#define _MD_INIT_CPUS()
+#define _MD_INIT_RUNNING_CPU(cpu)
+
+struct PRProcess;
+struct PRProcessAttr;
+
+/* --- Create a new process --- */
+#define _MD_CREATE_PROCESS _PR_CreateWindowsProcess
+extern struct PRProcess * _PR_CreateWindowsProcess(
+    const char *path,
+    char *const *argv,
+    char *const *envp,
+    const struct PRProcessAttr *attr
+);
+
+#define _MD_DETACH_PROCESS _PR_DetachWindowsProcess
+extern PRStatus _PR_DetachWindowsProcess(struct PRProcess *process);
+
+/* --- Wait for a child process to terminate --- */
+#define _MD_WAIT_PROCESS _PR_WaitWindowsProcess
+extern PRStatus _PR_WaitWindowsProcess(struct PRProcess *process, 
+    PRInt32 *exitCode);
+
+#define _MD_KILL_PROCESS _PR_KillWindowsProcess
+extern PRStatus _PR_KillWindowsProcess(struct PRProcess *process);
+
+/* --- User Threading stuff --- */
+#define HAVE_FIBERS
+#define _MD_CREATE_USER_THREAD            _PR_MD_CREATE_USER_THREAD
+#define _MD_CREATE_PRIMORDIAL_USER_THREAD _PR_MD_CREATE_PRIMORDIAL_USER_THREAD
+#define _MD_CLEANUP_BEFORE_EXIT           _PR_MD_CLEANUP_BEFORE_EXIT
+#define _MD_EXIT                          _PR_MD_EXIT
+#define _MD_INIT_CONTEXT                  _PR_MD_INIT_CONTEXT
+#define _MD_SWITCH_CONTEXT                _PR_MD_SWITCH_CONTEXT
+#define _MD_RESTORE_CONTEXT               _PR_MD_RESTORE_CONTEXT
+
+/* --- Intervals --- */
+#define _MD_INTERVAL_INIT                 _PR_MD_INTERVAL_INIT
+#define _MD_GET_INTERVAL                  _PR_MD_GET_INTERVAL
+#define _MD_INTERVAL_PER_SEC              _PR_MD_INTERVAL_PER_SEC
+#define _MD_INTERVAL_PER_MILLISEC()       (_PR_MD_INTERVAL_PER_SEC() / 1000)
+#define _MD_INTERVAL_PER_MICROSEC()       (_PR_MD_INTERVAL_PER_SEC() / 1000000)
+
+/* --- Time --- */
+extern void _PR_FileTimeToPRTime(const FILETIME *filetime, PRTime *prtm);
+
+/* --- Native-Thread Specific Definitions ------------------------------- */
+
+extern BOOL _pr_use_static_tls;
+
+extern __declspec(thread) struct PRThread *_pr_current_fiber;
+extern DWORD _pr_currentFiberIndex;
+
+#define _MD_GET_ATTACHED_THREAD() \
+    (_pr_use_static_tls ? _pr_current_fiber \
+    : (PRThread *) TlsGetValue(_pr_currentFiberIndex))
+
+extern struct PRThread * _MD_CURRENT_THREAD(void);
+
+#define _MD_SET_CURRENT_THREAD(_thread) \
+    PR_BEGIN_MACRO \
+        if (_pr_use_static_tls) { \
+            _pr_current_fiber = (_thread); \
+        } else { \
+            TlsSetValue(_pr_currentFiberIndex, (_thread)); \
+        } \
+    PR_END_MACRO
+
+extern __declspec(thread) struct PRThread *_pr_fiber_last_run;
+extern DWORD _pr_lastFiberIndex;
+
+#define _MD_LAST_THREAD() \
+    (_pr_use_static_tls ? _pr_fiber_last_run \
+    : (PRThread *) TlsGetValue(_pr_lastFiberIndex))
+
+#define _MD_SET_LAST_THREAD(_thread) \
+    PR_BEGIN_MACRO \
+        if (_pr_use_static_tls) { \
+            _pr_fiber_last_run = (_thread); \
+        } else { \
+            TlsSetValue(_pr_lastFiberIndex, (_thread)); \
+        } \
+    PR_END_MACRO
+
+extern __declspec(thread) struct _PRCPU *_pr_current_cpu;
+extern DWORD _pr_currentCPUIndex;
+
+#define _MD_CURRENT_CPU() \
+    (_pr_use_static_tls ? _pr_current_cpu \
+    : (struct _PRCPU *) TlsGetValue(_pr_currentCPUIndex))
+
+#define _MD_SET_CURRENT_CPU(_cpu) \
+    PR_BEGIN_MACRO \
+        if (_pr_use_static_tls) { \
+            _pr_current_cpu = (_cpu); \
+        } else { \
+            TlsSetValue(_pr_currentCPUIndex, (_cpu)); \
+        } \
+    PR_END_MACRO
+
+extern __declspec(thread) PRUintn _pr_ints_off;
+extern DWORD _pr_intsOffIndex;
+
+#define _MD_GET_INTSOFF() \
+    (_pr_use_static_tls ? _pr_ints_off \
+    : (PRUintn) TlsGetValue(_pr_intsOffIndex))
+
+#define _MD_SET_INTSOFF(_val) \
+    PR_BEGIN_MACRO \
+        if (_pr_use_static_tls) { \
+            _pr_ints_off = (_val); \
+        } else { \
+            TlsSetValue(_pr_intsOffIndex, (LPVOID) (_val)); \
+        } \
+    PR_END_MACRO
+
+/* --- Initialization stuff --- */
+#define _MD_INIT_LOCKS()
+
+/* --- Stack stuff --- */
+#define _MD_INIT_STACK(stack, redzone)
+#define _MD_CLEAR_STACK(stack)
+
+/* --- Memory-mapped files stuff --- */
+
+struct _MDFileMap {
+    HANDLE hFileMap;
+    DWORD dwAccess;
+};
+
+extern PRStatus _MD_CreateFileMap(struct PRFileMap *fmap, PRInt64 size);
+#define _MD_CREATE_FILE_MAP _MD_CreateFileMap
+
+extern PRInt32 _MD_GetMemMapAlignment(void);
+#define _MD_GET_MEM_MAP_ALIGNMENT _MD_GetMemMapAlignment
+
+extern void * _MD_MemMap(struct PRFileMap *fmap, PRInt64 offset,
+        PRUint32 len);
+#define _MD_MEM_MAP _MD_MemMap
+
+extern PRStatus _MD_MemUnmap(void *addr, PRUint32 size);
+#define _MD_MEM_UNMAP _MD_MemUnmap
+
+extern PRStatus _MD_CloseFileMap(struct PRFileMap *fmap);
+#define _MD_CLOSE_FILE_MAP _MD_CloseFileMap
+
+extern PRStatus _MD_SyncMemMap(
+    PRFileDesc *fd,
+    void *addr,
+    PRUint32 len);
+#define _MD_SYNC_MEM_MAP _MD_SyncMemMap
+
+/* --- Named semaphores stuff --- */
+#define _PR_HAVE_NAMED_SEMAPHORES
+#define _MD_OPEN_SEMAPHORE            _PR_MD_OPEN_SEMAPHORE
+#define _MD_WAIT_SEMAPHORE            _PR_MD_WAIT_SEMAPHORE
+#define _MD_POST_SEMAPHORE            _PR_MD_POST_SEMAPHORE
+#define _MD_CLOSE_SEMAPHORE           _PR_MD_CLOSE_SEMAPHORE
+#define _MD_DELETE_SEMAPHORE(name)    PR_SUCCESS  /* no op */
+
+#endif /* nspr_win32_defs_h___ */
diff --git a/pr/include/md/prosdep.h b/pr/include/md/prosdep.h
new file mode 100644
index 0000000..94d8945
--- /dev/null
+++ b/pr/include/md/prosdep.h
@@ -0,0 +1,113 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef prosdep_h___
+#define prosdep_h___
+
+/*
+** Get OS specific header information
+*/
+#include "prtypes.h"
+
+PR_BEGIN_EXTERN_C
+
+#ifdef XP_PC
+
+#include "md/_pcos.h"
+#ifdef WINNT
+#include "md/_winnt.h"
+#include "md/_win32_errors.h"
+#elif defined(WIN95) || defined(WINCE)
+#include "md/_win95.h"
+#include "md/_win32_errors.h"
+#elif defined(OS2)
+#include "md/_os2.h"
+#include "md/_os2_errors.h"
+#else
+#error unknown Windows platform
+#endif
+
+#elif defined(XP_UNIX)
+
+#if defined(AIX)
+#include "md/_aix.h"
+
+#elif defined(FREEBSD)
+#include "md/_freebsd.h"
+
+#elif defined(NETBSD)
+#include "md/_netbsd.h"
+
+#elif defined(OPENBSD)
+#include "md/_openbsd.h"
+
+#elif defined(BSDI)
+#include "md/_bsdi.h"
+
+#elif defined(HPUX)
+#include "md/_hpux.h"
+
+#elif defined(IRIX)
+#include "md/_irix.h"
+
+#elif defined(LINUX) || defined(__GNU__) || defined(__GLIBC__)
+#include "md/_linux.h"
+
+#elif defined(OSF1)
+#include "md/_osf1.h"
+
+#elif defined(DARWIN)
+#include "md/_darwin.h"
+
+#elif defined(SOLARIS)
+#include "md/_solaris.h"
+
+#elif defined(SCO)
+#include "md/_scoos.h"
+
+#elif defined(UNIXWARE)
+#include "md/_unixware.h"
+
+#elif defined(DGUX)
+#include "md/_dgux.h"
+
+#elif defined(QNX)
+#include "md/_qnx.h"
+
+#elif defined(NTO)
+#include "md/_nto.h"
+
+#elif defined(RISCOS)
+#include "md/_riscos.h"
+
+#elif defined(SYMBIAN)
+#include "md/_symbian.h"
+
+#else
+#error unknown Unix flavor
+
+#endif
+
+#include "md/_unixos.h"
+#include "md/_unix_errors.h"
+
+#elif defined(XP_BEOS)
+
+#include "md/_beos.h"
+#include "md/_unix_errors.h"
+
+#else
+
+#error "The platform is not BeOS, Unix, Windows, or Mac"
+
+#endif
+
+#ifdef _PR_PTHREADS
+#include "md/_pth.h"
+#endif
+
+PR_END_EXTERN_C
+
+#endif /* prosdep_h___ */
diff --git a/pr/include/nspr.h b/pr/include/nspr.h
new file mode 100644
index 0000000..0cbc71c
--- /dev/null
+++ b/pr/include/nspr.h
@@ -0,0 +1,43 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef nspr_h___
+#define nspr_h___
+
+#include "pratom.h"
+#include "prbit.h"
+#include "prclist.h"
+#include "prcmon.h"
+#include "prcvar.h"
+#include "prdtoa.h"
+#include "prenv.h"
+#include "prerror.h"
+#include "prinet.h"
+#include "prinit.h"
+#include "prinrval.h"
+#include "prio.h"
+#include "pripcsem.h"
+#include "prlink.h"
+#include "prlock.h"
+#include "prlog.h"
+#include "prlong.h"
+#include "prmem.h"
+#include "prmon.h"
+#include "prmwait.h"
+#include "prnetdb.h"
+#include "prprf.h"
+#include "prproces.h"
+#include "prrng.h"
+#include "prrwlock.h"
+#include "prshm.h"
+#include "prshma.h"
+#include "prsystem.h"
+#include "prthread.h"
+#include "prtime.h"
+#include "prtpool.h"
+#include "prtrace.h"
+#include "prtypes.h"
+
+#endif /* nspr_h___ */
diff --git a/pr/include/obsolete/.cvsignore b/pr/include/obsolete/.cvsignore
new file mode 100644
index 0000000..f3c7a7c
--- /dev/null
+++ b/pr/include/obsolete/.cvsignore
@@ -0,0 +1 @@
+Makefile
diff --git a/pr/include/obsolete/Makefile.in b/pr/include/obsolete/Makefile.in
new file mode 100644
index 0000000..27116a2
--- /dev/null
+++ b/pr/include/obsolete/Makefile.in
@@ -0,0 +1,28 @@
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+#! gmake
+
+MOD_DEPTH	= ../../..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+
+include $(MOD_DEPTH)/config/autoconf.mk
+
+include $(topsrcdir)/config/config.mk
+
+HEADERS = $(wildcard $(srcdir)/*.h)
+
+RELEASE_HEADERS = $(HEADERS)
+RELEASE_HEADERS_DEST = $(RELEASE_INCLUDE_DIR)/obsolete
+
+include_subdir = obsolete
+
+include $(topsrcdir)/config/rules.mk
+
+export:: $(RELEASE_HEADERS)
+	$(INSTALL) -m 444 $(RELEASE_HEADERS) $(dist_includedir)/obsolete
diff --git a/pr/include/obsolete/pralarm.h b/pr/include/obsolete/pralarm.h
new file mode 100644
index 0000000..959e74b
--- /dev/null
+++ b/pr/include/obsolete/pralarm.h
@@ -0,0 +1,162 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** File:		pralarm.h
+** Description:	API to periodic alarms.
+**
+**
+** Alarms are defined to invoke some client specified function at 
+** a time in the future. The notification may be a one time event
+** or repeated at a fixed interval. The interval at which the next
+** notification takes place may be modified by the client code only
+** during the respective notification.
+**
+** The notification is delivered on a thread that is part of the
+** alarm context (PRAlarm). The thread will inherit the priority
+** of the Alarm creator.
+**
+** Any number of periodic alarms (PRAlarmID) may be created within
+** the context of a single alarm (PRAlarm). The notifications will be
+** scheduled as close to the desired time as possible.
+**
+** Repeating periodic notifies are expected to run at a fixed rate.
+** That rate is expressed as some number of notifies per period where
+** the period is much larger than a PRIntervalTime (see prinrval.h).
+*/
+
+#if !defined(pralarm_h)
+#define pralarm_h
+
+#include "prtypes.h"
+#include "prinrval.h"
+
+
+PR_BEGIN_EXTERN_C
+
+/**********************************************************************/
+/************************* TYPES AND CONSTANTS ************************/
+/**********************************************************************/
+
+typedef struct PRAlarm PRAlarm;
+typedef struct PRAlarmID PRAlarmID;
+
+typedef PRBool (PR_CALLBACK *PRPeriodicAlarmFn)(
+    PRAlarmID *id, void *clientData, PRUint32 late);
+
+/**********************************************************************/
+/****************************** FUNCTIONS *****************************/
+/**********************************************************************/
+
+/***********************************************************************
+** FUNCTION:    PR_CreateAlarm
+** DESCRIPTION:
+**  Create an alarm context.
+** INPUTS:      void
+** OUTPUTS:     None
+** RETURN:      PRAlarm*
+**  
+** SIDE EFFECTS:
+**  This creates an alarm context, which is an object used for subsequent
+**  notification creations. It also creates a thread that will be used to
+** deliver the notifications that are expected to be defined. The client
+** is resposible for destroying the context when appropriate.
+** RESTRICTIONS:
+**  None. 
+** MEMORY:      The object (PRAlarm) and a thread to support notifications.
+** ALGORITHM:   N/A
+***********************************************************************/
+NSPR_API(PRAlarm*) PR_CreateAlarm(void);
+
+/***********************************************************************
+** FUNCTION:    PR_DestroyAlarm
+** DESCRIPTION:
+**  Destroys the context created by PR_CreateAlarm().
+** INPUTS:      PRAlarm*
+** OUTPUTS:     None
+** RETURN:      PRStatus
+**  
+** SIDE EFFECTS:
+**  This destroys the context that was created by PR_CreateAlarm().
+**  If there are any active alarms (PRAlarmID), they will be cancelled.
+**  Once that is done, the thread that was used to deliver the alarms
+**  will be joined. 
+** RESTRICTIONS:
+**  None. 
+** MEMORY:      N/A
+** ALGORITHM:   N/A
+***********************************************************************/
+NSPR_API(PRStatus) PR_DestroyAlarm(PRAlarm *alarm);
+
+/***********************************************************************
+** FUNCTION:    PR_SetAlarm
+** DESCRIPTION:
+**  Creates a periodic notifier that is to be delivered to a specified
+**  function at some fixed interval.
+** INPUTS:      PRAlarm *alarm              Parent alarm context
+**              PRIntervalTime period       Interval over which the notifies
+**                                          are delivered.
+**              PRUint32 rate               The rate within the interval that
+**                                          the notifies will be delivered.
+**              PRPeriodicAlarmFn function  Entry point where the notifies
+**                                          will be delivered.
+** OUTPUTS:     None
+** RETURN:      PRAlarmID*                  Handle to the notifier just created
+**                                          or NULL if the request failed.
+**  
+** SIDE EFFECTS:
+**  A periodic notifier is created. The notifications will be delivered
+**  by the alarm's internal thread at a fixed interval whose rate is the
+**  number of interrupts per interval specified. The first notification
+**  will be delivered as soon as possible, and they will continue until
+**  the notifier routine indicates that they should cease of the alarm
+**  context is destroyed (PR_DestroyAlarm).
+** RESTRICTIONS:
+**  None. 
+** MEMORY:      Memory for the notifier object.
+** ALGORITHM:   The rate at which notifications are delivered are stated
+**              to be "'rate' notifies per 'interval'". The exact time of
+**              the notification is computed based on a epoch established
+**              when the notifier was set. Each notification is delivered
+**              not ealier than the epoch plus the fixed rate times the
+**              notification sequence number. Such notifications have the
+**              potential to be late by not more than 'interval'/'rate'.
+**              The amount of lateness of one notification is taken into
+**              account on the next in an attempt to avoid long term slew.  
+***********************************************************************/
+NSPR_API(PRAlarmID*) PR_SetAlarm(
+    PRAlarm *alarm, PRIntervalTime period, PRUint32 rate,
+    PRPeriodicAlarmFn function, void *clientData);
+
+/***********************************************************************
+** FUNCTION:    PR_ResetAlarm
+** DESCRIPTION:
+**  Resets an existing alarm.
+** INPUTS:      PRAlarmID *id               Identify of the notifier.
+**              PRIntervalTime period       Interval over which the notifies
+**                                          are delivered.
+**              PRUint32 rate               The rate within the interval that
+**                                          the notifies will be delivered.
+** OUTPUTS:     None
+** RETURN:      PRStatus                    Indication of completion.
+**  
+** SIDE EFFECTS:
+**  An existing alarm may have its period and rate redefined. The
+**  additional side effect is that the notifier's epoch is recomputed.
+**  The first notification delivered by the newly refreshed alarm is
+**  defined to be 'interval'/'rate' from the time of the reset.
+** RESTRICTIONS:
+**  This function may only be called in the notifier for that alarm.
+** MEMORY:      N/A.
+** ALGORITHM:   See PR_SetAlarm().  
+***********************************************************************/
+NSPR_API(PRStatus) PR_ResetAlarm(
+	PRAlarmID *id, PRIntervalTime period, PRUint32 rate);
+
+PR_END_EXTERN_C
+
+#endif /* !defined(pralarm_h) */
+
+/* prinrval.h */
diff --git a/pr/include/obsolete/probslet.h b/pr/include/obsolete/probslet.h
new file mode 100644
index 0000000..2eff0ba
--- /dev/null
+++ b/pr/include/obsolete/probslet.h
@@ -0,0 +1,149 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** A collection of things thought to be obsolete
+*/
+
+#if defined(PROBSLET_H)
+#else
+#define PROBSLET_H
+
+#include "prio.h"
+#include "private/pprio.h"  /* for PROsfd */
+
+PR_BEGIN_EXTERN_C
+
+/*
+** Yield the current thread.  The proper function to use in place of
+** PR_Yield() is PR_Sleep() with an argument of PR_INTERVAL_NO_WAIT.
+*/
+NSPR_API(PRStatus) PR_Yield(void);
+
+/************************************************************************/
+/************* The following definitions are for select *****************/
+/************************************************************************/
+
+/*
+** The following is obsolete and will be deleted in the next release!
+** These are provided for compatibility, but are GUARANTEED to be slow.
+**
+** Override PR_MAX_SELECT_DESC if you need more space in the select set.
+*/
+#ifndef PR_MAX_SELECT_DESC
+#define PR_MAX_SELECT_DESC 1024
+#endif
+typedef struct PR_fd_set {
+    PRUint32      hsize;
+    PRFileDesc   *harray[PR_MAX_SELECT_DESC];
+    PRUint32      nsize;
+    PROsfd        narray[PR_MAX_SELECT_DESC];
+} PR_fd_set;
+
+/*
+*************************************************************************
+** FUNCTION:    PR_Select
+** DESCRIPTION:
+**
+** The call returns as soon as I/O is ready on one or more of the underlying
+** file/socket descriptors or an exceptional condition is pending. A count of the 
+** number of ready descriptors is returned unless a timeout occurs in which case 
+** zero is returned.  On return, PR_Select replaces the given descriptor sets with 
+** subsets consisting of those descriptors that are ready for the requested condition.
+** The total number of ready descriptors in all the sets is the return value.
+**
+** INPUTS:
+**   PRInt32 num             
+**       This argument is unused but is provided for select(unix) interface
+**       compatability.  All input PR_fd_set arguments are self-describing
+**       with its own maximum number of elements in the set.
+**                               
+**   PR_fd_set *readfds
+**       A set describing the io descriptors for which ready for reading
+**       condition is of interest.  
+**                               
+**   PR_fd_set *writefds
+**       A set describing the io descriptors for which ready for writing
+**       condition is of interest.  
+**                               
+**   PR_fd_set *exceptfds
+**       A set describing the io descriptors for which exception pending
+**       condition is of interest.  
+**
+**   Any of the above readfds, writefds or exceptfds may be given as NULL 
+**   pointers if no descriptors are of interest for that particular condition.                          
+**   
+**   PRIntervalTime timeout  
+**       Amount of time the call will block waiting for I/O to become ready. 
+**       If this time expires without any I/O becoming ready, the result will
+**       be zero.
+**
+** OUTPUTS:    
+**   PR_fd_set *readfds
+**       A set describing the io descriptors which are ready for reading.
+**                               
+**   PR_fd_set *writefds
+**       A set describing the io descriptors which are ready for writing.
+**                               
+**   PR_fd_set *exceptfds
+**       A set describing the io descriptors which have pending exception.
+**
+** RETURN:PRInt32
+**   Number of io descriptors with asked for conditions or zero if the function
+**   timed out or -1 on failure.  The reason for the failure is obtained by 
+**   calling PR_GetError().
+** XXX can we implement this on windoze and mac?
+**************************************************************************
+*/
+NSPR_API(PRInt32) PR_Select(
+    PRInt32 num, PR_fd_set *readfds, PR_fd_set *writefds,
+    PR_fd_set *exceptfds, PRIntervalTime timeout);
+
+/* 
+** The following are not thread safe for two threads operating on them at the
+** same time.
+**
+** The following routines are provided for manipulating io descriptor sets.
+** PR_FD_ZERO(&fdset) initializes a descriptor set fdset to the null set.
+** PR_FD_SET(fd, &fdset) includes a particular file descriptor fd in fdset.
+** PR_FD_CLR(fd, &fdset) removes a file descriptor fd from fdset.  
+** PR_FD_ISSET(fd, &fdset) is nonzero if file descriptor fd is a member of 
+** fdset, zero otherwise.
+**
+** PR_FD_NSET(osfd, &fdset) includes a particular native file descriptor osfd
+** in fdset.
+** PR_FD_NCLR(osfd, &fdset) removes a native file descriptor osfd from fdset.  
+** PR_FD_NISSET(osfd, &fdset) is nonzero if native file descriptor osfd is a member of 
+** fdset, zero otherwise.
+*/
+
+NSPR_API(void)        PR_FD_ZERO(PR_fd_set *set);
+NSPR_API(void)        PR_FD_SET(PRFileDesc *fd, PR_fd_set *set);
+NSPR_API(void)        PR_FD_CLR(PRFileDesc *fd, PR_fd_set *set);
+NSPR_API(PRInt32)     PR_FD_ISSET(PRFileDesc *fd, PR_fd_set *set);
+NSPR_API(void)        PR_FD_NSET(PROsfd osfd, PR_fd_set *set);
+NSPR_API(void)        PR_FD_NCLR(PROsfd osfd, PR_fd_set *set);
+NSPR_API(PRInt32)     PR_FD_NISSET(PROsfd osfd, PR_fd_set *set);
+
+/*
+** The next two entry points should not be in the API, but they are
+** declared here for historical reasons.
+*/
+
+NSPR_API(PRInt32) PR_GetSysfdTableMax(void);
+
+NSPR_API(PRInt32) PR_SetSysfdTableSize(PRIntn table_size);
+
+#ifndef NO_NSPR_10_SUPPORT
+#include <sys/stat.h>
+
+NSPR_API(PRInt32) PR_Stat(const char *path, struct stat *buf);
+#endif /* NO_NSPR_10_SUPPORT */
+
+PR_END_EXTERN_C
+
+#endif /* defined(PROBSLET_H) */
+
+/* probslet.h */
diff --git a/pr/include/obsolete/protypes.h b/pr/include/obsolete/protypes.h
new file mode 100644
index 0000000..2275bce
--- /dev/null
+++ b/pr/include/obsolete/protypes.h
@@ -0,0 +1,199 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+ * This header typedefs the old 'native' types to the new PR<type>s.
+ * These definitions are scheduled to be eliminated at the earliest
+ * possible time. The NSPR API is implemented and documented using
+ * the new definitions.
+ */
+
+#if !defined(PROTYPES_H)
+#define PROTYPES_H
+
+typedef PRUintn uintn;
+#ifndef _XP_Core_
+typedef PRIntn intn;
+#endif
+
+/*
+ * It is trickier to define uint, int8, uint8, int16, uint16,
+ * int32, uint32, int64, and uint64 because some of these int
+ * types are defined by standard header files on some platforms.
+ * Our strategy here is to include all such standard headers
+ * first, and then define these int types only if they are not
+ * defined by those standard headers.
+ */
+
+/*
+ * BeOS defines all the int types below in its standard header
+ * file SupportDefs.h.
+ */
+#ifdef XP_BEOS
+#include <support/SupportDefs.h>
+#endif
+
+/*
+ * SVR4 typedef of uint is commonly found on UNIX machines.
+ *
+ * On AIX 4.3, sys/inttypes.h (which is included by sys/types.h)
+ * defines the types int8, int16, int32, and int64.
+ *
+ * On OS/2, sys/types.h defines uint.
+ */
+#if defined(XP_UNIX) || defined(XP_OS2)
+#include <sys/types.h>
+#endif
+
+/* model.h on HP-UX defines int8, int16, and int32. */
+#ifdef HPUX
+#include <model.h>
+#endif
+
+/*
+ * uint
+ */
+
+#if !defined(XP_BEOS) && !defined(XP_OS2) && !defined(XP_UNIX) || defined(NTO)
+typedef PRUintn uint;
+#endif
+
+/*
+ * uint64
+ */
+
+#if !defined(XP_BEOS)
+typedef PRUint64 uint64;
+#endif
+
+/*
+ * uint32
+ */
+
+#if !defined(XP_BEOS)
+#if !defined(_WIN32) && !defined(XP_OS2) && !defined(NTO)
+typedef PRUint32 uint32;
+#else
+typedef unsigned long uint32;
+#endif
+#endif
+
+/*
+ * uint16
+ */
+
+#if !defined(XP_BEOS)
+typedef PRUint16 uint16;
+#endif
+
+/*
+ * uint8
+ */
+
+#if !defined(XP_BEOS)
+typedef PRUint8 uint8;
+#endif
+
+/*
+ * int64
+ */
+
+#if !defined(XP_BEOS) && !defined(_PR_AIX_HAVE_BSD_INT_TYPES)
+typedef PRInt64 int64;
+#endif
+
+/*
+ * int32
+ */
+
+#if !defined(XP_BEOS) && !defined(_PR_AIX_HAVE_BSD_INT_TYPES) \
+    && !defined(HPUX)
+#if !defined(_WIN32) && !defined(XP_OS2) && !defined(NTO)
+typedef PRInt32 int32;
+#else
+typedef long int32;
+#endif
+#endif
+
+/*
+ * int16
+ */
+
+#if !defined(XP_BEOS) && !defined(_PR_AIX_HAVE_BSD_INT_TYPES) \
+    && !defined(HPUX)
+typedef PRInt16 int16;
+#endif
+
+/*
+ * int8
+ */
+
+#if !defined(XP_BEOS) && !defined(_PR_AIX_HAVE_BSD_INT_TYPES) \
+    && !defined(HPUX)
+typedef PRInt8 int8;
+#endif
+
+typedef PRFloat64 float64;
+typedef PRUptrdiff uptrdiff_t;
+typedef PRUword uprword_t;
+typedef PRWord prword_t;
+
+
+/* Re: prbit.h */
+#define TEST_BIT	PR_TEST_BIT
+#define SET_BIT		PR_SET_BIT
+#define CLEAR_BIT	PR_CLEAR_BIT
+
+/* Re: prarena.h->plarena.h */
+#define PRArena PLArena
+#define PRArenaPool PLArenaPool
+#define PRArenaStats PLArenaStats
+#define PR_ARENA_ALIGN PL_ARENA_ALIGN
+#define PR_INIT_ARENA_POOL PL_INIT_ARENA_POOL
+#define PR_ARENA_ALLOCATE PL_ARENA_ALLOCATE
+#define PR_ARENA_GROW PL_ARENA_GROW
+#define PR_ARENA_MARK PL_ARENA_MARK
+#define PR_CLEAR_UNUSED PL_CLEAR_UNUSED
+#define PR_CLEAR_ARENA PL_CLEAR_ARENA
+#define PR_ARENA_RELEASE PL_ARENA_RELEASE
+#define PR_COUNT_ARENA PL_COUNT_ARENA
+#define PR_ARENA_DESTROY PL_ARENA_DESTROY
+#define PR_InitArenaPool PL_InitArenaPool
+#define PR_FreeArenaPool PL_FreeArenaPool
+#define PR_FinishArenaPool PL_FinishArenaPool
+#define PR_CompactArenaPool PL_CompactArenaPool
+#define PR_ArenaFinish PL_ArenaFinish
+#define PR_ArenaAllocate PL_ArenaAllocate
+#define PR_ArenaGrow PL_ArenaGrow
+#define PR_ArenaRelease PL_ArenaRelease
+#define PR_ArenaCountAllocation PL_ArenaCountAllocation
+#define PR_ArenaCountInplaceGrowth PL_ArenaCountInplaceGrowth
+#define PR_ArenaCountGrowth PL_ArenaCountGrowth
+#define PR_ArenaCountRelease PL_ArenaCountRelease
+#define PR_ArenaCountRetract PL_ArenaCountRetract
+
+/* Re: prhash.h->plhash.h */
+#define PRHashEntry PLHashEntry
+#define PRHashTable PLHashTable
+#define PRHashNumber PLHashNumber
+#define PRHashFunction PLHashFunction
+#define PRHashComparator PLHashComparator
+#define PRHashEnumerator PLHashEnumerator
+#define PRHashAllocOps PLHashAllocOps
+#define PR_NewHashTable PL_NewHashTable
+#define PR_HashTableDestroy PL_HashTableDestroy
+#define PR_HashTableRawLookup PL_HashTableRawLookup
+#define PR_HashTableRawAdd PL_HashTableRawAdd
+#define PR_HashTableRawRemove PL_HashTableRawRemove
+#define PR_HashTableAdd PL_HashTableAdd
+#define PR_HashTableRemove PL_HashTableRemove
+#define PR_HashTableEnumerateEntries PL_HashTableEnumerateEntries
+#define PR_HashTableLookup PL_HashTableLookup
+#define PR_HashTableDump PL_HashTableDump
+#define PR_HashString PL_HashString
+#define PR_CompareStrings PL_CompareStrings
+#define PR_CompareValues PL_CompareValues
+
+#endif /* !defined(PROTYPES_H) */
diff --git a/pr/include/obsolete/prsem.h b/pr/include/obsolete/prsem.h
new file mode 100644
index 0000000..ee313cb
--- /dev/null
+++ b/pr/include/obsolete/prsem.h
@@ -0,0 +1,64 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef prsem_h___
+#define prsem_h___
+
+/*
+** API for counting semaphores. Semaphores are counting synchronizing 
+** variables based on a lock and a condition variable.  They are lightweight 
+** contention control for a given count of resources.
+*/
+#include "prtypes.h"
+
+PR_BEGIN_EXTERN_C
+
+typedef struct PRSemaphore PRSemaphore;
+
+/*
+** Create a new semaphore object.
+*/
+NSPR_API(PRSemaphore*) PR_NewSem(PRUintn value);
+
+/*
+** Destroy the given semaphore object.
+**
+*/
+NSPR_API(void) PR_DestroySem(PRSemaphore *sem);
+
+/*
+** Wait on a Semaphore.
+** 
+** This routine allows a calling thread to wait or proceed depending upon the 
+** state of the semahore sem. The thread can proceed only if the counter value 
+** of the semaphore sem is currently greater than 0. If the value of semaphore 
+** sem is positive, it is decremented by one and the routine returns immediately 
+** allowing the calling thread to continue. If the value of semaphore sem is 0, 
+** the calling thread blocks awaiting the semaphore to be released by another 
+** thread.
+** 
+** This routine can return PR_PENDING_INTERRUPT if the waiting thread 
+** has been interrupted.
+*/
+NSPR_API(PRStatus) PR_WaitSem(PRSemaphore *sem);
+
+/*
+** This routine increments the counter value of the semaphore. If other threads 
+** are blocked for the semaphore, then the scheduler will determine which ONE 
+** thread will be unblocked.
+*/
+NSPR_API(void) PR_PostSem(PRSemaphore *sem);
+
+/*
+** Returns the value of the semaphore referenced by sem without affecting
+** the state of the semaphore.  The value represents the semaphore vaule
+F** at the time of the call, but may not be the actual value when the
+** caller inspects it.
+*/
+NSPR_API(PRUintn) PR_GetValueSem(PRSemaphore *sem);
+
+PR_END_EXTERN_C
+
+#endif /* prsem_h___ */
diff --git a/pr/include/pratom.h b/pr/include/pratom.h
new file mode 100644
index 0000000..dff9d6c
--- /dev/null
+++ b/pr/include/pratom.h
@@ -0,0 +1,198 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* GLOBAL FUNCTIONS:
+** DESCRIPTION:
+**     PR Atomic operations
+*/
+
+#ifndef pratom_h___
+#define pratom_h___
+
+#include "prtypes.h"
+#include "prlock.h"
+
+PR_BEGIN_EXTERN_C
+
+/*
+** FUNCTION: PR_AtomicIncrement
+** DESCRIPTION:
+**    Atomically increment a 32 bit value.
+** INPUTS:
+**    val:  a pointer to the value to increment
+** RETURN:
+**    the returned value is the result of the increment
+*/
+NSPR_API(PRInt32)	PR_AtomicIncrement(PRInt32 *val);
+
+/*
+** FUNCTION: PR_AtomicDecrement
+** DESCRIPTION:
+**    Atomically decrement a 32 bit value.
+** INPUTS:
+**    val:  a pointer to the value to decrement
+** RETURN:
+**    the returned value is the result of the decrement
+*/
+NSPR_API(PRInt32)	PR_AtomicDecrement(PRInt32 *val);
+
+/*
+** FUNCTION: PR_AtomicSet
+** DESCRIPTION:
+**    Atomically set a 32 bit value.
+** INPUTS:
+**    val: A pointer to a 32 bit value to be set
+**    newval: The newvalue to assign to val
+** RETURN:
+**    Returns the prior value
+*/
+NSPR_API(PRInt32) PR_AtomicSet(PRInt32 *val, PRInt32 newval);
+
+/*
+** FUNCTION: PR_AtomicAdd
+** DESCRIPTION:
+**    Atomically add a 32 bit value.
+** INPUTS:
+**    ptr:  a pointer to the value to increment
+**	  val:  value to be added
+** RETURN:
+**    the returned value is the result of the addition
+*/
+NSPR_API(PRInt32)	PR_AtomicAdd(PRInt32 *ptr, PRInt32 val);
+
+/*
+** MACRO: PR_ATOMIC_INCREMENT
+** MACRO: PR_ATOMIC_DECREMENT
+** MACRO: PR_ATOMIC_SET
+** MACRO: PR_ATOMIC_ADD
+** DESCRIPTION:
+**    Macro versions of the atomic operations.  They may be implemented
+**    as compiler intrinsics.
+**
+** IMPORTANT NOTE TO NSPR MAINTAINERS:
+**    Implement these macros with compiler intrinsics only on platforms
+**    where the PR_AtomicXXX functions are truly atomic (i.e., where the
+**    configuration macro _PR_HAVE_ATOMIC_OPS is defined).  Otherwise,
+**    the macros and functions won't be compatible and can't be used
+**    interchangeably.
+*/
+#if defined(_WIN32) && !defined(_WIN32_WCE) && \
+    (!defined(_MSC_VER) || (_MSC_VER >= 1310))
+
+#include <intrin.h>
+
+#ifdef _MSC_VER
+#pragma intrinsic(_InterlockedIncrement)
+#pragma intrinsic(_InterlockedDecrement)
+#pragma intrinsic(_InterlockedExchange)
+#pragma intrinsic(_InterlockedExchangeAdd)
+#endif
+
+#define PR_ATOMIC_INCREMENT(val) _InterlockedIncrement((long volatile *)(val))
+#define PR_ATOMIC_DECREMENT(val) _InterlockedDecrement((long volatile *)(val))
+#define PR_ATOMIC_SET(val, newval) \
+        _InterlockedExchange((long volatile *)(val), (long)(newval))
+#define PR_ATOMIC_ADD(ptr, val) \
+        (_InterlockedExchangeAdd((long volatile *)(ptr), (long)(val)) + (val))
+
+#elif ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) && \
+      ((defined(__APPLE__) && \
+           (defined(__ppc__) || defined(__i386__) || defined(__x86_64__))) || \
+       (defined(__linux__) && \
+           ((defined(__i386__) && \
+           defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)) || \
+           defined(__ia64__) || defined(__x86_64__) || \
+           defined(__powerpc__) || \
+           (defined(__arm__) && \
+           defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)) || \
+           defined(__aarch64__) || defined(__alpha) || \
+           (defined(__mips__) && \
+           defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)))))
+
+/*
+ * Because the GCC manual warns that some processors may support
+ * reduced functionality of __sync_lock_test_and_set, we test for the
+ * processors that we believe support a full atomic exchange operation.
+ */
+
+#define PR_ATOMIC_INCREMENT(val) __sync_add_and_fetch(val, 1)
+#define PR_ATOMIC_DECREMENT(val) __sync_sub_and_fetch(val, 1)
+#define PR_ATOMIC_SET(val, newval) __sync_lock_test_and_set(val, newval)
+#define PR_ATOMIC_ADD(ptr, val) __sync_add_and_fetch(ptr, val)
+
+#else
+
+#define PR_ATOMIC_INCREMENT(val) PR_AtomicIncrement(val)
+#define PR_ATOMIC_DECREMENT(val) PR_AtomicDecrement(val)
+#define PR_ATOMIC_SET(val, newval) PR_AtomicSet(val, newval)
+#define PR_ATOMIC_ADD(ptr, val) PR_AtomicAdd(ptr, val)
+
+#endif
+
+/*
+** LIFO linked-list (stack)
+*/
+typedef struct PRStackElemStr PRStackElem;
+
+struct PRStackElemStr {
+    PRStackElem	*prstk_elem_next;	/* next pointer MUST be at offset 0;
+									  assembly language code relies on this */
+};
+
+typedef struct PRStackStr PRStack;
+
+/*
+** FUNCTION: PR_CreateStack
+** DESCRIPTION:
+**    Create a stack, a LIFO linked list
+** INPUTS:
+**    stack_name:  a pointer to string containing the name of the stack
+** RETURN:
+**    A pointer to the created stack, if successful, else NULL.
+*/
+NSPR_API(PRStack *)	PR_CreateStack(const char *stack_name);
+
+/*
+** FUNCTION: PR_StackPush
+** DESCRIPTION:
+**    Push an element on the top of the stack
+** INPUTS:
+**    stack:		pointer to the stack
+**    stack_elem:	pointer to the stack element
+** RETURN:
+**    None
+*/
+NSPR_API(void)			PR_StackPush(PRStack *stack, PRStackElem *stack_elem);
+
+/*
+** FUNCTION: PR_StackPop
+** DESCRIPTION:
+**    Remove the element on the top of the stack
+** INPUTS:
+**    stack:		pointer to the stack
+** RETURN:
+**    A pointer to the stack element removed from the top of the stack,
+**	  if non-empty,
+**    else NULL
+*/
+NSPR_API(PRStackElem *)	PR_StackPop(PRStack *stack);
+
+/*
+** FUNCTION: PR_DestroyStack
+** DESCRIPTION:
+**    Destroy the stack
+** INPUTS:
+**    stack:		pointer to the stack
+** RETURN:
+**    PR_SUCCESS - if successfully deleted
+**	  PR_FAILURE - if the stack is not empty
+**					PR_GetError will return
+**						PR_INVALID_STATE_ERROR - stack is not empty
+*/
+NSPR_API(PRStatus)		PR_DestroyStack(PRStack *stack);
+
+PR_END_EXTERN_C
+
+#endif /* pratom_h___ */
diff --git a/pr/include/prbit.h b/pr/include/prbit.h
new file mode 100644
index 0000000..0434fc6
--- /dev/null
+++ b/pr/include/prbit.h
@@ -0,0 +1,150 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef prbit_h___
+#define prbit_h___
+
+#include "prtypes.h"
+PR_BEGIN_EXTERN_C
+
+/*
+** Replace compare/jump/add/shift sequence with compiler built-in/intrinsic
+** functions.
+*/
+#if defined(_WIN32) && (_MSC_VER >= 1300) && \
+    (defined(_M_IX86) || defined(_M_AMD64) || defined(_M_ARM))
+# include <intrin.h>
+# pragma  intrinsic(_BitScanForward,_BitScanReverse)
+  __forceinline static int __prBitScanForward32(unsigned int val)
+  { 
+    unsigned long idx;
+    _BitScanForward(&idx, (unsigned long)val);
+    return( (int)idx );
+  }
+  __forceinline static int __prBitScanReverse32(unsigned int val)
+  {
+    unsigned long idx;
+    _BitScanReverse(&idx, (unsigned long)val);
+    return( (int)(31-idx) );
+  }
+# define pr_bitscan_ctz32(val)  __prBitScanForward32(val)
+# define pr_bitscan_clz32(val)  __prBitScanReverse32(val)
+# define  PR_HAVE_BUILTIN_BITSCAN32
+#elif ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) && \
+       (defined(__i386__) || defined(__x86_64__) || defined(__arm__))
+# define pr_bitscan_ctz32(val)  __builtin_ctz(val)
+# define pr_bitscan_clz32(val)  __builtin_clz(val)
+# define  PR_HAVE_BUILTIN_BITSCAN32
+#endif /* MSVC || GCC */
+
+/*
+** A prbitmap_t is a long integer that can be used for bitmaps
+*/
+typedef unsigned long prbitmap_t;
+
+#define PR_TEST_BIT(_map,_bit) \
+    ((_map)[(_bit)>>PR_BITS_PER_LONG_LOG2] & (1L << ((_bit) & (PR_BITS_PER_LONG-1))))
+#define PR_SET_BIT(_map,_bit) \
+    ((_map)[(_bit)>>PR_BITS_PER_LONG_LOG2] |= (1L << ((_bit) & (PR_BITS_PER_LONG-1))))
+#define PR_CLEAR_BIT(_map,_bit) \
+    ((_map)[(_bit)>>PR_BITS_PER_LONG_LOG2] &= ~(1L << ((_bit) & (PR_BITS_PER_LONG-1))))
+
+/*
+** Compute the log of the least power of 2 greater than or equal to n
+*/
+NSPR_API(PRIntn) PR_CeilingLog2(PRUint32 i); 
+
+/*
+** Compute the log of the greatest power of 2 less than or equal to n
+*/
+NSPR_API(PRIntn) PR_FloorLog2(PRUint32 i); 
+
+/*
+** Macro version of PR_CeilingLog2: Compute the log of the least power of
+** 2 greater than or equal to _n. The result is returned in _log2.
+*/
+#ifdef PR_HAVE_BUILTIN_BITSCAN32 
+#define PR_CEILING_LOG2(_log2,_n)      \
+  PR_BEGIN_MACRO                       \
+    PRUint32 j_ = (PRUint32)(_n);      \
+    (_log2) = (j_ <= 1 ? 0 : 32 - pr_bitscan_clz32(j_ - 1)); \
+  PR_END_MACRO
+#else
+#define PR_CEILING_LOG2(_log2,_n)   \
+  PR_BEGIN_MACRO                    \
+    PRUint32 j_ = (PRUint32)(_n); 	\
+    (_log2) = 0;                    \
+    if ((j_) & ((j_)-1))            \
+	(_log2) += 1;               \
+    if ((j_) >> 16)                 \
+	(_log2) += 16, (j_) >>= 16; \
+    if ((j_) >> 8)                  \
+	(_log2) += 8, (j_) >>= 8;   \
+    if ((j_) >> 4)                  \
+	(_log2) += 4, (j_) >>= 4;   \
+    if ((j_) >> 2)                  \
+	(_log2) += 2, (j_) >>= 2;   \
+    if ((j_) >> 1)                  \
+	(_log2) += 1;               \
+  PR_END_MACRO
+#endif /* PR_HAVE_BUILTIN_BITSCAN32 */
+
+/*
+** Macro version of PR_FloorLog2: Compute the log of the greatest power of
+** 2 less than or equal to _n. The result is returned in _log2.
+**
+** This is equivalent to finding the highest set bit in the word.
+*/
+#ifdef PR_HAVE_BUILTIN_BITSCAN32
+#define PR_FLOOR_LOG2(_log2,_n)     \
+  PR_BEGIN_MACRO                    \
+    PRUint32 j_ = (PRUint32)(_n);   \
+    (_log2) = 31 - pr_bitscan_clz32((j_) | 1); \
+  PR_END_MACRO
+#else
+#define PR_FLOOR_LOG2(_log2,_n)   \
+  PR_BEGIN_MACRO                    \
+    PRUint32 j_ = (PRUint32)(_n); 	\
+    (_log2) = 0;                    \
+    if ((j_) >> 16)                 \
+	(_log2) += 16, (j_) >>= 16; \
+    if ((j_) >> 8)                  \
+	(_log2) += 8, (j_) >>= 8;   \
+    if ((j_) >> 4)                  \
+	(_log2) += 4, (j_) >>= 4;   \
+    if ((j_) >> 2)                  \
+	(_log2) += 2, (j_) >>= 2;   \
+    if ((j_) >> 1)                  \
+	(_log2) += 1;               \
+  PR_END_MACRO
+#endif /* PR_HAVE_BUILTIN_BITSCAN32 */
+
+/*
+** Macros for rotate left and right. The argument 'a' must be an unsigned
+** 32-bit integer type such as PRUint32.
+**
+** There is no rotate operation in the C Language, so the construct
+** (a << 4) | (a >> 28) is frequently used instead. Most compilers convert
+** this to a rotate instruction, but MSVC doesn't without a little help.
+** To get MSVC to generate a rotate instruction, we have to use the _rotl
+** or _rotr intrinsic and use a pragma to make it inline.
+**
+** Note: MSVC in VS2005 will do an inline rotate instruction on the above
+** construct.
+*/
+
+#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_AMD64) || \
+    defined(_M_X64) || defined(_M_ARM))
+#include <stdlib.h>
+#pragma intrinsic(_rotl, _rotr)
+#define PR_ROTATE_LEFT32(a, bits) _rotl(a, bits)
+#define PR_ROTATE_RIGHT32(a, bits) _rotr(a, bits)
+#else
+#define PR_ROTATE_LEFT32(a, bits) (((a) << (bits)) | ((a) >> (32 - (bits))))
+#define PR_ROTATE_RIGHT32(a, bits) (((a) >> (bits)) | ((a) << (32 - (bits))))
+#endif
+
+PR_END_EXTERN_C
+#endif /* prbit_h___ */
diff --git a/pr/include/prclist.h b/pr/include/prclist.h
new file mode 100644
index 0000000..2324722
--- /dev/null
+++ b/pr/include/prclist.h
@@ -0,0 +1,108 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef prclist_h___
+#define prclist_h___
+
+#include "prtypes.h"
+
+typedef struct PRCListStr PRCList;
+
+/*
+** Circular linked list
+*/
+struct PRCListStr {
+    PRCList	*next;
+    PRCList	*prev;
+};
+
+/*
+** Insert element "_e" into the list, before "_l".
+*/
+#define PR_INSERT_BEFORE(_e,_l)	 \
+    PR_BEGIN_MACRO		 \
+	(_e)->next = (_l);	 \
+	(_e)->prev = (_l)->prev; \
+	(_l)->prev->next = (_e); \
+	(_l)->prev = (_e);	 \
+    PR_END_MACRO
+
+/*
+** Insert element "_e" into the list, after "_l".
+*/
+#define PR_INSERT_AFTER(_e,_l)	 \
+    PR_BEGIN_MACRO		 \
+	(_e)->next = (_l)->next; \
+	(_e)->prev = (_l);	 \
+	(_l)->next->prev = (_e); \
+	(_l)->next = (_e);	 \
+    PR_END_MACRO
+
+/*
+** Return the element following element "_e"
+*/
+#define PR_NEXT_LINK(_e)	 \
+    	((_e)->next)
+/*
+** Return the element preceding element "_e"
+*/
+#define PR_PREV_LINK(_e)	 \
+    	((_e)->prev)
+
+/*
+** Append an element "_e" to the end of the list "_l"
+*/
+#define PR_APPEND_LINK(_e,_l) PR_INSERT_BEFORE(_e,_l)
+
+/*
+** Insert an element "_e" at the head of the list "_l"
+*/
+#define PR_INSERT_LINK(_e,_l) PR_INSERT_AFTER(_e,_l)
+
+/* Return the head/tail of the list */
+#define PR_LIST_HEAD(_l) (_l)->next
+#define PR_LIST_TAIL(_l) (_l)->prev
+
+/*
+** Remove the element "_e" from it's circular list.
+*/
+#define PR_REMOVE_LINK(_e)	       \
+    PR_BEGIN_MACRO		       \
+	(_e)->prev->next = (_e)->next; \
+	(_e)->next->prev = (_e)->prev; \
+    PR_END_MACRO
+
+/*
+** Remove the element "_e" from it's circular list. Also initializes the
+** linkage.
+*/
+#define PR_REMOVE_AND_INIT_LINK(_e)    \
+    PR_BEGIN_MACRO		       \
+	(_e)->prev->next = (_e)->next; \
+	(_e)->next->prev = (_e)->prev; \
+	(_e)->next = (_e);	       \
+	(_e)->prev = (_e);	       \
+    PR_END_MACRO
+
+/*
+** Return non-zero if the given circular list "_l" is empty, zero if the
+** circular list is not empty
+*/
+#define PR_CLIST_IS_EMPTY(_l) \
+    ((_l)->next == (_l))
+
+/*
+** Initialize a circular list
+*/
+#define PR_INIT_CLIST(_l)  \
+    PR_BEGIN_MACRO	   \
+	(_l)->next = (_l); \
+	(_l)->prev = (_l); \
+    PR_END_MACRO
+
+#define PR_INIT_STATIC_CLIST(_l) \
+    {(_l), (_l)}
+
+#endif /* prclist_h___ */
diff --git a/pr/include/prcmon.h b/pr/include/prcmon.h
new file mode 100644
index 0000000..6917113
--- /dev/null
+++ b/pr/include/prcmon.h
@@ -0,0 +1,66 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef prcmon_h___
+#define prcmon_h___
+
+/*
+** Interface to cached monitors. Cached monitors use an address to find a
+** given PR monitor. In this way a monitor can be associated with another
+** object without preallocating a monitor for all objects.
+**
+** A hash table is used to quickly map addresses to individual monitors
+** and the system automatically grows the hash table as needed.
+**
+** Cache monitors are about 5 times slower to use than uncached monitors.
+*/
+#include "prmon.h"
+#include "prinrval.h"
+
+PR_BEGIN_EXTERN_C
+
+/**
+** Like PR_EnterMonitor except use the "address" to find a monitor in the
+** monitor cache. If successful, returns the PRMonitor now associated
+** with "address". Note that you must PR_CExitMonitor the address to
+** release the monitor cache entry (otherwise the monitor cache will fill
+** up). This call will return NULL if the monitor cache needs to be
+** expanded and the system is out of memory.
+*/
+NSPR_API(PRMonitor*) PR_CEnterMonitor(void *address);
+
+/*
+** Like PR_ExitMonitor except use the "address" to find a monitor in the
+** monitor cache.
+*/
+NSPR_API(PRStatus) PR_CExitMonitor(void *address);
+
+/*
+** Like PR_Wait except use the "address" to find a monitor in the
+** monitor cache.
+*/
+NSPR_API(PRStatus) PR_CWait(void *address, PRIntervalTime timeout);
+
+/*
+** Like PR_Notify except use the "address" to find a monitor in the
+** monitor cache.
+*/
+NSPR_API(PRStatus) PR_CNotify(void *address);
+
+/*
+** Like PR_NotifyAll except use the "address" to find a monitor in the
+** monitor cache.
+*/
+NSPR_API(PRStatus) PR_CNotifyAll(void *address);
+
+/*
+** Set a callback to be invoked each time a monitor is recycled from the cache
+** freelist, with the monitor's cache-key passed in address.
+*/
+NSPR_API(void) PR_CSetOnMonitorRecycle(void (PR_CALLBACK *callback)(void *address));
+
+PR_END_EXTERN_C
+
+#endif /* prcmon_h___ */
diff --git a/pr/include/prcountr.h b/pr/include/prcountr.h
new file mode 100644
index 0000000..53b6176
--- /dev/null
+++ b/pr/include/prcountr.h
@@ -0,0 +1,525 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef prcountr_h___
+#define prcountr_h___
+
+/*----------------------------------------------------------------------------
+** prcountr.h -- NSPR Instrumentation counters
+**
+** The NSPR Counter Feature provides a means to "count
+** something." Counters can be dynamically defined, incremented,
+** decremented, set, and deleted under application program
+** control.
+** 																                   
+** The Counter Feature is intended to be used as instrumentation,                  
+** not as operational data. If you need a counter for operational                  
+** data, use native integral types.                                                
+** 																                   
+** Counters are 32bit unsigned intergers. On overflow, a counter                   
+** will wrap. No exception is recognized or reported.                              
+**                                                                                 
+** A counter can be dynamically created using a two level naming
+** convention. A "handle" is returned when the counter is
+** created. The counter can subsequently be addressed by its
+** handle. An API is provided to get an existing counter's handle
+** given the names with  which it was originally created. 
+** Similarly, a counter's name can be retrieved given its handle.
+** 
+** The counter naming convention is a two-level hierarchy. The
+** QName is the higher level of the hierarchy; RName is the
+** lower level. RNames can be thought of as existing within a
+** QName. The same RName can exist within multiple QNames. QNames
+** are unique. The NSPR Counter is not a near-zero overhead
+** feature. Application designers should be aware of 
+** serialization issues when using the Counter API. Creating a
+** counter locks a large asset, potentially causing a stall. This
+** suggest that applications should create counters at component
+** initialization, for example, and not create and destroy them
+** willy-nilly. ... You have been warned.
+** 
+** Incrementing and Adding to counters uses atomic operations.
+** The performance of these operations will vary from platform
+** to platform. On platforms where atomic operations are not
+** supported the overhead may be substantial.
+** 
+** When traversing the counter database with FindNext functions,
+** the instantaneous values of any given counter is that at the
+** moment of extraction. The state of the entire counter database
+** may not be viewed as atomic.
+** 
+** The counter interface may be disabled (No-Op'd) at compile
+** time. When DEBUG is defined at compile time, the Counter
+** Feature is compiled into NSPR and applications invoking it.
+** When DEBUG is not defined, the counter macros compile to
+** nothing. To force the Counter Feature to be compiled into an
+** optimized build, define FORCE_NSPR_COUNTERS at compile time
+** for both NSPR and the application intending to use it.
+** 
+** Application designers should use the macro form of the Counter
+** Feature methods to minimize performance impact in optimized
+** builds. The macros normally compile to nothing on optimized
+** builds.
+** 
+** Application designers should be aware of the effects of
+** debug and optimized build differences when using result of the
+** Counter Feature macros in expressions.
+** 
+** The Counter Feature is thread-safe and SMP safe.
+** 
+** /lth. 09-Jun-1998.
+*/
+
+#include "prtypes.h"
+
+PR_BEGIN_EXTERN_C
+
+/*
+** Opaque counter handle type.
+** ... don't even think of looking in here.
+**
+*/
+typedef void *  PRCounterHandle;
+
+#define PRCOUNTER_NAME_MAX 31
+#define PRCOUNTER_DESC_MAX 255
+
+
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_DEFINE_COUNTER() -- Define a PRCounterHandle
+** 
+** DESCRIPTION: PR_DEFINE_COUNTER() is used to define a counter
+** handle.
+** 
+*/
+#define PR_DEFINE_COUNTER(name) PRCounterHandle name
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_INIT_COUNTER_HANDLE() -- Set the value of a PRCounterHandle
+** 
+** DESCRIPTION: 
+** PR_INIT_COUNTER_HANDLE() sets the value of a PRCounterHandle
+** to value.
+** 
+*/
+#if defined(DEBUG) || defined(FORCE_NSPR_COUNTERS)
+#define PR_INIT_COUNTER_HANDLE(handle,value)\
+    (handle) = (PRCounterHandle)(value)
+#else
+#define PR_INIT_COUNTER_HANDLE(handle,value)
+#endif
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_CreateCounter() -- Create a counter
+** 
+** DESCRIPTION: PR_CreateCounter() creates a counter object and
+** initializes it to zero.
+** 
+** The macro form takes as its first argument the name of the
+** PRCounterHandle to receive the handle returned from
+** PR_CreateCounter().
+** 
+** INPUTS:
+**  qName: The QName for the counter object. The maximum length
+** of qName is defined by PRCOUNTER_NAME_MAX
+** 
+**  rName: The RName for the counter object. The maximum length
+** of qName is defined by PRCOUNTER_NAME_MAX
+** 
+**  descrioption: The description of the counter object. The
+** maximum length of description is defined by
+** PRCOUNTER_DESC_MAX.
+** 
+** OUTPUTS:
+** 
+** RETURNS:
+**  PRCounterHandle.
+** 
+** RESTRICTIONS:
+** 
+*/
+#if defined(DEBUG) || defined(FORCE_NSPR_COUNTERS)
+#define PR_CREATE_COUNTER(handle,qName,rName,description)\
+   (handle) = PR_CreateCounter((qName),(rName),(description))
+#else
+#define PR_CREATE_COUNTER(handle,qName,rName,description)
+#endif
+
+NSPR_API(PRCounterHandle) 
+	PR_CreateCounter( 
+		const char *qName, 
+    	const char *rName, 
+        const char *description 
+);
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_DestroyCounter() -- Destroy a counter object.
+** 
+** DESCRIPTION: PR_DestroyCounter() removes a counter and
+** unregisters its handle from the counter database.
+** 
+** INPUTS:
+**  handle: the PRCounterHandle of the counter to be destroyed.
+** 
+** OUTPUTS: 
+**  The counter is destroyed.
+** 
+** RETURNS: void
+** 
+** RESTRICTIONS:
+** 
+*/
+#if defined(DEBUG) || defined(FORCE_NSPR_COUNTERS)
+#define PR_DESTROY_COUNTER(handle) PR_DestroyCounter((handle))
+#else
+#define PR_DESTROY_COUNTER(handle)
+#endif
+
+NSPR_API(void) 
+	PR_DestroyCounter( 
+		PRCounterHandle handle 
+);
+
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_GetCounterHandleFromName() -- Retreive a
+** counter's handle give its name.
+** 
+** DESCRIPTION: PR_GetCounterHandleFromName() retreives a
+** counter's handle from the counter database, given the name
+** the counter was originally created with.
+** 
+** INPUTS:
+**  qName: Counter's original QName.
+**  rName: Counter's original RName.
+** 
+** OUTPUTS:
+** 
+** RETURNS: 
+**  PRCounterHandle or PRCounterError.
+** 
+** RESTRICTIONS:
+** 
+*/
+#if defined(DEBUG) || defined(FORCE_NSPR_COUNTERS)
+#define PR_GET_COUNTER_HANDLE_FROM_NAME(handle,qName,rName)\
+    (handle) = PR_GetCounterHandleFromName((qName),(rName))
+#else
+#define PR_GET_COUNTER_HANDLE_FROM_NAME(handle,qName,rName)
+#endif
+
+NSPR_API(PRCounterHandle) 
+	PR_GetCounterHandleFromName( 
+    	const char *qName, 
+    	const char *rName 
+);
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_GetCounterNameFromHandle() -- Retreive a
+** counter's name, given its handle.
+** 
+** DESCRIPTION: PR_GetCounterNameFromHandle() retreives a
+** counter's name given its handle.
+** 
+** INPUTS:
+**  qName: Where to store a pointer to qName.
+**  rName: Where to store a pointer to rName.
+**  description: Where to store a pointer to description.
+** 
+** OUTPUTS: Pointers to the Counter Feature's copies of the names
+** used when the counters were created.
+** 
+** RETURNS: void
+** 
+** RESTRICTIONS:
+** 
+*/
+#if defined(DEBUG) || defined(FORCE_NSPR_COUNTERS)
+#define PR_GET_COUNTER_NAME_FROM_HANDLE(handle,qName,rName,description)\
+    PR_GetCounterNameFromHandle((handle),(qName),(rName),(description))
+#else
+#define PR_GET_COUNTER_NAME_FROM_HANDLE(handle,qName,rName,description )
+#endif
+
+NSPR_API(void) 
+	PR_GetCounterNameFromHandle( 
+    	PRCounterHandle handle,  
+	    const char **qName, 
+	    const char **rName, 
+		const char **description 
+);
+
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_IncrementCounter() -- Add one to the referenced
+** counter.
+** 
+** DESCRIPTION: Add one to the referenced counter.
+** 
+** INPUTS:
+**  handle: The PRCounterHandle of the counter to be incremented
+** 
+** OUTPUTS: The counter is incrementd.
+** 
+** RETURNS: void
+** 
+** RESTRICTIONS:
+** 
+*/
+#if defined(DEBUG) || defined(FORCE_NSPR_COUNTERS)
+#define PR_INCREMENT_COUNTER(handle) PR_IncrementCounter(handle)
+#else
+#define PR_INCREMENT_COUNTER(handle)
+#endif
+
+NSPR_API(void) 
+	PR_IncrementCounter( 
+		PRCounterHandle handle
+);
+
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_DecrementCounter() -- Subtract one from the
+** referenced counter
+** 
+** DESCRIPTION: Subtract one from the referenced counter.
+** 
+** INPUTS: 
+**  handle: The PRCounterHandle of the coutner to be
+** decremented.
+** 
+** OUTPUTS: the counter is decremented.
+** 
+** RETURNS: void
+** 
+** RESTRICTIONS:
+** 
+*/
+#if defined(DEBUG) || defined(FORCE_NSPR_COUNTERS)
+#define PR_DECREMENT_COUNTER(handle) PR_DecrementCounter(handle)
+#else
+#define PR_DECREMENT_COUNTER(handle)
+#endif
+
+NSPR_API(void) 
+	PR_DecrementCounter( 
+		PRCounterHandle handle
+);
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_AddToCounter() -- Add a value to a counter.
+** 
+** DESCRIPTION: Add value to the counter referenced by handle.
+** 
+** INPUTS:
+**  handle: the PRCounterHandle of the counter to be added to.
+** 
+**  value: the value to be added to the counter.
+** 
+** OUTPUTS: new value for counter.
+** 
+** RETURNS: void
+** 
+** RESTRICTIONS:
+** 
+*/
+#if defined(DEBUG) || defined(FORCE_NSPR_COUNTERS)
+#define PR_ADD_TO_COUNTER(handle,value)\
+    PR_AddToCounter((handle),(value))
+#else
+#define PR_ADD_TO_COUNTER(handle,value)
+#endif
+
+NSPR_API(void) 
+	PR_AddToCounter( 
+    	PRCounterHandle handle, 
+	    PRUint32 value 
+);
+
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_SubtractFromCounter() -- A value is subtracted
+** from a counter.
+** 
+** DESCRIPTION:
+** Subtract a value from a counter.
+** 
+** INPUTS:
+**  handle: the PRCounterHandle of the counter to be subtracted
+** from.
+** 
+**  value: the value to be subtracted from the counter.
+** 
+** OUTPUTS: new value for counter
+** 
+** RETURNS: void
+** 
+** RESTRICTIONS:
+** 
+*/
+#if defined(DEBUG) || defined(FORCE_NSPR_COUNTERS)
+#define PR_SUBTRACT_FROM_COUNTER(handle,value)\
+    PR_SubtractFromCounter((handle),(value))
+#else
+#define PR_SUBTRACT_FROM_COUNTER(handle,value)
+#endif
+
+NSPR_API(void) 
+	PR_SubtractFromCounter( 
+    	PRCounterHandle handle, 
+	    PRUint32 value 
+);
+
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_GetCounter() -- Retreive the value of a counter
+** 
+** DESCRIPTION:
+** Retreive the value of a counter.
+** 
+** INPUTS:
+**  handle: the PR_CounterHandle of the counter to be retreived
+** 
+** OUTPUTS:
+** 
+** RETURNS: The value of the referenced counter
+** 
+** RESTRICTIONS:
+** 
+*/
+#if defined(DEBUG) || defined(FORCE_NSPR_COUNTERS)
+#define PR_GET_COUNTER(counter,handle)\
+    (counter) = PR_GetCounter((handle))
+#else
+#define PR_GET_COUNTER(counter,handle) 0
+#endif
+
+NSPR_API(PRUint32) 
+	PR_GetCounter( 
+		PRCounterHandle handle 
+);
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_SetCounter() -- Replace the content of counter
+** with value.
+** 
+** DESCRIPTION: The contents of the referenced counter are
+** replaced by value.
+** 
+** INPUTS:
+**  handle: the PRCounterHandle of the counter whose contents
+** are to be replaced.
+** 
+**  value: the new value of the counter.
+** 
+** OUTPUTS:
+** 
+** RETURNS: void
+** 
+** RESTRICTIONS:
+** 
+*/
+#if defined(DEBUG) || defined(FORCE_NSPR_COUNTERS)
+#define PR_SET_COUNTER(handle,value) PR_SetCounter((handle),(value))
+#else
+#define PR_SET_COUNTER(handle,value)
+#endif
+
+NSPR_API(void) 
+	PR_SetCounter( 
+		PRCounterHandle handle, 
+		PRUint32 value 
+);
+
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_FindNextCounterQname() -- Retreive the next QName counter
+** handle iterator
+** 
+** DESCRIPTION:
+** PR_FindNextCounterQname() retreives the first or next Qname
+** the counter data base, depending on the value of handle. When
+** handle is NULL, the function attempts to retreive the first
+** QName handle in the database. When handle is a handle previosly
+** retreived QName handle, then the function attempts to retreive
+** the next QName handle.
+** 
+** INPUTS: 
+**  handle: PRCounterHandle or NULL.
+** 
+** OUTPUTS: returned
+** 
+** RETURNS: PRCounterHandle or NULL when no more QName counter
+** handles are present.
+** 
+** RESTRICTIONS:
+**  A concurrent PR_CreateCounter() or PR_DestroyCounter() may
+** cause unpredictable results.
+** 
+** A PRCounterHandle returned from this function may only be used
+** in another PR_FindNextCounterQname() function call; other
+** operations may cause unpredictable results.
+** 
+*/
+#if defined(DEBUG) || defined(FORCE_NSPR_COUNTERS)
+#define PR_FIND_NEXT_COUNTER_QNAME(next,handle)\
+    (next) = PR_FindNextCounterQname((handle))
+#else
+#define PR_FIND_NEXT_COUNTER_QNAME(next,handle) NULL
+#endif
+
+NSPR_API(PRCounterHandle) 
+	PR_FindNextCounterQname( 
+        PRCounterHandle handle
+);
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_FindNextCounterRname() -- Retreive the next RName counter
+** handle iterator
+** 
+** DESCRIPTION:
+** PR_FindNextCounterRname() retreives the first or next RNname
+** handle from the counter data base, depending on the
+** value of handle. When handle is NULL, the function attempts to
+** retreive the first RName handle in the database. When handle is
+** a handle previosly retreived RName handle, then the function
+** attempts to retreive the next RName handle.
+** 
+** INPUTS:
+**  handle: PRCounterHandle or NULL.
+**  qhandle: PRCounterHandle of a previously aquired via
+** PR_FIND_NEXT_QNAME_HANDLE()
+** 
+** OUTPUTS: returned
+** 
+** RETURNS: PRCounterHandle or NULL when no more RName counter
+** handles are present.
+** 
+** RESTRICTIONS:
+**  A concurrent PR_CreateCounter() or PR_DestroyCounter() may
+** cause unpredictable results.
+** 
+** A PRCounterHandle returned from this function may only be used
+** in another PR_FindNextCounterRname() function call; other
+** operations may cause unpredictable results.
+** 
+*/
+#if defined(DEBUG) || defined(FORCE_NSPR_COUNTERS)
+#define PR_FIND_NEXT_COUNTER_RNAME(next,rhandle,qhandle)\
+    (next) = PR_FindNextCounterRname((rhandle),(qhandle))
+#else
+#define PR_FIND_NEXT_COUNTER_RNAME(next,rhandle,qhandle)
+#endif
+
+NSPR_API(PRCounterHandle) 
+	PR_FindNextCounterRname( 
+        PRCounterHandle rhandle,
+        PRCounterHandle qhandle
+);
+
+PR_END_EXTERN_C
+
+#endif /* prcountr_h___ */
diff --git a/pr/include/prcvar.h b/pr/include/prcvar.h
new file mode 100644
index 0000000..3e30ce1
--- /dev/null
+++ b/pr/include/prcvar.h
@@ -0,0 +1,94 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef prcvar_h___
+#define prcvar_h___
+
+#include "prlock.h"
+#include "prinrval.h"
+
+PR_BEGIN_EXTERN_C
+
+typedef struct PRCondVar PRCondVar;
+
+/*
+** Create a new condition variable.
+**
+** 	"lock" is the lock used to protect the condition variable.
+**
+** Condition variables are synchronization objects that threads can use
+** to wait for some condition to occur.
+**
+** This may fail if memory is tight or if some operating system resource
+** is low. In such cases, a NULL will be returned.
+*/
+NSPR_API(PRCondVar*) PR_NewCondVar(PRLock *lock);
+
+/*
+** Destroy a condition variable. There must be no thread
+** waiting on the condvar. The caller is responsible for guaranteeing
+** that the condvar is no longer in use.
+**
+*/
+NSPR_API(void) PR_DestroyCondVar(PRCondVar *cvar);
+
+/*
+** The thread that waits on a condition is blocked in a "waiting on
+** condition" state until another thread notifies the condition or a
+** caller specified amount of time expires. The lock associated with
+** the condition variable will be released, which must have be held
+** prior to the call to wait.
+**
+** Logically a notified thread is moved from the "waiting on condition"
+** state and made "ready." When scheduled, it will attempt to reacquire
+** the lock that it held when wait was called.
+**
+** The timeout has two well known values, PR_INTERVAL_NO_TIMEOUT and
+** PR_INTERVAL_NO_WAIT. The former value requires that a condition be
+** notified (or the thread interrupted) before it will resume from the
+** wait. If the timeout has a value of PR_INTERVAL_NO_WAIT, the effect
+** is to release the lock, possibly causing a rescheduling within the
+** runtime, then immediately attempting to reacquire the lock and resume.
+**
+** Any other value for timeout will cause the thread to be rescheduled
+** either due to explicit notification or an expired interval. The latter
+** must be determined by treating time as one part of the monitored data
+** being protected by the lock and tested explicitly for an expired
+** interval.
+**
+** Returns PR_FAILURE if the caller has not locked the lock associated
+** with the condition variable or the thread was interrupted (PR_Interrupt()).
+** The particular reason can be extracted with PR_GetError().
+*/
+NSPR_API(PRStatus) PR_WaitCondVar(PRCondVar *cvar, PRIntervalTime timeout);
+
+/*
+** Notify ONE thread that is currently waiting on 'cvar'. Which thread is
+** dependent on the implementation of the runtime. Common sense would dictate
+** that all threads waiting on a single condition have identical semantics,
+** therefore which one gets notified is not significant. 
+**
+** The calling thead must hold the lock that protects the condition, as
+** well as the invariants that are tightly bound to the condition, when
+** notify is called.
+**
+** Returns PR_FAILURE if the caller has not locked the lock associated
+** with the condition variable.
+*/
+NSPR_API(PRStatus) PR_NotifyCondVar(PRCondVar *cvar);
+
+/*
+** Notify all of the threads waiting on the condition variable. The order
+** that the threads are notified is indeterminant. The lock that protects
+** the condition must be held.
+**
+** Returns PR_FAILURE if the caller has not locked the lock associated
+** with the condition variable.
+*/
+NSPR_API(PRStatus) PR_NotifyAllCondVar(PRCondVar *cvar);
+
+PR_END_EXTERN_C
+
+#endif /* prcvar_h___ */
diff --git a/pr/include/prdtoa.h b/pr/include/prdtoa.h
new file mode 100644
index 0000000..191b6c7
--- /dev/null
+++ b/pr/include/prdtoa.h
@@ -0,0 +1,51 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef prdtoa_h___
+#define prdtoa_h___
+
+#include "prtypes.h"
+
+PR_BEGIN_EXTERN_C
+
+/*
+** PR_strtod() returns as a double-precision floating-point number
+** the  value represented by the character string pointed to by
+** s00. The string is scanned up to the first unrecognized
+** character.
+**a
+** If the value of se is not (char **)NULL, a  pointer  to
+** the  character terminating the scan is returned in the location pointed
+** to by se. If no number can be formed, se is set to s00, and
+** zero is returned.
+*/
+NSPR_API(PRFloat64)
+PR_strtod(const char *s00, char **se);
+
+/*
+** PR_cnvtf()
+** conversion routines for floating point
+** prcsn - number of digits of precision to generate floating
+** point value.
+*/
+NSPR_API(void) PR_cnvtf(char *buf, PRIntn bufsz, PRIntn prcsn, PRFloat64 fval);
+
+/*
+** PR_dtoa() converts double to a string.
+**
+** ARGUMENTS:
+** If rve is not null, *rve is set to point to the end of the return value.
+** If d is +-Infinity or NaN, then *decpt is set to 9999.
+**
+** mode:
+**     0 ==> shortest string that yields d when read in
+**           and rounded to nearest.
+*/
+NSPR_API(PRStatus) PR_dtoa(PRFloat64 d, PRIntn mode, PRIntn ndigits,
+	PRIntn *decpt, PRIntn *sign, char **rve, char *buf, PRSize bufsize);
+
+PR_END_EXTERN_C
+
+#endif /* prdtoa_h___ */
diff --git a/pr/include/prenv.h b/pr/include/prenv.h
new file mode 100644
index 0000000..468c7d5
--- /dev/null
+++ b/pr/include/prenv.h
@@ -0,0 +1,162 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef prenv_h___
+#define prenv_h___
+
+#include "prtypes.h"
+
+/*******************************************************************************/
+/*******************************************************************************/
+/****************** THESE FUNCTIONS MAY NOT BE THREAD SAFE *********************/
+/*******************************************************************************/
+/*******************************************************************************/
+
+PR_BEGIN_EXTERN_C
+
+/*
+** PR_GetEnv() -- Retrieve value of environment variable
+** 
+** Description:
+** PR_GetEnv() is modeled on Unix getenv().
+** 
+** 
+** Inputs: 
+**   var -- The name of the environment variable
+** 
+** Returns:
+**   The value of the environment variable 'var' or NULL if
+** the variable is undefined.
+** 
+** Restrictions:
+**   You'd think that a POSIX getenv(), putenv() would be
+**   consistently implemented everywhere. Surprise! It is not. On
+**   some platforms, a putenv() where the argument is of
+**   the form "name"  causes the named environment variable to
+**   be un-set; that is: a subsequent getenv() returns NULL. On
+**   other platforms, the putenv() fails, on others, it is a
+**   no-op. Similarly, a putenv() where the argument is of the
+**   form "name=" causes the named environment variable to be
+**   un-set; a subsequent call to getenv() returns NULL. On
+**   other platforms, a subsequent call to getenv() returns a
+**   pointer to a null-string (a byte of zero).
+** 
+**   PR_GetEnv(), PR_SetEnv() provide a consistent behavior 
+**   across all supported platforms. There are, however, some
+**   restrictions and some practices you must use to achieve
+**   consistent results everywhere.
+** 
+**   When manipulating the environment there is no way to un-set
+**   an environment variable across all platforms. We suggest
+**   you interpret the return of a pointer to null-string to
+**   mean the same as a return of NULL from PR_GetEnv().
+** 
+**   A call to PR_SetEnv() where the parameter is of the form
+**   "name" will return PR_FAILURE; the environment remains
+**   unchanged. A call to PR_SetEnv() where the parameter is
+**   of the form "name=" may un-set the envrionment variable on
+**   some platforms; on others it may set the value of the
+**   environment variable to the null-string.
+** 
+**   For example, to test for NULL return or return of the
+**   null-string from PR_GetEnv(), use the following code
+**   fragment:
+** 
+**      char *val = PR_GetEnv("foo");
+**      if ((NULL == val) || ('\0' == *val)) { 
+**          ... interpret this as un-set ... 
+**      }
+** 
+**   The caller must ensure that the string passed
+**   to PR_SetEnv() is persistent. That is: The string should
+**   not be on the stack, where it can be overwritten
+**   on return from the function calling PR_SetEnv().
+**   Similarly, the string passed to PR_SetEnv() must not be
+**   overwritten by other actions of the process. ... Some
+**   platforms use the string by reference rather than copying
+**   it into the environment space. ... You have been warned!
+** 
+**   Use of platform-native functions that manipulate the
+**   environment (getenv(), putenv(), 
+**   SetEnvironmentVariable(), etc.) must not be used with
+**   NSPR's similar functions. The platform-native functions
+**   may not be thread safe and/or may operate on different
+**   conceptual environment space than that operated upon by
+**   NSPR's functions or other environment manipulating
+**   functions on the same platform. (!)
+** 
+*/
+NSPR_API(char*) PR_GetEnv(const char *var);
+
+/*
+** PR_GetEnvSecure() -- get a security-sensitive environment variable
+**
+** Description:
+**
+** PR_GetEnvSecure() is similar to PR_GetEnv(), but it returns NULL if
+** the program was run with elevated privilege (e.g., setuid or setgid
+** on Unix).  This can be used for cases like log file paths which
+** could otherwise be used for privilege escalation.  Note that some
+** platforms may have platform-specific privilege elevation mechanisms
+** not recognized by this function; see the implementation for details.
+*/
+NSPR_API(char*) PR_GetEnvSecure(const char *var);
+
+/*
+** PR_SetEnv() -- set, unset or change an environment variable
+** 
+** Description:
+** PR_SetEnv() is modeled on the Unix putenv() function.
+** 
+** Inputs: 
+**   string -- pointer to a caller supplied
+**   constant, persistent string of the form name=value. Where
+**   name is the name of the environment variable to be set or
+**   changed; value is the value assigned to the variable.
+**
+** Returns: 
+**   PRStatus.
+** 
+** Restrictions: 
+**   See the Restrictions documented in the description of
+**   PR_GetEnv() in this header file.
+** 
+** 
+*/
+NSPR_API(PRStatus) PR_SetEnv(const char *string);
+
+/*
+** PR_DuplicateEnvironment() -- Obtain a copy of the environment.
+**
+** Description:
+** PR_DuplicateEnvironment() copies the environment so that it can be
+** modified without changing the current process's environment, and
+** then passed to interfaces such as POSIX execve().  In particular,
+** this avoids needing to allocate memory or take locks in the child
+** after a fork(); neither of these is allowed by POSIX after a
+** multithreaded process calls fork(), and PR_SetEnv does both.
+**
+** Inputs:
+**   none
+**
+** Returns:
+**   A pointer to a null-terminated array of null-terminated strings,
+**   like the traditional global variable "environ".  The array and
+**   the strings are allocated with PR_Malloc(), and it is the
+**   caller's responsibility to free them.
+**
+**   In case of memory allocation failure, or if the operating system
+**   doesn't support reading the entire environment through the global
+**   variable "environ" or similar, returns NULL instead.
+**
+** Restrictions:
+**   Similarly to PR_GetEnv(), this function may not interoperate as
+**   expected with the operating system's native environment accessors.
+*/
+NSPR_API(char **) PR_DuplicateEnvironment(void);
+
+PR_END_EXTERN_C
+
+#endif /* prenv_h___ */
diff --git a/pr/include/prerr.h b/pr/include/prerr.h
new file mode 100644
index 0000000..8512329
--- /dev/null
+++ b/pr/include/prerr.h
@@ -0,0 +1,249 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef prerr_h___
+#define prerr_h___
+
+/*
+ *
+ * prerr.h
+ * This file is automatically generated; please do not edit it.
+ */
+
+/* Memory allocation attempt failed */
+#define PR_OUT_OF_MEMORY_ERROR                   (-6000L)
+
+/* Invalid file descriptor */
+#define PR_BAD_DESCRIPTOR_ERROR                  (-5999L)
+
+/* The operation would have blocked */
+#define PR_WOULD_BLOCK_ERROR                     (-5998L)
+
+/* Invalid memory address argument */
+#define PR_ACCESS_FAULT_ERROR                    (-5997L)
+
+/* Invalid function for file type */
+#define PR_INVALID_METHOD_ERROR                  (-5996L)
+
+/* Invalid memory address argument */
+#define PR_ILLEGAL_ACCESS_ERROR                  (-5995L)
+
+/* Some unknown error has occurred */
+#define PR_UNKNOWN_ERROR                         (-5994L)
+
+/* Operation interrupted by another thread */
+#define PR_PENDING_INTERRUPT_ERROR               (-5993L)
+
+/* function not implemented */
+#define PR_NOT_IMPLEMENTED_ERROR                 (-5992L)
+
+/* I/O function error */
+#define PR_IO_ERROR                              (-5991L)
+
+/* I/O operation timed out */
+#define PR_IO_TIMEOUT_ERROR                      (-5990L)
+
+/* I/O operation on busy file descriptor */
+#define PR_IO_PENDING_ERROR                      (-5989L)
+
+/* The directory could not be opened */
+#define PR_DIRECTORY_OPEN_ERROR                  (-5988L)
+
+/* Invalid function argument */
+#define PR_INVALID_ARGUMENT_ERROR                (-5987L)
+
+/* Network address not available (in use?) */
+#define PR_ADDRESS_NOT_AVAILABLE_ERROR           (-5986L)
+
+/* Network address type not supported */
+#define PR_ADDRESS_NOT_SUPPORTED_ERROR           (-5985L)
+
+/* Already connected */
+#define PR_IS_CONNECTED_ERROR                    (-5984L)
+
+/* Network address is invalid */
+#define PR_BAD_ADDRESS_ERROR                     (-5983L)
+
+/* Local Network address is in use */
+#define PR_ADDRESS_IN_USE_ERROR                  (-5982L)
+
+/* Connection refused by peer */
+#define PR_CONNECT_REFUSED_ERROR                 (-5981L)
+
+/* Network address is presently unreachable */
+#define PR_NETWORK_UNREACHABLE_ERROR             (-5980L)
+
+/* Connection attempt timed out */
+#define PR_CONNECT_TIMEOUT_ERROR                 (-5979L)
+
+/* Network file descriptor is not connected */
+#define PR_NOT_CONNECTED_ERROR                   (-5978L)
+
+/* Failure to load dynamic library */
+#define PR_LOAD_LIBRARY_ERROR                    (-5977L)
+
+/* Failure to unload dynamic library */
+#define PR_UNLOAD_LIBRARY_ERROR                  (-5976L)
+
+/* Symbol not found in any of the loaded dynamic libraries */
+#define PR_FIND_SYMBOL_ERROR                     (-5975L)
+
+/* Insufficient system resources */
+#define PR_INSUFFICIENT_RESOURCES_ERROR          (-5974L)
+
+/* A directory lookup on a network address has failed */
+#define PR_DIRECTORY_LOOKUP_ERROR                (-5973L)
+
+/* Attempt to access a TPD key that is out of range */
+#define PR_TPD_RANGE_ERROR                       (-5972L)
+
+/* Process open FD table is full */
+#define PR_PROC_DESC_TABLE_FULL_ERROR            (-5971L)
+
+/* System open FD table is full */
+#define PR_SYS_DESC_TABLE_FULL_ERROR             (-5970L)
+
+/* Network operation attempted on non-network file descriptor */
+#define PR_NOT_SOCKET_ERROR                      (-5969L)
+
+/* TCP-specific function attempted on a non-TCP file descriptor */
+#define PR_NOT_TCP_SOCKET_ERROR                  (-5968L)
+
+/* TCP file descriptor is already bound */
+#define PR_SOCKET_ADDRESS_IS_BOUND_ERROR         (-5967L)
+
+/* Access Denied */
+#define PR_NO_ACCESS_RIGHTS_ERROR                (-5966L)
+
+/* The requested operation is not supported by the platform */
+#define PR_OPERATION_NOT_SUPPORTED_ERROR         (-5965L)
+
+/* The host operating system does not support the protocol requested */
+#define PR_PROTOCOL_NOT_SUPPORTED_ERROR          (-5964L)
+
+/* Access to the remote file has been severed */
+#define PR_REMOTE_FILE_ERROR                     (-5963L)
+
+/* The value requested is too large to be stored in the data buffer provided */
+#define PR_BUFFER_OVERFLOW_ERROR                 (-5962L)
+
+/* TCP connection reset by peer */
+#define PR_CONNECT_RESET_ERROR                   (-5961L)
+
+/* Unused */
+#define PR_RANGE_ERROR                           (-5960L)
+
+/* The operation would have deadlocked */
+#define PR_DEADLOCK_ERROR                        (-5959L)
+
+/* The file is already locked */
+#define PR_FILE_IS_LOCKED_ERROR                  (-5958L)
+
+/* Write would result in file larger than the system allows */
+#define PR_FILE_TOO_BIG_ERROR                    (-5957L)
+
+/* The device for storing the file is full */
+#define PR_NO_DEVICE_SPACE_ERROR                 (-5956L)
+
+/* Unused */
+#define PR_PIPE_ERROR                            (-5955L)
+
+/* Unused */
+#define PR_NO_SEEK_DEVICE_ERROR                  (-5954L)
+
+/* Cannot perform a normal file operation on a directory */
+#define PR_IS_DIRECTORY_ERROR                    (-5953L)
+
+/* Symbolic link loop */
+#define PR_LOOP_ERROR                            (-5952L)
+
+/* File name is too long */
+#define PR_NAME_TOO_LONG_ERROR                   (-5951L)
+
+/* File not found */
+#define PR_FILE_NOT_FOUND_ERROR                  (-5950L)
+
+/* Cannot perform directory operation on a normal file */
+#define PR_NOT_DIRECTORY_ERROR                   (-5949L)
+
+/* Cannot write to a read-only file system */
+#define PR_READ_ONLY_FILESYSTEM_ERROR            (-5948L)
+
+/* Cannot delete a directory that is not empty */
+#define PR_DIRECTORY_NOT_EMPTY_ERROR             (-5947L)
+
+/* Cannot delete or rename a file object while the file system is busy */
+#define PR_FILESYSTEM_MOUNTED_ERROR              (-5946L)
+
+/* Cannot rename a file to a file system on another device */
+#define PR_NOT_SAME_DEVICE_ERROR                 (-5945L)
+
+/* The directory object in the file system is corrupted */
+#define PR_DIRECTORY_CORRUPTED_ERROR             (-5944L)
+
+/* Cannot create or rename a filename that already exists */
+#define PR_FILE_EXISTS_ERROR                     (-5943L)
+
+/* Directory is full.  No additional filenames may be added */
+#define PR_MAX_DIRECTORY_ENTRIES_ERROR           (-5942L)
+
+/* The required device was in an invalid state */
+#define PR_INVALID_DEVICE_STATE_ERROR            (-5941L)
+
+/* The device is locked */
+#define PR_DEVICE_IS_LOCKED_ERROR                (-5940L)
+
+/* No more entries in the directory */
+#define PR_NO_MORE_FILES_ERROR                   (-5939L)
+
+/* Encountered end of file */
+#define PR_END_OF_FILE_ERROR                     (-5938L)
+
+/* Seek error */
+#define PR_FILE_SEEK_ERROR                       (-5937L)
+
+/* The file is busy */
+#define PR_FILE_IS_BUSY_ERROR                    (-5936L)
+
+/* The I/O operation was aborted */
+#define PR_OPERATION_ABORTED_ERROR               (-5935L)
+
+/* Operation is still in progress (probably a non-blocking connect) */
+#define PR_IN_PROGRESS_ERROR                     (-5934L)
+
+/* Operation has already been initiated (probably a non-blocking connect) */
+#define PR_ALREADY_INITIATED_ERROR               (-5933L)
+
+/* The wait group is empty */
+#define PR_GROUP_EMPTY_ERROR                     (-5932L)
+
+/* Object state improper for request */
+#define PR_INVALID_STATE_ERROR                   (-5931L)
+
+/* Network is down */
+#define PR_NETWORK_DOWN_ERROR                    (-5930L)
+
+/* Socket shutdown */
+#define PR_SOCKET_SHUTDOWN_ERROR                 (-5929L)
+
+/* Connection aborted */
+#define PR_CONNECT_ABORTED_ERROR                 (-5928L)
+
+/* Host is unreachable */
+#define PR_HOST_UNREACHABLE_ERROR                (-5927L)
+
+/* The library is not loaded */
+#define PR_LIBRARY_NOT_LOADED_ERROR              (-5926L)
+
+/* The one-time function was previously called and failed. Its error code is no longer available */
+#define PR_CALL_ONCE_ERROR                       (-5925L)
+
+/* Placeholder for the end of the list */
+#define PR_MAX_ERROR                             (-5924L)
+
+extern void nspr_InitializePRErrorTable(void);
+#define ERROR_TABLE_BASE_nspr (-6000L)
+
+#endif /* prerr_h___ */
diff --git a/pr/include/prerror.h b/pr/include/prerror.h
new file mode 100644
index 0000000..3d6baf6
--- /dev/null
+++ b/pr/include/prerror.h
@@ -0,0 +1,294 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef prerror_h___
+#define prerror_h___
+
+#include "prtypes.h"
+
+PR_BEGIN_EXTERN_C
+
+typedef PRInt32 PRErrorCode;
+
+#define PR_NSPR_ERROR_BASE -6000
+
+#include "prerr.h"
+
+/*
+** Set error will preserve an error condition within a thread context.
+** The values stored are the NSPR (platform independent) translation of
+** the error. Also, if available, the platform specific oserror is stored.
+** If there is no appropriate OS error number, a zero my be supplied.
+*/
+NSPR_API(void) PR_SetError(PRErrorCode errorCode, PRInt32 oserr);
+
+/*
+** The text value specified may be NULL. If it is not NULL and the text length
+** is zero, the string is assumed to be a null terminated C string. Otherwise
+** the text is assumed to be the length specified and possibly include NULL
+** characters (e.g., a multi-national string).
+**
+** The text will be copied into to thread structure and remain there
+** until the next call to PR_SetError.
+*/
+NSPR_API(void) PR_SetErrorText(
+    PRIntn textLength, const char *text);
+
+/*
+** Return the current threads last set error code.
+*/
+NSPR_API(PRErrorCode) PR_GetError(void);
+
+/*
+** Return the current threads last set os error code. This is used for
+** machine specific code that desires the underlying os error.
+*/
+NSPR_API(PRInt32) PR_GetOSError(void);
+
+/*
+** Get the length of the error text. If a zero is returned, then there
+** is no text. Otherwise, the value returned is sufficient to contain
+** the error text currently available.
+*/
+NSPR_API(PRInt32) PR_GetErrorTextLength(void);
+
+/*
+** Copy the current threads current error text. Then actual number of bytes
+** copied is returned as the result. If the result is zero, the 'text' area
+** is unaffected.
+*/
+NSPR_API(PRInt32) PR_GetErrorText(char *text);
+
+
+/*
+Copyright (C) 1987, 1988 Student Information Processing Board of the
+Massachusetts Institute of Technology.
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted, provided
+that the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation, and that the names of M.I.T. and the M.I.T. S.I.P.B. not be
+used in advertising or publicity pertaining to distribution of the software
+without specific, written prior permission.  M.I.T. and the M.I.T. S.I.P.B.
+make no representations about the suitability of this software for any
+purpose.  It is provided "as is" without express or implied warranty.
+*/
+
+
+/*
+ * NOTE:
+ *		The interfaces for error-code-translation described in the rest of
+ *		this file are preliminary in the 3.1 release of nspr and are subject 
+ *		to change in future releases.
+ */
+
+/*
+** Description:	Localizable error code to string function.
+**
+**
+** NSPR provides a mechanism for converting an error code to a
+** descriptive string, in a caller-specified language.
+**
+** Error codes themselves are 32 bit (signed) integers.  Typically,
+** the high order 24 bits are an identifier of which error table the
+** error code is from, and the low order 8 bits are a sequential error
+** number within the table.  NSPR supports error tables whose first
+** error code is not a multiple of 256, such error code assignments
+** should be avoided when possible.
+**
+** Error table 0 is defined to match the UNIX system call error table
+** (sys_errlist); this allows errno values to be used directly in the
+** library.  Other error table numbers are typically formed by
+** compacting together the first four characters of the error table
+** name.  The mapping between characters in the name and numeric
+** values in the error code are defined in a system-independent
+** fashion, so that two systems that can pass integral values between
+** them can reliably pass error codes without loss of meaning; this
+** should work even if the character sets used are not the
+** same. (However, if this is to be done, error table 0 should be
+** avoided, since the local system call error tables may differ.)
+**
+** Libraries defining error codes need only provide a table mapping
+** error code numbers to names and default English descriptions,
+** calling a routine to install the table, making it ``known'' to NSPR
+** library.  Once installed, a table may not be removed.  Any error
+** code the library generates can be converted to the corresponding
+** error message.  There is also a default format for error codes
+** accidentally returned before making the table known, which is of
+** the form "unknown code foo 32", where "foo" would be the name of
+** the table.
+**
+** Normally, the error code conversion routine only supports the
+** languages "i-default" and "en", returning the error-table-provided
+** English description for both languages.  The application may
+** provide a localization plugin, allowing support for additional
+** languages.
+**
+**/
+
+/**********************************************************************/
+/************************* TYPES AND CONSTANTS ************************/
+/**********************************************************************/
+
+/*
+ * PRLanguageCode --
+ *
+ *    NSPR represents a language code as a non-negative integer.
+ *    Languages 0 is always "i-default" the language you get without
+ *    explicit negotiation.  Language 1 is always "en", English
+ *    which has been explicitly negotiated.  Additional language
+ *    codes are defined by an application-provided localization plugin.
+ */
+typedef PRUint32 PRLanguageCode;
+#define PR_LANGUAGE_I_DEFAULT 0 /* i-default, the default language */
+#define PR_LANGUAGE_EN 1 /* English, explicitly negotiated */
+
+/*
+ * struct PRErrorMessage --
+ *
+ *    An error message in an error table.
+ */
+struct PRErrorMessage {
+    const char * name;    /* Macro name for error */
+    const char * en_text; /* Default English text */
+};
+
+/*
+ * struct PRErrorTable --
+ *
+ *    An error table, provided by a library.
+ */
+struct PRErrorTable {
+    const struct PRErrorMessage * msgs; /* Array of error information */
+    const char *name; /* Name of error table source */
+    PRErrorCode base; /* Error code for first error in table */
+    int n_msgs; /* Number of codes in table */
+};
+
+/*
+ * struct PRErrorCallbackPrivate --
+ *
+ *    A private structure for the localization plugin 
+ */
+struct PRErrorCallbackPrivate;
+
+/*
+ * struct PRErrorCallbackTablePrivate --
+ *
+ *    A data structure under which the localization plugin may store information,
+ *    associated with an error table, that is private to itself.
+ */
+struct PRErrorCallbackTablePrivate;
+
+/*
+ * PRErrorCallbackLookupFn --
+ *
+ *    A function of PRErrorCallbackLookupFn type is a localization
+ *    plugin callback which converts an error code into a description
+ *    in the requested language.  The callback is provided the
+ *    appropriate error table, private data for the plugin and the table.
+ *    The callback returns the appropriate UTF-8 encoded description, or NULL
+ *    if no description can be found.
+ */
+typedef const char *
+PRErrorCallbackLookupFn(PRErrorCode code, PRLanguageCode language, 
+		   const struct PRErrorTable *table,
+		   struct PRErrorCallbackPrivate *cb_private,
+		   struct PRErrorCallbackTablePrivate *table_private);
+
+/*
+ * PRErrorCallbackNewTableFn --
+ *
+ *    A function PRErrorCallbackNewTableFn type is a localization plugin
+ *    callback which is called once with each error table registered
+ *    with NSPR.  The callback is provided with the error table and
+ *    the plugin's private structure.  The callback returns any table private
+ *    data it wishes to associate with the error table.  Does not need to be thread
+ *    safe.
+ */
+typedef struct PRErrorCallbackTablePrivate *
+PRErrorCallbackNewTableFn(const struct PRErrorTable *table,
+			struct PRErrorCallbackPrivate *cb_private);
+
+/**********************************************************************/
+/****************************** FUNCTIONS *****************************/
+/**********************************************************************/
+
+/***********************************************************************
+** FUNCTION:    PR_ErrorToString
+** DESCRIPTION:
+**  Returns the UTF-8 message for an error code in
+**  the requested language.  May return the message
+**  in the default language if a translation in the requested
+**  language is not available.  The returned string is
+**  valid for the duration of the process.  Never returns NULL.
+**
+***********************************************************************/
+NSPR_API(const char *) PR_ErrorToString(PRErrorCode code,
+    PRLanguageCode language);
+
+
+/***********************************************************************
+** FUNCTION:    PR_ErrorToName
+** DESCRIPTION:
+**  Returns the macro name for an error code, or NULL
+**  if the error code is not known.  The returned string is
+**  valid for the duration of the process.
+**
+**  Does not work for error table 0, the system error codes.
+**
+***********************************************************************/
+NSPR_API(const char *) PR_ErrorToName(PRErrorCode code);
+
+
+/***********************************************************************
+** FUNCTION:    PR_ErrorLanguages
+** DESCRIPTION:
+**  Returns the RFC 1766 language tags for the language
+**  codes PR_ErrorToString() supports.  The returned array is valid
+**  for the duration of the process.  Never returns NULL.  The first
+**  item in the returned array is the language tag for PRLanguageCode 0,
+**  the second is for PRLanguageCode 1, and so on.  The array is terminated
+**  with a null pointer.
+**
+***********************************************************************/
+NSPR_API(const char * const *) PR_ErrorLanguages(void);
+
+
+/***********************************************************************
+** FUNCTION:    PR_ErrorInstallTable
+** DESCRIPTION:
+**  Registers an error table with NSPR.  Must be done exactly once per
+**  table.  Memory pointed to by `table' must remain valid for the life
+**  of the process.
+**
+**  NOT THREAD SAFE!
+**  
+***********************************************************************/
+NSPR_API(PRErrorCode) PR_ErrorInstallTable(const struct PRErrorTable *table);
+
+
+/***********************************************************************
+** FUNCTION:    PR_ErrorInstallCallback
+** DESCRIPTION:
+**  Registers an error localization plugin with NSPR.  May be called
+**  at most one time.  `languages' contains the language codes supported
+**  by this plugin.  Languages 0 and 1 must be "i-default" and "en"
+**  respectively.  `lookup' and `newtable' contain pointers to
+**  the plugin callback functions.  `cb_private' contains any information
+**  private to the plugin functions.
+**
+**  NOT THREAD SAFE!
+**
+***********************************************************************/
+NSPR_API(void) PR_ErrorInstallCallback(const char * const * languages,
+			      PRErrorCallbackLookupFn *lookup, 
+			      PRErrorCallbackNewTableFn *newtable,
+			      struct PRErrorCallbackPrivate *cb_private);
+
+PR_END_EXTERN_C
+
+#endif /* prerror_h___ */
diff --git a/pr/include/prinet.h b/pr/include/prinet.h
new file mode 100644
index 0000000..15d229f
--- /dev/null
+++ b/pr/include/prinet.h
@@ -0,0 +1,99 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+ * File:		prinet.h
+ * Description:
+ *     Header file used to find the system header files for socket support[1].
+ *     This file serves the following purposes:
+ *     - A cross-platform, "get-everything" socket header file.  On
+ *       Unix, socket support is scattered in several header files,
+ *       while Windows has a "get-everything" socket header file[2].
+ *     - NSPR needs the following macro definitions and function
+ *       prototype declarations from these header files:
+ *           AF_INET
+ *           INADDR_ANY, INADDR_LOOPBACK, INADDR_BROADCAST
+ *           ntohl(), ntohs(), htonl(), ntons().
+ *       NSPR does not define its own versions of these macros and
+ *       functions.  It simply uses the native versions, which have
+ *       the same names on all supported platforms.
+ *     This file is intended to be included by NSPR public header
+ *     files, such as prio.h.  One should not include this file directly.
+ *
+ * Notes:
+ *     1. This file should have been an internal header.  Please do not
+ *        depend on it to pull in the system header files you need.
+ *     2. WARNING: This file is no longer cross-platform as it is a no-op
+ *        for WIN32!  See the comment in the WIN32 section for details.
+ */
+
+#ifndef prinet_h__
+#define prinet_h__
+
+#if defined(XP_UNIX) || defined(XP_OS2) || defined(XP_BEOS)
+#include <sys/types.h>
+#include <sys/socket.h>		/* AF_INET */
+#include <netinet/in.h>         /* INADDR_ANY, ..., ntohl(), ... */
+#ifdef XP_OS2
+#include <sys/ioctl.h>
+#endif
+#ifdef XP_UNIX
+#ifdef AIX
+/*
+ * On AIX 4.3, the header <arpa/inet.h> refers to struct
+ * ether_addr and struct sockaddr_dl that are not declared.
+ * The following struct declarations eliminate the compiler
+ * warnings.
+ */
+struct ether_addr;
+struct sockaddr_dl;
+#endif /* AIX */
+#include <arpa/inet.h>
+#endif /* XP_UNIX */
+#include <netdb.h>
+
+#if defined(FREEBSD) || defined(BSDI) || defined(QNX)
+#include <rpc/types.h> /* the only place that defines INADDR_LOOPBACK */
+#endif
+
+/*
+ * OS/2 hack.  For some reason INADDR_LOOPBACK is not defined in the
+ * socket headers.
+ */
+#if defined(OS2) && !defined(INADDR_LOOPBACK)
+#define INADDR_LOOPBACK 0x7f000001
+#endif
+
+/*
+ * Prototypes of ntohl() etc. are declared in <machine/endian.h>
+ * on these platforms.
+ */
+#if defined(BSDI) || defined(OSF1)
+#include <machine/endian.h>
+#endif
+
+/* On Android, ntohl() etc. are declared in <sys/endian.h>. */
+#ifdef __ANDROID__
+#include <sys/endian.h>
+#endif
+
+#elif defined(WIN32)
+
+/*
+ * Do not include any system header files.
+ *
+ * Originally we were including <windows.h>.  It slowed down the
+ * compilation of files that included NSPR headers, so we removed
+ * the <windows.h> inclusion at customer's request, which created
+ * an unfortunate inconsistency with other platforms.
+ */
+
+#else
+
+#error Unknown platform
+
+#endif
+
+#endif /* prinet_h__ */
diff --git a/pr/include/prinit.h b/pr/include/prinit.h
new file mode 100644
index 0000000..e27fc34
--- /dev/null
+++ b/pr/include/prinit.h
@@ -0,0 +1,215 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef prinit_h___
+#define prinit_h___
+
+#include "prthread.h"
+#include "prtypes.h"
+#include "prwin16.h"
+#include <stdio.h>
+
+PR_BEGIN_EXTERN_C
+
+/************************************************************************/
+/**************************IDENTITY AND VERSIONING***********************/
+/************************************************************************/
+
+/*
+** NSPR's name, this should persist until at least the turn of the
+** century.
+*/
+#define PR_NAME     "NSPR"
+
+/*
+** NSPR's version is used to determine the likelihood that the version you
+** used to build your component is anywhere close to being compatible with
+** what is in the underlying library.
+**
+** The format of the version string is
+**     "<major version>.<minor version>[.<patch level>] [<Beta>]"
+*/
+#define PR_VERSION  "4.13.1"
+#define PR_VMAJOR   4
+#define PR_VMINOR   13
+#define PR_VPATCH   1
+#define PR_BETA     PR_FALSE
+
+/*
+** PRVersionCheck
+**
+** The basic signature of the function that is called to provide version
+** checking. The result will be a boolean that indicates the likelihood
+** that the underling library will perform as the caller expects.
+**
+** The only argument is a string, which should be the verson identifier
+** of the library in question. That string will be compared against an
+** equivalent string that represents the actual build version of the
+** exporting library.
+**
+** The result will be the logical union of the directly called library
+** and all dependent libraries.
+*/
+
+typedef PRBool (*PRVersionCheck)(const char*);
+
+/*
+** PR_VersionCheck
+**
+** NSPR's existance proof of the version check function.
+**
+** Note that NSPR has no cooperating dependencies.
+*/
+
+NSPR_API(PRBool) PR_VersionCheck(const char *importedVersion);
+
+/*
+ * Returns a const string of the NSPR library version.
+ */
+NSPR_API(const char*) PR_GetVersion(void);
+
+
+/************************************************************************/
+/*******************************INITIALIZATION***************************/
+/************************************************************************/
+
+/*
+** Initialize the runtime. Attach a thread object to the currently
+** executing native thread of type "type".
+**
+** The specificaiton of 'maxPTDs' is ignored.
+*/
+NSPR_API(void) PR_Init(
+    PRThreadType type, PRThreadPriority priority, PRUintn maxPTDs);
+
+/*
+** And alternate form of initialization, one that may become the default if
+** not the only mechanism, provides a method to get the NSPR runtime init-
+** ialized and place NSPR between the caller and the runtime library. This
+** allows main() to be treated as any other thread root function, signalling
+** its compeletion by returning and allowing the runtime to coordinate the
+** completion of the other threads of the runtime.
+**
+** The priority of the main (or primordial) thread will be PR_PRIORITY_NORMAL.
+** The thread may adjust its own priority by using PR_SetPriority(), though
+** at this time the support for priorities is somewhat weak.
+**
+** The specificaiton of 'maxPTDs' is ignored.
+**
+** The value returned by PR_Initialize is the value returned from the root
+** function, 'prmain'.
+*/
+
+typedef PRIntn (PR_CALLBACK *PRPrimordialFn)(PRIntn argc, char **argv);
+
+NSPR_API(PRIntn) PR_Initialize(
+    PRPrimordialFn prmain, PRIntn argc, char **argv, PRUintn maxPTDs);
+
+/*
+** Return PR_TRUE if PR_Init has already been called.
+*/
+NSPR_API(PRBool) PR_Initialized(void);
+
+/*
+ * Perform a graceful shutdown of NSPR.  PR_Cleanup() may be called by
+ * the primordial thread near the end of the main() function.
+ *
+ * PR_Cleanup() attempts to synchronize the natural termination of
+ * process.  It does that by blocking the caller, if and only if it is
+ * the primordial thread, until the number of user threads has dropped
+ * to zero.  When the primordial thread returns from main(), the process
+ * will immediately and silently exit.  That is, it will (if necessary)
+ * forcibly terminate any existing threads and exit without significant
+ * blocking and there will be no error messages or core files.
+ *
+ * PR_Cleanup() returns PR_SUCCESS if NSPR is successfully shutdown,
+ * or PR_FAILURE if the calling thread of this function is not the
+ * primordial thread.
+ */
+NSPR_API(PRStatus) PR_Cleanup(void);
+
+/*
+** Disable Interrupts
+**		Disables timer signals used for pre-emptive scheduling.
+*/
+NSPR_API(void) PR_DisableClockInterrupts(void);
+
+/*
+** Enables Interrupts
+**		Enables timer signals used for pre-emptive scheduling.
+*/
+NSPR_API(void) PR_EnableClockInterrupts(void);
+
+/*
+** Block Interrupts
+**		Blocks the timer signal used for pre-emptive scheduling
+*/
+NSPR_API(void) PR_BlockClockInterrupts(void);
+
+/*
+** Unblock Interrupts
+**		Unblocks the timer signal used for pre-emptive scheduling
+*/
+NSPR_API(void) PR_UnblockClockInterrupts(void);
+
+/*
+** Create extra virtual processor threads. Generally used with MP systems.
+*/
+NSPR_API(void) PR_SetConcurrency(PRUintn numCPUs);
+
+/*
+** Control the method and size of the file descriptor (PRFileDesc*)
+** cache used by the runtime. Setting 'high' to zero is for performance,
+** any other value probably for debugging (see memo on FD caching).
+*/
+NSPR_API(PRStatus) PR_SetFDCacheSize(PRIntn low, PRIntn high);
+
+/*
+ * Cause an immediate, nongraceful, forced termination of the process.
+ * It takes a PRIntn argument, which is the exit status code of the
+ * process.
+ */
+NSPR_API(void) PR_ProcessExit(PRIntn status);
+
+/*
+** Abort the process in a non-graceful manner. This will cause a core file,
+** call to the debugger or other moral equivalent as well as causing the
+** entire process to stop.
+*/
+NSPR_API(void) PR_Abort(void);
+
+/*
+ ****************************************************************
+ *
+ * Module initialization:
+ *
+ ****************************************************************
+ */
+
+typedef struct PRCallOnceType {
+    PRIntn initialized;
+    PRInt32 inProgress;
+    PRStatus status;
+} PRCallOnceType;
+
+typedef PRStatus (PR_CALLBACK *PRCallOnceFN)(void);
+
+typedef PRStatus (PR_CALLBACK *PRCallOnceWithArgFN)(void *arg);
+
+NSPR_API(PRStatus) PR_CallOnce(
+    PRCallOnceType *once,
+    PRCallOnceFN    func
+);
+
+NSPR_API(PRStatus) PR_CallOnceWithArg(
+    PRCallOnceType      *once,
+    PRCallOnceWithArgFN  func,
+    void                *arg
+);
+
+
+PR_END_EXTERN_C
+
+#endif /* prinit_h___ */
diff --git a/pr/include/prinrval.h b/pr/include/prinrval.h
new file mode 100644
index 0000000..14cd39b
--- /dev/null
+++ b/pr/include/prinrval.h
@@ -0,0 +1,146 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** File:		prinrval.h
+** Description:	API to interval timing functions of NSPR.
+**
+**
+** NSPR provides interval times that are independent of network time
+** of day values. Interval times are (in theory) accurate regardless
+** of host processing requirements and also very cheap to acquire. It
+** is expected that getting an interval time while in a synchronized
+** function (holding one's lock).
+**/
+
+#if !defined(prinrval_h)
+#define prinrval_h
+
+#include "prtypes.h"
+
+PR_BEGIN_EXTERN_C
+
+/**********************************************************************/
+/************************* TYPES AND CONSTANTS ************************/
+/**********************************************************************/
+
+typedef PRUint32 PRIntervalTime;
+
+/***********************************************************************
+** DEFINES:     PR_INTERVAL_MIN
+**              PR_INTERVAL_MAX
+** DESCRIPTION:
+**  These two constants define the range (in ticks / second) of the
+**  platform dependent type, PRIntervalTime. These constants bound both
+**  the period and the resolution of a PRIntervalTime. 
+***********************************************************************/
+#define PR_INTERVAL_MIN 1000UL
+#define PR_INTERVAL_MAX 100000UL
+
+/***********************************************************************
+** DEFINES:     PR_INTERVAL_NO_WAIT
+**              PR_INTERVAL_NO_TIMEOUT
+** DESCRIPTION:
+**  Two reserved constants are defined in the PRIntervalTime namespace.
+**  They are used to indicate that the process should wait no time (return
+**  immediately) or wait forever (never time out), respectively.
+**  Note: PR_INTERVAL_NO_TIMEOUT passed as input to PR_Connect is 
+**  interpreted as use the OS's connect timeout.
+**  
+***********************************************************************/
+#define PR_INTERVAL_NO_WAIT 0UL
+#define PR_INTERVAL_NO_TIMEOUT 0xffffffffUL
+
+/**********************************************************************/
+/****************************** FUNCTIONS *****************************/
+/**********************************************************************/
+
+/***********************************************************************
+** FUNCTION:    PR_IntervalNow
+** DESCRIPTION:
+**  Return the value of NSPR's free running interval timer. That timer
+**  can be used to establish epochs and determine intervals (be computing
+**  the difference between two times).
+** INPUTS:      void
+** OUTPUTS:     void
+** RETURN:      PRIntervalTime
+**  
+** SIDE EFFECTS:
+**  None
+** RESTRICTIONS:
+**  The units of PRIntervalTime are platform dependent. They are chosen
+**  such that they are appropriate for the host OS, yet provide sufficient
+**  resolution and period to be useful to clients. 
+** MEMORY:      N/A
+** ALGORITHM:   Platform dependent
+***********************************************************************/
+NSPR_API(PRIntervalTime) PR_IntervalNow(void);
+
+/***********************************************************************
+** FUNCTION:    PR_TicksPerSecond
+** DESCRIPTION:
+**  Return the number of ticks per second for PR_IntervalNow's clock.
+**  The value will be in the range [PR_INTERVAL_MIN..PR_INTERVAL_MAX].
+** INPUTS:      void
+** OUTPUTS:     void
+** RETURN:      PRUint32
+**  
+** SIDE EFFECTS:
+**  None
+** RESTRICTIONS:
+**  None
+** MEMORY:      N/A
+** ALGORITHM:   N/A
+***********************************************************************/
+NSPR_API(PRUint32) PR_TicksPerSecond(void);
+
+/***********************************************************************
+** FUNCTION:    PR_SecondsToInterval
+**              PR_MillisecondsToInterval
+**              PR_MicrosecondsToInterval
+** DESCRIPTION:
+**  Convert standard clock units to platform dependent intervals.
+** INPUTS:      PRUint32
+** OUTPUTS:     void
+** RETURN:      PRIntervalTime
+**  
+** SIDE EFFECTS:
+**  None
+** RESTRICTIONS:
+**  Conversion may cause overflow, which is not reported.
+** MEMORY:      N/A
+** ALGORITHM:   N/A
+***********************************************************************/
+NSPR_API(PRIntervalTime) PR_SecondsToInterval(PRUint32 seconds);
+NSPR_API(PRIntervalTime) PR_MillisecondsToInterval(PRUint32 milli);
+NSPR_API(PRIntervalTime) PR_MicrosecondsToInterval(PRUint32 micro);
+
+/***********************************************************************
+** FUNCTION:    PR_IntervalToSeconds
+**              PR_IntervalToMilliseconds
+**              PR_IntervalToMicroseconds
+** DESCRIPTION:
+**  Convert platform dependent intervals to standard clock units.
+** INPUTS:      PRIntervalTime
+** OUTPUTS:     void
+** RETURN:      PRUint32
+**  
+** SIDE EFFECTS:
+**  None
+** RESTRICTIONS:
+**  Conversion may cause overflow, which is not reported.
+** MEMORY:      N/A
+** ALGORITHM:   N/A
+***********************************************************************/
+NSPR_API(PRUint32) PR_IntervalToSeconds(PRIntervalTime ticks);
+NSPR_API(PRUint32) PR_IntervalToMilliseconds(PRIntervalTime ticks);
+NSPR_API(PRUint32) PR_IntervalToMicroseconds(PRIntervalTime ticks);
+
+PR_END_EXTERN_C
+
+
+#endif /* !defined(prinrval_h) */
+
+/* prinrval.h */
diff --git a/pr/include/prio.h b/pr/include/prio.h
new file mode 100644
index 0000000..a9fcf37
--- /dev/null
+++ b/pr/include/prio.h
@@ -0,0 +1,2022 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+ * File:     prio.h
+ *
+ * Description:    PR i/o related stuff, such as file system access, file
+ *         i/o, socket i/o, etc.
+ */
+
+#ifndef prio_h___
+#define prio_h___
+
+#include "prlong.h"
+#include "prtime.h"
+#include "prinrval.h"
+#include "prinet.h"
+
+PR_BEGIN_EXTERN_C
+
+/* Typedefs */
+typedef struct PRDir            PRDir;
+typedef struct PRDirEntry       PRDirEntry;
+#ifdef MOZ_UNICODE
+typedef struct PRDirUTF16       PRDirUTF16;
+typedef struct PRDirEntryUTF16  PRDirEntryUTF16;
+#endif /* MOZ_UNICODE */
+typedef struct PRFileDesc       PRFileDesc;
+typedef struct PRFileInfo       PRFileInfo;
+typedef struct PRFileInfo64     PRFileInfo64;
+typedef union  PRNetAddr        PRNetAddr;
+typedef struct PRIOMethods      PRIOMethods;
+typedef struct PRPollDesc       PRPollDesc;
+typedef struct PRFilePrivate    PRFilePrivate;
+typedef struct PRSendFileData   PRSendFileData;
+
+/*
+***************************************************************************
+** The file descriptor.
+** This is the primary structure to represent any active open socket,
+** whether it be a normal file or a network connection. Such objects
+** are stackable (or layerable). Each layer may have its own set of
+** method pointers and context private to that layer. All each layer
+** knows about its neighbors is how to get to their method table.
+***************************************************************************
+*/
+
+typedef PRIntn PRDescIdentity;          /* see: Layering file descriptors */
+
+struct PRFileDesc {
+    const PRIOMethods *methods;         /* the I/O methods table */
+    PRFilePrivate *secret;              /* layer dependent data */
+    PRFileDesc *lower, *higher;         /* pointers to adjacent layers */
+    void (PR_CALLBACK *dtor)(PRFileDesc *fd);
+                                        /* A destructor function for layer */
+    PRDescIdentity identity;            /* Identity of this particular layer  */
+};
+
+/*
+***************************************************************************
+** PRTransmitFileFlags
+**
+** Flags for PR_TransmitFile.  Pass PR_TRANSMITFILE_CLOSE_SOCKET to
+** PR_TransmitFile if the connection should be closed after the file
+** is transmitted.
+***************************************************************************
+*/
+typedef enum PRTransmitFileFlags {
+    PR_TRANSMITFILE_KEEP_OPEN = 0,    /* socket is left open after file
+                                       * is transmitted. */
+    PR_TRANSMITFILE_CLOSE_SOCKET = 1  /* socket is closed after file
+                                       * is transmitted. */
+} PRTransmitFileFlags;
+
+/*
+**************************************************************************
+** Macros for PRNetAddr
+**
+** Address families: PR_AF_INET, PR_AF_INET6, PR_AF_LOCAL
+** IP addresses: PR_INADDR_ANY, PR_INADDR_LOOPBACK, PR_INADDR_BROADCAST
+**************************************************************************
+*/
+
+#ifdef WIN32
+
+#define PR_AF_INET 2
+#define PR_AF_LOCAL 1
+#define PR_INADDR_ANY (unsigned long)0x00000000
+#define PR_INADDR_LOOPBACK 0x7f000001
+#define PR_INADDR_BROADCAST (unsigned long)0xffffffff
+
+#else /* WIN32 */
+
+#define PR_AF_INET AF_INET
+#define PR_AF_LOCAL AF_UNIX
+#define PR_INADDR_ANY INADDR_ANY
+#define PR_INADDR_LOOPBACK INADDR_LOOPBACK
+#define PR_INADDR_BROADCAST INADDR_BROADCAST
+
+#endif /* WIN32 */
+
+/*
+** Define PR_AF_INET6 in prcpucfg.h with the same
+** value as AF_INET6 on platforms with IPv6 support.
+** Otherwise define it here.
+*/
+#ifndef PR_AF_INET6
+#define PR_AF_INET6 100
+#endif
+
+#define PR_AF_INET_SDP 101
+#define PR_AF_INET6_SDP 102
+
+#ifndef PR_AF_UNSPEC
+#define PR_AF_UNSPEC 0
+#endif
+
+/*
+**************************************************************************
+** A network address
+**
+** Only Internet Protocol (IPv4 and IPv6) addresses are supported.
+** The address family must always represent IPv4 (AF_INET, probably == 2)
+** or IPv6 (AF_INET6).
+**************************************************************************
+*************************************************************************/
+
+struct PRIPv6Addr {
+	union {
+		PRUint8  _S6_u8[16];
+		PRUint16 _S6_u16[8];
+		PRUint32 _S6_u32[4];
+		PRUint64 _S6_u64[2];
+	} _S6_un;
+};
+#define pr_s6_addr		_S6_un._S6_u8
+#define pr_s6_addr16	_S6_un._S6_u16
+#define pr_s6_addr32	_S6_un._S6_u32
+#define pr_s6_addr64 	_S6_un._S6_u64
+
+typedef struct PRIPv6Addr PRIPv6Addr;
+
+union PRNetAddr {
+    struct {
+        PRUint16 family;                /* address family (0x00ff maskable) */
+#ifdef XP_BEOS
+        char data[10];                  /* Be has a smaller structure */
+#else
+        char data[14];                  /* raw address data */
+#endif
+    } raw;
+    struct {
+        PRUint16 family;                /* address family (AF_INET) */
+        PRUint16 port;                  /* port number */
+        PRUint32 ip;                    /* The actual 32 bits of address */
+#ifdef XP_BEOS
+        char pad[4];                    /* Be has a smaller structure */
+#else
+        char pad[8];
+#endif
+    } inet;
+    struct {
+        PRUint16 family;                /* address family (AF_INET6) */
+        PRUint16 port;                  /* port number */
+        PRUint32 flowinfo;              /* routing information */
+        PRIPv6Addr ip;                  /* the actual 128 bits of address */
+        PRUint32 scope_id;              /* set of interfaces for a scope */
+    } ipv6;
+#if defined(XP_UNIX) || defined(XP_OS2)
+    struct {                            /* Unix domain socket address */
+        PRUint16 family;                /* address family (AF_UNIX) */
+#ifdef XP_OS2
+        char path[108];                 /* null-terminated pathname */
+                                        /* bind fails if size is not 108. */
+#else
+        char path[104];                 /* null-terminated pathname */
+#endif
+    } local;
+#endif
+};
+
+/*
+***************************************************************************
+** PRSockOption
+**
+** The file descriptors can have predefined options set after they file
+** descriptor is created to change their behavior. Only the options in
+** the following enumeration are supported.
+***************************************************************************
+*/
+typedef enum PRSockOption
+{
+    PR_SockOpt_Nonblocking,     /* nonblocking io */
+    PR_SockOpt_Linger,          /* linger on close if data present */
+    PR_SockOpt_Reuseaddr,       /* allow local address reuse */
+    PR_SockOpt_Keepalive,       /* keep connections alive */
+    PR_SockOpt_RecvBufferSize,  /* receive buffer size */
+    PR_SockOpt_SendBufferSize,  /* send buffer size */
+
+    PR_SockOpt_IpTimeToLive,    /* time to live */
+    PR_SockOpt_IpTypeOfService, /* type of service and precedence */
+
+    PR_SockOpt_AddMember,       /* add an IP group membership */
+    PR_SockOpt_DropMember,      /* drop an IP group membership */
+    PR_SockOpt_McastInterface,  /* multicast interface address */
+    PR_SockOpt_McastTimeToLive, /* multicast timetolive */
+    PR_SockOpt_McastLoopback,   /* multicast loopback */
+
+    PR_SockOpt_NoDelay,         /* don't delay send to coalesce packets */
+    PR_SockOpt_MaxSegment,      /* maximum segment size */
+    PR_SockOpt_Broadcast,       /* enable broadcast */
+    PR_SockOpt_Reuseport,       /* allow local address & port reuse on
+                                 * platforms that support it */
+    PR_SockOpt_Last
+} PRSockOption;
+
+typedef struct PRLinger {
+	PRBool polarity;		    /* Polarity of the option's setting */
+	PRIntervalTime linger;	    /* Time to linger before closing */
+} PRLinger;
+
+typedef struct PRMcastRequest {
+	PRNetAddr mcaddr;			/* IP multicast address of group */
+	PRNetAddr ifaddr;			/* local IP address of interface */
+} PRMcastRequest;
+
+typedef struct PRSocketOptionData
+{
+    PRSockOption option;
+    union
+    {
+        PRUintn ip_ttl;             /* IP time to live */
+        PRUintn mcast_ttl;          /* IP multicast time to live */
+        PRUintn tos;                /* IP type of service and precedence */
+        PRBool non_blocking;        /* Non-blocking (network) I/O */
+        PRBool reuse_addr;          /* Allow local address reuse */
+        PRBool reuse_port;          /* Allow local address & port reuse on
+                                     * platforms that support it */
+        PRBool keep_alive;          /* Keep connections alive */
+        PRBool mcast_loopback;      /* IP multicast loopback */
+        PRBool no_delay;            /* Don't delay send to coalesce packets */
+        PRBool broadcast;           /* Enable broadcast */
+        PRSize max_segment;         /* Maximum segment size */
+        PRSize recv_buffer_size;    /* Receive buffer size */
+        PRSize send_buffer_size;    /* Send buffer size */
+        PRLinger linger;            /* Time to linger on close if data present */
+        PRMcastRequest add_member;  /* add an IP group membership */
+        PRMcastRequest drop_member; /* Drop an IP group membership */
+        PRNetAddr mcast_if;         /* multicast interface address */
+    } value;
+} PRSocketOptionData;
+
+/*
+***************************************************************************
+** PRIOVec
+**
+** The I/O vector is used by the write vector method to describe the areas
+** that are affected by the ouput operation.
+***************************************************************************
+*/
+typedef struct PRIOVec {
+    char *iov_base;
+    int iov_len;
+} PRIOVec;
+
+/*
+***************************************************************************
+** Discover what type of socket is being described by the file descriptor.
+***************************************************************************
+*/
+typedef enum PRDescType
+{
+    PR_DESC_FILE = 1,
+    PR_DESC_SOCKET_TCP = 2,
+    PR_DESC_SOCKET_UDP = 3,
+    PR_DESC_LAYERED = 4,
+    PR_DESC_PIPE = 5
+} PRDescType;
+
+typedef enum PRSeekWhence {
+    PR_SEEK_SET = 0,
+    PR_SEEK_CUR = 1,
+    PR_SEEK_END = 2
+} PRSeekWhence;
+
+NSPR_API(PRDescType) PR_GetDescType(PRFileDesc *file);
+
+/*
+***************************************************************************
+** PRIOMethods
+**
+** The I/O methods table provides procedural access to the functions of
+** the file descriptor. It is the responsibility of a layer implementor
+** to provide suitable functions at every entry point. If a layer provides
+** no functionality, it should call the next lower(higher) function of the
+** same name (e.g., return fd->lower->method->close(fd->lower));
+**
+** Not all functions are implemented for all types of files. In cases where
+** that is true, the function will return a error indication with an error
+** code of PR_INVALID_METHOD_ERROR.
+***************************************************************************
+*/
+
+typedef PRStatus (PR_CALLBACK *PRCloseFN)(PRFileDesc *fd);
+typedef PRInt32 (PR_CALLBACK *PRReadFN)(PRFileDesc *fd, void *buf, PRInt32 amount);
+typedef PRInt32 (PR_CALLBACK *PRWriteFN)(PRFileDesc *fd, const void *buf, PRInt32 amount);
+typedef PRInt32 (PR_CALLBACK *PRAvailableFN)(PRFileDesc *fd);
+typedef PRInt64 (PR_CALLBACK *PRAvailable64FN)(PRFileDesc *fd);
+typedef PRStatus (PR_CALLBACK *PRFsyncFN)(PRFileDesc *fd);
+typedef PROffset32 (PR_CALLBACK *PRSeekFN)(PRFileDesc *fd, PROffset32 offset, PRSeekWhence how);
+typedef PROffset64 (PR_CALLBACK *PRSeek64FN)(PRFileDesc *fd, PROffset64 offset, PRSeekWhence how);
+typedef PRStatus (PR_CALLBACK *PRFileInfoFN)(PRFileDesc *fd, PRFileInfo *info);
+typedef PRStatus (PR_CALLBACK *PRFileInfo64FN)(PRFileDesc *fd, PRFileInfo64 *info);
+typedef PRInt32 (PR_CALLBACK *PRWritevFN)(
+    PRFileDesc *fd, const PRIOVec *iov, PRInt32 iov_size,
+    PRIntervalTime timeout);
+typedef PRStatus (PR_CALLBACK *PRConnectFN)(
+    PRFileDesc *fd, const PRNetAddr *addr, PRIntervalTime timeout);
+typedef PRFileDesc* (PR_CALLBACK *PRAcceptFN) (
+    PRFileDesc *fd, PRNetAddr *addr, PRIntervalTime timeout);
+typedef PRStatus (PR_CALLBACK *PRBindFN)(PRFileDesc *fd, const PRNetAddr *addr);
+typedef PRStatus (PR_CALLBACK *PRListenFN)(PRFileDesc *fd, PRIntn backlog);
+typedef PRStatus (PR_CALLBACK *PRShutdownFN)(PRFileDesc *fd, PRIntn how);
+typedef PRInt32 (PR_CALLBACK *PRRecvFN)(
+    PRFileDesc *fd, void *buf, PRInt32 amount,
+    PRIntn flags, PRIntervalTime timeout);
+typedef PRInt32 (PR_CALLBACK *PRSendFN) (
+    PRFileDesc *fd, const void *buf, PRInt32 amount,
+    PRIntn flags, PRIntervalTime timeout);
+typedef PRInt32 (PR_CALLBACK *PRRecvfromFN)(
+    PRFileDesc *fd, void *buf, PRInt32 amount,
+    PRIntn flags, PRNetAddr *addr, PRIntervalTime timeout);
+typedef PRInt32 (PR_CALLBACK *PRSendtoFN)(
+    PRFileDesc *fd, const void *buf, PRInt32 amount,
+    PRIntn flags, const PRNetAddr *addr, PRIntervalTime timeout);
+typedef PRInt16 (PR_CALLBACK *PRPollFN)(
+    PRFileDesc *fd, PRInt16 in_flags, PRInt16 *out_flags);
+typedef PRInt32 (PR_CALLBACK *PRAcceptreadFN)(
+    PRFileDesc *sd, PRFileDesc **nd, PRNetAddr **raddr,
+    void *buf, PRInt32 amount, PRIntervalTime t);
+typedef PRInt32 (PR_CALLBACK *PRTransmitfileFN)(
+     PRFileDesc *sd, PRFileDesc *fd, const void *headers,
+     PRInt32 hlen, PRTransmitFileFlags flags, PRIntervalTime t);
+typedef PRStatus (PR_CALLBACK *PRGetsocknameFN)(PRFileDesc *fd, PRNetAddr *addr);
+typedef PRStatus (PR_CALLBACK *PRGetpeernameFN)(PRFileDesc *fd, PRNetAddr *addr);
+typedef PRStatus (PR_CALLBACK *PRGetsocketoptionFN)(
+    PRFileDesc *fd, PRSocketOptionData *data);
+typedef PRStatus (PR_CALLBACK *PRSetsocketoptionFN)(
+    PRFileDesc *fd, const PRSocketOptionData *data);
+typedef PRInt32 (PR_CALLBACK *PRSendfileFN)(
+	PRFileDesc *networkSocket, PRSendFileData *sendData,
+	PRTransmitFileFlags flags, PRIntervalTime timeout);
+typedef PRStatus (PR_CALLBACK *PRConnectcontinueFN)(
+    PRFileDesc *fd, PRInt16 out_flags);
+typedef PRIntn (PR_CALLBACK *PRReservedFN)(PRFileDesc *fd);
+
+struct PRIOMethods {
+    PRDescType file_type;           /* Type of file represented (tos)           */
+    PRCloseFN close;                /* close file and destroy descriptor        */
+    PRReadFN read;                  /* read up to specified bytes into buffer   */
+    PRWriteFN write;                /* write specified bytes from buffer        */
+    PRAvailableFN available;        /* determine number of bytes available      */
+    PRAvailable64FN available64;    /*          ditto, 64 bit                   */
+    PRFsyncFN fsync;                /* flush all buffers to permanent store     */
+    PRSeekFN seek;                  /* position the file to the desired place   */
+    PRSeek64FN seek64;              /*           ditto, 64 bit                  */
+    PRFileInfoFN fileInfo;          /* Get information about an open file       */
+    PRFileInfo64FN fileInfo64;      /*           ditto, 64 bit                  */
+    PRWritevFN writev;              /* Write segments as described by iovector  */
+    PRConnectFN connect;            /* Connect to the specified (net) address   */
+    PRAcceptFN accept;              /* Accept a connection for a (net) peer     */
+    PRBindFN bind;                  /* Associate a (net) address with the fd    */
+    PRListenFN listen;              /* Prepare to listen for (net) connections  */
+    PRShutdownFN shutdown;          /* Shutdown a (net) connection              */
+    PRRecvFN recv;                  /* Solicit up the the specified bytes       */
+    PRSendFN send;                  /* Send all the bytes specified             */
+    PRRecvfromFN recvfrom;          /* Solicit (net) bytes and report source    */
+    PRSendtoFN sendto;              /* Send bytes to (net) address specified    */
+    PRPollFN poll;                  /* Test the fd to see if it is ready        */
+    PRAcceptreadFN acceptread;      /* Accept and read on a new (net) fd        */
+    PRTransmitfileFN transmitfile;  /* Transmit at entire file                  */
+    PRGetsocknameFN getsockname;    /* Get (net) address associated with fd     */
+    PRGetpeernameFN getpeername;    /* Get peer's (net) address                 */
+    PRReservedFN reserved_fn_6;     /* reserved for future use */
+    PRReservedFN reserved_fn_5;     /* reserved for future use */
+    PRGetsocketoptionFN getsocketoption;
+                                    /* Get current setting of specified option  */
+    PRSetsocketoptionFN setsocketoption;
+                                    /* Set value of specified option            */
+    PRSendfileFN sendfile;			/* Send a (partial) file with header/trailer*/
+    PRConnectcontinueFN connectcontinue;
+                                    /* Continue a nonblocking connect */
+    PRReservedFN reserved_fn_3;		/* reserved for future use */
+    PRReservedFN reserved_fn_2;		/* reserved for future use */
+    PRReservedFN reserved_fn_1;		/* reserved for future use */
+    PRReservedFN reserved_fn_0;		/* reserved for future use */
+};
+
+/*
+ **************************************************************************
+ * FUNCTION: PR_GetSpecialFD
+ * DESCRIPTION: Get the file descriptor that represents the standard input,
+ *              output, or error stream.
+ * INPUTS:
+ *     PRSpecialFD id
+ *         A value indicating the type of stream desired:
+ *             PR_StandardInput: standard input
+ *             PR_StandardOuput: standard output
+ *             PR_StandardError: standard error
+ * OUTPUTS: none
+ * RETURNS: PRFileDesc *
+ *     If the argument is valid, PR_GetSpecialFD returns a file descriptor
+ *     that represents the corresponding standard I/O stream.  Otherwise,
+ *     PR_GetSpecialFD returns NULL and sets error PR_INVALID_ARGUMENT_ERROR.
+ **************************************************************************
+ */
+
+typedef enum PRSpecialFD
+{
+    PR_StandardInput,          /* standard input */
+    PR_StandardOutput,         /* standard output */
+    PR_StandardError           /* standard error */
+} PRSpecialFD;
+
+NSPR_API(PRFileDesc*) PR_GetSpecialFD(PRSpecialFD id);
+
+#define PR_STDIN	PR_GetSpecialFD(PR_StandardInput)
+#define PR_STDOUT	PR_GetSpecialFD(PR_StandardOutput)
+#define PR_STDERR	PR_GetSpecialFD(PR_StandardError)
+
+/*
+ **************************************************************************
+ * Layering file descriptors
+ *
+ * File descriptors may be layered. Each layer has it's own identity.
+ * Identities are allocated by the runtime and are to be associated
+ * (by the layer implementor) with all layers that are of that type.
+ * It is then possible to scan the chain of layers and find a layer
+ * that one recongizes and therefore predict that it will implement
+ * a desired protocol.
+ *
+ * There are three well-known identities:
+ *      PR_INVALID_IO_LAYER => an invalid layer identity, for error return
+ *      PR_TOP_IO_LAYER     => the identity of the top of the stack
+ *      PR_NSPR_IO_LAYER    => the identity used by NSPR proper
+ * PR_TOP_IO_LAYER may be used as a shorthand for identifying the topmost
+ * layer of an existing stack. Ie., the following two constructs are
+ * equivalent.
+ *
+ *      rv = PR_PushIOLayer(stack, PR_TOP_IO_LAYER, my_layer);
+ *      rv = PR_PushIOLayer(stack, PR_GetLayersIdentity(stack), my_layer)
+ *
+ * A string may be associated with the creation of the identity. It
+ * will be copied by the runtime. If queried the runtime will return
+ * a reference to that copied string (not yet another copy). There
+ * is no facility for deleting an identity.
+ **************************************************************************
+ */
+
+#define PR_IO_LAYER_HEAD (PRDescIdentity)-3
+#define PR_INVALID_IO_LAYER (PRDescIdentity)-1
+#define PR_TOP_IO_LAYER (PRDescIdentity)-2
+#define PR_NSPR_IO_LAYER (PRDescIdentity)0
+
+NSPR_API(PRDescIdentity) PR_GetUniqueIdentity(const char *layer_name);
+NSPR_API(const char*) PR_GetNameForIdentity(PRDescIdentity ident);
+NSPR_API(PRDescIdentity) PR_GetLayersIdentity(PRFileDesc* fd);
+NSPR_API(PRFileDesc*) PR_GetIdentitiesLayer(PRFileDesc* fd_stack, PRDescIdentity id);
+
+/*
+ **************************************************************************
+ * PR_GetDefaultIOMethods: Accessing the default methods table.
+ * You may get a pointer to the default methods table by calling this function.
+ * You may then select any elements from that table with which to build your
+ * layer's methods table. You may NOT modify the table directly.
+ **************************************************************************
+ */
+NSPR_API(const PRIOMethods *) PR_GetDefaultIOMethods(void);
+
+/*
+ **************************************************************************
+ * Creating a layer
+ *
+ * A new layer may be allocated by calling PR_CreateIOLayerStub(). The
+ * file descriptor returned will contain the pointer to the methods table
+ * provided. The runtime will not modify the table nor test its correctness.
+ **************************************************************************
+ */
+NSPR_API(PRFileDesc*) PR_CreateIOLayerStub(
+    PRDescIdentity ident, const PRIOMethods *methods);
+
+/*
+ **************************************************************************
+ * Creating a layer
+ *
+ * A new stack may be created by calling PR_CreateIOLayer(). The
+ * file descriptor returned will point to the top of the stack, which has
+ * the layer 'fd' as the topmost layer.
+ * 
+ * NOTE: This function creates a new style stack, which has a fixed, dummy
+ * header. The old style stack, created by a call to PR_PushIOLayer,
+ * results in modifying contents of the top layer of the stack, when
+ * pushing and popping layers of the stack.
+ **************************************************************************
+ */
+NSPR_API(PRFileDesc*) PR_CreateIOLayer(PRFileDesc* fd);
+
+/*
+ **************************************************************************
+ * Pushing a layer
+ *
+ * A file descriptor (perhaps allocated using PR_CreateIOLayerStub()) may
+ * be pushed into an existing stack of file descriptors at any point the
+ * caller deems appropriate. The new layer will be inserted into the stack
+ * just above the layer with the indicated identity.
+ *
+ * Note: Even if the identity parameter indicates the top-most layer of
+ * the stack, the value of the file descriptor describing the original
+ * stack will not change.
+ **************************************************************************
+ */
+NSPR_API(PRStatus) PR_PushIOLayer(
+    PRFileDesc *fd_stack, PRDescIdentity id, PRFileDesc *layer);
+
+/*
+ **************************************************************************
+ * Popping a layer
+ *
+ * A layer may be popped from a stack by indicating the identity of the
+ * layer to be removed. If found, a pointer to the removed object will
+ * be returned to the caller. The object then becomes the responsibility
+ * of the caller.
+ *
+ * Note: Even if the identity indicates the top layer of the stack, the
+ * reference returned will not be the file descriptor for the stack and
+ * that file descriptor will remain valid.
+ **************************************************************************
+ */
+NSPR_API(PRFileDesc*) PR_PopIOLayer(PRFileDesc *fd_stack, PRDescIdentity id);
+
+/*
+ **************************************************************************
+ * FUNCTION:    PR_Open
+ * DESCRIPTION:    Open a file for reading, writing, or both.
+ * INPUTS:
+ *     const char *name
+ *         The path name of the file to be opened
+ *     PRIntn flags
+ *         The file status flags.
+ *         It is a bitwise OR of the following bit flags (only one of
+ *         the first three flags below may be used):
+ *		PR_RDONLY        Open for reading only.
+ *		PR_WRONLY        Open for writing only.
+ *		PR_RDWR          Open for reading and writing.
+ *		PR_CREATE_FILE   If the file does not exist, the file is created
+ *                              If the file exists, this flag has no effect.
+ *      PR_SYNC          If set, each write will wait for both the file data
+ *                              and file status to be physically updated.
+ *		PR_APPEND        The file pointer is set to the end of
+ *                              the file prior to each write.
+ *		PR_TRUNCATE      If the file exists, its length is truncated to 0.
+ *      PR_EXCL          With PR_CREATE_FILE, if the file does not exist,
+ *                              the file is created. If the file already 
+ *                              exists, no action and NULL is returned
+ *
+ *     PRIntn mode
+ *         The access permission bits of the file mode, if the file is
+ *         created when PR_CREATE_FILE is on.
+ * OUTPUTS:    None
+ * RETURNS:    PRFileDesc *
+ *     If the file is successfully opened,
+ *     returns a pointer to the PRFileDesc
+ *     created for the newly opened file.
+ *     Returns a NULL pointer if the open
+ *     failed.
+ * SIDE EFFECTS:
+ * RESTRICTIONS:
+ * MEMORY:
+ *     The return value, if not NULL, points to a dynamically allocated
+ *     PRFileDesc object.
+ * ALGORITHM:
+ **************************************************************************
+ */
+
+/* Open flags */
+#define PR_RDONLY       0x01
+#define PR_WRONLY       0x02
+#define PR_RDWR         0x04
+#define PR_CREATE_FILE  0x08
+#define PR_APPEND       0x10
+#define PR_TRUNCATE     0x20
+#define PR_SYNC         0x40
+#define PR_EXCL         0x80
+
+/*
+** File modes ....
+**
+** CAVEAT: 'mode' is currently only applicable on UNIX platforms.
+** The 'mode' argument may be ignored by PR_Open on other platforms.
+**
+**   00400   Read by owner.
+**   00200   Write by owner.
+**   00100   Execute (search if a directory) by owner.
+**   00040   Read by group.
+**   00020   Write by group.
+**   00010   Execute by group.
+**   00004   Read by others.
+**   00002   Write by others
+**   00001   Execute by others.
+**
+*/
+
+NSPR_API(PRFileDesc*) PR_Open(const char *name, PRIntn flags, PRIntn mode);
+
+/*
+ **************************************************************************
+ * FUNCTION: PR_OpenFile
+ * DESCRIPTION:
+ *     Open a file for reading, writing, or both.
+ *     PR_OpenFile has the same prototype as PR_Open but implements
+ *     the specified file mode where possible.
+ **************************************************************************
+ */
+
+/* File mode bits */
+#define PR_IRWXU 00700  /* read, write, execute/search by owner */
+#define PR_IRUSR 00400  /* read permission, owner */
+#define PR_IWUSR 00200  /* write permission, owner */
+#define PR_IXUSR 00100  /* execute/search permission, owner */
+#define PR_IRWXG 00070  /* read, write, execute/search by group */
+#define PR_IRGRP 00040  /* read permission, group */
+#define PR_IWGRP 00020  /* write permission, group */
+#define PR_IXGRP 00010  /* execute/search permission, group */
+#define PR_IRWXO 00007  /* read, write, execute/search by others */
+#define PR_IROTH 00004  /* read permission, others */
+#define PR_IWOTH 00002  /* write permission, others */
+#define PR_IXOTH 00001  /* execute/search permission, others */
+
+NSPR_API(PRFileDesc*) PR_OpenFile(
+    const char *name, PRIntn flags, PRIntn mode);
+
+#ifdef MOZ_UNICODE
+/*
+ * EXPERIMENTAL: This function may be removed in a future release.
+ */
+NSPR_API(PRFileDesc*) PR_OpenFileUTF16(
+    const PRUnichar *name, PRIntn flags, PRIntn mode);
+#endif /* MOZ_UNICODE */
+
+/*
+ **************************************************************************
+ * FUNCTION: PR_Close
+ * DESCRIPTION:
+ *     Close a file or socket.
+ * INPUTS:
+ *     PRFileDesc *fd
+ *         a pointer to a PRFileDesc.
+ * OUTPUTS:
+ *     None.
+ * RETURN:
+ *     PRStatus
+ * SIDE EFFECTS:
+ * RESTRICTIONS:
+ *     None.
+ * MEMORY:
+ *     The dynamic memory pointed to by the argument fd is freed.
+ **************************************************************************
+ */
+
+NSPR_API(PRStatus)    PR_Close(PRFileDesc *fd);
+
+/*
+ **************************************************************************
+ * FUNCTION: PR_Read
+ * DESCRIPTION:
+ *     Read bytes from a file or socket.
+ *     The operation will block until either an end of stream indication is
+ *     encountered, some positive number of bytes are transferred, or there
+ *     is an error. No more than 'amount' bytes will be transferred.
+ * INPUTS:
+ *     PRFileDesc *fd
+ *         pointer to the PRFileDesc object for the file or socket
+ *     void *buf
+ *         pointer to a buffer to hold the data read in.
+ *     PRInt32 amount
+ *         the size of 'buf' (in bytes)
+ * OUTPUTS:
+ * RETURN:
+ *     PRInt32
+ *         a positive number indicates the number of bytes actually read in.
+ *         0 means end of file is reached or the network connection is closed.
+ *         -1 indicates a failure. The reason for the failure is obtained
+ *         by calling PR_GetError().
+ * SIDE EFFECTS:
+ *     data is written into the buffer pointed to by 'buf'.
+ * RESTRICTIONS:
+ *     None.
+ * MEMORY:
+ *     N/A
+ * ALGORITHM:
+ *     N/A
+ **************************************************************************
+ */
+
+NSPR_API(PRInt32) PR_Read(PRFileDesc *fd, void *buf, PRInt32 amount);
+
+/*
+ ***************************************************************************
+ * FUNCTION: PR_Write
+ * DESCRIPTION:
+ *     Write a specified number of bytes to a file or socket.  The thread
+ *     invoking this function blocks until all the data is written.
+ * INPUTS:
+ *     PRFileDesc *fd
+ *         pointer to a PRFileDesc object that refers to a file or socket
+ *     const void *buf
+ *         pointer to the buffer holding the data
+ *     PRInt32 amount
+ *         amount of data in bytes to be written from the buffer
+ * OUTPUTS:
+ *     None.
+ * RETURN: PRInt32
+ *     A positive number indicates the number of bytes successfully written.
+ *     A -1 is an indication that the operation failed. The reason
+ *     for the failure is obtained by calling PR_GetError().
+ ***************************************************************************
+ */
+
+NSPR_API(PRInt32) PR_Write(PRFileDesc *fd,const void *buf,PRInt32 amount);
+
+/*
+ ***************************************************************************
+ * FUNCTION: PR_Writev
+ * DESCRIPTION:
+ *     Write data to a socket.  The data is organized in a PRIOVec array. The
+ *     operation will block until all the data is written or the operation
+ *     fails.
+ * INPUTS:
+ *     PRFileDesc *fd
+ *         Pointer that points to a PRFileDesc object for a socket.
+ *     const PRIOVec *iov
+ *         An array of PRIOVec.  PRIOVec is a struct with the following
+ *         two fields:
+ *             char *iov_base;
+ *             int iov_len;
+ *     PRInt32 iov_size
+ *         Number of elements in the iov array. The value of this
+ *         argument must not be greater than PR_MAX_IOVECTOR_SIZE.
+ *         If it is, the method will fail (PR_BUFFER_OVERFLOW_ERROR).
+ *     PRIntervalTime timeout
+ *       Time limit for completion of the entire write operation.
+ * OUTPUTS:
+ *     None
+ * RETURN:
+ *     A positive number indicates the number of bytes successfully written.
+ *     A -1 is an indication that the operation failed. The reason
+ *     for the failure is obtained by calling PR_GetError().
+ ***************************************************************************
+ */
+
+#define PR_MAX_IOVECTOR_SIZE 16   /* 'iov_size' must be <= */
+
+NSPR_API(PRInt32) PR_Writev(
+    PRFileDesc *fd, const PRIOVec *iov, PRInt32 iov_size,
+    PRIntervalTime timeout);
+
+/*
+ ***************************************************************************
+ * FUNCTION: PR_Delete
+ * DESCRIPTION:
+ *     Delete a file from the filesystem. The operation may fail if the
+ *     file is open.
+ * INPUTS:
+ *     const char *name
+ *         Path name of the file to be deleted.
+ * OUTPUTS:
+ *     None.
+ * RETURN: PRStatus
+ *     The function returns PR_SUCCESS if the file is successfully
+ *     deleted, otherwise it returns PR_FAILURE.
+ ***************************************************************************
+ */
+
+NSPR_API(PRStatus) PR_Delete(const char *name);
+
+/**************************************************************************/
+
+typedef enum PRFileType
+{
+    PR_FILE_FILE = 1,
+    PR_FILE_DIRECTORY = 2,
+    PR_FILE_OTHER = 3
+} PRFileType;
+
+struct PRFileInfo {
+    PRFileType type;        /* Type of file */
+    PROffset32 size;        /* Size, in bytes, of file's contents */
+    PRTime creationTime;    /* Creation time per definition of PRTime */
+    PRTime modifyTime;      /* Last modification time per definition of PRTime */
+};
+
+struct PRFileInfo64 {
+    PRFileType type;        /* Type of file */
+    PROffset64 size;        /* Size, in bytes, of file's contents */
+    PRTime creationTime;    /* Creation time per definition of PRTime */
+    PRTime modifyTime;      /* Last modification time per definition of PRTime */
+};
+
+/****************************************************************************
+ * FUNCTION: PR_GetFileInfo, PR_GetFileInfo64
+ * DESCRIPTION:
+ *     Get the information about the file with the given path name. This is
+ *     applicable only to NSFileDesc describing 'file' types (see
+ * INPUTS:
+ *     const char *fn
+ *         path name of the file
+ * OUTPUTS:
+ *     PRFileInfo *info
+ *         Information about the given file is written into the file
+ *         information object pointer to by 'info'.
+ * RETURN: PRStatus
+ *     PR_GetFileInfo returns PR_SUCCESS if file information is successfully
+ *     obtained, otherwise it returns PR_FAILURE.
+ ***************************************************************************
+ */
+
+NSPR_API(PRStatus) PR_GetFileInfo(const char *fn, PRFileInfo *info);
+NSPR_API(PRStatus) PR_GetFileInfo64(const char *fn, PRFileInfo64 *info);
+
+#ifdef MOZ_UNICODE
+/*
+ * EXPERIMENTAL: This function may be removed in a future release.
+ */
+NSPR_API(PRStatus) PR_GetFileInfo64UTF16(const PRUnichar *fn, PRFileInfo64 *info);
+#endif /* MOZ_UNICODE */
+
+/*
+ **************************************************************************
+ * FUNCTION: PR_GetOpenFileInfo, PR_GetOpenFileInfo64
+ * DESCRIPTION:
+ *     Get information about an open file referred to by the
+ *     given PRFileDesc object.
+ * INPUTS:
+ *     const PRFileDesc *fd
+ *          A reference to a valid, open file.
+ * OUTPUTS:
+ *     Same as PR_GetFileInfo, PR_GetFileInfo64
+ * RETURN: PRStatus
+ *     PR_GetFileInfo returns PR_SUCCESS if file information is successfully
+ *     obtained, otherwise it returns PR_FAILURE.
+ ***************************************************************************
+ */
+
+NSPR_API(PRStatus) PR_GetOpenFileInfo(PRFileDesc *fd, PRFileInfo *info);
+NSPR_API(PRStatus) PR_GetOpenFileInfo64(PRFileDesc *fd, PRFileInfo64 *info);
+
+/*
+ **************************************************************************
+ * FUNCTION: PR_Rename
+ * DESCRIPTION:
+ *     Rename a file from the old name 'from' to the new name 'to'.
+ * INPUTS:
+ *     const char *from
+ *         The old name of the file to be renamed.
+ *     const char *to
+ *         The new name of the file.
+ * OUTPUTS:
+ *     None.
+ * RETURN: PRStatus
+ **************************************************************************
+ */
+
+NSPR_API(PRStatus)    PR_Rename(const char *from, const char *to);
+
+/*
+ *************************************************************************
+ * FUNCTION: PR_Access
+ * DESCRIPTION:
+ *     Determine accessibility of a file.
+ * INPUTS:
+ *     const char *name
+ *         path name of the file
+ *     PRAccessHow how
+ *         specifies which access permission to check for.
+ *         It can be one of the following values:
+ *             PR_ACCESS_READ_OK       Test for read permission
+ *             PR_ACCESS_WRITE_OK      Test for write permission
+ *             PR_ACCESS_EXISTS        Check existence of file
+ * OUTPUTS:
+ *     None.
+ * RETURN: PRStatus
+ *     PR_SUCCESS is returned if the requested access is permitted.
+ *     Otherwise, PR_FAILURE is returned. Additional information
+ *     regarding the reason for the failure may be retrieved from
+ *     PR_GetError().
+ *************************************************************************
+ */
+
+typedef enum PRAccessHow {
+    PR_ACCESS_EXISTS = 1,
+    PR_ACCESS_WRITE_OK = 2,
+    PR_ACCESS_READ_OK = 3
+} PRAccessHow;
+
+NSPR_API(PRStatus) PR_Access(const char *name, PRAccessHow how);
+
+/*
+ *************************************************************************
+ * FUNCTION: PR_Seek, PR_Seek64
+ * DESCRIPTION:
+ *     Moves read-write file offset
+ * INPUTS:
+ *     PRFileDesc *fd
+ *         Pointer to a PRFileDesc object.
+ *     PROffset32, PROffset64 offset
+ *         Specifies a value, in bytes, that is used in conjunction
+ *         with the 'whence' parameter to set the file pointer.  A
+ *         negative value causes seeking in the reverse direction.
+ *     PRSeekWhence whence
+ *         Specifies how to interpret the 'offset' parameter in setting
+ *         the file pointer associated with the 'fd' parameter.
+ *         Values for the 'whence' parameter are:
+ *             PR_SEEK_SET  Sets the file pointer to the value of the
+ *                          'offset' parameter
+ *             PR_SEEK_CUR  Sets the file pointer to its current location
+ *                          plus the value of the offset parameter.
+ *             PR_SEEK_END  Sets the file pointer to the size of the
+ *                          file plus the value of the offset parameter.
+ * OUTPUTS:
+ *     None.
+ * RETURN: PROffset32, PROffset64
+ *     Upon successful completion, the resulting pointer location,
+ *     measured in bytes from the beginning of the file, is returned.
+ *     If the PR_Seek() function fails, the file offset remains
+ *     unchanged, and the returned value is -1. The error code can
+ *     then be retrieved via PR_GetError().
+ *************************************************************************
+ */
+
+NSPR_API(PROffset32) PR_Seek(PRFileDesc *fd, PROffset32 offset, PRSeekWhence whence);
+NSPR_API(PROffset64) PR_Seek64(PRFileDesc *fd, PROffset64 offset, PRSeekWhence whence);
+
+/*
+ ************************************************************************
+ * FUNCTION: PR_Available
+ * DESCRIPTION:
+ *     Determine the amount of data in bytes available for reading
+ *     in the given file or socket.
+ * INPUTS:
+ *     PRFileDesc *fd
+ *         Pointer to a PRFileDesc object that refers to a file or
+ *         socket.
+ * OUTPUTS:
+ *     None
+ * RETURN: PRInt32, PRInt64
+ *     Upon successful completion, PR_Available returns the number of
+ *     bytes beyond the current read pointer that is available for
+ *     reading.  Otherwise, it returns a -1 and the reason for the
+ *     failure can be retrieved via PR_GetError().
+ ************************************************************************
+ */
+
+NSPR_API(PRInt32) PR_Available(PRFileDesc *fd);
+NSPR_API(PRInt64) PR_Available64(PRFileDesc *fd);
+
+/*
+ ************************************************************************
+ * FUNCTION: PR_Sync
+ * DESCRIPTION:
+ *     Sync any buffered data for a fd to its backing device (disk).
+ * INPUTS:
+ *     PRFileDesc *fd
+ *         Pointer to a PRFileDesc object that refers to a file or
+ *         socket
+ * OUTPUTS:
+ *     None
+ * RETURN: PRStatus
+ *     PR_SUCCESS is returned if the requested access is permitted.
+ *     Otherwise, PR_FAILURE is returned.
+ ************************************************************************
+ */
+
+NSPR_API(PRStatus)	PR_Sync(PRFileDesc *fd);
+
+/************************************************************************/
+
+struct PRDirEntry {
+    const char *name;        /* name of entry, relative to directory name */
+};
+
+#ifdef MOZ_UNICODE
+struct PRDirEntryUTF16 {
+    const PRUnichar *name;   /* name of entry in UTF16, relative to
+                              * directory name */
+};
+#endif /* MOZ_UNICODE */
+
+#if !defined(NO_NSPR_10_SUPPORT)
+#define PR_DirName(dirEntry)	(dirEntry->name)
+#endif
+
+/*
+ *************************************************************************
+ * FUNCTION: PR_OpenDir
+ * DESCRIPTION:
+ *     Open the directory by the given name
+ * INPUTS:
+ *     const char *name
+ *         path name of the directory to be opened
+ * OUTPUTS:
+ *     None
+ * RETURN: PRDir *
+ *     If the directory is sucessfully opened, a PRDir object is
+ *     dynamically allocated and a pointer to it is returned.
+ *     If the directory cannot be opened, a NULL pointer is returned.
+ * MEMORY:
+ *     Upon successful completion, the return value points to
+ *     dynamically allocated memory.
+ *************************************************************************
+ */
+
+NSPR_API(PRDir*) PR_OpenDir(const char *name);
+
+#ifdef MOZ_UNICODE
+/*
+ * EXPERIMENTAL: This function may be removed in a future release.
+ */
+NSPR_API(PRDirUTF16*) PR_OpenDirUTF16(const PRUnichar *name);
+#endif /* MOZ_UNICODE */
+
+/*
+ *************************************************************************
+ * FUNCTION: PR_ReadDir
+ * DESCRIPTION:
+ * INPUTS:
+ *     PRDir *dir
+ *         pointer to a PRDir object that designates an open directory
+ *     PRDirFlags flags
+ *           PR_SKIP_NONE     Do not skip any files
+ *           PR_SKIP_DOT      Skip the directory entry "." that
+ *                            represents the current directory
+ *           PR_SKIP_DOT_DOT  Skip the directory entry ".." that
+ *                            represents the parent directory.
+ *           PR_SKIP_BOTH     Skip both '.' and '..'
+ *           PR_SKIP_HIDDEN   Skip hidden files
+ * OUTPUTS:
+ * RETURN: PRDirEntry*
+ *     Returns a pointer to the next entry in the directory.  Returns
+ *     a NULL pointer upon reaching the end of the directory or when an
+ *     error occurs. The actual reason can be retrieved via PR_GetError().
+ *************************************************************************
+ */
+
+typedef enum PRDirFlags {
+    PR_SKIP_NONE = 0x0,
+    PR_SKIP_DOT = 0x1,
+    PR_SKIP_DOT_DOT = 0x2,
+    PR_SKIP_BOTH = 0x3,
+    PR_SKIP_HIDDEN = 0x4
+} PRDirFlags;
+
+NSPR_API(PRDirEntry*) PR_ReadDir(PRDir *dir, PRDirFlags flags);
+
+#ifdef MOZ_UNICODE
+/*
+ * EXPERIMENTAL: This function may be removed in a future release.
+ */
+NSPR_API(PRDirEntryUTF16*) PR_ReadDirUTF16(PRDirUTF16 *dir, PRDirFlags flags);
+#endif /* MOZ_UNICODE */
+
+/*
+ *************************************************************************
+ * FUNCTION: PR_CloseDir
+ * DESCRIPTION:
+ *     Close the specified directory.
+ * INPUTS:
+ *     PRDir *dir
+ *        The directory to be closed.
+ * OUTPUTS:
+ *     None
+ * RETURN: PRStatus
+ *        If successful, will return a status of PR_SUCCESS. Otherwise
+ *        a value of PR_FAILURE. The reason for the failure may be re-
+ *        trieved using PR_GetError().
+ *************************************************************************
+ */
+
+NSPR_API(PRStatus) PR_CloseDir(PRDir *dir);
+
+#ifdef MOZ_UNICODE
+/*
+ * EXPERIMENTAL: This function may be removed in a future release.
+ */
+NSPR_API(PRStatus) PR_CloseDirUTF16(PRDirUTF16 *dir);
+#endif /* MOZ_UNICODE */
+
+/*
+ *************************************************************************
+ * FUNCTION: PR_MkDir
+ * DESCRIPTION:
+ *     Create a new directory with the given name and access mode.
+ * INPUTS:
+ *     const char *name
+ *        The name of the directory to be created. All the path components
+ *        up to but not including the leaf component must already exist.
+ *     PRIntn mode
+ *        See 'mode' definiton in PR_Open().
+ * OUTPUTS:
+ *     None
+ * RETURN: PRStatus
+ *        If successful, will return a status of PR_SUCCESS. Otherwise
+ *        a value of PR_FAILURE. The reason for the failure may be re-
+ *        trieved using PR_GetError().
+ *************************************************************************
+ */
+
+NSPR_API(PRStatus) PR_MkDir(const char *name, PRIntn mode);
+
+/*
+ *************************************************************************
+ * FUNCTION: PR_MakeDir
+ * DESCRIPTION:
+ *     Create a new directory with the given name and access mode.
+ *     PR_MakeDir has the same prototype as PR_MkDir but implements
+ *     the specified access mode where possible.
+ *************************************************************************
+ */
+
+NSPR_API(PRStatus) PR_MakeDir(const char *name, PRIntn mode);
+
+/*
+ *************************************************************************
+ * FUNCTION: PR_RmDir
+ * DESCRIPTION:
+ *     Remove a directory by the given name.
+ * INPUTS:
+ *     const char *name
+ *        The name of the directory to be removed. All the path components
+ *        must already exist. Only the leaf component will be removed.
+ * OUTPUTS:
+ *     None
+ * RETURN: PRStatus
+ *        If successful, will return a status of PR_SUCCESS. Otherwise
+ *        a value of PR_FAILURE. The reason for the failure may be re-
+ *        trieved using PR_GetError().
+ **************************************************************************
+ */
+
+NSPR_API(PRStatus) PR_RmDir(const char *name);
+
+/*
+ *************************************************************************
+ * FUNCTION: PR_NewUDPSocket
+ * DESCRIPTION:
+ *     Create a new UDP socket.
+ * INPUTS:
+ *     None
+ * OUTPUTS:
+ *     None
+ * RETURN: PRFileDesc*
+ *     Upon successful completion, PR_NewUDPSocket returns a pointer
+ *     to the PRFileDesc created for the newly opened UDP socket.
+ *     Returns a NULL pointer if the creation of a new UDP socket failed.
+ *
+ **************************************************************************
+ */
+
+NSPR_API(PRFileDesc*)    PR_NewUDPSocket(void);
+
+/*
+ *************************************************************************
+ * FUNCTION: PR_NewTCPSocket
+ * DESCRIPTION:
+ *     Create a new TCP socket.
+ * INPUTS:
+ *     None
+ * OUTPUTS:
+ *     None
+ * RETURN: PRFileDesc*
+ *     Upon successful completion, PR_NewTCPSocket returns a pointer
+ *     to the PRFileDesc created for the newly opened TCP socket.
+ *     Returns a NULL pointer if the creation of a new TCP socket failed.
+ *
+ **************************************************************************
+ */
+
+NSPR_API(PRFileDesc*)    PR_NewTCPSocket(void);
+
+/*
+ *************************************************************************
+ * FUNCTION: PR_OpenUDPSocket
+ * DESCRIPTION:
+ *     Create a new UDP socket of the specified address family.
+ * INPUTS:
+ *     PRIntn af
+ *       Address family
+ * OUTPUTS:
+ *     None
+ * RETURN: PRFileDesc*
+ *     Upon successful completion, PR_OpenUDPSocket returns a pointer
+ *     to the PRFileDesc created for the newly opened UDP socket.
+ *     Returns a NULL pointer if the creation of a new UDP socket failed.
+ *
+ **************************************************************************
+ */
+
+NSPR_API(PRFileDesc*)    PR_OpenUDPSocket(PRIntn af);
+
+/*
+ *************************************************************************
+ * FUNCTION: PR_OpenTCPSocket
+ * DESCRIPTION:
+ *     Create a new TCP socket of the specified address family.
+ * INPUTS:
+ *     PRIntn af
+ *       Address family
+ * OUTPUTS:
+ *     None
+ * RETURN: PRFileDesc*
+ *     Upon successful completion, PR_NewTCPSocket returns a pointer
+ *     to the PRFileDesc created for the newly opened TCP socket.
+ *     Returns a NULL pointer if the creation of a new TCP socket failed.
+ *
+ **************************************************************************
+ */
+
+NSPR_API(PRFileDesc*)    PR_OpenTCPSocket(PRIntn af);
+
+/*
+ *************************************************************************
+ * FUNCTION: PR_Connect
+ * DESCRIPTION:
+ *     Initiate a connection on a socket.
+ * INPUTS:
+ *     PRFileDesc *fd
+ *       Points to a PRFileDesc object representing a socket
+ *     PRNetAddr *addr
+ *       Specifies the address of the socket in its own communication
+ *       space.
+ *     PRIntervalTime timeout
+ *       The function uses the lesser of the provided timeout and
+ *       the OS's connect timeout.  In particular, if you specify
+ *       PR_INTERVAL_NO_TIMEOUT as the timeout, the OS's connection
+ *       time limit will be used.
+ *
+ * OUTPUTS:
+ *     None
+ * RETURN: PRStatus
+ *     Upon successful completion of connection initiation, PR_Connect
+ *     returns PR_SUCCESS.  Otherwise, it returns PR_FAILURE.  Further
+ *     failure information can be obtained by calling PR_GetError().
+ **************************************************************************
+ */
+
+NSPR_API(PRStatus) PR_Connect(
+    PRFileDesc *fd, const PRNetAddr *addr, PRIntervalTime timeout);
+
+/*
+ *************************************************************************
+ * FUNCTION: PR_ConnectContinue
+ * DESCRIPTION:
+ *     Continue a nonblocking connect.  After a nonblocking connect
+ *     is initiated with PR_Connect() (which fails with
+ *     PR_IN_PROGRESS_ERROR), one should call PR_Poll() on the socket,
+ *     with the in_flags PR_POLL_WRITE | PR_POLL_EXCEPT.  When
+ *     PR_Poll() returns, one calls PR_ConnectContinue() on the
+ *     socket to determine whether the nonblocking connect has
+ *     completed or is still in progress.  Repeat the PR_Poll(),
+ *     PR_ConnectContinue() sequence until the nonblocking connect
+ *     has completed.
+ * INPUTS:
+ *     PRFileDesc *fd
+ *         the file descriptor representing a socket
+ *     PRInt16 out_flags
+ *         the out_flags field of the poll descriptor returned by
+ *         PR_Poll()
+ * RETURN: PRStatus
+ *     If the nonblocking connect has successfully completed,
+ *     PR_ConnectContinue returns PR_SUCCESS.  If PR_ConnectContinue()
+ *     returns PR_FAILURE, call PR_GetError():
+ *     - PR_IN_PROGRESS_ERROR: the nonblocking connect is still in
+ *       progress and has not completed yet.  The caller should poll
+ *       on the file descriptor for the in_flags
+ *       PR_POLL_WRITE|PR_POLL_EXCEPT and retry PR_ConnectContinue
+ *       later when PR_Poll() returns.
+ *     - Other errors: the nonblocking connect has failed with this
+ *       error code.
+ */
+
+NSPR_API(PRStatus)    PR_ConnectContinue(PRFileDesc *fd, PRInt16 out_flags);
+
+/*
+ *************************************************************************
+ * THIS FUNCTION IS DEPRECATED.  USE PR_ConnectContinue INSTEAD.
+ *
+ * FUNCTION: PR_GetConnectStatus
+ * DESCRIPTION:
+ *     Get the completion status of a nonblocking connect.  After
+ *     a nonblocking connect is initiated with PR_Connect() (which
+ *     fails with PR_IN_PROGRESS_ERROR), one should call PR_Poll()
+ *     on the socket, with the in_flags PR_POLL_WRITE | PR_POLL_EXCEPT.
+ *     When PR_Poll() returns, one calls PR_GetConnectStatus on the
+ *     PRPollDesc structure to determine whether the nonblocking
+ *     connect has succeeded or failed.
+ * INPUTS:
+ *     const PRPollDesc *pd
+ *         Pointer to a PRPollDesc whose fd member is the socket,
+ *         and in_flags must contain PR_POLL_WRITE and PR_POLL_EXCEPT.
+ *         PR_Poll() should have been called and set the out_flags.
+ * RETURN: PRStatus
+ *     If the nonblocking connect has successfully completed,
+ *     PR_GetConnectStatus returns PR_SUCCESS.  If PR_GetConnectStatus()
+ *     returns PR_FAILURE, call PR_GetError():
+ *     - PR_IN_PROGRESS_ERROR: the nonblocking connect is still in
+ *       progress and has not completed yet.
+ *     - Other errors: the nonblocking connect has failed with this
+ *       error code.
+ */
+
+NSPR_API(PRStatus)    PR_GetConnectStatus(const PRPollDesc *pd);
+
+/*
+ *************************************************************************
+ * FUNCTION: PR_Accept
+ * DESCRIPTION:
+ *     Accept a connection on a socket.
+ * INPUTS:
+ *     PRFileDesc *fd
+ *       Points to a PRFileDesc object representing the rendezvous socket
+ *       on which the caller is willing to accept new connections.
+ *     PRIntervalTime timeout
+ *       Time limit for completion of the accept operation.
+ * OUTPUTS:
+ *     PRNetAddr *addr
+ *       Returns the address of the connecting entity in its own
+ *       communication space. It may be NULL.
+ * RETURN: PRFileDesc*
+ *     Upon successful acceptance of a connection, PR_Accept
+ *     returns a valid file descriptor. Otherwise, it returns NULL.
+ *     Further failure information can be obtained by calling PR_GetError().
+ **************************************************************************
+ */
+
+NSPR_API(PRFileDesc*) PR_Accept(
+    PRFileDesc *fd, PRNetAddr *addr, PRIntervalTime timeout);
+
+/*
+ *************************************************************************
+ * FUNCTION: PR_Bind
+ * DESCRIPTION:
+ *    Bind an address to a socket.
+ * INPUTS:
+ *     PRFileDesc *fd
+ *       Points to a PRFileDesc object representing a socket.
+ *     PRNetAddr *addr
+ *       Specifies the address to which the socket will be bound.
+ * OUTPUTS:
+ *     None
+ * RETURN: PRStatus
+ *     Upon successful binding of an address to a socket, PR_Bind
+ *     returns PR_SUCCESS.  Otherwise, it returns PR_FAILURE.  Further
+ *     failure information can be obtained by calling PR_GetError().
+ **************************************************************************
+ */
+
+NSPR_API(PRStatus) PR_Bind(PRFileDesc *fd, const PRNetAddr *addr);
+
+/*
+ *************************************************************************
+ * FUNCTION: PR_Listen
+ * DESCRIPTION:
+ *    Listen for connections on a socket.
+ * INPUTS:
+ *     PRFileDesc *fd
+ *       Points to a PRFileDesc object representing a socket that will be
+ *       used to listen for new connections.
+ *     PRIntn backlog
+ *       Specifies the maximum length of the queue of pending connections.
+ * OUTPUTS:
+ *     None
+ * RETURN: PRStatus
+ *     Upon successful completion of listen request, PR_Listen
+ *     returns PR_SUCCESS.  Otherwise, it returns PR_FAILURE.  Further
+ *     failure information can be obtained by calling PR_GetError().
+ **************************************************************************
+ */
+
+NSPR_API(PRStatus) PR_Listen(PRFileDesc *fd, PRIntn backlog);
+
+/*
+ *************************************************************************
+ * FUNCTION: PR_Shutdown
+ * DESCRIPTION:
+ *    Shut down part of a full-duplex connection on a socket.
+ * INPUTS:
+ *     PRFileDesc *fd
+ *       Points to a PRFileDesc object representing a connected socket.
+ *     PRIntn how
+ *       Specifies the kind of disallowed operations on the socket.
+ *           PR_SHUTDOWN_RCV - Further receives will be disallowed
+ *           PR_SHUTDOWN_SEND - Further sends will be disallowed
+ *           PR_SHUTDOWN_BOTH - Further sends and receives will be disallowed
+ * OUTPUTS:
+ *     None
+ * RETURN: PRStatus
+ *     Upon successful completion of shutdown request, PR_Shutdown
+ *     returns PR_SUCCESS.  Otherwise, it returns PR_FAILURE.  Further
+ *     failure information can be obtained by calling PR_GetError().
+ **************************************************************************
+ */
+
+typedef enum PRShutdownHow
+{
+    PR_SHUTDOWN_RCV = 0,      /* disallow further receives */
+    PR_SHUTDOWN_SEND = 1,     /* disallow further sends */
+    PR_SHUTDOWN_BOTH = 2      /* disallow further receives and sends */
+} PRShutdownHow;
+
+NSPR_API(PRStatus)    PR_Shutdown(PRFileDesc *fd, PRShutdownHow how);
+
+/*
+ *************************************************************************
+ * FUNCTION: PR_Recv
+ * DESCRIPTION:
+ *    Receive a specified number of bytes from a connected socket.
+ *     The operation will block until some positive number of bytes are 
+ *     transferred, a time out has occurred, or there is an error. 
+ *     No more than 'amount' bytes will be transferred.
+ * INPUTS:
+ *     PRFileDesc *fd
+ *       points to a PRFileDesc object representing a socket.
+ *     void *buf
+ *       pointer to a buffer to hold the data received.
+ *     PRInt32 amount
+ *       the size of 'buf' (in bytes)
+ *     PRIntn flags
+ *       must be zero or PR_MSG_PEEK.
+ *     PRIntervalTime timeout
+ *       Time limit for completion of the receive operation.
+ * OUTPUTS:
+ *     None
+ * RETURN: PRInt32
+ *         a positive number indicates the number of bytes actually received.
+ *         0 means the network connection is closed.
+ *         -1 indicates a failure. The reason for the failure is obtained
+ *         by calling PR_GetError().
+ **************************************************************************
+ */
+
+#define PR_MSG_PEEK 0x2
+
+NSPR_API(PRInt32)    PR_Recv(PRFileDesc *fd, void *buf, PRInt32 amount,
+                PRIntn flags, PRIntervalTime timeout);
+
+/*
+ *************************************************************************
+ * FUNCTION: PR_Send
+ * DESCRIPTION:
+ *    Send a specified number of bytes from a connected socket.
+ *     The operation will block until all bytes are 
+ *     processed, a time out has occurred, or there is an error. 
+ * INPUTS:
+ *     PRFileDesc *fd
+ *       points to a PRFileDesc object representing a socket.
+ *     void *buf
+ *       pointer to a buffer from where the data is sent.
+ *     PRInt32 amount
+ *       the size of 'buf' (in bytes)
+ *     PRIntn flags
+ *        (OBSOLETE - must always be zero)
+ *     PRIntervalTime timeout
+ *       Time limit for completion of the send operation.
+ * OUTPUTS:
+ *     None
+ * RETURN: PRInt32
+ *     A positive number indicates the number of bytes successfully processed.
+ *     This number must always equal 'amount'. A -1 is an indication that the
+ *     operation failed. The reason for the failure is obtained by calling
+ *     PR_GetError().
+ **************************************************************************
+ */
+
+NSPR_API(PRInt32)    PR_Send(PRFileDesc *fd, const void *buf, PRInt32 amount,
+                                PRIntn flags, PRIntervalTime timeout);
+
+/*
+ *************************************************************************
+ * FUNCTION: PR_RecvFrom
+ * DESCRIPTION:
+ *     Receive up to a specified number of bytes from socket which may
+ *     or may not be connected.
+ *     The operation will block until one or more bytes are 
+ *     transferred, a time out has occurred, or there is an error. 
+ *     No more than 'amount' bytes will be transferred.
+ * INPUTS:
+ *     PRFileDesc *fd
+ *       points to a PRFileDesc object representing a socket.
+ *     void *buf
+ *       pointer to a buffer to hold the data received.
+ *     PRInt32 amount
+ *       the size of 'buf' (in bytes)
+ *     PRIntn flags
+ *        (OBSOLETE - must always be zero)
+ *     PRNetAddr *addr
+ *       Specifies the address of the sending peer. It may be NULL.
+ *     PRIntervalTime timeout
+ *       Time limit for completion of the receive operation.
+ * OUTPUTS:
+ *     None
+ * RETURN: PRInt32
+ *         a positive number indicates the number of bytes actually received.
+ *         0 means the network connection is closed.
+ *         -1 indicates a failure. The reason for the failure is obtained
+ *         by calling PR_GetError().
+ **************************************************************************
+ */
+
+NSPR_API(PRInt32) PR_RecvFrom(
+    PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
+    PRNetAddr *addr, PRIntervalTime timeout);
+
+/*
+ *************************************************************************
+ * FUNCTION: PR_SendTo
+ * DESCRIPTION:
+ *    Send a specified number of bytes from an unconnected socket.
+ *    The operation will block until all bytes are 
+ *    sent, a time out has occurred, or there is an error. 
+ * INPUTS:
+ *     PRFileDesc *fd
+ *       points to a PRFileDesc object representing an unconnected socket.
+ *     void *buf
+ *       pointer to a buffer from where the data is sent.
+ *     PRInt32 amount
+ *       the size of 'buf' (in bytes)
+ *     PRIntn flags
+ *        (OBSOLETE - must always be zero)
+ *     PRNetAddr *addr
+ *       Specifies the address of the peer.
+.*     PRIntervalTime timeout
+ *       Time limit for completion of the send operation.
+ * OUTPUTS:
+ *     None
+ * RETURN: PRInt32
+ *     A positive number indicates the number of bytes successfully sent.
+ *     -1 indicates a failure. The reason for the failure is obtained
+ *     by calling PR_GetError().
+ **************************************************************************
+ */
+
+NSPR_API(PRInt32) PR_SendTo(
+    PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
+    const PRNetAddr *addr, PRIntervalTime timeout);
+
+/*
+*************************************************************************
+** FUNCTION: PR_TransmitFile
+** DESCRIPTION:
+**    Transmitfile sends a complete file (sourceFile) across a socket 
+**    (networkSocket).  If headers is non-NULL, the headers will be sent across
+**    the socket prior to sending the file.
+** 
+**    Optionally, the PR_TRANSMITFILE_CLOSE_SOCKET flag may be passed to
+**    transmitfile.  This flag specifies that transmitfile should close the
+**    socket after sending the data.
+**
+** INPUTS:
+**    PRFileDesc *networkSocket
+**        The socket to send data over
+**    PRFileDesc *sourceFile
+**        The file to send
+**    const void *headers
+**        A pointer to headers to be sent before sending data
+**    PRInt32       hlen
+**        length of header buffers in bytes.
+**    PRTransmitFileFlags       flags
+**        If the flags indicate that the connection should be closed,
+**        it will be done immediately after transferring the file, unless
+**        the operation is unsuccessful. 
+.*     PRIntervalTime timeout
+ *        Time limit for completion of the transmit operation.
+**
+** RETURNS:
+**    Returns the number of bytes written or -1 if the operation failed.
+**    If an error occurs while sending the file, the PR_TRANSMITFILE_CLOSE_
+**    SOCKET flag is ignored. The reason for the failure is obtained
+**    by calling PR_GetError().
+**************************************************************************
+*/
+
+NSPR_API(PRInt32) PR_TransmitFile(
+    PRFileDesc *networkSocket, PRFileDesc *sourceFile,
+    const void *headers, PRInt32 hlen, PRTransmitFileFlags flags,
+    PRIntervalTime timeout);
+
+/*
+*************************************************************************
+** FUNCTION: PR_SendFile
+** DESCRIPTION:
+**    PR_SendFile sends data from a file (sendData->fd) across a socket 
+**    (networkSocket).  If specified, a header and/or trailer buffer are sent
+**	  before and after the file, respectively. The file offset, number of bytes
+** 	  of file data to send, the header and trailer buffers are specified in the
+**	  sendData argument.
+** 
+**    Optionally, if the PR_TRANSMITFILE_CLOSE_SOCKET flag is passed, the
+**    socket is closed after successfully sending the data.
+**
+** INPUTS:
+**    PRFileDesc *networkSocket
+**        The socket to send data over
+**    PRSendFileData *sendData
+**        Contains the FD, file offset and length, header and trailer
+**		  buffer specifications.
+**    PRTransmitFileFlags       flags
+**        If the flags indicate that the connection should be closed,
+**        it will be done immediately after transferring the file, unless
+**        the operation is unsuccessful. 
+.*     PRIntervalTime timeout
+ *        Time limit for completion of the send operation.
+**
+** RETURNS:
+**    Returns the number of bytes written or -1 if the operation failed.
+**    If an error occurs while sending the file, the PR_TRANSMITFILE_CLOSE_
+**    SOCKET flag is ignored. The reason for the failure is obtained
+**    by calling PR_GetError().
+**************************************************************************
+*/
+
+struct PRSendFileData {
+	PRFileDesc	*fd;			/* file to send							*/
+	PRUint32	file_offset;	/* file offset							*/
+	PRSize		file_nbytes;	/* number of bytes of file data to send	*/
+								/* if 0, send data from file_offset to	*/
+								/* end-of-file.							*/
+	const void	*header;		/* header buffer						*/
+	PRInt32		hlen;			/* header len							*/
+	const void	*trailer;		/* trailer buffer						*/
+	PRInt32		tlen;			/* trailer len							*/
+};
+
+
+NSPR_API(PRInt32) PR_SendFile(
+    PRFileDesc *networkSocket, PRSendFileData *sendData,
+	PRTransmitFileFlags flags, PRIntervalTime timeout);
+
+/*
+*************************************************************************
+** FUNCTION: PR_AcceptRead
+** DESCRIPTION:
+**    AcceptRead accepts a new connection, returns the newly created
+**    socket's descriptor and also returns the connecting peer's address.
+**    AcceptRead, as its name suggests, also receives the first block of data 
+**    sent by the peer.
+**
+** INPUTS:
+**    PRFileDesc *listenSock
+**        A socket descriptor that has been called with the PR_Listen() 
+**        function, also known as the rendezvous socket.
+**    void *buf
+**        A pointer to a buffer to receive data sent by the client.  This 
+**        buffer must be large enough to receive <amount> bytes of data
+**        and two PRNetAddr structures, plus an extra 32 bytes. See:
+**        PR_ACCEPT_READ_BUF_OVERHEAD.
+**    PRInt32 amount
+**        The number of bytes of client data to receive.  Does not include
+**        the size of the PRNetAddr structures.  If 0, no data will be read
+**        from the client.
+**    PRIntervalTime timeout
+**        The timeout interval only applies to the read portion of the 
+**        operation.  PR_AcceptRead will block indefinitely until the 
+**        connection is accepted; the read will timeout after the timeout 
+**        interval elapses.
+** OUTPUTS:
+**    PRFileDesc **acceptedSock
+**        The file descriptor for the newly connected socket.  This parameter
+**        will only be valid if the function return does not indicate failure.
+**    PRNetAddr  **peerAddr,
+**        The address of the remote socket.  This parameter will only be
+**        valid if the function return does not indicate failure.  The
+**        returned address is not guaranteed to be properly aligned.
+** 
+** RETURNS:
+**     The number of bytes read from the client or -1 on failure.  The reason 
+**     for the failure is obtained by calling PR_GetError().
+**************************************************************************
+**/       
+/* define buffer overhead constant. Add this value to the user's 
+** data length when allocating a buffer to accept data.
+**    Example:
+**    #define USER_DATA_SIZE 10
+**    char buf[USER_DATA_SIZE + PR_ACCEPT_READ_BUF_OVERHEAD];
+**    bytesRead = PR_AcceptRead( s, fd, &a, &p, USER_DATA_SIZE, ...);
+*/
+#define PR_ACCEPT_READ_BUF_OVERHEAD (32+(2*sizeof(PRNetAddr)))
+
+NSPR_API(PRInt32) PR_AcceptRead(
+    PRFileDesc *listenSock, PRFileDesc **acceptedSock,
+    PRNetAddr **peerAddr, void *buf, PRInt32 amount, PRIntervalTime timeout);
+
+/*
+*************************************************************************
+** FUNCTION: PR_NewTCPSocketPair
+** DESCRIPTION:
+**    Create a new TCP socket pair. The returned descriptors can be used
+**    interchangeably; they are interconnected full-duplex descriptors: data
+**    written to one can be read from the other and vice-versa.
+**
+** INPUTS:
+**    None
+** OUTPUTS:
+**    PRFileDesc *fds[2]
+**        The file descriptor pair for the newly created TCP sockets.
+** RETURN: PRStatus
+**     Upon successful completion of TCP socket pair, PR_NewTCPSocketPair 
+**     returns PR_SUCCESS.  Otherwise, it returns PR_FAILURE.  Further
+**     failure information can be obtained by calling PR_GetError().
+** XXX can we implement this on windoze and mac?
+**************************************************************************
+**/
+NSPR_API(PRStatus) PR_NewTCPSocketPair(PRFileDesc *fds[2]);
+
+/*
+*************************************************************************
+** FUNCTION: PR_GetSockName
+** DESCRIPTION:
+**    Get socket name.  Return the network address for this socket.
+**
+** INPUTS:
+**     PRFileDesc *fd
+**       Points to a PRFileDesc object representing the socket.
+** OUTPUTS:
+**     PRNetAddr *addr
+**       Returns the address of the socket in its own communication space.
+** RETURN: PRStatus
+**     Upon successful completion, PR_GetSockName returns PR_SUCCESS.  
+**     Otherwise, it returns PR_FAILURE.  Further failure information can 
+**     be obtained by calling PR_GetError().
+**************************************************************************
+**/
+NSPR_API(PRStatus)	PR_GetSockName(PRFileDesc *fd, PRNetAddr *addr);
+
+/*
+*************************************************************************
+** FUNCTION: PR_GetPeerName
+** DESCRIPTION:
+**    Get name of the connected peer.  Return the network address for the 
+**    connected peer socket.
+**
+** INPUTS:
+**     PRFileDesc *fd
+**       Points to a PRFileDesc object representing the connected peer.
+** OUTPUTS:
+**     PRNetAddr *addr
+**       Returns the address of the connected peer in its own communication
+**       space.
+** RETURN: PRStatus
+**     Upon successful completion, PR_GetPeerName returns PR_SUCCESS.  
+**     Otherwise, it returns PR_FAILURE.  Further failure information can 
+**     be obtained by calling PR_GetError().
+**************************************************************************
+**/
+NSPR_API(PRStatus)	PR_GetPeerName(PRFileDesc *fd, PRNetAddr *addr);
+
+NSPR_API(PRStatus)	PR_GetSocketOption(
+    PRFileDesc *fd, PRSocketOptionData *data);
+
+NSPR_API(PRStatus)	PR_SetSocketOption(
+    PRFileDesc *fd, const PRSocketOptionData *data);
+
+/*
+ *********************************************************************
+ *
+ * File descriptor inheritance
+ *
+ *********************************************************************
+ */
+
+/*
+ ************************************************************************
+ * FUNCTION: PR_SetFDInheritable
+ * DESCRIPTION:
+ *    Set the inheritance attribute of a file descriptor.
+ *
+ * INPUTS:
+ *     PRFileDesc *fd
+ *       Points to a PRFileDesc object.
+ *     PRBool inheritable
+ *       If PR_TRUE, the file descriptor fd is set to be inheritable
+ *       by a child process.  If PR_FALSE, the file descriptor is set
+ *       to be not inheritable by a child process.
+ * RETURN: PRStatus
+ *     Upon successful completion, PR_SetFDInheritable returns PR_SUCCESS.  
+ *     Otherwise, it returns PR_FAILURE.  Further failure information can 
+ *     be obtained by calling PR_GetError().
+ *************************************************************************
+ */
+NSPR_API(PRStatus) PR_SetFDInheritable(
+    PRFileDesc *fd,
+    PRBool inheritable);
+
+/*
+ ************************************************************************
+ * FUNCTION: PR_GetInheritedFD
+ * DESCRIPTION:
+ *    Get an inherited file descriptor with the specified name.
+ *
+ * INPUTS:
+ *     const char *name
+ *       The name of the inherited file descriptor.
+ * RETURN: PRFileDesc *
+ *     Upon successful completion, PR_GetInheritedFD returns the
+ *     inherited file descriptor with the specified name.  Otherwise,  
+ *     it returns NULL.  Further failure information can be obtained
+ *     by calling PR_GetError().
+ *************************************************************************
+ */
+NSPR_API(PRFileDesc *) PR_GetInheritedFD(const char *name);
+
+/*
+ *********************************************************************
+ *
+ * Memory-mapped files
+ *
+ *********************************************************************
+ */
+
+typedef struct PRFileMap PRFileMap;
+
+/*
+ * protection options for read and write accesses of a file mapping
+ */
+typedef enum PRFileMapProtect {
+    PR_PROT_READONLY,     /* read only */
+    PR_PROT_READWRITE,    /* readable, and write is shared */
+    PR_PROT_WRITECOPY     /* readable, and write is private (copy-on-write) */
+} PRFileMapProtect;
+
+NSPR_API(PRFileMap *) PR_CreateFileMap(
+    PRFileDesc *fd,
+    PRInt64 size,
+    PRFileMapProtect prot);
+
+/*
+ * return the alignment (in bytes) of the offset argument to PR_MemMap
+ */
+NSPR_API(PRInt32) PR_GetMemMapAlignment(void);
+
+NSPR_API(void *) PR_MemMap(
+    PRFileMap *fmap,
+    PROffset64 offset,  /* must be aligned and sized according to the
+                         * return value of PR_GetMemMapAlignment() */
+    PRUint32 len);
+
+NSPR_API(PRStatus) PR_MemUnmap(void *addr, PRUint32 len);
+
+NSPR_API(PRStatus) PR_CloseFileMap(PRFileMap *fmap);
+
+/*
+ * Synchronously flush the given memory-mapped address range of the given open
+ * file to disk. The function does not return until all modified data have
+ * been written to disk.
+ *
+ * On some platforms, the function will call PR_Sync(fd) internally if it is
+ * necessary for flushing modified data to disk synchronously.
+ */
+NSPR_API(PRStatus) PR_SyncMemMap(
+    PRFileDesc *fd,
+    void *addr,
+    PRUint32 len);
+
+/*
+ ******************************************************************
+ *
+ * Interprocess communication
+ *
+ ******************************************************************
+ */
+
+/*
+ * Creates an anonymous pipe and returns file descriptors for the
+ * read and write ends of the pipe.
+ */
+
+NSPR_API(PRStatus) PR_CreatePipe(
+    PRFileDesc **readPipe,
+    PRFileDesc **writePipe
+);
+
+/************************************************************************/
+/************** The following definitions are for poll ******************/
+/************************************************************************/
+
+struct PRPollDesc {
+    PRFileDesc* fd;
+    PRInt16 in_flags;
+    PRInt16 out_flags;
+};
+
+/*
+** Bit values for PRPollDesc.in_flags or PRPollDesc.out_flags. Binary-or
+** these together to produce the desired poll request.
+*/
+
+#if defined(_PR_POLL_BACKCOMPAT)
+
+#include <poll.h>
+#define PR_POLL_READ    POLLIN
+#define PR_POLL_WRITE   POLLOUT
+#define PR_POLL_EXCEPT  POLLPRI
+#define PR_POLL_ERR     POLLERR     /* only in out_flags */
+#define PR_POLL_NVAL    POLLNVAL    /* only in out_flags when fd is bad */
+#define PR_POLL_HUP     POLLHUP     /* only in out_flags */
+
+#else  /* _PR_POLL_BACKCOMPAT */
+
+#define PR_POLL_READ    0x1
+#define PR_POLL_WRITE   0x2
+#define PR_POLL_EXCEPT  0x4
+#define PR_POLL_ERR     0x8         /* only in out_flags */
+#define PR_POLL_NVAL    0x10        /* only in out_flags when fd is bad */
+#define PR_POLL_HUP     0x20        /* only in out_flags */
+
+#endif  /* _PR_POLL_BACKCOMPAT */
+
+/*
+*************************************************************************
+** FUNCTION:    PR_Poll
+** DESCRIPTION:
+**
+** The call returns as soon as I/O is ready on one or more of the underlying
+** socket objects. A count of the number of ready descriptors is
+** returned unless a timeout occurs in which case zero is returned.
+**
+** PRPollDesc.fd should be set to a pointer to a PRFileDesc object
+** representing a socket. This field can be set to NULL to indicate to
+** PR_Poll that this PRFileDesc object should be ignored.
+** PRPollDesc.in_flags should be set to the desired request
+** (read/write/except or some combination). Upon successful return from
+** this call PRPollDesc.out_flags will be set to indicate what kind of
+** i/o can be performed on the respective descriptor. PR_Poll() uses the
+** out_flags fields as scratch variables during the call. If PR_Poll()
+** returns 0 or -1, the out_flags fields do not contain meaningful values
+** and must not be used.
+**
+** INPUTS:
+**      PRPollDesc *pds         A pointer to an array of PRPollDesc
+**
+**      PRIntn npds             The number of elements in the array
+**                              If this argument is zero PR_Poll is
+**                              equivalent to a PR_Sleep(timeout).
+**
+**      PRIntervalTime timeout  Amount of time the call will block waiting
+**                              for I/O to become ready. If this time expires
+**                              w/o any I/O becoming ready, the result will
+**                              be zero.
+**
+** OUTPUTS:    None
+** RETURN:
+**      PRInt32                 Number of PRPollDesc's with events or zero
+**                              if the function timed out or -1 on failure.
+**                              The reason for the failure is obtained by
+**                              calling PR_GetError().
+**************************************************************************
+*/
+NSPR_API(PRInt32) PR_Poll(
+    PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout);
+
+/*
+**************************************************************************
+**
+** Pollable events
+**
+** A pollable event is a special kind of file descriptor.
+** The only I/O operation you can perform on a pollable event
+** is to poll it with the PR_POLL_READ flag.  You can't
+** read from or write to a pollable event.
+**
+** The purpose of a pollable event is to combine event waiting
+** with I/O waiting in a single PR_Poll call.  Pollable events
+** are implemented using a pipe or a pair of TCP sockets
+** connected via the loopback address, therefore setting and
+** waiting for pollable events are expensive operating system
+** calls.  Do not use pollable events for general thread
+** synchronization. Use condition variables instead.
+**
+** A pollable event has two states: set and unset.  Events
+** are not queued, so there is no notion of an event count.
+** A pollable event is either set or unset.
+**
+** A new pollable event is created by a PR_NewPollableEvent
+** call and is initially in the unset state.
+**
+** PR_WaitForPollableEvent blocks the calling thread until
+** the pollable event is set, and then it atomically unsets
+** the pollable event before it returns.
+**
+** To set a pollable event, call PR_SetPollableEvent.
+**
+** One can call PR_Poll with the PR_POLL_READ flag on a pollable
+** event.  When the pollable event is set, PR_Poll returns with
+** the PR_POLL_READ flag set in the out_flags.
+**
+** To close a pollable event, call PR_DestroyPollableEvent
+** (not PR_Close).
+**
+**************************************************************************
+*/
+
+NSPR_API(PRFileDesc *) PR_NewPollableEvent(void);
+
+NSPR_API(PRStatus) PR_DestroyPollableEvent(PRFileDesc *event);
+
+NSPR_API(PRStatus) PR_SetPollableEvent(PRFileDesc *event);
+
+NSPR_API(PRStatus) PR_WaitForPollableEvent(PRFileDesc *event);
+
+PR_END_EXTERN_C
+
+#endif /* prio_h___ */
diff --git a/pr/include/pripcsem.h b/pr/include/pripcsem.h
new file mode 100644
index 0000000..f5a524d
--- /dev/null
+++ b/pr/include/pripcsem.h
@@ -0,0 +1,101 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+ * File: pripcsem.h
+ *
+ * Description: named semaphores for interprocess
+ * synchronization
+ *
+ * Unrelated processes obtain access to a shared semaphore
+ * by specifying its name.
+ *
+ * Our goal is to support named semaphores on at least
+ * Unix and Win32 platforms.  The implementation will use
+ * one of the three native semaphore APIs: POSIX, System V,
+ * and Win32.
+ *
+ * Because POSIX named semaphores have kernel persistence,
+ * we are forced to have a delete function in this API.
+ */
+
+#ifndef pripcsem_h___
+#define pripcsem_h___
+
+#include "prtypes.h"
+#include "prio.h"
+
+PR_BEGIN_EXTERN_C
+
+/*
+ * PRSem is an opaque structure that represents a named
+ * semaphore.
+ */
+typedef struct PRSem PRSem;
+
+/*
+ * PR_OpenSemaphore --
+ *
+ * Create or open a named semaphore with the specified name.
+ * A handle to the semaphore is returned.
+ *
+ * If the named semaphore doesn't exist and the PR_SEM_CREATE
+ * flag is specified, the named semaphore is created.  The
+ * created semaphore needs to be removed from the system with
+ * a PR_DeleteSemaphore call.
+ *
+ * If PR_SEM_CREATE is specified, the third argument is the
+ * access permission bits of the new semaphore (same
+ * interpretation as the mode argument to PR_Open) and the
+ * fourth argument is the initial value of the new semaphore.
+ * If PR_SEM_CREATE is not specified, the third and fourth
+ * arguments are ignored.
+ */
+
+#define PR_SEM_CREATE 0x1  /* create if not exist */
+#define PR_SEM_EXCL   0x2  /* fail if already exists */
+
+NSPR_API(PRSem *) PR_OpenSemaphore(
+    const char *name, PRIntn flags, PRIntn mode, PRUintn value);
+
+/*
+ * PR_WaitSemaphore --
+ *
+ * If the value of the semaphore is > 0, decrement the value and return.
+ * If the value is 0, sleep until the value becomes > 0, then decrement
+ * the value and return.
+ *
+ * The "test and decrement" operation is performed atomically.
+ */
+
+NSPR_API(PRStatus) PR_WaitSemaphore(PRSem *sem);
+
+/*
+ * PR_PostSemaphore --
+ *
+ * Increment the value of the named semaphore by 1.
+ */
+
+NSPR_API(PRStatus) PR_PostSemaphore(PRSem *sem);
+
+/*
+ * PR_CloseSemaphore --
+ *
+ * Close a named semaphore handle.
+ */
+
+NSPR_API(PRStatus) PR_CloseSemaphore(PRSem *sem);
+
+/*
+ * PR_DeleteSemaphore --
+ *
+ * Remove a named semaphore from the system.
+ */
+
+NSPR_API(PRStatus) PR_DeleteSemaphore(const char *name);
+
+PR_END_EXTERN_C
+
+#endif /* pripcsem_h___ */
diff --git a/pr/include/private/.cvsignore b/pr/include/private/.cvsignore
new file mode 100644
index 0000000..f3c7a7c
--- /dev/null
+++ b/pr/include/private/.cvsignore
@@ -0,0 +1 @@
+Makefile
diff --git a/pr/include/private/Makefile.in b/pr/include/private/Makefile.in
new file mode 100644
index 0000000..db0c2f1
--- /dev/null
+++ b/pr/include/private/Makefile.in
@@ -0,0 +1,29 @@
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+#! gmake
+
+MOD_DEPTH	= ../../..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+
+include $(MOD_DEPTH)/config/autoconf.mk
+
+include $(topsrcdir)/config/config.mk
+
+RELEASE_HEADERS = pprio.h pprthred.h prpriv.h
+RELEASE_HEADERS := $(addprefix $(srcdir)/, $(RELEASE_HEADERS))
+RELEASE_HEADERS_DEST = $(RELEASE_INCLUDE_DIR)/private
+
+HEADERS = $(RELEASE_HEADERS) $(srcdir)/pprmwait.h $(srcdir)/primpl.h
+
+include_subdir = private
+
+include $(topsrcdir)/config/rules.mk
+
+export:: $(RELEASE_HEADERS)
+	$(INSTALL) -m 444 $(RELEASE_HEADERS) $(dist_includedir)/private
diff --git a/pr/include/private/pprio.h b/pr/include/private/pprio.h
new file mode 100644
index 0000000..26bcd0d
--- /dev/null
+++ b/pr/include/private/pprio.h
@@ -0,0 +1,242 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** File:	pprio.h
+**
+** Description:	Private definitions for I/O related structures
+*/
+
+#ifndef pprio_h___
+#define pprio_h___
+
+#include "prtypes.h"
+#include "prio.h"
+
+PR_BEGIN_EXTERN_C
+
+/************************************************************************/
+/************************************************************************/
+
+#ifdef _WIN64
+typedef __int64 PROsfd;
+#else
+typedef PRInt32 PROsfd;
+#endif
+
+/* Return the method tables for files, tcp sockets and udp sockets */
+NSPR_API(const PRIOMethods*)    PR_GetFileMethods(void);
+NSPR_API(const PRIOMethods*)    PR_GetTCPMethods(void);
+NSPR_API(const PRIOMethods*)    PR_GetUDPMethods(void);
+NSPR_API(const PRIOMethods*)    PR_GetPipeMethods(void);
+
+/*
+** Convert a NSPR socket handle to a native socket handle.
+**
+** Using this function makes your code depend on the properties of the
+** current NSPR implementation, which may change (although extremely
+** unlikely because of NSPR's backward compatibility requirement).  Avoid
+** using it if you can.
+**
+** If you use this function, you need to understand what NSPR does to
+** the native handle.  For example, NSPR puts native socket handles in
+** non-blocking mode or associates them with an I/O completion port (the
+** WINNT build configuration only).  Your use of the native handle should
+** not interfere with NSPR's use of the native handle.  If your code
+** changes the configuration of the native handle, (e.g., changes it to
+** blocking or closes it), NSPR will not work correctly.
+*/
+NSPR_API(PROsfd)       PR_FileDesc2NativeHandle(PRFileDesc *);
+NSPR_API(void)         PR_ChangeFileDescNativeHandle(PRFileDesc *, PROsfd);
+NSPR_API(PRFileDesc*)  PR_AllocFileDesc(PROsfd osfd,
+                                         const PRIOMethods *methods);
+NSPR_API(void)         PR_FreeFileDesc(PRFileDesc *fd);
+/*
+** Import an existing OS file to NSPR. 
+*/
+NSPR_API(PRFileDesc*)  PR_ImportFile(PROsfd osfd);
+NSPR_API(PRFileDesc*)  PR_ImportPipe(PROsfd osfd);
+NSPR_API(PRFileDesc*)  PR_ImportTCPSocket(PROsfd osfd);
+NSPR_API(PRFileDesc*)  PR_ImportUDPSocket(PROsfd osfd);
+
+
+/*
+ *************************************************************************
+ * FUNCTION: PR_CreateSocketPollFd
+ * DESCRIPTION:
+ *     Create a PRFileDesc wrapper for a native socket handle, for use with
+ *	   PR_Poll only
+ * INPUTS:
+ *     None
+ * OUTPUTS:
+ *     None
+ * RETURN: PRFileDesc*
+ *     Upon successful completion, PR_CreateSocketPollFd returns a pointer
+ *     to the PRFileDesc created for the native socket handle
+ *     Returns a NULL pointer if the create of a new PRFileDesc failed
+ *
+ **************************************************************************
+ */
+
+NSPR_API(PRFileDesc*)	PR_CreateSocketPollFd(PROsfd osfd);
+
+/*
+ *************************************************************************
+ * FUNCTION: PR_DestroySocketPollFd
+ * DESCRIPTION:
+ *     Destroy the PRFileDesc wrapper created by PR_CreateSocketPollFd
+ * INPUTS:
+ *     None
+ * OUTPUTS:
+ *     None
+ * RETURN: PRFileDesc*
+ *     Upon successful completion, PR_DestroySocketPollFd returns
+ *	   PR_SUCCESS, else PR_FAILURE
+ *
+ **************************************************************************
+ */
+
+NSPR_API(PRStatus) PR_DestroySocketPollFd(PRFileDesc *fd);
+
+
+/*
+** Macros for PR_Socket
+**
+** Socket types: PR_SOCK_STREAM, PR_SOCK_DGRAM
+*/
+
+#ifdef WIN32
+
+#define PR_SOCK_STREAM 1
+#define PR_SOCK_DGRAM 2
+
+#else /* WIN32 */
+
+#define PR_SOCK_STREAM SOCK_STREAM
+#define PR_SOCK_DGRAM SOCK_DGRAM
+
+#endif /* WIN32 */
+
+/*
+** Create a new Socket; this function is obsolete.
+*/
+NSPR_API(PRFileDesc*)	PR_Socket(PRInt32 domain, PRInt32 type, PRInt32 proto);
+
+/* FUNCTION: PR_LockFile
+** DESCRIPTION:
+**    Lock a file for exclusive access.
+** RETURNS:
+**    PR_SUCCESS when the lock is held
+**    PR_FAILURE otherwise
+*/
+NSPR_API(PRStatus) PR_LockFile(PRFileDesc *fd);
+
+/* FUNCTION: PR_TLockFile
+** DESCRIPTION:
+**    Test and Lock a file for exclusive access.  Do not block if the
+**    file cannot be locked immediately.
+** RETURNS:
+**    PR_SUCCESS when the lock is held
+**    PR_FAILURE otherwise
+*/
+NSPR_API(PRStatus) PR_TLockFile(PRFileDesc *fd);
+
+/* FUNCTION: PR_UnlockFile
+** DESCRIPTION:
+**    Unlock a file which has been previously locked successfully by this
+**    process.
+** RETURNS:
+**    PR_SUCCESS when the lock is released
+**    PR_FAILURE otherwise
+*/
+NSPR_API(PRStatus) PR_UnlockFile(PRFileDesc *fd);
+
+/*
+** Emulate acceptread by accept and recv.
+*/
+NSPR_API(PRInt32) PR_EmulateAcceptRead(PRFileDesc *sd, PRFileDesc **nd,
+    PRNetAddr **raddr, void *buf, PRInt32 amount, PRIntervalTime timeout);
+
+/*
+** Emulate sendfile by reading from the file and writing to the socket.
+** The file is memory-mapped if memory-mapped files are supported.
+*/
+NSPR_API(PRInt32) PR_EmulateSendFile(
+    PRFileDesc *networkSocket, PRSendFileData *sendData,
+    PRTransmitFileFlags flags, PRIntervalTime timeout);
+
+#ifdef WIN32
+/* FUNCTION: PR_NTFast_AcceptRead
+** DESCRIPTION:
+**    NT has the notion of an "accept context", which is only needed in
+**    order to make certain calls.  By default, a socket connected via
+**    AcceptEx can only do a limited number of things without updating
+**    the acceptcontext.  The generic version of PR_AcceptRead always
+**    updates the accept context.  This version does not.
+**/
+NSPR_API(PRInt32) PR_NTFast_AcceptRead(PRFileDesc *sd, PRFileDesc **nd,
+              PRNetAddr **raddr, void *buf, PRInt32 amount, PRIntervalTime t);
+
+typedef void (*_PR_AcceptTimeoutCallback)(void *);
+
+/* FUNCTION: PR_NTFast_AcceptRead_WithTimeoutCallback
+** DESCRIPTION:
+**    The AcceptEx call combines the accept with the read function.  However,
+**    our daemon threads need to be able to wakeup and reliably flush their
+**    log buffers if the Accept times out.  However, with the current blocking
+**    interface to AcceptRead, there is no way for us to timeout the Accept;
+**    this is because when we timeout the Read, we can close the newly 
+**    socket and continue; but when we timeout the accept itself, there is no
+**    new socket to timeout.  So instead, this version of the function is
+**    provided.  After the initial timeout period elapses on the accept()
+**    portion of the function, it will call the callback routine and then
+**    continue the accept.   If the timeout occurs on the read, it will 
+**    close the connection and return error.
+*/
+NSPR_API(PRInt32) PR_NTFast_AcceptRead_WithTimeoutCallback(
+              PRFileDesc *sd, 
+              PRFileDesc **nd,
+              PRNetAddr **raddr, 
+              void *buf, 
+              PRInt32 amount, 
+              PRIntervalTime t,
+              _PR_AcceptTimeoutCallback callback, 
+              void *callback_arg);
+
+/* FUNCTION: PR_NTFast_Accept
+** DESCRIPTION:
+**    NT has the notion of an "accept context", which is only needed in
+**    order to make certain calls.  By default, a socket connected via
+**    AcceptEx can only do a limited number of things without updating
+**    the acceptcontext.  The generic version of PR_Accept always
+**    updates the accept context.  This version does not.
+**/
+NSPR_API(PRFileDesc*)	PR_NTFast_Accept(PRFileDesc *fd, PRNetAddr *addr,
+                                                PRIntervalTime timeout);
+
+/* FUNCTION: PR_NTFast_Update
+** DESCRIPTION:
+**    For sockets accepted with PR_NTFast_Accept or PR_NTFastAcceptRead,
+**    this function will update the accept context for those sockets,
+**    so that the socket can make general purpose socket calls.
+**    Without calling this, the only operations supported on the socket
+**    Are PR_Read, PR_Write, PR_Transmitfile, and PR_Close.
+*/
+NSPR_API(void) PR_NTFast_UpdateAcceptContext(PRFileDesc *acceptSock, 
+                                        PRFileDesc *listenSock);
+
+
+/* FUNCTION: PR_NT_CancelIo
+** DESCRIPTION:
+**    Cancel IO operations on fd.
+*/
+NSPR_API(PRStatus) PR_NT_CancelIo(PRFileDesc *fd);
+
+
+#endif /* WIN32 */
+
+PR_END_EXTERN_C
+
+#endif /* pprio_h___ */
diff --git a/pr/include/private/pprmwait.h b/pr/include/private/pprmwait.h
new file mode 100644
index 0000000..3e4057c
--- /dev/null
+++ b/pr/include/private/pprmwait.h
@@ -0,0 +1,103 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#if defined(_PPRMWAIT_H)
+#else
+#define _PPRMWAIT_H
+
+#include "prlock.h"
+#include "prcvar.h"
+#include "prclist.h"
+#include "prthread.h"
+
+#define MAX_POLLING_INTERVAL 100
+#define _PR_POLL_COUNT_FUDGE 64
+#define _PR_DEFAULT_HASH_LENGTH 59
+
+/*
+ * Our hash table resolves collisions by open addressing with
+ * double hashing.  See Cormen, Leiserson, and Rivest,
+ * Introduction to Algorithms, p. 232, The MIT Press, 1990.
+ */
+
+#define _MW_HASH(a, m) ((((PRUptrdiff)(a) >> 4) ^ ((PRUptrdiff)(a) >> 10)) % (m))
+#define _MW_HASH2(a, m) (1 + ((((PRUptrdiff)(a) >> 4) ^ ((PRUptrdiff)(a) >> 10)) % (m - 2)))
+#define _MW_ABORTED(_rv) \
+    ((PR_FAILURE == (_rv)) && (PR_PENDING_INTERRUPT_ERROR == PR_GetError()))
+
+typedef enum {_prmw_success, _prmw_rehash, _prmw_error} _PR_HashStory;
+
+typedef struct _PRWaiterHash
+{
+    PRUint16 count;             /* current number in hash table */
+    PRUint16 length;            /* current size of the hash table */
+    PRRecvWait *recv_wait;      /* hash table of receive wait objects */
+} _PRWaiterHash;
+
+typedef enum {_prmw_running, _prmw_stopping, _prmw_stopped} PRMWGroupState;
+
+struct PRWaitGroup
+{
+    PRCList group_link;         /* all groups are linked to each other */
+    PRCList io_ready;           /* list of I/O requests that are ready */
+    PRMWGroupState state;       /* state of this group (so we can shut down) */
+
+    PRLock *ml;                 /* lock for synchronizing this wait group */
+    PRCondVar *io_taken;        /* calling threads notify when they take I/O */
+    PRCondVar *io_complete;     /* calling threads wait here for completions */
+    PRCondVar *new_business;    /* polling thread waits here more work */
+    PRCondVar *mw_manage;       /* used to manage group lists */
+    PRThread* poller;           /* thread that's actually doing the poll() */
+    PRUint16 waiting_threads;   /* number of threads waiting for recv */
+    PRUint16 polling_count;     /* number of elements in the polling list */
+    PRUint32 p_timestamp;       /* pseudo-time group had element removed */
+    PRPollDesc *polling_list;   /* list poller builds for polling */
+    PRIntervalTime last_poll;   /* last time we polled */
+    _PRWaiterHash *waiter;      /* pointer to hash table of wait receive objects */
+
+#ifdef WINNT
+    /*
+     * On NT, idle threads are responsible for getting completed i/o.
+     * They need to add completed i/o to the io_ready list.  Since
+     * idle threads cannot use nspr locks, we have to use an md lock
+     * to protect the io_ready list.
+     */
+    _MDLock mdlock;             /* protect io_ready, waiter, and wait_list */
+    PRCList wait_list;          /* used in place of io_complete.  reuse
+                                 * waitQLinks in the PRThread structure. */
+#endif /* WINNT */
+};
+
+/**********************************************************************
+***********************************************************************
+******************** Wait group enumerations **************************
+***********************************************************************
+**********************************************************************/
+typedef struct _PRGlobalState
+{
+    PRCList group_list;         /* master of the group list */
+    PRWaitGroup *group;         /* the default (NULL) group */
+} _PRGlobalState;
+
+#ifdef WINNT
+extern PRStatus NT_HashRemoveInternal(PRWaitGroup *group, PRFileDesc *fd);
+#endif
+
+typedef enum {_PR_ENUM_UNSEALED=0, _PR_ENUM_SEALED=0x0eadface} _PREnumSeal;
+
+struct PRMWaitEnumerator
+{
+    PRWaitGroup *group;       /* group this enumerator is bound to */
+    PRThread *thread;               /* thread in midst of an enumeration */
+    _PREnumSeal seal;               /* trying to detect deleted objects */
+    PRUint32 p_timestamp;           /* when enumeration was (re)started */
+    PRRecvWait **waiter;            /* pointer into hash table */
+    PRUintn index;                  /* position in hash table */
+    void *pad[4];                   /* some room to grow */
+};
+
+#endif /* defined(_PPRMWAIT_H) */
+
+/* pprmwait.h */
diff --git a/pr/include/private/pprthred.h b/pr/include/private/pprthred.h
new file mode 100644
index 0000000..eb60bae
--- /dev/null
+++ b/pr/include/private/pprthred.h
@@ -0,0 +1,331 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef pprthred_h___
+#define pprthred_h___
+
+/*
+** API for PR private functions.  These calls are to be used by internal
+** developers only.
+*/
+#include "nspr.h"
+
+#if defined(XP_OS2)
+#define INCL_DOS
+#define INCL_DOSERRORS
+#define INCL_WIN
+#include <os2.h>
+#endif
+
+PR_BEGIN_EXTERN_C
+
+/*---------------------------------------------------------------------------
+** THREAD PRIVATE FUNCTIONS
+---------------------------------------------------------------------------*/
+
+/*
+** Associate a thread object with an existing native thread.
+** 	"type" is the type of thread object to attach
+** 	"priority" is the priority to assign to the thread
+** 	"stack" defines the shape of the threads stack
+**
+** This can return NULL if some kind of error occurs, or if memory is
+** tight. This call invokes "start(obj,arg)" and returns when the
+** function returns. The thread object is automatically destroyed.
+**
+** This call is not normally needed unless you create your own native
+** thread. PR_Init does this automatically for the primordial thread.
+*/
+NSPR_API(PRThread*) PR_AttachThread(PRThreadType type,
+                                     PRThreadPriority priority,
+				     PRThreadStack *stack);
+
+/*
+** Detach the nspr thread from the currently executing native thread.
+** The thread object will be destroyed and all related data attached
+** to it. The exit procs will be invoked.
+**
+** This call is not normally needed unless you create your own native
+** thread. PR_Exit will automatially detach the nspr thread object
+** created by PR_Init for the primordial thread.
+**
+** This call returns after the nspr thread object is destroyed.
+*/
+NSPR_API(void) PR_DetachThread(void);
+
+/*
+** Get the id of the named thread. Each thread is assigned a unique id
+** when it is created or attached.
+*/
+NSPR_API(PRUint32) PR_GetThreadID(PRThread *thread);
+
+/*
+** Set the procedure that is called when a thread is dumped. The procedure
+** will be applied to the argument, arg, when called. Setting the procedure
+** to NULL effectively removes it.
+*/
+typedef void (*PRThreadDumpProc)(PRFileDesc *fd, PRThread *t, void *arg);
+NSPR_API(void) PR_SetThreadDumpProc(
+    PRThread* thread, PRThreadDumpProc dump, void *arg);
+
+/*
+** Get this thread's affinity mask.  The affinity mask is a 32 bit quantity
+** marking a bit for each processor this process is allowed to run on.
+** The processor mask is returned in the mask argument.
+** The least-significant-bit represents processor 0.
+**
+** Returns 0 on success, -1 on failure.
+*/
+NSPR_API(PRInt32) PR_GetThreadAffinityMask(PRThread *thread, PRUint32 *mask);
+
+/*
+** Set this thread's affinity mask.  
+**
+** Returns 0 on success, -1 on failure.
+*/
+NSPR_API(PRInt32) PR_SetThreadAffinityMask(PRThread *thread, PRUint32 mask );
+
+/*
+** Set the default CPU Affinity mask.
+**
+*/
+NSPR_API(PRInt32) PR_SetCPUAffinityMask(PRUint32 mask);
+
+/*
+** Show status of all threads to standard error output.
+*/
+NSPR_API(void) PR_ShowStatus(void);
+
+/*
+** Set thread recycle mode to on (1) or off (0)
+*/
+NSPR_API(void) PR_SetThreadRecycleMode(PRUint32 flag);
+
+
+/*---------------------------------------------------------------------------
+** THREAD PRIVATE FUNCTIONS FOR GARBAGE COLLECTIBLE THREADS           
+---------------------------------------------------------------------------*/
+
+/* 
+** Only Garbage collectible threads participate in resume all, suspend all and 
+** enumeration operations.  They are also different during creation when
+** platform specific action may be needed (For example, all Solaris GC able
+** threads are bound threads).
+*/
+
+/*
+** Same as PR_CreateThread except that the thread is marked as garbage
+** collectible.
+*/
+NSPR_API(PRThread*) PR_CreateThreadGCAble(PRThreadType type,
+				     void (*start)(void *arg),
+				     void *arg,
+				     PRThreadPriority priority,
+				     PRThreadScope scope,
+				     PRThreadState state,
+				     PRUint32 stackSize);
+
+/*
+** Same as PR_AttachThread except that the thread being attached is marked as 
+** garbage collectible.
+*/
+NSPR_API(PRThread*) PR_AttachThreadGCAble(PRThreadType type,
+					PRThreadPriority priority,
+					PRThreadStack *stack);
+
+/*
+** Mark the thread as garbage collectible.
+*/
+NSPR_API(void) PR_SetThreadGCAble(void);
+
+/*
+** Unmark the thread as garbage collectible.
+*/
+NSPR_API(void) PR_ClearThreadGCAble(void);
+
+/*
+** This routine prevents all other GC able threads from running. This call is needed by 
+** the garbage collector.
+*/
+NSPR_API(void) PR_SuspendAll(void);
+
+/*
+** This routine unblocks all other GC able threads that were suspended from running by 
+** PR_SuspendAll(). This call is needed by the garbage collector.
+*/
+NSPR_API(void) PR_ResumeAll(void);
+
+/*
+** Return the thread stack pointer of the given thread. 
+** Needed by the garbage collector.
+*/
+NSPR_API(void *) PR_GetSP(PRThread *thread);
+
+/*
+** Save the registers that the GC would find interesting into the thread
+** "t". isCurrent will be non-zero if the thread state that is being
+** saved is the currently executing thread. Return the address of the
+** first register to be scanned as well as the number of registers to
+** scan in "np".
+**
+** If "isCurrent" is non-zero then it is allowed for the thread context
+** area to be used as scratch storage to hold just the registers
+** necessary for scanning.
+**
+** This function simply calls the internal function _MD_HomeGCRegisters().
+*/
+NSPR_API(PRWord *) PR_GetGCRegisters(PRThread *t, int isCurrent, int *np);
+
+/*
+** (Get|Set)ExecutionEnvironent
+**
+** Used by Java to associate it's execution environment so garbage collector
+** can find it. If return is NULL, then it's probably not a collectable thread.
+**
+** There's no locking required around these calls.
+*/
+NSPR_API(void*) GetExecutionEnvironment(PRThread *thread);
+NSPR_API(void) SetExecutionEnvironment(PRThread* thread, void *environment);
+
+/*
+** Enumeration function that applies "func(thread,i,arg)" to each active
+** thread in the process. The enumerator returns PR_SUCCESS if the enumeration
+** should continue, any other value is considered failure, and enumeration
+** stops, returning the failure value from PR_EnumerateThreads.
+** Needed by the garbage collector.
+*/
+typedef PRStatus (PR_CALLBACK *PREnumerator)(PRThread *t, int i, void *arg);
+NSPR_API(PRStatus) PR_EnumerateThreads(PREnumerator func, void *arg);
+
+/* 
+** Signature of a thread stack scanning function. It is applied to every
+** contiguous group of potential pointers within a thread. Count denotes the
+** number of pointers. 
+*/
+typedef PRStatus 
+(PR_CALLBACK *PRScanStackFun)(PRThread* t,
+			      void** baseAddr, PRUword count, void* closure);
+
+/*
+** Applies scanFun to all contiguous groups of potential pointers 
+** within a thread. This includes the stack, registers, and thread-local
+** data. If scanFun returns a status value other than PR_SUCCESS the scan
+** is aborted, and the status value is returned. 
+*/
+NSPR_API(PRStatus)
+PR_ThreadScanStackPointers(PRThread* t,
+                           PRScanStackFun scanFun, void* scanClosure);
+
+/* 
+** Calls PR_ThreadScanStackPointers for every thread.
+*/
+NSPR_API(PRStatus)
+PR_ScanStackPointers(PRScanStackFun scanFun, void* scanClosure);
+
+/*
+** Returns a conservative estimate on the amount of stack space left
+** on a thread in bytes, sufficient for making decisions about whether 
+** to continue recursing or not.
+*/
+NSPR_API(PRUword)
+PR_GetStackSpaceLeft(PRThread* t);
+
+/*---------------------------------------------------------------------------
+** THREAD CPU PRIVATE FUNCTIONS             
+---------------------------------------------------------------------------*/
+
+/*
+** Get a pointer to the primordial CPU.
+*/
+NSPR_API(struct _PRCPU *) _PR_GetPrimordialCPU(void);
+
+/*---------------------------------------------------------------------------
+** THREAD SYNCHRONIZATION PRIVATE FUNCTIONS
+---------------------------------------------------------------------------*/
+
+/*
+** Create a new named monitor (named for debugging purposes).
+**  Monitors are re-entrant locks with a built-in condition variable.
+**
+** This may fail if memory is tight or if some operating system resource
+** is low.
+*/
+NSPR_API(PRMonitor*) PR_NewNamedMonitor(const char* name);
+
+/*
+** Test and then lock the lock if it's not already locked by some other
+** thread. Return PR_FALSE if some other thread owned the lock at the
+** time of the call.
+*/
+NSPR_API(PRBool) PR_TestAndLock(PRLock *lock);
+
+/*
+** Test and then enter the mutex associated with the monitor if it's not
+** already entered by some other thread. Return PR_FALSE if some other
+** thread owned the mutex at the time of the call.
+*/
+NSPR_API(PRBool) PR_TestAndEnterMonitor(PRMonitor *mon);
+
+/*
+** Return the number of times that the current thread has entered the
+** mutex. Returns zero if the current thread has not entered the mutex.
+*/
+NSPR_API(PRIntn) PR_GetMonitorEntryCount(PRMonitor *mon);
+
+/*
+** Just like PR_CEnterMonitor except that if the monitor is owned by
+** another thread NULL is returned.
+*/
+NSPR_API(PRMonitor*) PR_CTestAndEnterMonitor(void *address);
+
+/*---------------------------------------------------------------------------
+** PLATFORM-SPECIFIC INITIALIZATION FUNCTIONS
+---------------------------------------------------------------------------*/
+#if defined(IRIX)
+/*
+** Irix specific initialization funtion to be called before PR_Init
+** is called by the application. Sets the CONF_INITUSERS and CONF_INITSIZE
+** attributes of the shared arena set up by nspr.
+**
+** The environment variables _NSPR_IRIX_INITUSERS and _NSPR_IRIX_INITSIZE
+** can also be used to set these arena attributes. If _NSPR_IRIX_INITUSERS
+** is set, but not _NSPR_IRIX_INITSIZE, the value of the CONF_INITSIZE
+** attribute of the nspr arena is scaled as a function of the
+** _NSPR_IRIX_INITUSERS value.
+** 
+** If the _PR_Irix_Set_Arena_Params() is called in addition to setting the
+** environment variables, the values of the environment variables are used.
+** 
+*/
+NSPR_API(void) _PR_Irix_Set_Arena_Params(PRInt32 initusers, PRInt32 initsize);
+
+#endif /* IRIX */
+
+#if defined(XP_OS2)
+/*
+** These functions need to be called at the start and end of a thread.
+** An EXCEPTIONREGISTRATIONRECORD must be declared on the stack and its
+** address passed to the two functions.
+*/
+NSPR_API(void) PR_OS2_SetFloatExcpHandler(EXCEPTIONREGISTRATIONRECORD* e);
+NSPR_API(void) PR_OS2_UnsetFloatExcpHandler(EXCEPTIONREGISTRATIONRECORD* e);
+#endif /* XP_OS2 */
+
+/* I think PR_GetMonitorEntryCount is useless. All you really want is this... */
+#define PR_InMonitor(m)		(PR_GetMonitorEntryCount(m) > 0)
+
+/*---------------------------------------------------------------------------
+** Special X-Lock hack for client
+---------------------------------------------------------------------------*/
+
+#ifdef XP_UNIX
+extern void PR_XLock(void);
+extern void PR_XUnlock(void);
+extern PRBool PR_XIsLocked(void);
+#endif /* XP_UNIX */
+
+PR_END_EXTERN_C
+
+#endif /* pprthred_h___ */
diff --git a/pr/include/private/primpl.h b/pr/include/private/primpl.h
new file mode 100644
index 0000000..63ba3ee
--- /dev/null
+++ b/pr/include/private/primpl.h
@@ -0,0 +1,2151 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef primpl_h___
+#define primpl_h___
+
+/*
+ * HP-UX 10.10's pthread.h (DCE threads) includes dce/cma.h, which
+ * has:
+ *     #define sigaction _sigaction_sys
+ * This macro causes chaos if signal.h gets included before pthread.h.
+ * To be safe, we include pthread.h first.
+ */
+
+#if defined(_PR_PTHREADS)
+#include <pthread.h>
+#endif
+
+#if defined(_PR_BTHREADS)
+#include <kernel/OS.h>
+#endif
+
+#ifdef WIN32
+/*
+ * Allow use of functions and symbols first defined in Win2k.
+ */
+#if !defined(WINVER) || (WINVER < 0x0500)
+#undef WINVER
+#define WINVER 0x0500
+#endif
+#if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0500)
+#undef _WIN32_WINNT
+#define _WIN32_WINNT 0x0500
+#endif
+#endif /* WIN32 */
+
+#include "nspr.h"
+#include "prpriv.h"
+
+typedef struct PRSegment PRSegment;
+
+#include "md/prosdep.h"
+#include "obsolete/probslet.h"
+
+#ifdef _PR_HAVE_POSIX_SEMAPHORES
+#include <semaphore.h>
+#elif defined(_PR_HAVE_SYSV_SEMAPHORES)
+#include <sys/sem.h>
+#endif
+
+#ifdef HAVE_SYSCALL
+#include <sys/syscall.h>
+#endif
+
+/*************************************************************************
+*****  A Word about Model Dependent Function Naming Convention ***********
+*************************************************************************/
+
+/*
+NSPR 2.0 must implement its function across a range of platforms 
+including: MAC, Windows/16, Windows/95, Windows/NT, and several
+variants of Unix. Each implementation shares common code as well 
+as having platform dependent portions. This standard describes how
+the model dependent portions are to be implemented.
+
+In header file pr/include/primpl.h, each publicly declared 
+platform dependent function is declared as:
+
+NSPR_API void _PR_MD_FUNCTION( long arg1, long arg2 );
+#define _PR_MD_FUNCTION _MD_FUNCTION
+
+In header file pr/include/md/<platform>/_<platform>.h, 
+each #define'd macro is redefined as one of:
+
+#define _MD_FUNCTION <blanks>
+#define _MD_FUNCTION <expanded macro>
+#define _MD_FUNCTION <osFunction>
+#define _MD_FUNCTION <_MD_Function>
+
+Where:
+
+<blanks> is no definition at all. In this case, the function is not implemented 
+and is never called for this platform. 
+For example: 
+#define _MD_INIT_CPUS()
+
+<expanded macro> is a C language macro expansion. 
+For example: 
+#define        _MD_CLEAN_THREAD(_thread) \
+    PR_BEGIN_MACRO \
+        PR_DestroyCondVar(_thread->md.asyncIOCVar); \
+        PR_DestroyLock(_thread->md.asyncIOLock); \
+    PR_END_MACRO
+
+<osFunction> is some function implemented by the host operating system. 
+For example: 
+#define _MD_EXIT        exit
+
+<_MD_function> is the name of a function implemented for this platform in 
+pr/src/md/<platform>/<soruce>.c file. 
+For example: 
+#define        _MD_GETFILEINFO         _MD_GetFileInfo
+
+In <source>.c, the implementation is:
+PR_IMPLEMENT(PRInt32) _MD_GetFileInfo(const char *fn, PRFileInfo *info);
+*/
+
+PR_BEGIN_EXTERN_C
+
+typedef struct _MDLock _MDLock;
+typedef struct _MDCVar _MDCVar;
+typedef struct _MDSegment _MDSegment;
+typedef struct _MDThread _MDThread;
+typedef struct _MDThreadStack _MDThreadStack;
+typedef struct _MDSemaphore _MDSemaphore;
+typedef struct _MDDir _MDDir;
+#ifdef MOZ_UNICODE
+typedef struct _MDDirUTF16 _MDDirUTF16;
+#endif /* MOZ_UNICODE */
+typedef struct _MDFileDesc _MDFileDesc;
+typedef struct _MDProcess _MDProcess;
+typedef struct _MDFileMap _MDFileMap;
+
+#if defined(_PR_PTHREADS)
+
+/*
+** The following definitions are unique to implementing NSPR using pthreads.
+** Since pthreads defines most of the thread and thread synchronization
+** stuff, this is a pretty small set.
+*/
+
+#define PT_CV_NOTIFIED_LENGTH 6
+typedef struct _PT_Notified _PT_Notified;
+struct _PT_Notified
+{
+    PRIntn length;              /* # of used entries in this structure */
+    struct
+    {
+        PRCondVar *cv;          /* the condition variable notified */
+        PRIntn times;           /* and the number of times notified */
+    } cv[PT_CV_NOTIFIED_LENGTH];
+    _PT_Notified *link;         /* link to another of these | NULL */
+};
+
+/*
+ * bits defined for pthreads 'state' field 
+ */
+#define PT_THREAD_DETACHED  0x01    /* thread can't be joined */
+#define PT_THREAD_GLOBAL    0x02    /* a global thread (unlikely) */
+#define PT_THREAD_SYSTEM    0x04    /* system (not user) thread */
+#define PT_THREAD_PRIMORD   0x08    /* this is the primordial thread */
+#define PT_THREAD_ABORTED   0x10    /* thread has been interrupted */
+#define PT_THREAD_GCABLE    0x20    /* thread is garbage collectible */
+#define PT_THREAD_SUSPENDED 0x40    /* thread has been suspended */
+#define PT_THREAD_FOREIGN   0x80    /* thread is not one of ours */
+#define PT_THREAD_BOUND     0x100    /* a bound-global thread */
+
+#define _PT_THREAD_INTERRUPTED(thr)					\
+		(!(thr->interrupt_blocked) && (thr->state & PT_THREAD_ABORTED))
+#define _PT_THREAD_BLOCK_INTERRUPT(thr)				\
+		(thr->interrupt_blocked = 1)
+#define _PT_THREAD_UNBLOCK_INTERRUPT(thr)			\
+		(thr->interrupt_blocked = 0)
+
+#define _PT_IS_GCABLE_THREAD(thr) ((thr)->state & PT_THREAD_GCABLE)
+
+/* 
+** Possible values for thread's suspend field
+** Note that the first two can be the same as they are really mutually exclusive,
+** i.e. both cannot be happening at the same time. We have two symbolic names
+** just as a mnemonic.
+**/
+#define PT_THREAD_RESUMED   0x80    /* thread has been resumed */
+#define PT_THREAD_SETGCABLE 0x100   /* set the GCAble flag */
+
+#if defined(DEBUG)
+
+typedef struct PTDebug
+{
+    PRTime timeStarted;
+    PRUintn locks_created, locks_destroyed;
+    PRUintn locks_acquired, locks_released;
+    PRUintn cvars_created, cvars_destroyed;
+    PRUintn cvars_notified, delayed_cv_deletes;
+} PTDebug;
+
+#endif /* defined(DEBUG) */
+
+NSPR_API(void) PT_FPrintStats(PRFileDesc *fd, const char *msg);
+
+/*
+ * On Linux and its derivatives POSIX priority scheduling works only for
+ * real-time threads. On those platforms we set thread's nice values
+ * instead which requires us to track kernel thread IDs for each POSIX
+ * thread we create.
+ */
+#if defined(LINUX) && defined(HAVE_SETPRIORITY) && \
+    ((defined(HAVE_SYSCALL) && defined(SYS_gettid)) || defined(HAVE_GETTID))
+#define _PR_NICE_PRIORITY_SCHEDULING
+#endif
+
+#else /* defined(_PR_PTHREADS) */
+
+NSPR_API(void) PT_FPrintStats(PRFileDesc *fd, const char *msg);
+
+/*
+** This section is contains those parts needed to implement NSPR on
+** platforms in general. One would assume that the pthreads implementation
+** included lots of the same types, at least conceptually.
+*/
+
+/*
+ * Local threads only.  No multiple CPU support and hence all the
+ * following routines are no-op.
+ */
+#ifdef _PR_LOCAL_THREADS_ONLY
+
+#define        _PR_MD_SUSPEND_THREAD(thread)        
+#define        _PR_MD_RESUME_THREAD(thread)        
+#define        _PR_MD_SUSPEND_CPU(cpu)        
+#define        _PR_MD_RESUME_CPU(cpu)        
+#define        _PR_MD_BEGIN_SUSPEND_ALL()        
+#define        _PR_MD_END_SUSPEND_ALL()        
+#define        _PR_MD_BEGIN_RESUME_ALL()        
+#define        _PR_MD_END_RESUME_ALL()
+#define _PR_MD_INIT_ATTACHED_THREAD(thread) PR_FAILURE
+
+#endif
+
+typedef struct _PRCPUQueue _PRCPUQueue;
+typedef struct _PRCPU _PRCPU;
+typedef struct _MDCPU _MDCPU;
+
+struct _PRCPUQueue {
+    _MDLock  runQLock;          /* lock for the run + wait queues */
+    _MDLock  sleepQLock;        /* lock for the run + wait queues */
+    _MDLock  miscQLock;         /* lock for the run + wait queues */
+
+    PRCList runQ[PR_PRIORITY_LAST + 1]; /* run queue for this CPU */
+    PRUint32  runQReadyMask;
+    PRCList sleepQ;
+    PRIntervalTime sleepQmax;
+    PRCList pauseQ;
+    PRCList suspendQ;
+    PRCList waitingToJoinQ;
+
+    PRUintn   numCPUs;          /* number of CPUs using this Q */
+};
+
+struct _PRCPU {
+    PRCList links;              /* link list of CPUs */
+    PRUint32 id;                /* id for this CPU */
+
+    union {
+        PRInt32 bits;
+        PRUint8 missed[4];
+    } u;
+    PRIntn where;               /* index into u.missed */
+    PRPackedBool paused;        /* cpu is paused */
+    PRPackedBool exit;          /* cpu should exit */
+
+    PRThread *thread;           /* native thread for this CPUThread */
+    PRThread *idle_thread;      /* user-level idle thread for this CPUThread */
+
+    PRIntervalTime last_clock;  /* the last time we went into 
+                                 * _PR_ClockInterrupt() on this CPU
+                                 */
+
+    _PRCPUQueue *queue;
+
+    _MDCPU md;
+};
+
+typedef struct _PRInterruptTable {
+    const char *name;
+    PRUintn missed_bit;
+    void (*handler)(void);
+} _PRInterruptTable;
+
+#define _PR_CPU_PTR(_qp) \
+    ((_PRCPU*) ((char*) (_qp) - offsetof(_PRCPU,links)))
+
+#if !defined(IRIX) && !defined(WIN32) && !defined(XP_OS2) \
+        && !(defined(SOLARIS) && defined(_PR_GLOBAL_THREADS_ONLY))
+#define _MD_GET_ATTACHED_THREAD()        (_PR_MD_CURRENT_THREAD())
+#endif
+
+#ifdef _PR_LOCAL_THREADS_ONLY 
+
+NSPR_API(struct _PRCPU *)              _pr_currentCPU;
+NSPR_API(PRThread *)                   _pr_currentThread;
+NSPR_API(PRThread *)                   _pr_lastThread;
+NSPR_API(PRInt32)                      _pr_intsOff;
+
+#define _MD_CURRENT_CPU()               (_pr_currentCPU)
+#define _MD_SET_CURRENT_CPU(_cpu)       (_pr_currentCPU = (_cpu))
+#define _MD_CURRENT_THREAD()            (_pr_currentThread)
+#define _MD_SET_CURRENT_THREAD(_thread) (_pr_currentThread = (_thread))
+#define _MD_LAST_THREAD()               (_pr_lastThread)
+#define _MD_SET_LAST_THREAD(t)          (_pr_lastThread = t)
+
+#define _MD_GET_INTSOFF()               (_pr_intsOff)
+#define _MD_SET_INTSOFF(_val)           (_pr_intsOff = _val)
+
+
+/* The unbalanced curly braces in these two macros are intentional */
+#define _PR_LOCK_HEAP() { PRIntn _is; if (_pr_currentCPU) _PR_INTSOFF(_is);
+#define _PR_UNLOCK_HEAP() if (_pr_currentCPU) _PR_INTSON(_is); }
+
+#endif /* _PR_LOCAL_THREADS_ONLY */
+
+extern PRInt32                  _native_threads_only;
+
+#if defined(_PR_GLOBAL_THREADS_ONLY)
+
+#define _MD_GET_INTSOFF() 0
+#define _MD_SET_INTSOFF(_val)
+#define _PR_INTSOFF(_is)
+#define _PR_FAST_INTSON(_is)
+#define _PR_INTSON(_is)
+#define _PR_THREAD_LOCK(_thread)
+#define _PR_THREAD_UNLOCK(_thread)
+#define _PR_RUNQ_LOCK(cpu)
+#define _PR_RUNQ_UNLOCK(cpu)
+#define _PR_SLEEPQ_LOCK(thread)
+#define _PR_SLEEPQ_UNLOCK(thread)
+#define _PR_MISCQ_LOCK(thread)
+#define _PR_MISCQ_UNLOCK(thread)
+#define _PR_CPU_LIST_LOCK()
+#define _PR_CPU_LIST_UNLOCK()
+
+#define _PR_ADD_RUNQ(_thread, _cpu, _pri)
+#define _PR_DEL_RUNQ(_thread)
+#define _PR_ADD_SLEEPQ(_thread, _timeout)
+#define _PR_DEL_SLEEPQ(_thread, _propogate)
+#define _PR_ADD_JOINQ(_thread, _cpu)
+#define _PR_DEL_JOINQ(_thread)
+#define _PR_ADD_SUSPENDQ(_thread, _cpu)
+#define _PR_DEL_SUSPENDQ(_thread)
+
+#define _PR_THREAD_SWITCH_CPU(_thread, _newCPU)
+
+#define _PR_IS_NATIVE_THREAD(thread) 1
+#define _PR_IS_NATIVE_THREAD_SUPPORTED() 1
+
+#else
+
+#define _PR_INTSOFF(_is) \
+    PR_BEGIN_MACRO \
+        (_is) = _PR_MD_GET_INTSOFF(); \
+        _PR_MD_SET_INTSOFF(1); \
+    PR_END_MACRO
+
+#define _PR_FAST_INTSON(_is) \
+    PR_BEGIN_MACRO \
+        _PR_MD_SET_INTSOFF(_is); \
+    PR_END_MACRO
+
+#define _PR_INTSON(_is) \
+    PR_BEGIN_MACRO \
+        if ((_is == 0) && (_PR_MD_CURRENT_CPU())->u.bits) \
+                _PR_IntsOn((_PR_MD_CURRENT_CPU())); \
+        _PR_MD_SET_INTSOFF(_is); \
+    PR_END_MACRO
+
+#ifdef _PR_LOCAL_THREADS_ONLY 
+
+#define _PR_IS_NATIVE_THREAD(thread) 0
+#define _PR_THREAD_LOCK(_thread)
+#define _PR_THREAD_UNLOCK(_thread)
+#define _PR_RUNQ_LOCK(cpu)
+#define _PR_RUNQ_UNLOCK(cpu)
+#define _PR_SLEEPQ_LOCK(thread)
+#define _PR_SLEEPQ_UNLOCK(thread)
+#define _PR_MISCQ_LOCK(thread)
+#define _PR_MISCQ_UNLOCK(thread)
+#define _PR_CPU_LIST_LOCK()
+#define _PR_CPU_LIST_UNLOCK()
+
+#define _PR_ADD_RUNQ(_thread, _cpu, _pri) \
+    PR_BEGIN_MACRO \
+    PR_APPEND_LINK(&(_thread)->links, &_PR_RUNQ(_cpu)[_pri]); \
+    _PR_RUNQREADYMASK(_cpu) |= (1L << _pri); \
+    PR_END_MACRO
+
+#define _PR_DEL_RUNQ(_thread) \
+    PR_BEGIN_MACRO \
+    _PRCPU *_cpu = _thread->cpu; \
+    PRInt32 _pri = _thread->priority; \
+    PR_REMOVE_LINK(&(_thread)->links); \
+    if (PR_CLIST_IS_EMPTY(&_PR_RUNQ(_cpu)[_pri])) \
+        _PR_RUNQREADYMASK(_cpu) &= ~(1L << _pri); \
+    PR_END_MACRO
+
+#define _PR_ADD_SLEEPQ(_thread, _timeout) \
+    _PR_AddSleepQ(_thread, _timeout);   
+
+#define _PR_DEL_SLEEPQ(_thread, _propogate) \
+    _PR_DelSleepQ(_thread, _propogate);  
+
+#define _PR_ADD_JOINQ(_thread, _cpu) \
+    PR_APPEND_LINK(&(_thread)->links, &_PR_WAITINGTOJOINQ(_cpu));
+
+#define _PR_DEL_JOINQ(_thread) \
+    PR_REMOVE_LINK(&(_thread)->links);
+
+#define _PR_ADD_SUSPENDQ(_thread, _cpu) \
+    PR_APPEND_LINK(&(_thread)->links, &_PR_SUSPENDQ(_cpu));
+
+#define _PR_DEL_SUSPENDQ(_thread) \
+    PR_REMOVE_LINK(&(_thread)->links);
+
+#define _PR_THREAD_SWITCH_CPU(_thread, _newCPU)
+
+#define _PR_IS_NATIVE_THREAD_SUPPORTED() 0
+
+#else        /* _PR_LOCAL_THREADS_ONLY */
+
+/* These are for the "combined" thread model */
+
+#define _PR_THREAD_LOCK(_thread) \
+    _PR_MD_LOCK(&(_thread)->threadLock);
+
+#define _PR_THREAD_UNLOCK(_thread) \
+    _PR_MD_UNLOCK(&(_thread)->threadLock);
+
+#define _PR_RUNQ_LOCK(_cpu) \
+    PR_BEGIN_MACRO \
+    _PR_MD_LOCK(&(_cpu)->queue->runQLock );\
+    PR_END_MACRO
+    
+#define _PR_RUNQ_UNLOCK(_cpu) \
+    PR_BEGIN_MACRO \
+    _PR_MD_UNLOCK(&(_cpu)->queue->runQLock );\
+    PR_END_MACRO
+
+#define _PR_SLEEPQ_LOCK(_cpu) \
+    _PR_MD_LOCK(&(_cpu)->queue->sleepQLock );
+
+#define _PR_SLEEPQ_UNLOCK(_cpu) \
+    _PR_MD_UNLOCK(&(_cpu)->queue->sleepQLock );
+
+#define _PR_MISCQ_LOCK(_cpu) \
+    _PR_MD_LOCK(&(_cpu)->queue->miscQLock );
+
+#define _PR_MISCQ_UNLOCK(_cpu) \
+    _PR_MD_UNLOCK(&(_cpu)->queue->miscQLock );
+
+#define _PR_CPU_LIST_LOCK()                 _PR_MD_LOCK(&_pr_cpuLock)
+#define _PR_CPU_LIST_UNLOCK()               _PR_MD_UNLOCK(&_pr_cpuLock)
+
+#define QUEUE_RUN           0x1
+#define QUEUE_SLEEP         0x2
+#define QUEUE_JOIN          0x4
+#define QUEUE_SUSPEND       0x8
+#define QUEUE_LOCK          0x10
+
+#define _PR_ADD_RUNQ(_thread, _cpu, _pri) \
+    PR_BEGIN_MACRO \
+    PR_APPEND_LINK(&(_thread)->links, &_PR_RUNQ(_cpu)[_pri]); \
+    _PR_RUNQREADYMASK(_cpu) |= (1L << _pri); \
+    PR_ASSERT((_thread)->queueCount == 0); \
+    (_thread)->queueCount = QUEUE_RUN; \
+    PR_END_MACRO
+
+#define _PR_DEL_RUNQ(_thread) \
+    PR_BEGIN_MACRO \
+    _PRCPU *_cpu = _thread->cpu; \
+    PRInt32 _pri = _thread->priority; \
+    PR_REMOVE_LINK(&(_thread)->links); \
+    if (PR_CLIST_IS_EMPTY(&_PR_RUNQ(_cpu)[_pri])) \
+        _PR_RUNQREADYMASK(_cpu) &= ~(1L << _pri); \
+    PR_ASSERT((_thread)->queueCount == QUEUE_RUN);\
+    (_thread)->queueCount = 0; \
+    PR_END_MACRO
+
+#define _PR_ADD_SLEEPQ(_thread, _timeout) \
+    PR_ASSERT((_thread)->queueCount == 0); \
+    (_thread)->queueCount = QUEUE_SLEEP; \
+    _PR_AddSleepQ(_thread, _timeout);  
+
+#define _PR_DEL_SLEEPQ(_thread, _propogate) \
+    PR_ASSERT((_thread)->queueCount == QUEUE_SLEEP);\
+    (_thread)->queueCount = 0; \
+    _PR_DelSleepQ(_thread, _propogate);  
+
+#define _PR_ADD_JOINQ(_thread, _cpu) \
+    PR_ASSERT((_thread)->queueCount == 0); \
+    (_thread)->queueCount = QUEUE_JOIN; \
+    PR_APPEND_LINK(&(_thread)->links, &_PR_WAITINGTOJOINQ(_cpu));
+
+#define _PR_DEL_JOINQ(_thread) \
+    PR_ASSERT((_thread)->queueCount == QUEUE_JOIN);\
+    (_thread)->queueCount = 0; \
+    PR_REMOVE_LINK(&(_thread)->links);
+
+#define _PR_ADD_SUSPENDQ(_thread, _cpu) \
+    PR_ASSERT((_thread)->queueCount == 0); \
+    (_thread)->queueCount = QUEUE_SUSPEND; \
+    PR_APPEND_LINK(&(_thread)->links, &_PR_SUSPENDQ(_cpu));
+
+#define _PR_DEL_SUSPENDQ(_thread) \
+    PR_ASSERT((_thread)->queueCount == QUEUE_SUSPEND);\
+    (_thread)->queueCount = 0; \
+    PR_REMOVE_LINK(&(_thread)->links);
+
+#define _PR_THREAD_SWITCH_CPU(_thread, _newCPU) \
+    (_thread)->cpu = (_newCPU);
+
+#define _PR_IS_NATIVE_THREAD(thread) (thread->flags & _PR_GLOBAL_SCOPE)
+#define _PR_IS_NATIVE_THREAD_SUPPORTED() 1
+
+#endif /* _PR_LOCAL_THREADS_ONLY */
+
+#endif /* _PR_GLOBAL_THREADS_ONLY */
+
+#define _PR_SET_RESCHED_FLAG() _PR_MD_CURRENT_CPU()->u.missed[3] = 1
+#define _PR_CLEAR_RESCHED_FLAG() _PR_MD_CURRENT_CPU()->u.missed[3] = 0
+
+extern _PRInterruptTable _pr_interruptTable[];
+
+/* Bits for _pr_interruptState.u.missed[0,1] */
+#define _PR_MISSED_CLOCK    0x1
+#define _PR_MISSED_IO        0x2
+#define _PR_MISSED_CHILD    0x4
+
+extern void _PR_IntsOn(_PRCPU *cpu);
+
+NSPR_API(void) _PR_WakeupCPU(void);
+NSPR_API(void) _PR_PauseCPU(void);
+
+/************************************************************************/
+
+#define _PR_LOCK_LOCK(_lock) \
+    _PR_MD_LOCK(&(_lock)->ilock);
+#define _PR_LOCK_UNLOCK(_lock) \
+    _PR_MD_UNLOCK(&(_lock)->ilock);
+    
+extern void _PR_UnblockLockWaiter(PRLock *lock);
+extern PRStatus _PR_InitLock(PRLock *lock);
+extern void _PR_FreeLock(PRLock *lock);
+
+#define _PR_LOCK_PTR(_qp) \
+    ((PRLock*) ((char*) (_qp) - offsetof(PRLock,links)))
+
+/************************************************************************/
+
+#define _PR_CVAR_LOCK(_cvar) \
+    _PR_MD_LOCK(&(_cvar)->ilock); 
+#define _PR_CVAR_UNLOCK(_cvar) \
+    _PR_MD_UNLOCK(&(_cvar)->ilock);
+
+extern PRStatus _PR_InitCondVar(PRCondVar *cvar, PRLock *lock);
+extern void _PR_FreeCondVar(PRCondVar *cvar);
+extern PRStatus _PR_WaitCondVar(
+    PRThread *thread, PRCondVar *cvar, PRLock *lock, PRIntervalTime timeout);
+extern void _PR_NotifyCondVar(PRCondVar *cvar, PRThread *me);
+extern PRUint32 _PR_CondVarToString(PRCondVar *cvar, char *buf, PRUint32 buflen);
+
+NSPR_API(void) _PR_Notify(PRMonitor *mon, PRBool all, PRBool sticky);
+
+/* PRThread.flags */
+#define _PR_SYSTEM          0x01
+#define _PR_INTERRUPT       0x02
+#define _PR_ATTACHED        0x04        /* created via PR_AttachThread */
+#define _PR_PRIMORDIAL      0x08        /* the thread that called PR_Init */
+#define _PR_ON_SLEEPQ       0x10        /* thread is on the sleepQ */
+#define _PR_ON_PAUSEQ       0x20        /* thread is on the pauseQ */
+#define _PR_SUSPENDING      0x40        /* thread wants to suspend */
+#define _PR_GLOBAL_SCOPE    0x80        /* thread is global scope */
+#define _PR_IDLE_THREAD     0x200       /* this is an idle thread        */
+#define _PR_GCABLE_THREAD   0x400       /* this is a collectable thread */
+#define _PR_BOUND_THREAD    0x800       /* a bound thread */
+#define _PR_INTERRUPT_BLOCKED	0x1000	/* interrupts blocked */
+
+/* PRThread.state */
+#define _PR_UNBORN       0
+#define _PR_RUNNABLE     1
+#define _PR_RUNNING      2
+#define _PR_LOCK_WAIT    3
+#define _PR_COND_WAIT    4
+#define _PR_JOIN_WAIT    5
+#define _PR_IO_WAIT      6
+#define _PR_SUSPENDED    7
+#define _PR_DEAD_STATE   8  /* for debugging */
+
+/* PRThreadStack.flags */
+#define _PR_STACK_VM            0x1    /* using vm instead of malloc */
+#define _PR_STACK_MAPPED        0x2    /* vm is mapped */
+#define _PR_STACK_PRIMORDIAL    0x4    /* stack for primordial thread */
+
+/* 
+** If the default stcksize from the client is zero, we need to pick a machine
+** dependent value.  This is only for standard user threads.  For custom threads,
+** 0 has a special meaning.
+** Adjust stackSize. Round up to a page boundary.
+*/
+
+#ifndef _MD_MINIMUM_STACK_SIZE
+#define _MD_MINIMUM_STACK_SIZE	0
+#endif
+
+#if (!defined(HAVE_CUSTOM_USER_THREADS))
+#define        _PR_ADJUST_STACKSIZE(stackSize) \
+        PR_BEGIN_MACRO \
+    if (stackSize == 0) \
+                stackSize = _MD_DEFAULT_STACK_SIZE; \
+    if (stackSize < _MD_MINIMUM_STACK_SIZE) \
+                stackSize = _MD_MINIMUM_STACK_SIZE; \
+    stackSize = (stackSize + (1 << _pr_pageShift) - 1) >> _pr_pageShift; \
+    stackSize <<= _pr_pageShift; \
+        PR_END_MACRO
+#else
+#define        _PR_ADJUST_STACKSIZE(stackSize)
+#endif
+
+#define _PR_IS_GCABLE_THREAD(thr) ((thr)->flags & _PR_GCABLE_THREAD)
+
+#define _PR_PENDING_INTERRUPT(thr)					\
+		(!((thr)->flags & _PR_INTERRUPT_BLOCKED) && ((thr)->flags & _PR_INTERRUPT))
+#define _PR_THREAD_BLOCK_INTERRUPT(thr)			\
+		(thr->flags |= _PR_INTERRUPT_BLOCKED)
+#define _PR_THREAD_UNBLOCK_INTERRUPT(thr)			\
+		(thr->flags &= ~_PR_INTERRUPT_BLOCKED)
+
+#define _PR_THREAD_PTR(_qp) \
+    ((PRThread*) ((char*) (_qp) - offsetof(PRThread,links)))
+
+#define _PR_ACTIVE_THREAD_PTR(_qp) \
+    ((PRThread*) ((char*) (_qp) - offsetof(PRThread,active)))
+
+#define _PR_THREAD_CONDQ_PTR(_qp) \
+    ((PRThread*) ((char*) (_qp) - offsetof(PRThread,waitQLinks)))
+
+#define _PR_THREAD_MD_TO_PTR(_md) \
+    ((PRThread*) ((char*) (_md) - offsetof(PRThread,md)))
+
+#define _PR_THREAD_STACK_TO_PTR(_stack) \
+    ((PRThread*) (_stack->thr))
+
+extern PRCList _pr_active_local_threadQ;
+extern PRCList _pr_active_global_threadQ;
+extern PRCList _pr_cpuQ;
+extern _MDLock  _pr_cpuLock;
+extern PRInt32 _pr_md_idle_cpus;
+
+#define _PR_ACTIVE_LOCAL_THREADQ()          _pr_active_local_threadQ
+#define _PR_ACTIVE_GLOBAL_THREADQ()         _pr_active_global_threadQ
+#define _PR_CPUQ()                          _pr_cpuQ
+#define _PR_RUNQ(_cpu)                      ((_cpu)->queue->runQ)
+#define _PR_RUNQREADYMASK(_cpu)             ((_cpu)->queue->runQReadyMask)
+#define _PR_SLEEPQ(_cpu)                    ((_cpu)->queue->sleepQ)
+#define _PR_SLEEPQMAX(_cpu)                 ((_cpu)->queue->sleepQmax)
+#define _PR_PAUSEQ(_cpu)                    ((_cpu)->queue->pauseQ)
+#define _PR_SUSPENDQ(_cpu)                  ((_cpu)->queue->suspendQ)
+#define _PR_WAITINGTOJOINQ(_cpu)            ((_cpu)->queue->waitingToJoinQ)
+
+extern PRUint32 _pr_recycleThreads;   /* Flag for behavior on thread cleanup */
+extern PRLock *_pr_deadQLock;
+extern PRUint32 _pr_numNativeDead;
+extern PRUint32 _pr_numUserDead;
+extern PRCList _pr_deadNativeQ;
+extern PRCList _pr_deadUserQ;
+#define _PR_DEADNATIVEQ     _pr_deadNativeQ
+#define _PR_DEADUSERQ       _pr_deadUserQ
+#define _PR_DEADQ_LOCK      PR_Lock(_pr_deadQLock);
+#define _PR_DEADQ_UNLOCK    PR_Unlock(_pr_deadQLock);
+#define _PR_INC_DEADNATIVE  (_pr_numNativeDead++)
+#define _PR_DEC_DEADNATIVE  (_pr_numNativeDead--)
+#define _PR_NUM_DEADNATIVE  (_pr_numNativeDead)
+#define _PR_INC_DEADUSER    (_pr_numUserDead++)
+#define _PR_DEC_DEADUSER    (_pr_numUserDead--)
+#define _PR_NUM_DEADUSER    (_pr_numUserDead)
+
+extern PRUint32 _pr_utid;
+
+extern struct _PRCPU  *_pr_primordialCPU;
+
+extern PRLock *_pr_activeLock;          /* lock for userActive and systemActive */
+extern PRInt32 _pr_userActive;          /* number of active user threads */
+extern PRInt32 _pr_systemActive;        /* number of active system threads */
+extern PRInt32 _pr_primordialExitCount; /* number of user threads left
+                                         * before the primordial thread
+                                         * can exit.  */
+extern PRCondVar *_pr_primordialExitCVar; /* the condition variable for
+                                           * notifying the primordial thread
+                                           * when all other user threads
+                                           * have terminated.  */
+
+extern PRUintn _pr_maxPTDs;
+
+extern PRLock *_pr_terminationCVLock;
+
+/*************************************************************************
+* Internal routines either called by PR itself or from machine-dependent *
+* code.                                                                  *
+*************************************************************************/
+
+extern void _PR_ClockInterrupt(void);
+
+extern void _PR_Schedule(void);
+extern void _PR_SetThreadPriority(
+    PRThread* thread, PRThreadPriority priority);
+
+/***********************************************************************
+** FUNCTION:	_PR_NewSegment()
+** DESCRIPTION:
+**   Allocate a memory segment. The "size" value is rounded up to the
+**   native system page size and a page aligned portion of memory is
+**   returned.  This memory is not part of the malloc heap. If "vaddr" is
+**   not NULL then PR tries to allocate the segment at the desired virtual
+**   address.
+** INPUTS:	size:  size of the desired memory segment
+**          vaddr:  address at which the newly aquired segment is to be
+**                  mapped into memory.
+** OUTPUTS:	a memory segment is allocated, a PRSegment is allocated
+** RETURN:	pointer to PRSegment
+***********************************************************************/
+extern PRSegment* _PR_NewSegment(PRUint32 size, void *vaddr);
+
+/***********************************************************************
+** FUNCTION:	_PR_DestroySegment()
+** DESCRIPTION:
+**   The memory segment and the PRSegment are freed
+** INPUTS:	seg:  pointer to PRSegment to be freed
+** OUTPUTS:	the the PRSegment and its associated memory segment are freed
+** RETURN:	void
+***********************************************************************/
+extern void _PR_DestroySegment(PRSegment *seg);
+
+extern PRThreadStack * _PR_NewStack(PRUint32 stackSize);
+extern void _PR_FreeStack(PRThreadStack *stack);
+extern PRBool _PR_NotifyThread (PRThread *thread, PRThread *me);
+extern void _PR_NotifyLockedThread (PRThread *thread);
+
+NSPR_API(void) _PR_AddSleepQ(PRThread *thread, PRIntervalTime timeout);
+NSPR_API(void) _PR_DelSleepQ(PRThread *thread, PRBool propogate_time);
+
+extern void _PR_AddThreadToRunQ(PRThread *me, PRThread *thread);
+
+NSPR_API(PRThread*) _PR_CreateThread(PRThreadType type,
+                                     void (*start)(void *arg),
+                                     void *arg,
+                                     PRThreadPriority priority,
+                                     PRThreadScope scope,
+                                     PRThreadState state,
+                                     PRUint32 stackSize,
+                     PRUint32 flags);
+
+extern void _PR_NativeDestroyThread(PRThread *thread);
+extern void _PR_UserDestroyThread(PRThread *thread);
+
+extern PRThread* _PRI_AttachThread(
+    PRThreadType type, PRThreadPriority priority,
+    PRThreadStack *stack, PRUint32 flags);
+
+extern void _PRI_DetachThread(void);
+
+
+#define _PR_IO_PENDING(_thread) ((_thread)->io_pending)
+
+NSPR_API(void) _PR_MD_INIT_CPUS();
+#define    _PR_MD_INIT_CPUS _MD_INIT_CPUS
+
+NSPR_API(void) _PR_MD_WAKEUP_CPUS();
+#define    _PR_MD_WAKEUP_CPUS _MD_WAKEUP_CPUS
+
+/* Interrupts related */
+
+NSPR_API(void) _PR_MD_START_INTERRUPTS(void);
+#define    _PR_MD_START_INTERRUPTS _MD_START_INTERRUPTS
+
+NSPR_API(void) _PR_MD_STOP_INTERRUPTS(void);
+#define    _PR_MD_STOP_INTERRUPTS _MD_STOP_INTERRUPTS
+
+NSPR_API(void) _PR_MD_ENABLE_CLOCK_INTERRUPTS(void);
+#define    _PR_MD_ENABLE_CLOCK_INTERRUPTS _MD_ENABLE_CLOCK_INTERRUPTS
+
+NSPR_API(void) _PR_MD_DISABLE_CLOCK_INTERRUPTS(void);
+#define    _PR_MD_DISABLE_CLOCK_INTERRUPTS _MD_DISABLE_CLOCK_INTERRUPTS
+
+NSPR_API(void) _PR_MD_BLOCK_CLOCK_INTERRUPTS(void);
+#define    _PR_MD_BLOCK_CLOCK_INTERRUPTS _MD_BLOCK_CLOCK_INTERRUPTS
+
+NSPR_API(void) _PR_MD_UNBLOCK_CLOCK_INTERRUPTS(void);
+#define    _PR_MD_UNBLOCK_CLOCK_INTERRUPTS _MD_UNBLOCK_CLOCK_INTERRUPTS
+
+/* The _PR_MD_WAIT_LOCK and _PR_MD_WAKEUP_WAITER functions put to sleep and
+ * awaken a thread which is waiting on a lock or cvar.
+ */
+extern PRStatus _PR_MD_WAIT(PRThread *, PRIntervalTime timeout);
+#define    _PR_MD_WAIT _MD_WAIT
+
+extern PRStatus _PR_MD_WAKEUP_WAITER(PRThread *);
+#define    _PR_MD_WAKEUP_WAITER _MD_WAKEUP_WAITER
+
+#ifndef _PR_LOCAL_THREADS_ONLY /* not if only local threads supported */
+NSPR_API(void) _PR_MD_CLOCK_INTERRUPT(void);
+#define    _PR_MD_CLOCK_INTERRUPT _MD_CLOCK_INTERRUPT
+#endif
+
+/* Stack debugging */
+NSPR_API(void) _PR_MD_INIT_STACK(PRThreadStack *ts, PRIntn redzone);
+#define    _PR_MD_INIT_STACK _MD_INIT_STACK
+
+NSPR_API(void) _PR_MD_CLEAR_STACK(PRThreadStack* ts);
+#define    _PR_MD_CLEAR_STACK _MD_CLEAR_STACK
+
+/* CPU related */
+NSPR_API(PRInt32) _PR_MD_GET_INTSOFF(void);
+#define    _PR_MD_GET_INTSOFF _MD_GET_INTSOFF
+
+NSPR_API(void) _PR_MD_SET_INTSOFF(PRInt32 _val);
+#define    _PR_MD_SET_INTSOFF _MD_SET_INTSOFF
+
+NSPR_API(_PRCPU*) _PR_MD_CURRENT_CPU(void);
+#define    _PR_MD_CURRENT_CPU _MD_CURRENT_CPU
+
+NSPR_API(void) _PR_MD_SET_CURRENT_CPU(_PRCPU *cpu);
+#define    _PR_MD_SET_CURRENT_CPU _MD_SET_CURRENT_CPU
+
+NSPR_API(void) _PR_MD_INIT_RUNNING_CPU(_PRCPU *cpu);
+#define    _PR_MD_INIT_RUNNING_CPU _MD_INIT_RUNNING_CPU
+
+/*
+ * Returns the number of threads awoken or 0 if a timeout occurred;
+ */
+extern PRInt32 _PR_MD_PAUSE_CPU(PRIntervalTime timeout);
+#define    _PR_MD_PAUSE_CPU _MD_PAUSE_CPU
+
+extern void _PR_MD_CLEANUP_BEFORE_EXIT(void);
+#define _PR_MD_CLEANUP_BEFORE_EXIT _MD_CLEANUP_BEFORE_EXIT
+
+extern void _PR_MD_EXIT(PRIntn status);
+#define    _PR_MD_EXIT _MD_EXIT
+
+/* Locks related */
+
+NSPR_API(void) _PR_MD_INIT_LOCKS(void);
+#define    _PR_MD_INIT_LOCKS _MD_INIT_LOCKS
+
+NSPR_API(PRStatus) _PR_MD_NEW_LOCK(_MDLock *md);
+#define    _PR_MD_NEW_LOCK _MD_NEW_LOCK
+
+NSPR_API(void) _PR_MD_FREE_LOCK(_MDLock *md);
+#define    _PR_MD_FREE_LOCK _MD_FREE_LOCK
+
+NSPR_API(void) _PR_MD_LOCK(_MDLock *md);
+#define    _PR_MD_LOCK _MD_LOCK
+
+/* Return 0 on success, a nonzero value on failure. */
+NSPR_API(PRIntn) _PR_MD_TEST_AND_LOCK(_MDLock *md);
+#define    _PR_MD_TEST_AND_LOCK _MD_TEST_AND_LOCK
+
+NSPR_API(void) _PR_MD_UNLOCK(_MDLock *md);
+#define    _PR_MD_UNLOCK _MD_UNLOCK
+
+NSPR_API(void) _PR_MD_IOQ_LOCK(void);
+#define    _PR_MD_IOQ_LOCK _MD_IOQ_LOCK
+
+NSPR_API(void) _PR_MD_IOQ_UNLOCK(void);
+#define    _PR_MD_IOQ_UNLOCK _MD_IOQ_UNLOCK
+
+#ifndef _PR_LOCAL_THREADS_ONLY /* not if only local threads supported */
+/* Semaphore related -- only for native threads */
+#ifdef HAVE_CVAR_BUILT_ON_SEM
+NSPR_API(void) _PR_MD_NEW_SEM(_MDSemaphore *md, PRUintn value);
+#define _PR_MD_NEW_SEM _MD_NEW_SEM
+
+NSPR_API(void) _PR_MD_DESTROY_SEM(_MDSemaphore *md);
+#define _PR_MD_DESTROY_SEM _MD_DESTROY_SEM
+
+NSPR_API(PRStatus) _PR_MD_TIMED_WAIT_SEM(
+    _MDSemaphore *md, PRIntervalTime timeout);
+#define _PR_MD_TIMED_WAIT_SEM _MD_TIMED_WAIT_SEM
+
+NSPR_API(PRStatus) _PR_MD_WAIT_SEM(_MDSemaphore *md);
+#define _PR_MD_WAIT_SEM _MD_WAIT_SEM
+
+NSPR_API(void) _PR_MD_POST_SEM(_MDSemaphore *md);
+#define _PR_MD_POST_SEM _MD_POST_SEM
+#endif /* HAVE_CVAR_BUILT_ON_SEM */
+
+#endif
+
+/* Condition Variables related -- only for native threads */
+
+#ifndef _PR_LOCAL_THREADS_ONLY /* not if only local threads supported */
+NSPR_API(PRInt32) _PR_MD_NEW_CV(_MDCVar *md);
+#define    _PR_MD_NEW_CV _MD_NEW_CV
+
+NSPR_API(void) _PR_MD_FREE_CV(_MDCVar *md);
+#define    _PR_MD_FREE_CV _MD_FREE_CV
+
+NSPR_API(void) _PR_MD_WAIT_CV(
+    _MDCVar *mdCVar,_MDLock *mdLock,PRIntervalTime timeout);
+#define    _PR_MD_WAIT_CV _MD_WAIT_CV
+
+NSPR_API(void) _PR_MD_NOTIFY_CV(_MDCVar *md, _MDLock *lock);
+#define    _PR_MD_NOTIFY_CV _MD_NOTIFY_CV
+
+NSPR_API(void) _PR_MD_NOTIFYALL_CV(_MDCVar *md, _MDLock *lock);
+#define    _PR_MD_NOTIFYALL_CV _MD_NOTIFYALL_CV
+#endif /* _PR_LOCAL_THREADS_ONLY */
+
+/* Threads related */
+NSPR_API(PRThread*) _PR_MD_CURRENT_THREAD(void);
+#define    _PR_MD_CURRENT_THREAD _MD_CURRENT_THREAD
+
+NSPR_API(PRThread*) _PR_MD_GET_ATTACHED_THREAD(void);
+#define    _PR_MD_GET_ATTACHED_THREAD _MD_GET_ATTACHED_THREAD
+
+NSPR_API(PRThread*) _PR_MD_LAST_THREAD(void);
+#define    _PR_MD_LAST_THREAD _MD_LAST_THREAD
+
+NSPR_API(void) _PR_MD_SET_CURRENT_THREAD(PRThread *thread);
+#define    _PR_MD_SET_CURRENT_THREAD _MD_SET_CURRENT_THREAD
+
+NSPR_API(void) _PR_MD_SET_LAST_THREAD(PRThread *thread);
+#define    _PR_MD_SET_LAST_THREAD _MD_SET_LAST_THREAD
+
+extern PRStatus _PR_MD_INIT_THREAD(PRThread *thread);
+#define    _PR_MD_INIT_THREAD _MD_INIT_THREAD
+
+extern void _PR_MD_EXIT_THREAD(PRThread *thread);
+#define    _PR_MD_EXIT_THREAD _MD_EXIT_THREAD
+
+#ifndef _PR_LOCAL_THREADS_ONLY /* not if only local threads supported */
+
+NSPR_API(PRStatus) _PR_MD_INIT_ATTACHED_THREAD(PRThread *thread);
+#define    _PR_MD_INIT_ATTACHED_THREAD _MD_INIT_ATTACHED_THREAD
+
+extern void _PR_MD_SUSPEND_THREAD(PRThread *thread);
+#define    _PR_MD_SUSPEND_THREAD _MD_SUSPEND_THREAD
+
+extern void _PR_MD_RESUME_THREAD(PRThread *thread);
+#define    _PR_MD_RESUME_THREAD _MD_RESUME_THREAD
+
+extern void _PR_MD_SUSPEND_CPU(_PRCPU  *cpu);
+#define    _PR_MD_SUSPEND_CPU _MD_SUSPEND_CPU
+
+extern void _PR_MD_RESUME_CPU(_PRCPU  *cpu);
+#define    _PR_MD_RESUME_CPU _MD_RESUME_CPU
+
+extern void _PR_MD_BEGIN_SUSPEND_ALL(void);
+#define    _PR_MD_BEGIN_SUSPEND_ALL _MD_BEGIN_SUSPEND_ALL
+
+extern void _PR_MD_END_SUSPEND_ALL(void);
+#define    _PR_MD_END_SUSPEND_ALL _MD_END_SUSPEND_ALL
+
+extern void _PR_MD_BEGIN_RESUME_ALL(void);
+#define    _PR_MD_BEGIN_RESUME_ALL _MD_BEGIN_RESUME_ALL
+
+extern void _PR_MD_END_RESUME_ALL(void);
+#define    _PR_MD_END_RESUME_ALL _MD_END_RESUME_ALL
+
+#if defined(IRIX) 
+NSPR_API(void) _PR_IRIX_CHILD_PROCESS(void);
+#endif        /* IRIX */
+
+#endif        /* !_PR_LOCAL_THREADS_ONLY */
+
+extern void _PR_MD_CLEAN_THREAD(PRThread *thread);
+#define    _PR_MD_CLEAN_THREAD _MD_CLEAN_THREAD
+
+#ifdef HAVE_CUSTOM_USER_THREADS
+extern void _PR_MD_CREATE_PRIMORDIAL_USER_THREAD(PRThread *);
+#define    _PR_MD_CREATE_PRIMORDIAL_USER_THREAD _MD_CREATE_PRIMORDIAL_USER_THREAD
+
+extern PRThread* _PR_MD_CREATE_USER_THREAD(
+                        PRUint32 stacksize,
+                        void (*start)(void *),
+                        void *arg);
+#define    _PR_MD_CREATE_USER_THREAD _MD_CREATE_USER_THREAD
+#endif
+
+extern PRStatus _PR_MD_CREATE_THREAD(
+                        PRThread *thread, 
+                        void (*start) (void *), 
+                        PRThreadPriority priority,                      
+                        PRThreadScope scope,
+                        PRThreadState state,
+                        PRUint32 stackSize);
+#define    _PR_MD_CREATE_THREAD _MD_CREATE_THREAD
+
+extern void _PR_MD_JOIN_THREAD(_MDThread *md);
+#define    _PR_MD_JOIN_THREAD _MD_JOIN_THREAD
+
+extern void _PR_MD_END_THREAD(void);
+#define    _PR_MD_END_THREAD _MD_END_THREAD
+
+extern void _PR_MD_YIELD(void);
+#define    _PR_MD_YIELD _MD_YIELD
+
+extern void _PR_MD_SET_PRIORITY(_MDThread *md, PRThreadPriority newPri);
+#define    _PR_MD_SET_PRIORITY _MD_SET_PRIORITY
+
+extern void _PR_MD_SET_CURRENT_THREAD_NAME(const char *name);
+#define    _PR_MD_SET_CURRENT_THREAD_NAME _MD_SET_CURRENT_THREAD_NAME
+
+NSPR_API(void) _PR_MD_SUSPENDALL(void);
+#define    _PR_MD_SUSPENDALL _MD_SUSPENDALL
+
+NSPR_API(void) _PR_MD_RESUMEALL(void);
+#define    _PR_MD_RESUMEALL _MD_RESUMEALL
+
+extern void _PR_MD_INIT_CONTEXT(
+    PRThread *thread, char *top, void (*start) (void), PRBool *status);
+#define    _PR_MD_INIT_CONTEXT _MD_INIT_CONTEXT
+
+extern void _PR_MD_SWITCH_CONTEXT(PRThread *thread);
+#define    _PR_MD_SWITCH_CONTEXT _MD_SWITCH_CONTEXT
+
+extern void _PR_MD_RESTORE_CONTEXT(PRThread *thread);
+#define    _PR_MD_RESTORE_CONTEXT _MD_RESTORE_CONTEXT
+
+/* Segment related */
+extern void _PR_MD_INIT_SEGS(void);
+#define    _PR_MD_INIT_SEGS _MD_INIT_SEGS
+
+extern PRStatus _PR_MD_ALLOC_SEGMENT(PRSegment *seg, PRUint32 size, void *vaddr);
+#define    _PR_MD_ALLOC_SEGMENT _MD_ALLOC_SEGMENT
+
+extern void _PR_MD_FREE_SEGMENT(PRSegment *seg);
+#define    _PR_MD_FREE_SEGMENT _MD_FREE_SEGMENT
+
+/* Directory enumeration related */
+extern PRStatus _PR_MD_OPEN_DIR(_MDDir *md,const char *name);
+#define    _PR_MD_OPEN_DIR _MD_OPEN_DIR
+
+extern char * _PR_MD_READ_DIR(_MDDir *md, PRIntn flags);
+#define    _PR_MD_READ_DIR _MD_READ_DIR
+
+extern PRInt32 _PR_MD_CLOSE_DIR(_MDDir *md);
+#define    _PR_MD_CLOSE_DIR _MD_CLOSE_DIR
+
+/* Named semaphores related */
+extern PRSem * _PR_MD_OPEN_SEMAPHORE(
+    const char *osname, PRIntn flags, PRIntn mode, PRUintn value);
+#define    _PR_MD_OPEN_SEMAPHORE _MD_OPEN_SEMAPHORE
+
+extern PRStatus _PR_MD_WAIT_SEMAPHORE(PRSem *sem);
+#define    _PR_MD_WAIT_SEMAPHORE _MD_WAIT_SEMAPHORE
+
+extern PRStatus _PR_MD_POST_SEMAPHORE(PRSem *sem);
+#define    _PR_MD_POST_SEMAPHORE _MD_POST_SEMAPHORE
+
+extern PRStatus _PR_MD_CLOSE_SEMAPHORE(PRSem *sem);
+#define    _PR_MD_CLOSE_SEMAPHORE _MD_CLOSE_SEMAPHORE
+
+extern PRStatus _PR_MD_DELETE_SEMAPHORE(const char *osname);
+#define    _PR_MD_DELETE_SEMAPHORE _MD_DELETE_SEMAPHORE
+
+/* I/O related */
+extern void _PR_MD_INIT_FILEDESC(PRFileDesc *fd);
+#define    _PR_MD_INIT_FILEDESC _MD_INIT_FILEDESC
+
+extern void _PR_MD_MAKE_NONBLOCK(PRFileDesc *fd);
+#define    _PR_MD_MAKE_NONBLOCK _MD_MAKE_NONBLOCK
+
+/* File I/O related */
+extern PROsfd _PR_MD_OPEN(const char *name, PRIntn osflags, PRIntn mode);
+#define    _PR_MD_OPEN _MD_OPEN
+
+extern PROsfd _PR_MD_OPEN_FILE(const char *name, PRIntn osflags, PRIntn mode);
+#define    _PR_MD_OPEN_FILE _MD_OPEN_FILE
+
+extern PRInt32 _PR_MD_CLOSE_FILE(PROsfd osfd);
+#define    _PR_MD_CLOSE_FILE _MD_CLOSE_FILE
+
+extern PRInt32 _PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 amount);
+#define    _PR_MD_READ _MD_READ
+
+extern PRInt32 _PR_MD_WRITE(PRFileDesc *fd, const void *buf, PRInt32 amount);
+#define    _PR_MD_WRITE _MD_WRITE
+
+extern PRInt32 _PR_MD_WRITEV(
+    PRFileDesc *fd, const struct PRIOVec *iov,
+    PRInt32 iov_size, PRIntervalTime timeout);
+#define    _PR_MD_WRITEV _MD_WRITEV
+
+extern PRInt32 _PR_MD_FSYNC(PRFileDesc *fd);
+#define    _PR_MD_FSYNC _MD_FSYNC
+
+extern PRInt32 _PR_MD_DELETE(const char *name);
+#define        _PR_MD_DELETE _MD_DELETE
+
+extern PRInt32 _PR_MD_RENAME(const char *from, const char *to);
+#define _PR_MD_RENAME _MD_RENAME
+
+extern PRInt32 _PR_MD_ACCESS(const char *name, PRAccessHow how);
+#define _PR_MD_ACCESS _MD_ACCESS
+
+extern PRInt32 _PR_MD_STAT(const char *name, struct stat *buf);
+#define _PR_MD_STAT _MD_STAT
+
+extern PRInt32 _PR_MD_MKDIR(const char *name, PRIntn mode);
+#define _PR_MD_MKDIR _MD_MKDIR
+
+extern PRInt32 _PR_MD_MAKE_DIR(const char *name, PRIntn mode);
+#define _PR_MD_MAKE_DIR _MD_MAKE_DIR
+
+extern PRInt32 _PR_MD_RMDIR(const char *name);
+#define _PR_MD_RMDIR _MD_RMDIR
+
+#ifdef MOZ_UNICODE
+/* UTF16 File I/O related */
+extern PRStatus _PR_MD_OPEN_DIR_UTF16(_MDDirUTF16 *md, const PRUnichar *name);
+#define    _PR_MD_OPEN_DIR_UTF16 _MD_OPEN_DIR_UTF16
+
+extern PROsfd _PR_MD_OPEN_FILE_UTF16(const PRUnichar *name, PRIntn osflags, PRIntn mode);
+#define    _PR_MD_OPEN_FILE_UTF16 _MD_OPEN_FILE_UTF16
+
+extern PRUnichar * _PR_MD_READ_DIR_UTF16(_MDDirUTF16 *md, PRIntn flags);
+#define    _PR_MD_READ_DIR_UTF16 _MD_READ_DIR_UTF16
+
+extern PRInt32 _PR_MD_CLOSE_DIR_UTF16(_MDDirUTF16 *md);
+#define    _PR_MD_CLOSE_DIR_UTF16 _MD_CLOSE_DIR_UTF16
+
+extern PRInt32 _PR_MD_GETFILEINFO64_UTF16(const PRUnichar *fn, PRFileInfo64 *info);
+#define _PR_MD_GETFILEINFO64_UTF16 _MD_GETFILEINFO64_UTF16
+#endif /* MOZ_UNICODE */
+
+/* Socket I/O related */
+extern void _PR_MD_INIT_IO(void);
+#define    _PR_MD_INIT_IO _MD_INIT_IO
+
+extern PRInt32 _PR_MD_CLOSE_SOCKET(PROsfd osfd);
+#define    _PR_MD_CLOSE_SOCKET _MD_CLOSE_SOCKET
+
+extern PRInt32 _PR_MD_CONNECT(
+    PRFileDesc *fd, const PRNetAddr *addr,
+    PRUint32 addrlen, PRIntervalTime timeout);
+#define    _PR_MD_CONNECT _MD_CONNECT
+
+extern PROsfd _PR_MD_ACCEPT(
+    PRFileDesc *fd, PRNetAddr *addr,
+    PRUint32 *addrlen, PRIntervalTime timeout);
+#define    _PR_MD_ACCEPT _MD_ACCEPT
+
+extern PRInt32 _PR_MD_BIND(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen);
+#define    _PR_MD_BIND _MD_BIND
+
+extern PRInt32 _PR_MD_LISTEN(PRFileDesc *fd, PRIntn backlog);
+#define    _PR_MD_LISTEN _MD_LISTEN
+
+extern PRInt32 _PR_MD_SHUTDOWN(PRFileDesc *fd, PRIntn how);
+#define    _PR_MD_SHUTDOWN _MD_SHUTDOWN
+
+extern PRInt32 _PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, 
+                               PRIntn flags, PRIntervalTime timeout);
+#define    _PR_MD_RECV _MD_RECV
+
+extern PRInt32 _PR_MD_SEND(
+    PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags, 
+    PRIntervalTime timeout);
+#define    _PR_MD_SEND _MD_SEND
+
+extern PRInt32 _PR_MD_ACCEPT_READ(PRFileDesc *sd, PROsfd *newSock, 
+                                PRNetAddr **raddr, void *buf, PRInt32 amount,
+                                PRIntervalTime timeout);
+#define _PR_MD_ACCEPT_READ _MD_ACCEPT_READ
+
+#ifdef WIN32
+extern PROsfd _PR_MD_FAST_ACCEPT(PRFileDesc *fd, PRNetAddr *addr, 
+                                PRUint32 *addrlen, PRIntervalTime timeout,
+                                PRBool fast,
+                                _PR_AcceptTimeoutCallback callback,
+                                void *callbackArg);
+
+extern PRInt32 _PR_MD_FAST_ACCEPT_READ(PRFileDesc *sd, PROsfd *newSock, 
+                                PRNetAddr **raddr, void *buf, PRInt32 amount,
+                                PRIntervalTime timeout, PRBool fast,
+                                _PR_AcceptTimeoutCallback callback,
+                                void *callbackArg);
+
+extern void _PR_MD_UPDATE_ACCEPT_CONTEXT(PROsfd s, PROsfd ls);
+#define _PR_MD_UPDATE_ACCEPT_CONTEXT _MD_UPDATE_ACCEPT_CONTEXT
+/*
+ * The NSPR epoch (00:00:00 1 Jan 1970 UTC) in FILETIME.
+ * We store the value in a PRTime variable for convenience.
+ * This constant is used by _PR_FileTimeToPRTime().
+ * This is defined in ntmisc.c
+ */
+extern const PRTime _pr_filetime_offset;
+#endif /* WIN32 */
+
+extern PRInt32 _PR_MD_SENDFILE(
+    PRFileDesc *sock, PRSendFileData *sfd, 
+	PRInt32 flags, PRIntervalTime timeout);
+#define _PR_MD_SENDFILE _MD_SENDFILE
+
+extern PRStatus _PR_MD_GETSOCKNAME(
+    PRFileDesc *fd, PRNetAddr *addr, PRUint32 *addrlen);
+#define    _PR_MD_GETSOCKNAME _MD_GETSOCKNAME
+
+extern PRStatus _PR_MD_GETPEERNAME(
+    PRFileDesc *fd, PRNetAddr *addr, PRUint32 *addrlen);
+#define    _PR_MD_GETPEERNAME _MD_GETPEERNAME
+
+extern PRStatus _PR_MD_GETSOCKOPT(
+    PRFileDesc *fd, PRInt32 level, PRInt32 optname, char* optval, PRInt32* optlen);
+#define    _PR_MD_GETSOCKOPT _MD_GETSOCKOPT
+
+extern PRStatus _PR_MD_SETSOCKOPT(
+    PRFileDesc *fd, PRInt32 level, PRInt32 optname,
+    const char* optval, PRInt32 optlen);
+#define    _PR_MD_SETSOCKOPT _MD_SETSOCKOPT
+
+extern PRStatus PR_CALLBACK _PR_SocketGetSocketOption(
+    PRFileDesc *fd, PRSocketOptionData *data);
+
+extern PRStatus PR_CALLBACK _PR_SocketSetSocketOption(
+    PRFileDesc *fd, const PRSocketOptionData *data);
+
+extern PRInt32 _PR_MD_RECVFROM(
+    PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
+    PRNetAddr *addr, PRUint32 *addrlen, PRIntervalTime timeout);
+#define    _PR_MD_RECVFROM _MD_RECVFROM
+
+extern PRInt32 _PR_MD_SENDTO(
+    PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
+    const PRNetAddr *addr, PRUint32 addrlen, PRIntervalTime timeout);
+#define    _PR_MD_SENDTO _MD_SENDTO
+
+extern PRInt32 _PR_MD_SOCKETPAIR(int af, int type, int flags, PROsfd *osfd);
+#define    _PR_MD_SOCKETPAIR _MD_SOCKETPAIR
+
+extern PROsfd _PR_MD_SOCKET(int af, int type, int flags);
+#define    _PR_MD_SOCKET _MD_SOCKET
+
+extern PRInt32 _PR_MD_SOCKETAVAILABLE(PRFileDesc *fd);
+#define    _PR_MD_SOCKETAVAILABLE _MD_SOCKETAVAILABLE
+
+extern PRInt32 _PR_MD_PIPEAVAILABLE(PRFileDesc *fd);
+#define    _PR_MD_PIPEAVAILABLE _MD_PIPEAVAILABLE
+
+extern PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds,
+                                                                                        PRIntervalTime timeout);
+#define    _PR_MD_PR_POLL _MD_PR_POLL
+
+/*
+ * Initialize fd->secret->inheritable for a newly created fd.
+ * If 'imported' is false, the osfd (i.e., fd->secret->md.osfd)
+ * was created by NSPR and hence has the OS-dependent default
+ * inheritable attribute.  If 'imported' is true, the osfd was
+ * not created by NSPR and hence a system call is required to
+ * query its inheritable attribute.  Since we may never need to
+ * know the inheritable attribute of a fd, a platform may choose
+ * to initialize fd->secret->inheritable of an imported fd to
+ * _PR_TRI_UNKNOWN and only pay the cost of the system call
+ * (in _PR_MD_QUERY_FD_INHERITABLE) when necessary.
+ */
+extern void _PR_MD_INIT_FD_INHERITABLE(PRFileDesc *fd, PRBool imported);
+#define    _PR_MD_INIT_FD_INHERITABLE _MD_INIT_FD_INHERITABLE
+
+extern PRStatus _PR_MD_SET_FD_INHERITABLE(PRFileDesc *fd, PRBool inheritable);
+#define    _PR_MD_SET_FD_INHERITABLE _MD_SET_FD_INHERITABLE
+
+
+#define _PR_PROCESS_TIMEOUT_INTERRUPT_ERRORS(me) \
+        if (_PR_PENDING_INTERRUPT(me)) { \
+                me->flags &= ~_PR_INTERRUPT; \
+                PR_SetError( PR_PENDING_INTERRUPT_ERROR, 0); \
+        } else { \
+                PR_SetError(PR_IO_TIMEOUT_ERROR, 0); \
+        }                                                        
+                
+extern void *_PR_MD_GET_SP(PRThread *thread);
+#define    _PR_MD_GET_SP _MD_GET_SP
+
+#endif /* defined(_PR_PTHREADS) */
+
+/************************************************************************/
+/*************************************************************************
+** The remainder of the definitions are shared by pthreads and the classic
+** NSPR code. These too may be conditionalized.
+*************************************************************************/
+/************************************************************************/
+
+extern PROffset32 _PR_MD_LSEEK(PRFileDesc *fd, PROffset32 offset, PRSeekWhence whence);
+#define    _PR_MD_LSEEK _MD_LSEEK
+
+extern PROffset64 _PR_MD_LSEEK64(PRFileDesc *fd, PROffset64 offset, PRSeekWhence whence);
+#define    _PR_MD_LSEEK64 _MD_LSEEK64
+
+extern PRInt32 _PR_MD_GETFILEINFO(const char *fn, PRFileInfo *info);
+#define _PR_MD_GETFILEINFO _MD_GETFILEINFO
+
+extern PRInt32 _PR_MD_GETFILEINFO64(const char *fn, PRFileInfo64 *info);
+#define _PR_MD_GETFILEINFO64 _MD_GETFILEINFO64
+
+extern PRInt32 _PR_MD_GETOPENFILEINFO(const PRFileDesc *fd, PRFileInfo *info);
+#define _PR_MD_GETOPENFILEINFO _MD_GETOPENFILEINFO
+
+extern PRInt32 _PR_MD_GETOPENFILEINFO64(const PRFileDesc *fd, PRFileInfo64 *info);
+#define _PR_MD_GETOPENFILEINFO64 _MD_GETOPENFILEINFO64
+
+
+/*****************************************************************************/
+/************************** File descriptor caching **************************/
+/*****************************************************************************/
+extern void _PR_InitFdCache(void);
+extern void _PR_CleanupFdCache(void);
+extern PRFileDesc *_PR_Getfd(void);
+extern void _PR_Putfd(PRFileDesc *fd);
+
+/*
+ * These flags are used by NSPR temporarily in the poll
+ * descriptor's out_flags field to record the mapping of
+ * NSPR's poll flags to the system poll flags.
+ *
+ * If _PR_POLL_READ_SYS_WRITE bit is set, it means the
+ * PR_POLL_READ flag specified by the topmost layer is
+ * mapped to the WRITE flag at the system layer.  Similarly
+ * for the other three _PR_POLL_XXX_SYS_YYY flags.  It is
+ * assumed that the PR_POLL_EXCEPT flag doesn't get mapped
+ * to other flags.
+ */
+#define _PR_POLL_READ_SYS_READ     0x1
+#define _PR_POLL_READ_SYS_WRITE    0x2
+#define _PR_POLL_WRITE_SYS_READ    0x4
+#define _PR_POLL_WRITE_SYS_WRITE   0x8
+
+/*
+** These methods are coerced into file descriptor methods table
+** when the intended service is inappropriate for the particular
+** type of file descriptor.
+*/
+extern PRIntn _PR_InvalidInt(void);
+extern PRInt16 _PR_InvalidInt16(void);
+extern PRInt64 _PR_InvalidInt64(void);
+extern PRStatus _PR_InvalidStatus(void);
+extern PRFileDesc *_PR_InvalidDesc(void);
+
+extern PRIOMethods _pr_faulty_methods;
+
+/*
+** The PR_NETADDR_SIZE macro can only be called on a PRNetAddr union
+** whose 'family' field is set.  It returns the size of the union
+** member corresponding to the specified address family.
+*/
+
+extern PRUintn _PR_NetAddrSize(const PRNetAddr* addr);
+
+#if defined(_PR_INET6)
+
+#define PR_NETADDR_SIZE(_addr) _PR_NetAddrSize(_addr)
+
+#elif defined(_PR_HAVE_MD_SOCKADDR_IN6)
+
+/*
+** Under the following conditions:
+** 1. _PR_INET6 is not defined;
+** 2. _PR_INET6_PROBE is defined;
+** 3. struct sockaddr_in6 has nonstandard fields at the end
+**    (e.g., on Solaris 8),
+** (_addr)->ipv6 is smaller than struct sockaddr_in6, and
+** hence we can't pass sizeof((_addr)->ipv6) to socket
+** functions such as connect because they would fail with
+** EINVAL.
+**
+** To pass the correct socket address length to socket
+** functions, define the macro _PR_HAVE_MD_SOCKADDR_IN6 and
+** define struct _md_sockaddr_in6 to be isomorphic to
+** struct sockaddr_in6.
+*/
+
+#if defined(XP_UNIX) || defined(XP_OS2)
+#define PR_NETADDR_SIZE(_addr) 					\
+        ((_addr)->raw.family == PR_AF_INET		\
+        ? sizeof((_addr)->inet)					\
+        : ((_addr)->raw.family == PR_AF_INET6	\
+        ? sizeof(struct _md_sockaddr_in6)		\
+        : sizeof((_addr)->local)))
+#else
+#define PR_NETADDR_SIZE(_addr) 					\
+        ((_addr)->raw.family == PR_AF_INET		\
+        ? sizeof((_addr)->inet)					\
+        : sizeof(struct _md_sockaddr_in6))
+#endif /* defined(XP_UNIX) */
+
+#else
+
+#if defined(XP_UNIX) || defined(XP_OS2)
+#define PR_NETADDR_SIZE(_addr) 					\
+        ((_addr)->raw.family == PR_AF_INET		\
+        ? sizeof((_addr)->inet)					\
+        : ((_addr)->raw.family == PR_AF_INET6	\
+        ? sizeof((_addr)->ipv6)					\
+        : sizeof((_addr)->local)))
+#else
+#define PR_NETADDR_SIZE(_addr) 					\
+        ((_addr)->raw.family == PR_AF_INET		\
+        ? sizeof((_addr)->inet)					\
+        : sizeof((_addr)->ipv6))
+#endif /* defined(XP_UNIX) */
+
+#endif /* defined(_PR_INET6) */
+
+extern PRStatus _PR_MapOptionName(
+    PRSockOption optname, PRInt32 *level, PRInt32 *name);
+extern void _PR_InitThreads(
+    PRThreadType type, PRThreadPriority priority, PRUintn maxPTDs);
+
+struct PRLock {
+#if defined(_PR_PTHREADS)
+    pthread_mutex_t mutex;          /* the underlying lock */
+    _PT_Notified notified;          /* array of conditions notified */
+    PRBool locked;                  /* whether the mutex is locked */
+    pthread_t owner;                /* if locked, current lock owner */
+#elif defined(_PR_BTHREADS)
+    sem_id	semaphoreID;	    /* the underlying lock */
+    int32	benaphoreCount;	    /* number of people in lock */
+    thread_id	owner;		    /* current lock owner */
+#else /* not pthreads or Be threads */
+    PRCList links;                  /* linkage for PRThread.lockList */
+    struct PRThread *owner;         /* current lock owner */
+    PRCList waitQ;                  /* list of threads waiting for lock */
+    PRThreadPriority priority;      /* priority of lock */ 
+    PRThreadPriority boostPriority; /* boosted priority of lock owner */
+    _MDLock ilock;                  /* Internal Lock to protect user-level fields */
+#endif
+};
+
+struct PRCondVar {
+    PRLock *lock;               /* associated lock that protects the condition */
+#if defined(_PR_PTHREADS)
+    pthread_cond_t cv;          /* underlying pthreads condition */
+    PRInt32 notify_pending;     /* CV has destroy pending notification */
+#elif defined(_PR_BTHREADS)
+    sem_id    sem;              /* the underlying lock */
+    sem_id    handshakeSem;     /* the lock for 'notify'-threads waiting for confirmation */
+    sem_id    signalSem;        /* the lock for threads waiting for someone to notify */
+    volatile int32    nw;       /* the number waiting */
+    volatile int32    ns;       /* the number signalling */
+    long signalBenCount;        /* the number waiting on the underlying sem */
+#else /* not pthreads or Be threads */
+    PRCList condQ;              /* Condition variable wait Q */
+    _MDLock ilock;              /* Internal Lock to protect condQ */
+    _MDCVar md;
+#endif
+};
+
+/************************************************************************/
+
+struct PRMonitor {
+    const char* name;           /* monitor name for debugging */
+#if defined(_PR_PTHREADS)
+    pthread_mutex_t lock;       /* lock is only held when accessing fields
+                                 * of the PRMonitor, instead of being held
+                                 * while the monitor is entered. The only
+                                 * exception is notifyTimes, which is
+                                 * protected by the monitor. */
+    pthread_t owner;            /* the owner of the monitor or invalid */
+    pthread_cond_t entryCV;     /* for threads waiting to enter the monitor */
+
+    pthread_cond_t waitCV;      /* for threads waiting on the monitor */
+    PRInt32 refCount;           /* reference count, an atomic variable.
+                                 * PR_NewMonitor adds a reference to the
+                                 * newly created PRMonitor, and
+                                 * PR_DestroyMonitor releases that reference.
+                                 * PR_ExitMonitor adds a reference before
+                                 * unlocking the internal lock if it needs to
+                                 * signal entryCV, and releases the reference
+                                 * after signaling entryCV. */
+#else  /* defined(_PR_PTHREADS) */
+    PRLock lock;                /* lock is only held when accessing fields
+                                 * of the PRMonitor, instead of being held
+                                 * while the monitor is entered. The only
+                                 * exception is notifyTimes, which is
+                                 * protected by the monitor. */
+    PRThread *owner;            /* the owner of the monitor or invalid */
+    PRCondVar entryCV;          /* for threads waiting to enter the monitor */
+
+    PRCondVar waitCV;           /* for threads waiting on the monitor */
+#endif /* defined(_PR_PTHREADS) */
+    PRUint32 entryCount;        /* # of times re-entered */
+    PRIntn notifyTimes;         /* number of pending notifies for waitCV.
+                                 * The special value -1 means a broadcast
+                                 * (PR_NotifyAll). */
+};
+
+/************************************************************************/
+
+struct PRSemaphore {
+#if defined(_PR_BTHREADS)
+    sem_id  sem;
+    int32   benaphoreCount;
+#else
+    PRCondVar *cvar;        /* associated lock and condition variable queue */
+    PRUintn count;            /* the value of the counting semaphore */
+    PRUint32 waiters;            /* threads waiting on the semaphore */
+#if defined(_PR_PTHREADS)
+#else  /* defined(_PR_PTHREADS) */
+    _MDSemaphore md;
+#endif /* defined(_PR_PTHREADS) */
+#endif /* defined(_PR_BTHREADS) */
+};
+
+/*************************************************************************/
+
+struct PRSem {
+#ifdef _PR_HAVE_POSIX_SEMAPHORES
+    sem_t *sem;
+#elif defined(_PR_HAVE_SYSV_SEMAPHORES)
+    int semid;
+#elif defined(WIN32)
+    HANDLE sem;
+#else
+    PRInt8 notused;
+#endif
+};
+
+/*************************************************************************/
+
+struct PRStackStr {
+    /* head MUST be at offset 0; assembly language code relies on this */
+#if defined(AIX)
+    volatile PRStackElem prstk_head;
+#else
+    PRStackElem prstk_head;
+#endif
+
+    PRLock *prstk_lock;
+    char *prstk_name;
+};
+
+/************************************************************************/
+
+/* XXX this needs to be exported (sigh) */
+struct PRThreadStack {
+    PRCList links;
+    PRUintn flags;
+
+    char *allocBase;            /* base of stack's allocated memory */
+    PRUint32 allocSize;         /* size of stack's allocated memory */
+    char *stackBottom;          /* bottom of stack from C's point of view */
+    char *stackTop;             /* top of stack from C's point of view */
+    PRUint32 stackSize;         /* size of usable portion of the stack */
+
+    PRSegment *seg;
+        PRThread* thr;          /* back pointer to thread owning this stack */
+
+#if defined(_PR_PTHREADS)
+#else /* defined(_PR_PTHREADS) */
+    _MDThreadStack md;
+#endif /* defined(_PR_PTHREADS) */
+};
+
+extern void _PR_DestroyThreadPrivate(PRThread*);
+
+typedef void (PR_CALLBACK *_PRStartFn)(void *);
+
+struct PRThread {
+    PRUint32 state;                 /* thread's creation state */
+    PRThreadPriority priority;      /* apparent priority, loosly defined */
+
+    void *arg;                      /* argument to the client's entry point */
+    _PRStartFn startFunc;           /* the root of the client's thread */
+
+    PRThreadStack *stack;           /* info about thread's stack (for GC) */
+    void *environment;              /* pointer to execution environment */
+
+    PRThreadDumpProc dump;          /* dump thread info out */
+    void *dumpArg;                  /* argument for the dump function */
+
+    /*
+    ** Per thread private data
+    */
+    PRUint32 tpdLength;             /* thread's current vector length */
+    void **privateData;             /* private data vector or NULL */
+    PRErrorCode errorCode;          /* current NSPR error code | zero */
+    PRInt32 osErrorCode;            /* mapping of errorCode | zero */
+    PRIntn  errorStringLength;      /* textLength from last call to PR_SetErrorText() */
+    PRInt32 errorStringSize;        /* malloc()'d size of buffer | zero */
+    char *errorString;              /* current error string | NULL */
+    char *name;                     /* thread's name */
+
+#if defined(_PR_PTHREADS)
+    pthread_t id;                   /* pthread identifier for the thread */
+    PRBool idSet;                   /* whether 'id' has been set. Protected by
+                                     * pt_book.ml. */
+#ifdef _PR_NICE_PRIORITY_SCHEDULING
+    pid_t tid;                      /* Linux-specific kernel thread ID */
+#endif
+    PRBool okToDelete;              /* ok to delete the PRThread struct? */
+    PRCondVar *waiting;             /* where the thread is waiting | NULL */
+    void *sp;                       /* recorded sp for garbage collection */
+    PRThread *next, *prev;          /* simple linked list of all threads */
+    PRUint32 suspend;               /* used to store suspend and resume flags */
+#ifdef PT_NO_SIGTIMEDWAIT
+    pthread_mutex_t suspendResumeMutex;
+    pthread_cond_t suspendResumeCV;
+#endif
+    PRUint32 interrupt_blocked;     /* interrupt blocked */
+    struct pollfd *syspoll_list;    /* Unix polling list used by PR_Poll */
+    PRUint32 syspoll_count;         /* number of elements in syspoll_list */
+#if defined(_PR_POLL_WITH_SELECT)
+    int *selectfd_list;             /* Unix fd's that PR_Poll selects on */
+    PRUint32 selectfd_count;        /* number of elements in selectfd_list */
+#endif
+#elif defined(_PR_BTHREADS)
+    PRUint32 flags;
+    _MDThread md;
+    PRBool io_pending;
+    PRInt32 io_fd;
+    PRBool io_suspended;
+#else /* not pthreads or Be threads */
+    _MDLock threadLock;             /* Lock to protect thread state variables.
+                                     * Protects the following fields:
+                                     *     state
+                                     *     priority
+                                     *     links
+                                     *     wait
+                                     *     cpu
+                                     */
+    PRUint32 queueCount;
+    PRUint32 waitCount;
+
+    PRCList active;                 /* on list of all active threads        */
+    PRCList links;
+    PRCList waitQLinks;             /* when thread is PR_Wait'ing */
+    PRCList lockList;               /* list of locks currently holding */
+    PRIntervalTime sleep;           /* sleep time when thread is sleeping */
+    struct _wait {
+        struct PRLock *lock;
+        struct PRCondVar *cvar;
+    } wait;
+
+    PRUint32 id;
+    PRUint32 flags;
+    PRUint32 no_sched;              /* Don't schedule the thread to run.
+                                     * This flag has relevance only when
+                                     * multiple NSPR CPUs are created.
+                                     * When a thread is de-scheduled, there
+                                     * is a narrow window of time in which
+                                     * the thread is put on the run queue
+                                     * but the scheduler is actually using
+                                     * the stack of this thread.  It is safe
+                                     * to run this thread on a different CPU
+                                     * only when its stack is not in use on
+                                     * any other CPU.  The no_sched flag is
+                                     * set during this interval to prevent
+                                     * the thread from being scheduled on a
+                                     * different CPU.
+                                     */
+
+    /* thread termination condition variable for join */
+    PRCondVar *term;
+
+    _PRCPU *cpu;                    /* cpu to which this thread is bound    */
+    PRUint32 threadAllocatedOnStack;/* boolean */
+
+    /* When an async IO is in progress and a second async IO cannot be 
+     * initiated, the io_pending flag is set to true.  Some platforms will
+     * not use the io_pending flag.  If the io_pending flag is true, then
+     * io_fd is the OS-file descriptor on which IO is pending.
+     */
+    PRBool io_pending;
+    PRInt32 io_fd;
+ 
+    /* If a timeout occurs or if an outstanding IO is interrupted and the
+     * OS doesn't support a real cancellation (NT or MAC), then the 
+     * io_suspended flag will be set to true.  The thread will be resumed
+     * but may run into trouble issuing additional IOs until the io_pending
+     * flag can be cleared 
+     */
+    PRBool io_suspended;
+
+    _MDThread md;
+#endif
+};
+
+struct PRProcessAttr {
+    PRFileDesc *stdinFd;
+    PRFileDesc *stdoutFd;
+    PRFileDesc *stderrFd;
+    char *currentDirectory;
+    char *fdInheritBuffer;
+    PRSize fdInheritBufferSize;
+    PRSize fdInheritBufferUsed;
+};
+
+struct PRProcess {
+    _MDProcess md;
+};
+
+struct PRFileMap {
+    PRFileDesc *fd;
+    PRFileMapProtect prot;
+    _MDFileMap md;
+};
+
+/************************************************************************/
+
+/*
+** File descriptors of the NSPR layer can be in one of the
+** following states (stored in the 'state' field of struct
+** PRFilePrivate):
+** - _PR_FILEDESC_OPEN: The OS fd is open.
+** - _PR_FILEDESC_CLOSED: The OS fd is closed.  The PRFileDesc
+**   is still open but is unusable.  The only operation allowed
+**   on the PRFileDesc is PR_Close().
+** - _PR_FILEDESC_FREED: The OS fd is closed and the PRFileDesc
+**   structure is freed.
+*/
+
+#define _PR_FILEDESC_OPEN       0xaaaaaaaa    /* 1010101... */
+#define _PR_FILEDESC_CLOSED     0x55555555    /* 0101010... */
+#define _PR_FILEDESC_FREED      0x11111111
+
+/*
+** A boolean type with an additional "unknown" state
+*/
+
+typedef enum {
+    _PR_TRI_TRUE = 1,
+    _PR_TRI_FALSE = 0,
+    _PR_TRI_UNKNOWN = -1
+} _PRTriStateBool;
+
+struct PRFilePrivate {
+    PRInt32 state;
+    PRBool nonblocking;
+    _PRTriStateBool inheritable;
+    PRFileDesc *next;
+    PRIntn lockCount;   /*   0: not locked
+                         *  -1: a native lockfile call is in progress
+                         * > 0: # times the file is locked */
+#ifdef _PR_HAVE_PEEK_BUFFER
+    char *peekBuffer;
+    PRInt32 peekBufSize;
+    PRInt32 peekBytes;
+#endif
+#if !defined(_PR_HAVE_O_APPEND)
+    PRBool  appendMode; /* Some platforms don't have O_APPEND or its
+                         * equivalent, so they have to seek to end of
+                         * file on write if the file was opened in
+                         * append mode.  See Bugzilla 4090, 276330. */
+#endif
+    _MDFileDesc md;
+#ifdef _PR_NEED_SECRET_AF
+    PRUint16 af;        /* If the platform's implementation of accept()
+                         * requires knowing the address family of the 
+			 * socket, we save the address family here. */
+#endif
+};
+
+#ifdef _WIN64
+#define PR_PRIdOSFD "lld"       /* for printing PROsfd */
+#define PR_PRIxOSFD "llx"
+#define PR_SCNdOSFD "lld"       /* for scanning PROsfd */
+#define PR_SCNxOSFD "llx"
+#else
+#define PR_PRIdOSFD "ld"        /* for printing PROsfd */
+#define PR_PRIxOSFD "lx"
+#define PR_SCNdOSFD "ld"        /* for scanning PROsfd */
+#define PR_SCNxOSFD "lx"
+#endif
+
+struct PRDir {
+    PRDirEntry d;
+    _MDDir md;
+};
+
+#ifdef MOZ_UNICODE
+struct PRDirUTF16 { 
+    PRDirEntry d; 
+    _MDDirUTF16 md; 
+}; 
+#endif /* MOZ_UNICODE */
+
+extern void _PR_InitLocks(void);
+extern void _PR_InitSegs(void);
+extern void _PR_InitStacks(void);
+extern void _PR_InitTPD(void);
+extern void _PR_InitMem(void);
+extern void _PR_InitEnv(void);
+extern void _PR_InitCMon(void);
+extern void _PR_InitIO(void);
+extern void _PR_InitLog(void);
+extern void _PR_InitNet(void);
+extern void _PR_InitClock(void);
+extern void _PR_InitLinker(void);
+extern void _PR_InitAtomic(void);
+extern void _PR_InitCPUs(void);
+extern void _PR_InitDtoa(void);
+extern void _PR_InitTime(void);
+extern void _PR_InitMW(void);
+extern void _PR_InitRWLocks(void);
+extern void _PR_CleanupThread(PRThread *thread);
+extern void _PR_CleanupCallOnce(void);
+extern void _PR_CleanupMW(void);
+extern void _PR_CleanupTime(void);
+extern void _PR_CleanupDtoa(void);
+extern void _PR_ShutdownLinker(void);
+extern void _PR_CleanupEnv(void);
+extern void _PR_CleanupIO(void);
+extern void _PR_CleanupCMon(void);
+extern void _PR_CleanupNet(void);
+extern void _PR_CleanupLayerCache(void);
+extern void _PR_CleanupStacks(void);
+#ifdef WINNT
+extern void _PR_CleanupCPUs(void);
+#endif
+extern void _PR_CleanupThreads(void);
+extern void _PR_CleanupTPD(void);
+extern void _PR_Cleanup(void);
+extern void _PR_LogCleanup(void);
+extern void _PR_InitLayerCache(void);
+
+extern PRBool _pr_initialized;
+extern void _PR_ImplicitInitialization(void);
+extern PRBool _PR_Obsolete(const char *obsolete, const char *preferred);
+
+/************************************************************************/
+
+struct PRSegment {
+    void *vaddr;
+    PRUint32 size;
+    PRUintn flags;
+#if defined(_PR_PTHREADS)
+#else  /* defined(_PR_PTHREADS) */
+    _MDSegment md;
+#endif /* defined(_PR_PTHREADS) */
+};
+
+/* PRSegment.flags */
+#define _PR_SEG_VM    0x1
+
+/************************************************************************/
+
+extern PRInt32 _pr_pageSize;
+extern PRInt32 _pr_pageShift;
+
+extern PRLogModuleInfo *_pr_clock_lm;
+extern PRLogModuleInfo *_pr_cmon_lm;
+extern PRLogModuleInfo *_pr_io_lm;
+extern PRLogModuleInfo *_pr_cvar_lm;
+extern PRLogModuleInfo *_pr_mon_lm;
+extern PRLogModuleInfo *_pr_linker_lm;
+extern PRLogModuleInfo *_pr_sched_lm;
+extern PRLogModuleInfo *_pr_thread_lm;
+extern PRLogModuleInfo *_pr_gc_lm;
+
+extern PRFileDesc *_pr_stdin;
+extern PRFileDesc *_pr_stdout;
+extern PRFileDesc *_pr_stderr;
+
+/* Zone allocator */
+/*
+** The zone allocator code has hardcoded pthread types and
+** functions, so it can only be used in the pthreads version.
+** This can be fixed by replacing the hardcoded pthread types
+** and functions with macros that expand to the native thread
+** types and functions on each platform.
+*/
+#if defined(_PR_PTHREADS) && !defined(_PR_DCETHREADS)
+#define _PR_ZONE_ALLOCATOR
+#endif
+
+#ifdef _PR_ZONE_ALLOCATOR
+extern void _PR_InitZones(void);
+extern void _PR_DestroyZones(void);
+#endif
+
+/* Overriding malloc, free, etc. */
+#if !defined(_PR_NO_PREEMPT) && defined(XP_UNIX) \
+        && !defined(_PR_PTHREADS) && !defined(_PR_GLOBAL_THREADS_ONLY) \
+        && !defined(PURIFY) \
+        && !defined(DARWIN) \
+        && !defined(QNX) \
+        && !(defined (UNIXWARE) && defined (USE_SVR4_THREADS))
+#define _PR_OVERRIDE_MALLOC
+#endif
+
+/*************************************************************************
+* External machine-dependent code provided by each OS.                     *                                                                     *
+*************************************************************************/
+
+/* Initialization related */
+extern void _PR_MD_EARLY_INIT(void);
+#define    _PR_MD_EARLY_INIT _MD_EARLY_INIT
+
+extern void _PR_MD_INTERVAL_INIT(void);
+#define    _PR_MD_INTERVAL_INIT _MD_INTERVAL_INIT
+
+NSPR_API(void) _PR_MD_FINAL_INIT(void);
+#define    _PR_MD_FINAL_INIT _MD_FINAL_INIT
+
+extern void _PR_MD_EARLY_CLEANUP(void);
+#define    _PR_MD_EARLY_CLEANUP _MD_EARLY_CLEANUP
+
+/* Process control */
+
+extern PRProcess * _PR_MD_CREATE_PROCESS(
+    const char *path,
+    char *const *argv,
+    char *const *envp,
+    const PRProcessAttr *attr);
+#define    _PR_MD_CREATE_PROCESS _MD_CREATE_PROCESS
+
+extern PRStatus _PR_MD_DETACH_PROCESS(PRProcess *process);
+#define    _PR_MD_DETACH_PROCESS _MD_DETACH_PROCESS
+
+extern PRStatus _PR_MD_WAIT_PROCESS(PRProcess *process, PRInt32 *exitCode);
+#define    _PR_MD_WAIT_PROCESS _MD_WAIT_PROCESS
+
+extern PRStatus _PR_MD_KILL_PROCESS(PRProcess *process);
+#define    _PR_MD_KILL_PROCESS _MD_KILL_PROCESS        
+
+/* Current Time */
+NSPR_API(PRTime) _PR_MD_NOW(void);
+#define    _PR_MD_NOW _MD_NOW
+
+/* Environment related */
+extern char* _PR_MD_GET_ENV(const char *name);
+#define    _PR_MD_GET_ENV _MD_GET_ENV
+
+extern PRIntn _PR_MD_PUT_ENV(const char *name);
+#define    _PR_MD_PUT_ENV _MD_PUT_ENV
+
+/* Atomic operations */
+
+extern void _PR_MD_INIT_ATOMIC(void);
+#define    _PR_MD_INIT_ATOMIC _MD_INIT_ATOMIC
+
+extern PRInt32 _PR_MD_ATOMIC_INCREMENT(PRInt32 *);
+#define    _PR_MD_ATOMIC_INCREMENT _MD_ATOMIC_INCREMENT
+
+extern PRInt32 _PR_MD_ATOMIC_ADD(PRInt32 *, PRInt32);
+#define    _PR_MD_ATOMIC_ADD _MD_ATOMIC_ADD
+
+extern PRInt32 _PR_MD_ATOMIC_DECREMENT(PRInt32 *);
+#define    _PR_MD_ATOMIC_DECREMENT _MD_ATOMIC_DECREMENT
+
+extern PRInt32 _PR_MD_ATOMIC_SET(PRInt32 *, PRInt32);
+#define    _PR_MD_ATOMIC_SET _MD_ATOMIC_SET
+
+/* Garbage collection */
+
+/*
+** Save the registers that the GC would find interesting into the thread
+** "t". isCurrent will be non-zero if the thread state that is being
+** saved is the currently executing thread. Return the address of the
+** first register to be scanned as well as the number of registers to
+** scan in "np".
+**
+** If "isCurrent" is non-zero then it is allowed for the thread context
+** area to be used as scratch storage to hold just the registers
+** necessary for scanning.
+*/
+extern PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np);
+
+/* Time intervals */
+
+extern PRIntervalTime _PR_MD_GET_INTERVAL(void);
+#define _PR_MD_GET_INTERVAL _MD_GET_INTERVAL
+
+extern PRIntervalTime _PR_MD_INTERVAL_PER_SEC(void);
+#define _PR_MD_INTERVAL_PER_SEC _MD_INTERVAL_PER_SEC
+
+/* Affinity masks */
+
+extern PRInt32 _PR_MD_SETTHREADAFFINITYMASK(PRThread *thread, PRUint32 mask );
+#define _PR_MD_SETTHREADAFFINITYMASK _MD_SETTHREADAFFINITYMASK
+
+extern PRInt32 _PR_MD_GETTHREADAFFINITYMASK(PRThread *thread, PRUint32 *mask);
+#define _PR_MD_GETTHREADAFFINITYMASK _MD_GETTHREADAFFINITYMASK
+
+/* File locking */
+
+extern PRStatus _PR_MD_LOCKFILE(PROsfd osfd);
+#define    _PR_MD_LOCKFILE _MD_LOCKFILE
+
+extern PRStatus _PR_MD_TLOCKFILE(PROsfd osfd);
+#define    _PR_MD_TLOCKFILE _MD_TLOCKFILE
+
+extern PRStatus _PR_MD_UNLOCKFILE(PROsfd osfd);
+#define    _PR_MD_UNLOCKFILE _MD_UNLOCKFILE
+
+/* Memory-mapped files */
+
+extern PRStatus _PR_MD_CREATE_FILE_MAP(PRFileMap *fmap, PRInt64 size);
+#define _PR_MD_CREATE_FILE_MAP _MD_CREATE_FILE_MAP
+
+extern PRInt32 _PR_MD_GET_MEM_MAP_ALIGNMENT(void);
+#define _PR_MD_GET_MEM_MAP_ALIGNMENT _MD_GET_MEM_MAP_ALIGNMENT
+
+extern void * _PR_MD_MEM_MAP(
+    PRFileMap *fmap,
+    PROffset64 offset,
+    PRUint32 len);
+#define _PR_MD_MEM_MAP _MD_MEM_MAP
+
+extern PRStatus _PR_MD_MEM_UNMAP(void *addr, PRUint32 size);
+#define _PR_MD_MEM_UNMAP _MD_MEM_UNMAP
+
+extern PRStatus _PR_MD_CLOSE_FILE_MAP(PRFileMap *fmap);
+#define _PR_MD_CLOSE_FILE_MAP _MD_CLOSE_FILE_MAP
+
+extern PRStatus _PR_MD_SYNC_MEM_MAP(
+    PRFileDesc *fd,
+    void *addr,
+    PRUint32 len);
+#define _PR_MD_SYNC_MEM_MAP _MD_SYNC_MEM_MAP
+
+/* Named Shared Memory */
+
+/*
+** Declare PRSharedMemory.
+*/
+struct PRSharedMemory 
+{
+    char        *ipcname; /* after conversion to native */
+    PRSize      size;  /* from open */
+    PRIntn      mode;  /* from open */
+    PRIntn      flags; /* from open */
+#if defined(PR_HAVE_POSIX_NAMED_SHARED_MEMORY)
+    int         id;
+#elif defined(PR_HAVE_SYSV_NAMED_SHARED_MEMORY)
+    int         id;
+#elif defined(PR_HAVE_WIN32_NAMED_SHARED_MEMORY)
+    HANDLE      handle;
+#else
+    PRUint32    nothing; /* placeholder, nothing behind here */
+#endif
+    PRUint32    ident; /* guard word at end of struct */
+#define _PR_SHM_IDENT 0xdeadbad
+};
+                                                      
+extern PRSharedMemory * _MD_OpenSharedMemory( 
+    const char *name,
+    PRSize      size,
+    PRIntn      flags,
+    PRIntn      mode
+);
+#define _PR_MD_OPEN_SHARED_MEMORY _MD_OpenSharedMemory
+
+extern void * _MD_AttachSharedMemory( PRSharedMemory *shm, PRIntn flags );
+#define _PR_MD_ATTACH_SHARED_MEMORY _MD_AttachSharedMemory
+
+extern PRStatus _MD_DetachSharedMemory( PRSharedMemory *shm, void *addr );
+#define _PR_MD_DETACH_SHARED_MEMORY _MD_DetachSharedMemory
+
+extern PRStatus _MD_CloseSharedMemory( PRSharedMemory *shm );
+#define _PR_MD_CLOSE_SHARED_MEMORY _MD_CloseSharedMemory
+
+extern PRStatus _MD_DeleteSharedMemory( const char *name );
+#define _PR_MD_DELETE_SHARED_MEMORY  _MD_DeleteSharedMemory
+
+extern PRFileMap* _md_OpenAnonFileMap( 
+    const char *dirName,
+    PRSize      size,
+    PRFileMapProtect prot
+);
+#define _PR_MD_OPEN_ANON_FILE_MAP _md_OpenAnonFileMap
+
+extern PRStatus _md_ExportFileMapAsString(
+    PRFileMap *fm,
+    PRSize    bufSize,
+    char      *buf
+);
+#define _PR_MD_EXPORT_FILE_MAP_AS_STRING _md_ExportFileMapAsString
+
+extern PRFileMap * _md_ImportFileMapFromString(
+    const char *fmstring
+);
+#define _PR_MD_IMPORT_FILE_MAP_FROM_STRING _md_ImportFileMapFromString
+
+
+
+/* Interprocess communications (IPC) */
+
+/*
+ * The maximum length of an NSPR IPC name, including the
+ * terminating null byte.
+ */
+#define PR_IPC_NAME_SIZE 1024
+
+/*
+ * Types of NSPR IPC objects
+ */
+typedef enum {
+    _PRIPCSem,  /* semaphores */
+    _PRIPCShm   /* shared memory segments */
+} _PRIPCType;
+
+/*
+ * Make a native IPC name from an NSPR IPC name.
+ */
+extern PRStatus _PR_MakeNativeIPCName(
+    const char *name,  /* NSPR IPC name */
+    char *result,      /* result buffer */
+    PRIntn size,       /* size of result buffer */
+    _PRIPCType type    /* type of IPC object */
+);
+
+/* Socket call error code */
+
+NSPR_API(PRInt32) _PR_MD_GET_SOCKET_ERROR(void);
+#define    _PR_MD_GET_SOCKET_ERROR _MD_GET_SOCKET_ERROR
+
+/* Get name of current host */
+extern PRStatus _PR_MD_GETHOSTNAME(char *name, PRUint32 namelen);
+#define    _PR_MD_GETHOSTNAME _MD_GETHOSTNAME
+
+extern PRStatus _PR_MD_GETSYSINFO(PRSysInfo cmd, char *name, PRUint32 namelen);
+#define    _PR_MD_GETSYSINFO _MD_GETSYSINFO
+
+/* File descriptor inheritance */
+
+/*
+ * If fd->secret->inheritable is _PR_TRI_UNKNOWN and we need to
+ * know the inheritable attribute of the fd, call this function
+ * to find that out.  This typically requires a system call.
+ */
+extern void _PR_MD_QUERY_FD_INHERITABLE(PRFileDesc *fd);
+#define    _PR_MD_QUERY_FD_INHERITABLE _MD_QUERY_FD_INHERITABLE
+
+/* --- PR_GetRandomNoise() related things --- */
+
+extern PRSize _PR_MD_GetRandomNoise( void *buf, PRSize size );
+#define _PR_MD_GET_RANDOM_NOISE(buf,size) _PR_MD_GetRandomNoise((buf),(size))
+extern PRSize _pr_CopyLowBits( void *dest, PRSize dstlen, void *src, PRSize srclen );
+
+/* end PR_GetRandomNoise() related */
+
+#ifdef XP_BEOS
+
+extern PRLock *_connectLock;
+
+typedef struct _ConnectListNode {
+	PRInt32		osfd;
+	PRNetAddr	addr;
+	PRUint32	addrlen;
+	PRIntervalTime	timeout;
+} ConnectListNode;
+
+extern ConnectListNode connectList[64];
+
+extern PRUint32 connectCount;
+
+#endif /* XP_BEOS */
+
+PR_END_EXTERN_C
+
+#endif /* primpl_h___ */
diff --git a/pr/include/private/prpriv.h b/pr/include/private/prpriv.h
new file mode 100644
index 0000000..f45eee4
--- /dev/null
+++ b/pr/include/private/prpriv.h
@@ -0,0 +1,16 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef prpriv_h___
+#define prpriv_h___
+
+/*
+ * NSPR 2.0 Private API
+ */
+
+#include "private/pprio.h"
+#include "private/pprthred.h"
+
+#endif /* prpriv_h___ */
diff --git a/pr/include/prlink.h b/pr/include/prlink.h
new file mode 100644
index 0000000..ea45ef8
--- /dev/null
+++ b/pr/include/prlink.h
@@ -0,0 +1,230 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef prlink_h___
+#define prlink_h___
+
+/*
+** API to static and dynamic linking.
+*/
+#include "prtypes.h"
+
+PR_BEGIN_EXTERN_C
+
+typedef struct PRLibrary PRLibrary;
+
+typedef struct PRStaticLinkTable {
+    const char *name;
+    void (*fp)(void);
+} PRStaticLinkTable;
+
+/*
+** Change the default library path to the given string. The string is
+** copied. This call will fail if it runs out of memory.
+**
+** The string provided as 'path' is copied. The caller can do whatever is
+** convenient with the argument when the function is complete.
+*/
+NSPR_API(PRStatus) PR_SetLibraryPath(const char *path);
+
+/*
+** Return a character string which contains the path used to search for
+** dynamically loadable libraries.
+**
+** The returned value is basically a copy of a PR_SetLibraryPath().
+** The storage is allocated by the runtime and becomes the responsibilty
+** of the caller.
+*/
+NSPR_API(char*) PR_GetLibraryPath(void);
+
+/*
+** Given a directory name "dir" and a library name "lib" construct a full
+** path name that will refer to the actual dynamically loaded
+** library. This does not test for existance of said file, it just
+** constructs the full filename. The name constructed is system dependent
+** and prepared for PR_LoadLibrary. The result must be free'd when the
+** caller is done with it.
+**
+** The storage for the result is allocated by the runtime and becomes the
+** responsibility of the caller.
+*/
+NSPR_API(char*) PR_GetLibraryName(const char *dir, const char *lib);
+
+/*
+**
+** Free the memory allocated, for the caller, by PR_GetLibraryName
+*/
+NSPR_API(void) PR_FreeLibraryName(char *mem);
+
+/*
+** Given a library "name" try to load the library. The argument "name"
+** is a machine-dependent name for the library, such as the full pathname
+** returned by PR_GetLibraryName.  If the library is already loaded,
+** this function will avoid loading the library twice.
+**
+** If the library is loaded successfully, then a pointer to the PRLibrary
+** structure representing the library is returned.  Otherwise, NULL is
+** returned.
+**
+** This increments the reference count of the library.
+*/
+NSPR_API(PRLibrary*) PR_LoadLibrary(const char *name);
+
+/*
+** Each operating system has its preferred way of specifying
+** a file in the file system.  Most operating systems use
+** a pathname.  Mac OS Classic, on the other hand, uses the FSSpec
+** structure to specify a file. PRLibSpec allows NSPR clients
+** to use the type of file specification that is most efficient
+** for a particular platform.
+**
+** On some operating systems such as Mac OS Classic, a shared library
+** may contain code fragments that can be individually loaded.
+** PRLibSpec also allows NSPR clients to identify a code fragment
+** in a library, if code fragments are supported by the OS.
+** A code fragment can be specified by name or by an integer index.
+**
+** Right now PRLibSpec supports four types of library specification:
+** a pathname in the native character encoding, a Mac code fragment
+** by name, a Mac code fragment by index, and a UTF-16 pathname.
+*/
+
+typedef enum PRLibSpecType {
+    PR_LibSpec_Pathname,
+    PR_LibSpec_MacNamedFragment,   /* obsolete (for Mac OS Classic) */
+    PR_LibSpec_MacIndexedFragment, /* obsolete (for Mac OS Classic) */
+    PR_LibSpec_PathnameU           /* supported only on Win32 */ 
+} PRLibSpecType;
+
+struct FSSpec; /* Mac OS Classic FSSpec */
+
+typedef struct PRLibSpec {
+    PRLibSpecType type;
+    union {
+        /* if type is PR_LibSpec_Pathname */
+        const char *pathname;
+
+        /* if type is PR_LibSpec_MacNamedFragment */
+        struct {
+            const struct FSSpec *fsspec;
+            const char *name;
+        } mac_named_fragment;      /* obsolete (for Mac OS Classic) */
+
+        /* if type is PR_LibSpec_MacIndexedFragment */
+        struct {
+            const struct FSSpec *fsspec;
+            PRUint32 index;
+        } mac_indexed_fragment;    /* obsolete (for Mac OS Classic) */
+
+        /* if type is PR_LibSpec_PathnameU */
+        const PRUnichar *pathname_u; /* supported only on Win32 */
+    } value;
+} PRLibSpec;
+
+/*
+** The following bit flags may be or'd together and passed
+** as the 'flags' argument to PR_LoadLibraryWithFlags.
+** Flags not supported by the underlying OS are ignored.
+*/
+
+#define PR_LD_LAZY   0x1  /* equivalent to RTLD_LAZY on Unix */
+#define PR_LD_NOW    0x2  /* equivalent to RTLD_NOW on Unix */
+#define PR_LD_GLOBAL 0x4  /* equivalent to RTLD_GLOBAL on Unix */
+#define PR_LD_LOCAL  0x8  /* equivalent to RTLD_LOCAL on Unix */
+/* The following is equivalent to LOAD_WITH_ALTERED_SEARCH_PATH on Windows */
+#define PR_LD_ALT_SEARCH_PATH  0x10  
+/*                0x8000     reserved for NSPR internal use */
+
+/*
+** Load the specified library, in the manner specified by 'flags'.
+*/
+
+NSPR_API(PRLibrary *)
+PR_LoadLibraryWithFlags(
+    PRLibSpec libSpec,    /* the shared library */
+    PRIntn flags          /* flags that affect the loading */
+);
+
+/*
+** Unload a previously loaded library. If the library was a static
+** library then the static link table will no longer be referenced. The
+** associated PRLibrary object is freed.
+**
+** PR_FAILURE is returned if the library cannot be unloaded.
+**
+** This function decrements the reference count of the library.
+*/
+NSPR_API(PRStatus) PR_UnloadLibrary(PRLibrary *lib);
+
+/*
+** Given the name of a procedure, return the address of the function that
+** implements the procedure, or NULL if no such function can be
+** found. This does not find symbols in the main program (the ".exe");
+** use PR_LoadStaticLibrary to register symbols in the main program.
+**
+** This function does not modify the reference count of the library.
+*/
+NSPR_API(void*) PR_FindSymbol(PRLibrary *lib, const char *name);
+
+/*
+** Similar to PR_FindSymbol, except that the return value is a pointer to
+** a function, and not a pointer to void. Casting between a data pointer
+** and a function pointer is not portable according to the C standard.
+** Any function pointer can be cast to any other function pointer.
+**
+** This function does not modify the reference count of the library.
+*/
+typedef void (*PRFuncPtr)(void);
+NSPR_API(PRFuncPtr) PR_FindFunctionSymbol(PRLibrary *lib, const char *name);
+
+/*
+** Finds a symbol in one of the currently loaded libraries. Given the
+** name of a procedure, return the address of the function that
+** implements the procedure, and return the library that contains that
+** symbol, or NULL if no such function can be found. This does not find
+** symbols in the main program (the ".exe"); use PR_AddStaticLibrary to
+** register symbols in the main program.  
+**
+** This increments the reference count of the library.
+*/
+NSPR_API(void*) PR_FindSymbolAndLibrary(const char *name,
+						      PRLibrary* *lib);
+
+/*
+** Similar to PR_FindSymbolAndLibrary, except that the return value is
+** a pointer to a function, and not a pointer to void. Casting between a
+** data pointer and a function pointer is not portable according to the C
+** standard. Any function pointer can be cast to any other function pointer.
+**
+** This increments the reference count of the library.
+*/
+NSPR_API(PRFuncPtr) PR_FindFunctionSymbolAndLibrary(const char *name,
+						      PRLibrary* *lib);
+
+/*
+** Register a static link table with the runtime under the name
+** "name". The symbols present in the static link table will be made
+** available to PR_FindSymbol. If "name" is null then the symbols will be
+** made available to the library which represents the executable. The
+** tables are not copied.
+**
+** Returns the library object if successful, null otherwise.
+**
+** This increments the reference count of the library.
+*/
+NSPR_API(PRLibrary*) PR_LoadStaticLibrary(
+    const char *name, const PRStaticLinkTable *table);
+
+/*
+** Return the pathname of the file that the library "name" was loaded
+** from. "addr" is the address of a function defined in the library.
+**
+** The caller is responsible for freeing the result with PR_Free.
+*/
+NSPR_API(char *) PR_GetLibraryFilePathname(const char *name, PRFuncPtr addr);
+
+PR_END_EXTERN_C
+
+#endif /* prlink_h___ */
diff --git a/pr/include/prlock.h b/pr/include/prlock.h
new file mode 100644
index 0000000..bc76a0e
--- /dev/null
+++ b/pr/include/prlock.h
@@ -0,0 +1,109 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** File:		prlock.h
+** Description:	API to basic locking functions of NSPR.
+**
+**
+** NSPR provides basic locking mechanisms for thread synchronization.  Locks 
+** are lightweight resource contention controls that prevent multiple threads 
+** from accessing something (code/data) simultaneously.
+**/
+
+#ifndef prlock_h___
+#define prlock_h___
+
+#include "prtypes.h"
+
+PR_BEGIN_EXTERN_C
+
+/**********************************************************************/
+/************************* TYPES AND CONSTANTS ************************/
+/**********************************************************************/
+
+/*
+ * PRLock --
+ *
+ *     NSPR represents the lock as an opaque entity to the client of the
+ *	   API.  All routines operate on a pointer to this opaque entity.
+ */
+
+typedef struct PRLock PRLock;
+
+/**********************************************************************/
+/****************************** FUNCTIONS *****************************/
+/**********************************************************************/
+
+/***********************************************************************
+** FUNCTION:    PR_NewLock
+** DESCRIPTION:
+**  Returns a pointer to a newly created opaque lock object.
+** INPUTS:      void
+** OUTPUTS:     void
+** RETURN:      PRLock*
+**   If the lock can not be created because of resource constraints, NULL
+**   is returned.
+**  
+***********************************************************************/
+NSPR_API(PRLock*) PR_NewLock(void);
+
+/***********************************************************************
+** FUNCTION:    PR_DestroyLock
+** DESCRIPTION:
+**  Destroys a given opaque lock object.
+** INPUTS:      PRLock *lock
+**              Lock to be freed.
+** OUTPUTS:     void
+** RETURN:      None
+***********************************************************************/
+NSPR_API(void) PR_DestroyLock(PRLock *lock);
+
+/***********************************************************************
+** FUNCTION:    PR_Lock
+** DESCRIPTION:
+**  Lock a lock.
+** INPUTS:      PRLock *lock
+**              Lock to locked.
+** OUTPUTS:     void
+** RETURN:      None
+***********************************************************************/
+NSPR_API(void) PR_Lock(PRLock *lock);
+
+/***********************************************************************
+** FUNCTION:    PR_Unlock
+** DESCRIPTION:
+**  Unlock a lock.  Unlocking an unlocked lock has undefined results.
+** INPUTS:      PRLock *lock
+**              Lock to unlocked.
+** OUTPUTS:     void
+** RETURN:      PR_STATUS
+**              Returns PR_FAILURE if the caller does not own the lock.
+***********************************************************************/
+NSPR_API(PRStatus) PR_Unlock(PRLock *lock);
+
+/***********************************************************************
+** MACRO:    PR_ASSERT_CURRENT_THREAD_OWNS_LOCK
+** DESCRIPTION:
+**  If the current thread owns |lock|, this assertion is guaranteed to
+**  succeed.  Otherwise, the behavior of this function is undefined.
+** INPUTS:      PRLock *lock
+**              Lock to assert ownership of.
+** OUTPUTS:     void
+** RETURN:      None
+***********************************************************************/
+#if defined(DEBUG) || defined(FORCE_PR_ASSERT)
+#define PR_ASSERT_CURRENT_THREAD_OWNS_LOCK(/* PrLock* */ lock) \
+    PR_AssertCurrentThreadOwnsLock(lock)
+#else
+#define PR_ASSERT_CURRENT_THREAD_OWNS_LOCK(/* PrLock* */ lock)
+#endif
+
+/* Don't call this function directly. */
+NSPR_API(void) PR_AssertCurrentThreadOwnsLock(PRLock *lock);
+
+PR_END_EXTERN_C
+
+#endif /* prlock_h___ */
diff --git a/pr/include/prlog.h b/pr/include/prlog.h
new file mode 100644
index 0000000..4a291dc
--- /dev/null
+++ b/pr/include/prlog.h
@@ -0,0 +1,222 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef prlog_h___
+#define prlog_h___
+
+#include "prtypes.h"
+
+PR_BEGIN_EXTERN_C
+
+/*
+** prlog.h -- Declare interfaces to NSPR's Logging service
+**
+** NSPR provides a logging service that is used by NSPR itself and is
+** available to client programs.
+**
+** To use the service from a client program, you should create a
+** PRLogModuleInfo structure by calling PR_NewLogModule(). After
+** creating the LogModule, you can write to the log using the PR_LOG()
+** macro.
+**
+** Initialization of the log service is handled by NSPR initialization.
+**
+** At execution time, you must enable the log service. To enable the
+** log service, set the environment variable: NSPR_LOG_MODULES
+** variable.
+**
+** NSPR_LOG_MODULES variable has the form:
+**
+**     <moduleName>:<value>[, <moduleName>:<value>]*
+**
+** Where:
+**  <moduleName> is the name passed to PR_NewLogModule().
+**  <value> is a numeric constant, e.g. 5. This value is the maximum
+** value of a log event, enumerated by PRLogModuleLevel, that you want
+** written to the log.
+** 
+** For example: to record all events of greater value than or equal to
+** PR_LOG_ERROR for a LogModule names "gizmo", say:
+** 
+** set NSPR_LOG_MODULES=gizmo:2
+** 
+** Note that you must specify the numeric value of PR_LOG_ERROR.
+** 
+** Special LogModule names are provided for controlling NSPR's log
+** service at execution time. These controls should be set in the
+** NSPR_LOG_MODULES environment variable at execution time to affect
+** NSPR's log service for your application.
+** 
+** The special LogModule "all" enables all LogModules. To enable all
+** LogModule calls to PR_LOG(), say:
+** 
+** set NSPR_LOG_MODULES=all:5
+** 
+** The special LogModule name "sync" tells the NSPR log service to do
+** unbuffered logging.
+** 
+** The special LogModule name "bufsize:<size>" tells NSPR to set the
+** log buffer to <size>.
+**
+** The environment variable NSPR_LOG_FILE specifies the log file to use
+** unless the default of "stderr" is acceptable. For MS Windows
+** systems, NSPR_LOG_FILE can be set to a special value: "WinDebug"
+** (case sensitive). This value causes PR_LOG() output to be written
+** using the Windows API OutputDebugString(). OutputDebugString()
+** writes to the debugger window; some people find this helpful.
+** 
+**
+** To put log messages in your programs, use the PR_LOG macro:
+**
+**     PR_LOG(<module>, <level>, (<printfString>, <args>*));
+**
+** Where <module> is the address of a PRLogModuleInfo structure, and
+** <level> is one of the levels defined by the enumeration:
+** PRLogModuleLevel. <args> is a printf() style of argument list. That
+** is: (fmtstring, ...).
+**
+** Example:
+** 
+** main() {
+**    PRIntn one = 1;
+**    PRLogModuleInfo * myLm = PR_NewLogModule("gizmo");
+**    PR_LOG( myLm, PR_LOG_ALWAYS, ("Log this! %d\n", one)); 
+**    return; 
+** }
+** 
+** Note the use of printf() style arguments as the third agrument(s) to
+** PR_LOG().
+** 
+** After compiling and linking you application, set the environment:
+** 
+** set NSPR_LOG_MODULES=gizmo:5
+** set NSPR_LOG_FILE=logfile.txt
+** 
+** When you execute your application, the string "Log this! 1" will be
+** written to the file "logfile.txt".
+** 
+** Note to NSPR engineers: a number of PRLogModuleInfo structures are
+** defined and initialized in prinit.c. See this module for ideas on
+** what to log where.
+** 
+*/
+
+typedef enum PRLogModuleLevel {
+    PR_LOG_NONE = 0,                /* nothing */
+    PR_LOG_ALWAYS = 1,              /* always printed */
+    PR_LOG_ERROR = 2,               /* error messages */
+    PR_LOG_WARNING = 3,             /* warning messages */
+    PR_LOG_DEBUG = 4,               /* debug messages */
+
+    PR_LOG_NOTICE = PR_LOG_DEBUG,   /* notice messages */
+    PR_LOG_WARN = PR_LOG_WARNING,   /* warning messages */
+    PR_LOG_MIN = PR_LOG_DEBUG,      /* minimal debugging messages */
+    PR_LOG_MAX = PR_LOG_DEBUG       /* maximal debugging messages */
+} PRLogModuleLevel;
+
+/*
+** One of these structures is created for each module that uses logging.
+**    "name" is the name of the module
+**    "level" is the debugging level selected for that module
+*/
+typedef struct PRLogModuleInfo {
+    const char *name;
+    PRLogModuleLevel level;
+    struct PRLogModuleInfo *next;
+} PRLogModuleInfo;
+
+/*
+** Create a new log module.
+*/
+NSPR_API(PRLogModuleInfo*) PR_NewLogModule(const char *name);
+
+/*
+** Set the file to use for logging. Returns PR_FALSE if the file cannot
+** be created
+*/
+NSPR_API(PRBool) PR_SetLogFile(const char *name);
+
+/*
+** Set the size of the logging buffer. If "buffer_size" is zero then the
+** logging becomes "synchronous" (or unbuffered).
+*/
+NSPR_API(void) PR_SetLogBuffering(PRIntn buffer_size);
+
+/*
+** Print a string to the log. "fmt" is a PR_snprintf format type. All
+** messages printed to the log are preceeded by the name of the thread
+** and a time stamp. Also, the routine provides a missing newline if one
+** is not provided.
+*/
+NSPR_API(void) PR_LogPrint(const char *fmt, ...);
+
+/*
+** Flush the log to its file.
+*/
+NSPR_API(void) PR_LogFlush(void);
+
+NSPR_API(void) PR_Assert(const char *s, const char *file, PRIntn ln)
+    PR_PRETEND_NORETURN;
+
+#if defined(DEBUG) || defined(FORCE_PR_LOG)
+#define PR_LOGGING 1
+
+#define PR_LOG_TEST(_module,_level) \
+    ((_module)->level >= (_level))
+
+/*
+** Log something.
+**    "module" is the address of a PRLogModuleInfo structure
+**    "level" is the desired logging level
+**    "args" is a variable length list of arguments to print, in the following
+**       format:  ("printf style format string", ...)
+*/
+#define PR_LOG(_module,_level,_args)     \
+    PR_BEGIN_MACRO             \
+      if (PR_LOG_TEST(_module,_level)) { \
+      PR_LogPrint _args;         \
+      }                     \
+    PR_END_MACRO
+
+#else /* defined(DEBUG) || defined(FORCE_PR_LOG) */
+
+#undef PR_LOGGING
+#define PR_LOG_TEST(module,level) 0
+#define PR_LOG(module,level,args)
+
+#endif /* defined(DEBUG) || defined(FORCE_PR_LOG) */
+
+#ifndef NO_NSPR_10_SUPPORT
+
+#ifdef PR_LOGGING
+#define PR_LOG_BEGIN    PR_LOG
+#define PR_LOG_END      PR_LOG
+#define PR_LOG_DEFINE   PR_NewLogModule
+#else
+#define PR_LOG_BEGIN(module,level,args)
+#define PR_LOG_END(module,level,args)
+#define PR_LOG_DEFINE(_name)    NULL
+#endif /* PR_LOGGING */
+
+#endif /* NO_NSPR_10_SUPPORT */
+
+#if defined(DEBUG) || defined(FORCE_PR_ASSERT)
+
+#define PR_ASSERT(_expr) \
+    ((_expr)?((void)0):PR_Assert(# _expr,__FILE__,__LINE__))
+
+#define PR_NOT_REACHED(_reasonStr) \
+    PR_Assert(_reasonStr,__FILE__,__LINE__)
+
+#else
+
+#define PR_ASSERT(expr) ((void) 0)
+#define PR_NOT_REACHED(reasonStr)
+
+#endif /* defined(DEBUG) || defined(FORCE_PR_ASSERT) */
+
+PR_END_EXTERN_C
+
+#endif /* prlog_h___ */
diff --git a/pr/include/prlong.h b/pr/include/prlong.h
new file mode 100644
index 0000000..df1f30b
--- /dev/null
+++ b/pr/include/prlong.h
@@ -0,0 +1,403 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** File:                prlong.h
+** Description: Portable access to 64 bit numerics
+**
+** Long-long (64-bit signed integer type) support. Some C compilers
+** don't support 64 bit integers yet, so we use these macros to
+** support both machines that do and don't.
+**/
+#ifndef prlong_h___
+#define prlong_h___
+
+#include "prtypes.h"
+
+PR_BEGIN_EXTERN_C
+
+/***********************************************************************
+** DEFINES:     LL_MaxInt
+**              LL_MinInt
+**              LL_Zero
+**              LL_MaxUint
+** DESCRIPTION:
+**      Various interesting constants and static variable
+**      initializer
+***********************************************************************/
+NSPR_API(PRInt64) LL_MaxInt(void);
+NSPR_API(PRInt64) LL_MinInt(void);
+NSPR_API(PRInt64) LL_Zero(void);
+NSPR_API(PRUint64) LL_MaxUint(void);
+
+#if defined(HAVE_LONG_LONG)
+
+/* Keep this in sync with prtypes.h. */
+#if PR_BYTES_PER_LONG == 8 && !defined(PR_ALTERNATE_INT64_TYPEDEF)
+#define LL_MAXINT   9223372036854775807L
+#define LL_MININT   (-LL_MAXINT - 1L)
+#define LL_ZERO     0L
+#define LL_MAXUINT  18446744073709551615UL
+#define LL_INIT(hi, lo)  ((hi ## L << 32) + lo ## L)
+#elif defined(WIN32) && !defined(__GNUC__)
+#define LL_MAXINT   9223372036854775807i64
+#define LL_MININT   (-LL_MAXINT - 1i64)
+#define LL_ZERO     0i64
+#define LL_MAXUINT  18446744073709551615ui64
+#define LL_INIT(hi, lo)  ((hi ## i64 << 32) + lo ## i64)
+#else
+#define LL_MAXINT   9223372036854775807LL
+#define LL_MININT   (-LL_MAXINT - 1LL)
+#define LL_ZERO     0LL
+#define LL_MAXUINT  18446744073709551615ULL
+#define LL_INIT(hi, lo)  ((hi ## LL << 32) + lo ## LL)
+#endif
+
+/***********************************************************************
+** MACROS:      LL_*
+** DESCRIPTION:
+**      The following macros define portable access to the 64 bit
+**      math facilities.
+**
+***********************************************************************/
+
+/***********************************************************************
+** MACROS:      LL_<relational operators>
+**
+**  LL_IS_ZERO        Test for zero
+**  LL_EQ             Test for equality
+**  LL_NE             Test for inequality
+**  LL_GE_ZERO        Test for zero or positive
+**  LL_CMP            Compare two values
+***********************************************************************/
+#define LL_IS_ZERO(a)       ((a) == 0)
+#define LL_EQ(a, b)         ((a) == (b))
+#define LL_NE(a, b)         ((a) != (b))
+#define LL_GE_ZERO(a)       ((a) >= 0)
+#define LL_CMP(a, op, b)    ((PRInt64)(a) op (PRInt64)(b))
+#define LL_UCMP(a, op, b)   ((PRUint64)(a) op (PRUint64)(b))
+
+/***********************************************************************
+** MACROS:      LL_<logical operators>
+**
+**  LL_AND            Logical and
+**  LL_OR             Logical or
+**  LL_XOR            Logical exclusion
+**  LL_OR2            A disgusting deviation
+**  LL_NOT            Negation (one's complement)
+***********************************************************************/
+#define LL_AND(r, a, b)        ((r) = (a) & (b))
+#define LL_OR(r, a, b)        ((r) = (a) | (b))
+#define LL_XOR(r, a, b)        ((r) = (a) ^ (b))
+#define LL_OR2(r, a)        ((r) = (r) | (a))
+#define LL_NOT(r, a)        ((r) = ~(a))
+
+/***********************************************************************
+** MACROS:      LL_<mathematical operators>
+**
+**  LL_NEG            Negation (two's complement)
+**  LL_ADD            Summation (two's complement)
+**  LL_SUB            Difference (two's complement)
+***********************************************************************/
+#define LL_NEG(r, a)        ((r) = -(a))
+#define LL_ADD(r, a, b)     ((r) = (a) + (b))
+#define LL_SUB(r, a, b)     ((r) = (a) - (b))
+
+/***********************************************************************
+** MACROS:      LL_<mathematical operators>
+**
+**  LL_MUL            Product (two's complement)
+**  LL_DIV            Quotient (two's complement)
+**  LL_MOD            Modulus (two's complement)
+***********************************************************************/
+#define LL_MUL(r, a, b)        ((r) = (a) * (b))
+#define LL_DIV(r, a, b)        ((r) = (a) / (b))
+#define LL_MOD(r, a, b)        ((r) = (a) % (b))
+
+/***********************************************************************
+** MACROS:      LL_<shifting operators>
+**
+**  LL_SHL            Shift left [0..64] bits
+**  LL_SHR            Shift right [0..64] bits with sign extension
+**  LL_USHR           Unsigned shift right [0..64] bits
+**  LL_ISHL           Signed shift left [0..64] bits
+***********************************************************************/
+#define LL_SHL(r, a, b)     ((r) = (PRInt64)(a) << (b))
+#define LL_SHR(r, a, b)     ((r) = (PRInt64)(a) >> (b))
+#define LL_USHR(r, a, b)    ((r) = (PRUint64)(a) >> (b))
+#define LL_ISHL(r, a, b)    ((r) = (PRInt64)(a) << (b))
+
+/***********************************************************************
+** MACROS:      LL_<conversion operators>
+**
+**  LL_L2I            Convert to signed 32 bit
+**  LL_L2UI           Convert to unsigned 32 bit
+**  LL_L2F            Convert to floating point
+**  LL_L2D            Convert to floating point
+**  LL_I2L            Convert signed to 64 bit
+**  LL_UI2L           Convert unsigned to 64 bit
+**  LL_F2L            Convert float to 64 bit
+**  LL_D2L            Convert float to 64 bit
+***********************************************************************/
+#define LL_L2I(i, l)        ((i) = (PRInt32)(l))
+#define LL_L2UI(ui, l)        ((ui) = (PRUint32)(l))
+#define LL_L2F(f, l)        ((f) = (PRFloat64)(l))
+#define LL_L2D(d, l)        ((d) = (PRFloat64)(l))
+
+#define LL_I2L(l, i)        ((l) = (PRInt64)(i))
+#define LL_UI2L(l, ui)        ((l) = (PRInt64)(ui))
+#define LL_F2L(l, f)        ((l) = (PRInt64)(f))
+#define LL_D2L(l, d)        ((l) = (PRInt64)(d))
+
+/***********************************************************************
+** MACROS:      LL_UDIVMOD
+** DESCRIPTION:
+**  Produce both a quotient and a remainder given an unsigned 
+** INPUTS:      PRUint64 a: The dividend of the operation
+**              PRUint64 b: The quotient of the operation
+** OUTPUTS:     PRUint64 *qp: pointer to quotient
+**              PRUint64 *rp: pointer to remainder
+***********************************************************************/
+#define LL_UDIVMOD(qp, rp, a, b) \
+    (*(qp) = ((PRUint64)(a) / (b)), \
+     *(rp) = ((PRUint64)(a) % (b)))
+
+#else  /* !HAVE_LONG_LONG */
+
+#define LL_MAXINT   LL_MaxInt()
+#define LL_MININT   LL_MinInt()
+#define LL_ZERO     LL_Zero()
+#define LL_MAXUINT  LL_MaxUint()
+
+#ifdef IS_LITTLE_ENDIAN
+#define LL_INIT(hi, lo) {PR_UINT32(lo), PR_UINT32(hi)}
+#else
+#define LL_INIT(hi, lo) {PR_UINT32(hi), PR_UINT32(lo)}
+#endif
+
+#define LL_IS_ZERO(a)        (((a).hi == 0) && ((a).lo == 0))
+#define LL_EQ(a, b)        (((a).hi == (b).hi) && ((a).lo == (b).lo))
+#define LL_NE(a, b)        (((a).hi != (b).hi) || ((a).lo != (b).lo))
+#define LL_GE_ZERO(a)        (((a).hi >> 31) == 0)
+
+#define LL_CMP(a, op, b)    (((a).hi == (b).hi) ? ((a).lo op (b).lo) : \
+                 ((PRInt32)(a).hi op (PRInt32)(b).hi))
+#define LL_UCMP(a, op, b)    (((a).hi == (b).hi) ? ((a).lo op (b).lo) : \
+                 ((a).hi op (b).hi))
+
+#define LL_AND(r, a, b)        ((r).lo = (a).lo & (b).lo, \
+                 (r).hi = (a).hi & (b).hi)
+#define LL_OR(r, a, b)        ((r).lo = (a).lo | (b).lo, \
+                 (r).hi = (a).hi | (b).hi)
+#define LL_XOR(r, a, b)        ((r).lo = (a).lo ^ (b).lo, \
+                 (r).hi = (a).hi ^ (b).hi)
+#define LL_OR2(r, a)        ((r).lo = (r).lo | (a).lo, \
+                 (r).hi = (r).hi | (a).hi)
+#define LL_NOT(r, a)        ((r).lo = ~(a).lo, \
+                 (r).hi = ~(a).hi)
+
+#define LL_NEG(r, a)        ((r).lo = -(PRInt32)(a).lo, \
+                 (r).hi = -(PRInt32)(a).hi - ((r).lo != 0))
+#define LL_ADD(r, a, b) { \
+    PRInt64 _a, _b; \
+    _a = a; _b = b; \
+    (r).lo = _a.lo + _b.lo; \
+    (r).hi = _a.hi + _b.hi + ((r).lo < _b.lo); \
+}
+
+#define LL_SUB(r, a, b) { \
+    PRInt64 _a, _b; \
+    _a = a; _b = b; \
+    (r).lo = _a.lo - _b.lo; \
+    (r).hi = _a.hi - _b.hi - (_a.lo < _b.lo); \
+}
+
+#define LL_MUL(r, a, b) { \
+    PRInt64 _a, _b; \
+    _a = a; _b = b; \
+    LL_MUL32(r, _a.lo, _b.lo); \
+    (r).hi += _a.hi * _b.lo + _a.lo * _b.hi; \
+}
+
+#define _lo16(a)        ((a) & PR_BITMASK(16))
+#define _hi16(a)        ((a) >> 16)
+
+#define LL_MUL32(r, a, b) { \
+     PRUint32 _a1, _a0, _b1, _b0, _y0, _y1, _y2, _y3; \
+     _a1 = _hi16(a), _a0 = _lo16(a); \
+     _b1 = _hi16(b), _b0 = _lo16(b); \
+     _y0 = _a0 * _b0; \
+     _y1 = _a0 * _b1; \
+     _y2 = _a1 * _b0; \
+     _y3 = _a1 * _b1; \
+     _y1 += _hi16(_y0);                         /* can't carry */ \
+     _y1 += _y2;                                /* might carry */ \
+     if (_y1 < _y2)    \
+        _y3 += (PRUint32)(PR_BIT(16));  /* propagate */ \
+     (r).lo = (_lo16(_y1) << 16) + _lo16(_y0); \
+     (r).hi = _y3 + _hi16(_y1); \
+}
+
+#define LL_UDIVMOD(qp, rp, a, b)    ll_udivmod(qp, rp, a, b)
+
+NSPR_API(void) ll_udivmod(PRUint64 *qp, PRUint64 *rp, PRUint64 a, PRUint64 b);
+
+#define LL_DIV(r, a, b) { \
+    PRInt64 _a, _b; \
+    PRUint32 _negative = (PRInt32)(a).hi < 0; \
+    if (_negative) { \
+    LL_NEG(_a, a); \
+    } else { \
+    _a = a; \
+    } \
+    if ((PRInt32)(b).hi < 0) { \
+    _negative ^= 1; \
+    LL_NEG(_b, b); \
+    } else { \
+    _b = b; \
+    } \
+    LL_UDIVMOD(&(r), 0, _a, _b); \
+    if (_negative) \
+    LL_NEG(r, r); \
+}
+
+#define LL_MOD(r, a, b) { \
+    PRInt64 _a, _b; \
+    PRUint32 _negative = (PRInt32)(a).hi < 0; \
+    if (_negative) { \
+    LL_NEG(_a, a); \
+    } else { \
+    _a = a; \
+    } \
+    if ((PRInt32)(b).hi < 0) { \
+    LL_NEG(_b, b); \
+    } else { \
+    _b = b; \
+    } \
+    LL_UDIVMOD(0, &(r), _a, _b); \
+    if (_negative) \
+    LL_NEG(r, r); \
+}
+
+#define LL_SHL(r, a, b) { \
+    if (b) { \
+    PRInt64 _a; \
+        _a = a; \
+        if ((b) < 32) { \
+        (r).lo = _a.lo << ((b) & 31); \
+        (r).hi = (_a.hi << ((b) & 31)) | (_a.lo >> (32 - (b))); \
+    } else { \
+        (r).lo = 0; \
+        (r).hi = _a.lo << ((b) & 31); \
+    } \
+    } else { \
+    (r) = (a); \
+    } \
+}
+
+/* a is an PRInt32, b is PRInt32, r is PRInt64 */
+#define LL_ISHL(r, a, b) { \
+    if (b) { \
+    PRInt64 _a; \
+    _a.lo = (a); \
+    _a.hi = 0; \
+        if ((b) < 32) { \
+        (r).lo = (a) << ((b) & 31); \
+        (r).hi = ((a) >> (32 - (b))); \
+    } else { \
+        (r).lo = 0; \
+        (r).hi = (a) << ((b) & 31); \
+    } \
+    } else { \
+    (r).lo = (a); \
+    (r).hi = 0; \
+    } \
+}
+
+#define LL_SHR(r, a, b) { \
+    if (b) { \
+    PRInt64 _a; \
+        _a = a; \
+    if ((b) < 32) { \
+        (r).lo = (_a.hi << (32 - (b))) | (_a.lo >> ((b) & 31)); \
+        (r).hi = (PRInt32)_a.hi >> ((b) & 31); \
+    } else { \
+        (r).lo = (PRInt32)_a.hi >> ((b) & 31); \
+        (r).hi = (PRInt32)_a.hi >> 31; \
+    } \
+    } else { \
+    (r) = (a); \
+    } \
+}
+
+#define LL_USHR(r, a, b) { \
+    if (b) { \
+    PRInt64 _a; \
+        _a = a; \
+    if ((b) < 32) { \
+        (r).lo = (_a.hi << (32 - (b))) | (_a.lo >> ((b) & 31)); \
+        (r).hi = _a.hi >> ((b) & 31); \
+    } else { \
+        (r).lo = _a.hi >> ((b) & 31); \
+        (r).hi = 0; \
+    } \
+    } else { \
+    (r) = (a); \
+    } \
+}
+
+#define LL_L2I(i, l)        ((i) = (l).lo)
+#define LL_L2UI(ui, l)        ((ui) = (l).lo)
+#define LL_L2F(f, l)        { double _d; LL_L2D(_d, l); (f) = (PRFloat64)_d; }
+
+#define LL_L2D(d, l) { \
+    int _negative; \
+    PRInt64 _absval; \
+ \
+    _negative = (l).hi >> 31; \
+    if (_negative) { \
+    LL_NEG(_absval, l); \
+    } else { \
+    _absval = l; \
+    } \
+    (d) = (double)_absval.hi * 4.294967296e9 + _absval.lo; \
+    if (_negative) \
+    (d) = -(d); \
+}
+
+#define LL_I2L(l, i)        { PRInt32 _i = ((PRInt32)(i)) >> 31; (l).lo = (i); (l).hi = _i; }
+#define LL_UI2L(l, ui)      ((l).lo = (ui), (l).hi = 0)
+#define LL_F2L(l, f)        { double _d = (double)f; LL_D2L(l, _d); }
+
+#define LL_D2L(l, d) { \
+    int _negative; \
+    double _absval, _d_hi; \
+    PRInt64 _lo_d; \
+ \
+    _negative = ((d) < 0); \
+    _absval = _negative ? -(d) : (d); \
+ \
+    (l).hi = _absval / 4.294967296e9; \
+    (l).lo = 0; \
+    LL_L2D(_d_hi, l); \
+    _absval -= _d_hi; \
+    _lo_d.hi = 0; \
+    if (_absval < 0) { \
+    _lo_d.lo = -_absval; \
+    LL_SUB(l, l, _lo_d); \
+    } else { \
+    _lo_d.lo = _absval; \
+    LL_ADD(l, l, _lo_d); \
+    } \
+ \
+    if (_negative) \
+    LL_NEG(l, l); \
+}
+
+#endif /* !HAVE_LONG_LONG */
+
+PR_END_EXTERN_C
+
+#endif /* prlong_h___ */
diff --git a/pr/include/prmem.h b/pr/include/prmem.h
new file mode 100644
index 0000000..c7cb5fb
--- /dev/null
+++ b/pr/include/prmem.h
@@ -0,0 +1,126 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** File: prmem.h
+** Description: API to NSPR memory management functions
+**
+*/
+#ifndef prmem_h___
+#define prmem_h___
+
+#include "prtypes.h"
+#include <stdlib.h>
+
+PR_BEGIN_EXTERN_C
+
+/*
+** Thread safe memory allocation.
+**
+** NOTE: pr wraps up malloc, free, calloc, realloc so they are already
+** thread safe (and are not declared here - look in stdlib.h).
+*/
+
+/*
+** PR_Malloc, PR_Calloc, PR_Realloc, and PR_Free have the same signatures
+** as their libc equivalent malloc, calloc, realloc, and free, and have
+** the same semantics.  (Note that the argument type size_t is replaced
+** by PRUint32.)  Memory allocated by PR_Malloc, PR_Calloc, or PR_Realloc
+** must be freed by PR_Free.
+*/
+
+NSPR_API(void *) PR_Malloc(PRUint32 size);
+
+NSPR_API(void *) PR_Calloc(PRUint32 nelem, PRUint32 elsize);
+
+NSPR_API(void *) PR_Realloc(void *ptr, PRUint32 size);
+
+NSPR_API(void) PR_Free(void *ptr);
+
+/*
+** The following are some convenience macros defined in terms of
+** PR_Malloc, PR_Calloc, PR_Realloc, and PR_Free.
+*/
+
+/***********************************************************************
+** FUNCTION:	PR_MALLOC()
+** DESCRIPTION:
+**   PR_NEW() allocates an untyped item of size _size from the heap.
+** INPUTS:  _size: size in bytes of item to be allocated
+** OUTPUTS:	untyped pointer to the node allocated
+** RETURN:	pointer to node or error returned from malloc().
+***********************************************************************/
+#define PR_MALLOC(_bytes) (PR_Malloc((_bytes)))
+
+/***********************************************************************
+** FUNCTION:	PR_NEW()
+** DESCRIPTION:
+**   PR_NEW() allocates an item of type _struct from the heap.
+** INPUTS:  _struct: a data type
+** OUTPUTS:	pointer to _struct
+** RETURN:	pointer to _struct or error returns from malloc().
+***********************************************************************/
+#define PR_NEW(_struct) ((_struct *) PR_MALLOC(sizeof(_struct)))
+
+/***********************************************************************
+** FUNCTION:	PR_REALLOC()
+** DESCRIPTION:
+**   PR_REALLOC() re-allocates _ptr bytes from the heap as a _size
+**   untyped item.
+** INPUTS:	_ptr: pointer to node to reallocate
+**          _size: size of node to allocate
+** OUTPUTS:	pointer to node allocated
+** RETURN:	pointer to node allocated
+***********************************************************************/
+#define PR_REALLOC(_ptr, _size) (PR_Realloc((_ptr), (_size)))
+
+/***********************************************************************
+** FUNCTION:	PR_CALLOC()
+** DESCRIPTION:
+**   PR_CALLOC() allocates a _size bytes untyped item from the heap
+**   and sets the allocated memory to all 0x00.
+** INPUTS:	_size: size of node to allocate
+** OUTPUTS:	pointer to node allocated
+** RETURN:	pointer to node allocated
+***********************************************************************/
+#define PR_CALLOC(_size) (PR_Calloc(1, (_size)))
+
+/***********************************************************************
+** FUNCTION:	PR_NEWZAP()
+** DESCRIPTION:
+**   PR_NEWZAP() allocates an item of type _struct from the heap
+**   and sets the allocated memory to all 0x00.
+** INPUTS:	_struct: a data type
+** OUTPUTS:	pointer to _struct
+** RETURN:	pointer to _struct
+***********************************************************************/
+#define PR_NEWZAP(_struct) ((_struct*)PR_Calloc(1, sizeof(_struct)))
+
+/***********************************************************************
+** FUNCTION:	PR_DELETE()
+** DESCRIPTION:
+**   PR_DELETE() unallocates an object previosly allocated via PR_NEW()
+**   or PR_NEWZAP() to the heap.
+** INPUTS:	pointer to previously allocated object
+** OUTPUTS:	the referenced object is returned to the heap
+** RETURN:	void
+***********************************************************************/
+#define PR_DELETE(_ptr) { PR_Free(_ptr); (_ptr) = NULL; }
+
+/***********************************************************************
+** FUNCTION:	PR_FREEIF()
+** DESCRIPTION:
+**   PR_FREEIF() conditionally unallocates an object previously allocated
+**   vial PR_NEW() or PR_NEWZAP(). If the pointer to the object is
+**   equal to zero (0), the object is not released.
+** INPUTS:	pointer to previously allocated object
+** OUTPUTS:	the referenced object is conditionally returned to the heap
+** RETURN:	void
+***********************************************************************/
+#define PR_FREEIF(_ptr)	if (_ptr) PR_DELETE(_ptr)
+
+PR_END_EXTERN_C
+
+#endif /* prmem_h___ */
diff --git a/pr/include/prmon.h b/pr/include/prmon.h
new file mode 100644
index 0000000..374e298
--- /dev/null
+++ b/pr/include/prmon.h
@@ -0,0 +1,96 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef prmon_h___
+#define prmon_h___
+
+#include "prtypes.h"
+#include "prinrval.h"
+
+PR_BEGIN_EXTERN_C
+
+typedef struct PRMonitor PRMonitor;
+
+/*
+** Create a new monitor. Monitors are re-entrant locks with a single built-in
+** condition variable.
+**
+** This may fail if memory is tight or if some operating system resource
+** is low.
+*/
+NSPR_API(PRMonitor*) PR_NewMonitor(void);
+
+/*
+** Destroy a monitor. The caller is responsible for guaranteeing that the
+** monitor is no longer in use. There must be no thread waiting on the monitor's
+** condition variable and that the lock is not held.
+**
+*/
+NSPR_API(void) PR_DestroyMonitor(PRMonitor *mon);
+
+/*
+** Enter the lock associated with the monitor. If the calling thread currently
+** is in the monitor, the call to enter will silently succeed. In either case,
+** it will increment the entry count by one.
+*/
+NSPR_API(void) PR_EnterMonitor(PRMonitor *mon);
+
+/*
+** Decrement the entry count associated with the monitor. If the decremented
+** entry count is zero, the monitor is exited. Returns PR_FAILURE if the
+** calling thread has not entered the monitor.
+*/
+NSPR_API(PRStatus) PR_ExitMonitor(PRMonitor *mon);
+
+/*
+** Wait for a notify on the monitor's condition variable. Sleep for "ticks"
+** amount of time (if "ticks" is PR_INTERVAL_NO_TIMEOUT then the sleep is
+** indefinite).
+**
+** While the thread is waiting it exits the monitor (as if it called
+** PR_ExitMonitor as many times as it had called PR_EnterMonitor).  When
+** the wait has finished the thread regains control of the monitors lock
+** with the same entry count as before the wait began.
+**
+** The thread waiting on the monitor will be resumed when the monitor is
+** notified (assuming the thread is the next in line to receive the
+** notify) or when the "ticks" timeout elapses.
+**
+** Returns PR_FAILURE if the caller has not entered the monitor.
+*/
+NSPR_API(PRStatus) PR_Wait(PRMonitor *mon, PRIntervalTime ticks);
+
+/*
+** Notify a thread waiting on the monitor's condition variable. If a thread
+** is waiting on the condition variable (using PR_Wait) then it is awakened
+** and attempts to reenter the monitor.
+*/
+NSPR_API(PRStatus) PR_Notify(PRMonitor *mon);
+
+/*
+** Notify all of the threads waiting on the monitor's condition variable.
+** All of threads waiting on the condition are scheduled to reenter the
+** monitor.
+*/
+NSPR_API(PRStatus) PR_NotifyAll(PRMonitor *mon);
+
+/*
+** PR_ASSERT_CURRENT_THREAD_IN_MONITOR
+** If the current thread is in |mon|, this assertion is guaranteed to
+** succeed.  Otherwise, the behavior of this function is undefined.
+*/
+#if defined(DEBUG) || defined(FORCE_PR_ASSERT)
+#define PR_ASSERT_CURRENT_THREAD_IN_MONITOR(/* PRMonitor* */ mon) \
+    PR_AssertCurrentThreadInMonitor(mon)
+#else
+#define PR_ASSERT_CURRENT_THREAD_IN_MONITOR(/* PRMonitor* */ mon)
+#endif
+
+/* Don't call this function directly. */
+NSPR_API(void) PR_AssertCurrentThreadInMonitor(PRMonitor *mon);
+
+PR_END_EXTERN_C
+
+#endif /* prmon_h___ */
diff --git a/pr/include/prmwait.h b/pr/include/prmwait.h
new file mode 100644
index 0000000..a902d90
--- /dev/null
+++ b/pr/include/prmwait.h
@@ -0,0 +1,380 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#if defined(_PRMWAIT_H)
+#else
+#define _PRMWAIT_H
+
+#include "prio.h"
+#include "prtypes.h"
+#include "prclist.h"
+
+PR_BEGIN_EXTERN_C
+
+/********************************************************************************/
+/********************************************************************************/
+/********************************************************************************/
+/******************************       WARNING        ****************************/
+/********************************************************************************/
+/**************************** This is work in progress. *************************/
+/************************** Do not make any assumptions *************************/
+/************************** about the stability of this *************************/
+/************************** API or the underlying imple- ************************/
+/************************** mentation.                   ************************/
+/********************************************************************************/
+/********************************************************************************/
+
+/*
+** STRUCTURE:   PRWaitGroup
+** DESCRIPTION:
+**      The client may define several wait groups in order to semantically
+**      tie a collection of file descriptors for a single purpose. This allows
+**      easier dispatching of threads that returned with active file descriptors
+**      from the wait function.
+*/
+typedef struct PRWaitGroup PRWaitGroup;
+
+/*
+** ENUMERATION: PRMWStatus
+** DESCRIPTION:
+**      This enumeration is used to indicate the completion status of
+**      a receive wait object. Generally stated, a positive value indicates
+**      that the operation is not yet complete. A zero value indicates
+**      success (similar to PR_SUCCESS) and any negative value is an
+**      indication of failure. The reason for the failure can be retrieved
+**      by calling PR_GetError().
+**
+**  PR_MW_PENDING       The operation is still pending. None of the other
+**                      fields of the object are currently valid.
+**  PR_MW_SUCCESS       The operation is complete and it was successful.
+**  PR_MW_FAILURE       The operation failed. The reason for the failure
+**                      can be retrieved by calling PR_GetError().
+**  PR_MW_TIMEOUT       The amount of time allowed for by the object's
+**                      'timeout' field has expired w/o the operation
+**                      otherwise coming to closure.
+**  PR_MW_INTERRUPT     The operation was cancelled, either by the client
+**                      calling PR_CancelWaitFileDesc() or destroying the
+**                      entire wait group (PR_DestroyWaitGroup()).
+*/
+typedef enum PRMWStatus
+{
+    PR_MW_PENDING = 1,
+    PR_MW_SUCCESS = 0,
+    PR_MW_FAILURE = -1,
+    PR_MW_TIMEOUT = -2,
+    PR_MW_INTERRUPT = -3
+} PRMWStatus;
+
+/*
+** STRUCTURE:   PRMemoryDescriptor
+** DESCRIPTION:
+**      THis is a descriptor for an interval of memory. It contains a
+**      pointer to the first byte of that memory and the length (in
+**      bytes) of the interval.
+*/
+typedef struct PRMemoryDescriptor
+{
+    void *start;                /* pointer to first byte of memory */
+    PRSize length;              /* length (in bytes) of memory interval */
+} PRMemoryDescriptor;
+
+/*
+** STRUCTURE:   PRMWaitClientData
+** DESCRIPTION:
+**      An opague stucture for which a client MAY give provide a concrete
+**      definition and associate with a receive descriptor. The NSPR runtime
+**      does not manage this field. It is completely up to the client.
+*/
+typedef struct PRMWaitClientData PRMWaitClientData;
+
+/*
+** STRUCTURE:   PRRecvWait
+** DESCRIPTION:
+**      A receive wait object contains the file descriptor that is subject
+**      to the wait and the amount of time (beginning epoch established
+**      when the object is presented to the runtime) the the channel should
+**      block before abandoning the process.
+**
+**      The success of the wait operation will be noted in the object's
+**      'outcome' field. The fields are not valid when the NSPR runtime
+**      is in possession of the object.
+**
+**      The memory descriptor describes an interval of writable memory
+**      in the caller's address space where data from an initial read
+**      can be placed. The description may indicate a null interval.
+*/
+typedef struct PRRecvWait 
+{
+    PRCList internal;           /* internal runtime linkages */
+
+    PRFileDesc *fd;             /* file descriptor associated w/ object */
+    PRMWStatus outcome;         /* outcome of the current/last operation */
+    PRIntervalTime timeout;     /* time allowed for entire operation */
+
+    PRInt32 bytesRecv;          /* number of bytes transferred into buffer */
+    PRMemoryDescriptor buffer;  /* where to store first segment of input data */
+    PRMWaitClientData *client;  /* pointer to arbitrary client defined data */
+} PRRecvWait;
+
+/*
+** STRUCTURE:   PRMWaitEnumerator
+** DESCRIPTION:
+**      An enumeration object is used to store the state of an existing
+**      enumeration over a wait group. The opaque object must be allocated
+**      by the client and the reference presented on each call to the
+**      pseudo-stateless enumerator. The enumeration objects are sharable
+**      only in serial fashion.
+*/
+typedef struct PRMWaitEnumerator PRMWaitEnumerator;
+
+
+/*
+** FUNCTION:    PR_AddWaitFileDesc
+** DESCRIPTION:
+**      This function will effectively add a file descriptor to the
+**      list of those waiting for network receive. The new descriptor
+**      will be semantically tied to the wait group specified.
+**
+**      The ownership for the storage pointed to by 'desc' is temporarily
+**      passed over the the NSPR runtime. It will be handed back by the
+**      function PR_WaitRecvReady().
+**
+**  INPUTS
+**      group       A reference to a PRWaitGroup or NULL. Wait groups are
+**                  created by calling PR_CreateWaitGroup() and are used
+**                  to semantically group various file descriptors by the
+**                  client's application.
+**      desc        A reference to a valid PRRecvWait. The object of the
+**                  reference must be preserved and not be modified
+**                  until its ownership is returned to the client.
+**  RETURN
+**      PRStatus    An indication of success. If equal to PR_FAILUE details
+**                  of the failure are avaiable via PR_GetError().
+**
+**  ERRORS
+**      PR_INVALID_ARGUMENT_ERROR
+**                  Invalid 'group' identifier or duplicate 'desc' object.
+**      PR_OUT_OF_MEMORY_ERROR
+**                  Insuffient memory for internal data structures.
+**      PR_INVALID_STATE_ERROR
+**                  The group is being destroyed.
+*/
+NSPR_API(PRStatus) PR_AddWaitFileDesc(PRWaitGroup *group, PRRecvWait *desc);
+
+/*
+** FUNCTION:    PR_WaitRecvReady
+** DESCRIPTION:
+**      PR_WaitRecvReady will block the calling thread until one of the
+**      file descriptors that have been added via PR_AddWaitFileDesc is
+**      available for input I/O.
+**  INPUT
+**      group       A pointer to a valid PRWaitGroup or NULL (the null
+**                  group. The function will block the caller until a
+**                  channel from the wait group becomes ready for receive
+**                  or there is some sort of error.
+**  RETURN
+**      PRReciveWait
+**                  When the caller is resumed it is either returned a
+**                  valid pointer to a previously added receive wait or
+**                  a NULL. If the latter, the function has terminated
+**                  for a reason that can be determined by calling
+**                  PR_GetError().
+**                  If a valid pointer is returned, the reference is to the
+**                  file descriptor contained in the receive wait object.
+**                  The outcome of the wait operation may still fail, and
+**                  if it has, that fact will be noted in the object's
+**                  outcome field. Details can be retrieved from PR_GetError().
+**
+**  ERRORS
+**      PR_INVALID_ARGUMENT_ERROR
+**                  The 'group' is not known by the runtime.
+**      PR_PENDING_INTERRUPT_ERROR
+                    The thread was interrupted.
+**      PR_INVALID_STATE_ERROR
+**                  The group is being destroyed.
+*/
+NSPR_API(PRRecvWait*) PR_WaitRecvReady(PRWaitGroup *group);
+
+/*
+** FUNCTION:    PR_CancelWaitFileDesc
+** DESCRIPTION:
+**      PR_CancelWaitFileDesc is provided as a means for cancelling operations
+**      on objects previously submitted by use of PR_AddWaitFileDesc(). If
+**      the runtime knows of the object, it will be marked as having failed
+**      because it was interrupted (similar to PR_Interrupt()). The first
+**      available thread waiting on the group will be made to return the
+**      PRRecvWait object with the outcome noted.
+**
+**  INPUTS
+**      group       The wait group under which the wait receive object was
+**                  added.
+**      desc        A pointer to the wait receive object that is to be
+**                  cancelled.
+**  RETURN
+**      PRStatus    If the wait receive object was located and associated
+**                  with the specified wait group, the status returned will
+**                  be PR_SUCCESS. There is still a race condition that would
+**                  permit the offected object to complete normally, but it
+**                  is assured that it will complete in the near future.
+**                  If the receive object or wait group are invalid, the
+**                  function will return with a status of PR_FAILURE.
+**
+**  ERRORS
+**      PR_INVALID_ARGUMENT_ERROR
+**                  The 'group' argument is not recognized as a valid group.
+**      PR_COLLECTION_EMPTY_ERROR
+**                  There are no more receive wait objects in the group's
+**                  collection.
+**      PR_INVALID_STATE_ERROR
+**                  The group is being destroyed.
+*/
+NSPR_API(PRStatus) PR_CancelWaitFileDesc(PRWaitGroup *group, PRRecvWait *desc);
+
+/*
+** FUNCTION:    PR_CancelWaitGroup
+** DESCRIPTION:
+**      PR_CancelWaitGroup is provided as a means for cancelling operations
+**      on objects previously submitted by use of PR_AddWaitFileDesc(). Each
+**      successive call will return a pointer to a PRRecvWait object that
+**      was previously registered via PR_AddWaitFileDesc(). If no wait
+**      objects are associated with the wait group, a NULL will be returned.
+**      This function should be called in a loop until a NULL is returned
+**      to reclaim all the wait objects prior to calling PR_DestroyWaitGroup().
+**
+**  INPUTS
+**      group       The wait group under which the wait receive object was
+**                  added.
+**  RETURN
+**      PRRecvWait* If the wait group is valid and at least one receive wait
+**                  object is present in the group, that object will be
+**                  marked as PR_MW_INTERRUPT'd and removed from the group's
+**                  queues. Otherwise a NULL will be returned and the reason
+**                  for the NULL may be retrieved by calling PR_GetError().
+**
+**  ERRORS
+**      PR_INVALID_ARGUMENT_ERROR
+**      PR_GROUP_EMPTY_ERROR
+*/
+NSPR_API(PRRecvWait*) PR_CancelWaitGroup(PRWaitGroup *group);
+
+/*
+** FUNCTION:    PR_CreateWaitGroup
+** DESCRIPTION:
+**      A wait group is an opaque object that a client may create in order
+**      to semantically group various wait requests. Each wait group is
+**      unique, including the default wait group (NULL). A wait request
+**      that was added under a wait group will only be serviced by a caller
+**      that specified the same wait group.
+**
+**  INPUT
+**      size        The size of the hash table to be used to contain the
+**                  receive wait objects. This is just the initial size.
+**                  It will grow as it needs to, but to avoid that hassle
+**                  one can suggest a suitable size initially. It should
+**                  be ~30% larger than the maximum number of receive wait
+**                  objects expected.
+**  RETURN
+**      PRWaitGroup If successful, the function will return a pointer to an
+**                  object that was allocated by and owned by the runtime.
+**                  The reference remains valid until it is explicitly destroyed
+**                  by calling PR_DestroyWaitGroup().
+**
+**  ERRORS
+**      PR_OUT_OF_MEMORY_ERROR
+*/
+NSPR_API(PRWaitGroup*) PR_CreateWaitGroup(PRInt32 size);
+
+/*
+** FUNCTION:    PR_DestroyWaitGroup
+** DESCRIPTION:
+**      Undo the effects of PR_CreateWaitGroup(). Any receive wait operations
+**      on the group will be treated as if the each had been the target of a
+**      PR_CancelWaitFileDesc().
+**
+**  INPUT
+**      group       Reference to a wait group previously allocated using
+**                  PR_CreateWaitGroup().
+**  RETURN
+**      PRStatus    Will be PR_SUCCESS if the wait group was valid and there
+**                  are no receive wait objects in that group. Otherwise
+**                  will indicate PR_FAILURE.
+**
+**  ERRORS
+**      PR_INVALID_ARGUMENT_ERROR
+**                  The 'group' argument does not reference a known object.
+**      PR_INVALID_STATE_ERROR
+**                  The group still contains receive wait objects.
+*/
+NSPR_API(PRStatus) PR_DestroyWaitGroup(PRWaitGroup *group);
+
+/*
+** FUNCTION:    PR_CreateMWaitEnumerator
+** DESCRIPTION:
+**      The PR_CreateMWaitEnumerator() function returns a reference to an
+**      opaque PRMWaitEnumerator object. The enumerator object is required
+**      as an argument for each successive call in the stateless enumeration
+**      of the indicated wait group.
+**
+**      group       The wait group that the enumeration is intended to
+**                  process. It may be be the default wait group (NULL).
+** RETURN
+**      PRMWaitEnumerator* group
+**                  A reference to an object that will be used to store
+**                  intermediate state of enumerations.
+** ERRORS
+**      Errors are indicated by the function returning a NULL.
+**      PR_INVALID_ARGUMENT_ERROR
+**                  The 'group' argument does not reference a known object.
+**      PR_OUT_OF_MEMORY_ERROR
+*/
+NSPR_API(PRMWaitEnumerator*) PR_CreateMWaitEnumerator(PRWaitGroup *group);
+
+/*
+** FUNCTION:    PR_DestroyMWaitEnumerator
+** DESCRIPTION:
+**      Destroys the object created by PR_CreateMWaitEnumerator(). The reference
+**      used as an argument becomes invalid.
+**
+** INPUT
+**      PRMWaitEnumerator* enumerator
+**          The PRMWaitEnumerator object to destroy.
+** RETURN
+**      PRStatus
+**          PR_SUCCESS if successful, PR_FAILURE otherwise.
+** ERRORS
+**      PR_INVALID_ARGUMENT_ERROR
+**                  The enumerator is invalid.
+*/
+NSPR_API(PRStatus) PR_DestroyMWaitEnumerator(PRMWaitEnumerator* enumerator);
+
+/*
+** FUNCTION:    PR_EnumerateWaitGroup
+** DESCRIPTION:
+**      PR_EnumerateWaitGroup is a thread safe enumerator over a wait group.
+**      Each call to the enumerator must present a valid PRMWaitEnumerator
+**      rererence and a pointer to the "previous" element returned from the
+**      enumeration process or a NULL.
+**
+**      An enumeration is started by passing a NULL as the "previous" value.
+**      Subsequent calls to the enumerator must pass in the result of the
+**      previous call. The enumeration end is signaled by the runtime returning
+**      a NULL as the result.
+**
+**      Modifications to the content of the wait group are allowed during
+**      an enumeration. The effect is that the enumeration may have to be
+**      "reset" and that may result in duplicates being returned from the
+**      enumeration.
+**
+**      An enumeration may be abandoned at any time. The runtime is not
+**      keeping any state, so there are no issues in that regard.
+*/
+NSPR_API(PRRecvWait*) PR_EnumerateWaitGroup(
+    PRMWaitEnumerator *enumerator, const PRRecvWait *previous);
+   
+PR_END_EXTERN_C
+
+#endif /* defined(_PRMWAIT_H) */
+
+/* prmwait.h */
diff --git a/pr/include/prnetdb.h b/pr/include/prnetdb.h
new file mode 100644
index 0000000..49b77b1
--- /dev/null
+++ b/pr/include/prnetdb.h
@@ -0,0 +1,467 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef prnetdb_h___
+#define prnetdb_h___
+
+#include "prtypes.h"
+#include "prio.h"
+
+PR_BEGIN_EXTERN_C
+
+
+/*
+ *********************************************************************
+ *  Translate an Internet address to/from a character string
+ *********************************************************************
+ */
+NSPR_API(PRStatus) PR_StringToNetAddr(
+    const char *string, PRNetAddr *addr);
+
+NSPR_API(PRStatus) PR_NetAddrToString(
+    const PRNetAddr *addr, char *string, PRUint32 size);
+
+/*
+** Structures returned by network data base library.  All addresses are
+** supplied in host order, and returned in network order (suitable for
+** use in system calls).
+*/
+/*
+** Beware that WINSOCK.H defines h_addrtype and h_length as short.
+** Client code does direct struct copies of hostent to PRHostEnt and
+** hence the ifdef.
+*/
+typedef struct PRHostEnt {
+    char *h_name;       /* official name of host */
+    char **h_aliases;   /* alias list */
+#ifdef WIN32
+    PRInt16 h_addrtype; /* host address type */
+    PRInt16 h_length;   /* length of address */
+#else
+    PRInt32 h_addrtype; /* host address type */
+    PRInt32 h_length;   /* length of address */
+#endif
+    char **h_addr_list; /* list of addresses from name server */
+} PRHostEnt;
+
+/* A safe size to use that will mostly work... */
+#if (defined(AIX) && defined(_THREAD_SAFE)) || defined(OSF1)
+#define PR_NETDB_BUF_SIZE sizeof(struct protoent_data)
+#else
+#define PR_NETDB_BUF_SIZE 1024
+#endif
+
+/***********************************************************************
+** FUNCTION:	
+** DESCRIPTION:	PR_GetHostByName()
+** Lookup a host by name.
+**
+** INPUTS:
+**  char *hostname      Character string defining the host name of interest
+**  char *buf           A scratch buffer for the runtime to return result.
+**                      This buffer is allocated by the caller.
+**  PRIntn bufsize      Number of bytes in 'buf'. A recommnded value to
+**                      use is PR_NETDB_BUF_SIZE.
+** OUTPUTS:
+**  PRHostEnt *hostentry
+**                      This structure is filled in by the runtime if
+**                      the function returns PR_SUCCESS. This structure
+**                      is allocated by the caller.
+** RETURN:
+**  PRStatus            PR_SUCCESS if the lookup succeeds. If it fails
+**                      the result will be PR_FAILURE and the reason
+**                      for the failure can be retrieved by PR_GetError().
+***********************************************************************/
+NSPR_API(PRStatus) PR_GetHostByName(
+    const char *hostname, char *buf, PRIntn bufsize, PRHostEnt *hostentry);
+
+/***********************************************************************
+** FUNCTION:	
+** DESCRIPTION:	PR_GetIPNodeByName()
+** Lookup a host by name. Equivalent to getipnodebyname(AI_DEFAULT)
+** of RFC 2553.
+**
+** INPUTS:
+**  char *hostname      Character string defining the host name of interest
+**  PRUint16 af         Address family (either PR_AF_INET or PR_AF_INET6)
+**  PRIntn flags        Specifies the types of addresses that are searched
+**                      for and the types of addresses that are returned.
+**                      The only supported flag is PR_AI_DEFAULT.
+**  char *buf           A scratch buffer for the runtime to return result.
+**                      This buffer is allocated by the caller.
+**  PRIntn bufsize      Number of bytes in 'buf'. A recommnded value to
+**                      use is PR_NETDB_BUF_SIZE.
+** OUTPUTS:
+**  PRHostEnt *hostentry
+**                      This structure is filled in by the runtime if
+**                      the function returns PR_SUCCESS. This structure
+**                      is allocated by the caller.
+** RETURN:
+**  PRStatus            PR_SUCCESS if the lookup succeeds. If it fails
+**                      the result will be PR_FAILURE and the reason
+**                      for the failure can be retrieved by PR_GetError().
+***********************************************************************/
+
+
+#define PR_AI_ALL         0x08
+#define PR_AI_V4MAPPED    0x10
+#define PR_AI_ADDRCONFIG  0x20
+#define PR_AI_NOCANONNAME 0x8000
+#define PR_AI_DEFAULT     (PR_AI_V4MAPPED | PR_AI_ADDRCONFIG)
+
+NSPR_API(PRStatus) PR_GetIPNodeByName(
+    const char *hostname,
+    PRUint16 af,
+    PRIntn flags,
+    char *buf,
+    PRIntn bufsize,
+    PRHostEnt *hostentry);
+
+/***********************************************************************
+** FUNCTION:	
+** DESCRIPTION:	PR_GetHostByAddr()
+** Lookup a host entry by its network address.
+**
+** INPUTS:
+**  char *hostaddr      IP address of host in question
+**  char *buf           A scratch buffer for the runtime to return result.
+**                      This buffer is allocated by the caller.
+**  PRIntn bufsize      Number of bytes in 'buf'. A recommnded value to
+**                      use is PR_NETDB_BUF_SIZE.
+** OUTPUTS:
+**  PRHostEnt *hostentry
+**                      This structure is filled in by the runtime if
+**                      the function returns PR_SUCCESS. This structure
+**                      is allocated by the caller.
+** RETURN:
+**  PRStatus            PR_SUCCESS if the lookup succeeds. If it fails
+**                      the result will be PR_FAILURE and the reason
+**                      for the failure can be retrieved by PR_GetError().
+***********************************************************************/
+NSPR_API(PRStatus) PR_GetHostByAddr(
+    const PRNetAddr *hostaddr, char *buf, PRIntn bufsize, PRHostEnt *hostentry);
+
+/***********************************************************************
+** FUNCTION:	PR_EnumerateHostEnt()	
+** DESCRIPTION:
+**  A stateless enumerator over a PRHostEnt structure acquired from
+**  PR_GetHostByName() PR_GetHostByAddr() to evaluate the possible
+**  network addresses.
+**
+** INPUTS:
+**  PRIntn  enumIndex   Index of the enumeration. The enumeration starts
+**                      and ends with a value of zero.
+**
+**  PRHostEnt *hostEnt  A pointer to a host entry struct that was
+**                      previously returned by PR_GetHostByName() or
+**                      PR_GetHostByAddr().
+**
+**  PRUint16 port       The port number to be assigned as part of the
+**                      PRNetAddr.
+**
+** OUTPUTS:
+**  PRNetAddr *address  A pointer to an address structure that will be
+**                      filled in by the call to the enumeration if the
+**                      result of the call is greater than zero.
+**
+** RETURN:
+**  PRIntn              The value that should be used for the next call
+**                      of the enumerator ('enumIndex'). The enumeration
+**                      is ended if this value is returned zero.
+**                      If a value of -1 is returned, the enumeration
+**                      has failed. The reason for the failure can be
+**                      retrieved by calling PR_GetError().
+***********************************************************************/
+NSPR_API(PRIntn) PR_EnumerateHostEnt(
+    PRIntn enumIndex, const PRHostEnt *hostEnt, PRUint16 port, PRNetAddr *address);
+
+/***********************************************************************
+** FUNCTION: PR_InitializeNetAddr(), 
+** DESCRIPTION:
+**  Initialize the fields of a PRNetAddr, assigning well known values as
+**  appropriate.
+**
+** INPUTS
+**  PRNetAddrValue val  The value to be assigned to the IP Address portion
+**                      of the network address. This can only specify the
+**                      special well known values that are equivalent to
+**                      INADDR_ANY and INADDR_LOOPBACK.
+**
+**  PRUint16 port       The port number to be assigned in the structure.
+**
+** OUTPUTS:
+**  PRNetAddr *addr     The address to be manipulated.
+**
+** RETURN:
+**  PRStatus            To indicate success or failure. If the latter, the
+**                      reason for the failure can be retrieved by calling
+**                      PR_GetError();
+***********************************************************************/
+typedef enum PRNetAddrValue
+{
+    PR_IpAddrNull,      /* do NOT overwrite the IP address */
+    PR_IpAddrAny,       /* assign logical INADDR_ANY to IP address */
+    PR_IpAddrLoopback,  /* assign logical INADDR_LOOPBACK  */
+    PR_IpAddrV4Mapped   /* IPv4 mapped address */
+} PRNetAddrValue;
+
+NSPR_API(PRStatus) PR_InitializeNetAddr(
+    PRNetAddrValue val, PRUint16 port, PRNetAddr *addr);
+
+/***********************************************************************
+** FUNCTION: PR_SetNetAddr(), 
+** DESCRIPTION:
+**  Set the fields of a PRNetAddr, assigning well known values as
+**  appropriate. This function is similar to PR_InitializeNetAddr
+**  but differs in that the address family is specified.
+**
+** INPUTS
+**  PRNetAddrValue val  The value to be assigned to the IP Address portion
+**                      of the network address. This can only specify the
+**                      special well known values that are equivalent to
+**                      INADDR_ANY and INADDR_LOOPBACK.
+**
+**  PRUint16 af         The address family (either PR_AF_INET or PR_AF_INET6)
+**
+**  PRUint16 port       The port number to be assigned in the structure.
+**
+** OUTPUTS:
+**  PRNetAddr *addr     The address to be manipulated.
+**
+** RETURN:
+**  PRStatus            To indicate success or failure. If the latter, the
+**                      reason for the failure can be retrieved by calling
+**                      PR_GetError();
+***********************************************************************/
+NSPR_API(PRStatus) PR_SetNetAddr(
+    PRNetAddrValue val, PRUint16 af, PRUint16 port, PRNetAddr *addr);
+
+/***********************************************************************
+** FUNCTION:	
+** DESCRIPTION:	PR_IsNetAddrType()
+** Determine if the network address is of the specified type.
+**
+** INPUTS:
+**  const PRNetAddr *addr   A network address.
+**  PRNetAddrValue          The type of network address 
+**
+** RETURN:
+**  PRBool                  PR_TRUE if the network address is of the
+**                          specified type, else PR_FALSE.
+***********************************************************************/
+NSPR_API(PRBool) PR_IsNetAddrType(const PRNetAddr *addr, PRNetAddrValue val);
+
+/***********************************************************************
+** FUNCTION:	
+** DESCRIPTION:	PR_ConvertIPv4AddrToIPv6()
+** Convert an IPv4 addr to an (IPv4-mapped) IPv6 addr
+**
+** INPUTS:
+**  PRUint32 	v4addr		IPv4 address
+**
+** OUTPUTS:
+**  PRIPv6Addr *v6addr      The converted IPv6 address
+**
+** RETURN:
+**  void
+**                       
+***********************************************************************/
+NSPR_API(void) PR_ConvertIPv4AddrToIPv6(PRUint32 v4addr, PRIPv6Addr *v6addr);
+
+/***********************************************************************
+** MACRO:	
+** DESCRIPTION:	PR_NetAddrFamily()
+** Get the 'family' field of a PRNetAddr union.
+**
+** INPUTS:
+**  const PRNetAddr *addr   A network address.
+**
+** RETURN:
+**  PRUint16                The 'family' field of 'addr'.
+***********************************************************************/
+#define PR_NetAddrFamily(addr) ((addr)->raw.family)
+
+/***********************************************************************
+** MACRO:	
+** DESCRIPTION:	PR_NetAddrInetPort()
+** Get the 'port' field of a PRNetAddr union.
+**
+** INPUTS:
+**  const PRNetAddr *addr   A network address.
+**
+** RETURN:
+**  PRUint16                The 'port' field of 'addr'.
+***********************************************************************/
+#define PR_NetAddrInetPort(addr) \
+    ((addr)->raw.family == PR_AF_INET6 ? (addr)->ipv6.port : (addr)->inet.port)
+
+/***********************************************************************
+** FUNCTION:	
+** DESCRIPTION:	PR_GetProtoByName()
+** Lookup a protocol entry based on protocol's name
+**
+** INPUTS:
+**  char *protocolname  Character string of the protocol's name.
+**  char *buf           A scratch buffer for the runtime to return result.
+**                      This buffer is allocated by the caller.
+**  PRIntn bufsize      Number of bytes in 'buf'. A recommnded value to
+**                      use is PR_NETDB_BUF_SIZE.
+** OUTPUTS:
+**  PRHostEnt *PRProtoEnt
+**                      This structure is filled in by the runtime if
+**                      the function returns PR_SUCCESS. This structure
+**                      is allocated by the caller.
+** RETURN:
+**  PRStatus            PR_SUCCESS if the lookup succeeds. If it fails
+**                      the result will be PR_FAILURE and the reason
+**                      for the failure can be retrieved by PR_GetError().
+***********************************************************************/
+
+typedef struct PRProtoEnt {
+    char *p_name;       /* official protocol name */
+    char **p_aliases;   /* alias list */
+#ifdef WIN32
+    PRInt16 p_num;      /* protocol # */
+#else
+    PRInt32 p_num;      /* protocol # */
+#endif
+} PRProtoEnt;
+
+NSPR_API(PRStatus) PR_GetProtoByName(
+    const char* protocolname, char* buffer, PRInt32 bufsize, PRProtoEnt* result);
+
+/***********************************************************************
+** FUNCTION:	
+** DESCRIPTION:	PR_GetProtoByNumber()
+** Lookup a protocol entry based on protocol's number
+**
+** INPUTS:
+**  PRInt32 protocolnumber
+**                      Number assigned to the protocol.
+**  char *buf           A scratch buffer for the runtime to return result.
+**                      This buffer is allocated by the caller.
+**  PRIntn bufsize      Number of bytes in 'buf'. A recommnded value to
+**                      use is PR_NETDB_BUF_SIZE.
+** OUTPUTS:
+**  PRHostEnt *PRProtoEnt
+**                      This structure is filled in by the runtime if
+**                      the function returns PR_SUCCESS. This structure
+**                      is allocated by the caller.
+** RETURN:
+**  PRStatus            PR_SUCCESS if the lookup succeeds. If it fails
+**                      the result will be PR_FAILURE and the reason
+**                      for the failure can be retrieved by PR_GetError().
+***********************************************************************/
+NSPR_API(PRStatus) PR_GetProtoByNumber(
+    PRInt32 protocolnumber, char* buffer, PRInt32 bufsize, PRProtoEnt* result);
+
+/***********************************************************************
+** FUNCTION:
+** DESCRIPTION: PR_GetAddrInfoByName()
+**  Look up a host by name. Equivalent to getaddrinfo(host, NULL, ...) of
+**  RFC 3493.
+**
+** INPUTS:
+**  char *hostname      Character string defining the host name of interest
+**  PRUint16 af         May be PR_AF_UNSPEC or PR_AF_INET.
+**  PRIntn flags        May be either PR_AI_ADDRCONFIG or
+**                      PR_AI_ADDRCONFIG | PR_AI_NOCANONNAME. Include
+**                      PR_AI_NOCANONNAME to suppress the determination of
+**                      the canonical name corresponding to hostname.
+** RETURN:
+**  PRAddrInfo*         Handle to a data structure containing the results
+**                      of the host lookup. Use PR_EnumerateAddrInfo to
+**                      inspect the PRNetAddr values stored in this object.
+**                      When no longer needed, this handle must be destroyed
+**                      with a call to PR_FreeAddrInfo.  If a lookup error
+**                      occurs, then NULL will be returned.
+***********************************************************************/
+typedef struct PRAddrInfo PRAddrInfo;
+
+NSPR_API(PRAddrInfo*) PR_GetAddrInfoByName(
+    const char *hostname, PRUint16 af, PRIntn flags);
+
+/***********************************************************************
+** FUNCTION:
+** DESCRIPTION: PR_FreeAddrInfo()
+**  Destroy the PRAddrInfo handle allocated by PR_GetAddrInfoByName().
+**
+** INPUTS:
+**  PRAddrInfo *addrInfo
+**                      The handle resulting from a successful call to
+**                      PR_GetAddrInfoByName().
+** RETURN:
+**  void
+***********************************************************************/
+NSPR_API(void) PR_FreeAddrInfo(PRAddrInfo *addrInfo);
+
+/***********************************************************************
+** FUNCTION:
+** DESCRIPTION: PR_EnumerateAddrInfo()
+**  A stateless enumerator over a PRAddrInfo handle acquired from
+**  PR_GetAddrInfoByName() to inspect the possible network addresses.
+**
+** INPUTS:
+**  void *enumPtr       Index pointer of the enumeration. The enumeration
+**                      starts and ends with a value of NULL.
+**  const PRAddrInfo *addrInfo
+**                      The PRAddrInfo handle returned by a successful
+**                      call to PR_GetAddrInfoByName().
+**  PRUint16 port       The port number to be assigned as part of the
+**                      PRNetAddr.
+** OUTPUTS:
+**  PRNetAddr *result   A pointer to an address structure that will be
+**                      filled in by the call to the enumeration if the
+**                      result of the call is not NULL.
+** RETURN:
+**  void*               The value that should be used for the next call
+**                      of the enumerator ('enumPtr'). The enumeration
+**                      is ended if this value is NULL.
+***********************************************************************/
+NSPR_API(void *) PR_EnumerateAddrInfo(
+    void *enumPtr, const PRAddrInfo *addrInfo, PRUint16 port, PRNetAddr *result);
+
+/***********************************************************************
+** FUNCTION:
+** DESCRIPTION: PR_GetCanonNameFromAddrInfo()
+**  Extracts the canonical name of the hostname passed to
+**  PR_GetAddrInfoByName().
+**
+** INPUTS:
+**  const PRAddrInfo *addrInfo 
+**                      The PRAddrInfo handle returned by a successful
+**                      call to PR_GetAddrInfoByName().
+** RETURN:
+**  const char *        A const pointer to the canonical hostname stored
+**                      in the given PRAddrInfo handle. This pointer is
+**                      invalidated once the PRAddrInfo handle is destroyed
+**                      by a call to PR_FreeAddrInfo().
+***********************************************************************/
+NSPR_API(const char *) PR_GetCanonNameFromAddrInfo(
+    const PRAddrInfo *addrInfo);
+
+/***********************************************************************
+** FUNCTIONS: PR_ntohs, PR_ntohl, PR_ntohll, PR_htons, PR_htonl, PR_htonll
+**
+** DESCRIPTION: API entries for the common byte ordering routines.
+**
+**      PR_ntohs        16 bit conversion from network to host
+**      PR_ntohl        32 bit conversion from network to host
+**      PR_ntohll       64 bit conversion from network to host
+**      PR_htons        16 bit conversion from host to network
+**      PR_htonl        32 bit conversion from host to network
+**      PR_ntonll       64 bit conversion from host to network
+**
+***********************************************************************/
+NSPR_API(PRUint16) PR_ntohs(PRUint16);
+NSPR_API(PRUint32) PR_ntohl(PRUint32);
+NSPR_API(PRUint64) PR_ntohll(PRUint64);
+NSPR_API(PRUint16) PR_htons(PRUint16);
+NSPR_API(PRUint32) PR_htonl(PRUint32);
+NSPR_API(PRUint64) PR_htonll(PRUint64);
+
+PR_END_EXTERN_C
+
+#endif /* prnetdb_h___ */
diff --git a/pr/include/prolock.h b/pr/include/prolock.h
new file mode 100644
index 0000000..5e5a409
--- /dev/null
+++ b/pr/include/prolock.h
@@ -0,0 +1,178 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef prolock_h___
+#define prolock_h___
+
+#include "prtypes.h"
+
+PR_BEGIN_EXTERN_C
+
+/*
+** A locking mechanism, built on the existing PRLock definition,
+** is provided that will permit applications to define a Lock
+** Hierarchy (or Lock Ordering) schema. An application designed
+** using the Ordered Lock functions will terminate with a
+** diagnostic message when a lock inversion condition is
+** detected. 
+** 
+** The lock ordering detection is compile-time enabled only. In
+** optimized builds of NSPR, the Ordered Lock functions map
+** directly to PRLock functions, providing no lock order
+** detection.
+** 
+** The Ordered Lock Facility is compiled in when DEBUG is defined at
+** compile-time. Ordered Lock can be forced on in optimized builds by
+** defining FORCE_NSPR_ORDERED_LOCK at compile-time. Both the
+** application using Ordered Lock and NSPR must be compiled with the
+** facility enabled to achieve the desired results.
+** 
+** Application designers should use the macro interfaces to the Ordered
+** Lock facility to ensure that it is compiled out in optimized builds.
+**
+** Application designers are responsible for defining their own
+** lock hierarchy. 
+**
+** Ordered Lock is thread-safe and SMP safe.
+**
+** See Also: prlock.h
+**
+** /lth. 10-Jun-1998.
+**
+*/
+
+/*
+** Opaque type for ordered lock.
+** ... Don't even think of looking in here.
+**
+*/
+
+#if defined(DEBUG) || defined(FORCE_NSPR_ORDERED_LOCKS)
+typedef void * PROrderedLock;
+#else
+/*
+** Map PROrderedLock and methods onto PRLock when ordered locking
+** is not compiled in.
+**  
+*/
+#include "prlock.h"
+
+typedef PRLock PROrderedLock;
+#endif
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_CreateOrderedLock() -- Create an Ordered Lock
+** 
+** DESCRIPTION: PR_CreateOrderedLock() creates an ordered lock.
+** 
+** INPUTS:
+**  order: user defined order of this lock.
+**  name: name of the lock. For debugging purposes.
+** 
+** OUTPUTS: returned
+** 
+** RETURNS: PR_OrderedLock pointer
+** 
+** RESTRICTIONS:
+** 
+*/
+#if defined(DEBUG) || defined(FORCE_NSPR_ORDERED_LOCKS)
+#define PR_CREATE_ORDERED_LOCK(order,name)\
+    PR_CreateOrderedLock((order),(name))
+#else
+#define PR_CREATE_ORDERED_LOCK(order) PR_NewLock()
+#endif
+
+NSPR_API(PROrderedLock *) 
+    PR_CreateOrderedLock( 
+        PRInt32 order,
+        const char *name
+);
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_DestroyOrderedLock() -- Destroy an Ordered Lock
+** 
+** DESCRIPTION: PR_DestroyOrderedLock() destroys the ordered lock
+** referenced by lock.
+** 
+** INPUTS: lock: pointer to a PROrderedLock
+** 
+** OUTPUTS: the lock is destroyed
+** 
+** RETURNS: void
+** 
+** RESTRICTIONS:
+** 
+*/
+#if defined(DEBUG) || defined(FORCE_NSPR_ORDERED_LOCKS)
+#define PR_DESTROY_ORDERED_LOCK(lock) PR_DestroyOrderedLock((lock))
+#else
+#define PR_DESTROY_ORDERED_LOCK(lock) PR_DestroyLock((lock))
+#endif
+
+NSPR_API(void) 
+    PR_DestroyOrderedLock( 
+        PROrderedLock *lock 
+);
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_LockOrderedLock() -- Lock an ordered lock
+** 
+** DESCRIPTION: PR_LockOrderedLock() locks the ordered lock
+** referenced by lock. If the order of lock is less than or equal
+** to the order of the highest lock held by the locking thread,
+** the function asserts.
+** 
+** INPUTS: lock: a pointer to a PROrderedLock
+** 
+** OUTPUTS: The lock is held or the function asserts.
+** 
+** RETURNS: void
+** 
+** RESTRICTIONS:
+** 
+*/
+#if defined(DEBUG) || defined(FORCE_NSPR_ORDERED_LOCKS)
+#define PR_LOCK_ORDERED_LOCK(lock) PR_LockOrderedLock((lock))
+#else
+#define PR_LOCK_ORDERED_LOCK(lock) PR_Lock((lock))
+#endif
+
+NSPR_API(void) 
+    PR_LockOrderedLock( 
+        PROrderedLock *lock 
+);
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_UnlockOrderedLock() -- unlock and Ordered Lock
+** 
+** DESCRIPTION: PR_UnlockOrderedLock() unlocks the lock referenced
+** by lock.
+** 
+** INPUTS: lock: a pointer to a PROrderedLock
+** 
+** OUTPUTS: the lock is unlocked
+** 
+** RETURNS:
+**  PR_SUCCESS
+**  PR_FAILURE
+** 
+** RESTRICTIONS:
+** 
+*/
+#if defined(DEBUG) || defined(FORCE_NSPR_ORDERED_LOCKS)
+#define PR_UNLOCK_ORDERED_LOCK(lock) PR_UnlockOrderedLock((lock))
+#else
+#define PR_UNLOCK_ORDERED_LOCK(lock) PR_Unlock((lock))
+#endif
+
+NSPR_API(PRStatus) 
+    PR_UnlockOrderedLock( 
+        PROrderedLock *lock 
+);
+
+PR_END_EXTERN_C
+
+#endif /* prolock_h___ */
diff --git a/pr/include/prpdce.h b/pr/include/prpdce.h
new file mode 100644
index 0000000..b681795
--- /dev/null
+++ b/pr/include/prpdce.h
@@ -0,0 +1,86 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+ * File:		prpdce.h
+ * Description:	This file is the API defined to allow for DCE (aka POSIX)
+ *				thread emulation in an NSPR environment. It is not the
+ *				intent that this be a fully supported API.
+ */
+
+#if !defined(PRPDCE_H)
+#define PRPDCE_H
+
+#include "prlock.h"
+#include "prcvar.h"
+#include "prtypes.h"
+#include "prinrval.h"
+
+PR_BEGIN_EXTERN_C
+
+#define _PR_NAKED_CV_LOCK (PRLock*)0xdce1dce1
+
+/*
+** Test and acquire a lock.
+**
+** If the lock is acquired by the calling thread, the
+** return value will be PR_SUCCESS. If the lock is
+** already held, by another thread or this thread, the
+** result will be PR_FAILURE.
+*/
+NSPR_API(PRStatus) PRP_TryLock(PRLock *lock);
+
+/*
+** Create a naked condition variable
+**
+** A "naked" condition variable is one that is not created bound
+** to a lock. The CV created with this function is the only type
+** that may be used in the subsequent "naked" condition variable
+** operations (see PRP_NakedWait, PRP_NakedNotify, PRP_NakedBroadcast);
+*/
+NSPR_API(PRCondVar*) PRP_NewNakedCondVar(void);
+
+/*
+** Destroy a naked condition variable
+**
+** Destroy the condition variable created by PR_NewNakedCondVar.
+*/
+NSPR_API(void) PRP_DestroyNakedCondVar(PRCondVar *cvar);
+
+/*
+** Wait on a condition
+**
+** Wait on the condition variable 'cvar'. It is asserted that
+** the lock protecting the condition 'lock' is held by the
+** calling thread. If more time expires than that declared in
+** 'timeout' the condition will be notified. Waits can be
+** interrupted by another thread.
+**
+** NB: The CV ('cvar') must be one created using PR_NewNakedCondVar.
+*/
+NSPR_API(PRStatus) PRP_NakedWait(
+	PRCondVar *cvar, PRLock *lock, PRIntervalTime timeout);
+
+/*
+** Notify a thread waiting on a condition
+**
+** Notify the condition specified 'cvar'.
+**
+** NB: The CV ('cvar') must be one created using PR_NewNakedCondVar.
+*/
+NSPR_API(PRStatus) PRP_NakedNotify(PRCondVar *cvar);
+
+/*
+** Notify all threads waiting on a condition
+**
+** Notify the condition specified 'cvar'.
+**
+** NB: The CV ('cvar') must be one created using PR_NewNakedCondVar.
+*/
+NSPR_API(PRStatus) PRP_NakedBroadcast(PRCondVar *cvar);
+
+PR_END_EXTERN_C
+
+#endif /* PRPDCE_H */
diff --git a/pr/include/prprf.h b/pr/include/prprf.h
new file mode 100644
index 0000000..440be88
--- /dev/null
+++ b/pr/include/prprf.h
@@ -0,0 +1,122 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef prprf_h___
+#define prprf_h___
+
+/*
+** API for PR printf like routines. Supports the following formats
+**	%d - decimal
+**	%u - unsigned decimal
+**	%x - unsigned hex
+**	%X - unsigned uppercase hex
+**	%o - unsigned octal
+**	%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
+**	%s - string
+**	%c - character
+**	%p - pointer (deals with machine dependent pointer size)
+**	%f - float
+**	%g - float
+*/
+#include "prtypes.h"
+#include "prio.h"
+#include <stdio.h>
+#include <stdarg.h>
+
+PR_BEGIN_EXTERN_C
+
+/*
+** sprintf into a fixed size buffer. Guarantees that a NUL is at the end
+** of the buffer. Returns the length of the written output, NOT including
+** the NUL, or (PRUint32)-1 if an error occurs.
+*/
+NSPR_API(PRUint32) PR_snprintf(char *out, PRUint32 outlen, const char *fmt, ...);
+
+/*
+** sprintf into a PR_MALLOC'd buffer. Return a pointer to the malloc'd
+** buffer on success, NULL on failure. Call "PR_smprintf_free" to release
+** the memory returned.
+*/
+NSPR_API(char*) PR_smprintf(const char *fmt, ...);
+
+/*
+** Free the memory allocated, for the caller, by PR_smprintf
+*/
+NSPR_API(void) PR_smprintf_free(char *mem);
+
+/*
+** "append" sprintf into a PR_MALLOC'd buffer. "last" is the last value of
+** the PR_MALLOC'd buffer. sprintf will append data to the end of last,
+** growing it as necessary using realloc. If last is NULL, PR_sprintf_append
+** will allocate the initial string. The return value is the new value of
+** last for subsequent calls, or NULL if there is a malloc failure.
+*/
+NSPR_API(char*) PR_sprintf_append(char *last, const char *fmt, ...);
+
+/*
+** sprintf into a function. The function "f" is called with a string to
+** place into the output. "arg" is an opaque pointer used by the stuff
+** function to hold any state needed to do the storage of the output
+** data. The return value is a count of the number of characters fed to
+** the stuff function, or (PRUint32)-1 if an error occurs.
+*/
+typedef PRIntn (*PRStuffFunc)(void *arg, const char *s, PRUint32 slen);
+
+NSPR_API(PRUint32) PR_sxprintf(PRStuffFunc f, void *arg, const char *fmt, ...);
+
+/*
+** fprintf to a PRFileDesc
+*/
+NSPR_API(PRUint32) PR_fprintf(struct PRFileDesc* fd, const char *fmt, ...);
+
+/*
+** va_list forms of the above.
+*/
+NSPR_API(PRUint32) PR_vsnprintf(char *out, PRUint32 outlen, const char *fmt, va_list ap);
+NSPR_API(char*) PR_vsmprintf(const char *fmt, va_list ap);
+NSPR_API(char*) PR_vsprintf_append(char *last, const char *fmt, va_list ap);
+NSPR_API(PRUint32) PR_vsxprintf(PRStuffFunc f, void *arg, const char *fmt, va_list ap);
+NSPR_API(PRUint32) PR_vfprintf(struct PRFileDesc* fd, const char *fmt, va_list ap);
+
+/*
+***************************************************************************
+** FUNCTION: PR_sscanf
+** DESCRIPTION:
+**     PR_sscanf() scans the input character string, performs data
+**     conversions, and stores the converted values in the data objects
+**     pointed to by its arguments according to the format control
+**     string.
+**
+**     PR_sscanf() behaves the same way as the sscanf() function in the
+**     Standard C Library (stdio.h), with the following exceptions:
+**     - PR_sscanf() handles the NSPR integer and floating point types,
+**       such as PRInt16, PRInt32, PRInt64, and PRFloat64, whereas
+**       sscanf() handles the standard C types like short, int, long,
+**       and double.
+**     - PR_sscanf() has no multibyte character support, while sscanf()
+**       does.
+** INPUTS:
+**     const char *buf
+**         a character string holding the input to scan
+**     const char *fmt
+**         the format control string for the conversions
+**     ...
+**         variable number of arguments, each of them is a pointer to
+**         a data object in which the converted value will be stored
+** OUTPUTS: none
+** RETURNS: PRInt32
+**     The number of values converted and stored.
+** RESTRICTIONS:
+**    Multibyte characters in 'buf' or 'fmt' are not allowed.
+***************************************************************************
+*/
+
+NSPR_API(PRInt32) PR_sscanf(const char *buf, const char *fmt, ...);
+
+PR_END_EXTERN_C
+
+#endif /* prprf_h___ */
diff --git a/pr/include/prproces.h b/pr/include/prproces.h
new file mode 100644
index 0000000..9782542
--- /dev/null
+++ b/pr/include/prproces.h
@@ -0,0 +1,86 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef prproces_h___
+#define prproces_h___
+
+#include "prtypes.h"
+#include "prio.h"
+
+PR_BEGIN_EXTERN_C
+
+/************************************************************************/
+/*****************************PROCESS OPERATIONS*************************/
+/************************************************************************/
+
+typedef struct PRProcess PRProcess;
+typedef struct PRProcessAttr PRProcessAttr;
+
+NSPR_API(PRProcessAttr *) PR_NewProcessAttr(void);
+
+NSPR_API(void) PR_ResetProcessAttr(PRProcessAttr *attr);
+
+NSPR_API(void) PR_DestroyProcessAttr(PRProcessAttr *attr);
+
+NSPR_API(void) PR_ProcessAttrSetStdioRedirect(
+    PRProcessAttr *attr,
+    PRSpecialFD stdioFd,
+    PRFileDesc *redirectFd
+);
+
+/*
+ * OBSOLETE -- use PR_ProcessAttrSetStdioRedirect instead.
+ */
+NSPR_API(void) PR_SetStdioRedirect(
+    PRProcessAttr *attr,
+    PRSpecialFD stdioFd,
+    PRFileDesc *redirectFd
+);
+
+NSPR_API(PRStatus) PR_ProcessAttrSetCurrentDirectory(
+    PRProcessAttr *attr,
+    const char *dir
+);
+
+NSPR_API(PRStatus) PR_ProcessAttrSetInheritableFD(
+    PRProcessAttr *attr,
+    PRFileDesc *fd,
+    const char *name
+);
+
+/*
+** Create a new process
+**
+** Create a new process executing the file specified as 'path' and with
+** the supplied arguments and environment.
+**
+** This function may fail because of illegal access (permissions),
+** invalid arguments or insufficient resources.
+**
+** A process may be created such that the creator can later synchronize its
+** termination using PR_WaitProcess(). 
+*/
+
+NSPR_API(PRProcess*) PR_CreateProcess(
+    const char *path,
+    char *const *argv,
+    char *const *envp,
+    const PRProcessAttr *attr);
+
+NSPR_API(PRStatus) PR_CreateProcessDetached(
+    const char *path,
+    char *const *argv,
+    char *const *envp,
+    const PRProcessAttr *attr);
+
+NSPR_API(PRStatus) PR_DetachProcess(PRProcess *process);
+
+NSPR_API(PRStatus) PR_WaitProcess(PRProcess *process, PRInt32 *exitCode);
+
+NSPR_API(PRStatus) PR_KillProcess(PRProcess *process);
+
+PR_END_EXTERN_C
+
+#endif /* prproces_h___ */
diff --git a/pr/include/prrng.h b/pr/include/prrng.h
new file mode 100644
index 0000000..3b5a443
--- /dev/null
+++ b/pr/include/prrng.h
@@ -0,0 +1,75 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+/*
+** prrng.h -- NSPR Random Number Generator
+** 
+**
+** lth. 29-Oct-1999.
+*/
+
+#ifndef prrng_h___ 
+#define prrng_h___
+
+#include "prtypes.h"
+
+PR_BEGIN_EXTERN_C
+
+/*
+** PR_GetRandomNoise() -- Get random noise from the host platform
+**
+** Description:
+** PR_GetRandomNoise() provides, depending on platform, a random value.
+** The length of the random value is dependent on platform and the
+** platform's ability to provide a random value at that moment.
+**
+** The intent of PR_GetRandomNoise() is to provide a "seed" value for a
+** another random number generator that may be suitable for
+** cryptographic operations. This implies that the random value
+** provided may not be, by itself, cryptographically secure. The value
+** generated by PR_GetRandomNoise() is at best, extremely difficult to
+** predict and is as non-deterministic as the underlying platfrom can
+** provide.
+**
+** Inputs:
+**   buf -- pointer to a caller supplied buffer to contain the
+**          generated random number. buf must be at least as large as
+**          is specified in the 'size' argument.
+**
+**   size -- the requested size of the generated random number
+**
+** Outputs:
+**   a random number provided in 'buf'.
+**
+** Returns:
+**   PRSize value equal to the size of the random number actually
+**   generated, or zero. The generated size may be less than the size
+**   requested. A return value of zero means that PR_GetRandomNoise() is
+**   not implemented on this platform, or there is no available noise
+**   available to be returned at the time of the call.
+**
+** Restrictions:
+**   Calls to PR_GetRandomNoise() may use a lot of CPU on some platforms.
+**   Some platforms may block for up to a few seconds while they
+**   accumulate some noise. Busy machines generate lots of noise, but
+**   care is advised when using PR_GetRandomNoise() frequently in your
+**   application.
+**
+** History:
+**   Parts of the model dependent implementation for PR_GetRandomNoise()
+**   were taken in whole or part from code previously in Netscape's NSS
+**   component.
+**
+*/
+NSPR_API(PRSize) PR_GetRandomNoise( 
+    void    *buf,
+    PRSize  size
+);
+
+PR_END_EXTERN_C
+
+#endif /* prrng_h___ */
+/* end prrng.h */
diff --git a/pr/include/prrwlock.h b/pr/include/prrwlock.h
new file mode 100644
index 0000000..65d052d
--- /dev/null
+++ b/pr/include/prrwlock.h
@@ -0,0 +1,88 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** File:		prrwlock.h
+** Description:	API to basic reader-writer lock functions of NSPR.
+**
+**/
+
+#ifndef prrwlock_h___
+#define prrwlock_h___
+
+#include "prtypes.h"
+
+PR_BEGIN_EXTERN_C
+
+/*
+ * PRRWLock --
+ *
+ *	The reader writer lock, PRRWLock, is an opaque object to the clients
+ *	of NSPR.  All routines operate on a pointer to this opaque entity.
+ */
+
+
+typedef struct PRRWLock PRRWLock;
+
+#define	PR_RWLOCK_RANK_NONE	0
+
+
+/***********************************************************************
+** FUNCTION:    PR_NewRWLock
+** DESCRIPTION:
+**  Returns a pointer to a newly created reader-writer lock object.
+** INPUTS:      Lock rank
+**				Lock name
+** OUTPUTS:     void
+** RETURN:      PRRWLock*
+**   If the lock cannot be created because of resource constraints, NULL
+**   is returned.
+**  
+***********************************************************************/
+NSPR_API(PRRWLock*) PR_NewRWLock(PRUint32 lock_rank, const char *lock_name);
+
+/***********************************************************************
+** FUNCTION:    PR_DestroyRWLock
+** DESCRIPTION:
+**  Destroys a given RW lock object.
+** INPUTS:      PRRWLock *lock - Lock to be freed.
+** OUTPUTS:     void
+** RETURN:      None
+***********************************************************************/
+NSPR_API(void) PR_DestroyRWLock(PRRWLock *lock);
+
+/***********************************************************************
+** FUNCTION:    PR_RWLock_Rlock
+** DESCRIPTION:
+**  Apply a read lock (non-exclusive) on a RWLock
+** INPUTS:      PRRWLock *lock - Lock to be read-locked.
+** OUTPUTS:     void
+** RETURN:      None
+***********************************************************************/
+NSPR_API(void) PR_RWLock_Rlock(PRRWLock *lock);
+
+/***********************************************************************
+** FUNCTION:    PR_RWLock_Wlock
+** DESCRIPTION:
+**  Apply a write lock (exclusive) on a RWLock
+** INPUTS:      PRRWLock *lock - Lock to write-locked.
+** OUTPUTS:     void
+** RETURN:      None
+***********************************************************************/
+NSPR_API(void) PR_RWLock_Wlock(PRRWLock *lock);
+
+/***********************************************************************
+** FUNCTION:    PR_RWLock_Unlock
+** DESCRIPTION:
+**  Release a RW lock. Unlocking an unlocked lock has undefined results.
+** INPUTS:      PRRWLock *lock - Lock to unlocked.
+** OUTPUTS:     void
+** RETURN:      void
+***********************************************************************/
+NSPR_API(void) PR_RWLock_Unlock(PRRWLock *lock);
+
+PR_END_EXTERN_C
+
+#endif /* prrwlock_h___ */
diff --git a/pr/include/prshm.h b/pr/include/prshm.h
new file mode 100644
index 0000000..f821a58
--- /dev/null
+++ b/pr/include/prshm.h
@@ -0,0 +1,257 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** prshm.h -- NSPR Shared Memory
+**
+** NSPR Named Shared Memory API provides a cross-platform named
+** shared-memory interface. NSPR Named Shared Memory is modeled on
+** similar constructs in Unix and Windows operating systems. Shared
+** memory allows multiple processes to access one or more common shared
+** memory regions, using it as an inter-process communication channel.
+**
+** Notes on Platform Independence:
+**   NSPR Named Shared Memory is built on the native services offered
+**   by most platforms. The NSPR Named Shared Memory API tries to
+**   provide a least common denominator interface so that it works
+**   across all supported platforms. To ensure that it works everywhere,
+**   some platform considerations must be accomodated and the protocol
+**   for using NSPR Shared Memory API must be observed.
+**
+** Protocol:
+**   Multiple shared memories can be created using NSPR's Shared Memory
+**   feature. For each named shared memory, as defined by the name
+**   given in the PR_OpenSharedMemory() call, a protocol for using the
+**   shared memory API is required to ensure desired behavior. Failing
+**   to follow the protocol may yield unpredictable results.
+**   
+**   PR_OpenSharedMemory() will create the shared memory segment, if it
+**   does not already exist, or open a connection that the existing
+**   shared memory segment if it already exists.
+**   
+**   PR_AttachSharedMemory() should be called following
+**   PR_OpenSharedMemory() to map the memory segment to an address in
+**   the application's address space.
+**   
+**   PR_AttachSharedMemory() may be called to re-map a shared memory
+**   segment after detaching the same PRSharedMemory object. Be
+**   sure to detach it when done.
+**   
+**   PR_DetachSharedMemory() should be called to un-map the shared
+**   memory segment from the application's address space.
+**   
+**   PR_CloseSharedMemory() should be called when no further use of the
+**   PRSharedMemory object is required within a process. Following a
+**   call to  PR_CloseSharedMemory() the PRSharedMemory object is
+**   invalid and cannot be reused.
+**   
+**   PR_DeleteSharedMemory() should be called before process
+**   termination. After calling PR_DeleteSharedMemory() any further use
+**   of the shared memory associated with the name may cause
+**   unpredictable results.
+**   
+** Files:
+**   The name passed to PR_OpenSharedMemory() should be a valid filename
+**   for a unix platform. PR_OpenSharedMemory() creates file using the
+**   name passed in. Some platforms may mangle the name before creating
+**   the file and the shared memory.
+**   
+**   The unix implementation may use SysV IPC shared memory, Posix
+**   shared memory, or memory mapped files; the filename may used to
+**   define the namespace. On Windows, the name is significant, but
+**   there is no file associated with name.
+**   
+**   No assumptions about the persistence of data in the named file
+**   should be made. Depending on platform, the shared memory may be
+**   mapped onto system paging space and be discarded at process
+**   termination.
+**   
+**   All names provided to PR_OpenSharedMemory() should be valid
+**   filename syntax or name syntax for shared memory for the target
+**   platform. Referenced directories should have permissions 
+**   appropriate for writing.
+**
+** Limits:
+**   Different platforms have limits on both the number and size of
+**   shared memory resources. The default system limits on some
+**   platforms may be smaller than your requirements. These limits may
+**   be adjusted on some platforms either via boot-time options or by
+**   setting the size of the system paging space to accomodate more
+**   and/or larger shared memory segment(s).
+**
+** Security:
+**   On unix platforms, depending on implementation, contents of the
+**   backing store for the shared memory can be exposed via the file
+**   system. Set permissions and or access controls at create and attach
+**   time to ensure you get the desired security.
+**
+**   On windows platforms, no special security measures are provided.
+**
+** Example:
+**   The test case pr/tests/nameshm1.c provides an example of use as
+**   well as testing the operation of NSPR's Named Shared Memory.
+**
+** lth. 18-Aug-1999.
+*/
+
+#ifndef prshm_h___
+#define prshm_h___
+
+#include "prtypes.h"
+#include "prio.h"
+
+PR_BEGIN_EXTERN_C
+
+/*
+** Declare opaque type PRSharedMemory.
+*/
+typedef struct PRSharedMemory PRSharedMemory;
+
+/*
+** FUNCTION: PR_OpenSharedMemory()
+**
+** DESCRIPTION:
+**   PR_OpenSharedMemory() creates a new shared-memory segment or
+**   associates a previously created memory segment with name.
+**
+**   When parameter create is (PR_SHM_EXCL | PR_SHM_CREATE) and the
+**   shared memory already exists, the function returns NULL with the
+**   error set to PR_FILE_EXISTS_ERROR.
+**
+**   When parameter create is PR_SHM_CREATE and the shared memory
+**   already exists, a handle to that memory segment is returned. If
+**   the segment does not exist, it is created and a pointer to the
+**   related PRSharedMemory structure is returned.
+**
+**   When parameter create is 0, and the shared memory exists, a
+**   pointer to a PRSharedMemory is returned. If the shared memory does
+**   not exist, NULL is returned with the error set to
+**   PR_FILE_NOT_FOUND_ERROR.
+**
+** INPUTS:
+**   name -- the name the shared-memory segment is known as.
+**   size -- the size of the shared memory segment. 
+**   flags -- Options for creating the shared memory
+**   mode -- Same as is passed to PR_Open()
+**
+** OUTPUTS: 
+**   The shared memory is allocated.
+**
+** RETURNS: Pointer to opaque structure PRSharedMemory or NULL.
+**   NULL is returned on error. The reason for the error can be
+**   retrieved via PR_GetError() and PR_GetOSError();
+**
+*/
+NSPR_API( PRSharedMemory * )
+    PR_OpenSharedMemory(
+        const char *name,
+        PRSize      size,
+        PRIntn      flags,
+        PRIntn      mode
+);
+/* Define values for PR_OpenShareMemory(...,create) */
+#define PR_SHM_CREATE 0x1  /* create if not exist */
+#define PR_SHM_EXCL   0x2  /* fail if already exists */
+
+/*
+** FUNCTION: PR_AttachSharedMemory()
+**
+** DESCRIPTION:
+** PR_AttachSharedMemory() maps the shared-memory described by
+** shm to the current process. 
+**
+** INPUTS: 
+**   shm -- The handle returned from PR_OpenSharedMemory().
+**   flags -- options for mapping the shared memory.
+**   PR_SHM_READONLY causes the memory to be attached 
+**   read-only.
+**
+** OUTPUTS:
+**   On success, the shared memory segment represented by shm is mapped
+**   into the process' address space.
+**
+** RETURNS: Address where shared memory is mapped, or NULL.
+**   NULL is returned on error. The reason for the error can be
+**   retrieved via PR_GetError() and PR_GetOSError();
+**
+**
+*/
+NSPR_API( void * )
+    PR_AttachSharedMemory(
+        PRSharedMemory *shm,
+        PRIntn  flags
+);
+/* Define values for PR_AttachSharedMemory(...,flags) */ 
+#define PR_SHM_READONLY 0x01
+
+/*
+** FUNCTION: PR_DetachSharedMemory()
+**
+** DESCRIPTION:
+**   PR_DetachSharedMemory() detaches the shared-memory described
+**   by shm. 
+**
+** INPUTS: 
+**   shm -- The handle returned from PR_OpenSharedMemory().
+**   addr -- The address at which the memory was attached.
+**
+** OUTPUTS:
+**   The shared memory mapped to an address via a previous call to
+**   PR_AttachSharedMemory() is unmapped.
+**
+** RETURNS: PRStatus
+**
+*/
+NSPR_API( PRStatus )
+    PR_DetachSharedMemory(
+        PRSharedMemory *shm,
+        void  *addr
+);
+
+/*
+** FUNCTION: PR_CloseSharedMemory()
+**
+** DESCRIPTION:
+**   PR_CloseSharedMemory() closes the shared-memory described by
+**   shm.
+** 
+** INPUTS:
+**   shm -- The handle returned from PR_OpenSharedMemory().
+**
+** OUTPUTS:
+**   the shared memory represented by shm is closed
+**
+** RETURNS: PRStatus
+**
+*/
+NSPR_API( PRStatus )
+    PR_CloseSharedMemory(
+        PRSharedMemory *shm
+);
+
+/*
+** FUNCTION: PR_DeleteSharedMemory()
+**
+** DESCRIPTION:
+**   The shared memory resource represented by name is released.
+**
+** INPUTS:
+**   name -- the name the shared-memory segment
+**
+** OUTPUTS:
+**   depending on platform, resources may be returned to the underlying
+**   operating system.
+**
+** RETURNS: PRStatus
+**
+*/
+NSPR_API( PRStatus )
+    PR_DeleteSharedMemory( 
+        const char *name
+);
+
+PR_END_EXTERN_C
+
+#endif /* prshm_h___ */
diff --git a/pr/include/prshma.h b/pr/include/prshma.h
new file mode 100644
index 0000000..2abc4ae
--- /dev/null
+++ b/pr/include/prshma.h
@@ -0,0 +1,239 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** prshma.h -- NSPR Anonymous Shared Memory
+**
+** NSPR provides an anonymous shared memory based on NSPR's PRFileMap
+** type. The anonymous file-mapped shared memory provides an inheritable
+** shared memory, as in: the child process inherits the shared memory.
+** Compare the file-mapped anonymous shared memory to to a named shared
+** memory described in prshm.h. The intent is to provide a shared
+** memory that is accessable only by parent and child processes. ...
+** It's a security thing.
+** 
+** Depending on the underlying platform, the file-mapped shared memory
+** may be backed by a file. ... surprise! ... On some platforms, no
+** real file backs the shared memory. On platforms where the shared
+** memory is backed by a file, the file's name in the filesystem is
+** visible to other processes for only the duration of the creation of
+** the file, hopefully a very short time. This restricts processess
+** that do not inherit the shared memory from opening the file and
+** reading or writing its contents. Further, when all processes
+** using an anonymous shared memory terminate, the backing file is
+** deleted. ... If you are not paranoid, you're not paying attention.
+** 
+** The file-mapped shared memory requires a protocol for the parent
+** process and child process to share the memory. NSPR provides two
+** protocols. Use one or the other; don't mix and match.
+** 
+** In the first protocol, the job of passing the inheritable shared
+** memory is done via helper-functions with PR_CreateProcess(). In the
+** second protocol, the parent process is responsible for creating the
+** child process; the parent and child are mutually responsible for
+** passing a FileMap string. NSPR provides helper functions for
+** extracting data from the PRFileMap object. ... See the examples
+** below.
+** 
+** Both sides should adhere strictly to the protocol for proper
+** operation. The pseudo-code below shows the use of a file-mapped
+** shared memory by a parent and child processes. In the examples, the
+** server creates the file-mapped shared memory, the client attaches to
+** it.
+**
+** First protocol.
+** Server:
+**
+**   fm = PR_OpenAnonFileMap(dirName, size, FilemapProt); 
+**   addr = PR_MemMap(fm); 
+**   attr = PR_NewProcessAttr();
+**   PR_ProcessAttrSetInheritableFileMap( attr, fm, shmname );
+**   PR_CreateProcess(Client); 
+**   PR_DestroyProcessAttr(attr);
+**   ... yadda ...
+**   PR_MemUnmap( addr );
+**   PR_CloseFileMap(fm);
+**
+**
+** Client: 
+**   ... started by server via PR_CreateProcess()
+**   fm = PR_GetInheritedFileMap( shmname );
+**   addr = PR_MemMap(fm);
+**   ... yadda ...
+**   PR_MemUnmap(addr);
+**   PR_CloseFileMap(fm);
+**
+**
+** Second Protocol:
+** Server:
+**
+**   fm = PR_OpenAnonFileMap(dirName, size, FilemapProt); 
+**   fmstring = PR_ExportFileMapAsString( fm );
+**   addr = PR_MemMap(fm); 
+**    ... application specific technique to pass fmstring to child
+**    ... yadda ... Server uses his own magic to create child
+**   PR_MemUnmap( addr );
+**   PR_CloseFileMap(fm);
+**
+**
+** Client: 
+**   ... started by server via his own magic
+**   ... application specific technique to find fmstring from parent
+**   fm = PR_ImportFileMapFromString( fmstring )
+**   addr = PR_MemMap(fm);
+**   ... yadda ...
+**   PR_MemUnmap(addr);
+**   PR_CloseFileMap(fm);
+**
+**
+** lth. 2-Jul-1999.
+**
+** Note: The second protocol was requested by NelsonB (7/1999); this is
+** to accomodate servers which already create their own child processes
+** using platform native methods.
+** 
+*/
+
+#ifndef prshma_h___
+#define prshma_h___
+
+#include "prtypes.h"
+#include "prio.h"
+#include "prproces.h"
+
+PR_BEGIN_EXTERN_C
+
+/*
+** PR_OpenAnonFileMap() -- Creates an anonymous file-mapped shared memory
+**
+** Description:
+** PR_OpenAnonFileMap() creates an anonymous shared memory. If the
+** shared memory already exists, a handle is returned to that shared
+** memory object.
+**
+** On Unix platforms, PR_OpenAnonFileMap() uses 'dirName' as a
+** directory name, without the trailing '/', to contain the anonymous
+** file. A filename is generated for the name.
+**
+** On Windows platforms, dirName is ignored.
+**
+** Inputs:
+**   dirName -- A directory name to contain the anonymous file.
+**   size -- The size of the shared memory
+**   prot -- How the shared memory is mapped. See prio.h
+**   
+** Outputs:
+**   PRFileMap *
+**
+** Returns:
+**   Pointer to PRFileMap or NULL on error.
+**
+*/
+NSPR_API( PRFileMap *)
+PR_OpenAnonFileMap(
+    const char *dirName,
+    PRSize      size, 
+    PRFileMapProtect prot
+);  
+
+/*
+** PR_ProcessAttrSetInheritableFileMap() -- Prepare FileMap for export  
+**   to my children processes via PR_CreateProcess()
+**
+** Description:
+** PR_ProcessAttrSetInheritableFileMap() connects the PRFileMap to
+** PRProcessAttr with shmname. A subsequent call to PR_CreateProcess()
+** makes the PRFileMap importable by the child process.
+**
+** Inputs:
+**   attr -- PRProcessAttr, used to pass data to PR_CreateProcess()
+**   fm -- PRFileMap structure to be passed to the child process
+**   shmname -- The name for the PRFileMap; used by child.
+**
+** Outputs:
+**   PRFileMap *
+**
+** Returns:
+**   PRStatus
+**
+*/
+NSPR_API(PRStatus) 
+PR_ProcessAttrSetInheritableFileMap( 
+    PRProcessAttr   *attr,
+    PRFileMap       *fm, 
+    const char      *shmname
+);
+
+/*
+** PR_GetInheritedFileMap() -- Import a PRFileMap previously exported
+**   by my parent process via PR_CreateProcess()
+**
+** Description:
+** PR_GetInheritedFileMap() retrieves a PRFileMap object exported from
+** its parent process via PR_CreateProcess().
+**
+** Inputs:
+**    shmname -- The name provided to PR_ProcessAttrSetInheritableFileMap()
+** 
+** Outputs:
+**   PRFileMap *
+**
+** Returns:
+**   PRFileMap pointer or NULL.
+**
+*/
+NSPR_API( PRFileMap *)
+PR_GetInheritedFileMap( 
+    const char *shmname 
+);
+
+/*
+** PR_ExportFileMapAsString() -- Creates a string identifying a PRFileMap
+**
+** Description:
+** Creates an identifier, as a string, from a PRFileMap object
+** previously created with PR_OpenAnonFileMap().
+**
+** Inputs:
+**   fm -- PRFileMap pointer to be represented as a string.
+**   bufsize -- sizeof(buf)
+**   buf -- a buffer of length PR_FILEMAP_STRING_BUFSIZE
+**
+** Outputs:
+**   buf contains the stringized PRFileMap identifier
+**
+** Returns:
+**   PRStatus
+**
+*/
+NSPR_API( PRStatus )
+PR_ExportFileMapAsString( 
+    PRFileMap *fm,
+    PRSize    bufsize,
+    char      *buf
+);
+#define PR_FILEMAP_STRING_BUFSIZE 128
+
+/*
+** PR_ImportFileMapFromString() -- Creates a PRFileMap from the identifying string
+**
+** Description:
+** PR_ImportFileMapFromString() creates a PRFileMap object from a
+** string previously created by PR_ExportFileMapAsString().
+**
+** Inputs:
+**   fmstring -- string created by PR_ExportFileMapAsString()
+**
+** Returns:
+**   PRFileMap pointer or NULL.
+**
+*/
+NSPR_API( PRFileMap * )
+PR_ImportFileMapFromString( 
+    const char *fmstring
+);
+
+PR_END_EXTERN_C
+#endif /* prshma_h___ */
diff --git a/pr/include/prsystem.h b/pr/include/prsystem.h
new file mode 100644
index 0000000..b3e14e7
--- /dev/null
+++ b/pr/include/prsystem.h
@@ -0,0 +1,108 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef prsystem_h___
+#define prsystem_h___
+
+/*
+** API to NSPR functions returning system info.
+*/
+#include "prtypes.h"
+
+PR_BEGIN_EXTERN_C
+
+/*
+** Get the host' directory separator.
+**  Pathnames are then assumed to be of the form:
+**      [<sep><root_component><sep>]*(<component><sep>)<leaf_name>
+*/
+
+NSPR_API(char) PR_GetDirectorySeparator(void);
+
+/*
+** OBSOLETE -- the function name is misspelled.
+** Use PR_GetDirectorySeparator instead.
+*/
+
+NSPR_API(char) PR_GetDirectorySepartor(void);
+
+/*
+** Get the host' path separator.
+**  Paths are assumed to be of the form:
+**      <directory>[<sep><directory>]*
+*/
+
+NSPR_API(char) PR_GetPathSeparator(void);
+
+/* Types of information available via PR_GetSystemInfo(...) */
+typedef enum {
+    PR_SI_HOSTNAME,  /* the hostname with the domain name (if any)
+                      * removed */
+    PR_SI_SYSNAME,
+    PR_SI_RELEASE,
+    PR_SI_ARCHITECTURE,
+    PR_SI_HOSTNAME_UNTRUNCATED  /* the hostname exactly as configured
+                                 * on the system */
+} PRSysInfo;
+
+
+/*
+** If successful returns a null termintated string in 'buf' for
+** the information indicated in 'cmd'. If unseccussful the reason for
+** the failure can be retrieved from PR_GetError().
+**
+** The buffer is allocated by the caller and should be at least
+** SYS_INFO_BUFFER_LENGTH bytes in length.
+*/
+
+#define SYS_INFO_BUFFER_LENGTH 256
+
+NSPR_API(PRStatus) PR_GetSystemInfo(PRSysInfo cmd, char *buf, PRUint32 buflen);
+
+/*
+** Return the number of bytes in a page
+*/
+NSPR_API(PRInt32) PR_GetPageSize(void);
+
+/*
+** Return log2 of the size of a page
+*/
+NSPR_API(PRInt32) PR_GetPageShift(void);
+
+/*
+** PR_GetNumberOfProcessors() -- returns the number of CPUs
+**
+** Description:
+** PR_GetNumberOfProcessors() extracts the number of processors
+** (CPUs available in an SMP system) and returns the number.
+** 
+** Parameters:
+**   none
+**
+** Returns:
+**   The number of available processors or -1 on error
+** 
+*/
+NSPR_API(PRInt32) PR_GetNumberOfProcessors( void );
+
+/*
+** PR_GetPhysicalMemorySize() -- returns the amount of system RAM
+**
+** Description:
+** PR_GetPhysicalMemorySize() determines the amount of physical RAM
+** in the system and returns the size in bytes.
+**
+** Parameters:
+**   none
+**
+** Returns:
+**   The amount of system RAM, or 0 on failure.
+**
+*/
+NSPR_API(PRUint64) PR_GetPhysicalMemorySize(void);
+
+PR_END_EXTERN_C
+
+#endif /* prsystem_h___ */
diff --git a/pr/include/prthread.h b/pr/include/prthread.h
new file mode 100644
index 0000000..f8b28a6
--- /dev/null
+++ b/pr/include/prthread.h
@@ -0,0 +1,272 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef prthread_h___
+#define prthread_h___
+
+/*
+** API for NSPR threads. On some architectures (Mac OS Classic
+** notably) pre-emptibility is not guaranteed. Hard priority scheduling
+** is not guaranteed, so programming using priority based synchronization
+** is a no-no.
+**
+** NSPR threads are scheduled based loosely on their client set priority.
+** In general, a thread of a higher priority has a statistically better
+** chance of running relative to threads of lower priority. However,
+** NSPR uses multiple strategies to provide execution vehicles for thread
+** abstraction of various host platforms. As it turns out, there is little
+** NSPR can do to affect the scheduling attributes of "GLOBAL" threads.
+** However, a semblance of GLOBAL threads is used to implement "LOCAL"
+** threads. An arbitrary number of such LOCAL threads can be assigned to
+** a single GLOBAL thread.
+**
+** For scheduling, NSPR will attempt to run the highest priority LOCAL
+** thread associated with a given GLOBAL thread. It is further assumed
+** that the host OS will apply some form of "fair" scheduling on the
+** GLOBAL threads.
+**
+** Threads have a "system flag" which when set indicates the thread
+** doesn't count for determining when the process should exit (the
+** process exits when the last user thread exits).
+**
+** Threads also have a "scope flag" which controls whether the threads
+** are scheduled in the local scope or scheduled by the OS globally. This 
+** indicates whether a thread is permanently bound to a native OS thread. 
+** An unbound thread competes for scheduling resources in the same process.
+**
+** Another flag is "state flag" which control whether the thread is joinable.
+** It allows other threads to wait for the created thread to reach completion.
+**
+** Threads can have "per-thread-data" attached to them. Each thread has a
+** per-thread error number and error string which are updated when NSPR
+** operations fail.
+*/
+#include "prtypes.h"
+#include "prinrval.h"
+
+PR_BEGIN_EXTERN_C
+
+typedef struct PRThread PRThread;
+typedef struct PRThreadStack PRThreadStack;
+
+typedef enum PRThreadType {
+    PR_USER_THREAD,
+    PR_SYSTEM_THREAD
+} PRThreadType;
+
+typedef enum PRThreadScope {
+    PR_LOCAL_THREAD,
+    PR_GLOBAL_THREAD,
+    PR_GLOBAL_BOUND_THREAD
+} PRThreadScope;
+
+typedef enum PRThreadState {
+    PR_JOINABLE_THREAD,
+    PR_UNJOINABLE_THREAD
+} PRThreadState;
+
+typedef enum PRThreadPriority
+{
+    PR_PRIORITY_FIRST = 0,      /* just a placeholder */
+    PR_PRIORITY_LOW = 0,        /* the lowest possible priority */
+    PR_PRIORITY_NORMAL = 1,     /* most common expected priority */
+    PR_PRIORITY_HIGH = 2,       /* slightly more aggressive scheduling */
+    PR_PRIORITY_URGENT = 3,     /* it does little good to have more than one */
+    PR_PRIORITY_LAST = 3        /* this is just a placeholder */
+} PRThreadPriority;
+
+/*
+** Create a new thread:
+**     "type" is the type of thread to create
+**     "start(arg)" will be invoked as the threads "main"
+**     "priority" will be created thread's priority
+**     "scope" will specify whether the thread is local or global
+**     "state" will specify whether the thread is joinable or not
+**     "stackSize" the size of the stack, in bytes. The value can be zero
+**        and then a machine specific stack size will be chosen.
+**
+** This can return NULL if some kind of error occurs, such as if memory is
+** tight.
+**
+** If you want the thread to start up waiting for the creator to do
+** something, enter a lock before creating the thread and then have the
+** threads start routine enter and exit the same lock. When you are ready
+** for the thread to run, exit the lock.
+**
+** If you want to detect the completion of the created thread, the thread
+** should be created joinable.  Then, use PR_JoinThread to synchrnoize the
+** termination of another thread.
+**
+** When the start function returns the thread exits. If it is the last
+** PR_USER_THREAD to exit then the process exits.
+*/
+NSPR_API(PRThread*) PR_CreateThread(PRThreadType type,
+                     void (PR_CALLBACK *start)(void *arg),
+                     void *arg,
+                     PRThreadPriority priority,
+                     PRThreadScope scope,
+                     PRThreadState state,
+                     PRUint32 stackSize);
+
+/*
+** Wait for thread termination:
+**     "thread" is the target thread 
+**
+** This can return PR_FAILURE if no joinable thread could be found 
+** corresponding to the specified target thread.
+**
+** The calling thread is blocked until the target thread completes.
+** Several threads cannot wait for the same thread to complete; one thread
+** will operate successfully and others will terminate with an error PR_FAILURE.
+** The calling thread will not be blocked if the target thread has already
+** terminated.
+*/
+NSPR_API(PRStatus) PR_JoinThread(PRThread *thread);
+
+/*
+** Return the current thread object for the currently running code.
+** Never returns NULL.
+*/
+NSPR_API(PRThread*) PR_GetCurrentThread(void);
+#ifndef NO_NSPR_10_SUPPORT
+#define PR_CurrentThread() PR_GetCurrentThread() /* for nspr1.0 compat. */
+#endif /* NO_NSPR_10_SUPPORT */
+
+/*
+** Get the priority of "thread".
+*/
+NSPR_API(PRThreadPriority) PR_GetThreadPriority(const PRThread *thread);
+
+/*
+** Change the priority of the "thread" to "priority".
+**
+** PR_SetThreadPriority works in a best-effort manner. On some platforms a
+** special privilege, such as root access, is required to change thread
+** priorities, especially to raise thread priorities. If the caller doesn't
+** have enough privileges to change thread priorites, the function has no
+** effect except causing a future PR_GetThreadPriority call to return
+** |priority|.
+*/
+NSPR_API(void) PR_SetThreadPriority(PRThread *thread, PRThreadPriority priority);
+
+/*
+** Set the name of the current thread, which will be visible in a debugger
+** and accessible via a call to PR_GetThreadName().
+*/
+NSPR_API(PRStatus) PR_SetCurrentThreadName(const char *name);
+
+/*
+** Return the name of "thread", if set.  Otherwise return NULL.
+*/
+NSPR_API(const char *) PR_GetThreadName(const PRThread *thread);
+
+/*
+** This routine returns a new index for per-thread-private data table. 
+** The index is visible to all threads within a process. This index can 
+** be used with the PR_SetThreadPrivate() and PR_GetThreadPrivate() routines 
+** to save and retrieve data associated with the index for a thread.
+**
+** Each index is associationed with a destructor function ('dtor'). The function
+** may be specified as NULL when the index is created. If it is not NULL, the
+** function will be called when:
+**      - the thread exits and the private data for the associated index
+**        is not NULL,
+**      - new thread private data is set and the current private data is
+**        not NULL.
+**
+** The index independently maintains specific values for each binding thread. 
+** A thread can only get access to its own thread-specific-data.
+**
+** Upon a new index return the value associated with the index for all threads
+** is NULL, and upon thread creation the value associated with all indices for 
+** that thread is NULL. 
+**
+** Returns PR_FAILURE if the total number of indices will exceed the maximun 
+** allowed.
+*/
+typedef void (PR_CALLBACK *PRThreadPrivateDTOR)(void *priv);
+
+NSPR_API(PRStatus) PR_NewThreadPrivateIndex(
+    PRUintn *newIndex, PRThreadPrivateDTOR destructor);
+
+/*
+** Define some per-thread-private data.
+**     "tpdIndex" is an index into the per-thread private data table
+**     "priv" is the per-thread-private data 
+**
+** If the per-thread private data table has a previously registered
+** destructor function and a non-NULL per-thread-private data value,
+** the destructor function is invoked.
+**
+** This can return PR_FAILURE if the index is invalid.
+*/
+NSPR_API(PRStatus) PR_SetThreadPrivate(PRUintn tpdIndex, void *priv);
+
+/*
+** Recover the per-thread-private data for the current thread. "tpdIndex" is
+** the index into the per-thread private data table. 
+**
+** The returned value may be NULL which is indistinguishable from an error 
+** condition.
+**
+** A thread can only get access to its own thread-specific-data.
+*/
+NSPR_API(void*) PR_GetThreadPrivate(PRUintn tpdIndex);
+
+/*
+** This routine sets the interrupt request for a target thread. The interrupt
+** request remains in the thread's state until it is delivered exactly once
+** or explicitly canceled.
+**
+** A thread that has been interrupted will fail all NSPR blocking operations
+** that return a PRStatus (I/O, waiting on a condition, etc).
+**
+** PR_Interrupt may itself fail if the target thread is invalid.
+*/
+NSPR_API(PRStatus) PR_Interrupt(PRThread *thread);
+
+/*
+** Clear the interrupt request for the calling thread. If no such request
+** is pending, this operation is a noop.
+*/
+NSPR_API(void) PR_ClearInterrupt(void);
+
+/*
+** Block the interrupt for the calling thread.
+*/
+NSPR_API(void) PR_BlockInterrupt(void);
+
+/*
+** Unblock the interrupt for the calling thread.
+*/
+NSPR_API(void) PR_UnblockInterrupt(void);
+
+/*
+** Make the current thread sleep until "ticks" time amount of time
+** has expired. If "ticks" is PR_INTERVAL_NO_WAIT then the call is
+** equivalent to calling PR_Yield. Calling PR_Sleep with an argument
+** equivalent to PR_INTERVAL_NO_TIMEOUT is an error and will result
+** in a PR_FAILURE error return.
+*/
+NSPR_API(PRStatus) PR_Sleep(PRIntervalTime ticks);
+
+/*
+** Get the scoping of this thread.
+*/
+NSPR_API(PRThreadScope) PR_GetThreadScope(const PRThread *thread);
+
+/*
+** Get the type of this thread.
+*/
+NSPR_API(PRThreadType) PR_GetThreadType(const PRThread *thread);
+
+/*
+** Get the join state of this thread.
+*/
+NSPR_API(PRThreadState) PR_GetThreadState(const PRThread *thread);
+
+PR_END_EXTERN_C
+
+#endif /* prthread_h___ */
diff --git a/pr/include/prtime.h b/pr/include/prtime.h
new file mode 100644
index 0000000..caaee14
--- /dev/null
+++ b/pr/include/prtime.h
@@ -0,0 +1,262 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * prtime.h --
+ *
+ *     NSPR date and time functions
+ *
+ *-----------------------------------------------------------------------
+ */
+
+#ifndef prtime_h___
+#define prtime_h___
+
+#include "prlong.h"
+
+PR_BEGIN_EXTERN_C
+
+/**********************************************************************/
+/************************* TYPES AND CONSTANTS ************************/
+/**********************************************************************/
+
+#define PR_MSEC_PER_SEC		1000L
+#define PR_USEC_PER_SEC		1000000L
+#define PR_NSEC_PER_SEC		1000000000L
+#define PR_USEC_PER_MSEC	1000L
+#define PR_NSEC_PER_MSEC	1000000L
+
+/*
+ * PRTime --
+ *
+ *     NSPR represents basic time as 64-bit signed integers relative
+ *     to midnight (00:00:00), January 1, 1970 Greenwich Mean Time (GMT).
+ *     (GMT is also known as Coordinated Universal Time, UTC.)
+ *     The units of time are in microseconds. Negative times are allowed
+ *     to represent times prior to the January 1970 epoch. Such values are
+ *     intended to be exported to other systems or converted to human
+ *     readable form.
+ *
+ *     Notes on porting: PRTime corresponds to time_t in ANSI C.  NSPR 1.0
+ *     simply uses PRInt64.
+ */
+
+typedef PRInt64 PRTime;
+
+/*
+ * Time zone and daylight saving time corrections applied to GMT to
+ * obtain the local time of some geographic location
+ */
+
+typedef struct PRTimeParameters {
+    PRInt32 tp_gmt_offset;     /* the offset from GMT in seconds */
+    PRInt32 tp_dst_offset;     /* contribution of DST in seconds */
+} PRTimeParameters;
+
+/*
+ * PRExplodedTime --
+ *
+ *     Time broken down into human-readable components such as year, month,
+ *     day, hour, minute, second, and microsecond.  Time zone and daylight
+ *     saving time corrections may be applied.  If they are applied, the
+ *     offsets from the GMT must be saved in the 'tm_params' field so that
+ *     all the information is available to reconstruct GMT.
+ *
+ *     Notes on porting: PRExplodedTime corrresponds to struct tm in
+ *     ANSI C, with the following differences:
+ *       - an additional field tm_usec;
+ *       - replacing tm_isdst by tm_params;
+ *       - the month field is spelled tm_month, not tm_mon;
+ *       - we use absolute year, AD, not the year since 1900.
+ *     The corresponding type in NSPR 1.0 is called PRTime.  Below is
+ *     a table of date/time type correspondence in the three APIs:
+ *         API          time since epoch          time in components
+ *       ANSI C             time_t                  struct tm
+ *       NSPR 1.0           PRInt64                   PRTime
+ *       NSPR 2.0           PRTime                  PRExplodedTime
+ */
+
+typedef struct PRExplodedTime {
+    PRInt32 tm_usec;		    /* microseconds past tm_sec (0-99999)  */
+    PRInt32 tm_sec;             /* seconds past tm_min (0-61, accomodating
+                                   up to two leap seconds) */
+    PRInt32 tm_min;             /* minutes past tm_hour (0-59) */
+    PRInt32 tm_hour;            /* hours past tm_day (0-23) */
+    PRInt32 tm_mday;            /* days past tm_mon (1-31, note that it
+				                starts from 1) */
+    PRInt32 tm_month;           /* months past tm_year (0-11, Jan = 0) */
+    PRInt16 tm_year;            /* absolute year, AD (note that we do not
+				                count from 1900) */
+
+    PRInt8 tm_wday;		        /* calculated day of the week
+				                (0-6, Sun = 0) */
+    PRInt16 tm_yday;            /* calculated day of the year
+				                (0-365, Jan 1 = 0) */
+
+    PRTimeParameters tm_params;  /* time parameters used by conversion */
+} PRExplodedTime;
+
+/*
+ * PRTimeParamFn --
+ *
+ *     A function of PRTimeParamFn type returns the time zone and
+ *     daylight saving time corrections for some geographic location,
+ *     given the current time in GMT.  The input argument gmt should
+ *     point to a PRExplodedTime that is in GMT, i.e., whose
+ *     tm_params contains all 0's.
+ *
+ *     For any time zone other than GMT, the computation is intended to
+ *     consist of two steps:
+ *       - Figure out the time zone correction, tp_gmt_offset.  This number
+ *         usually depends on the geographic location only.  But it may
+ *         also depend on the current time.  For example, all of China
+ *         is one time zone right now.  But this situation may change
+ *         in the future.
+ *       - Figure out the daylight saving time correction, tp_dst_offset.
+ *         This number depends on both the geographic location and the
+ *         current time.  Most of the DST rules are expressed in local
+ *         current time.  If so, one should apply the time zone correction
+ *         to GMT before applying the DST rules.
+ */
+
+typedef PRTimeParameters (PR_CALLBACK *PRTimeParamFn)(const PRExplodedTime *gmt);
+
+/**********************************************************************/
+/****************************** FUNCTIONS *****************************/
+/**********************************************************************/
+
+/*
+ * The PR_Now routine returns the current time relative to the
+ * epoch, midnight, January 1, 1970 UTC. The units of the returned
+ * value are microseconds since the epoch.
+ *
+ * The values returned are not guaranteed to advance in a linear fashion
+ * due to the application of time correction protocols which synchronize
+ * computer clocks to some external time source. Consequently it should
+ * not be depended on for interval timing.
+ *
+ * The implementation is machine dependent.
+ * Cf. time_t time(time_t *tp) in ANSI C.
+ */
+NSPR_API(PRTime)
+PR_Now(void);
+
+/*
+ * Expand time binding it to time parameters provided by PRTimeParamFn.
+ * The calculation is envisoned to proceed in the following steps:
+ *   - From given PRTime, calculate PRExplodedTime in GMT
+ *   - Apply the given PRTimeParamFn to the GMT that we just calculated
+ *     to obtain PRTimeParameters.
+ *   - Add the PRTimeParameters offsets to GMT to get the local time
+ *     as PRExplodedTime.
+ */
+
+NSPR_API(void) PR_ExplodeTime(
+    PRTime usecs, PRTimeParamFn params, PRExplodedTime *exploded);
+
+/* Reverse operation of PR_ExplodeTime */
+NSPR_API(PRTime)
+PR_ImplodeTime(const PRExplodedTime *exploded);
+
+/*
+ * Adjust exploded time to normalize field overflows after manipulation.
+ * Note that the following fields of PRExplodedTime should not be
+ * manipulated:
+ *   - tm_month and tm_year: because the number of days in a month and
+ *     number of days in a year are not constant, it is ambiguous to
+ *     manipulate the month and year fields, although one may be tempted
+ *     to.  For example, what does "a month from January 31st" mean?
+ *   - tm_wday and tm_yday: these fields are calculated by NSPR.  Users
+ *     should treat them as "read-only".
+ */
+
+NSPR_API(void) PR_NormalizeTime(
+    PRExplodedTime *exploded, PRTimeParamFn params);
+
+/**********************************************************************/
+/*********************** TIME PARAMETER FUNCTIONS *********************/
+/**********************************************************************/
+
+/* Time parameters that suit current host machine */
+NSPR_API(PRTimeParameters) PR_LocalTimeParameters(const PRExplodedTime *gmt);
+
+/* Time parameters that represent Greenwich Mean Time */
+NSPR_API(PRTimeParameters) PR_GMTParameters(const PRExplodedTime *gmt);
+
+/*
+ * Time parameters that represent the US Pacific Time Zone, with the
+ * current daylight saving time rules (for testing only)
+ */
+NSPR_API(PRTimeParameters) PR_USPacificTimeParameters(const PRExplodedTime *gmt);
+
+/*
+ * This parses a time/date string into a PRExplodedTime
+ * struct. It populates all fields but it can't split
+ * the offset from UTC into tp_gmt_offset and tp_dst_offset in
+ * most cases (exceptions: PST/PDT, MST/MDT, CST/CDT, EST/EDT, GMT/BST).
+ * In those cases tp_gmt_offset will be the sum of these two and
+ * tp_dst_offset will be 0.
+ * It returns PR_SUCCESS on success, and PR_FAILURE
+ * if the time/date string can't be parsed.
+ *
+ * Many formats are handled, including:
+ *
+ *   14 Apr 89 03:20:12
+ *   14 Apr 89 03:20 GMT
+ *   Fri, 17 Mar 89 4:01:33
+ *   Fri, 17 Mar 89 4:01 GMT
+ *   Mon Jan 16 16:12 PDT 1989
+ *   Mon Jan 16 16:12 +0130 1989
+ *   6 May 1992 16:41-JST (Wednesday)
+ *   22-AUG-1993 10:59:12.82
+ *   22-AUG-1993 10:59pm
+ *   22-AUG-1993 12:59am
+ *   22-AUG-1993 12:59 PM
+ *   Friday, August 04, 1995 3:54 PM
+ *   06/21/95 04:24:34 PM
+ *   20/06/95 21:07
+ *   95-06-08 19:32:48 EDT
+ *
+ * If the input string doesn't contain a description of the timezone,
+ * we consult the `default_to_gmt' to decide whether the string should
+ * be interpreted relative to the local time zone (PR_FALSE) or GMT (PR_TRUE).
+ * The correct value for this argument depends on what standard specified
+ * the time string which you are parsing.
+ */
+
+NSPR_API(PRStatus) PR_ParseTimeStringToExplodedTime (
+        const char *string,
+        PRBool default_to_gmt,
+        PRExplodedTime *result);
+
+/*
+ * This uses PR_ParseTimeStringToExplodedTime to parse
+ * a time/date string and PR_ImplodeTime to transform it into
+ * a PRTime (microseconds after "1-Jan-1970 00:00:00 GMT").
+ * It returns PR_SUCCESS on success, and PR_FAILURE
+ * if the time/date string can't be parsed.
+ */
+
+NSPR_API(PRStatus) PR_ParseTimeString (
+	const char *string,
+	PRBool default_to_gmt,
+	PRTime *result);
+
+/* Format a time value into a buffer. Same semantics as strftime() */
+NSPR_API(PRUint32) PR_FormatTime(char *buf, int buflen, const char *fmt,
+                                 const PRExplodedTime *time);
+
+/* Format a time value into a buffer. Time is always in US English format,
+ * regardless of locale setting.
+ */
+NSPR_API(PRUint32)
+PR_FormatTimeUSEnglish(char *buf, PRUint32 bufSize,
+                       const char *format, const PRExplodedTime *time);
+
+PR_END_EXTERN_C
+
+#endif /* prtime_h___ */
diff --git a/pr/include/prtpool.h b/pr/include/prtpool.h
new file mode 100644
index 0000000..6a434dd
--- /dev/null
+++ b/pr/include/prtpool.h
@@ -0,0 +1,83 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef prtpool_h___
+#define prtpool_h___
+
+#include "prtypes.h"
+#include "prthread.h"
+#include "prio.h"
+#include "prerror.h"
+
+/*
+ * NOTE:
+ *		THIS API IS A PRELIMINARY VERSION IN NSPR 4.0 AND IS SUBJECT TO
+ *		CHANGE
+ */
+
+PR_BEGIN_EXTERN_C
+
+typedef struct PRJobIoDesc {
+    PRFileDesc *socket;
+    PRErrorCode error;
+    PRIntervalTime timeout;
+} PRJobIoDesc;
+
+typedef struct PRThreadPool PRThreadPool;
+typedef struct PRJob PRJob;
+typedef void (PR_CALLBACK *PRJobFn) (void *arg);
+
+/* Create thread pool */
+NSPR_API(PRThreadPool *)
+PR_CreateThreadPool(PRInt32 initial_threads, PRInt32 max_threads,
+                          PRUint32 stacksize);
+
+/* queue a job */
+NSPR_API(PRJob *)
+PR_QueueJob(PRThreadPool *tpool, PRJobFn fn, void *arg, PRBool joinable);
+
+/* queue a job, when a socket is readable */
+NSPR_API(PRJob *)
+PR_QueueJob_Read(PRThreadPool *tpool, PRJobIoDesc *iod,
+							PRJobFn fn, void * arg, PRBool joinable);
+
+/* queue a job, when a socket is writeable */
+NSPR_API(PRJob *)
+PR_QueueJob_Write(PRThreadPool *tpool, PRJobIoDesc *iod,
+								PRJobFn fn, void * arg, PRBool joinable);
+
+/* queue a job, when a socket has a pending connection */
+NSPR_API(PRJob *)
+PR_QueueJob_Accept(PRThreadPool *tpool, PRJobIoDesc *iod,
+									PRJobFn fn, void * arg, PRBool joinable);
+
+/* queue a job, when the socket connection to addr succeeds or fails */
+NSPR_API(PRJob *)
+PR_QueueJob_Connect(PRThreadPool *tpool, PRJobIoDesc *iod,
+			const PRNetAddr *addr, PRJobFn fn, void * arg, PRBool joinable);
+
+/* queue a job, when a timer exipres */
+NSPR_API(PRJob *)
+PR_QueueJob_Timer(PRThreadPool *tpool, PRIntervalTime timeout,
+								PRJobFn fn, void * arg, PRBool joinable);
+/* cancel a job */
+NSPR_API(PRStatus)
+PR_CancelJob(PRJob *job);
+
+/* join a job */
+NSPR_API(PRStatus)
+PR_JoinJob(PRJob *job);
+
+/* shutdown pool */
+NSPR_API(PRStatus)
+PR_ShutdownThreadPool(PRThreadPool *tpool);
+
+/* join pool, wait for exit of all threads */
+NSPR_API(PRStatus)
+PR_JoinThreadPool(PRThreadPool *tpool);
+
+PR_END_EXTERN_C
+
+#endif /* prtpool_h___ */
diff --git a/pr/include/prtrace.h b/pr/include/prtrace.h
new file mode 100644
index 0000000..12a5fbf
--- /dev/null
+++ b/pr/include/prtrace.h
@@ -0,0 +1,646 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef prtrace_h___
+#define prtrace_h___
+/*
+** prtrace.h -- NSPR's Trace Facility.  		           
+**                                                               		           
+** The Trace Facility provides a means to trace application				           
+** program events within a process. When implementing an         		           
+** application program an engineer may insert a "Trace" function 		           
+** call, passing arguments to be traced. The "Trace" function     		           
+** combines the user trace data with identifying data and        		           
+** writes this data in time ordered sequence into a circular     		           
+** in-memory buffer; when the buffer fills, it wraps.
+**                                                               		           
+** Functions are provided to set and/or re-configure the size of		           
+** the trace buffer, control what events are recorded in the			           
+** buffer, enable and disable tracing based on specific user			           
+** supplied data and other control functions. Methods are provided		           
+** to record the trace entries in the in-memory trace buffer to
+** a file.
+**                                                               		           
+** Tracing may cause a performance degredation to the application		           
+** depending on the number and placement of calls to the tracing		           
+** facility. When tracing is compiled in and all tracing is				           
+** disabled via the runtime controls, the overhead should be			           
+** minimal. ... Famous last words, eh?									           
+** 																                   
+** When DEBUG is defined at compile time, the Trace Facility is                    
+** compiled as part of NSPR and any application using NSPR's                       
+** header files will have tracing compiled in. When DEBUG is not                   
+** defined, the Trace Facility is not compiled into NSPR nor                       
+** exported in its header files.  If the Trace Facility is                         
+** desired in a non-debug build, then FORCE_NSPR_TRACE may be                      
+** defined at compile time for both the optimized build of NSPR                    
+** and the application. NSPR and any application using  NSPR's                     
+** Trace Facility must be compiled with the same level of trace                    
+** conditioning or unresolved references may be realized at link                   
+** time.                                                                           
+**                                                                                 
+** For any of the Trace Facility methods that requires a trace                     
+** handle as an input argument, the caller must ensure that the                    
+** trace handle argument is valid. An invalid trace handle                         
+** argument may cause unpredictable results.                                       
+**                                                                                 
+** Trace Facility methods are thread-safe and SMP safe.                            
+**                                                                                 
+** Users of the Trace Facility should use the defined macros to                     
+** invoke trace methods, not the function calls directly. e.g.                      
+** PR_TRACE( h1,0,1,2, ...); not PR_Trace(h1,0,1,2, ...);
+**                                                                                  
+** Application designers should be aware of the effects of
+** debug and optimized build differences when using result of the
+** Trace Facility macros in expressions.
+** 
+** See Also: prcountr.h                                                                                 
+**                                                                                  
+** /lth. 08-Jun-1998.                                                                                  
+*/
+
+#include "prtypes.h"
+#include "prthread.h"
+#include "prtime.h"
+
+PR_BEGIN_EXTERN_C
+
+/*
+** Opaque type for the trace handle 
+** ... Don't even think about looking in here.
+**
+*/
+typedef void *  PRTraceHandle;
+
+/*
+** PRTraceEntry -- A trace entry in the in-memory trace buffer
+** looks like this.
+**
+*/
+typedef struct PRTraceEntry
+{
+    PRThread        *thread;        /* The thread creating the trace entry */
+    PRTraceHandle   handle;         /* PRTraceHandle creating the trace entry */
+    PRTime          time;           /* Value of PR_Now() at time of trace entry */
+    PRUint32        userData[8];    /* user supplied trace data */
+} PRTraceEntry;
+
+/*
+** PRTraceOption -- command operands to
+** PR_[Set|Get]TraceOption(). See descriptive meanings there.
+**
+*/
+typedef enum PRTraceOption
+{
+    PRTraceBufSize,
+    PRTraceEnable,              
+    PRTraceDisable,
+    PRTraceSuspend,
+    PRTraceResume,
+    PRTraceSuspendRecording,
+    PRTraceResumeRecording,
+    PRTraceLockHandles,
+    PRTraceUnLockHandles,
+    PRTraceStopRecording
+} PRTraceOption;
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_DEFINE_TRACE() -- Define a PRTraceHandle
+** 
+** DESCRIPTION: PR_DEFINE_TRACE() is used to define a trace
+** handle.
+** 
+*/
+#define PR_DEFINE_TRACE(name) PRTraceHandle name
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_INIT_TRACE_HANDLE() -- Set the value of a PRTraceHandle
+** 
+** DESCRIPTION: 
+** PR_INIT_TRACE_HANDLE() sets the value of a PRTraceHandle
+** to value. e.g. PR_INIT_TRACE_HANDLE( myHandle, NULL );
+** 
+*/
+#if defined (DEBUG) || defined (FORCE_NSPR_TRACE)
+#define PR_INIT_TRACE_HANDLE(handle,value)\
+    (handle) = (PRCounterHandle)(value)
+#else
+#define PR_INIT_TRACE_HANDLE(handle,value)
+#endif
+
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_CreateTrace() -- Create a trace handle
+** 
+** DESCRIPTION:
+**  PR_CreateTrace() creates a new trace handle. Tracing is
+**  enabled for this handle when it is created. The trace handle
+**  is intended for use in other Trace Facility calls.
+**  
+**  PR_CreateTrace() registers the QName, RName and description
+**  data so that this data can be retrieved later.
+** 
+** INPUTS: 
+**  qName: pointer to string. QName for this trace handle. 
+** 
+**  rName: pointer to string. RName for this trace handle. 
+** 
+**  description: pointer to string. Descriptive data about this
+**  trace handle.
+**
+** OUTPUTS:
+**  Creates the trace handle. 
+**  Registers the QName and RName with the trace facility.
+** 
+** RETURNS: 
+**  PRTraceHandle
+** 
+** RESTRICTIONS:
+**  qName is limited to 31 characters.
+**  rName is limited to 31 characters.
+**  description is limited to 255 characters.
+** 
+*/
+#define PRTRACE_NAME_MAX 31
+#define PRTRACE_DESC_MAX 255
+
+#if defined (DEBUG) || defined (FORCE_NSPR_TRACE)
+#define PR_CREATE_TRACE(handle,qName,rName,description)\
+    (handle) = PR_CreateTrace((qName),(rName),(description))
+#else
+#define PR_CREATE_TRACE(handle,qName,rName,description)
+#endif
+
+NSPR_API(PRTraceHandle)
+	PR_CreateTrace( 
+    	const char *qName,          /* QName for this trace handle */
+	    const char *rName,          /* RName for this trace handle */
+	    const char *description     /* description for this trace handle */
+);
+
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_DestroyTrace() -- Destroy a trace handle
+** 
+** DESCRIPTION: 
+**  PR_DestroyTrace() removes the referenced trace handle and
+** associated QName, RName and description data from the Trace
+** Facility.
+** 
+** INPUTS: handle. A PRTraceHandle
+** 
+** OUTPUTS: 
+**  The trace handle is unregistered.
+**  The QName, RName and description are removed.
+** 
+** RETURNS: void
+** 
+** RESTRICTIONS:
+** 
+*/
+#if defined (DEBUG) || defined (FORCE_NSPR_TRACE)
+#define PR_DESTROY_TRACE(handle)\
+    PR_DestroyTrace((handle))
+#else
+#define PR_DESTROY_TRACE(handle)
+#endif
+
+NSPR_API(void) 
+	PR_DestroyTrace( 
+		PRTraceHandle handle    /* Handle to be destroyed */
+);
+
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_Trace() -- Make a trace entry in the in-memory trace
+** 
+** DESCRIPTION:
+** PR_Trace() makes an entry in the in-memory trace buffer for
+** the referenced trace handle. The next logically available
+** PRTraceEntry is used; when the next trace entry would overflow
+** the trace table, the table wraps.
+**
+** PR_Trace() for a specific trace handle may be disabled by
+** calling PR_SetTraceOption() specifying PRTraceDisable for the
+** trace handle to be disabled.
+** 
+** INPUTS:
+** handle: PRTraceHandle. The trace handle for this trace.
+** 
+** userData[0..7]: unsigned 32bit integers. user supplied data
+** that is copied into the PRTraceEntry
+** 
+** OUTPUTS:
+**  A PRTraceEntry is (conditionally) formatted in the in-memory
+** trace buffer.
+** 
+** RETURNS: void.
+** 
+** RESTRICTIONS:
+** 
+*/
+#if defined (DEBUG) || defined (FORCE_NSPR_TRACE)
+#define PR_TRACE(handle,ud0,ud1,ud2,ud3,ud4,ud5,ud6,ud7)\
+    PR_Trace((handle),(ud0),(ud1),(ud2),(ud3),(ud4),(ud5),(ud6),(ud7))
+#else
+#define PR_TRACE(handle,ud0,ud1,ud2,ud3,ud4,ud5,ud6,ud7)
+#endif
+
+NSPR_API(void) 
+	PR_Trace( 
+    	PRTraceHandle handle,       /* use this trace handle */
+	    PRUint32    userData0,      /* User supplied data word 0 */
+	    PRUint32    userData1,      /* User supplied data word 1 */
+	    PRUint32    userData2,      /* User supplied data word 2 */
+	    PRUint32    userData3,      /* User supplied data word 3 */
+	    PRUint32    userData4,      /* User supplied data word 4 */
+	    PRUint32    userData5,      /* User supplied data word 5 */
+	    PRUint32    userData6,      /* User supplied data word 6 */
+	    PRUint32    userData7       /* User supplied data word 7 */
+);
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_SetTraceOption() -- Control the Trace Facility
+** 
+** DESCRIPTION:
+** PR_SetTraceOption() controls the Trace Facility. Depending on
+** command and value, attributes of the Trace Facility may be
+** changed.
+** 
+** INPUTS:
+**  command: An enumerated value in the set of PRTraceOption.
+**  value: pointer to the data to be set. Type of the data is
+**  dependent on command; for each value of command, the type
+**  and meaning of dereferenced value is shown.
+**
+**  PRTraceBufSize: unsigned long: the size of the trace buffer,
+** in bytes.
+** 
+**  PRTraceEnable: PRTraceHandle. The trace handle to be
+** enabled.
+** 
+**  PRTraceDisable: PRTraceHandle. The trace handle to be
+** disabled.
+** 
+**  PRTraceSuspend: void. value must be NULL. All tracing is
+** suspended.
+** 
+**  PRTraceResume: void. value must be NULL. Tracing for all
+** previously enabled, prior to a PRTraceSuspend, is resumed.
+** 
+**  PRTraceStopRecording: void. value must be NULL. If recording
+** (see: ** PR_RecordTraceEntries()) is being done, 
+** PRTraceStopRecording causes PR_RecordTraceEntries() to return
+** to its caller. If recording is not being done, this function
+** has no effect.
+** 
+**  PRTraceSuspendRecording: void. Must be NULL. If recording is
+** being done, PRTraceSuspendRecording causes further writes to
+** the trace file to be suspended. Data in the in-memory
+** trace buffer that would ordinarily be written to the
+** trace file will not be written. Trace entries will continue
+** to be entered in the in-memory buffer. If the Trace Facility
+** recording is already in a suspended state, the call has no
+** effect.
+** 
+**  PRTraceResumeRecording: void. value must be NULL. If
+** recording for the Trace Facility has been previously been
+** suspended, this causes recording to resume. Recording resumes
+** with the next in-memory buffer segment that would be written
+** if trace recording had not been suspended. If recording is
+** not currently suspended, the call has no effect.
+** 
+**  PRTraceLockHandles: void. value must be NULL. Locks the
+** trace handle lock. While the trace handle lock is held,
+** calls to PR_CreateTrace() will block until the lock is
+** released.
+** 
+**  PRTraceUnlockHandles: void. value must be NULL. Unlocks the
+** trace handle lock.
+** 
+** OUTPUTS:
+**  The operation of the Trace Facility may be changed.
+** 
+** RETURNS: void
+** 
+** RESTRICTIONS:
+** 
+*/
+#if defined (DEBUG) || defined (FORCE_NSPR_TRACE)
+#define PR_SET_TRACE_OPTION(command,value)\
+    PR_SetTraceOption((command),(value))
+#else
+#define PR_SET_TRACE_OPTION(command,value)
+#endif
+
+NSPR_API(void) 
+	PR_SetTraceOption( 
+	    PRTraceOption command,  /* One of the enumerated values */
+	    void *value             /* command value or NULL */
+);
+
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_GetTraceOption() -- Retrieve settings from the Trace Facility
+** 
+** DESCRIPTION:
+** PR_GetTraceOption() retrieves the current setting of the
+** Trace Facility control depending on command.
+** 
+** 
+**  PRTraceBufSize: unsigned long: the size of the trace buffer,
+** in bytes.
+** 
+** 
+** INPUTS:
+**  command: one of the enumerated values in PRTraceOptions
+** valid for PR_GetTraceOption().
+** 
+** OUTPUTS:
+**  dependent on command.
+** 
+** RETURNS: void
+** 
+** RESTRICTIONS:
+** 
+*/
+#if defined (DEBUG) || defined (FORCE_NSPR_TRACE)
+#define PR_GET_TRACE_OPTION(command,value)\
+    PR_GetTraceOption((command),(value))
+#else
+#define PR_GET_TRACE_OPTION(command,value)
+#endif
+
+NSPR_API(void) 
+	PR_GetTraceOption( 
+    	PRTraceOption command,  /* One of the enumerated values */
+	    void *value             /* command value or NULL */
+);
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_GetTraceHandleFromName() -- Retrieve an existing
+** handle by name.
+** 
+** DESCRIPTION:
+** PR_GetTraceHandleFromName() retreives an existing tracehandle
+** using the name specified by qName and rName.
+** 
+** INPUTS:
+**  qName: pointer to string. QName for this trace handle. 
+** 
+**  rName: pointer to string. RName for this trace handle. 
+** 
+** 
+** OUTPUTS: returned.
+** 
+** RETURNS: 
+**  PRTraceHandle associated with qName and rName or NULL when
+** there is no match.
+** 
+** RESTRICTIONS:
+** 
+*/
+#if defined (DEBUG) || defined (FORCE_NSPR_TRACE)
+#define PR_GET_TRACE_HANDLE_FROM_NAME(handle,qName,rName)\
+    (handle) = PR_GetTraceHandleFromName((qName),(rName))
+#else
+#define PR_GET_TRACE_HANDLE_FROM_NAME(handle,qName,rName)
+#endif
+
+NSPR_API(PRTraceHandle) 
+	PR_GetTraceHandleFromName( 
+    	const char *qName,      /* QName search argument */
+        const char *rName       /* RName search argument */
+);
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_GetTraceNameFromHandle() -- Retreive trace name
+** by bandle.
+** 
+** DESCRIPTION:
+** PR_GetTraceNameFromHandle() retreives the existing qName,
+** rName, and description for the referenced trace handle.
+** 
+** INPUTS: handle: PRTraceHandle.
+** 
+** OUTPUTS: pointers to the Trace Facility's copy of qName,
+** rName and description. ... Don't mess with these values.
+** They're mine.
+** 
+** RETURNS: void
+** 
+** RESTRICTIONS:
+** 
+*/
+#if defined (DEBUG) || defined (FORCE_NSPR_TRACE)
+#define PR_GET_TRACE_NAME_FROM_HANDLE(handle,qName,rName,description)\
+    PR_GetTraceNameFromHandle((handle),(qName),(rName),(description))
+#else
+#define PR_GET_TRACE_NAME_FROM_HANDLE(handle,qName,rName,description)
+#endif
+
+NSPR_API(void) 
+	PR_GetTraceNameFromHandle( 
+    	PRTraceHandle handle,       /* handle as search argument */
+	    const char **qName,         /* pointer to associated QName */
+	    const char **rName,         /* pointer to associated RName */
+    	const char **description    /* pointer to associated description */
+);
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_FindNextTraceQname() -- Retrieive a QName handle
+** iterator.
+** 
+** DESCRIPTION:
+** PR_FindNextTraceQname() retreives the first or next trace
+** QName handle, depending on the value of handle, from the trace
+** database. The PRTraceHandle returned can be used as an
+** iterator to traverse the QName handles in the Trace database.
+** 
+** INPUTS:
+**  handle: When NULL, PR_FindNextQname() returns the first QName
+** handle. When a handle is a valid PRTraceHandle previously
+** retreived using PR_FindNextQname() the next QName handle is
+** retreived.
+** 
+** OUTPUTS: returned.
+** 
+** RETURNS: 
+**  PRTraceHandle or NULL when there are no trace handles.
+** 
+** RESTRICTIONS:
+**  Iterating thru the trace handles via FindFirst/FindNext
+** should be done under protection of the trace handle lock.
+** See: PR_SetTraceOption( PRLockTraceHandles ).
+** 
+*/
+#if defined (DEBUG) || defined (FORCE_NSPR_TRACE)
+#define PR_FIND_NEXT_TRACE_QNAME(next,handle)\
+    (next) = PR_FindNextTraceQname((handle))
+#else
+#define PR_FIND_NEXT_TRACE_QNAME(next,handle)
+#endif
+
+NSPR_API(PRTraceHandle) 
+	PR_FindNextTraceQname( 
+        PRTraceHandle handle
+);
+
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_FindNextTraceRname() -- Retrieive an RName handle
+** iterator.
+** 
+** DESCRIPTION:
+** PR_FindNextTraceRname() retreives the first or next trace
+** RName handle, depending on the value of handle, from the trace
+** database. The PRTraceHandle returned can be used as an
+** iterator to traverse the RName handles in the Trace database.
+** 
+** INPUTS:
+**  rhandle: When NULL, PR_FindNextRname() returns the first
+** RName handle. When a handle is a valid PRTraceHandle
+** previously retreived using PR_FindNextRname() the next RName
+** handle is retreived.
+**  qhandle: A valid PRTraceHandle retruned from a previous call
+** to PR_FIND_NEXT_TRACE_QNAME().
+** 
+** OUTPUTS: returned.
+** 
+** RETURNS: 
+**  PRTraceHandle or NULL when there are no trace handles.
+** 
+** RESTRICTIONS:
+**  Iterating thru the trace handles via FindNext should be done
+** under protection of the trace handle lock. See: (
+** PR_SetTraceOption( PRLockTraceHandles ).
+** 
+*/
+#if defined (DEBUG) || defined (FORCE_NSPR_TRACE)
+#define PR_FIND_NEXT_TRACE_RNAME(next,rhandle,qhandle)\
+    (next) = PR_FindNextTraceRname((rhandle),(qhandle))
+#else
+#define PR_FIND_NEXT_TRACE_RNAME(next,rhandle,qhandle)
+#endif
+
+NSPR_API(PRTraceHandle) 
+	PR_FindNextTraceRname( 
+        PRTraceHandle rhandle,
+        PRTraceHandle qhandle
+);
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_RecordTraceEntries() -- Write trace entries to external media
+** 
+** DESCRIPTION:
+** PR_RecordTraceEntries() causes entries in the in-memory trace
+** buffer to be written to external media.
+**
+** When PR_RecordTraceEntries() is called from an application
+** thread, the function appears to block until another thread
+** calls PR_SetTraceOption() with the PRTraceStopRecording
+** option. This suggests that PR_RecordTraceEntries() should be
+** called from a user supplied thread whose only job is to
+** record trace entries. 
+** 
+** The environment variable NSPR_TRACE_LOG controls the operation
+** of this function. When NSPR_TRACE_LOG is not defined in the
+** environment, no recording of trace entries occurs. When
+** NSPR_TRACE_LOG is defined, the value of its definition must be
+** the filename of the file to receive the trace entry buffer.
+**
+** PR_RecordTraceEntries() attempts to record the in-memory
+** buffer to a file, subject to the setting of the environment
+** variable NSPR_TRACE_LOG. It is possible because of system
+** load, the thread priority of the recording thread, number of
+** active trace records being written over time, and other
+** variables that some trace records can be lost. ... In other
+** words: don't bet the farm on getting everything.
+** 
+** INPUTS: none
+** 
+** OUTPUTS: none
+** 
+** RETURNS: PR_STATUS
+**    PR_SUCCESS no errors were found.
+**    PR_FAILURE errors were found.
+** 
+** RESTRICTIONS:
+** Only one thread can call PR_RecordTraceEntries() within a
+** process.
+** 
+** On error, PR_RecordTraceEntries() may return prematurely.
+** 
+*/
+#if defined (DEBUG) || defined (FORCE_NSPR_TRACE)
+#define PR_RECORD_TRACE_ENTRIES()\
+	PR_RecordTraceEntries()
+#else
+#define PR_RECORD_TRACE_ENTRIES()
+#endif
+    
+NSPR_API(void)
+	PR_RecordTraceEntries(
+        void 
+);
+
+/* -----------------------------------------------------------------------
+** FUNCTION: PR_GetTraceEntries() -- Retreive trace entries from
+** the Trace Facility
+** 
+** DESCRIPTION:
+** PR_GetTraceEntries() retreives trace entries from the Trace
+** Facility. Up to count trace entries are copied from the Trace
+** Facility into buffer. Only those trace entries that have not
+** been copied via a previous call to PR_GetTraceEntries() are
+** copied. The actual number copied is placed in the PRInt32
+** variable pointed to by found.
+**
+** If more than count trace entries have entered the Trace
+** Facility since the last call to PR_GetTraceEntries() 
+** a lost data condition is returned. In this case, the most
+** recent count trace entries are copied into buffer and found is
+** set to count.
+** 
+** INPUTS:
+**  count. The number of trace entries to be copied into buffer.
+** 
+** 
+** OUTPUTS:
+**  buffer. An array of PRTraceEntries. The buffer is supplied
+** by the caller.
+** 
+** found: 32bit signed integer. The number of PRTraceEntries
+** actually copied. found is always less than or equal to count.
+** 
+** RETURNS: 
+**  zero when there is no lost data.
+**  non-zero when some PRTraceEntries have been lost.
+** 
+** RESTRICTIONS:
+** This is a real performance pig. The copy out operation is bad
+** enough, but depending on then frequency of calls to the
+** function, serious performance impact to the operating
+** application may be realized. ... YMMV.
+** 
+*/
+#if defined (DEBUG) || defined (FORCE_NSPR_TRACE)
+#define PR_GET_TRACE_ENTRIES(buffer,count,found)\
+        PR_GetTraceEntries((buffer),(count),(found))
+#else
+#define PR_GET_TRACE_ENTRIES(buffer,count,found)
+#endif
+
+NSPR_API(PRIntn)
+    PR_GetTraceEntries(
+        PRTraceEntry    *buffer,    /* where to write output */
+        PRInt32         count,      /* number to get */
+        PRInt32         *found      /* number you got */
+);
+
+PR_END_EXTERN_C
+
+#endif /* prtrace_h___ */
+
diff --git a/pr/include/prtypes.h b/pr/include/prtypes.h
new file mode 100644
index 0000000..52b3ab0
--- /dev/null
+++ b/pr/include/prtypes.h
@@ -0,0 +1,590 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** File:                prtypes.h
+** Description: Definitions of NSPR's basic types
+**
+** Prototypes and macros used to make up for deficiencies that we have found
+** in ANSI environments.
+**
+** Since we do not wrap <stdlib.h> and all the other standard headers, authors
+** of portable code will not know in general that they need these definitions.
+** Instead of requiring these authors to find the dependent uses in their code
+** and take the following steps only in those C files, we take steps once here
+** for all C files.
+**/
+
+#ifndef prtypes_h___
+#define prtypes_h___
+
+#ifdef MDCPUCFG
+#include MDCPUCFG
+#else
+#include "prcpucfg.h"
+#endif
+
+#include <stddef.h>
+
+/***********************************************************************
+** MACROS:      PR_EXTERN
+**              PR_IMPLEMENT
+** DESCRIPTION:
+**      These are only for externally visible routines and globals.  For
+**      internal routines, just use "extern" for type checking and that
+**      will not export internal cross-file or forward-declared symbols.
+**      Define a macro for declaring procedures return types. We use this to
+**      deal with windoze specific type hackery for DLL definitions. Use
+**      PR_EXTERN when the prototype for the method is declared. Use
+**      PR_IMPLEMENT for the implementation of the method.
+**
+** Example:
+**   in dowhim.h
+**     PR_EXTERN( void ) DoWhatIMean( void );
+**   in dowhim.c
+**     PR_IMPLEMENT( void ) DoWhatIMean( void ) { return; }
+**
+**
+***********************************************************************/
+#if defined(WIN32)
+
+#define PR_EXPORT(__type) extern __declspec(dllexport) __type
+#define PR_EXPORT_DATA(__type) extern __declspec(dllexport) __type
+#define PR_IMPORT(__type) __declspec(dllimport) __type
+#define PR_IMPORT_DATA(__type) __declspec(dllimport) __type
+
+#define PR_EXTERN(__type) extern __declspec(dllexport) __type
+#define PR_IMPLEMENT(__type) __declspec(dllexport) __type
+#define PR_EXTERN_DATA(__type) extern __declspec(dllexport) __type
+#define PR_IMPLEMENT_DATA(__type) __declspec(dllexport) __type
+
+#define PR_CALLBACK
+#define PR_CALLBACK_DECL
+#define PR_STATIC_CALLBACK(__x) static __x
+
+#elif defined(XP_BEOS)
+
+#define PR_EXPORT(__type) extern __declspec(dllexport) __type
+#define PR_EXPORT_DATA(__type) extern __declspec(dllexport) __type
+#define PR_IMPORT(__type) extern __declspec(dllexport) __type
+#define PR_IMPORT_DATA(__type) extern __declspec(dllexport) __type
+
+#define PR_EXTERN(__type) extern __declspec(dllexport) __type
+#define PR_IMPLEMENT(__type) __declspec(dllexport) __type
+#define PR_EXTERN_DATA(__type) extern __declspec(dllexport) __type
+#define PR_IMPLEMENT_DATA(__type) __declspec(dllexport) __type
+
+#define PR_CALLBACK
+#define PR_CALLBACK_DECL
+#define PR_STATIC_CALLBACK(__x) static __x
+
+#elif defined(XP_OS2) && defined(__declspec)
+
+#define PR_EXPORT(__type) extern __declspec(dllexport) __type
+#define PR_EXPORT_DATA(__type) extern __declspec(dllexport) __type
+#define PR_IMPORT(__type) extern  __declspec(dllimport) __type
+#define PR_IMPORT_DATA(__type) extern __declspec(dllimport) __type
+
+#define PR_EXTERN(__type) extern __declspec(dllexport) __type
+#define PR_IMPLEMENT(__type) __declspec(dllexport) __type
+#define PR_EXTERN_DATA(__type) extern __declspec(dllexport) __type
+#define PR_IMPLEMENT_DATA(__type) __declspec(dllexport) __type
+
+#define PR_CALLBACK
+#define PR_CALLBACK_DECL
+#define PR_STATIC_CALLBACK(__x) static __x
+
+#elif defined(SYMBIAN)
+
+#define PR_EXPORT(__type) extern __declspec(dllexport) __type
+#define PR_EXPORT_DATA(__type) extern __declspec(dllexport) __type
+#ifdef __WINS__
+#define PR_IMPORT(__type) extern __declspec(dllexport) __type
+#define PR_IMPORT_DATA(__type) extern __declspec(dllexport) __type
+#else
+#define PR_IMPORT(__type) extern __declspec(dllimport) __type
+#define PR_IMPORT_DATA(__type) extern __declspec(dllimport) __type
+#endif
+
+#define PR_EXTERN(__type) extern __type
+#define PR_IMPLEMENT(__type) __type
+#define PR_EXTERN_DATA(__type) extern __type
+#define PR_IMPLEMENT_DATA(__type) __type
+
+#define PR_CALLBACK
+#define PR_CALLBACK_DECL
+#define PR_STATIC_CALLBACK(__x) static __x
+
+#else /* Unix */
+
+/* GCC 3.3 and later support the visibility attribute. */
+#if (__GNUC__ >= 4) || \
+    (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
+#define PR_VISIBILITY_DEFAULT __attribute__((visibility("default")))
+#else
+#define PR_VISIBILITY_DEFAULT
+#endif
+
+#define PR_EXPORT(__type) extern PR_VISIBILITY_DEFAULT __type
+#define PR_EXPORT_DATA(__type) extern PR_VISIBILITY_DEFAULT __type
+#define PR_IMPORT(__type) extern PR_VISIBILITY_DEFAULT __type
+#define PR_IMPORT_DATA(__type) extern PR_VISIBILITY_DEFAULT __type
+
+#define PR_EXTERN(__type) extern PR_VISIBILITY_DEFAULT __type
+#define PR_IMPLEMENT(__type) PR_VISIBILITY_DEFAULT __type
+#define PR_EXTERN_DATA(__type) extern PR_VISIBILITY_DEFAULT __type
+#define PR_IMPLEMENT_DATA(__type) PR_VISIBILITY_DEFAULT __type
+#define PR_CALLBACK
+#define PR_CALLBACK_DECL
+#define PR_STATIC_CALLBACK(__x) static __x
+
+#endif
+
+#if defined(_NSPR_BUILD_)
+#define NSPR_API(__type) PR_EXPORT(__type)
+#define NSPR_DATA_API(__type) PR_EXPORT_DATA(__type)
+#else
+#define NSPR_API(__type) PR_IMPORT(__type)
+#define NSPR_DATA_API(__type) PR_IMPORT_DATA(__type)
+#endif
+
+/***********************************************************************
+** MACROS:      PR_BEGIN_MACRO
+**              PR_END_MACRO
+** DESCRIPTION:
+**      Macro body brackets so that macros with compound statement definitions
+**      behave syntactically more like functions when called.
+***********************************************************************/
+#define PR_BEGIN_MACRO  do {
+#define PR_END_MACRO    } while (0)
+
+/***********************************************************************
+** MACROS:      PR_BEGIN_EXTERN_C
+**              PR_END_EXTERN_C
+** DESCRIPTION:
+**      Macro shorthands for conditional C++ extern block delimiters.
+***********************************************************************/
+#ifdef __cplusplus
+#define PR_BEGIN_EXTERN_C       extern "C" {
+#define PR_END_EXTERN_C         }
+#else
+#define PR_BEGIN_EXTERN_C
+#define PR_END_EXTERN_C
+#endif
+
+/***********************************************************************
+** MACROS:      PR_BIT
+**              PR_BITMASK
+** DESCRIPTION:
+** Bit masking macros.  XXX n must be <= 31 to be portable
+***********************************************************************/
+#define PR_BIT(n)       ((PRUint32)1 << (n))
+#define PR_BITMASK(n)   (PR_BIT(n) - 1)
+
+/***********************************************************************
+** MACROS:      PR_ROUNDUP
+**              PR_MIN
+**              PR_MAX
+**              PR_ABS
+** DESCRIPTION:
+**      Commonly used macros for operations on compatible types.
+***********************************************************************/
+#define PR_ROUNDUP(x,y) ((((x)+((y)-1))/(y))*(y))
+#define PR_MIN(x,y)     ((x)<(y)?(x):(y))
+#define PR_MAX(x,y)     ((x)>(y)?(x):(y))
+#define PR_ABS(x)       ((x)<0?-(x):(x))
+
+/***********************************************************************
+** MACROS:      PR_ARRAY_SIZE
+** DESCRIPTION:
+**  The number of elements in an array.
+***********************************************************************/
+#define PR_ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
+
+PR_BEGIN_EXTERN_C
+
+/*
+** Starting in NSPR 4.9.5, NSPR's exact-width integer types should match
+** the exact-width integer types defined in <stdint.h>. This allows sloppy
+** code to use PRInt{N} and int{N}_t interchangeably.
+**
+** The 8-bit and 16-bit integer types can only be defined using char and
+** short. All platforms define the 32-bit integer types using int. So only
+** the 64-bit integer types could be defined differently.
+**
+** NSPR's original strategy was to use the "shortest" 64-bit integer type:
+** if long is 64-bit, then prefer it over long long. This strategy is also
+** used by Linux/glibc, FreeBSD, and NetBSD.
+**
+** Other platforms use a different strategy: simply define the 64-bit
+** integer types using long long. We define the PR_ALTERNATE_INT64_TYPEDEF
+** macro on these platforms. Note that PR_ALTERNATE_INT64_TYPEDEF is for
+** internal use by NSPR headers only. Do not define or test this macro in
+** your code.
+**
+** NOTE: NSPR can't use <stdint.h> because C99 requires C++ code to define
+** __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS to make all the macros
+** defined in <stdint.h> available. This strange requirement is gone in
+** C11. When most platforms ignore this C99 requirement, NSPR will be able
+** to use <stdint.h>. A patch to do that is in NSPR bug 634793.
+*/
+
+#if defined(__APPLE__) || defined(__ANDROID__) || defined(__OpenBSD__)
+#define PR_ALTERNATE_INT64_TYPEDEF
+#endif
+
+/************************************************************************
+** TYPES:       PRUint8
+**              PRInt8
+** DESCRIPTION:
+**  The int8 types are known to be 8 bits each. There is no type that
+**      is equivalent to a plain "char".
+************************************************************************/
+#if PR_BYTES_PER_BYTE == 1
+typedef unsigned char PRUint8;
+/*
+** Some cfront-based C++ compilers do not like 'signed char' and
+** issue the warning message:
+**     warning: "signed" not implemented (ignored)
+** For these compilers, we have to define PRInt8 as plain 'char'.
+** Make sure that plain 'char' is indeed signed under these compilers.
+*/
+#if (defined(HPUX) && defined(__cplusplus) \
+        && !defined(__GNUC__) && __cplusplus < 199707L) \
+    || (defined(SCO) && defined(__cplusplus) \
+        && !defined(__GNUC__) && __cplusplus == 1L)
+typedef char PRInt8;
+#else
+typedef signed char PRInt8;
+#endif
+#else
+#error No suitable type for PRInt8/PRUint8
+#endif
+
+/************************************************************************
+ * MACROS:      PR_INT8_MAX
+ *              PR_INT8_MIN
+ *              PR_UINT8_MAX
+ * DESCRIPTION:
+ *  The maximum and minimum values of a PRInt8 or PRUint8.
+************************************************************************/
+
+#define PR_INT8_MAX 127
+#define PR_INT8_MIN (-128)
+#define PR_UINT8_MAX 255U
+
+/************************************************************************
+** TYPES:       PRUint16
+**              PRInt16
+** DESCRIPTION:
+**  The int16 types are known to be 16 bits each.
+************************************************************************/
+#if PR_BYTES_PER_SHORT == 2
+typedef unsigned short PRUint16;
+typedef short PRInt16;
+#else
+#error No suitable type for PRInt16/PRUint16
+#endif
+
+/************************************************************************
+ * MACROS:      PR_INT16_MAX
+ *              PR_INT16_MIN
+ *              PR_UINT16_MAX
+ * DESCRIPTION:
+ *  The maximum and minimum values of a PRInt16 or PRUint16.
+************************************************************************/
+
+#define PR_INT16_MAX 32767
+#define PR_INT16_MIN (-32768)
+#define PR_UINT16_MAX 65535U
+
+/************************************************************************
+** TYPES:       PRUint32
+**              PRInt32
+** DESCRIPTION:
+**  The int32 types are known to be 32 bits each.
+************************************************************************/
+#if PR_BYTES_PER_INT == 4
+typedef unsigned int PRUint32;
+typedef int PRInt32;
+#define PR_INT32(x)  x
+#define PR_UINT32(x) x ## U
+#elif PR_BYTES_PER_LONG == 4
+typedef unsigned long PRUint32;
+typedef long PRInt32;
+#define PR_INT32(x)  x ## L
+#define PR_UINT32(x) x ## UL
+#else
+#error No suitable type for PRInt32/PRUint32
+#endif
+
+/************************************************************************
+ * MACROS:      PR_INT32_MAX
+ *              PR_INT32_MIN
+ *              PR_UINT32_MAX
+ * DESCRIPTION:
+ *  The maximum and minimum values of a PRInt32 or PRUint32.
+************************************************************************/
+
+#define PR_INT32_MAX PR_INT32(2147483647)
+#define PR_INT32_MIN (-PR_INT32_MAX - 1)
+#define PR_UINT32_MAX PR_UINT32(4294967295)
+
+/************************************************************************
+** TYPES:       PRUint64
+**              PRInt64
+** DESCRIPTION:
+**  The int64 types are known to be 64 bits each. Care must be used when
+**      declaring variables of type PRUint64 or PRInt64. Different hardware
+**      architectures and even different compilers have varying support for
+**      64 bit values. The only guaranteed portability requires the use of
+**      the LL_ macros (see prlong.h).
+**
+** MACROS:      PR_INT64
+**              PR_UINT64
+** DESCRIPTION:
+**  The PR_INT64 and PR_UINT64 macros provide a portable way for
+**      specifying 64-bit integer constants. They can only be used if
+**      PRInt64 and PRUint64 are defined as compiler-supported 64-bit
+**      integer types (i.e., if HAVE_LONG_LONG is defined, which is true
+**      for all the supported compilers topday). If PRInt64 and PRUint64
+**      are defined as structs, the LL_INIT macro defined in prlong.h has
+**      to be used.
+**
+** MACROS:      PR_INT64_MAX
+**              PR_INT64_MIN
+**              PR_UINT64_MAX
+** DESCRIPTION:
+**  The maximum and minimum values of a PRInt64 or PRUint64.
+************************************************************************/
+#ifdef HAVE_LONG_LONG
+/* Keep this in sync with prlong.h. */
+#if PR_BYTES_PER_LONG == 8 && !defined(PR_ALTERNATE_INT64_TYPEDEF)
+typedef long PRInt64;
+typedef unsigned long PRUint64;
+#define PR_INT64(x)  x ## L
+#define PR_UINT64(x) x ## UL
+#elif defined(WIN32) && !defined(__GNUC__)
+typedef __int64  PRInt64;
+typedef unsigned __int64 PRUint64;
+#define PR_INT64(x)  x ## i64
+#define PR_UINT64(x) x ## ui64
+#else
+typedef long long PRInt64;
+typedef unsigned long long PRUint64;
+#define PR_INT64(x)  x ## LL
+#define PR_UINT64(x) x ## ULL
+#endif /* PR_BYTES_PER_LONG == 8 */
+
+#define PR_INT64_MAX PR_INT64(0x7fffffffffffffff)
+#define PR_INT64_MIN (-PR_INT64_MAX - 1)
+#define PR_UINT64_MAX PR_UINT64(-1)
+#else  /* !HAVE_LONG_LONG */
+typedef struct {
+#ifdef IS_LITTLE_ENDIAN
+    PRUint32 lo, hi;
+#else
+    PRUint32 hi, lo;
+#endif
+} PRInt64;
+typedef PRInt64 PRUint64;
+
+#define PR_INT64_MAX (PRInt64){0x7fffffff, 0xffffffff}
+#define PR_INT64_MIN (PRInt64){0xffffffff, 0xffffffff}
+#define PR_UINT64_MAX (PRUint64){0xffffffff, 0xffffffff}
+
+#endif /* !HAVE_LONG_LONG */
+
+/************************************************************************
+** TYPES:       PRUintn
+**              PRIntn
+** DESCRIPTION:
+**  The PRIntn types are most appropriate for automatic variables. They are
+**      guaranteed to be at least 16 bits, though various architectures may
+**      define them to be wider (e.g., 32 or even 64 bits). These types are
+**      never valid for fields of a structure.
+************************************************************************/
+#if PR_BYTES_PER_INT >= 2
+typedef int PRIntn;
+typedef unsigned int PRUintn;
+#else
+#error 'sizeof(int)' not sufficient for platform use
+#endif
+
+/************************************************************************
+** TYPES:       PRFloat64
+** DESCRIPTION:
+**  NSPR's floating point type is always 64 bits.
+************************************************************************/
+typedef double          PRFloat64;
+
+/************************************************************************
+** TYPES:       PRSize
+** DESCRIPTION:
+**  A type for representing the size of objects.
+************************************************************************/
+typedef size_t PRSize;
+
+
+/************************************************************************
+** TYPES:       PROffset32, PROffset64
+** DESCRIPTION:
+**  A type for representing byte offsets from some location.
+************************************************************************/
+typedef PRInt32 PROffset32;
+typedef PRInt64 PROffset64;
+
+/************************************************************************
+** TYPES:       PRPtrDiff
+** DESCRIPTION:
+**  A type for pointer difference. Variables of this type are suitable
+**      for storing a pointer or pointer subtraction.
+************************************************************************/
+typedef ptrdiff_t PRPtrdiff;
+
+/************************************************************************
+** TYPES:       PRUptrdiff
+** DESCRIPTION:
+**  A type for pointer difference. Variables of this type are suitable
+**      for storing a pointer or pointer sutraction.
+************************************************************************/
+#ifdef _WIN64
+typedef PRUint64 PRUptrdiff;
+#else
+typedef unsigned long PRUptrdiff;
+#endif
+
+/************************************************************************
+** TYPES:       PRBool
+** DESCRIPTION:
+**  Use PRBool for variables and parameter types. Use PR_FALSE and PR_TRUE
+**      for clarity of target type in assignments and actual arguments. Use
+**      'if (bool)', 'while (!bool)', '(bool) ? x : y' etc., to test booleans
+**      just as you would C int-valued conditions.
+************************************************************************/
+typedef PRIntn PRBool;
+#define PR_TRUE 1
+#define PR_FALSE 0
+
+/************************************************************************
+** TYPES:       PRPackedBool
+** DESCRIPTION:
+**  Use PRPackedBool within structs where bitfields are not desirable
+**      but minimum and consistant overhead matters.
+************************************************************************/
+typedef PRUint8 PRPackedBool;
+
+/*
+** Status code used by some routines that have a single point of failure or
+** special status return.
+*/
+typedef enum { PR_FAILURE = -1, PR_SUCCESS = 0 } PRStatus;
+
+#ifndef __PRUNICHAR__
+#define __PRUNICHAR__
+#ifdef WIN32
+typedef wchar_t PRUnichar;
+#else
+typedef PRUint16 PRUnichar;
+#endif
+#endif
+
+/*
+** WARNING: The undocumented data types PRWord and PRUword are
+** only used in the garbage collection and arena code.  Do not
+** use PRWord and PRUword in new code.
+**
+** A PRWord is an integer that is the same size as a void*.
+** It implements the notion of a "word" in the Java Virtual
+** Machine.  (See Sec. 3.4 "Words", The Java Virtual Machine
+** Specification, Addison-Wesley, September 1996.
+** http://java.sun.com/docs/books/vmspec/index.html.)
+*/
+#ifdef _WIN64
+typedef PRInt64 PRWord;
+typedef PRUint64 PRUword;
+#else
+typedef long PRWord;
+typedef unsigned long PRUword;
+#endif
+
+/*
+ * PR_PRETEND_NORETURN, specified at the end of a function declaration,
+ * indicates that for the purposes of static analysis, this function does not
+ * return.  (The function definition does not need to be annotated.)
+ *
+ * void PR_Assert(const char *s, const char *file, PRIntn ln)
+ *     PR_PRETEND_NORETURN;
+ *
+ * Some static analyzers, like scan-build from clang, can use this information
+ * to eliminate false positives.  From the upstream documentation of
+ * scan-build:
+ *     This attribute is useful for annotating assertion handlers that actually
+ *     can return, but for the purpose of using the analyzer we want to pretend
+ *     that such functions do not return.
+ */
+#ifdef __clang_analyzer__
+#if __has_extension(attribute_analyzer_noreturn)
+#define PR_PRETEND_NORETURN __attribute__((analyzer_noreturn))
+#endif
+#endif
+
+#ifndef PR_PRETEND_NORETURN
+#define PR_PRETEND_NORETURN /* no support */
+#endif
+
+#if defined(NO_NSPR_10_SUPPORT)
+#else
+/********* ???????????????? FIX ME       ??????????????????????????? *****/
+/********************** Some old definitions until pr=>ds transition is done ***/
+/********************** Also, we are still using NSPR 1.0. GC ******************/
+/*
+** Fundamental NSPR macros, used nearly everywhere.
+*/
+
+#define PR_PUBLIC_API		PR_IMPLEMENT
+
+/*
+** Macro body brackets so that macros with compound statement definitions
+** behave syntactically more like functions when called.
+*/
+#define NSPR_BEGIN_MACRO        do {
+#define NSPR_END_MACRO          } while (0)
+
+/*
+** Macro shorthands for conditional C++ extern block delimiters.
+*/
+#ifdef NSPR_BEGIN_EXTERN_C
+#undef NSPR_BEGIN_EXTERN_C
+#endif
+#ifdef NSPR_END_EXTERN_C
+#undef NSPR_END_EXTERN_C
+#endif
+
+#ifdef __cplusplus
+#define NSPR_BEGIN_EXTERN_C     extern "C" {
+#define NSPR_END_EXTERN_C       }
+#else
+#define NSPR_BEGIN_EXTERN_C
+#define NSPR_END_EXTERN_C
+#endif
+
+#include "obsolete/protypes.h"
+
+/********* ????????????? End Fix me ?????????????????????????????? *****/
+#endif /* NO_NSPR_10_SUPPORT */
+
+/*
+** Compile-time assert. "condition" must be a constant expression.
+** The macro can be used only in places where an "extern" declaration is
+** allowed.
+*/
+#define PR_STATIC_ASSERT(condition) \
+    extern void pr_static_assert(int arg[(condition) ? 1 : -1])
+
+PR_END_EXTERN_C
+
+#endif /* prtypes_h___ */
+
diff --git a/pr/include/prvrsion.h b/pr/include/prvrsion.h
new file mode 100755
index 0000000..a8415b2
--- /dev/null
+++ b/pr/include/prvrsion.h
@@ -0,0 +1,105 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+/* author: jstewart */
+
+#if defined(_PRVERSION_H)
+#else
+#define _PRVERSION_H
+
+#include "prtypes.h"
+
+PR_BEGIN_EXTERN_C
+
+/* All components participating in the PR version protocol must expose
+ * a structure and a function. The structure is defined below and named
+ * according to the naming conventions outlined further below.  The function
+ * is called libVersionPoint and returns a pointer to this structure.
+ */
+
+/* on NT, always pack the structure the same. */
+#ifdef _WIN32
+#pragma pack(push, 8)
+#endif
+
+typedef struct {
+    /*
+     * The first field defines which version of this structure is in use.
+     * At this time, only version 2 is specified. If this value is not 
+     * 2, you must read no further into the structure.
+     */
+    PRInt32    version; 
+  
+    /* for Version 2, this is the body format. */
+    PRInt64         buildTime;      /* 64 bits - usecs since midnight, 1/1/1970 */
+    char *          buildTimeString;/* a human readable version of the time */
+  
+    PRUint8   vMajor;               /* Major version of this component */
+    PRUint8   vMinor;               /* Minor version of this component */
+    PRUint8   vPatch;               /* Patch level of this component */
+  
+    PRBool          beta;           /* true if this is a beta component */
+    PRBool          debug;          /* true if this is a debug component */
+    PRBool          special;        /* true if this component is a special build */
+  
+    char *          filename;       /* The original filename */
+    char *          description;    /* description of this component */
+    char *          security;       /* level of security in this component */
+    char *          copyright;      /* The copyright for this file */
+    char *          comment;        /* free form field for misc usage */
+    char *          specialString;  /* the special variant for this build */
+} PRVersionDescription;
+
+/* on NT, restore the previous packing */
+#ifdef _WIN32
+#pragma pack(pop)
+#endif
+
+/*
+ * All components must define an entrypoint named libVersionPoint which
+ * is of type versionEntryPointType.
+ *
+ * For example, for a library named libfoo, we would have:
+ *
+ *   PRVersionDescription prVersionDescription_libfoo =
+ *   {
+ *       ...
+ *   };
+ *
+ *   PR_IMPLEMENT(const PRVersionDescription*) libVersionPoint(void)
+ *   {
+ *       return &prVersionDescription_libfoo;
+ *   }
+ */
+typedef const PRVersionDescription *(*versionEntryPointType)(void);
+
+/* 
+ * Where you declare your libVersionPoint, do it like this: 
+ * PR_IMPLEMENT(const PRVersionDescription *) libVersionPoint(void) {
+ *  fill it in...
+ * }
+ */
+
+/*
+ * NAMING CONVENTION FOR struct
+ *
+ * all components should also expose a static PRVersionDescription
+ * The name of the struct should be calculated as follows:
+ * Take the value of filename. (If filename is not specified, calculate
+ * a short, unique string.)  Convert all non-alphanumeric characters
+ * to '_'.  To this, prepend "PRVersionDescription_".  Thus for libfoo.so,
+ * the symbol name is "PRVersionDescription_libfoo_so".
+ * so the file should have
+ * PRVersionDescription PRVersionDescription_libfoo_so { fill it in };
+ * on NT, this file should be declspec export.
+ */
+
+PR_END_EXTERN_C
+
+#endif  /* defined(_PRVERSION_H) */
+
+/* prvrsion.h */
+
diff --git a/pr/include/prwin16.h b/pr/include/prwin16.h
new file mode 100644
index 0000000..9f8d7a9
--- /dev/null
+++ b/pr/include/prwin16.h
@@ -0,0 +1,164 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef prwin16_h___
+#define prwin16_h___
+
+/*
+** Condition use of this header on platform.
+*/
+#if (defined(XP_PC) && !defined(_WIN32) && !defined(XP_OS2) && defined(MOZILLA_CLIENT)) || defined(WIN16)
+#include <stdio.h>
+
+PR_BEGIN_EXTERN_C
+/* 
+** Win16 stdio special case.
+** To get stdio to work for Win16, all calls to printf() and related
+** things must be called from the environment of the .EXE; calls to
+** printf() from the .DLL send output to the bit-bucket.
+**
+** To make sure that PR_fprintf(), and related functions, work correctly,
+** the actual stream I/O to stdout, stderr, stdin must be done in the
+** .EXE. To do this, a hack is placed in _MD_Write() such that the
+** fd for stdio handles results in a call to the .EXE.
+**
+** file w16stdio.c contains the functions that get called from NSPR
+** to do the actual I/O. w16stdio.o must be statically linked with
+** any application needing stdio for Win16.
+**
+** The address of these functions must be made available to the .DLL
+** so he can call back to the .EXE. To do this, function 
+** PR_MD_RegisterW16StdioCallbacks() is called from the .EXE.
+** The arguments are the functions defined in w16stdio.c
+** At runtime, MD_Write() calls the registered functions, if any
+** were registered.
+**
+** prinit.h contains a macro PR_STDIO_INIT() that calls the registration
+** function for Win16; For other platforms, the macro is a No-Op.
+**
+** Note that stdio is not operational at all on Win16 GUI applications.
+** This special case exists to provide stdio capability from the NSPR
+** .DLL for command line applications only. NSPR's test cases are
+** almost exclusively command line applications.
+**
+** See also: w16io.c, w16stdio.c
+*/
+typedef PRInt32 (PR_CALLBACK *PRStdinRead)( void *buf, PRInt32 amount);
+typedef PRInt32 (PR_CALLBACK *PRStdoutWrite)( void *buf, PRInt32 amount);
+typedef PRInt32 (PR_CALLBACK *PRStderrWrite)( void *buf, PRInt32 amount);
+
+NSPR_API(PRStatus)
+PR_MD_RegisterW16StdioCallbacks( 
+    PRStdinRead inReadf,            /* i: function pointer for stdin read       */
+    PRStdoutWrite outWritef,        /* i: function pointer for stdout write     */
+    PRStderrWrite errWritef         /* i: function pointer for stderr write     */
+    );
+
+NSPR_API(PRInt32)
+_PL_W16StdioWrite( void *buf, PRInt32 amount );
+
+NSPR_API(PRInt32)
+_PL_W16StdioRead( void *buf, PRInt32 amount );
+
+#define PR_STDIO_INIT() PR_MD_RegisterW16StdioCallbacks( \
+    _PL_W16StdioRead, _PL_W16StdioWrite, _PL_W16StdioWrite ); \
+    PR_INIT_CALLBACKS();
+
+/*
+** Win16 hackery.
+**
+*/
+struct PRMethodCallbackStr {
+    int     (PR_CALLBACK *auxOutput)(const char *outputString);
+    size_t  (PR_CALLBACK *strftime)(char *s, size_t len, const char *fmt, const struct tm *p);
+    void *  (PR_CALLBACK *malloc)( size_t size );
+    void *  (PR_CALLBACK *calloc)(size_t n, size_t size );
+    void *  (PR_CALLBACK *realloc)( void* old_blk, size_t size );
+    void    (PR_CALLBACK *free)( void *ptr );
+    void *  (PR_CALLBACK *getenv)( const char *name);
+    int     (PR_CALLBACK *putenv)( const char *assoc);
+/*    void *  (PR_CALLBACK *perror)( const char *prefix ); */
+};
+
+NSPR_API(void) PR_MDRegisterCallbacks(struct PRMethodCallbackStr *);
+
+int PR_CALLBACK _PL_W16CallBackPuts( const char *outputString );
+size_t PR_CALLBACK _PL_W16CallBackStrftime( 
+    char *s, 
+    size_t len, 
+    const char *fmt,
+    const struct tm *p );
+void * PR_CALLBACK _PL_W16CallBackMalloc( size_t size );
+void * PR_CALLBACK _PL_W16CallBackCalloc( size_t n, size_t size );
+void * PR_CALLBACK _PL_W16CallBackRealloc( 
+    void *old_blk, 
+    size_t size );
+void   PR_CALLBACK _PL_W16CallBackFree( void *ptr );
+void * PR_CALLBACK _PL_W16CallBackGetenv( const char *name );
+int PR_CALLBACK _PL_W16CallBackPutenv( const char *assoc );
+
+/*
+** Hackery! 
+**
+** These functions are provided as static link points.
+** This is to satisfy the quick port of Gromit to NSPR 2.0
+** ... Don't do this! ... alas, It may never go away.
+** 
+*/
+NSPR_API(int)     PR_MD_printf(const char *, ...);
+NSPR_API(void)    PR_MD_exit(int);
+NSPR_API(size_t)  PR_MD_strftime(char *, size_t, const char *, const struct tm *); 
+NSPR_API(int)     PR_MD_sscanf(const char *, const char *, ...);
+NSPR_API(void*)   PR_MD_malloc( size_t size );
+NSPR_API(void*)   PR_MD_calloc( size_t n, size_t size );
+NSPR_API(void*)   PR_MD_realloc( void* old_blk, size_t size );
+NSPR_API(void)    PR_MD_free( void *ptr );
+NSPR_API(char*)   PR_MD_getenv( const char *name );
+NSPR_API(int)     PR_MD_putenv( const char *assoc );
+NSPR_API(int)     PR_MD_fprintf(FILE *fPtr, const char *fmt, ...);
+
+#define PR_INIT_CALLBACKS()                         \
+    {                                               \
+        static struct PRMethodCallbackStr cbf = {   \
+            _PL_W16CallBackPuts,                    \
+            _PL_W16CallBackStrftime,                \
+            _PL_W16CallBackMalloc,                  \
+            _PL_W16CallBackCalloc,                  \
+            _PL_W16CallBackRealloc,                 \
+            _PL_W16CallBackFree,                    \
+            _PL_W16CallBackGetenv,                  \
+            _PL_W16CallBackPutenv,                  \
+        };                                          \
+        PR_MDRegisterCallbacks( &cbf );             \
+    }
+
+
+/*
+** Get the exception context for Win16 MFC applications threads
+*/
+NSPR_API(void *) PR_W16GetExceptionContext(void);
+/*
+** Set the exception context for Win16 MFC applications threads
+*/
+NSPR_API(void) PR_W16SetExceptionContext(void *context);
+
+PR_END_EXTERN_C
+#else
+/*
+** For platforms other than Win16, define
+** PR_STDIO_INIT() as a No-Op.
+*/
+#define PR_STDIO_INIT()
+#endif /* WIN16 || MOZILLA_CLIENT */
+
+#endif /* prwin16_h___ */
+
+
+
+
+
+
+
+
diff --git a/pr/src/.cvsignore b/pr/src/.cvsignore
new file mode 100644
index 0000000..41a1bd2
--- /dev/null
+++ b/pr/src/.cvsignore
@@ -0,0 +1,2 @@
+Makefile
+_pr_bld.h
diff --git a/pr/src/Makefile.in b/pr/src/Makefile.in
new file mode 100644
index 0000000..48b6fae
--- /dev/null
+++ b/pr/src/Makefile.in
@@ -0,0 +1,379 @@
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#! gmake
+
+MOD_DEPTH	= ../..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+
+include $(MOD_DEPTH)/config/autoconf.mk
+
+include $(topsrcdir)/config/config.mk
+
+DIRS = io linking malloc md memory misc threads
+
+ifeq ($(USE_PTHREADS), 1)
+	DIRS += pthreads
+endif
+
+ifeq ($(USE_BTHREADS), 1)
+	DIRS += bthreads
+endif
+
+ifeq ($(USE_CPLUS), 1)
+	DIRS += cplus
+endif
+
+#
+# Define platform-dependent OS_LIBS
+#
+
+ifeq ($(OS_ARCH),SunOS)
+MAPFILE = $(OBJDIR)/nsprmap.sun
+GARBAGE += $(MAPFILE)
+ifdef NS_USE_GCC
+ifdef GCC_USE_GNU_LD
+MKSHLIB += -Wl,--version-script,$(MAPFILE)
+else
+MKSHLIB += -Wl,-M,$(MAPFILE)
+endif
+else
+MKSHLIB += -M $(MAPFILE)
+endif
+#
+# In Solaris 2.6 or earlier, -lrt is called -lposix4.
+# 
+LIBRT_TEST=$(firstword $(sort 5.7 $(OS_RELEASE)))
+ifeq (5.7, $(LIBRT_TEST))
+LIBRT=-lrt
+else
+LIBRT=-lposix4
+endif
+
+ifdef USE_PTHREADS
+OS_LIBS			= -lpthread ${LIBRT} -lsocket -lnsl -ldl -lc
+else
+OS_LIBS			= -lsocket -lnsl -ldl -lc
+endif	# USE_PTHREADS
+ifeq ($(CPU_ARCH),sparc)
+ifndef USE_64
+DSO_LDOPTS	+= -Wl,-f,\$$ORIGIN/cpu/\$$ISALIST/lib$(ULTRASPARC_LIBRARY)$(LIBRARY_VERSION).so
+endif
+endif	# sparc
+endif	# SunOS
+
+ifeq ($(OS_ARCH), IRIX)
+ifeq ($(USE_PTHREADS), 1)
+OS_LIBS = -lpthread
+endif
+OS_LIBS += -lc
+endif
+
+ifeq ($(OS_ARCH),AIX)
+DSO_LDOPTS	+= -binitfini::_PR_Fini
+OS_LIBS		= -lodm -lcfg
+ifeq ($(CLASSIC_NSPR),1)
+ifeq ($(OS_RELEASE),4.1)
+OS_LIBS		+= -lsvld -lc
+else
+OS_LIBS		+= -ldl -lc
+endif
+else
+ifeq ($(OS_RELEASE),4.1)
+OS_LIBS		+= -lpthreads -lsvld -lC_r -lC -lc_r -lm /usr/lib/libc.a
+else
+OS_LIBS		+= -lpthreads -ldl -lC_r -lC -lc_r -lm /usr/lib/libc.a
+endif
+endif
+endif
+
+# On AIX, we override malloc in non-pthread versions.  On AIX 4.2 or
+# above, this requires that we use the rtl-enabled version of libc.a.
+ifeq ($(OS_ARCH),AIX)
+ifneq (,$(filter-out 3.2 4.1,$(OS_RELEASE)))
+ifneq ($(USE_PTHREADS),1)
+BUILD_AIX_RTL_LIBC = 1
+AIX_RTL_LIBC	= $(OBJDIR)/libc.a
+endif
+endif
+endif
+
+ifeq ($(OS_ARCH),OS2)
+MAPFILE = $(OBJDIR)/$(LIBRARY_NAME)$(LIBRARY_VERSION).def
+ADD_TO_DEF_FILE = cat $(srcdir)/os2extra.def >> $(MAPFILE)
+GARBAGE += $(MAPFILE)
+MKSHLIB += $(MAPFILE)
+endif
+
+ifeq ($(OS_ARCH),OSF1)
+ifeq ($(USE_PTHREADS), 1)
+OS_LIBS 	= -lpthread -lrt
+endif
+ifneq ($(OS_RELEASE),V2.0)
+OS_LIBS		+= -lc_r
+endif
+endif
+
+# Linux, GNU/Hurd, and GNU/kFreeBSD systems
+ifneq (,$(filter Linux GNU%,$(OS_ARCH)))
+ifeq ($(USE_PTHREADS), 1)
+ifeq ($(OS_TARGET),Android)
+# Android has no libpthread.so in NDK
+OS_LIBS		= -ldl
+else
+OS_LIBS		= -lpthread -ldl
+endif
+else
+OS_LIBS		= -ldl
+endif
+ifneq ($(OS_TARGET),Android)
+# Android has no librt - realtime functions are in libc
+OS_LIBS		+= -lrt
+endif
+endif
+
+ifeq ($(OS_ARCH),HP-UX)
+ifeq ($(USE_PTHREADS), 1)
+ifeq (,$(filter-out B.10.10 B.10.20,$(OS_RELEASE)))
+OS_LIBS 	= -ldce
+else
+OS_LIBS 	= -lpthread -lrt
+endif
+endif
+ifeq ($(PTHREADS_USER), 1)
+OS_LIBS 	= -lpthread
+endif
+ifeq ($(basename $(OS_RELEASE)),A.09)
+OS_LIBS		+= -ldld -L/lib/pa1.1 -lm
+else
+OS_LIBS		+= -ldld -lm -lc
+endif
+ifneq ($(OS_TEST),ia64)
+ifndef USE_64
+DSO_LDOPTS	+= +I PR_HPUX10xInit
+endif
+endif
+endif
+
+ifeq ($(OS_ARCH),UNIXWARE)
+OS_LIBS		= -lsocket -lc
+endif
+
+ifeq ($(OS_ARCH),WINNT)
+ifdef NS_USE_GCC
+OS_LIBS		= -ladvapi32 -lws2_32 -lmswsock -lwinmm
+else
+OS_LIBS		= advapi32.lib ws2_32.lib mswsock.lib winmm.lib
+endif
+endif
+
+ifeq ($(OS_ARCH),WINCE)
+OS_LIBS		= ws2.lib
+endif
+
+ifeq ($(OS_TARGET),Android)
+OS_LIBS		+= -llog
+endif
+
+ifeq ($(OS_TARGET),MacOSX)
+OS_LIBS		= -framework CoreServices -framework CoreFoundation
+endif
+
+EXTRA_LIBS += $(OS_LIBS)
+
+#
+# Define platform-dependent OBJS
+#
+
+OBJS = \
+    $(OBJDIR)/prvrsion.$(OBJ_SUFFIX) \
+    io/$(OBJDIR)/prfdcach.$(OBJ_SUFFIX) \
+    io/$(OBJDIR)/prmwait.$(OBJ_SUFFIX) \
+    io/$(OBJDIR)/prmapopt.$(OBJ_SUFFIX) \
+    io/$(OBJDIR)/priometh.$(OBJ_SUFFIX) \
+    io/$(OBJDIR)/pripv6.$(OBJ_SUFFIX) \
+    io/$(OBJDIR)/prlayer.$(OBJ_SUFFIX) \
+    io/$(OBJDIR)/prlog.$(OBJ_SUFFIX) \
+    io/$(OBJDIR)/prmmap.$(OBJ_SUFFIX) \
+    io/$(OBJDIR)/prpolevt.$(OBJ_SUFFIX) \
+    io/$(OBJDIR)/prprf.$(OBJ_SUFFIX) \
+    io/$(OBJDIR)/prscanf.$(OBJ_SUFFIX) \
+    io/$(OBJDIR)/prstdio.$(OBJ_SUFFIX) \
+    threads/$(OBJDIR)/prcmon.$(OBJ_SUFFIX) \
+	threads/$(OBJDIR)/prrwlock.$(OBJ_SUFFIX) \
+	threads/$(OBJDIR)/prtpd.$(OBJ_SUFFIX) \
+    linking/$(OBJDIR)/prlink.$(OBJ_SUFFIX) \
+    malloc/$(OBJDIR)/prmalloc.$(OBJ_SUFFIX) \
+    malloc/$(OBJDIR)/prmem.$(OBJ_SUFFIX) \
+    md/$(OBJDIR)/prosdep.$(OBJ_SUFFIX) \
+    memory/$(OBJDIR)/prshm.$(OBJ_SUFFIX) \
+    memory/$(OBJDIR)/prshma.$(OBJ_SUFFIX) \
+    memory/$(OBJDIR)/prseg.$(OBJ_SUFFIX) \
+    misc/$(OBJDIR)/pralarm.$(OBJ_SUFFIX) \
+    misc/$(OBJDIR)/pratom.$(OBJ_SUFFIX) \
+    misc/$(OBJDIR)/prcountr.$(OBJ_SUFFIX) \
+    misc/$(OBJDIR)/prdtoa.$(OBJ_SUFFIX) \
+    misc/$(OBJDIR)/prenv.$(OBJ_SUFFIX) \
+    misc/$(OBJDIR)/prerr.$(OBJ_SUFFIX) \
+    misc/$(OBJDIR)/prerror.$(OBJ_SUFFIX) \
+    misc/$(OBJDIR)/prerrortable.$(OBJ_SUFFIX) \
+    misc/$(OBJDIR)/prinit.$(OBJ_SUFFIX) \
+    misc/$(OBJDIR)/prinrval.$(OBJ_SUFFIX) \
+    misc/$(OBJDIR)/pripc.$(OBJ_SUFFIX) \
+    misc/$(OBJDIR)/prlog2.$(OBJ_SUFFIX) \
+    misc/$(OBJDIR)/prlong.$(OBJ_SUFFIX) \
+    misc/$(OBJDIR)/prnetdb.$(OBJ_SUFFIX) \
+    misc/$(OBJDIR)/praton.$(OBJ_SUFFIX) \
+    misc/$(OBJDIR)/prolock.$(OBJ_SUFFIX)	 \
+    misc/$(OBJDIR)/prrng.$(OBJ_SUFFIX)	 \
+    misc/$(OBJDIR)/prsystem.$(OBJ_SUFFIX) \
+    misc/$(OBJDIR)/prthinfo.$(OBJ_SUFFIX) \
+    misc/$(OBJDIR)/prtpool.$(OBJ_SUFFIX) \
+    misc/$(OBJDIR)/prtrace.$(OBJ_SUFFIX) \
+    misc/$(OBJDIR)/prtime.$(OBJ_SUFFIX)
+
+ifdef USE_PTHREADS
+OBJS += \
+    pthreads/$(OBJDIR)/ptsynch.$(OBJ_SUFFIX) \
+    pthreads/$(OBJDIR)/ptio.$(OBJ_SUFFIX) \
+    pthreads/$(OBJDIR)/ptthread.$(OBJ_SUFFIX) \
+    pthreads/$(OBJDIR)/ptmisc.$(OBJ_SUFFIX)
+else
+OBJS += \
+    io/$(OBJDIR)/prdir.$(OBJ_SUFFIX) \
+    io/$(OBJDIR)/prfile.$(OBJ_SUFFIX) \
+    io/$(OBJDIR)/prio.$(OBJ_SUFFIX) \
+    io/$(OBJDIR)/prsocket.$(OBJ_SUFFIX) \
+    misc/$(OBJDIR)/pripcsem.$(OBJ_SUFFIX)
+
+ifndef USE_BTHREADS
+OBJS += \
+	threads/$(OBJDIR)/prcthr.$(OBJ_SUFFIX) \
+	threads/$(OBJDIR)/prdump.$(OBJ_SUFFIX) \
+	threads/$(OBJDIR)/prmon.$(OBJ_SUFFIX) \
+	threads/$(OBJDIR)/prsem.$(OBJ_SUFFIX) \
+	threads/combined/$(OBJDIR)/prucpu.$(OBJ_SUFFIX) \
+	threads/combined/$(OBJDIR)/prucv.$(OBJ_SUFFIX) \
+	threads/combined/$(OBJDIR)/prulock.$(OBJ_SUFFIX) \
+	threads/combined/$(OBJDIR)/prustack.$(OBJ_SUFFIX) \
+	threads/combined/$(OBJDIR)/pruthr.$(OBJ_SUFFIX)
+endif
+
+endif
+
+ifeq ($(USE_CPLUS), 1)
+OBJS += \
+	cplus/$(OBJDIR)/rcbase.$(OBJ_SUFFIX) \
+	cplus/$(OBJDIR)/rccv.$(OBJ_SUFFIX) \
+	cplus/$(OBJDIR)/rcfileio.$(OBJ_SUFFIX) \
+	cplus/$(OBJDIR)/rcinrval.$(OBJ_SUFFIX) \
+	cplus/$(OBJDIR)/rcio.$(OBJ_SUFFIX) \
+	cplus/$(OBJDIR)/rclock.$(OBJ_SUFFIX) \
+	cplus/$(OBJDIR)/rcnetdb.$(OBJ_SUFFIX) \
+	cplus/$(OBJDIR)/rcnetio.$(OBJ_SUFFIX) \
+	cplus/$(OBJDIR)/rcthread.$(OBJ_SUFFIX) \
+	cplus/$(OBJDIR)/rctime.$(OBJ_SUFFIX)
+endif
+
+ifeq ($(OS_ARCH), WINNT)
+RES=$(OBJDIR)/nspr.res
+RESNAME=nspr.rc
+endif # WINNT
+
+include $(srcdir)/md/$(PR_MD_ARCH_DIR)/objs.mk
+ifdef USE_BTHREADS
+include $(srcdir)/bthreads/objs.mk
+endif
+
+LIBRARY_NAME = nspr
+LIBRARY_VERSION = $(MOD_MAJOR_VERSION)
+
+RELEASE_LIBS = $(TARGETS)
+
+include $(topsrcdir)/config/rules.mk
+
+ifeq ($(BUILD_AIX_RTL_LIBC),1)
+TARGETS		+= $(AIX_RTL_LIBC)
+# XXX is this a shared library?
+endif
+
+#
+# Version information generation (begin)
+#
+ECHO = echo
+INCLUDES = -I$(dist_includedir) -I$(topsrcdir)/pr/include -I$(topsrcdir)/pr/include/private
+TINC = $(OBJDIR)/_pr_bld.h
+
+ifeq ($(OS_TARGET),OS2)
+PROD = nspr$(MOD_MAJOR_VERSION).$(DLL_SUFFIX)
+else
+PROD = $(notdir $(SHARED_LIBRARY))
+endif
+
+NOW = $(MOD_DEPTH)/config/$(OBJDIR)/now
+SH_DATE = $(shell date "+%Y-%m-%d %T")
+SH_NOW = $(shell $(NOW))
+
+ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
+	SUF = i64
+else
+	SUF = LL
+endif
+
+DEFINES		+= -D_NSPR_BUILD_
+
+GARBAGE += $(TINC)
+
+$(TINC):
+	@$(MAKE_OBJDIR)
+	@$(ECHO) '#define _BUILD_STRING "$(SH_DATE)"' > $(TINC)
+	@if test ! -z "$(SH_NOW)"; then \
+	    $(ECHO) '#define _BUILD_TIME $(SH_NOW)$(SUF)' >> $(TINC); \
+	else \
+	    true; \
+	fi
+	@$(ECHO) '#define _PRODUCTION "$(PROD)"' >> $(TINC)
+
+
+$(OBJDIR)/prvrsion.$(OBJ_SUFFIX): prvrsion.c $(TINC)
+ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
+	$(CC) -Fo$@ -c $(CFLAGS) -I$(OBJDIR) $<
+else
+	$(CC) -o $@ -c $(CFLAGS) -I$(OBJDIR) $<
+endif
+#
+# Version information generation (end)
+#
+
+
+# We use a 'build' target here to ensure that we build $(TARGETS) after
+# looping over $(DIRS) to create the object files in a parallel build.
+# Recipe commands are executed sequentially in a parallel build while
+# target dependencies are executed in parallel.
+export::
+	$(MAKE) build
+
+#
+# The Client build wants the shared libraries in $(dist_bindir)
+# so we also install them there.
+#
+
+build:: $(TARGETS)
+	$(INSTALL) -m 444 $(TARGETS) $(dist_libdir)
+ifdef SHARED_LIBRARY
+ifeq ($(OS_ARCH),HP-UX)
+	$(INSTALL) -m 755 $(SHARED_LIBRARY) $(dist_libdir)
+	$(INSTALL) -m 755 $(SHARED_LIBRARY) $(dist_bindir)
+else
+	$(INSTALL) -m 444 $(SHARED_LIBRARY) $(dist_bindir)
+endif
+endif
+
+ifeq ($(BUILD_AIX_RTL_LIBC),1)
+$(AIX_RTL_LIBC): /usr/ccs/lib/libc.a
+	rtl_enable -o $@ $<
+endif
diff --git a/pr/src/bthreads/.cvsignore b/pr/src/bthreads/.cvsignore
new file mode 100644
index 0000000..f3c7a7c
--- /dev/null
+++ b/pr/src/bthreads/.cvsignore
@@ -0,0 +1 @@
+Makefile
diff --git a/pr/src/bthreads/Makefile.in b/pr/src/bthreads/Makefile.in
new file mode 100644
index 0000000..a85e6db
--- /dev/null
+++ b/pr/src/bthreads/Makefile.in
@@ -0,0 +1,31 @@
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+#! gmake
+
+MOD_DEPTH	= ../../..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+
+include $(MOD_DEPTH)/config/autoconf.mk
+
+include $(topsrcdir)/config/config.mk
+
+include $(srcdir)/bsrcs.mk
+CSRCS += $(BTCSRCS)
+
+TARGETS	= $(OBJS)
+
+INCLUDES = -I$(dist_includedir) -I$(topsrcdir)/pr/include -I$(topsrcdir)/pr/include/private
+
+include $(topsrcdir)/config/rules.mk
+
+DEFINES		+= -D_NSPR_BUILD_
+
+export:: $(TARGETS)
+
+
diff --git a/pr/src/bthreads/bsrcs.mk b/pr/src/bthreads/bsrcs.mk
new file mode 100644
index 0000000..7083299
--- /dev/null
+++ b/pr/src/bthreads/bsrcs.mk
@@ -0,0 +1,17 @@
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# this file lists the source files to be compiled (used in Makefile) and
+# then enumerated as object files (in objs.mk) for inclusion in the NSPR
+# shared library
+
+BTCSRCS = \
+	btthread.c \
+	btlocks.c \
+	btcvar.c \
+	btmon.c \
+	btsem.c \
+	btmisc.c \
+	$(NULL)
diff --git a/pr/src/bthreads/btcvar.c b/pr/src/bthreads/btcvar.c
new file mode 100644
index 0000000..c748379
--- /dev/null
+++ b/pr/src/bthreads/btcvar.c
@@ -0,0 +1,244 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <kernel/OS.h>
+
+#include "primpl.h"
+
+/*
+** Create a new condition variable.
+**
+** 	"lock" is the lock used to protect the condition variable.
+**
+** Condition variables are synchronization objects that threads can use
+** to wait for some condition to occur.
+**
+** This may fail if memory is tight or if some operating system resource
+** is low. In such cases, a NULL will be returned.
+*/
+PR_IMPLEMENT(PRCondVar*)
+    PR_NewCondVar (PRLock *lock)
+{
+    PRCondVar *cv = PR_NEW( PRCondVar );
+    PR_ASSERT( NULL != lock );
+    if( NULL != cv )
+    {
+	cv->lock = lock;
+	cv->sem = create_sem(0, "CVSem");
+	cv->handshakeSem = create_sem(0, "CVHandshake");
+	cv->signalSem = create_sem( 0, "CVSignal");
+	cv->signalBenCount = 0;
+	cv->ns = cv->nw = 0;
+	PR_ASSERT( cv->sem >= B_NO_ERROR );
+	PR_ASSERT( cv->handshakeSem >= B_NO_ERROR );
+	PR_ASSERT( cv->signalSem >= B_NO_ERROR );
+    }
+    return cv;
+} /* PR_NewCondVar */
+
+/*
+** Destroy a condition variable. There must be no thread
+** waiting on the condvar. The caller is responsible for guaranteeing
+** that the condvar is no longer in use.
+**
+*/
+PR_IMPLEMENT(void)
+    PR_DestroyCondVar (PRCondVar *cvar)
+{
+    status_t result = delete_sem( cvar->sem );
+    PR_ASSERT( result == B_NO_ERROR );
+    
+    result = delete_sem( cvar->handshakeSem );
+    PR_ASSERT( result == B_NO_ERROR );
+
+    result = delete_sem( cvar->signalSem );
+    PR_ASSERT( result == B_NO_ERROR );
+
+    PR_DELETE( cvar );
+}
+
+/*
+** The thread that waits on a condition is blocked in a "waiting on
+** condition" state until another thread notifies the condition or a
+** caller specified amount of time expires. The lock associated with
+** the condition variable will be released, which must have be held
+** prior to the call to wait.
+**
+** Logically a notified thread is moved from the "waiting on condition"
+** state and made "ready." When scheduled, it will attempt to reacquire
+** the lock that it held when wait was called.
+**
+** The timeout has two well known values, PR_INTERVAL_NO_TIMEOUT and
+** PR_INTERVAL_NO_WAIT. The former value requires that a condition be
+** notified (or the thread interrupted) before it will resume from the
+** wait. If the timeout has a value of PR_INTERVAL_NO_WAIT, the effect
+** is to release the lock, possibly causing a rescheduling within the
+** runtime, then immediately attempting to reacquire the lock and resume.
+**
+** Any other value for timeout will cause the thread to be rescheduled
+** either due to explicit notification or an expired interval. The latter
+** must be determined by treating time as one part of the monitored data
+** being protected by the lock and tested explicitly for an expired
+** interval.
+**
+** Returns PR_FAILURE if the caller has not locked the lock associated
+** with the condition variable or the thread was interrupted (PR_Interrupt()).
+** The particular reason can be extracted with PR_GetError().
+*/
+PR_IMPLEMENT(PRStatus)
+    PR_WaitCondVar (PRCondVar *cvar, PRIntervalTime timeout)
+{
+    status_t err;
+    if( timeout == PR_INTERVAL_NO_WAIT ) 
+    {
+        PR_Unlock( cvar->lock );
+        PR_Lock( cvar->lock );
+        return PR_SUCCESS;
+    }
+
+    if( atomic_add( &cvar->signalBenCount, 1 ) > 0 ) 
+    {
+        if (acquire_sem(cvar->signalSem) == B_INTERRUPTED) 
+        {
+            atomic_add( &cvar->signalBenCount, -1 );
+            return PR_FAILURE;
+        }
+    }
+    cvar->nw += 1;
+    if( atomic_add( &cvar->signalBenCount, -1 ) > 1 ) 
+    {
+        release_sem_etc(cvar->signalSem, 1, B_DO_NOT_RESCHEDULE);
+    }
+
+    PR_Unlock( cvar->lock );
+    if( timeout==PR_INTERVAL_NO_TIMEOUT ) 
+    {
+    	err = acquire_sem(cvar->sem);
+    } 
+    else 
+    {
+    	err = acquire_sem_etc(cvar->sem, 1, B_RELATIVE_TIMEOUT, PR_IntervalToMicroseconds(timeout) );
+    }
+
+    if( atomic_add( &cvar->signalBenCount, 1 ) > 0 ) 
+    {
+        while (acquire_sem(cvar->signalSem) == B_INTERRUPTED);
+    }
+
+    if (cvar->ns > 0)
+    {
+        release_sem_etc(cvar->handshakeSem, 1, B_DO_NOT_RESCHEDULE);
+        cvar->ns -= 1;
+    }
+    cvar->nw -= 1;
+    if( atomic_add( &cvar->signalBenCount, -1 ) > 1 ) 
+    {
+        release_sem_etc(cvar->signalSem, 1, B_DO_NOT_RESCHEDULE);
+    }
+
+    PR_Lock( cvar->lock );
+    if(err!=B_NO_ERROR) 
+    {
+        return PR_FAILURE;
+    }
+    return PR_SUCCESS;
+}
+
+/*
+** Notify ONE thread that is currently waiting on 'cvar'. Which thread is
+** dependent on the implementation of the runtime. Common sense would dictate
+** that all threads waiting on a single condition have identical semantics,
+** therefore which one gets notified is not significant. 
+**
+** The calling thead must hold the lock that protects the condition, as
+** well as the invariants that are tightly bound to the condition, when
+** notify is called.
+**
+** Returns PR_FAILURE if the caller has not locked the lock associated
+** with the condition variable.
+*/
+PR_IMPLEMENT(PRStatus)
+    PR_NotifyCondVar (PRCondVar *cvar)
+{
+    status_t err ;
+    if( atomic_add( &cvar->signalBenCount, 1 ) > 0 ) 
+    {
+        if (acquire_sem(cvar->signalSem) == B_INTERRUPTED) 
+        {
+            atomic_add( &cvar->signalBenCount, -1 );
+            return PR_FAILURE;
+        }
+    }
+    if (cvar->nw > cvar->ns)
+    {
+        cvar->ns += 1;
+        release_sem_etc(cvar->sem, 1, B_DO_NOT_RESCHEDULE);
+        if( atomic_add( &cvar->signalBenCount, -1 ) > 1 ) 
+        {
+            release_sem_etc(cvar->signalSem, 1, B_DO_NOT_RESCHEDULE);
+        }
+
+        while (acquire_sem(cvar->handshakeSem) == B_INTERRUPTED) 
+        {
+            err = B_INTERRUPTED; 
+        }
+    }
+    else
+    {
+        if( atomic_add( &cvar->signalBenCount, -1 ) > 1 )
+        {
+            release_sem_etc(cvar->signalSem, 1, B_DO_NOT_RESCHEDULE);
+        }
+    }
+    return PR_SUCCESS; 
+}
+
+/*
+** Notify all of the threads waiting on the condition variable. The order
+** that the threads are notified is indeterminant. The lock that protects
+** the condition must be held.
+**
+** Returns PR_FAILURE if the caller has not locked the lock associated
+** with the condition variable.
+*/
+PR_IMPLEMENT(PRStatus)
+    PR_NotifyAllCondVar (PRCondVar *cvar)
+{
+    int32 handshakes;
+    status_t err = B_OK;
+
+    if( atomic_add( &cvar->signalBenCount, 1 ) > 0 ) 
+    {
+        if (acquire_sem(cvar->signalSem) == B_INTERRUPTED) 
+        {
+            atomic_add( &cvar->signalBenCount, -1 );
+            return PR_FAILURE;
+        }
+    }
+
+    if (cvar->nw > cvar->ns)
+    {
+        handshakes = cvar->nw - cvar->ns;
+        cvar->ns = cvar->nw;				
+        release_sem_etc(cvar->sem, handshakes, B_DO_NOT_RESCHEDULE);	
+        if( atomic_add( &cvar->signalBenCount, -1 ) > 1 ) 
+        {
+            release_sem_etc(cvar->signalSem, 1, B_DO_NOT_RESCHEDULE);
+        }
+
+        while (acquire_sem_etc(cvar->handshakeSem, handshakes, 0, 0) == B_INTERRUPTED) 
+        {
+            err = B_INTERRUPTED; 
+        }
+    }
+    else
+    {
+        if( atomic_add( &cvar->signalBenCount, -1 ) > 1 ) 
+        {
+            release_sem_etc(cvar->signalSem, 1, B_DO_NOT_RESCHEDULE);
+        }
+    }
+    return PR_SUCCESS;
+}
diff --git a/pr/src/bthreads/btlocks.c b/pr/src/bthreads/btlocks.c
new file mode 100644
index 0000000..994c09c
--- /dev/null
+++ b/pr/src/bthreads/btlocks.c
@@ -0,0 +1,91 @@
+/* -*- Mode: C++; c-basic-offset: 4 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** File:        btlocks.c
+** Description: Implemenation for thread locks using bthreads
+** Exports:     prlock.h
+*/
+
+#include "primpl.h"
+
+#include <string.h>
+#include <sys/time.h>
+
+void
+_PR_InitLocks (void)
+{
+}
+
+PR_IMPLEMENT(PRLock*)
+    PR_NewLock (void)
+{
+    PRLock *lock;
+    status_t semresult;
+
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+
+    lock = PR_NEWZAP(PRLock);
+    if (lock != NULL) {
+
+	lock->benaphoreCount = 0;
+	lock->semaphoreID = create_sem( 0, "nsprLockSem" );
+	if( lock->semaphoreID < B_NO_ERROR ) {
+
+	    PR_DELETE( lock );
+	    lock = NULL;
+	}
+    }
+
+    return lock;
+}
+
+PR_IMPLEMENT(void)
+    PR_DestroyLock (PRLock* lock)
+{
+    status_t result;
+
+    PR_ASSERT(NULL != lock);
+    result = delete_sem(lock->semaphoreID);
+    PR_ASSERT(result == B_NO_ERROR);
+    PR_DELETE(lock);
+}
+
+PR_IMPLEMENT(void)
+    PR_Lock (PRLock* lock)
+{
+    PR_ASSERT(lock != NULL);
+
+    if( atomic_add( &lock->benaphoreCount, 1 ) > 0 ) {
+
+	if( acquire_sem(lock->semaphoreID ) != B_NO_ERROR ) {
+
+	    atomic_add( &lock->benaphoreCount, -1 );
+	    return;
+	}
+    }
+
+    lock->owner = find_thread( NULL );
+}
+
+PR_IMPLEMENT(PRStatus)
+    PR_Unlock (PRLock* lock)
+{
+    PR_ASSERT(lock != NULL);
+    lock->owner = NULL;
+    if( atomic_add( &lock->benaphoreCount, -1 ) > 1 ) {
+
+	release_sem_etc( lock->semaphoreID, 1, B_DO_NOT_RESCHEDULE );
+    }
+
+    return PR_SUCCESS;
+}
+
+PR_IMPLEMENT(void)
+    PR_AssertCurrentThreadOwnsLock(PRLock *lock)
+{
+    PR_ASSERT(lock != NULL);
+    PR_ASSERT(lock->owner == find_thread( NULL ));
+}
diff --git a/pr/src/bthreads/btmisc.c b/pr/src/bthreads/btmisc.c
new file mode 100644
index 0000000..8d84a60
--- /dev/null
+++ b/pr/src/bthreads/btmisc.c
@@ -0,0 +1,72 @@
+/* -*- Mode: C++; c-basic-offset: 4 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "primpl.h"
+#include <stdio.h>
+
+// void _PR_InitCPUs(void) {PT_LOG("_PR_InitCPUs")}
+// void _MD_StartInterrupts(void) {PT_LOG("_MD_StartInterrupts")}
+
+/* this is a total hack.. */
+
+struct protoent* getprotobyname(const char* name)
+{
+    return 0;
+}
+
+struct protoent* getprotobynumber(int number)
+{
+    return 0;
+}
+
+/* this is needed by prinit for some reason */
+void
+_PR_InitStacks (void)
+{
+}
+
+/* this is needed by prinit for some reason */
+void
+_PR_InitTPD (void)
+{
+}
+
+/*
+** Create extra virtual processor threads. Generally used with MP systems.
+*/
+PR_IMPLEMENT(void)
+    PR_SetConcurrency (PRUintn numCPUs)
+{
+}
+
+/*
+** Set thread recycle mode to on (1) or off (0)
+*/
+PR_IMPLEMENT(void)
+    PR_SetThreadRecycleMode (PRUint32 flag)
+{
+}
+
+/*
+** Get context registers, return with error for now.
+*/
+
+PR_IMPLEMENT(PRWord *)
+_MD_HomeGCRegisters( PRThread *t, int isCurrent, int *np )
+{
+     return 0;
+}
+
+PR_IMPLEMENT(void *)
+PR_GetSP( PRThread *t )
+{
+    return 0;
+}
+
+PR_IMPLEMENT(PRStatus)
+PR_EnumerateThreads( PREnumerator func, void *arg )
+{
+    return PR_FAILURE;
+}
diff --git a/pr/src/bthreads/btmon.c b/pr/src/bthreads/btmon.c
new file mode 100644
index 0000000..bd05e73
--- /dev/null
+++ b/pr/src/bthreads/btmon.c
@@ -0,0 +1,201 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <kernel/OS.h>
+
+#include "primpl.h"
+
+/*
+** Create a new monitor. Monitors are re-entrant locks with a single built-in
+** condition variable.
+**
+** This may fail if memory is tight or if some operating system resource
+** is low.
+*/
+PR_IMPLEMENT(PRMonitor*)
+    PR_NewMonitor (void)
+{
+    PRMonitor *mon;
+    PRCondVar *cvar;
+    PRLock    *lock;
+
+    mon = PR_NEWZAP( PRMonitor );
+    if( mon )
+    {
+	lock = PR_NewLock();
+	if( !lock )
+        {
+	    PR_DELETE( mon );
+	    return( 0 );
+	}
+
+	cvar = PR_NewCondVar( lock );
+	if( !cvar )
+	{
+	    PR_DestroyLock( lock );
+	    PR_DELETE( mon );
+	    return( 0 );
+	}
+
+	mon->cvar = cvar;
+	mon->name = NULL;
+    }
+
+    return( mon );
+}
+
+PR_IMPLEMENT(PRMonitor*) PR_NewNamedMonitor(const char* name)
+{
+    PRMonitor* mon = PR_NewMonitor();
+    if( mon )
+    {
+        mon->name = name;
+    }
+    return mon;
+}
+
+/*
+** Destroy a monitor. The caller is responsible for guaranteeing that the
+** monitor is no longer in use. There must be no thread waiting on the
+** monitor's condition variable and that the lock is not held.
+**
+*/
+PR_IMPLEMENT(void)
+    PR_DestroyMonitor (PRMonitor *mon)
+{
+    PR_DestroyLock( mon->cvar->lock );
+    PR_DestroyCondVar( mon->cvar );
+    PR_DELETE( mon );
+}
+
+/*
+** Enter the lock associated with the monitor. If the calling thread currently
+** is in the monitor, the call to enter will silently succeed. In either case,
+** it will increment the entry count by one.
+*/
+PR_IMPLEMENT(void)
+    PR_EnterMonitor (PRMonitor *mon)
+{
+    if( mon->cvar->lock->owner == find_thread( NULL ) )
+    {
+	mon->entryCount++;
+
+    } else
+    {
+	PR_Lock( mon->cvar->lock );
+	mon->entryCount = 1;
+    }
+}
+
+/*
+** Decrement the entry count associated with the monitor. If the decremented
+** entry count is zero, the monitor is exited. Returns PR_FAILURE if the
+** calling thread has not entered the monitor.
+*/
+PR_IMPLEMENT(PRStatus)
+    PR_ExitMonitor (PRMonitor *mon)
+{
+    if( mon->cvar->lock->owner != find_thread( NULL ) )
+    {
+	return( PR_FAILURE );
+    }
+    if( --mon->entryCount == 0 )
+    {
+	return( PR_Unlock( mon->cvar->lock ) );
+    }
+    return( PR_SUCCESS );
+}
+
+/*
+** Wait for a notify on the monitor's condition variable. Sleep for "ticks"
+** amount of time (if "ticks" is PR_INTERVAL_NO_TIMEOUT then the sleep is
+** indefinite).
+**
+** While the thread is waiting it exits the monitor (as if it called
+** PR_ExitMonitor as many times as it had called PR_EnterMonitor).  When
+** the wait has finished the thread regains control of the monitors lock
+** with the same entry count as before the wait began.
+**
+** The thread waiting on the monitor will be resumed when the monitor is
+** notified (assuming the thread is the next in line to receive the
+** notify) or when the "ticks" timeout elapses.
+**
+** Returns PR_FAILURE if the caller has not entered the monitor.
+*/
+PR_IMPLEMENT(PRStatus)
+    PR_Wait (PRMonitor *mon, PRIntervalTime ticks)
+{
+    PRUint32 entryCount;
+    PRUintn  status;
+    PRThread *meThread;
+    thread_id me = find_thread( NULL );
+    meThread = PR_GetCurrentThread();
+
+    if( mon->cvar->lock->owner != me ) return( PR_FAILURE );
+
+    entryCount = mon->entryCount;
+    mon->entryCount = 0;
+
+    status = PR_WaitCondVar( mon->cvar, ticks );
+
+    mon->entryCount = entryCount;
+
+    return( status );
+}
+
+/*
+** Notify a thread waiting on the monitor's condition variable. If a thread
+** is waiting on the condition variable (using PR_Wait) then it is awakened
+** and attempts to reenter the monitor.
+*/
+PR_IMPLEMENT(PRStatus)
+    PR_Notify (PRMonitor *mon)
+{
+    if( mon->cvar->lock->owner != find_thread( NULL ) )
+    {
+	return( PR_FAILURE );
+    }
+
+    PR_NotifyCondVar( mon->cvar );
+    return( PR_SUCCESS );
+}
+
+/*
+** Notify all of the threads waiting on the monitor's condition variable.
+** All of threads waiting on the condition are scheduled to reenter the
+** monitor.
+*/
+PR_IMPLEMENT(PRStatus)
+    PR_NotifyAll (PRMonitor *mon)
+{
+    if( mon->cvar->lock->owner != find_thread( NULL ) )
+    {
+	return( PR_FAILURE );
+    }
+
+    PR_NotifyAllCondVar( mon->cvar );
+    return( PR_SUCCESS );
+}
+
+/*
+** Return the number of times that the current thread has entered the
+** lock. Returns zero if the current thread has not entered the lock.
+*/
+PR_IMPLEMENT(PRIntn)
+    PR_GetMonitorEntryCount(PRMonitor *mon)
+{
+    return( (mon->cvar->lock->owner == find_thread( NULL )) ?
+            mon->entryCount : 0 );
+}
+
+/*
+** If the current thread is in |mon|, this assertion is guaranteed to
+** succeed.  Otherwise, the behavior of this function is undefined.
+*/
+PR_IMPLEMENT(void)
+    PR_AssertCurrentThreadInMonitor(PRMonitor *mon)
+{
+    PR_ASSERT_CURRENT_THREAD_OWNS_LOCK(mon->cvar->lock);
+}
diff --git a/pr/src/bthreads/btsem.c b/pr/src/bthreads/btsem.c
new file mode 100644
index 0000000..011ee6b
--- /dev/null
+++ b/pr/src/bthreads/btsem.c
@@ -0,0 +1,98 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <kernel/OS.h>
+
+#include "primpl.h"
+
+/*
+** Create a new semaphore object.
+*/
+PR_IMPLEMENT(PRSemaphore*)
+    PR_NewSem (PRUintn value)
+{
+	PRSemaphore *semaphore;
+
+	if (!_pr_initialized) _PR_ImplicitInitialization();
+
+	semaphore = PR_NEWZAP(PRSemaphore);
+	if (NULL != semaphore) {
+		if ((semaphore->sem = create_sem(value, "nspr_sem")) < B_NO_ERROR)
+			return NULL;
+		else 
+			return semaphore;
+	}
+	return NULL;
+}
+
+/*
+** Destroy the given semaphore object.
+**
+*/
+PR_IMPLEMENT(void)
+    PR_DestroySem (PRSemaphore *sem)
+{
+	status_t result;
+
+	PR_ASSERT(sem != NULL);
+	result = delete_sem(sem->sem);
+	PR_ASSERT(result == B_NO_ERROR);
+	PR_DELETE(sem);
+} 
+
+/*
+** Wait on a Semaphore.
+** 
+** This routine allows a calling thread to wait or proceed depending upon
+** the state of the semahore sem. The thread can proceed only if the
+** counter value of the semaphore sem is currently greater than 0. If the
+** value of semaphore sem is positive, it is decremented by one and the
+** routine returns immediately allowing the calling thread to continue. If
+** the value of semaphore sem is 0, the calling thread blocks awaiting the
+** semaphore to be released by another thread.
+** 
+** This routine can return PR_PENDING_INTERRUPT if the waiting thread 
+** has been interrupted.
+*/
+PR_IMPLEMENT(PRStatus)
+    PR_WaitSem (PRSemaphore *sem)
+{
+	PR_ASSERT(sem != NULL);
+	if (acquire_sem(sem->sem) == B_NO_ERROR)
+		return PR_SUCCESS;
+	else
+		return PR_FAILURE;
+}
+
+/*
+** This routine increments the counter value of the semaphore. If other
+** threads are blocked for the semaphore, then the scheduler will
+** determine which ONE thread will be unblocked.
+*/
+PR_IMPLEMENT(void)
+    PR_PostSem (PRSemaphore *sem)
+{
+	status_t result;
+
+	PR_ASSERT(sem != NULL);
+	result = release_sem_etc(sem->sem, 1, B_DO_NOT_RESCHEDULE);
+	PR_ASSERT(result == B_NO_ERROR);
+}
+
+/*
+** Returns the value of the semaphore referenced by sem without affecting
+** the state of the semaphore.  The value represents the semaphore value
+** at the time of the call, but may not be the actual value when the
+** caller inspects it.
+*/
+PR_IMPLEMENT(PRUintn)
+    PR_GetValueSem (PRSemaphore *sem)
+{
+	sem_info	info;
+
+	PR_ASSERT(sem != NULL);
+	get_sem_info(sem->sem, &info);
+	return info.count;
+}
diff --git a/pr/src/bthreads/btthread.c b/pr/src/bthreads/btthread.c
new file mode 100644
index 0000000..c2a1cd8
--- /dev/null
+++ b/pr/src/bthreads/btthread.c
@@ -0,0 +1,662 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <kernel/OS.h>
+#include <support/TLS.h>
+
+#include "prlog.h"
+#include "primpl.h"
+#include "prcvar.h"
+#include "prpdce.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <signal.h>
+
+/* values for PRThread.state */
+#define BT_THREAD_PRIMORD   0x01    /* this is the primordial thread */
+#define BT_THREAD_SYSTEM    0x02    /* this is a system thread */
+#define BT_THREAD_JOINABLE  0x04	/* this is a joinable thread */
+
+struct _BT_Bookeeping
+{
+    PRLock *ml;                 /* a lock to protect ourselves */
+	sem_id cleanUpSem;		/* the primoridal thread will block on this
+							   sem while waiting for the user threads */
+    PRInt32 threadCount;	/* user thred count */
+
+} bt_book = { NULL, B_ERROR, 0 };
+
+
+#define BT_TPD_LIMIT 128	/* number of TPD slots we'll provide (arbitrary) */
+
+/* these will be used to map an index returned by PR_NewThreadPrivateIndex()
+   to the corresponding beos native TLS slot number, and to the destructor
+   for that slot - note that, because it is allocated globally, this data
+   will be automatically zeroed for us when the program begins */
+static int32 tpd_beosTLSSlots[BT_TPD_LIMIT];
+static PRThreadPrivateDTOR tpd_dtors[BT_TPD_LIMIT];
+
+static vint32 tpd_slotsUsed=0;	/* number of currently-allocated TPD slots */
+static int32 tls_prThreadSlot;	/* TLS slot in which PRThread will be stored */
+
+/* this mutex will be used to synchronize access to every
+   PRThread.md.joinSem and PRThread.md.is_joining (we could
+   actually allocate one per thread, but that seems a bit excessive,
+   especially considering that there will probably be little
+   contention, PR_JoinThread() is allowed to block anyway, and the code
+   protected by the mutex is short/fast) */
+static PRLock *joinSemLock;
+
+static PRUint32 _bt_MapNSPRToNativePriority( PRThreadPriority priority );
+static PRThreadPriority _bt_MapNativeToNSPRPriority( PRUint32 priority );
+static void _bt_CleanupThread(void *arg);
+static PRThread *_bt_AttachThread();
+
+void
+_PR_InitThreads (PRThreadType type, PRThreadPriority priority,
+                 PRUintn maxPTDs)
+{
+    PRThread *primordialThread;
+    PRUint32  beThreadPriority;
+
+	/* allocate joinSem mutex */
+	joinSemLock = PR_NewLock();
+	if (joinSemLock == NULL)
+	{
+		PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+		return;
+    }
+
+    /*
+    ** Create and initialize NSPR structure for our primordial thread.
+    */
+    
+    primordialThread = PR_NEWZAP(PRThread);
+    if( NULL == primordialThread )
+    {
+        PR_SetError( PR_OUT_OF_MEMORY_ERROR, 0 );
+        return;
+    }
+
+	primordialThread->md.joinSem = B_ERROR;
+
+    /*
+    ** Set the priority to the desired level.
+    */
+
+    beThreadPriority = _bt_MapNSPRToNativePriority( priority );
+    
+    set_thread_priority( find_thread( NULL ), beThreadPriority );
+    
+    primordialThread->priority = priority;
+
+
+	/* set the thread's state - note that the thread is not joinable */
+    primordialThread->state |= BT_THREAD_PRIMORD;
+	if (type == PR_SYSTEM_THREAD)
+		primordialThread->state |= BT_THREAD_SYSTEM;
+
+    /*
+    ** Allocate a TLS slot for the PRThread structure (just using
+    ** native TLS, as opposed to NSPR TPD, will make PR_GetCurrentThread()
+    ** somewhat faster, and will leave one more TPD slot for our client)
+    */
+	
+	tls_prThreadSlot = tls_allocate();
+
+    /*
+    ** Stuff our new PRThread structure into our thread specific
+    ** slot.
+    */
+
+	tls_set(tls_prThreadSlot, primordialThread);
+    
+	/* allocate lock for bt_book */
+    bt_book.ml = PR_NewLock();
+    if( NULL == bt_book.ml )
+    {
+    	PR_SetError( PR_OUT_OF_MEMORY_ERROR, 0 );
+	return;
+    }
+}
+
+PRUint32
+_bt_MapNSPRToNativePriority( PRThreadPriority priority )
+    {
+    switch( priority )
+    {
+    	case PR_PRIORITY_LOW:	 return( B_LOW_PRIORITY );
+	case PR_PRIORITY_NORMAL: return( B_NORMAL_PRIORITY );
+	case PR_PRIORITY_HIGH:	 return( B_DISPLAY_PRIORITY );
+	case PR_PRIORITY_URGENT: return( B_URGENT_DISPLAY_PRIORITY );
+	default:		 return( B_NORMAL_PRIORITY );
+    }
+}
+
+PRThreadPriority
+_bt_MapNativeToNSPRPriority(PRUint32 priority)
+    {
+	if (priority < B_NORMAL_PRIORITY)
+		return PR_PRIORITY_LOW;
+	if (priority < B_DISPLAY_PRIORITY)
+		return PR_PRIORITY_NORMAL;
+	if (priority < B_URGENT_DISPLAY_PRIORITY)
+		return PR_PRIORITY_HIGH;
+	return PR_PRIORITY_URGENT;
+}
+
+PRUint32
+_bt_mapNativeToNSPRPriority( int32 priority )
+{
+    switch( priority )
+    {
+    	case PR_PRIORITY_LOW:	 return( B_LOW_PRIORITY );
+	case PR_PRIORITY_NORMAL: return( B_NORMAL_PRIORITY );
+	case PR_PRIORITY_HIGH:	 return( B_DISPLAY_PRIORITY );
+	case PR_PRIORITY_URGENT: return( B_URGENT_DISPLAY_PRIORITY );
+	default:		 return( B_NORMAL_PRIORITY );
+    }
+}
+
+/* This method is called by all NSPR threads as they exit */
+void _bt_CleanupThread(void *arg)
+{
+	PRThread *me = PR_GetCurrentThread();
+	int32 i;
+
+	/* first, clean up all thread-private data */
+	for (i = 0; i < tpd_slotsUsed; i++)
+	{
+		void *oldValue = tls_get(tpd_beosTLSSlots[i]);
+		if ( oldValue != NULL && tpd_dtors[i] != NULL )
+			(*tpd_dtors[i])(oldValue);
+	}
+
+	/* if this thread is joinable, wait for someone to join it */
+	if (me->state & BT_THREAD_JOINABLE)
+	{
+		/* protect access to our joinSem */
+		PR_Lock(joinSemLock);
+
+		if (me->md.is_joining)
+		{
+			/* someone is already waiting to join us (they've
+			   allocated a joinSem for us) - let them know we're
+			   ready */
+			delete_sem(me->md.joinSem);
+
+			PR_Unlock(joinSemLock);
+
+		}
+		else
+    {
+			/* noone is currently waiting for our demise - it
+			   is our responsibility to allocate the joinSem
+			   and block on it */
+			me->md.joinSem = create_sem(0, "join sem");
+
+			/* we're done accessing our joinSem */
+			PR_Unlock(joinSemLock);
+
+			/* wait for someone to join us */
+			while (acquire_sem(me->md.joinSem) == B_INTERRUPTED);
+	    }
+	}
+
+	/* if this is a user thread, we must update our books */
+	if ((me->state & BT_THREAD_SYSTEM) == 0)
+	{
+		/* synchronize access to bt_book */
+    PR_Lock( bt_book.ml );
+
+		/* decrement the number of currently-alive user threads */
+	bt_book.threadCount--;
+
+		if (bt_book.threadCount == 0 && bt_book.cleanUpSem != B_ERROR) {
+			/* we are the last user thread, and the primordial thread is
+			   blocked in PR_Cleanup() waiting for us to finish - notify
+			   it */
+			delete_sem(bt_book.cleanUpSem);
+	}
+
+    PR_Unlock( bt_book.ml );
+	}
+
+	/* finally, delete this thread's PRThread */
+	PR_DELETE(me);
+}
+
+/**
+ * This is a wrapper that all threads invoke that allows us to set some
+ * things up prior to a thread's invocation and clean up after a thread has
+ * exited.
+ */
+static void*
+_bt_root (void* arg)
+	{
+    PRThread *thred = (PRThread*)arg;
+    PRIntn rv;
+    void *privData;
+    status_t result;
+    int i;
+
+	/* save our PRThread object into our TLS */
+	tls_set(tls_prThreadSlot, thred);
+
+    thred->startFunc(thred->arg);  /* run the dang thing */
+
+	/* clean up */
+	_bt_CleanupThread(NULL);
+
+	return 0;
+}
+
+PR_IMPLEMENT(PRThread*)
+    PR_CreateThread (PRThreadType type, void (*start)(void* arg), void* arg,
+                     PRThreadPriority priority, PRThreadScope scope,
+                     PRThreadState state, PRUint32 stackSize)
+{
+    PRUint32 bePriority;
+
+    PRThread* thred;
+
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+
+	thred = PR_NEWZAP(PRThread);
+ 	if (thred == NULL)
+	{
+        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+        return NULL;
+    }
+
+    thred->md.joinSem = B_ERROR;
+
+        thred->arg = arg;
+        thred->startFunc = start;
+        thred->priority = priority;
+
+	if( state == PR_JOINABLE_THREAD )
+	{
+	    thred->state |= BT_THREAD_JOINABLE;
+	}
+
+        /* keep some books */
+
+	PR_Lock( bt_book.ml );
+
+	if (type == PR_USER_THREAD)
+	{
+	    bt_book.threadCount++;
+        }
+
+	PR_Unlock( bt_book.ml );
+
+	bePriority = _bt_MapNSPRToNativePriority( priority );
+
+        thred->md.tid = spawn_thread((thread_func)_bt_root, "moz-thread",
+                                     bePriority, thred);
+        if (thred->md.tid < B_OK) {
+            PR_SetError(PR_UNKNOWN_ERROR, thred->md.tid);
+            PR_DELETE(thred);
+			return NULL;
+        }
+
+        if (resume_thread(thred->md.tid) < B_OK) {
+            PR_SetError(PR_UNKNOWN_ERROR, 0);
+            PR_DELETE(thred);
+			return NULL;
+        }
+
+    return thred;
+    }
+
+PR_IMPLEMENT(PRThread*)
+	PR_AttachThread(PRThreadType type, PRThreadPriority priority,
+					PRThreadStack *stack)
+{
+	/* PR_GetCurrentThread() will attach a thread if necessary */
+	return PR_GetCurrentThread();
+}
+
+PR_IMPLEMENT(void)
+	PR_DetachThread()
+{
+	/* we don't support detaching */
+}
+
+PR_IMPLEMENT(PRStatus)
+    PR_JoinThread (PRThread* thred)
+{
+    status_t eval, status;
+
+    PR_ASSERT(thred != NULL);
+
+	if ((thred->state & BT_THREAD_JOINABLE) == 0)
+    {
+	PR_SetError( PR_INVALID_ARGUMENT_ERROR, 0 );
+	return( PR_FAILURE );
+    }
+
+	/* synchronize access to the thread's joinSem */
+	PR_Lock(joinSemLock);
+	
+	if (thred->md.is_joining)
+	{
+		/* another thread is already waiting to join the specified
+		   thread - we must fail */
+		PR_Unlock(joinSemLock);
+		return PR_FAILURE;
+	}
+
+	/* let others know we are waiting to join */
+	thred->md.is_joining = PR_TRUE;
+
+	if (thred->md.joinSem == B_ERROR)
+	{
+		/* the thread hasn't finished yet - it is our responsibility to
+		   allocate a joinSem and wait on it */
+		thred->md.joinSem = create_sem(0, "join sem");
+
+		/* we're done changing the joinSem now */
+		PR_Unlock(joinSemLock);
+
+		/* wait for the thread to finish */
+		while (acquire_sem(thred->md.joinSem) == B_INTERRUPTED);
+
+	}
+	else
+	{
+		/* the thread has already finished, and has allocated the
+		   joinSem itself - let it know it can finally die */
+		delete_sem(thred->md.joinSem);
+		
+		PR_Unlock(joinSemLock);
+    }
+
+	/* make sure the thread is dead */
+    wait_for_thread(thred->md.tid, &eval);
+
+    return PR_SUCCESS;
+}
+
+PR_IMPLEMENT(PRThread*)
+    PR_GetCurrentThread ()
+{
+    PRThread* thred;
+
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+
+    thred = (PRThread *)tls_get( tls_prThreadSlot);
+	if (thred == NULL)
+	{
+		/* this thread doesn't have a PRThread structure (it must be
+		   a native thread not created by the NSPR) - assimilate it */
+		thred = _bt_AttachThread();
+	}
+    PR_ASSERT(NULL != thred);
+
+    return thred;
+}
+
+PR_IMPLEMENT(PRThreadScope)
+    PR_GetThreadScope (const PRThread* thred)
+{
+    PR_ASSERT(thred != NULL);
+    return PR_GLOBAL_THREAD;
+}
+
+PR_IMPLEMENT(PRThreadType)
+    PR_GetThreadType (const PRThread* thred)
+{
+    PR_ASSERT(thred != NULL);
+    return (thred->state & BT_THREAD_SYSTEM) ?
+        PR_SYSTEM_THREAD : PR_USER_THREAD;
+}
+
+PR_IMPLEMENT(PRThreadState)
+    PR_GetThreadState (const PRThread* thred)
+{
+    PR_ASSERT(thred != NULL);
+    return (thred->state & BT_THREAD_JOINABLE)?
+    					PR_JOINABLE_THREAD: PR_UNJOINABLE_THREAD;
+}
+
+PR_IMPLEMENT(PRThreadPriority)
+    PR_GetThreadPriority (const PRThread* thred)
+{
+    PR_ASSERT(thred != NULL);
+    return thred->priority;
+}  /* PR_GetThreadPriority */
+
+PR_IMPLEMENT(void) PR_SetThreadPriority(PRThread *thred,
+                                        PRThreadPriority newPri)
+{
+    PRUint32 bePriority;
+
+    PR_ASSERT( thred != NULL );
+
+    thred->priority = newPri;
+    bePriority = _bt_MapNSPRToNativePriority( newPri );
+    set_thread_priority( thred->md.tid, bePriority );
+}
+
+PR_IMPLEMENT(PRStatus)
+    PR_NewThreadPrivateIndex (PRUintn* newIndex,
+                              PRThreadPrivateDTOR destructor)
+{
+	int32    index;
+
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+
+	/* reserve the next available tpd slot */
+	index = atomic_add( &tpd_slotsUsed, 1 );
+	if (index >= BT_TPD_LIMIT)
+	{
+		/* no slots left - decrement value, then fail */
+		atomic_add( &tpd_slotsUsed, -1 );
+		PR_SetError( PR_TPD_RANGE_ERROR, 0 );
+	    return( PR_FAILURE );
+	}
+
+	/* allocate a beos-native TLS slot for this index (the new slot
+	   automatically contains NULL) */
+	tpd_beosTLSSlots[index] = tls_allocate();
+
+	/* remember the destructor */
+	tpd_dtors[index] = destructor;
+
+    *newIndex = (PRUintn)index;
+
+    return( PR_SUCCESS );
+}
+
+PR_IMPLEMENT(PRStatus)
+    PR_SetThreadPrivate (PRUintn index, void* priv)
+{
+	void *oldValue;
+
+    /*
+    ** Sanity checking
+    */
+
+    if(index < 0 || index >= tpd_slotsUsed || index >= BT_TPD_LIMIT)
+    {
+		PR_SetError( PR_TPD_RANGE_ERROR, 0 );
+	return( PR_FAILURE );
+    }
+
+	/* if the old value isn't NULL, and the dtor for this slot isn't
+	   NULL, we must destroy the data */
+	oldValue = tls_get(tpd_beosTLSSlots[index]);
+	if (oldValue != NULL && tpd_dtors[index] != NULL)
+		(*tpd_dtors[index])(oldValue);
+
+	/* save new value */
+	tls_set(tpd_beosTLSSlots[index], priv);
+
+	    return( PR_SUCCESS );
+	}
+
+PR_IMPLEMENT(void*)
+    PR_GetThreadPrivate (PRUintn index)
+{
+	/* make sure the index is valid */
+	if (index < 0 || index >= tpd_slotsUsed || index >= BT_TPD_LIMIT)
+    {   
+		PR_SetError( PR_TPD_RANGE_ERROR, 0 );
+		return NULL;
+    }
+
+	/* return the value */
+	return tls_get( tpd_beosTLSSlots[index] );
+	}
+
+
+PR_IMPLEMENT(PRStatus)
+    PR_Interrupt (PRThread* thred)
+{
+    PRIntn rv;
+
+    PR_ASSERT(thred != NULL);
+
+    /*
+    ** there seems to be a bug in beos R5 in which calling
+    ** resume_thread() on a blocked thread returns B_OK instead
+    ** of B_BAD_THREAD_STATE (beos bug #20000422-19095).  as such,
+    ** to interrupt a thread, we will simply suspend then resume it
+    ** (no longer call resume_thread(), check for B_BAD_THREAD_STATE,
+    ** the suspend/resume to wake up a blocked thread).  this wakes
+    ** up blocked threads properly, and doesn't hurt unblocked threads
+    ** (they simply get stopped then re-started immediately)
+    */
+
+    rv = suspend_thread( thred->md.tid );
+    if( rv != B_NO_ERROR )
+    {
+        /* this doesn't appear to be a valid thread_id */
+        PR_SetError( PR_UNKNOWN_ERROR, rv );
+        return PR_FAILURE;
+    }
+
+    rv = resume_thread( thred->md.tid );
+    if( rv != B_NO_ERROR )
+    {
+        PR_SetError( PR_UNKNOWN_ERROR, rv );
+        return PR_FAILURE;
+    }
+
+    return PR_SUCCESS;
+}
+
+PR_IMPLEMENT(void)
+    PR_ClearInterrupt ()
+{
+}
+
+PR_IMPLEMENT(PRStatus)
+    PR_Yield ()
+{
+    /* we just sleep for long enough to cause a reschedule (100
+       microseconds) */
+    snooze(100);
+}
+
+#define BT_MILLION 1000000UL
+
+PR_IMPLEMENT(PRStatus)
+    PR_Sleep (PRIntervalTime ticks)
+{
+    bigtime_t tps;
+    status_t status;
+
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+
+    tps = PR_IntervalToMicroseconds( ticks );
+
+    status = snooze(tps);
+    if (status == B_NO_ERROR) return PR_SUCCESS;
+
+    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, status);
+    return PR_FAILURE;
+}
+
+PR_IMPLEMENT(PRStatus)
+    PR_Cleanup ()
+{
+    PRThread *me = PR_GetCurrentThread();
+
+    PR_ASSERT(me->state & BT_THREAD_PRIMORD);
+    if ((me->state & BT_THREAD_PRIMORD) == 0) {
+        return PR_FAILURE;
+    }
+
+    PR_Lock( bt_book.ml );
+
+	if (bt_book.threadCount != 0)
+    {
+		/* we'll have to wait for some threads to finish - create a
+		   sem to block on */
+		bt_book.cleanUpSem = create_sem(0, "cleanup sem");
+    }
+
+    PR_Unlock( bt_book.ml );
+
+	/* note that, if all the user threads were already dead, we
+	   wouldn't have created a sem above, so this acquire_sem()
+	   will fail immediately */
+	while (acquire_sem(bt_book.cleanUpSem) == B_INTERRUPTED);
+
+    return PR_SUCCESS;
+}
+
+PR_IMPLEMENT(void)
+    PR_ProcessExit (PRIntn status)
+{
+    exit(status);
+}
+
+PRThread *_bt_AttachThread()
+{
+	PRThread *thread;
+	thread_info tInfo;
+
+	/* make sure this thread doesn't already have a PRThread structure */
+	PR_ASSERT(tls_get(tls_prThreadSlot) == NULL);
+
+	/* allocate a PRThread structure for this thread */
+	thread = PR_NEWZAP(PRThread);
+	if (thread == NULL)
+	{
+		PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+		return NULL;
+	}
+
+	/* get the native thread's current state */
+	get_thread_info(find_thread(NULL), &tInfo);
+
+	/* initialize new PRThread */
+	thread->md.tid = tInfo.thread;
+	thread->md.joinSem = B_ERROR;
+	thread->priority = _bt_MapNativeToNSPRPriority(tInfo.priority);
+
+	/* attached threads are always non-joinable user threads */
+	thread->state = 0;
+
+	/* increment user thread count */
+	PR_Lock(bt_book.ml);
+	bt_book.threadCount++;
+	PR_Unlock(bt_book.ml);
+
+	/* store this thread's PRThread */
+	tls_set(tls_prThreadSlot, thread);
+	
+	/* the thread must call _bt_CleanupThread() before it dies, in order
+	   to clean up its PRThread, synchronize with the primordial thread,
+	   etc. */
+	on_exit_thread(_bt_CleanupThread, NULL);
+	
+	return thread;
+}
diff --git a/pr/src/bthreads/objs.mk b/pr/src/bthreads/objs.mk
new file mode 100644
index 0000000..b273ba4
--- /dev/null
+++ b/pr/src/bthreads/objs.mk
@@ -0,0 +1,11 @@
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# This makefile appends to the variable OBJS the bthread object modules
+# that will be part of the nspr20 library.
+
+include $(srcdir)/bthreads/bsrcs.mk
+
+OBJS += $(BTCSRCS:%.c=bthreads/$(OBJDIR)/%.$(OBJ_SUFFIX))
diff --git a/pr/src/cplus/.cvsignore b/pr/src/cplus/.cvsignore
new file mode 100644
index 0000000..f3c7a7c
--- /dev/null
+++ b/pr/src/cplus/.cvsignore
@@ -0,0 +1 @@
+Makefile
diff --git a/pr/src/cplus/Makefile.in b/pr/src/cplus/Makefile.in
new file mode 100644
index 0000000..ec08eab
--- /dev/null
+++ b/pr/src/cplus/Makefile.in
@@ -0,0 +1,43 @@
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#! gmake
+
+MOD_DEPTH	= ../../..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+
+include $(MOD_DEPTH)/config/autoconf.mk
+
+include $(topsrcdir)/config/config.mk
+
+CXXSRCS =           \
+	rcbase.cpp      \
+	rccv.cpp		\
+	rcfileio.cpp    \
+	rcinrval.cpp	\
+	rcio.cpp	    \
+	rclock.cpp	    \
+	rcnetdb.cpp	    \
+	rcnetio.cpp	    \
+	rcthread.cpp	\
+	rctime.cpp      \
+	$(NULL)
+
+OBJS = $(addprefix $(OBJDIR)/,$(CXXSRCS:.cpp=.$(OBJ_SUFFIX)))
+
+TARGETS	= $(OBJS)
+
+INCLUDES = -I$(dist_includedir)
+
+DEFINES	+= -D_NSPR_BUILD_
+
+include $(topsrcdir)/config/rules.mk
+
+HEADERS = $(wildcard $(srcdir)/*.h)
+
+export:: $(TARGETS)
+
diff --git a/pr/src/cplus/rcascii.h b/pr/src/cplus/rcascii.h
new file mode 100644
index 0000000..7383d8d
--- /dev/null
+++ b/pr/src/cplus/rcascii.h
@@ -0,0 +1,143 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** Class definitions to format ASCII data.
+*/
+
+#if defined(_RCASCII_H)
+#else
+#define _RCASCII_H
+
+/*
+** RCFormatStuff
+**  This class maintains no state - that is the responsibility of
+**  the class' client. For each call to Sx_printf(), the StuffFunction
+**  will be called for each embedded "%" in the 'fmt' string and once
+**  for each interveaning literal.
+*/
+class PR_IMPLEMENT(RCFormatStuff)
+{
+public:
+    RCFormatStuff();
+    virtual ~RCFormatStuff();
+
+    /*
+    ** Process the arbitrary argument list using as indicated by
+    ** the 'fmt' string. Each segment of the processing the stuff
+    ** function is called with the relavent translation.
+    */
+    virtual PRInt32 Sx_printf(void *state, const char *fmt, ...);
+
+    /*
+    ** The 'state' argument is not processed by the runtime. It
+    ** is merely passed from the Sx_printf() call. It is intended
+    ** to be used by the client to figure out what to do with the
+    ** new string.
+    **
+    ** The new string ('stuff') is ASCII translation driven by the
+    ** Sx_printf()'s 'fmt' string. It is not guaranteed to be a null
+    ** terminated string.
+    **
+    ** The return value is the number of bytes copied from the 'stuff'
+    ** string. It is accumulated for each of the calls to the stuff
+    ** function and returned from the original caller of Sx_printf().
+    */
+    virtual PRSize StuffFunction(
+        void *state, const char *stuff, PRSize stufflen) = 0;
+};  /* RCFormatStuff */
+
+
+/*
+** RCFormatBuffer
+**  The caller is supplying the buffer, the runtime is doing all
+**  the conversion. The object contains no state, so is reusable
+**  and reentrant.
+*/
+class PR_IMPLEMENT(RCFormatBuffer): public RCFormatStuff
+{
+public:
+    RCFormatBuffer();
+    virtual ~RCFormatBuffer();
+
+    /*
+    ** Format the trailing arguments as indicated by the 'fmt'
+    ** string. Put the result in 'buffer'. Return the number
+    ** of bytes moved into 'buffer'. 'buffer' will always be
+    ** a properly terminated string even if the convresion fails.
+    */
+    virtual PRSize Sn_printf(
+        char *buffer, PRSize length, const char *fmt, ...);
+
+    virtual char *Sm_append(char *buffer, const char *fmt, ...);
+
+private:
+    /*
+    ** This class overrides the stuff function, does not preserve
+    ** its virtual-ness and no longer allows the clients to call
+    ** it in the clear. In other words, it is now the implementation
+    ** for this class.
+    */
+    PRSize StuffFunction(void*, const char*, PRSize);
+        
+};  /* RCFormatBuffer */
+
+/*
+** RCFormat
+**  The runtime is supplying the buffer. The object has state - the
+**  buffer. Each operation must run to completion before the object
+**  can be reused. When it is, the buffer is reset (whatever that
+**  means). The result of a conversion is available via the extractor.
+**  After extracted, the memory still belongs to the class - if the
+**  caller wants to retain or modify, it must first be copied.
+*/
+class PR_IMPLEMENT(RCFormat): pubic RCFormatBuffer
+{
+public:
+    RCFormat();
+    virtual ~RCFormat();
+
+    /*
+    ** Translate the trailing arguments according to the 'fmt'
+    ** string and store the results in the object.
+    */
+    virtual PRSize Sm_printf(const char *fmt, ...);
+
+    /*
+    ** Extract the latest translation.
+    ** The object does not surrender the memory occupied by
+    ** the string. If the caller wishes to modify the data,
+    ** it must first be copied.
+    */
+    const char*();
+
+private:
+    char *buffer;
+
+    RCFormat(const RCFormat&);
+    RCFormat& operator=(const RCFormat&);
+}; /* RCFormat */
+
+/*
+** RCPrint
+**  The output is formatted and then written to an associated file
+**  descriptor. The client can provide a suitable file descriptor
+**  or can indicate that the output should be directed to one of
+**  the well-known "console" devices.
+*/
+class PR_IMPLEMENT(RCPrint): public RCFormat
+{
+    virtual ~RCPrint();
+    RCPrint(RCIO* output);
+    RCPrint(RCFileIO::SpecialFile output);
+
+    virtual PRSize Printf(const char *fmt, ...);
+private:
+    RCPrint();
+};  /* RCPrint */
+
+#endif /* defined(_RCASCII_H) */
+
+/* RCAscii.h */
diff --git a/pr/src/cplus/rcbase.cpp b/pr/src/cplus/rcbase.cpp
new file mode 100644
index 0000000..c258081
--- /dev/null
+++ b/pr/src/cplus/rcbase.cpp
@@ -0,0 +1,23 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** RCBase.cpp - Mixin class for NSPR C++ wrappers
+*/
+
+#include "rcbase.h"
+
+RCBase::~RCBase() { }
+
+PRSize RCBase::GetErrorTextLength() { return PR_GetErrorTextLength(); }
+PRSize RCBase::CopyErrorText(char *text) { return PR_GetErrorText(text); }
+
+void RCBase::SetError(PRErrorCode error, PRInt32 oserror)
+    { PR_SetError(error, oserror); }
+
+void RCBase::SetErrorText(PRSize text_length, const char *text)
+    { PR_SetErrorText(text_length, text); }
+
+/* rcbase.cpp */
diff --git a/pr/src/cplus/rcbase.h b/pr/src/cplus/rcbase.h
new file mode 100644
index 0000000..58df43c
--- /dev/null
+++ b/pr/src/cplus/rcbase.h
@@ -0,0 +1,51 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** RCBase.h - Mixin class for NSPR C++ wrappers
+*/
+
+#if defined(_RCRUNTIME_H)
+#else
+#define _RCRUNTIME_H
+
+#include <prerror.h>
+
+/*
+** Class: RCBase (mixin)
+**
+** Generally mixed into every base class. The functions in this class are all
+** static. Therefore this entire class is just syntatic sugar. It gives the
+** illusion that errors (in particular) are retrieved via the same object
+** that just reported a failure. It also (unfortunately) might lead one to
+** believe that the errors are persistent in that object. They're not.
+*/
+
+class PR_IMPLEMENT(RCBase)
+{
+public:
+    virtual ~RCBase();
+
+    static void AbortSelf();
+
+    static PRErrorCode GetError();
+    static PRInt32 GetOSError();
+
+    static PRSize GetErrorTextLength();
+    static PRSize CopyErrorText(char *text);
+
+    static void SetError(PRErrorCode error, PRInt32 oserror);
+    static void SetErrorText(PRSize textLength, const char *text);
+
+protected:
+    RCBase() { }
+};  /* RCObject */
+
+inline PRErrorCode RCBase::GetError() { return PR_GetError(); }
+inline PRInt32 RCBase::GetOSError() { return PR_GetOSError(); }
+
+#endif  /* defined(_RCRUNTIME_H) */
+
+/* rcbase.h */
diff --git a/pr/src/cplus/rccv.cpp b/pr/src/cplus/rccv.cpp
new file mode 100644
index 0000000..32b84b1
--- /dev/null
+++ b/pr/src/cplus/rccv.cpp
@@ -0,0 +1,65 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** RCCondition - C++ wrapper around NSPR's PRCondVar
+*/
+
+#include "rccv.h"
+
+#include <prlog.h>
+#include <prerror.h>
+#include <prcvar.h>
+
+RCCondition::RCCondition(class RCLock *lock): RCBase()
+{
+    cv = PR_NewCondVar(lock->lock);
+    PR_ASSERT(NULL != cv);
+    timeout = PR_INTERVAL_NO_TIMEOUT;
+}  /* RCCondition::RCCondition */
+
+RCCondition::~RCCondition()
+{
+    if (NULL != cv) PR_DestroyCondVar(cv);
+}  /* RCCondition::~RCCondition */
+
+PRStatus RCCondition::Wait()
+{
+    PRStatus rv;
+    PR_ASSERT(NULL != cv);
+    if (NULL == cv)
+    {
+        SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+        rv = PR_FAILURE;
+    }
+    else
+        rv = PR_WaitCondVar(cv, timeout.interval);
+    return rv;
+}  /* RCCondition::Wait */
+
+PRStatus RCCondition::Notify()
+{
+    return PR_NotifyCondVar(cv);
+}  /* RCCondition::Notify */
+
+PRStatus RCCondition::Broadcast()
+{
+    return PR_NotifyAllCondVar(cv);
+}  /* RCCondition::Broadcast */
+
+PRStatus RCCondition::SetTimeout(const RCInterval& tmo)
+{
+    if (NULL == cv)
+    {
+        SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+        return PR_FAILURE;
+    }
+    timeout = tmo;
+    return PR_SUCCESS;
+}  /* RCCondition::SetTimeout */
+
+RCInterval RCCondition::GetTimeout() const { return timeout; }
+
+/* rccv.cpp */
diff --git a/pr/src/cplus/rccv.h b/pr/src/cplus/rccv.h
new file mode 100644
index 0000000..e5c8913
--- /dev/null
+++ b/pr/src/cplus/rccv.h
@@ -0,0 +1,64 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** RCCondition - C++ wrapper around NSPR's PRCondVar
+**
+** Conditions have a notion of timeouts. A thread that waits on a condition
+** will resume execution when the condition is notified OR when a specified
+** interval of time has expired.
+**
+** Most applications don't adjust the timeouts on conditions. The literature
+** would argue that all threads waiting on a single condition must have the
+** same semantics. But if an application wishes to modify the timeout with
+** (perhaps) each wait call, that modification should be done consistantly
+** and under protection of the condition's associated lock.
+**
+** The default timeout is infinity.
+*/
+
+#if defined(_RCCOND_H)
+#else
+#define _RCCOND_H
+
+#include "rclock.h"
+#include "rcbase.h"
+#include "rcinrval.h"
+
+struct PRCondVar;
+
+class PR_IMPLEMENT(RCCondition): public RCBase
+{
+public:
+    RCCondition(RCLock*);           /* associates CV with a lock and infinite tmo */
+    virtual ~RCCondition();
+
+    virtual PRStatus Wait();        /* applies object's current timeout */
+
+    virtual PRStatus Notify();      /* perhaps ready one thread */
+    virtual PRStatus Broadcast();   /* perhaps ready many threads */
+
+    virtual PRStatus SetTimeout(const RCInterval&);
+                                    /* set object's current timeout value */
+
+private:
+    PRCondVar *cv;
+    RCInterval timeout;
+
+    RCCondition();
+    RCCondition(const RCCondition&);
+    void operator=(const RCCondition&);
+
+public:
+    RCInterval GetTimeout() const;
+};  /* RCCondition */
+
+inline RCCondition::RCCondition(): RCBase() { }
+inline RCCondition::RCCondition(const RCCondition&): RCBase() { }
+inline void RCCondition::operator=(const RCCondition&) { }
+
+#endif /* defined(_RCCOND_H) */
+
+/* RCCond.h */
diff --git a/pr/src/cplus/rcfileio.cpp b/pr/src/cplus/rcfileio.cpp
new file mode 100644
index 0000000..cdf6318
--- /dev/null
+++ b/pr/src/cplus/rcfileio.cpp
@@ -0,0 +1,167 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** Class implementation for normal and special file I/O (ref: prio.h)
+*/
+
+#include "rcfileio.h"
+
+#include <string.h>
+
+RCFileIO::RCFileIO(): RCIO(RCIO::file) { }
+
+RCFileIO::~RCFileIO() { if (NULL != fd) (void)Close(); }
+
+PRInt64 RCFileIO::Available()
+    { return fd->methods->available(fd); }
+
+PRStatus RCFileIO::Close()
+    { PRStatus rv = fd->methods->close(fd); fd = NULL; return rv; }
+
+PRStatus RCFileIO::Delete(const char* filename) { return PR_Delete(filename); }
+
+PRStatus RCFileIO::FileInfo(RCFileInfo* info) const
+    { return fd->methods->fileInfo64(fd, &info->info); }
+
+PRStatus RCFileIO::FileInfo(const char *name, RCFileInfo* info)
+    { return PR_GetFileInfo64(name, &info->info); }
+
+PRStatus RCFileIO::Fsync()
+    { return fd->methods->fsync(fd); }
+
+PRStatus RCFileIO::Open(const char *filename, PRIntn flags, PRIntn mode)
+{
+    fd = PR_Open(filename, flags, mode);
+    return (NULL == fd) ? PR_FAILURE : PR_SUCCESS;
+}  /* RCFileIO::Open */
+
+PRInt32 RCFileIO::Read(void *buf, PRSize amount)
+    { return fd->methods->read(fd, buf, amount); }
+
+PRInt64 RCFileIO::Seek(PRInt64 offset, RCIO::Whence how)
+{
+    PRSeekWhence whence;
+    switch (how)
+    {
+        case RCFileIO::set: whence = PR_SEEK_SET; break;
+        case RCFileIO::current: whence = PR_SEEK_CUR; break;
+        case RCFileIO::end: whence = PR_SEEK_END; break;
+        default: whence = (PRSeekWhence)-1;
+    }
+    return fd->methods->seek64(fd, offset, whence);
+}  /* RCFileIO::Seek */
+
+PRInt32 RCFileIO::Write(const void *buf, PRSize amount)
+    { return fd->methods->write(fd, buf, amount); }
+
+PRInt32 RCFileIO::Writev(
+    const PRIOVec *iov, PRSize size, const RCInterval& timeout)
+    { return fd->methods->writev(fd, iov, size, timeout); }
+
+RCIO *RCFileIO::GetSpecialFile(RCFileIO::SpecialFile special)
+{
+    PRFileDesc* fd;
+    PRSpecialFD which;
+    RCFileIO* spec = NULL;
+
+    switch (special)
+    {
+        case RCFileIO::input: which = PR_StandardInput; break;
+        case RCFileIO::output: which = PR_StandardOutput; break;
+        case RCFileIO::error: which = PR_StandardError; break;
+        default: which = (PRSpecialFD)-1;
+    }
+    fd = PR_GetSpecialFD(which);
+    if (NULL != fd)
+    {
+        spec = new RCFileIO();
+        if (NULL != spec) spec->fd = fd;
+    }
+    return spec;
+}  /* RCFileIO::GetSpecialFile */
+
+
+/*
+** The following methods have been made non-virtual and private. These
+** default implementations are intended to NEVER be called. They
+** are not valid for this type of I/O class (normal and special file).
+*/
+PRStatus RCFileIO::Connect(const RCNetAddr&, const RCInterval&)
+{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
+
+PRStatus RCFileIO::GetLocalName(RCNetAddr*) const
+{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
+
+PRStatus RCFileIO::GetPeerName(RCNetAddr*) const
+{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
+
+PRStatus RCFileIO::GetSocketOption(PRSocketOptionData*) const
+{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
+
+PRStatus RCFileIO::Listen(PRIntn)
+{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
+
+PRInt16 RCFileIO::Poll(PRInt16, PRInt16*)
+{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return 0; }
+
+PRInt32 RCFileIO::Recv(void*, PRSize, PRIntn, const RCInterval&)
+{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; }
+
+PRInt32 RCFileIO::Recvfrom(void*, PRSize, PRIntn, RCNetAddr*, const RCInterval&)
+{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; }
+
+PRInt32 RCFileIO::Send(
+    const void*, PRSize, PRIntn, const RCInterval&)
+{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; }
+
+PRInt32 RCFileIO::Sendto(
+    const void*, PRSize, PRIntn, const RCNetAddr&, const RCInterval&)
+{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; }
+
+RCIO* RCFileIO::Accept(RCNetAddr*, const RCInterval&)
+{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return NULL; }
+
+PRStatus RCFileIO::Bind(const RCNetAddr&)
+{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
+
+PRInt32 RCFileIO::AcceptRead(
+    RCIO**, RCNetAddr**, void*, PRSize, const RCInterval&)
+{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; }
+
+PRStatus RCFileIO::SetSocketOption(const PRSocketOptionData*)
+{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
+
+PRStatus RCFileIO::Shutdown(RCIO::ShutdownHow)
+{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
+
+PRInt32 RCFileIO::TransmitFile(
+    RCIO*, const void*, PRSize, RCIO::FileDisposition, const RCInterval&)
+{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; }
+
+/*
+** Class implementation for file information object (ref: prio.h)
+*/
+
+RCFileInfo::~RCFileInfo() { }
+
+RCFileInfo::RCFileInfo(const RCFileInfo& her): RCBase()
+    { info = her.info; }  /* RCFileInfo::RCFileInfo */
+
+RCTime RCFileInfo::CreationTime() const { return RCTime(info.creationTime); }
+
+RCTime RCFileInfo::ModifyTime() const { return RCTime(info.modifyTime); }
+
+RCFileInfo::FileType RCFileInfo::Type() const
+{
+    RCFileInfo::FileType type;
+    switch (info.type)
+    {
+        case PR_FILE_FILE: type = RCFileInfo::file; break;
+        case PR_FILE_DIRECTORY: type = RCFileInfo::directory; break;
+        default: type = RCFileInfo::other;
+    }
+    return type;
+}  /* RCFileInfo::Type */
diff --git a/pr/src/cplus/rcfileio.h b/pr/src/cplus/rcfileio.h
new file mode 100644
index 0000000..d9c8258
--- /dev/null
+++ b/pr/src/cplus/rcfileio.h
@@ -0,0 +1,129 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** Class definitions for normal and special file I/O (ref: prio.h)
+*/
+
+#if defined(_RCFILEIO_H)
+#else
+#define _RCFILEIO_H
+
+#include "rcio.h"
+#include "rctime.h"
+
+/*
+** One would normally create a concrete class, such as RCFileIO, but then
+** pass around more generic references, ie., RCIO.
+**
+** This subclass of RCIO hides (makes private) the methods that are not
+** applicable to normal files.
+*/
+
+class RCFileInfo;
+
+class PR_IMPLEMENT(RCFileIO): public RCIO
+{
+public:
+    RCFileIO();
+    virtual ~RCFileIO();
+
+    virtual PRInt64     Available();
+    virtual PRStatus    Close();
+    static  PRStatus    Delete(const char *name);
+    virtual PRStatus    FileInfo(RCFileInfo* info) const;
+    static  PRStatus    FileInfo(const char *name, RCFileInfo* info);
+    virtual PRStatus    Fsync();
+    virtual PRStatus    Open(const char *name, PRIntn flags, PRIntn mode);
+    virtual PRInt32     Read(void *buf, PRSize amount);
+    virtual PRInt64     Seek(PRInt64 offset, RCIO::Whence how);
+    virtual PRInt32     Write(const void *buf, PRSize amount);
+    virtual PRInt32     Writev(
+                            const PRIOVec *iov, PRSize size,
+                            const RCInterval& timeout);
+
+private:
+
+    /* These methods made private are unavailable for this object */
+    RCFileIO(const RCFileIO&);
+    void operator=(const RCFileIO&);
+
+    RCIO*       Accept(RCNetAddr* addr, const RCInterval& timeout);
+    PRInt32     AcceptRead(
+                    RCIO **newfd, RCNetAddr **address, void *buffer,
+                    PRSize amount, const RCInterval& timeout);
+    PRStatus    Bind(const RCNetAddr& addr);
+    PRStatus    Connect(const RCNetAddr& addr, const RCInterval& timeout);
+    PRStatus    GetLocalName(RCNetAddr *addr) const;
+    PRStatus    GetPeerName(RCNetAddr *addr) const;
+    PRStatus    GetSocketOption(PRSocketOptionData *data) const;
+    PRStatus    Listen(PRIntn backlog);
+    PRInt16     Poll(PRInt16 in_flags, PRInt16 *out_flags);
+    PRInt32     Recv(
+                    void *buf, PRSize amount, PRIntn flags,
+                    const RCInterval& timeout);
+    PRInt32     Recvfrom(
+                    void *buf, PRSize amount, PRIntn flags,
+                    RCNetAddr* addr, const RCInterval& timeout);
+    PRInt32     Send(
+                    const void *buf, PRSize amount, PRIntn flags,
+                    const RCInterval& timeout);
+    PRInt32     Sendto(
+                    const void *buf, PRSize amount, PRIntn flags,
+                    const RCNetAddr& addr,
+                    const RCInterval& timeout);
+    PRStatus    SetSocketOption(const PRSocketOptionData *data);
+    PRStatus    Shutdown(RCIO::ShutdownHow how);
+    PRInt32     TransmitFile(
+                    RCIO *source, const void *headers,
+                    PRSize hlen, RCIO::FileDisposition flags,
+                    const RCInterval& timeout);
+public:
+
+    /*
+    ** The following function return a valid normal file object,
+    ** Such objects can be used for scanned input and console output.
+    */
+    typedef enum {
+        input = PR_StandardInput,
+        output = PR_StandardOutput,
+        error = PR_StandardError
+    } SpecialFile;
+
+    static RCIO *GetSpecialFile(RCFileIO::SpecialFile special);
+
+};  /* RCFileIO */
+
+class PR_IMPLEMENT(RCFileInfo): public RCBase
+{
+public:
+    typedef enum {
+        file = PR_FILE_FILE,
+        directory = PR_FILE_DIRECTORY,
+        other = PR_FILE_OTHER
+    } FileType;
+
+public:
+    RCFileInfo();
+    RCFileInfo(const RCFileInfo&);
+
+    virtual ~RCFileInfo();
+
+    PRInt64 Size() const;
+    RCTime CreationTime() const;
+    RCTime ModifyTime() const;
+    RCFileInfo::FileType Type() const;
+
+friend PRStatus RCFileIO::FileInfo(RCFileInfo*) const;
+friend PRStatus RCFileIO::FileInfo(const char *name, RCFileInfo*);
+
+private:
+    PRFileInfo64 info;
+};  /* RCFileInfo */
+
+inline RCFileInfo::RCFileInfo(): RCBase() { }
+inline PRInt64 RCFileInfo::Size() const { return info.size; }
+
+#endif /* defined(_RCFILEIO_H) */
diff --git a/pr/src/cplus/rcinrval.cpp b/pr/src/cplus/rcinrval.cpp
new file mode 100644
index 0000000..cda5f8d
--- /dev/null
+++ b/pr/src/cplus/rcinrval.cpp
@@ -0,0 +1,37 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** C++ interval times (ref: prinrval.h)
+**
+**  An interval is a period of time. The start of the interval (epoch)
+**  must be defined by the application. The unit of time of an interval
+**  is platform dependent, therefore so is the maximum interval that is
+**  representable. However, that interval is never less that ~12 hours.
+*/
+
+#include "rcinrval.h"
+
+RCInterval::~RCInterval() { }
+
+RCInterval::RCInterval(RCInterval::RCReservedInterval special): RCBase()
+{
+    switch (special)
+    {
+    case RCInterval::now:
+        interval = PR_IntervalNow();
+        break;
+    case RCInterval::no_timeout:
+        interval = PR_INTERVAL_NO_TIMEOUT;
+        break;
+    case RCInterval::no_wait:
+        interval = PR_INTERVAL_NO_WAIT;
+        break;
+    default:
+        break;
+    }
+}  /* RCInterval::RCInterval */
+
+/* rcinrval.cpp */
diff --git a/pr/src/cplus/rcinrval.h b/pr/src/cplus/rcinrval.h
new file mode 100644
index 0000000..bcf755f
--- /dev/null
+++ b/pr/src/cplus/rcinrval.h
@@ -0,0 +1,137 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** C++ interval times (ref: prinrval.h)
+**
+**  An interval is a period of time. The start of the interval (epoch)
+**  must be defined by the application. The unit of time of an interval
+**  is platform dependent, therefore so is the maximum interval that is
+**  representable. However, that interval is never less than ~6 hours.
+*/
+#if defined(_RCINTERVAL_H)
+#else
+#define _RCINTERVAL_H
+
+#include "rcbase.h"
+#include <prinrval.h>
+
+class PR_IMPLEMENT(RCInterval): public RCBase
+{
+public:
+    typedef enum {now, no_timeout, no_wait} RCReservedInterval;
+
+    virtual ~RCInterval();
+
+    RCInterval();
+
+    RCInterval(PRIntervalTime interval);
+    RCInterval(const RCInterval& copy);
+    RCInterval(RCReservedInterval special);
+
+    void SetToNow();
+
+    void operator=(const RCInterval&);
+    void operator=(PRIntervalTime interval);
+
+    PRBool operator<(const RCInterval&);
+    PRBool operator>(const RCInterval&);
+    PRBool operator==(const RCInterval&);
+    PRBool operator>=(const RCInterval&);
+    PRBool operator<=(const RCInterval&);
+
+    RCInterval operator+(const RCInterval&);
+    RCInterval operator-(const RCInterval&);
+    RCInterval& operator+=(const RCInterval&);
+    RCInterval& operator-=(const RCInterval&);
+
+    RCInterval operator/(PRUint32);
+    RCInterval operator*(PRUint32);
+    RCInterval& operator/=(PRUint32);
+    RCInterval& operator*=(PRUint32);
+
+
+    PRUint32 ToSeconds() const;
+    PRUint32 ToMilliseconds() const;
+    PRUint32 ToMicroseconds() const;
+    operator PRIntervalTime() const;
+
+    static PRIntervalTime FromSeconds(PRUint32 seconds);
+    static PRIntervalTime FromMilliseconds(PRUint32 milli);
+    static PRIntervalTime FromMicroseconds(PRUint32 micro);
+
+    friend class RCCondition;
+
+private:
+    PRIntervalTime interval;
+    
+};  /* RCInterval */
+
+
+inline RCInterval::RCInterval(): RCBase() { }
+
+inline RCInterval::RCInterval(const RCInterval& his): RCBase()
+    { interval = his.interval; }
+
+inline RCInterval::RCInterval(PRIntervalTime ticks): RCBase()
+    { interval = ticks; }
+
+inline void RCInterval::SetToNow() { interval = PR_IntervalNow(); }
+
+inline void RCInterval::operator=(const RCInterval& his)
+    { interval = his.interval; }
+
+inline void RCInterval::operator=(PRIntervalTime his)
+    { interval = his; }
+
+inline PRBool RCInterval::operator==(const RCInterval& his)
+    { return (interval == his.interval) ? PR_TRUE : PR_FALSE; }
+inline PRBool RCInterval::operator<(const RCInterval& his)
+    { return (interval < his.interval)? PR_TRUE : PR_FALSE; }
+inline PRBool RCInterval::operator>(const RCInterval& his)
+    { return (interval > his.interval) ? PR_TRUE : PR_FALSE; }
+inline PRBool RCInterval::operator<=(const RCInterval& his)
+    { return (interval <= his.interval) ? PR_TRUE : PR_FALSE; }
+inline PRBool RCInterval::operator>=(const RCInterval& his)
+    { return (interval <= his.interval) ? PR_TRUE : PR_FALSE; }
+
+inline RCInterval RCInterval::operator+(const RCInterval& his)
+    { return RCInterval((PRIntervalTime)(interval + his.interval)); }
+inline RCInterval RCInterval::operator-(const RCInterval& his)
+    { return RCInterval((PRIntervalTime)(interval - his.interval)); }
+inline RCInterval& RCInterval::operator+=(const RCInterval& his)
+    { interval += his.interval; return *this; }
+inline RCInterval& RCInterval::operator-=(const RCInterval& his)
+    { interval -= his.interval; return *this; }
+
+inline RCInterval RCInterval::operator/(PRUint32 him)
+    { return RCInterval((PRIntervalTime)(interval / him)); }
+inline RCInterval RCInterval::operator*(PRUint32 him)
+    { return RCInterval((PRIntervalTime)(interval * him)); }
+
+inline RCInterval& RCInterval::operator/=(PRUint32 him)
+    { interval /= him; return *this; }
+
+inline RCInterval& RCInterval::operator*=(PRUint32 him)
+    { interval *= him; return *this; }
+
+inline PRUint32 RCInterval::ToSeconds() const
+    { return PR_IntervalToSeconds(interval); }
+inline PRUint32 RCInterval::ToMilliseconds() const
+    { return PR_IntervalToMilliseconds(interval); }
+inline PRUint32 RCInterval::ToMicroseconds() const
+    { return PR_IntervalToMicroseconds(interval); }
+inline RCInterval::operator PRIntervalTime() const { return interval; }
+
+inline PRIntervalTime RCInterval::FromSeconds(PRUint32 seconds)
+    { return PR_SecondsToInterval(seconds); }
+inline PRIntervalTime RCInterval::FromMilliseconds(PRUint32 milli)
+    { return PR_MillisecondsToInterval(milli); }
+inline PRIntervalTime RCInterval::FromMicroseconds(PRUint32 micro)
+    { return PR_MicrosecondsToInterval(micro); }
+
+#endif  /* defined(_RCINTERVAL_H) */
+
+/* RCInterval.h */
diff --git a/pr/src/cplus/rcio.cpp b/pr/src/cplus/rcio.cpp
new file mode 100644
index 0000000..081a9f6
--- /dev/null
+++ b/pr/src/cplus/rcio.cpp
@@ -0,0 +1,14 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** Base class implmenation for I/O (ref: prio.h)
+*/
+
+#include "rcio.h"
+
+RCIO::~RCIO() { }
+
+RCIO::RCIO(RCIO::RCIOType): RCBase() { }
diff --git a/pr/src/cplus/rcio.h b/pr/src/cplus/rcio.h
new file mode 100644
index 0000000..a4278d2
--- /dev/null
+++ b/pr/src/cplus/rcio.h
@@ -0,0 +1,116 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** Base class definitions for I/O (ref: prio.h)
+**
+** This class is a virtual base class. Construction must be done by a
+** subclass, but the I/O operations can be done on a RCIO object reference.
+*/
+
+#if defined(_RCIO_H)
+#else
+#define _RCIO_H
+
+#include "rcbase.h"
+#include "rcnetdb.h"
+#include "rcinrval.h"
+
+#include "prio.h"
+
+class RCFileInfo;
+
+class PR_IMPLEMENT(RCIO): public RCBase
+{
+public:
+    typedef enum {
+        open = PR_TRANSMITFILE_KEEP_OPEN,   /* socket is left open after file
+                                             * is transmitted. */
+        close = PR_TRANSMITFILE_CLOSE_SOCKET/* socket is closed after file
+                                             * is transmitted. */
+    } FileDisposition;
+
+    typedef enum {
+        set = PR_SEEK_SET,                  /* Set to value specified */
+        current = PR_SEEK_CUR,              /* Seek relative to current position */
+        end = PR_SEEK_END                   /* seek past end of current eof */
+    } Whence;
+
+    typedef enum {
+        recv = PR_SHUTDOWN_RCV,             /* receives will be disallowed */
+        send = PR_SHUTDOWN_SEND,            /* sends will be disallowed */
+        both = PR_SHUTDOWN_BOTH             /* sends & receives will be disallowed */
+    } ShutdownHow;
+
+public:
+    virtual ~RCIO();
+
+    virtual RCIO*       Accept(RCNetAddr* addr, const RCInterval& timeout) = 0;
+    virtual PRInt32     AcceptRead(
+                            RCIO **nd, RCNetAddr **raddr, void *buf,
+                            PRSize amount, const RCInterval& timeout) = 0;
+    virtual PRInt64     Available() = 0;
+    virtual PRStatus    Bind(const RCNetAddr& addr) = 0;
+    virtual PRStatus    Close() = 0;
+    virtual PRStatus    Connect(
+                            const RCNetAddr& addr,
+                            const RCInterval& timeout) = 0;
+    virtual PRStatus    FileInfo(RCFileInfo *info) const = 0;
+    virtual PRStatus    Fsync() = 0;
+    virtual PRStatus    GetLocalName(RCNetAddr *addr) const = 0;
+    virtual PRStatus    GetPeerName(RCNetAddr *addr) const = 0;
+    virtual PRStatus    GetSocketOption(PRSocketOptionData *data) const = 0;
+    virtual PRStatus    Listen(PRIntn backlog) = 0;
+    virtual PRStatus    Open(const char *name, PRIntn flags, PRIntn mode) = 0;
+    virtual PRInt16     Poll(PRInt16 in_flags, PRInt16 *out_flags) = 0;
+    virtual PRInt32     Read(void *buf, PRSize amount) = 0;
+    virtual PRInt32     Recv(
+                            void *buf, PRSize amount, PRIntn flags,
+                            const RCInterval& timeout) = 0;
+    virtual PRInt32     Recvfrom(
+                            void *buf, PRSize amount, PRIntn flags,
+                            RCNetAddr* addr, const RCInterval& timeout) = 0;
+    virtual PRInt64     Seek(PRInt64 offset, Whence how) = 0;
+    virtual PRInt32     Send(
+                            const void *buf, PRSize amount, PRIntn flags,
+                            const RCInterval& timeout) = 0;
+    virtual PRInt32     Sendto(
+                            const void *buf, PRSize amount, PRIntn flags,
+                            const RCNetAddr& addr,
+                            const RCInterval& timeout) = 0;
+    virtual PRStatus    SetSocketOption(const PRSocketOptionData *data) = 0;
+    virtual PRStatus    Shutdown(ShutdownHow how) = 0;
+    virtual PRInt32     TransmitFile(
+                            RCIO *source, const void *headers,
+                            PRSize hlen, RCIO::FileDisposition flags,
+                            const RCInterval& timeout) = 0;
+    virtual PRInt32     Write(const void *buf, PRSize amount) = 0;
+    virtual PRInt32     Writev(
+                            const PRIOVec *iov, PRSize size,
+                            const RCInterval& timeout) = 0;
+
+protected:
+    typedef enum {
+        file = PR_DESC_FILE,
+        tcp = PR_DESC_SOCKET_TCP,
+        udp = PR_DESC_SOCKET_UDP,
+        layered = PR_DESC_LAYERED} RCIOType;
+
+    RCIO(RCIOType);
+
+    PRFileDesc *fd;  /* where the real code hides */
+
+private:
+    /* no default construction and no copies allowed */
+    RCIO();
+    RCIO(const RCIO&);
+
+};  /* RCIO */
+
+#endif /* defined(_RCIO_H) */
+
+/* RCIO.h */
+
+
diff --git a/pr/src/cplus/rclock.cpp b/pr/src/cplus/rclock.cpp
new file mode 100644
index 0000000..60d13b8
--- /dev/null
+++ b/pr/src/cplus/rclock.cpp
@@ -0,0 +1,40 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+/*
+** C++ access to NSPR locks (PRLock)
+*/
+
+#include "rclock.h"
+#include <prlog.h>
+
+RCLock::RCLock()
+{
+    lock = PR_NewLock();  /* it might be NULL */
+    PR_ASSERT(NULL != lock);
+}  /* RCLock::RCLock */
+
+RCLock::~RCLock()
+{
+    if (NULL != lock) PR_DestroyLock(lock);
+    lock = NULL;
+}  /* RCLock::~RCLock */
+
+void RCLock::Acquire()
+{
+    PR_ASSERT(NULL != lock);
+    PR_Lock(lock);
+}  /* RCLock::Acquire */
+
+void RCLock::Release()
+{
+    PRStatus rv;
+    PR_ASSERT(NULL != lock);
+    rv = PR_Unlock(lock);
+    PR_ASSERT(PR_SUCCESS == rv);
+}  /* RCLock::Release */
+
+/* RCLock.cpp */
+
diff --git a/pr/src/cplus/rclock.h b/pr/src/cplus/rclock.h
new file mode 100644
index 0000000..511b6fa
--- /dev/null
+++ b/pr/src/cplus/rclock.h
@@ -0,0 +1,66 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** C++ access to NSPR locks (PRLock)
+*/
+
+#if defined(_RCLOCK_H)
+#else
+#define _RCLOCK_H
+
+#include "rcbase.h"
+
+#include <prlock.h>
+
+class PR_IMPLEMENT(RCLock): public RCBase
+{
+public:
+    RCLock();
+    virtual ~RCLock();
+
+    void Acquire();                 /* non-reentrant */
+    void Release();                 /* should be by owning thread */
+
+    friend class RCCondition;
+
+private:
+    RCLock(const RCLock&);          /* can't do that */
+    void operator=(const RCLock&);  /* nor that */
+
+    PRLock *lock;
+};  /* RCLock */
+
+/*
+** Class: RCEnter
+**
+** In scope locks. You can only allocate them on the stack. The language
+** will insure that they get released (by calling the destructor) when
+** the thread leaves scope, even if via an exception.
+*/
+class PR_IMPLEMENT(RCEnter)
+{
+public:
+    ~RCEnter();                     /* releases the lock */
+    RCEnter(RCLock*);               /* acquires the lock */
+
+private:
+    RCLock *lock;
+
+    RCEnter();
+    RCEnter(const RCEnter&);
+    void operator=(const RCEnter&);
+
+    void *operator new(PRSize) { return NULL; }
+    void operator delete(void*) { }
+};  /* RCEnter */
+
+
+inline RCEnter::RCEnter(RCLock* ml) { lock = ml; lock->Acquire(); }
+inline RCEnter::~RCEnter() { lock->Release(); lock = NULL; }
+
+#endif /* defined(_RCLOCK_H) */
+
+/* RCLock.h */
diff --git a/pr/src/cplus/rcmon.h b/pr/src/cplus/rcmon.h
new file mode 100644
index 0000000..5d084ef
--- /dev/null
+++ b/pr/src/cplus/rcmon.h
@@ -0,0 +1,47 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** Class: RCMonitor (ref prmonitor.h)
+**
+** RCMonitor.h - C++ wrapper around NSPR's monitors
+*/
+#if defined(_RCMONITOR_H)
+#else
+#define _RCMONITOR_H
+
+#include "rcbase.h"
+#include "rcinrval.h"
+
+struct PRMonitor;
+
+class PR_IMPLEMENT(RCMonitor): public RCBase
+{
+public:
+    RCMonitor();                    /* timeout is infinity */
+    virtual ~RCMonitor();
+
+    virtual void Enter();           /* reentrant entry */
+    virtual void Exit();
+
+    virtual void Notify();          /* possibly enable one thread */
+    virtual void NotifyAll();       /* enable all waiters */
+
+    virtual void Wait();            /* applies object's timeout */
+
+    virtual void SetTimeout(const RCInterval& timeout);
+
+private:
+    PRMonitor *monitor;
+    RCInterval timeout;
+
+public:
+    RCInterval GetTimeout() const;  /* get the current value */
+
+};  /* RCMonitor */
+
+#endif /* defined(_RCMONITOR_H) */
+
+/* RCMonitor.h */
diff --git a/pr/src/cplus/rcnetdb.cpp b/pr/src/cplus/rcnetdb.cpp
new file mode 100644
index 0000000..042943b
--- /dev/null
+++ b/pr/src/cplus/rcnetdb.cpp
@@ -0,0 +1,200 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** Base class implementation for network access functions (ref: prnetdb.h)
+*/
+
+#include "rclock.h"
+#include "rcnetdb.h"
+
+#include <prmem.h>
+#include <prlog.h>
+#include <string.h>
+
+RCNetAddr::RCNetAddr(const RCNetAddr& his): RCBase()
+    { address = his.address; }
+
+RCNetAddr::RCNetAddr(const RCNetAddr& his, PRUint16 port): RCBase()
+{
+    address = his.address;
+    switch (address.raw.family)
+    {
+        case PR_AF_INET: address.inet.port = port; break;
+        case PR_AF_INET6: address.ipv6.port = port; break;
+        default: break;
+    }
+}  /* RCNetAddr::RCNetAddr */
+
+RCNetAddr::RCNetAddr(RCNetAddr::HostValue host, PRUint16 port): RCBase()
+{
+    PRNetAddrValue how;
+    switch (host)
+    {
+        case RCNetAddr::any: how = PR_IpAddrAny; break;
+        case RCNetAddr::loopback: how = PR_IpAddrLoopback; break;
+        default: PR_NOT_REACHED("This can't happen -- and did!");
+    }
+    (void)PR_InitializeNetAddr(how, port, &address);
+}  /* RCNetAddr::RCNetAddr */
+
+RCNetAddr::~RCNetAddr() { }
+
+void RCNetAddr::operator=(const RCNetAddr& his) { address = his.address; }
+
+PRStatus RCNetAddr::FromString(const char* string)
+    { return PR_StringToNetAddr(string, &address); }
+
+void RCNetAddr::operator=(const PRNetAddr* addr) { address = *addr; }
+
+PRBool RCNetAddr::operator==(const RCNetAddr& his) const
+{
+    PRBool rv = EqualHost(his);
+    if (rv)
+    {
+        switch (address.raw.family)
+        {
+            case PR_AF_INET:
+                rv = (address.inet.port == his.address.inet.port); break;
+            case PR_AF_INET6:
+                rv = (address.ipv6.port == his.address.ipv6.port); break;
+            case PR_AF_LOCAL:
+            default: break;
+        }
+    }
+    return rv;
+}  /* RCNetAddr::operator== */
+
+PRBool RCNetAddr::EqualHost(const RCNetAddr& his) const
+{
+    PRBool rv;
+    switch (address.raw.family)
+    {
+        case PR_AF_INET:
+            rv = (address.inet.ip == his.address.inet.ip); break;
+        case PR_AF_INET6:
+            rv = (0 == memcmp(
+                &address.ipv6.ip, &his.address.ipv6.ip,
+                sizeof(address.ipv6.ip)));
+            break;
+#if defined(XP_UNIX)
+        case PR_AF_LOCAL:
+            rv = (0 == strncmp(
+                address.local.path, his.address.local.path,
+                sizeof(address.local.path)));
+            break;
+#endif
+        default: break;
+    }
+    return rv;
+}  /* RCNetAddr::operator== */
+
+PRStatus RCNetAddr::ToString(char *string, PRSize size) const
+    { return PR_NetAddrToString(&address, string, size); }
+
+/*
+** RCHostLookup
+*/
+
+RCHostLookup::~RCHostLookup()
+{
+    if (NULL != address) delete [] address;
+}  /* RCHostLookup::~RCHostLookup */
+
+RCHostLookup::RCHostLookup(): RCBase()
+{
+    address = NULL;
+    max_index = 0;
+}  /* RCHostLookup::RCHostLookup */
+
+PRStatus RCHostLookup::ByName(const char* name)
+{
+    PRStatus rv;
+    PRNetAddr addr;
+    PRHostEnt hostentry;
+    PRIntn index = 0, max;
+    RCNetAddr* vector = NULL;
+    RCNetAddr* old_vector = NULL;
+    void* buffer = PR_Malloc(PR_NETDB_BUF_SIZE);
+    if (NULL == buffer) return PR_FAILURE;
+    rv = PR_GetHostByName(name, (char*)buffer, PR_NETDB_BUF_SIZE, &hostentry);
+    if (PR_SUCCESS == rv)
+    {
+        for (max = 0, index = 0;; ++max)
+        {
+            index = PR_EnumerateHostEnt(index, &hostentry, 0, &addr);
+            if (0 == index) break;
+        }
+        if (max > 0)
+        {
+            vector = new RCNetAddr[max];
+            while (--max > 0)
+            {
+                index = PR_EnumerateHostEnt(index, &hostentry, 0, &addr);
+                if (0 == index) break;
+                vector[index] = &addr;
+            }
+            {
+                RCEnter entry(&ml);
+                old_vector = address;
+                address = vector;
+                max_index = max;
+            }
+            if (NULL != old_vector) delete [] old_vector;
+        }
+    }
+    if (NULL != buffer) PR_DELETE(buffer);
+    return PR_SUCCESS;
+}  /* RCHostLookup::ByName */
+
+PRStatus RCHostLookup::ByAddress(const RCNetAddr& host_addr)
+{
+    PRStatus rv;
+    PRNetAddr addr;
+    PRHostEnt hostentry;
+    PRIntn index = 0, max;
+    RCNetAddr* vector = NULL;
+    RCNetAddr* old_vector = NULL;
+    char *buffer = (char*)PR_Malloc(PR_NETDB_BUF_SIZE);
+    if (NULL == buffer) return PR_FAILURE;
+    rv = PR_GetHostByAddr(host_addr, buffer, PR_NETDB_BUF_SIZE, &hostentry);
+    if (PR_SUCCESS == rv)
+    {
+        for (max = 0, index = 0;; ++max)
+        {
+            index = PR_EnumerateHostEnt(index, &hostentry, 0, &addr);
+            if (0 == index) break;
+        }
+        if (max > 0)
+        {
+            vector = new RCNetAddr[max];
+            while (--max > 0)
+            {
+                index = PR_EnumerateHostEnt(index, &hostentry, 0, &addr);
+                if (0 == index) break;
+                vector[index] = &addr;
+            }
+            {
+                RCEnter entry(&ml);
+                old_vector = address;
+                address = vector;
+                max_index = max;
+            }
+            if (NULL != old_vector) delete [] old_vector;
+        }
+    }
+    if (NULL != buffer) PR_DELETE(buffer);
+    return PR_SUCCESS;
+}  /* RCHostLookup::ByAddress */
+
+const RCNetAddr* RCHostLookup::operator[](PRUintn which)
+{
+    RCNetAddr* addr = NULL;
+    if (which < max_index)
+        addr = &address[which];
+    return addr;
+}  /* RCHostLookup::operator[] */
+
+/* RCNetdb.cpp */
diff --git a/pr/src/cplus/rcnetdb.h b/pr/src/cplus/rcnetdb.h
new file mode 100644
index 0000000..8096113
--- /dev/null
+++ b/pr/src/cplus/rcnetdb.h
@@ -0,0 +1,97 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** Base class definitions for network access functions (ref: prnetdb.h)
+*/
+
+#if defined(_RCNETDB_H)
+#else
+#define _RCNETDB_H
+
+#include "rclock.h"
+#include "rcbase.h"
+
+#include <prnetdb.h>
+
+class PR_IMPLEMENT(RCNetAddr): public RCBase
+{
+public:
+    typedef enum {
+        any = PR_IpAddrAny,             /* assign logical INADDR_ANY */
+        loopback = PR_IpAddrLoopback    /* assign logical INADDR_LOOPBACK */
+    } HostValue;
+
+    RCNetAddr();                        /* default constructor is unit'd object */
+    RCNetAddr(const RCNetAddr&);        /* copy constructor */
+    RCNetAddr(HostValue, PRUint16 port);/* init'd w/ 'special' assignments */
+    RCNetAddr(const RCNetAddr&, PRUint16 port);
+                                        /* copy w/ port reassigment */
+
+    virtual ~RCNetAddr();
+
+    void operator=(const RCNetAddr&);
+
+    virtual PRBool operator==(const RCNetAddr&) const;
+                                        /* compare of all relavent fields */
+    virtual PRBool EqualHost(const RCNetAddr&) const;
+                                        /* compare of just host field */
+
+
+public:
+
+    void operator=(const PRNetAddr*);   /* construction from more primitive data */
+    operator const PRNetAddr*() const;  /* extraction of underlying representation */
+    virtual PRStatus FromString(const char* string);
+                                        /* initialization from an ASCII string */
+    virtual PRStatus ToString(char *string, PRSize size) const;
+                                        /* convert internal fromat to a string */
+
+private:
+
+    PRNetAddr address;
+
+};  /* RCNetAddr */
+
+/*
+** Class: RCHostLookup
+**
+** Abstractions to look up host names and addresses.
+**
+** This is a stateful class. One looks up the host by name or by
+** address, then enumerates over a possibly empty array of network
+** addresses. The storage for the addresses is owned by the class.
+*/
+
+class RCHostLookup: public RCBase
+{
+public:
+    virtual ~RCHostLookup();
+
+    RCHostLookup();
+
+    virtual PRStatus ByName(const char* name);
+    virtual PRStatus ByAddress(const RCNetAddr&);
+
+    virtual const RCNetAddr* operator[](PRUintn);
+
+private:
+    RCLock ml;
+    PRIntn max_index;
+    RCNetAddr* address;
+
+    RCHostLookup(const RCHostLookup&);
+    RCHostLookup& operator=(const RCHostLookup&);
+};
+
+inline RCNetAddr::RCNetAddr(): RCBase() { }
+inline RCNetAddr::operator const PRNetAddr*() const { return &address; }
+
+
+#endif /* defined(_RCNETDB_H) */
+
+/* RCNetdb.h */
+
+
diff --git a/pr/src/cplus/rcnetio.cpp b/pr/src/cplus/rcnetio.cpp
new file mode 100644
index 0000000..f511d81
--- /dev/null
+++ b/pr/src/cplus/rcnetio.cpp
@@ -0,0 +1,163 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** Subclass implementation for streamed network I/O (ref: prio.h)
+*/
+
+#include "rcnetio.h"
+
+#include <private/pprio.h>
+
+RCNetStreamIO::~RCNetStreamIO()
+    { PRStatus rv = (fd->methods->close)(fd); fd = NULL; }
+
+RCNetStreamIO::RCNetStreamIO(): RCIO(RCIO::tcp)
+    { fd = PR_NewTCPSocket(); }
+
+RCNetStreamIO::RCNetStreamIO(PRIntn protocol): RCIO(RCIO::tcp)
+    { fd = PR_Socket(PR_AF_INET, PR_SOCK_STREAM, protocol); }
+
+RCIO* RCNetStreamIO::Accept(RCNetAddr* addr, const RCInterval& timeout)
+{
+    PRNetAddr peer;
+    RCNetStreamIO* rcio = NULL;
+    PRFileDesc* newfd = fd->methods->accept(fd, &peer, timeout);
+    if (NULL != newfd)
+    {
+        rcio = new RCNetStreamIO();
+        if (NULL != rcio)
+        {
+            *addr = &peer;
+            rcio->fd = newfd;
+        }
+        else
+            (void)(newfd->methods->close)(newfd);
+    }
+    return rcio;
+}  /* RCNetStreamIO::Accept */
+
+PRInt32 RCNetStreamIO::AcceptRead(
+    RCIO **nd, RCNetAddr **raddr, void *buf,
+    PRSize amount, const RCInterval& timeout)
+{   
+    PRNetAddr *from;
+    PRFileDesc *accepted;
+    PRInt32 rv = (fd->methods->acceptread)(
+        fd, &accepted, &from, buf, amount, timeout);
+    if (rv >= 0)
+    {
+        RCNetStreamIO *ns = new RCNetStreamIO();
+        if (NULL != *nd) ns->fd = accepted;
+        else {PR_Close(accepted); rv = -1; }
+        *nd = ns;
+    }
+    return rv;
+}  /* RCNetStreamIO::AcceptRead */
+
+PRInt64 RCNetStreamIO::Available()
+    { return (fd->methods->available64)(fd); }
+
+PRStatus RCNetStreamIO::Bind(const RCNetAddr& addr)
+    { return (fd->methods->bind)(fd, addr); }
+
+PRStatus RCNetStreamIO::Connect(const RCNetAddr& addr, const RCInterval& timeout)
+    { return (fd->methods->connect)(fd, addr, timeout); }
+
+PRStatus RCNetStreamIO::GetLocalName(RCNetAddr *addr) const
+{
+    PRNetAddr local;
+    PRStatus rv = (fd->methods->getsockname)(fd, &local);
+    if (PR_SUCCESS == rv) *addr = &local;
+    return rv;
+}  /* RCNetStreamIO::GetLocalName */
+
+PRStatus RCNetStreamIO::GetPeerName(RCNetAddr *addr) const
+{
+    PRNetAddr peer;
+    PRStatus rv = (fd->methods->getpeername)(fd, &peer);
+    if (PR_SUCCESS == rv) *addr = &peer;
+    return rv;
+}  /* RCNetStreamIO::GetPeerName */
+
+PRStatus RCNetStreamIO::GetSocketOption(PRSocketOptionData *data) const
+    { return (fd->methods->getsocketoption)(fd, data); }
+
+PRStatus RCNetStreamIO::Listen(PRIntn backlog)
+    { return (fd->methods->listen)(fd, backlog); }
+
+PRInt16 RCNetStreamIO::Poll(PRInt16 in_flags, PRInt16 *out_flags)
+    { return (fd->methods->poll)(fd, in_flags, out_flags); }
+
+PRInt32 RCNetStreamIO::Read(void *buf, PRSize amount)
+    { return (fd->methods->read)(fd, buf, amount); }
+
+PRInt32 RCNetStreamIO::Recv(
+    void *buf, PRSize amount, PRIntn flags, const RCInterval& timeout)
+    { return (fd->methods->recv)(fd, buf, amount, flags, timeout); }
+
+PRInt32 RCNetStreamIO::Recvfrom(
+    void *buf, PRSize amount, PRIntn flags,
+    RCNetAddr* addr, const RCInterval& timeout)
+{
+    PRNetAddr peer;
+    PRInt32 rv = (fd->methods->recvfrom)(
+        fd, buf, amount, flags, &peer, timeout);
+    if (-1 != rv) *addr = &peer;
+    return rv;
+}  /* RCNetStreamIO::Recvfrom */
+
+PRInt32 RCNetStreamIO::Send(
+    const void *buf, PRSize amount, PRIntn flags, const RCInterval& timeout)
+    { return (fd->methods->send)(fd, buf, amount, flags, timeout); }
+
+PRInt32 RCNetStreamIO::Sendto(
+    const void *buf, PRSize amount, PRIntn flags,
+    const RCNetAddr& addr, const RCInterval& timeout)
+    { return (fd->methods->sendto)(fd, buf, amount, flags, addr, timeout); }
+
+PRStatus RCNetStreamIO::SetSocketOption(const PRSocketOptionData *data)
+    { return (fd->methods->setsocketoption)(fd, data); }
+
+PRStatus RCNetStreamIO::Shutdown(RCIO::ShutdownHow how)
+    { return (fd->methods->shutdown)(fd, (PRIntn)how); }
+
+PRInt32 RCNetStreamIO::TransmitFile(
+    RCIO *source, const void *headers, PRSize hlen,
+    RCIO::FileDisposition flags, const RCInterval& timeout)
+{
+    RCNetStreamIO *src = (RCNetStreamIO*)source;
+    return (fd->methods->transmitfile)(
+        fd, src->fd, headers, hlen, (PRTransmitFileFlags)flags, timeout); }
+
+PRInt32 RCNetStreamIO::Write(const void *buf, PRSize amount)
+    { return (fd->methods->write)(fd, buf, amount); }
+
+PRInt32 RCNetStreamIO::Writev(
+    const PRIOVec *iov, PRSize size, const RCInterval& timeout)
+    { return (fd->methods->writev)(fd, iov, size, timeout); }
+    
+/*
+** Invalid functions
+*/
+
+PRStatus RCNetStreamIO::Close()
+    { PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
+
+PRStatus RCNetStreamIO::FileInfo(RCFileInfo*) const
+    { PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
+
+PRStatus RCNetStreamIO::Fsync()
+    { return (fd->methods->fsync)(fd); }
+
+PRStatus RCNetStreamIO::Open(const char*, PRIntn, PRIntn)
+    { PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
+
+PRInt64 RCNetStreamIO::Seek(PRInt64, RCIO::Whence)
+    { PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
+
+/* RCNetStreamIO.cpp */
+
+
diff --git a/pr/src/cplus/rcnetio.h b/pr/src/cplus/rcnetio.h
new file mode 100644
index 0000000..44b8bf0
--- /dev/null
+++ b/pr/src/cplus/rcnetio.h
@@ -0,0 +1,94 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** Subclass definitions for network I/O (ref: prio.h)
+*/
+
+#if defined(_RCNETIO_H)
+#else
+#define _RCNETIO_H
+
+#include "rcbase.h"
+#include "rcinrval.h"
+#include "rcio.h"
+#include "rcnetdb.h"
+
+#include "prio.h"
+
+class RCFileInfo;
+
+/*
+** Class: RCNetStreamIO (ref prio.h)
+**
+** Streamed (reliable) network I/O (e.g., TCP).
+** This class hides (makes private) the functions that are not applicable
+** to network I/O (i.e., those for file I/O).
+*/
+
+class PR_IMPLEMENT(RCNetStreamIO): public RCIO
+{
+
+public:
+    RCNetStreamIO();
+    virtual ~RCNetStreamIO();
+
+    virtual RCIO*       Accept(RCNetAddr* addr, const RCInterval& timeout);
+    virtual PRInt32     AcceptRead(
+                            RCIO **nd, RCNetAddr **raddr, void *buf,
+                            PRSize amount, const RCInterval& timeout);
+    virtual PRInt64     Available();
+    virtual PRStatus    Bind(const RCNetAddr& addr);
+    virtual PRStatus    Connect(
+                            const RCNetAddr& addr, const RCInterval& timeout);
+    virtual PRStatus    GetLocalName(RCNetAddr *addr) const;
+    virtual PRStatus    GetPeerName(RCNetAddr *addr) const;
+    virtual PRStatus    GetSocketOption(PRSocketOptionData *data) const;
+    virtual PRStatus    Listen(PRIntn backlog);
+    virtual PRInt16     Poll(PRInt16 in_flags, PRInt16 *out_flags);
+    virtual PRInt32     Read(void *buf, PRSize amount);
+    virtual PRInt32     Recv(
+                            void *buf, PRSize amount, PRIntn flags,
+                            const RCInterval& timeout);
+    virtual PRInt32     Recvfrom(
+                            void *buf, PRSize amount, PRIntn flags,
+                            RCNetAddr* addr, const RCInterval& timeout);
+    virtual PRInt32     Send(
+                            const void *buf, PRSize amount, PRIntn flags,
+                            const RCInterval& timeout);
+    virtual PRInt32     Sendto(
+                            const void *buf, PRSize amount, PRIntn flags,
+                            const RCNetAddr& addr,
+                            const RCInterval& timeout);
+    virtual PRStatus    SetSocketOption(const PRSocketOptionData *data);
+    virtual PRStatus    Shutdown(ShutdownHow how);
+    virtual PRInt32     TransmitFile(
+                            RCIO *source, const void *headers,
+                            PRSize hlen, RCIO::FileDisposition flags,
+                            const RCInterval& timeout);
+    virtual PRInt32     Write(const void *buf, PRSize amount);
+    virtual PRInt32     Writev(
+                            const PRIOVec *iov, PRSize size,
+                            const RCInterval& timeout);
+
+private:
+    /* functions unavailable to this clients of this class */
+    RCNetStreamIO(const RCNetStreamIO&);
+
+    PRStatus    Close();
+    PRStatus    Open(const char *name, PRIntn flags, PRIntn mode);
+    PRStatus    FileInfo(RCFileInfo *info) const;
+    PRStatus    Fsync();
+    PRInt64     Seek(PRInt64 offset, RCIO::Whence how);
+
+public:
+    RCNetStreamIO(PRIntn protocol);
+};  /* RCNetIO */
+
+#endif /* defined(_RCNETIO_H) */
+
+/* RCNetStreamIO.h */
+
+
diff --git a/pr/src/cplus/rcthread.cpp b/pr/src/cplus/rcthread.cpp
new file mode 100755
index 0000000..3db00d3
--- /dev/null
+++ b/pr/src/cplus/rcthread.cpp
@@ -0,0 +1,188 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* RCThread.cpp - C++ wrapper on NSPR */
+
+#include "rcthread.h"
+#include "rcinrval.h"
+
+#include <prmem.h>
+#include <prlog.h>
+#include <stdio.h>
+#include <prinit.h>
+
+static RCPrimordialThread *primordial = NULL;
+
+void nas_Root(void *arg)
+{
+    RCThread *him = (RCThread*)arg;
+    while (RCThread::ex_unstarted == him->execution)
+        (void)PR_Sleep(PR_INTERVAL_NO_TIMEOUT);  /* wait for Start() */
+    him->RootFunction();  /* he gets a self reference */
+    if (PR_UNJOINABLE_THREAD == PR_GetThreadState(him->identity))
+        delete him;
+}  /* nas_Root */
+
+RCThread::~RCThread() { }
+
+RCThread::RCThread(): RCBase() { }
+
+RCThread::RCThread(const RCThread&): RCBase()
+{
+    PR_NOT_REACHED("Cannot call thread copy constructor");
+}  /* RCThread::RCThread */
+
+RCThread::RCThread(
+    RCThread::Scope scope, RCThread::State join, PRUint32 stackSize):
+    RCBase()
+{
+    execution = ex_unstarted;
+    identity = PR_CreateThread(
+        PR_USER_THREAD, nas_Root, this,
+        PR_GetThreadPriority(PR_GetCurrentThread()),
+        (PRThreadScope)scope, (PRThreadState)join, stackSize);
+}  /* RCThread::RCThread */
+
+void RCThread::operator=(const RCThread&)
+{
+    PR_NOT_REACHED("Cannot call thread assignment operator");
+}  /* RCThread::operator= */
+
+
+PRStatus RCThread::Start()
+{
+    PRStatus rv;
+    /* This is an unsafe check, but not too critical */
+    if (RCThread::ex_unstarted == execution)
+    {
+        execution = RCThread::ex_started;
+        rv = PR_Interrupt(identity);
+        PR_ASSERT(PR_SUCCESS == rv);
+    }
+    else
+    {
+        rv = PR_FAILURE;
+        PR_SetError(PR_INVALID_STATE_ERROR, 0);
+    }
+    return rv;
+}  /* RCThread::Start */
+
+PRStatus RCThread::Join()
+{
+    PRStatus rv;
+    if (RCThread::ex_unstarted == execution)
+    {
+        rv = PR_FAILURE;
+        PR_SetError(PR_INVALID_STATE_ERROR, 0);
+    }
+    else rv = PR_JoinThread(identity);
+    if (PR_SUCCESS == rv) delete this;
+    return rv;
+}  /* RCThread::Join */
+
+PRStatus RCThread::Interrupt()
+{
+    PRStatus rv;
+    if (RCThread::ex_unstarted == execution)
+    {
+        rv = PR_FAILURE;
+        PR_SetError(PR_INVALID_STATE_ERROR, 0);
+    }
+    else rv = PR_Interrupt(identity);
+    return rv;
+}  /* RCThread::Interrupt */
+
+void RCThread::ClearInterrupt() { PR_ClearInterrupt(); }
+
+void RCThread::SetPriority(RCThread::Priority new_priority)
+    { PR_SetThreadPriority(identity, (PRThreadPriority)new_priority); }
+
+PRThread *RCThread::Self()
+    { return PR_GetCurrentThread(); }
+
+RCThread::Scope RCThread::GetScope() const
+    { return (RCThread::Scope)PR_GetThreadScope(identity); }
+
+RCThread::State RCThread::GetState() const
+    { return (RCThread::State)PR_GetThreadState(identity); }
+
+RCThread::Priority RCThread::GetPriority() const
+    { return (RCThread::Priority)PR_GetThreadPriority(identity); }
+    
+static void _rc_PDDestructor(RCThreadPrivateData* privateData)
+{
+    PR_ASSERT(NULL != privateData);
+    privateData->Release();
+}
+
+static PRThreadPrivateDTOR _tpd_dtor = (PRThreadPrivateDTOR)_rc_PDDestructor;
+
+PRStatus RCThread::NewPrivateIndex(PRUintn* index)
+    { return PR_NewThreadPrivateIndex(index, _tpd_dtor); }
+
+PRStatus RCThread::SetPrivateData(PRUintn index)
+    { return PR_SetThreadPrivate(index, NULL); }
+
+PRStatus RCThread::SetPrivateData(PRUintn index, RCThreadPrivateData* data)
+{
+    return PR_SetThreadPrivate(index, data);
+}
+
+RCThreadPrivateData* RCThread::GetPrivateData(PRUintn index)
+    { return (RCThreadPrivateData*)PR_GetThreadPrivate(index); }
+
+PRStatus RCThread::Sleep(const RCInterval& ticks)
+    { PRIntervalTime tmo = ticks; return PR_Sleep(tmo); }
+
+RCPrimordialThread *RCThread::WrapPrimordialThread()
+{
+    /*
+    ** This needs to take more care in insuring that the thread
+    ** being wrapped is really the primordial thread. This code
+    ** is assuming that the caller is the primordial thread, and
+    ** there's nothing to insure that.
+    */
+    if (NULL == primordial)
+    {
+        /* it doesn't have to be perfect */
+        RCPrimordialThread *me = new RCPrimordialThread();
+        PR_ASSERT(NULL != me);
+        if (NULL == primordial)
+        {
+            primordial = me;
+            me->execution = RCThread::ex_started;
+            me->identity = PR_GetCurrentThread();
+        }
+        else delete me;  /* somebody beat us to it */
+    }
+    return primordial;
+}  /* RCThread::WrapPrimordialThread */
+
+RCPrimordialThread::RCPrimordialThread(): RCThread() { }
+
+RCPrimordialThread::~RCPrimordialThread() { }
+
+void RCPrimordialThread::RootFunction()
+{
+    PR_NOT_REACHED("Primordial thread calling root function"); 
+}  /* RCPrimordialThread::RootFunction */
+ 
+PRStatus RCPrimordialThread::Cleanup() { return PR_Cleanup(); }
+
+PRStatus RCPrimordialThread::SetVirtualProcessors(PRIntn count)
+{
+    PR_SetConcurrency(count);
+    return PR_SUCCESS;
+}  /* SetVirutalProcessors */
+
+RCThreadPrivateData::RCThreadPrivateData() { }
+
+RCThreadPrivateData::RCThreadPrivateData(
+    const RCThreadPrivateData& him) { }
+
+RCThreadPrivateData::~RCThreadPrivateData() { }
+
+/* RCThread.c */
+
diff --git a/pr/src/cplus/rcthread.h b/pr/src/cplus/rcthread.h
new file mode 100644
index 0000000..8683c0a
--- /dev/null
+++ b/pr/src/cplus/rcthread.h
@@ -0,0 +1,195 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* RCThread.h */
+
+#if defined(_RCTHREAD_H)
+#else
+#define _RCTHREAD_H
+
+#include "rcbase.h"
+
+#include <prthread.h>
+
+class RCInterval;
+
+class PR_IMPLEMENT(RCThreadPrivateData)
+{
+public:
+    RCThreadPrivateData();
+    RCThreadPrivateData(const RCThreadPrivateData&);
+
+    virtual ~RCThreadPrivateData();
+
+    virtual void Release() = 0;
+
+};  /* RCThreadPrivateData */
+
+class PR_IMPLEMENT(RCThread): public RCBase
+{
+public:
+
+    typedef enum 
+    {
+        local = PR_LOCAL_THREAD, global = PR_GLOBAL_THREAD
+    } Scope;
+
+    typedef enum
+    {
+        joinable = PR_JOINABLE_THREAD, unjoinable = PR_UNJOINABLE_THREAD
+    } State;
+
+    typedef enum
+    {
+        first = PR_PRIORITY_FIRST,
+        low = PR_PRIORITY_LOW,
+        normal = PR_PRIORITY_NORMAL,
+        high = PR_PRIORITY_HIGH,
+        urgent = PR_PRIORITY_URGENT,
+        last = PR_PRIORITY_LAST
+    } Priority;
+
+    /*
+     * Create a new thread, providing scope and joinability state.
+     */
+    RCThread(Scope scope, State state, PRUint32 stackSize=0);
+
+    /*
+     * New threads are created in a suspended state. It must be 'started"
+     * before it begins execution in the class' defined 'RootFunction()'.
+     */
+    virtual PRStatus Start();
+
+    /*
+     * If a thread is created joinable, then the thread's object exists
+     * until join is called. The thread that calls join will block until
+     * the target thread returns from it's root function.
+     */
+    virtual PRStatus Join();
+    
+    /*
+     * The priority of a newly created thread is the same as the creator.
+     * The priority may be changed either by the new thread itself, by
+     * the creator or any other arbitrary thread.
+     */   
+    virtual void SetPriority(Priority newPriority);
+
+
+    /*
+     * Interrupt another thread, causing it to stop what it
+     * is doing and return with a well known error code.
+     */
+    virtual PRStatus Interrupt();
+    
+    /*
+     * And in case a thread was interrupted and didn't get a chance
+     * to have the notification delivered, a way to cancel the pending
+     * status.
+     */
+    static void ClearInterrupt();
+    
+    /*
+     * Methods to discover the attributes of an existing thread.
+     */
+    static PRThread *Self();
+    Scope GetScope() const;
+    State GetState() const;
+    Priority GetPriority() const;
+
+    /*
+     * Thread private data
+     */
+    static PRStatus NewPrivateIndex(PRUintn* index);
+
+    /*
+     * Getting it - if you want to modify, make a copy
+     */
+    static RCThreadPrivateData* GetPrivateData(PRUintn index);
+
+    /*
+     * Setting it to <empty> - deletes existing data
+     */
+    static PRStatus SetPrivateData(PRUintn index);
+
+    /*
+     * Setting it - runtime will make a copy, freeing old iff necessary
+     */
+    static PRStatus SetPrivateData(PRUintn index, RCThreadPrivateData* data);
+
+    /*
+     * Scheduling control
+     */
+    static PRStatus Sleep(const RCInterval& ticks);
+
+    friend void nas_Root(void*);
+    friend class RCPrimordialThread;
+protected:
+
+    /*
+     * The instantiator of a class must not call the destructor. The base
+     * implementation of Join will, and if the thread is created unjoinable,
+     * then the code that called the RootFunction will call the desctructor.
+     */
+    virtual ~RCThread();
+
+private:
+
+    /*
+     * This is where a newly created thread begins execution. Returning
+     * from this function is equivalent to terminating the thread.
+     */
+    virtual void RootFunction() = 0;
+
+    PRThread *identity;
+
+    /* Threads are unstarted until started - pretty startling */
+    enum {ex_unstarted, ex_started} execution;
+
+    /* There is no public default constructor or copy constructor */
+    RCThread();
+    RCThread(const RCThread&);
+    
+    /* And there is no assignment operator */
+    void operator=(const RCThread&);
+
+public:
+    static RCPrimordialThread *WrapPrimordialThread();    
+
+ };
+ 
+/*
+** class RCPrimordialThread
+*/
+class PR_IMPLEMENT(RCPrimordialThread): public RCThread
+{
+public:
+    /*
+    ** The primordial thread can (optionally) wait for all created
+    ** threads to terminate before allowing the process to exit.
+    ** Not calling Cleanup() before returning from main() will cause
+    ** the immediate termination of the entire process, including
+    ** any running threads.
+    */
+    static PRStatus Cleanup();
+
+    /*
+    ** Only the primordial thread is allowed to adjust the number of
+    ** virtual processors of the runtime. It's a lame security thing.
+    */
+    static PRStatus SetVirtualProcessors(PRIntn count=10);
+
+friend class RCThread;
+private:
+    /*
+    ** None other than the runtime can create of destruct
+    ** a primordial thread. It is fabricated by the runtime
+    ** to wrap the thread that initiated the application.
+    */
+    RCPrimordialThread();
+    ~RCPrimordialThread();
+    void RootFunction();
+};  /* RCPrimordialThread */
+
+ #endif /* defined(_RCTHREAD_H) */
diff --git a/pr/src/cplus/rctime.cpp b/pr/src/cplus/rctime.cpp
new file mode 100644
index 0000000..d655104
--- /dev/null
+++ b/pr/src/cplus/rctime.cpp
@@ -0,0 +1,34 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** Class implementation for calendar time routines (ref: prtime.h)
+*/
+
+#include "rctime.h"
+
+RCTime::~RCTime() { }
+
+RCTime::RCTime(PRTime time): RCBase() { gmt = time; }
+RCTime::RCTime(const RCTime& his): RCBase() { gmt = his.gmt; }
+RCTime::RCTime(RCTime::Current): RCBase() { gmt = PR_Now(); }
+RCTime::RCTime(const PRExplodedTime& time): RCBase()
+{ gmt = PR_ImplodeTime(&time); }
+
+void RCTime::operator=(const PRExplodedTime& time)
+{ gmt = PR_ImplodeTime(&time); }
+
+RCTime RCTime::operator+(const RCTime& his)
+{ RCTime sum(gmt + his.gmt); return sum; }
+
+RCTime RCTime::operator-(const RCTime& his)
+{ RCTime difference(gmt - his.gmt); return difference; }
+
+RCTime RCTime::operator/(PRUint64 his)
+{ RCTime quotient(gmt / gmt); return quotient; }
+
+RCTime RCTime::operator*(PRUint64 his)
+{ RCTime product(gmt * his); return product; }
+
diff --git a/pr/src/cplus/rctime.h b/pr/src/cplus/rctime.h
new file mode 100644
index 0000000..4cf7b90
--- /dev/null
+++ b/pr/src/cplus/rctime.h
@@ -0,0 +1,106 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** Class definitions for calendar time routines (ref: prtime.h)
+*/
+
+#if defined(_RCTIME_H)
+#else
+#define _RCTIME_H
+
+#include "rcbase.h"
+
+#include <prtime.h>
+
+/*
+** Class: RCTime (ref: prtime.h)
+**
+** RCTimes are objects that are intended to be used to represent calendar
+** times. They maintain units internally as microseconds since the defined
+** epoch (midnight, January 1, 1970, GMT). Conversions to and from external
+** formats (PRExplodedTime) are available.
+**
+** In general, NCTimes possess normal algebretic capabilities.
+*/
+
+class PR_IMPLEMENT(RCTime): public RCBase
+{
+public:
+    typedef enum {now} Current;
+
+    RCTime();                       /* leaves the object unitialized */
+    RCTime(Current);                /* initializes to current system time */
+    RCTime(const RCTime&);          /* copy constructor */
+    RCTime(const PRExplodedTime&);  /* construction from exploded representation */
+
+    virtual ~RCTime();
+
+    /* assignment operators */
+    void operator=(const RCTime&); 
+    void operator=(const PRExplodedTime&);
+
+    /* comparitive operators */
+    PRBool operator<(const RCTime&);
+    PRBool operator>(const RCTime&);
+    PRBool operator<=(const RCTime&);
+    PRBool operator>=(const RCTime&);
+    PRBool operator==(const RCTime&);
+
+    /* associative operators */
+    RCTime operator+(const RCTime&);
+    RCTime operator-(const RCTime&);
+    RCTime& operator+=(const RCTime&);
+    RCTime& operator-=(const RCTime&);
+
+    /* multiply and divide operators */
+    RCTime operator/(PRUint64);
+    RCTime operator*(PRUint64);
+    RCTime& operator/=(PRUint64);
+    RCTime& operator*=(PRUint64);
+
+    void Now();                     /* assign current time to object */
+
+private:
+    PRTime gmt;
+
+public:
+
+    RCTime(PRTime);                 /* construct from raw PRTime */
+    void operator=(PRTime);         /* assign from raw PRTime */
+    operator PRTime() const;        /* extract internal representation */
+};  /* RCTime */
+
+inline RCTime::RCTime(): RCBase() { }
+
+inline void RCTime::Now() { gmt = PR_Now(); }
+inline RCTime::operator PRTime() const { return gmt; }
+
+inline void RCTime::operator=(PRTime his) { gmt = his; }
+inline void RCTime::operator=(const RCTime& his) { gmt = his.gmt; }
+
+inline PRBool RCTime::operator<(const RCTime& his)
+    { return (gmt < his.gmt) ? PR_TRUE : PR_FALSE; }
+inline PRBool RCTime::operator>(const RCTime& his)
+    { return (gmt > his.gmt) ? PR_TRUE : PR_FALSE; }
+inline PRBool RCTime::operator<=(const RCTime& his)
+    { return (gmt <= his.gmt) ? PR_TRUE : PR_FALSE; }
+inline PRBool RCTime::operator>=(const RCTime& his)
+    { return (gmt >= his.gmt) ? PR_TRUE : PR_FALSE; }
+inline PRBool RCTime::operator==(const RCTime& his)
+    { return (gmt == his.gmt) ? PR_TRUE : PR_FALSE; }
+
+inline RCTime& RCTime::operator+=(const RCTime& his)
+    { gmt += his.gmt; return *this; }
+inline RCTime& RCTime::operator-=(const RCTime& his)
+    { gmt -= his.gmt; return *this; }
+inline RCTime& RCTime::operator/=(PRUint64 his)
+    { gmt /= his; return *this; }
+inline RCTime& RCTime::operator*=(PRUint64 his)
+    { gmt *= his; return *this; }
+
+#endif /* defined(_RCTIME_H) */
+
+/* RCTime.h */
diff --git a/pr/src/cplus/tests/.cvsignore b/pr/src/cplus/tests/.cvsignore
new file mode 100644
index 0000000..f3c7a7c
--- /dev/null
+++ b/pr/src/cplus/tests/.cvsignore
@@ -0,0 +1 @@
+Makefile
diff --git a/pr/src/cplus/tests/Makefile.in b/pr/src/cplus/tests/Makefile.in
new file mode 100644
index 0000000..c164238
--- /dev/null
+++ b/pr/src/cplus/tests/Makefile.in
@@ -0,0 +1,221 @@
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+#! gmake
+
+MOD_DEPTH	= ../../../..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+
+include $(MOD_DEPTH)/config/autoconf.mk
+
+include $(topsrcdir)/config/config.mk
+
+ifeq ($(OS_TARGET), WIN16)
+OS_CFLAGS = $(OS_EXE_CFLAGS)
+endif
+
+CXXSRCS =           \
+	ranfile.cpp     \
+	thread.cpp      \
+	interval.cpp    \
+	time.cpp        \
+	fileio.cpp      \
+	switch.cpp      \
+	tpd.cpp         \
+	$(NULL)
+
+OBJS = $(addprefix $(OBJDIR)/,$(CXXSRCS:.cpp=.$(OBJ_SUFFIX)))
+
+ifeq (,$(filter-out WINNT OS2,$(OS_ARCH)))
+PROG_SUFFIX = .exe
+else
+PROG_SUFFIX =
+endif
+
+PROGS = $(addprefix $(OBJDIR)/, $(CXXSRCS:.cpp=$(PROG_SUFFIX)))
+
+TARGETS = $(PROGS) $(OBJS)
+
+INCLUDES = -I.. -I$(dist_includedir)
+
+# Setting the variables LDOPTS and LIBPR.  We first initialize
+# them to the default values, then adjust them for some platforms.
+LDOPTS = -L$(dist_libdir)
+LIBPR = -lnspr$(MOD_MAJOR_VERSION)
+LIBPL = -lplc$(MOD_MAJOR_VERSION)
+
+ifeq ($(OS_ARCH), IRIX)
+    LDOPTS += -rpath $(PWD)/$(dist_libdir) -rdata_shared
+    # For 6.x machines, include this flag
+    ifeq ($(basename $(OS_RELEASE)),6)
+        ifeq ($(USE_N32),1)
+            LDOPTS += -n32
+        else
+            LDOPTS += -32
+        endif
+
+        ifeq ($(USE_PTHREADS), 1)
+            ifeq ($(OS_RELEASE), 6.2)
+                LDOPTS += -Wl,-woff,85
+            endif
+        endif
+    endif
+endif
+
+# Solaris
+ifeq ($(OS_ARCH), SunOS)
+    ifdef NS_USE_GCC
+        LDOPTS += -Xlinker -R -Xlinker $(PWD)/$(dist_libdir)
+    else
+        LDOPTS += -R $(PWD)/$(dist_libdir)
+    endif
+
+# SunOS 5.5 needs to link with -lpthread, even though we already
+# linked with this system library when we built libnspr.so.
+    ifeq ($(OS_RELEASE), 5.5)
+        ifdef USE_PTHREADS
+            EXTRA_LIBS = -lpthread
+        endif
+    endif
+endif # SunOS
+
+ifeq ($(OS_ARCH), WINNT)
+ifeq ($(OS_TARGET), WIN16)
+  LIBPR = $(dist_libdir)/nspr$(MOD_MAJOR_VERSION).lib
+  LIBPL = $(dist_libdir)/plc$(MOD_MAJOR_VERSION).lib
+else
+  LDOPTS = -NOLOGO -DEBUG -INCREMENTAL:NO
+  LIBPR = $(dist_libdir)/libnspr$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)
+  LIBPL = $(dist_libdir)/libplc$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)
+endif
+endif
+
+ifeq ($(OS_ARCH),OS2)
+LDOPTS += -Zomf -Zlinker /PM:VIO -lstdcpp
+endif
+
+ifneq ($(OS_ARCH), WINNT)
+PWD = $(shell pwd)
+endif
+
+ifeq ($(OS_ARCH), OSF1)
+LDOPTS += -rpath $(PWD)/$(dist_libdir)
+endif
+
+ifeq ($(OS_ARCH), HP-UX)
+    LDOPTS += -Wl,+s,+b,$(PWD)/$(dist_libdir)
+endif
+
+# AIX
+ifeq ($(OS_ARCH),AIX)
+    LDOPTS += -blibpath:$(PWD)/$(dist_libdir):/usr/lib:/lib
+    ifeq ($(OS_ARCH)$(OS_RELEASE),AIX4.1)
+        LIBPR = -lnspr$(MOD_MAJOR_VERSION)_shr
+        LIBPLC = -lplc$(MOD_MAJOR_VERSION)_shr
+    else
+        LDOPTS += -brtl
+        EXTRA_LIBS = -ldl
+    endif
+endif
+
+ifeq ($(OS_ARCH), Linux)
+    ifeq ($(OS_RELEASE), 1.2)
+        EXTRA_LIBS = -ldl
+    else
+        LDOPTS += -Xlinker -rpath $(PWD)/$(dist_libdir)
+        ifeq ($(USE_PTHREADS),1)
+            EXTRA_LIBS = -lpthread
+        endif
+    endif
+endif
+
+ifeq ($(OS_ARCH), SCO_SV)
+# SCO Unix needs to link against -lsocket again even though we
+# already linked with these system libraries when we built libnspr.so.
+EXTRA_LIBS = -lsocket
+# This hardcodes in the executable programs the directory to find
+# libnspr.so etc. at program startup.  Equivalent to the -R or -rpath
+# option for ld on other platforms.
+export LD_RUN_PATH = $(PWD)/$(dist_libdir)
+endif
+
+ifeq ($(OS_ARCH), UNIXWARE)
+export LD_RUN_PATH = $(PWD)/$(dist_libdir)
+endif
+
+#####################################################
+#
+# The rules
+#
+#####################################################
+
+include $(topsrcdir)/config/rules.mk
+
+AIX_PRE_4_2 = 0
+ifeq ($(OS_ARCH),AIX)
+ifneq ($(OS_RELEASE),4.2)
+ifneq ($(USE_PTHREADS), 1)
+#AIX_PRE_4_2 = 1
+endif
+endif
+endif
+
+ifeq ($(AIX_PRE_4_2),1)
+
+# AIX releases prior to 4.2 need a special two-step linking hack
+# in order to both override the system select() and be able to 
+# get at the original system select().
+#
+# We use a pattern rule in ns/nspr20/config/rules.mk to generate
+# the .$(OBJ_SUFFIX) file from the .c source file, then do the
+# two-step linking hack below.
+
+$(OBJDIR)/%: $(OBJDIR)/%.$(OBJ_SUFFIX)
+	@$(MAKE_OBJDIR)
+	rm -f $@ $(AIX_TMP)
+	$(CC) $(AIX_LINK_OPTS) -o $(AIX_TMP) $< $(dist_libdir)/libnspr$(MOD_MAJOR_VERSION).a
+	$(CC) -o $@ $(AIX_TMP) $(AIX_WRAP)
+	rm -f $(AIX_TMP)
+
+else
+
+# All platforms that are not AIX pre-4.2.
+
+$(OBJDIR)/%$(PROG_SUFFIX): $(OBJDIR)/%.$(OBJ_SUFFIX)
+	@$(MAKE_OBJDIR)
+ifeq ($(OS_ARCH), WINNT)
+ifeq ($(OS_TARGET),WIN16)
+	echo system windows         >w16link
+	echo option map             >>w16link
+	echo option stack=10K       >>w16link
+	echo option heapsize=32K    >>w16link
+	echo debug $(DEBUGTYPE) all >>w16link
+	echo name $@                >>w16link
+	echo file                   >>w16link
+	echo $<                     >>w16link
+	echo library                >>w16link
+	echo $(LIBPR),	            >>w16link
+	echo $(LIBPL),	            >>w16link
+	echo winsock.lib            >>w16link
+	wlink @w16link.
+else
+	link $(LDOPTS) $< $(LIBPR) $(LIBPL) ws2_32.lib -out:$@
+endif
+else
+ifeq ($(OS_ARCH),OS2)
+	$(LINK) $(LDOPTS) $< $(LIBGC) $(LIBPLC) $(LIBPR) $(OS_LIBS) $(EXTRA_LIBS) -o $@
+else
+	$(CCC) $(XCFLAGS) $< $(LDOPTS) $(LIBPR) $(LIBPL) $(EXTRA_LIBS) -o $@
+endif
+endif
+endif
+
+export:: $(TARGETS)
+clean::
+	rm -f $(TARGETS)
+
diff --git a/pr/src/cplus/tests/fileio.cpp b/pr/src/cplus/tests/fileio.cpp
new file mode 100644
index 0000000..fdffe99
--- /dev/null
+++ b/pr/src/cplus/tests/fileio.cpp
@@ -0,0 +1,33 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* fileio.cpp - a test program */
+
+#include "rcfileio.h"
+
+#include <prlog.h>
+#include <prprf.h>
+
+#define DEFAULT_ITERATIONS 100
+
+PRIntn main(PRIntn argc, char **argv)
+{
+    PRStatus rv;
+    RCFileIO fd;
+    RCFileInfo info;
+    rv = fd.Open("filio.dat", PR_CREATE_FILE, 0666);
+    PR_ASSERT(PR_SUCCESS == rv);
+    rv = fd.FileInfo(&info);
+    PR_ASSERT(PR_SUCCESS == rv);
+    rv = fd.Delete("filio.dat");
+    PR_ASSERT(PR_SUCCESS == rv);
+    fd.Close();
+    PR_ASSERT(PR_SUCCESS == rv);
+
+    return 0;
+}  /* main */
+
+/* interval.cpp */
+
diff --git a/pr/src/cplus/tests/interval.cpp b/pr/src/cplus/tests/interval.cpp
new file mode 100644
index 0000000..8acf506
--- /dev/null
+++ b/pr/src/cplus/tests/interval.cpp
@@ -0,0 +1,101 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* interval.cpp - a test program */
+
+#include "rclock.h"
+#include "rcthread.h"
+#include "rcinrval.h"
+#include "rccv.h"
+
+#include <prio.h>
+#include <prlog.h>
+#include <prprf.h>
+
+#define DEFAULT_ITERATIONS 100
+
+PRIntn main(PRIntn argc, char **argv)
+{
+    RCLock ml;
+    PRStatus rv;
+    RCCondition cv(&ml);
+
+    RCInterval now, timeout, epoch, elapsed;
+    PRFileDesc *output = PR_GetSpecialFD(PR_StandardOutput);
+    PRIntn msecs, seconds, loops, iterations = DEFAULT_ITERATIONS;
+
+    /* slow, agonizing waits */
+    for (seconds = 0; seconds < 10; ++seconds)
+    {
+        timeout = RCInterval::FromSeconds(seconds);
+        cv.SetTimeout(timeout);
+        {
+            RCEnter lock(&ml);
+
+            epoch.SetToNow();
+
+            rv = cv.Wait();
+            PR_ASSERT(PR_SUCCESS == rv);
+
+            now = RCInterval(RCInterval::now);
+            elapsed = now - epoch;
+        }
+
+        PR_fprintf(
+            output, "Waiting %u seconds took %s%u milliseconds\n",
+            seconds, ((elapsed < timeout)? "**" : ""),
+            elapsed.ToMilliseconds());
+    }
+
+    /* more slow, agonizing sleeps */
+    for (seconds = 0; seconds < 10; ++seconds)
+    {
+        timeout = RCInterval::FromSeconds(seconds);
+        {
+            epoch.SetToNow();
+
+            rv = RCThread::Sleep(timeout);
+            PR_ASSERT(PR_SUCCESS == rv);
+
+            now = RCInterval(RCInterval::now);
+            elapsed = now - epoch;
+        }
+
+        PR_fprintf(
+            output, "Sleeping %u seconds took %s%u milliseconds\n",
+            seconds, ((elapsed < timeout)? "**" : ""),
+            elapsed.ToMilliseconds());
+    }
+
+    /* fast, spritely little devils */
+    for (msecs = 10; msecs < 100; msecs += 10)
+    {
+        timeout = RCInterval::FromMilliseconds(msecs);
+        cv.SetTimeout(timeout);
+        {
+            RCEnter lock(&ml);
+
+            epoch.SetToNow();
+
+            for (loops = 0; loops < iterations; ++loops)
+            {
+                rv = cv.Wait();
+                PR_ASSERT(PR_SUCCESS == rv);
+            }
+
+            now = RCInterval(RCInterval::now);
+            elapsed = now - epoch;
+        }
+        elapsed /= iterations;
+
+        PR_fprintf(
+            output, "Waiting %u msecs took %s%u milliseconds average\n",
+            msecs, ((elapsed < timeout)? "**" : ""), elapsed.ToMilliseconds());
+    }
+    return 0;
+}  /* main */
+
+/* interval.cpp */
+
diff --git a/pr/src/cplus/tests/ranfile.cpp b/pr/src/cplus/tests/ranfile.cpp
new file mode 100644
index 0000000..c3ac0d3
--- /dev/null
+++ b/pr/src/cplus/tests/ranfile.cpp
@@ -0,0 +1,400 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/***********************************************************************
+**
+** Contact:     AOF<mailto:freier@netscape.com>
+**
+** Name: ranfile.c
+**
+** Description: Test to hammer on various components of NSPR
+** Modification History:
+** 20-May-97 AGarcia- Converted the test to accomodate the debug_mode flag.
+**	         The debug mode will print all of the printfs associated with this test.
+**			 The regress mode will be the default mode. Since the regress tool limits
+**           the output to a one line status:PASS or FAIL,all of the printf statements
+**			 have been handled with an if (debug_mode) statement.
+** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to
+**			recognize the return code from tha main program.
+***********************************************************************/
+
+
+/***********************************************************************
+** Includes
+***********************************************************************/
+/* Used to get the command line option */
+#include <plgetopt.h>
+#include <prprf.h>
+#include <prio.h>
+
+#include "rccv.h"
+#include "rcthread.h"
+#include "rcfileio.h"
+#include "rclock.h"
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+static PRFileDesc *output;
+static PRIntn debug_mode = 0;
+static PRIntn failed_already = 0;
+
+class HammerData
+{
+public:
+    typedef enum {
+        sg_go, sg_stop, sg_done} Action;
+    typedef enum {
+        sg_okay, sg_open, sg_close, sg_delete, sg_write, sg_seek} Problem;
+
+	virtual ~HammerData();
+	HammerData(RCLock* lock, RCCondition *cond, PRUint32 clip);
+    virtual PRUint32 Random();
+
+    Action action;
+    Problem problem;
+    PRUint32 writes;
+    RCInterval timein;
+friend class Hammer;
+private:
+    RCLock *ml;
+    RCCondition *cv;
+    PRUint32 limit;
+
+    PRFloat64 seed;
+};  /* HammerData */
+
+class Hammer: public HammerData, public RCThread
+{
+public:
+    virtual ~Hammer();
+    Hammer(RCThread::Scope scope, RCLock* lock, RCCondition *cond, PRUint32 clip);
+
+private:
+    void RootFunction();
+
+};
+
+static PRInt32 pageSize = 1024;
+static const char* baseName = "./";
+static const char *programName = "Random File";
+
+/***********************************************************************
+** PRIVATE FUNCTION:    Random
+** DESCRIPTION:
+**   Generate a pseudo-random number
+** INPUTS:      None
+** OUTPUTS:     None
+** RETURN:      A pseudo-random unsigned number, 32-bits wide
+** SIDE EFFECTS:
+**      Updates random seed (a static)
+** RESTRICTIONS:
+**      None
+** MEMORY:      NA
+** ALGORITHM:
+**      Uses the current interval timer value, promoted to a 64 bit
+**      float as a multiplier for a static residue (which begins
+**      as an uninitialized variable). The result is bits [16..48)
+**      of the product. Seed is then updated with the return value
+**      promoted to a float-64.
+***********************************************************************/
+PRUint32 HammerData::Random()
+{
+    PRUint32 rv;
+    PRUint64 shift;
+    RCInterval now = RCInterval(RCInterval::now);
+    PRFloat64 random = seed * (PRFloat64)((PRIntervalTime)now);
+    LL_USHR(shift, *((PRUint64*)&random), 16);
+    LL_L2UI(rv, shift);
+    seed = (PRFloat64)rv;
+    return rv;
+}  /* HammerData::Random */
+
+Hammer::~Hammer() { }
+
+Hammer::Hammer(
+    RCThread::Scope scope, RCLock* lock, RCCondition *cond, PRUint32 clip):
+	HammerData(lock, cond, clip), RCThread(scope, RCThread::joinable, 0) { }
+
+HammerData::~HammerData() { }
+
+HammerData::HammerData(RCLock* lock, RCCondition *cond, PRUint32 clip)
+{
+    ml = lock;
+    cv = cond;
+    writes = 0;
+    limit = clip;
+    seed = 0x58a9382;
+    action = HammerData::sg_go;
+    problem = HammerData::sg_okay;
+    timein = RCInterval(RCInterval::now);
+}  /* HammerData::HammerData */
+
+
+/***********************************************************************
+** PRIVATE FUNCTION:    Hammer::RootFunction
+** DESCRIPTION:
+**   Hammer on the file I/O system
+** INPUTS:      A pointer to the thread's private data
+** OUTPUTS:     None
+** RETURN:      None
+** SIDE EFFECTS:
+**      Creates, accesses and deletes a file
+** RESTRICTIONS:
+**      (Currently) must have file create permission in "/usr/tmp".
+** MEMORY:      NA
+** ALGORITHM:
+**      This function is a root of a thread
+**      1) Creates a (hopefully) unique file in /usr/tmp/
+**      2) Writes a zero to a random number of sequential pages
+**      3) Closes the file
+**      4) Reopens the file
+**      5) Seeks to a random page within the file
+**      6) Writes a one byte on that page
+**      7) Repeat steps [5..6] for each page in the file
+**      8) Close and delete the file
+**      9) Repeat steps [1..8] until told to stop
+**     10) Notify complete and return
+***********************************************************************/
+void Hammer::RootFunction()
+{
+    PRUint32 index;
+    RCFileIO file;
+    char filename[30];
+    const char zero = 0;
+    PRStatus rv = PR_SUCCESS;
+
+    limit = (Random() % limit) + 1;
+
+    (void)sprintf(filename, "%ssg%04p.dat", baseName, this);
+
+    if (debug_mode) PR_fprintf(output, "Starting work on %s\n", filename);
+
+    while (PR_TRUE)
+    {
+        PRUint64 bytes;
+        PRUint32 minor = (Random() % limit) + 1;
+        PRUint32 random = (Random() % limit) + 1;
+        PRUint32 pages = (Random() % limit) + 10;
+        while (minor-- > 0)
+        {
+            problem = sg_okay;
+            if (action != sg_go) goto finished;
+            problem = sg_open;
+            rv = file.Open(filename, PR_RDWR|PR_CREATE_FILE, 0666);
+            if (PR_FAILURE == rv) goto finished;
+            for (index = 0; index < pages; index++)
+            {
+                problem = sg_okay;
+                if (action != sg_go) goto close;
+                problem = sg_seek;
+                bytes = file.Seek(pageSize * index, RCFileIO::set);
+                if (bytes != pageSize * index) goto close;
+                problem = sg_write;
+                bytes = file.Write(&zero, sizeof(zero));
+                if (bytes <= 0) goto close;
+                writes += 1;
+            }
+            problem = sg_close;
+            rv = file.Close();
+            if (rv != PR_SUCCESS) goto purge;
+
+            problem = sg_okay;
+            if (action != sg_go) goto purge;
+
+            problem = sg_open;
+            rv = file.Open(filename, PR_RDWR, 0666);
+            if (PR_FAILURE == rv) goto finished;
+            for (index = 0; index < pages; index++)
+            {
+                problem = sg_okay;
+                if (action != sg_go) goto close;
+                problem = sg_seek;
+                bytes = file.Seek(pageSize * index, RCFileIO::set);
+                if (bytes != pageSize * index) goto close;
+                problem = sg_write;
+                bytes = file.Write(&zero, sizeof(zero));
+                if (bytes <= 0) goto close;
+                writes += 1;
+                random = (random + 511) % pages;
+            }
+            problem = sg_close;
+            rv = file.Close();
+            if (rv != PR_SUCCESS) goto purge;
+            problem = sg_delete;
+            rv = file.Delete(filename);
+            if (rv != PR_SUCCESS) goto finished;
+       }
+    }
+
+close:
+    (void)file.Close();
+purge:
+    (void)file.Delete(filename);
+finished:
+    RCEnter scope(ml);
+    action = HammerData::sg_done;
+    cv->Notify();
+
+    if (debug_mode) PR_fprintf(output, "Ending work on %s\n", filename);
+
+    return;
+}  /* Hammer::RootFunction */
+
+static Hammer* hammer[100];
+/***********************************************************************
+** PRIVATE FUNCTION:    main
+** DESCRIPTION:
+**   Hammer on the file I/O system
+** INPUTS:      The usual argc and argv
+**              argv[0] - program name (not used)
+**              argv[1] - the number of virtual_procs to execute the major loop
+**              argv[2] - the number of threads to toss into the batch
+**              argv[3] - the clipping number applied to randoms
+**              default values: max_virtual_procs = 2, threads = 10, limit = 57
+** OUTPUTS:     None
+** RETURN:      None
+** SIDE EFFECTS:
+**      Creates, accesses and deletes lots of files
+** RESTRICTIONS:
+**      (Currently) must have file create permission in "/usr/tmp".
+** MEMORY:      NA
+** ALGORITHM:
+**      1) Fork a "Thread()"
+**      2) Wait for 'interleave' seconds
+**      3) For [0..'threads') repeat [1..2]
+**      4) Mark all objects to stop
+**      5) Collect the threads, accumulating the results
+**      6) For [0..'max_virtual_procs') repeat [1..5]
+**      7) Print accumulated results and exit
+**
+**      Characteristic output (from IRIX)
+**          Random File: Using max_virtual_procs = 2, threads = 10, limit = 57
+**          Random File: [min [avg] max] writes/sec average
+***********************************************************************/
+PRIntn main (PRIntn argc, char *argv[])
+{
+    RCLock ml;
+	PLOptStatus os;
+    RCCondition cv(&ml);
+    PRUint32 writesMax = 0, durationTot = 0;
+    RCThread::Scope thread_scope = RCThread::local;
+    PRUint32 writes, writesMin = 0x7fffffff, writesTot = 0;
+    PRIntn active, poll, limit = 0, max_virtual_procs = 0, threads = 0, virtual_procs;
+    RCInterval interleave(RCInterval::FromMilliseconds(10000)), duration(0);
+
+    const char *where[] = {"okay", "open", "close", "delete", "write", "seek"};
+
+	PLOptState *opt = PL_CreateOptState(argc, argv, "Gdl:t:i:");
+	while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+    {
+		if (PL_OPT_BAD == os) continue;
+        switch (opt->option)
+        {
+	case 0:
+		baseName = opt->value;
+		break;
+        case 'G':  /* global threads */
+		thread_scope = RCThread::global;
+            break;
+        case 'd':  /* debug mode */
+			debug_mode = 1;
+            break;
+        case 'l':  /* limiting number */
+			limit = atoi(opt->value);
+            break;
+        case 't':  /* number of threads */
+			threads = atoi(opt->value);
+            break;
+        case 'i':  /* iteration counter */
+			max_virtual_procs = atoi(opt->value);
+            break;
+         default:
+            break;
+        }
+    }
+	PL_DestroyOptState(opt);
+    output = PR_GetSpecialFD(PR_StandardOutput);
+
+ /* main test */
+ 
+    cv.SetTimeout(interleave);
+	
+    if (max_virtual_procs == 0) max_virtual_procs = 2;
+    if (limit == 0) limit = 57;
+    if (threads == 0) threads = 10;
+
+    if (debug_mode) PR_fprintf(output,
+        "%s: Using %d virtual processors, %d threads, limit = %d and %s threads\n",
+        programName, max_virtual_procs, threads, limit,
+        (thread_scope == RCThread::local) ? "LOCAL" : "GLOBAL");
+
+    for (virtual_procs = 0; virtual_procs < max_virtual_procs; ++virtual_procs)
+    {
+        if (debug_mode)
+			PR_fprintf(output,
+				"%s: Setting number of virtual processors to %d\n",
+				programName, virtual_procs + 1);
+		RCPrimordialThread::SetVirtualProcessors(virtual_procs + 1);
+        for (active = 0; active < threads; active++)
+        {
+            hammer[active] = new Hammer(thread_scope, &ml, &cv, limit);
+            hammer[active]->Start();  /* then make it roll */
+            RCThread::Sleep(interleave);  /* start them slowly */
+        }
+
+        /*
+         * The last thread started has had the opportunity to run for
+         * 'interleave' seconds. Now gather them all back in.
+         */
+        {
+            RCEnter scope(&ml);
+            for (poll = 0; poll < threads; poll++)
+            {
+                if (hammer[poll]->action == HammerData::sg_go)  /* don't overwrite done */
+                    hammer[poll]->action = HammerData::sg_stop;  /* ask him to stop */
+            }
+        }
+
+        while (active > 0)
+        {
+            for (poll = 0; poll < threads; poll++)
+            {
+                ml.Acquire();
+                while (hammer[poll]->action < HammerData::sg_done) cv.Wait();
+                ml.Release();
+
+                if (hammer[poll]->problem == HammerData::sg_okay)
+                {
+                    duration = RCInterval(RCInterval::now) - hammer[poll]->timein;
+                    writes = hammer[poll]->writes * 1000 / duration;
+                    if (writes < writesMin)  writesMin = writes;
+                    if (writes > writesMax) writesMax = writes;
+                    writesTot += hammer[poll]->writes;
+                    durationTot += duration;
+                }
+                else
+                {
+                    if (debug_mode) PR_fprintf(output,
+                        "%s: test failed %s after %ld seconds\n",
+                        programName, where[hammer[poll]->problem], duration);
+					else failed_already=1;
+                }
+                active -= 1;  /* this is another one down */
+                (void)hammer[poll]->Join();
+                hammer[poll] = NULL;
+            }
+        }
+        if (debug_mode) PR_fprintf(output,
+            "%s: [%ld [%ld] %ld] writes/sec average\n",
+            programName, writesMin,
+            writesTot * 1000 / durationTot, writesMax);
+    }
+
+        failed_already |= (PR_FAILURE == RCPrimordialThread::Cleanup());
+	    PR_fprintf(output, "%s\n", (failed_already) ? "FAIL\n" : "PASS\n");
+		return failed_already;
+}  /* main */
diff --git a/pr/src/cplus/tests/switch.cpp b/pr/src/cplus/tests/switch.cpp
new file mode 100644
index 0000000..4cb14c4
--- /dev/null
+++ b/pr/src/cplus/tests/switch.cpp
@@ -0,0 +1,234 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** File:            switch.cpp
+** Description:     trying to time context switches
+*/
+
+#include "rccv.h"
+#include "rcinrval.h"
+#include "rclock.h"
+#include "rcthread.h"
+
+#include <prio.h>
+#include <prlog.h>
+#include <prprf.h>
+#include <plerror.h>
+#include <plgetopt.h>
+
+#include <stdlib.h>
+
+#define INNER_LOOPS 100
+#define DEFAULT_LOOPS 100
+#define DEFAULT_THREADS 10
+
+static PRFileDesc *debug_out = NULL;
+static PRBool debug_mode = PR_FALSE, verbosity = PR_FALSE, failed = PR_FALSE;
+
+class Home: public RCCondition
+{
+public:
+    virtual ~Home();
+    Home(Home *link, RCLock* ml);
+
+public:
+    Home *next;
+    RCLock* ml;
+    PRBool twiddle;
+};  /* Home */
+
+Home::~Home() { }
+
+Home::Home(Home *link, RCLock* lock): RCCondition(lock)
+{
+    ml = lock;
+    next = link;
+    twiddle = PR_FALSE;
+}  /* Home::Home */
+
+class Shared: public Home, public RCThread
+{
+public:
+    Shared(RCThread::Scope scope, Home* link, RCLock* ml);
+
+private:
+    ~Shared();
+    void RootFunction();
+};  /* Shared */
+
+Shared::Shared(RCThread::Scope scope, Home* link, RCLock* lock):
+    Home(link, lock), RCThread(scope, RCThread::joinable) { }
+
+Shared::~Shared() { }
+
+void Shared::RootFunction()
+{
+    PRStatus status = PR_SUCCESS;
+    while (PR_SUCCESS == status)
+    {
+        RCEnter entry(ml);
+        while (twiddle && (PR_SUCCESS == status)) status = Wait();
+		if (verbosity) PR_fprintf(debug_out, "+");
+        twiddle = PR_TRUE;
+        next->twiddle = PR_FALSE;
+        next->Notify();
+    }
+}  /* Shared::RootFunction */
+
+static void Help(void)
+{
+    debug_out = PR_STDOUT;
+
+    PR_fprintf(
+		debug_out, "Usage: >./switch [-d] [-c n] [-t n] [-T n] [-G]\n");
+    PR_fprintf(
+		debug_out, "-c n\tloops at thread level (default: %d)\n", DEFAULT_LOOPS);
+    PR_fprintf(
+		debug_out, "-t n\tnumber of threads (default: %d)\n", DEFAULT_THREADS);
+    PR_fprintf(debug_out, "-d\tturn on debugging output (default: FALSE)\n");
+    PR_fprintf(debug_out, "-v\tturn on verbose output (default: FALSE)\n");
+    PR_fprintf(debug_out, "-G n\tglobal threads only (default: FALSE)\n");
+    PR_fprintf(debug_out, "-C n\tconcurrency setting (default: 1)\n");
+}  /* Help */
+
+PRIntn main(PRIntn argc, char **argv)
+{
+	PLOptStatus os;
+    PRStatus status;
+    PRBool help = PR_FALSE;
+    PRUintn concurrency = 1;
+    RCThread::Scope thread_scope = RCThread::local;
+    PRUintn thread_count, inner_count, loop_count, average;
+    PRUintn thread_limit = DEFAULT_THREADS, loop_limit = DEFAULT_LOOPS;
+	PLOptState *opt = PL_CreateOptState(argc, argv, "hdvc:t:C:G");
+	while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+    {
+		if (PL_OPT_BAD == os) continue;
+        switch (opt->option)
+        {
+        case 'v':  /* verbose mode */
+			verbosity = PR_TRUE;
+        case 'd':  /* debug mode */
+			debug_mode = PR_TRUE;
+            break;
+        case 'c':  /* loop counter */
+			loop_limit = atoi(opt->value);
+            break;
+        case 't':  /* thread limit */
+			thread_limit = atoi(opt->value);
+            break;
+        case 'C':  /* Concurrency limit */
+			concurrency = atoi(opt->value);
+            break;
+        case 'G':  /* global threads only */
+			thread_scope = RCThread::global;
+            break;
+        case 'h':  /* help message */
+			Help();
+			help = PR_TRUE;
+            break;
+         default:
+            break;
+        }
+    }
+	PL_DestroyOptState(opt);
+
+    if (help) return -1;
+
+	if (PR_TRUE == debug_mode)
+	{
+		debug_out = PR_STDOUT;
+		PR_fprintf(debug_out, "Test parameters\n");
+		PR_fprintf(debug_out, "\tThreads involved: %d\n", thread_limit);
+		PR_fprintf(debug_out, "\tIteration limit: %d\n", loop_limit);
+		PR_fprintf(debug_out, "\tConcurrency: %d\n", concurrency);
+		PR_fprintf(
+			debug_out, "\tThread type: %s\n",
+			(PR_GLOBAL_THREAD == thread_scope) ? "GLOBAL" : "LOCAL");
+	}
+
+    /*
+    ** The interesting part starts here
+    */
+    RCLock lock;
+    Shared* shared;
+    Home home(NULL, &lock);
+    Home* link = &home;
+    RCInterval timein, timeout = 0;
+
+    /* Build up the string of objects */
+    for (thread_count = 1; thread_count <= thread_limit; ++thread_count)
+    {
+        shared = new Shared(thread_scope, link, &lock);
+        shared->Start();  /* make it run */
+        link = (Home*)shared;
+	}
+
+    /* Pass the message around the horn a few times */
+    for (loop_count = 1; loop_count <= loop_limit; ++loop_count)
+    {
+		timein.SetToNow();
+		for (inner_count = 0; inner_count < INNER_LOOPS; ++inner_count)
+		{
+			RCEnter entry(&lock);
+			home.twiddle = PR_TRUE;
+			shared->twiddle = PR_FALSE;
+			shared->Notify();
+			while (home.twiddle)
+            {
+				failed = (PR_FAILURE == home.Wait()) ? PR_TRUE : PR_FALSE;
+            }
+		}
+		timeout += (RCInterval(RCInterval::now) - timein);
+	}
+
+    /* Figure out how well we did */
+	if (debug_mode)
+	{
+		average = timeout.ToMicroseconds()
+			/ (INNER_LOOPS * loop_limit * thread_count);
+		PR_fprintf(
+			debug_out, "Average switch times %d usecs for %d threads\n",
+            average, thread_limit);
+	}
+
+    /* Start reclamation process */
+    link = shared;
+    for (thread_count = 1; thread_count <= thread_limit; ++thread_count)
+    {
+        if (&home == link) break;
+        status = ((Shared*)link)->Interrupt();
+		if (PR_SUCCESS != status)
+        {
+            failed = PR_TRUE;
+            if (debug_mode)
+			    PL_FPrintError(debug_out, "Failed to interrupt");
+        }
+		link = link->next; 
+    }
+
+    for (thread_count = 1; thread_count <= thread_limit; ++thread_count)
+    {
+        link = shared->next;
+        status = shared->Join();
+		if (PR_SUCCESS != status)
+		{
+            failed = PR_TRUE;
+            if (debug_mode)
+			    PL_FPrintError(debug_out, "Failed to join");
+        }
+        if (&home == link) break;
+        shared = (Shared*)link;
+    }
+
+    PR_fprintf(PR_STDOUT, ((failed) ? "FAILED\n" : "PASSED\n"));
+
+    failed |= (PR_SUCCESS == RCPrimordialThread::Cleanup());
+
+    return ((failed) ? 1 : 0);
+}  /* main */
+
+/* switch.c */
diff --git a/pr/src/cplus/tests/thread.cpp b/pr/src/cplus/tests/thread.cpp
new file mode 100644
index 0000000..442c534
--- /dev/null
+++ b/pr/src/cplus/tests/thread.cpp
@@ -0,0 +1,108 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* thread.cpp - a test program */
+
+#include "rcthread.h"
+
+#include <prlog.h>
+
+#include <stdio.h>
+
+class TestThread: public RCThread
+{
+public:
+    TestThread(RCThread::State state, PRIntn count);
+
+    virtual void RootFunction();
+
+protected:
+    virtual ~TestThread();
+
+private:
+    PRUint32 mydata;
+};
+
+TestThread::~TestThread() { }
+
+TestThread::TestThread(RCThread::State state, PRIntn count):
+    RCThread(RCThread::global, state, 0) { mydata = count; }
+
+void TestThread::RootFunction()
+{
+    SetPriority(RCThread::high);
+    printf("TestThread::RootFunction %d did it\n", mydata);
+}  /* TestThread::RootFunction */
+
+class Foo1
+{
+public:
+    Foo1();
+    virtual ~Foo1();
+
+    TestThread *thread;
+    PRIntn data;
+};
+
+Foo1::Foo1() 
+{
+    data = 0xafaf;
+    thread = new TestThread(RCThread::joinable, 0xafaf);
+    thread->Start();
+}
+
+Foo1::~Foo1()
+{
+    PRStatus rv = thread->Join();
+    PR_ASSERT(PR_SUCCESS == rv);
+}  /* Foo1::~Foo1 */
+
+PRIntn main(PRIntn argc, char **agrv)
+{
+    PRStatus status;
+    PRIntn count = 100;
+    RCThread *thread[10];
+    while (--count > 0)
+    {
+        TestThread *thread = new TestThread(RCThread::joinable, count);
+        status = thread->Start();  /* have to remember to start it */
+        PR_ASSERT(PR_SUCCESS == status);
+        status = thread->Join();  /* this should work */
+        PR_ASSERT(PR_SUCCESS == status);
+    }
+    while (++count < 100)
+    {
+        TestThread *thread = new TestThread(RCThread::unjoinable, count);
+        status = thread->Start();  /* have to remember to start it */
+        PR_ASSERT(PR_SUCCESS == status);
+    }
+
+    {
+        Foo1 *foo1 = new Foo1();
+        PR_ASSERT(NULL != foo1);
+        delete foo1;
+    }
+
+    {
+        for (count = 0; count < 10; ++count)
+        {
+            thread[count] = new TestThread( RCThread::joinable, count);
+            status = thread[count]->Start();  /* have to remember to start it */
+            PR_ASSERT(PR_SUCCESS == status);
+        }
+        for (count = 0; count < 10; ++count)
+        {
+            PRStatus rv = thread[count]->Join();
+            PR_ASSERT(PR_SUCCESS == rv);
+        }
+    }
+
+    (void)RCPrimordialThread::Cleanup();
+
+    return 0;
+}  /* main */
+
+/* thread.cpp */
+
diff --git a/pr/src/cplus/tests/time.cpp b/pr/src/cplus/tests/time.cpp
new file mode 100644
index 0000000..ad27caa
--- /dev/null
+++ b/pr/src/cplus/tests/time.cpp
@@ -0,0 +1,29 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* time.cpp - a test program */
+
+#include "rctime.h"
+
+#include <prlog.h>
+#include <prprf.h>
+
+#define DEFAULT_ITERATIONS 100
+
+PRIntn main(PRIntn argc, char **argv)
+{
+    RCTime unitialized;
+    RCTime now(PR_Now());
+    RCTime current(RCTime::now);
+    PRTime time = current;
+
+    unitialized = now;
+    now.Now();
+
+    return 0;
+}  /* main */
+
+/* time.cpp */
+
diff --git a/pr/src/cplus/tests/tpd.cpp b/pr/src/cplus/tests/tpd.cpp
new file mode 100644
index 0000000..42290ab
--- /dev/null
+++ b/pr/src/cplus/tests/tpd.cpp
@@ -0,0 +1,336 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** File:        tpd.cpp
+** Description: Exercising the thread private data bailywick.
+*/
+
+#include "prlog.h"
+#include "prprf.h"
+#include "rcthread.h"
+
+#include <string.h>
+
+#include "plgetopt.h"
+
+/*
+** class MyThread
+*/
+class MyThread: public RCThread
+{
+public:
+    MyThread();
+
+private:
+    ~MyThread();
+    void RootFunction();
+};  /* MyThread */
+
+/*
+** class MyPrivateData
+*/
+class MyPrivateData: public RCThreadPrivateData
+{
+public:
+    virtual ~MyPrivateData();
+
+    MyPrivateData();
+    MyPrivateData(char*);
+    MyPrivateData(const MyPrivateData&);
+
+    void Release();
+
+private:
+    char *string;
+};  /* MyPrivateData */
+
+static PRUintn key[128];
+static PRIntn debug = 0;
+static PRBool failed = PR_FALSE;
+static PRBool should = PR_TRUE;
+static PRBool did = PR_TRUE;
+static PRFileDesc *fout = NULL;
+
+static void PrintProgress(PRIntn line)
+{
+    failed = failed || (should && !did);
+    failed = failed || (!should && did);
+    if (debug > 0)
+    {
+        PR_fprintf(
+            fout, "@ line %d destructor should %shave been called and was%s\n",
+            line, ((should) ? "" : "NOT "), ((did) ? "" : " NOT"));
+    }
+}  /* PrintProgress */
+
+static void MyAssert(const char *expr, const char *file, PRIntn line)
+{
+    if (debug > 0)
+        (void)PR_fprintf(fout, "'%s' in file: %s: %d\n", expr, file, line);
+}  /* MyAssert */
+
+#define MY_ASSERT(_expr) \
+    ((_expr)?((void)0):MyAssert(# _expr,__FILE__,__LINE__))
+
+int main(PRIntn argc, char *argv[])
+{
+    PRStatus rv;
+    PRUintn keys;
+    MyThread *thread;
+    const RCThreadPrivateData *pd;
+    PLOptStatus os;
+    PLOptState *opt = PL_CreateOptState(argc, argv, "d");
+    RCThread *primordial = RCThread::WrapPrimordialThread();
+    while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+    {
+        if (PL_OPT_BAD == os) continue;
+        switch (opt->option)
+        {
+        case 'd':  /* debug mode */
+            debug = PR_TRUE;
+            break;
+         default:
+            break;
+        }
+    }
+    PL_DestroyOptState(opt);
+
+    fout = PR_STDOUT;
+
+    MyPrivateData extension = MyPrivateData("EXTENSION");
+    MyPrivateData key_string[] = {
+        "Key #0", "Key #1", "Key #2", "Key #3",
+        "Bogus #5", "Bogus #6", "Bogus #7", "Bogus #8"};
+    
+
+    did = should = PR_FALSE;
+    for (keys = 0; keys < 4; ++keys)
+    {
+        rv = RCThread::NewPrivateIndex(&key[keys]);
+        key[keys + 4] = key[keys] + 4;
+        MY_ASSERT(PR_SUCCESS == rv);
+    }
+    PrintProgress(__LINE__);
+
+    /* the first four should be bu null, the last four undefined and null */
+    did = should = PR_FALSE;
+    for (keys = 0; keys < 8; ++keys)
+    {
+        pd = RCThread::GetPrivateData(key[keys]);
+        MY_ASSERT(NULL == pd);
+    }
+    PrintProgress(__LINE__);
+
+    /* initially set private data for new keys */
+    did = should = PR_FALSE;
+    for (keys = 0; keys < 4; ++keys)
+    {
+        rv = RCThread::SetPrivateData(key[keys], &key_string[keys]);
+        MY_ASSERT(PR_SUCCESS == rv);
+    }
+    PrintProgress(__LINE__);
+
+    /* re-assign the private data, albeit the same content */    
+    did = PR_FALSE; should = PR_TRUE;
+    for (keys = 0; keys < 4; ++keys)
+    {
+        pd = RCThread::GetPrivateData(key[keys]);
+        PR_ASSERT(NULL != pd);
+        rv = RCThread::SetPrivateData(key[keys], &key_string[keys]);
+        MY_ASSERT(PR_SUCCESS == rv);
+    }
+    PrintProgress(__LINE__);
+
+    /* set private to <empty> */
+    did = PR_FALSE; should = PR_TRUE;
+    for (keys = 0; keys < 4; ++keys)
+    {
+        rv = RCThread::SetPrivateData(key[keys]);
+        MY_ASSERT(PR_SUCCESS == rv);
+    }
+    PrintProgress(__LINE__);
+
+    /* should all be null now */
+    did = should = PR_FALSE;
+    for (keys = 0; keys < 4; ++keys)
+    {
+        pd = RCThread::GetPrivateData(key[keys]);
+        PR_ASSERT(NULL == pd);
+    }
+    PrintProgress(__LINE__);
+
+    /* allocate another batch of keys and assign data to them */
+    did = should = PR_FALSE;
+    for (keys = 8; keys < 127; ++keys)
+    {
+        rv = RCThread::NewPrivateIndex(&key[keys]);
+        MY_ASSERT(PR_SUCCESS == rv);
+        rv = RCThread::SetPrivateData(key[keys], &extension);
+        MY_ASSERT(PR_SUCCESS == rv);
+    }
+    PrintProgress(__LINE__);
+
+    /* set all the extended slots to <empty> */
+    did = PR_FALSE; should = PR_TRUE;
+    for (keys = 8; keys < 127; ++keys)
+    {
+        rv = RCThread::SetPrivateData(key[keys]);
+        MY_ASSERT(PR_SUCCESS == rv);
+    }
+    PrintProgress(__LINE__);
+
+    /* set all the extended slots to <empty> again (noop) */
+    did = should = PR_FALSE;
+    for (keys = 8; keys < 127; ++keys)
+    {
+        rv = RCThread::SetPrivateData(key[keys]);
+        MY_ASSERT(PR_SUCCESS == rv);
+    }
+
+    if (debug) PR_fprintf(fout, "Creating thread\n");
+    thread = new MyThread();
+    if (debug) PR_fprintf(fout, "Starting thread\n");
+    thread->Start();
+    if (debug) PR_fprintf(fout, "Joining thread\n");
+    (void)thread->Join();
+    if (debug) PR_fprintf(fout, "Joined thread\n");
+
+    failed |= (PR_FAILURE == RCPrimordialThread::Cleanup());
+
+    (void)PR_fprintf(
+        fout, "%s\n",((PR_TRUE == failed) ? "FAILED" : "PASSED"));
+
+    return (failed) ? 1 : 0;
+
+}  /* main */
+
+/*
+** class MyPrivateData
+*/
+MyPrivateData::~MyPrivateData()
+{
+    PR_fprintf(
+        fout, "MyPrivateData::~MyPrivateData[%s]\n",
+        (NULL != string) ? string : "NULL");
+}  /* MyPrivateData::~MyPrivateData */
+
+MyPrivateData::MyPrivateData(): RCThreadPrivateData()
+{
+    PR_fprintf(fout, "MyPrivateData::MyPrivateData()\n");
+    string = NULL;
+}  /* MyPrivateData::MyPrivateData */
+
+MyPrivateData::MyPrivateData(char* data): RCThreadPrivateData()
+{
+    PR_fprintf(fout, "MyPrivateData::MyPrivateData(char* data)\n");
+    string = data;
+}  /* MyPrivateData:: MyPrivateData */
+
+MyPrivateData::MyPrivateData(const MyPrivateData& him): RCThreadPrivateData(him)
+{
+    PR_fprintf(fout, "MyPrivateData::MyPrivateData(const MyPrivateData& him)\n");
+    string = him.string;
+}  /* MyPrivateData:: MyPrivateData */
+
+void MyPrivateData::Release()
+{
+    if (should) did = PR_TRUE;
+    else failed = PR_TRUE;
+}  /* MyPrivateData::operator= */
+
+/*
+** class MyThread
+*/
+MyThread::~MyThread() { }
+MyThread::MyThread(): RCThread(RCThread::global, RCThread::joinable) { }
+
+
+void MyThread::RootFunction()
+{
+    PRStatus rv;
+    PRUintn keys;
+    const RCThreadPrivateData *pd;
+    
+    MyPrivateData extension = MyPrivateData("EXTENSION");
+    MyPrivateData key_string[] = {
+        "Key #0", "Key #1", "Key #2", "Key #3",
+        "Bogus #5", "Bogus #6", "Bogus #7", "Bogus #8"};
+    
+    did = should = PR_FALSE;
+    for (keys = 0; keys < 8; ++keys)
+    {
+        pd = GetPrivateData(key[keys]);
+        MY_ASSERT(NULL == pd);
+    }
+    PrintProgress(__LINE__);
+
+    did = should = PR_FALSE;
+    for (keys = 0; keys < 4; ++keys)
+    {
+        rv = SetPrivateData(keys, &key_string[keys]);
+        MY_ASSERT(PR_SUCCESS == rv);
+    }
+    PrintProgress(__LINE__);
+
+#if !defined(DEBUG)
+    did = should = PR_FALSE;
+    for (keys = 4; keys < 8; ++keys)
+    {
+        rv = SetPrivateData(keys, &key_string[keys]);
+        MY_ASSERT(PR_FAILURE == rv);
+    }
+    PrintProgress(__LINE__);
+#endif
+    
+    did = PR_FALSE; should = PR_TRUE;
+    for (keys = 0; keys < 4; ++keys)
+    {
+        rv = SetPrivateData(key[keys], &key_string[keys]);
+        MY_ASSERT(PR_SUCCESS == rv);
+    }
+    PrintProgress(__LINE__);
+
+    did = PR_FALSE; should = PR_TRUE;
+    for (keys = 0; keys < 4; ++keys)
+    {
+        rv = SetPrivateData(key[keys]);
+        MY_ASSERT(PR_SUCCESS == rv);
+    }
+    PrintProgress(__LINE__);
+
+    did = should = PR_FALSE;
+    for (keys = 0; keys < 4; ++keys)
+    {
+        rv = SetPrivateData(key[keys]);
+        MY_ASSERT(PR_SUCCESS == rv);
+    }
+    PrintProgress(__LINE__);
+
+    did = should = PR_FALSE;
+    for (keys = 8; keys < 127; ++keys)
+    {
+        rv = SetPrivateData(key[keys], &extension);
+        MY_ASSERT(PR_SUCCESS == rv);
+    }
+    PrintProgress(__LINE__);
+
+    did = PR_FALSE; should = PR_TRUE;
+    for (keys = 8; keys < 127; ++keys)
+    {
+        rv = SetPrivateData(key[keys]);
+        MY_ASSERT(PR_SUCCESS == rv);
+    }
+    PrintProgress(__LINE__);
+
+    did = should = PR_FALSE;
+    for (keys = 8; keys < 127; ++keys)
+    {
+        rv = SetPrivateData(key[keys]);
+        MY_ASSERT(PR_SUCCESS == rv);
+    }
+}  /* MyThread::RootFunction */
+
+/* tpd.c */
diff --git a/pr/src/io/.cvsignore b/pr/src/io/.cvsignore
new file mode 100644
index 0000000..f3c7a7c
--- /dev/null
+++ b/pr/src/io/.cvsignore
@@ -0,0 +1 @@
+Makefile
diff --git a/pr/src/io/Makefile.in b/pr/src/io/Makefile.in
new file mode 100644
index 0000000..f6b5bcd
--- /dev/null
+++ b/pr/src/io/Makefile.in
@@ -0,0 +1,50 @@
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#! gmake
+
+MOD_DEPTH	= ../../..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+
+include $(MOD_DEPTH)/config/autoconf.mk
+
+include $(topsrcdir)/config/config.mk
+
+CSRCS = \
+    prfdcach.c \
+    prmwait.c \
+    priometh.c \
+    pripv6.c \
+	prmapopt.c \
+    prlayer.c \
+    prlog.c \
+	prmmap.c \
+    prpolevt.c \
+	prprf.c \
+	prscanf.c \
+	prstdio.c  \
+	$(NULL)
+
+ifndef USE_PTHREADS
+    CSRCS += \
+	    prdir.c \
+	    prfile.c \
+	    prio.c \
+	    prsocket.c \
+	    $(NULL)
+endif
+
+TARGETS	= $(OBJS)
+
+INCLUDES = -I$(dist_includedir) -I$(topsrcdir)/pr/include -I$(topsrcdir)/pr/include/private
+
+DEFINES	+= -D_NSPR_BUILD_
+
+include $(topsrcdir)/config/rules.mk
+
+export:: $(TARGETS)
+
diff --git a/pr/src/io/prdir.c b/pr/src/io/prdir.c
new file mode 100644
index 0000000..3701a6a
--- /dev/null
+++ b/pr/src/io/prdir.c
@@ -0,0 +1,131 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "primpl.h"
+
+PR_IMPLEMENT(PRDir*) PR_OpenDir(const char *name)
+{
+    PRDir *dir;
+    PRStatus sts;
+
+    dir = PR_NEW(PRDir);
+    if (dir) {
+        sts = _PR_MD_OPEN_DIR(&dir->md,name);
+        if (sts != PR_SUCCESS) {
+            PR_DELETE(dir);
+            return NULL;
+        }
+    } else {
+		PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+	}
+    return dir;
+}
+
+PR_IMPLEMENT(PRDirEntry*) PR_ReadDir(PRDir *dir, PRDirFlags flags)
+{
+    /* _MD_READ_DIR return a char* to the name; allocation in machine-dependent code */
+    char* name = _PR_MD_READ_DIR(&dir->md, flags);
+    dir->d.name = name;
+    return name ? &dir->d : NULL;
+}
+
+PR_IMPLEMENT(PRStatus) PR_CloseDir(PRDir *dir)
+{
+PRInt32 rv;
+
+    if (dir) {
+        rv = _PR_MD_CLOSE_DIR(&dir->md);
+		PR_DELETE(dir);
+		if (rv < 0) {
+			return PR_FAILURE;
+		} else
+			return PR_SUCCESS;
+    }
+	return PR_SUCCESS;
+}
+
+PR_IMPLEMENT(PRStatus) PR_MkDir(const char *name, PRIntn mode)
+{
+PRInt32 rv;
+
+	rv = _PR_MD_MKDIR(name, mode);
+	if (rv < 0) {
+		return PR_FAILURE;
+	} else
+		return PR_SUCCESS;
+}
+
+PR_IMPLEMENT(PRStatus) PR_MakeDir(const char *name, PRIntn mode)
+{
+PRInt32 rv;
+
+	if (!_pr_initialized) _PR_ImplicitInitialization();
+	rv = _PR_MD_MAKE_DIR(name, mode);
+	if (rv < 0) {
+		return PR_FAILURE;
+	} else
+		return PR_SUCCESS;
+}
+
+PR_IMPLEMENT(PRStatus) PR_RmDir(const char *name)
+{
+PRInt32 rv;
+
+	rv = _PR_MD_RMDIR(name);
+	if (rv < 0) {
+		return PR_FAILURE;
+	} else
+		return PR_SUCCESS;
+}
+
+#ifdef MOZ_UNICODE
+/*
+ *  UTF16 Interface
+ */
+PR_IMPLEMENT(PRDirUTF16*) PR_OpenDirUTF16(const PRUnichar *name)
+{ 
+    PRDirUTF16 *dir;
+    PRStatus sts;
+
+    dir = PR_NEW(PRDirUTF16);
+    if (dir) {
+        sts = _PR_MD_OPEN_DIR_UTF16(&dir->md,name);
+        if (sts != PR_SUCCESS) {
+            PR_DELETE(dir);
+            return NULL;
+        }
+    } else {
+        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+    }
+    return dir;
+}  
+ 
+PR_IMPLEMENT(PRDirEntryUTF16*) PR_ReadDirUTF16(PRDirUTF16 *dir, PRDirFlags flags)
+{ 
+    /*
+     * _MD_READ_DIR_UTF16 return a PRUnichar* to the name; allocation in
+     * machine-dependent code
+     */
+    PRUnichar* name = _PR_MD_READ_DIR_UTF16(&dir->md, flags);
+    dir->d.name = name;
+    return name ? &dir->d : NULL;
+} 
+ 
+PR_IMPLEMENT(PRStatus) PR_CloseDirUTF16(PRDirUTF16 *dir)
+{ 
+    PRInt32 rv; 
+
+    if (dir) {
+        rv = _PR_MD_CLOSE_DIR_UTF16(&dir->md);
+        PR_DELETE(dir);
+        if (rv < 0)
+	    return PR_FAILURE;
+        else
+	    return PR_SUCCESS;
+    } 
+    return PR_SUCCESS;
+}
+
+#endif /* MOZ_UNICODE */
diff --git a/pr/src/io/prfdcach.c b/pr/src/io/prfdcach.c
new file mode 100644
index 0000000..17b71fe
--- /dev/null
+++ b/pr/src/io/prfdcach.c
@@ -0,0 +1,230 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "primpl.h"
+
+#include <string.h>
+
+/*****************************************************************************/
+/*****************************************************************************/
+/************************** File descriptor caching **************************/
+/*****************************************************************************/
+/*****************************************************************************/
+
+/*
+** This code is built into debuggable versions of NSPR to assist in
+** finding misused file descriptors. Since file descritors (PRFileDesc)
+** are identified by a pointer to their structure, they can be the
+** target of dangling references. Furthermore, NSPR caches and tries
+** to aggressively reuse file descriptors, leading to more ambiguity.
+** The following code will allow a debugging client to set environment
+** variables and control the number of file descriptors that will be
+** preserved before they are recycled. The environment variables are
+** NSPR_FD_CACHE_SIZE_LOW and NSPR_FD_CACHE_SIZE_HIGH. The former sets
+** the number of descriptors NSPR will allocate before beginning to
+** recycle. The latter is the maximum number permitted in the cache
+** (exclusive of those in use) at a time.
+*/
+typedef struct _PR_Fd_Cache
+{
+    PRLock *ml;
+    PRIntn count;
+    PRFileDesc *head, *tail;
+    PRIntn limit_low, limit_high;
+} _PR_Fd_Cache;
+
+static _PR_Fd_Cache _pr_fd_cache;
+
+
+/*
+** Get a FileDescriptor from the cache if one exists. If not allocate
+** a new one from the heap.
+*/
+PRFileDesc *_PR_Getfd(void)
+{
+    PRFileDesc *fd;
+    /*
+    ** $$$
+    ** This may look a little wasteful. We'll see. Right now I want to
+    ** be able to toggle between caching and not at runtime to measure
+    ** the differences. If it isn't too annoying, I'll leave it in.
+    ** $$$$
+    **
+    ** The test is against _pr_fd_cache.limit_high. If that's zero,
+    ** we're not doing the extended cache but going for performance.
+    */
+    if (0 == _pr_fd_cache.limit_high)
+    {
+        goto allocate;
+    }
+    else
+    {
+        do
+        {
+            if (NULL == _pr_fd_cache.head) goto allocate;  /* nothing there */
+            if (_pr_fd_cache.count < _pr_fd_cache.limit_low) goto allocate;
+
+            /* we "should" be able to extract an fd from the cache */
+            PR_Lock(_pr_fd_cache.ml);  /* need the lock to do this safely */
+            fd = _pr_fd_cache.head;  /* protected extraction */
+            if (NULL == fd)  /* unexpected, but not fatal */
+            {
+                PR_ASSERT(0 == _pr_fd_cache.count);
+                PR_ASSERT(NULL == _pr_fd_cache.tail);
+            }
+            else
+            {
+                _pr_fd_cache.count -= 1;
+                _pr_fd_cache.head = fd->higher;
+                if (NULL == _pr_fd_cache.head)
+                {
+                    PR_ASSERT(0 == _pr_fd_cache.count);
+                    _pr_fd_cache.tail = NULL;
+                }
+                PR_ASSERT(&_pr_faulty_methods == fd->methods);
+                PR_ASSERT(PR_INVALID_IO_LAYER == fd->identity);
+                PR_ASSERT(_PR_FILEDESC_FREED == fd->secret->state);
+            }
+            PR_Unlock(_pr_fd_cache.ml);
+
+        } while (NULL == fd);  /* then go around and allocate a new one */
+    }
+
+finished:
+    fd->dtor = NULL;
+    fd->lower = fd->higher = NULL;
+    fd->identity = PR_NSPR_IO_LAYER;
+    memset(fd->secret, 0, sizeof(PRFilePrivate));
+    return fd;
+
+allocate:
+    fd = PR_NEW(PRFileDesc);
+    if (NULL != fd)
+    {
+        fd->secret = PR_NEW(PRFilePrivate);
+        if (NULL == fd->secret) PR_DELETE(fd);
+    }
+    if (NULL != fd) goto finished;
+    else return NULL;
+
+}  /* _PR_Getfd */
+
+/*
+** Return a file descriptor to the cache unless there are too many in
+** there already. If put in cache, clear the fields first.
+*/
+void _PR_Putfd(PRFileDesc *fd)
+{
+    PR_ASSERT(PR_NSPR_IO_LAYER == fd->identity);
+    fd->methods = &_pr_faulty_methods;
+    fd->identity = PR_INVALID_IO_LAYER;
+    fd->secret->state = _PR_FILEDESC_FREED;
+
+    if (0 != _pr_fd_cache.limit_high)
+    {
+        if (_pr_fd_cache.count < _pr_fd_cache.limit_high)
+        {
+            PR_Lock(_pr_fd_cache.ml);
+            if (NULL == _pr_fd_cache.tail)
+            {
+                PR_ASSERT(0 == _pr_fd_cache.count);
+                PR_ASSERT(NULL == _pr_fd_cache.head);
+                _pr_fd_cache.head = _pr_fd_cache.tail = fd;
+            }
+            else
+            {
+                PR_ASSERT(NULL == _pr_fd_cache.tail->higher);
+                _pr_fd_cache.tail->higher = fd;
+                _pr_fd_cache.tail = fd;  /* new value */
+            }
+            fd->higher = NULL;  /* always so */
+            _pr_fd_cache.count += 1;  /* count the new entry */
+            PR_Unlock(_pr_fd_cache.ml);
+            return;
+        }
+    }
+
+    PR_Free(fd->secret);
+    PR_Free(fd);
+}  /* _PR_Putfd */
+
+PR_IMPLEMENT(PRStatus) PR_SetFDCacheSize(PRIntn low, PRIntn high)
+{
+    /*
+    ** This can be called at any time, may adjust the cache sizes,
+    ** turn the caches off, or turn them on. It is not dependent
+    ** on the compilation setting of DEBUG.
+    */
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+
+    if (low > high) low = high;  /* sanity check the params */
+    
+    PR_Lock(_pr_fd_cache.ml);
+    _pr_fd_cache.limit_high = high;
+    _pr_fd_cache.limit_low = low;
+    PR_Unlock(_pr_fd_cache.ml);
+    return PR_SUCCESS;
+}  /* PR_SetFDCacheSize */
+
+void _PR_InitFdCache(void)
+{
+    /*
+    ** The fd caching is enabled by default for DEBUG builds,
+    ** disabled by default for OPT builds. That default can
+    ** be overridden at runtime using environment variables
+    ** or a super-wiz-bang API.
+    */
+    const char *low = PR_GetEnv("NSPR_FD_CACHE_SIZE_LOW");
+    const char *high = PR_GetEnv("NSPR_FD_CACHE_SIZE_HIGH");
+
+    /* 
+    ** _low is allowed to be zero, _high is not.
+    ** If _high is zero, we're not doing the caching.
+    */
+
+    _pr_fd_cache.limit_low = 0;
+#if defined(DEBUG)
+    _pr_fd_cache.limit_high = FD_SETSIZE;
+#else
+    _pr_fd_cache.limit_high = 0;
+#endif  /* defined(DEBUG) */
+
+    if (NULL != low) _pr_fd_cache.limit_low = atoi(low);
+    if (NULL != high) _pr_fd_cache.limit_high = atoi(high);
+
+    if (_pr_fd_cache.limit_low < 0)
+        _pr_fd_cache.limit_low = 0;
+    if (_pr_fd_cache.limit_low > FD_SETSIZE)
+        _pr_fd_cache.limit_low = FD_SETSIZE;
+
+    if (_pr_fd_cache.limit_high > FD_SETSIZE)
+        _pr_fd_cache.limit_high = FD_SETSIZE;
+
+    if (_pr_fd_cache.limit_high < _pr_fd_cache.limit_low)
+        _pr_fd_cache.limit_high = _pr_fd_cache.limit_low;
+
+    _pr_fd_cache.ml = PR_NewLock();
+    PR_ASSERT(NULL != _pr_fd_cache.ml);
+
+}  /* _PR_InitFdCache */
+
+void _PR_CleanupFdCache(void)
+{
+    PRFileDesc *fd, *next;
+
+    for (fd = _pr_fd_cache.head; fd != NULL; fd = next)
+    {
+        next = fd->higher;
+        PR_DELETE(fd->secret);
+        PR_DELETE(fd);
+    }
+    _pr_fd_cache.head = NULL;
+    _pr_fd_cache.tail = NULL;
+    _pr_fd_cache.count = 0;
+    PR_DestroyLock(_pr_fd_cache.ml);
+    _pr_fd_cache.ml = NULL;
+}  /* _PR_CleanupFdCache */
+
+/* prfdcach.c */
diff --git a/pr/src/io/prfile.c b/pr/src/io/prfile.c
new file mode 100644
index 0000000..e32031b
--- /dev/null
+++ b/pr/src/io/prfile.c
@@ -0,0 +1,783 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "primpl.h"
+
+#include <string.h>
+#include <fcntl.h>
+
+#ifdef XP_UNIX
+#if defined(AIX) || defined(QNX)
+/* To pick up sysconf */
+#include <unistd.h>
+#else
+/* To pick up getrlimit, setrlimit */
+#include <sys/time.h>
+#include <sys/resource.h>
+#endif
+#endif /* XP_UNIX */
+
+extern PRLock *_pr_flock_lock;
+extern PRCondVar *_pr_flock_cv;
+
+static PRInt32 PR_CALLBACK FileRead(PRFileDesc *fd, void *buf, PRInt32 amount)
+{
+    PRInt32 rv = 0;
+    PRThread *me = _PR_MD_CURRENT_THREAD();
+
+    if (_PR_PENDING_INTERRUPT(me)) {
+ 		me->flags &= ~_PR_INTERRUPT;
+		PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+		rv = -1;
+    }
+    if (_PR_IO_PENDING(me)) {
+        PR_SetError(PR_IO_PENDING_ERROR, 0);
+	rv = -1;
+    }
+    if (rv == -1)
+    	return rv;
+
+	rv = _PR_MD_READ(fd, buf, amount);
+	if (rv < 0) {
+		PR_ASSERT(rv == -1);
+	}
+    PR_LOG(_pr_io_lm, PR_LOG_MAX, ("read -> %d", rv));
+    return rv;
+}
+
+static PRInt32 PR_CALLBACK FileWrite(PRFileDesc *fd, const void *buf, PRInt32 amount)
+{
+    PRInt32 rv = 0;
+    PRInt32 temp, count;
+    PRThread *me = _PR_MD_CURRENT_THREAD();
+
+    if (_PR_PENDING_INTERRUPT(me)) {
+        me->flags &= ~_PR_INTERRUPT;
+        PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+	    rv = -1;
+    }
+    if (_PR_IO_PENDING(me)) {
+        PR_SetError(PR_IO_PENDING_ERROR, 0);
+	    rv = -1;
+    }
+    if (rv != 0)
+    	return rv;
+
+    count = 0;
+#if !defined(_PR_HAVE_O_APPEND)  /* Bugzilla: 4090, 276330 */
+    if (fd->secret->appendMode) {
+        if (PR_Seek64(fd, 0, PR_SEEK_END) == -1) {
+            return -1;
+        }
+    } /* if (fd->secret->appendMode...) */
+#endif /* _PR_HAVE_O_APPEND */
+    while (amount > 0) {
+		temp = _PR_MD_WRITE(fd, buf, amount);
+		if (temp < 0) {
+			count = -1;
+			break;
+		}
+		count += temp;
+		if (fd->secret->nonblocking) {
+			break;
+		}
+		buf = (const void*) ((const char*)buf + temp);
+		amount -= temp;
+    }
+    PR_LOG(_pr_io_lm, PR_LOG_MAX, ("write -> %d", count));
+    return count;
+}
+
+static PROffset32 PR_CALLBACK FileSeek(PRFileDesc *fd, PROffset32 offset, PRSeekWhence whence)
+{
+    PROffset32 result;
+
+    result = _PR_MD_LSEEK(fd, offset, whence);
+    return result;
+}
+
+static PROffset64 PR_CALLBACK FileSeek64(PRFileDesc *fd, PROffset64 offset, PRSeekWhence whence)
+{
+    PROffset64 result;
+
+    result = _PR_MD_LSEEK64(fd, offset, whence);
+    return result;
+}
+
+static PRInt32 PR_CALLBACK FileAvailable(PRFileDesc *fd)
+{
+    PRInt32 result, cur, end;
+
+    cur = _PR_MD_LSEEK(fd, 0, PR_SEEK_CUR);
+
+	if (cur >= 0)
+    	end = _PR_MD_LSEEK(fd, 0, PR_SEEK_END);
+
+    if ((cur < 0) || (end < 0)) {
+        return -1;
+    }
+
+    result = end - cur;
+    _PR_MD_LSEEK(fd, cur, PR_SEEK_SET);
+
+    return result;
+}
+
+static PRInt64 PR_CALLBACK FileAvailable64(PRFileDesc *fd)
+{
+    PRInt64 result, cur, end;
+    PRInt64 minus_one;
+
+    LL_I2L(minus_one, -1);
+    cur = _PR_MD_LSEEK64(fd, LL_ZERO, PR_SEEK_CUR);
+
+    if (LL_GE_ZERO(cur))
+    	end = _PR_MD_LSEEK64(fd, LL_ZERO, PR_SEEK_END);
+
+    if (!LL_GE_ZERO(cur) || !LL_GE_ZERO(end)) return minus_one;
+
+    LL_SUB(result, end, cur);
+    (void)_PR_MD_LSEEK64(fd, cur, PR_SEEK_SET);
+
+    return result;
+}
+
+static PRInt32 PR_CALLBACK PipeAvailable(PRFileDesc *fd)
+{
+	PRInt32 rv;
+	rv =  _PR_MD_PIPEAVAILABLE(fd);
+	return rv;		
+}
+
+static PRInt64 PR_CALLBACK PipeAvailable64(PRFileDesc *fd)
+{
+    PRInt64 rv;
+    LL_I2L(rv, _PR_MD_PIPEAVAILABLE(fd));
+	return rv;		
+}
+
+static PRStatus PR_CALLBACK PipeSync(PRFileDesc *fd)
+{
+	return PR_SUCCESS;
+}
+
+static PRStatus PR_CALLBACK FileGetInfo(PRFileDesc *fd, PRFileInfo *info)
+{
+	PRInt32 rv;
+
+    rv = _PR_MD_GETOPENFILEINFO(fd, info);
+    if (rv < 0) {
+	return PR_FAILURE;
+    } else
+	return PR_SUCCESS;
+}
+
+static PRStatus PR_CALLBACK FileGetInfo64(PRFileDesc *fd, PRFileInfo64 *info)
+{
+    /* $$$$ NOT YET IMPLEMENTED */
+	PRInt32 rv;
+
+    rv = _PR_MD_GETOPENFILEINFO64(fd, info);
+    if (rv < 0) return PR_FAILURE;
+    else return PR_SUCCESS;
+}
+
+static PRStatus PR_CALLBACK FileSync(PRFileDesc *fd)
+{
+    PRInt32 result;
+    result = _PR_MD_FSYNC(fd);
+    if (result < 0) {
+		return PR_FAILURE;
+    }
+    return PR_SUCCESS;
+}
+
+static PRStatus PR_CALLBACK FileClose(PRFileDesc *fd)
+{
+    if (!fd || !fd->secret
+            || (fd->secret->state != _PR_FILEDESC_OPEN
+            && fd->secret->state != _PR_FILEDESC_CLOSED)) {
+        PR_SetError(PR_BAD_DESCRIPTOR_ERROR, 0);
+        return PR_FAILURE;
+    }
+
+    if (fd->secret->state == _PR_FILEDESC_OPEN) {
+        if (_PR_MD_CLOSE_FILE(fd->secret->md.osfd) < 0) {
+            return PR_FAILURE;
+        }
+        fd->secret->state = _PR_FILEDESC_CLOSED;
+    }
+    PR_FreeFileDesc(fd);
+    return PR_SUCCESS;
+}
+
+static PRInt16 PR_CALLBACK FilePoll(
+    PRFileDesc *fd, PRInt16 in_flags, PRInt16 *out_flags)
+{
+    *out_flags = 0;
+    return in_flags;
+}  /* FilePoll */
+
+static PRIOMethods _pr_fileMethods = {
+    PR_DESC_FILE,
+    FileClose,
+    FileRead,
+    FileWrite,
+    FileAvailable,
+    FileAvailable64,
+    FileSync,
+    FileSeek,
+    FileSeek64,
+    FileGetInfo,
+    FileGetInfo64,
+    (PRWritevFN)_PR_InvalidInt,		
+    (PRConnectFN)_PR_InvalidStatus,		
+    (PRAcceptFN)_PR_InvalidDesc,		
+    (PRBindFN)_PR_InvalidStatus,		
+    (PRListenFN)_PR_InvalidStatus,		
+    (PRShutdownFN)_PR_InvalidStatus,	
+    (PRRecvFN)_PR_InvalidInt,		
+    (PRSendFN)_PR_InvalidInt,		
+    (PRRecvfromFN)_PR_InvalidInt,	
+    (PRSendtoFN)_PR_InvalidInt,		
+    FilePoll,         
+    (PRAcceptreadFN)_PR_InvalidInt,   
+    (PRTransmitfileFN)_PR_InvalidInt, 
+    (PRGetsocknameFN)_PR_InvalidStatus,	
+    (PRGetpeernameFN)_PR_InvalidStatus,	
+    (PRReservedFN)_PR_InvalidInt,	
+    (PRReservedFN)_PR_InvalidInt,	
+    (PRGetsocketoptionFN)_PR_InvalidStatus,	
+    (PRSetsocketoptionFN)_PR_InvalidStatus,
+    (PRSendfileFN)_PR_InvalidInt, 
+    (PRConnectcontinueFN)_PR_InvalidStatus, 
+    (PRReservedFN)_PR_InvalidInt, 
+    (PRReservedFN)_PR_InvalidInt, 
+    (PRReservedFN)_PR_InvalidInt, 
+    (PRReservedFN)_PR_InvalidInt
+};
+
+PR_IMPLEMENT(const PRIOMethods*) PR_GetFileMethods(void)
+{
+    return &_pr_fileMethods;
+}
+
+static PRIOMethods _pr_pipeMethods = {
+    PR_DESC_PIPE,
+    FileClose,
+    FileRead,
+    FileWrite,
+    PipeAvailable,
+    PipeAvailable64,
+    PipeSync,
+    (PRSeekFN)_PR_InvalidInt,
+    (PRSeek64FN)_PR_InvalidInt64,
+    (PRFileInfoFN)_PR_InvalidStatus,
+    (PRFileInfo64FN)_PR_InvalidStatus,
+    (PRWritevFN)_PR_InvalidInt,		
+    (PRConnectFN)_PR_InvalidStatus,		
+    (PRAcceptFN)_PR_InvalidDesc,		
+    (PRBindFN)_PR_InvalidStatus,		
+    (PRListenFN)_PR_InvalidStatus,		
+    (PRShutdownFN)_PR_InvalidStatus,	
+    (PRRecvFN)_PR_InvalidInt,		
+    (PRSendFN)_PR_InvalidInt,		
+    (PRRecvfromFN)_PR_InvalidInt,	
+    (PRSendtoFN)_PR_InvalidInt,		
+    FilePoll,         
+    (PRAcceptreadFN)_PR_InvalidInt,   
+    (PRTransmitfileFN)_PR_InvalidInt, 
+    (PRGetsocknameFN)_PR_InvalidStatus,	
+    (PRGetpeernameFN)_PR_InvalidStatus,	
+    (PRReservedFN)_PR_InvalidInt,	
+    (PRReservedFN)_PR_InvalidInt,	
+    (PRGetsocketoptionFN)_PR_InvalidStatus,	
+    (PRSetsocketoptionFN)_PR_InvalidStatus,
+    (PRSendfileFN)_PR_InvalidInt, 
+    (PRConnectcontinueFN)_PR_InvalidStatus, 
+    (PRReservedFN)_PR_InvalidInt, 
+    (PRReservedFN)_PR_InvalidInt, 
+    (PRReservedFN)_PR_InvalidInt, 
+    (PRReservedFN)_PR_InvalidInt
+};
+
+PR_IMPLEMENT(const PRIOMethods*) PR_GetPipeMethods(void)
+{
+    return &_pr_pipeMethods;
+}
+
+PR_IMPLEMENT(PRFileDesc*) PR_Open(const char *name, PRIntn flags, PRIntn mode)
+{
+    PROsfd osfd;
+    PRFileDesc *fd = 0;
+#if !defined(_PR_HAVE_O_APPEND)
+    PRBool  appendMode = ( PR_APPEND & flags )? PR_TRUE : PR_FALSE;
+#endif
+
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+
+    /* Map pr open flags and mode to os specific flags */
+
+    osfd = _PR_MD_OPEN(name, flags, mode);
+    if (osfd != -1) {
+        fd = PR_AllocFileDesc(osfd, &_pr_fileMethods);
+        if (!fd) {
+            (void) _PR_MD_CLOSE_FILE(osfd);
+        } else {
+#if !defined(_PR_HAVE_O_APPEND)
+            fd->secret->appendMode = appendMode;
+#endif
+            _PR_MD_INIT_FD_INHERITABLE(fd, PR_FALSE);
+        }
+    }
+    return fd;
+}
+
+PR_IMPLEMENT(PRFileDesc*) PR_OpenFile(
+    const char *name, PRIntn flags, PRIntn mode)
+{
+    PROsfd osfd;
+    PRFileDesc *fd = 0;
+#if !defined(_PR_HAVE_O_APPEND)
+    PRBool  appendMode = ( PR_APPEND & flags )? PR_TRUE : PR_FALSE;
+#endif
+
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+
+    /* Map pr open flags and mode to os specific flags */
+
+    osfd = _PR_MD_OPEN_FILE(name, flags, mode);
+    if (osfd != -1) {
+        fd = PR_AllocFileDesc(osfd, &_pr_fileMethods);
+        if (!fd) {
+            (void) _PR_MD_CLOSE_FILE(osfd);
+        } else {
+#if !defined(_PR_HAVE_O_APPEND)
+            fd->secret->appendMode = appendMode;
+#endif
+            _PR_MD_INIT_FD_INHERITABLE(fd, PR_FALSE);
+        }
+    }
+    return fd;
+}
+
+PR_IMPLEMENT(PRInt32) PR_GetSysfdTableMax(void)
+{
+#if defined(XP_UNIX) && !defined(AIX) && !defined(QNX)
+    struct rlimit rlim;
+
+    if ( getrlimit(RLIMIT_NOFILE, &rlim) < 0) {
+       /* XXX need to call PR_SetError() */
+       return -1;
+    }
+
+    return rlim.rlim_max;
+#elif defined(AIX) || defined(QNX)
+    return sysconf(_SC_OPEN_MAX);
+#elif defined(WIN32)
+    /*
+     * There is a systemwide limit of 65536 user handles.
+     */
+    return 16384;
+#elif defined (WIN16)
+    return FOPEN_MAX;
+#elif defined(XP_OS2)
+    ULONG ulReqCount = 0;
+    ULONG ulCurMaxFH = 0;
+    DosSetRelMaxFH(&ulReqCount, &ulCurMaxFH);
+    return ulCurMaxFH;
+#elif defined(XP_BEOS)
+    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+   return -1;
+#else
+    write me;
+#endif
+}
+
+PR_IMPLEMENT(PRInt32) PR_SetSysfdTableSize(int table_size)
+{
+#if defined(XP_UNIX) && !defined(AIX) && !defined(QNX)
+    struct rlimit rlim;
+    PRInt32 tableMax = PR_GetSysfdTableMax();
+
+    if (tableMax < 0) 
+        return -1;
+
+    if (tableMax > FD_SETSIZE)
+        tableMax = FD_SETSIZE;
+
+    rlim.rlim_max = tableMax;
+
+    /* Grow as much as we can; even if too big */
+    if ( rlim.rlim_max < table_size )
+        rlim.rlim_cur = rlim.rlim_max;
+    else
+        rlim.rlim_cur = table_size;
+
+    if ( setrlimit(RLIMIT_NOFILE, &rlim) < 0) {
+        /* XXX need to call PR_SetError() */
+        return -1;
+    }
+
+    return rlim.rlim_cur;
+#elif defined(XP_OS2)
+    PRInt32 tableMax = PR_GetSysfdTableMax();
+    if (table_size > tableMax) {
+      APIRET rc = NO_ERROR;
+      rc = DosSetMaxFH(table_size);
+      if (rc == NO_ERROR)
+        return table_size;
+      else
+        return -1;
+    } 
+    return tableMax;
+#elif defined(AIX) || defined(QNX) \
+        || defined(WIN32) || defined(WIN16) || defined(XP_BEOS)
+    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+    return -1;
+#else
+    write me;
+#endif
+}
+
+PR_IMPLEMENT(PRStatus) PR_Delete(const char *name)
+{
+	PRInt32 rv;
+
+	rv = _PR_MD_DELETE(name);
+	if (rv < 0) {
+		return PR_FAILURE;
+	} else
+		return PR_SUCCESS;
+}
+
+PR_IMPLEMENT(PRStatus) PR_GetFileInfo(const char *fn, PRFileInfo *info)
+{
+	PRInt32 rv;
+
+	rv = _PR_MD_GETFILEINFO(fn, info);
+	if (rv < 0) {
+		return PR_FAILURE;
+	} else
+		return PR_SUCCESS;
+}
+
+PR_IMPLEMENT(PRStatus) PR_GetFileInfo64(const char *fn, PRFileInfo64 *info)
+{
+    PRInt32 rv;
+
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+    rv = _PR_MD_GETFILEINFO64(fn, info);
+    if (rv < 0) {
+        return PR_FAILURE;
+    } else {
+        return PR_SUCCESS;
+    }
+}
+
+PR_IMPLEMENT(PRStatus) PR_Rename(const char *from, const char *to)
+{
+	PRInt32 rv;
+
+	rv = _PR_MD_RENAME(from, to);
+	if (rv < 0) {
+		return PR_FAILURE;
+	} else
+		return PR_SUCCESS;
+}
+
+PR_IMPLEMENT(PRStatus) PR_Access(const char *name, PRAccessHow how)
+{
+PRInt32 rv;
+
+	rv = _PR_MD_ACCESS(name, how);
+	if (rv < 0) {
+		return PR_FAILURE;
+	} else
+		return PR_SUCCESS;
+}
+
+/*
+** Import an existing OS file to NSPR 
+*/
+PR_IMPLEMENT(PRFileDesc*) PR_ImportFile(PROsfd osfd)
+{
+    PRFileDesc *fd = NULL;
+
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+
+    fd = PR_AllocFileDesc(osfd, &_pr_fileMethods);
+    if( !fd ) {
+        (void) _PR_MD_CLOSE_FILE(osfd);
+    } else {
+        _PR_MD_INIT_FD_INHERITABLE(fd, PR_TRUE);
+    }
+
+    return fd;
+}
+
+/*
+** Import an existing OS pipe to NSPR 
+*/
+PR_IMPLEMENT(PRFileDesc*) PR_ImportPipe(PROsfd osfd)
+{
+    PRFileDesc *fd = NULL;
+
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+
+    fd = PR_AllocFileDesc(osfd, &_pr_pipeMethods);
+    if( !fd ) {
+        (void) _PR_MD_CLOSE_FILE(osfd);
+    } else {
+        _PR_MD_INIT_FD_INHERITABLE(fd, PR_TRUE);
+#ifdef WINNT
+        fd->secret->md.sync_file_io = PR_TRUE;
+#endif
+    }
+
+    return fd;
+}
+
+#ifndef NO_NSPR_10_SUPPORT
+/*
+** PR_Stat() for Win16 is defined in w16io.c
+** it is a hack to circumvent problems in Gromit and Java
+** See also: BugSplat: 98516.
+*/
+#if !defined(WIN16)
+/*
+ * This function is supposed to be for backward compatibility with
+ * nspr 1.0.  Therefore, it still uses the nspr 1.0 error-reporting
+ * mechanism -- returns a PRInt32, which is the error code when the call
+ * fails.
+ * 
+ * If we need this function in nspr 2.0, it should be changed to
+ * return PRStatus, as follows:
+ *
+ * PR_IMPLEMENT(PRStatus) PR_Stat(const char *name, struct stat *buf)
+ * {
+ *     PRInt32 rv;
+ *
+ *     rv = _PR_MD_STAT(name, buf);
+ *     if (rv < 0)
+ *         return PR_FAILURE;
+ *     else
+ *         return PR_SUCCESS;
+ * }
+ *
+ * -- wtc, 2/14/97.
+ */
+PR_IMPLEMENT(PRInt32) PR_Stat(const char *name, struct stat *buf)
+{
+    PRInt32 rv;
+
+    rv = _PR_MD_STAT(name, buf);
+	return rv;
+}
+
+#endif /* !defined(WIN16)  */
+#endif /* ! NO_NSPR_10_SUPPORT */
+
+PR_IMPLEMENT(PRStatus) PR_LockFile(PRFileDesc *fd)
+{
+    PRStatus status = PR_SUCCESS;
+
+#ifdef WINNT
+    if (!fd->secret->md.io_model_committed) {
+        PRInt32 rv;
+        rv = _md_Associate((HANDLE)fd->secret->md.osfd);
+        PR_ASSERT(0 != rv);
+        fd->secret->md.io_model_committed = PR_TRUE;
+    }
+#endif
+
+    PR_Lock(_pr_flock_lock);
+    while (fd->secret->lockCount == -1)
+        PR_WaitCondVar(_pr_flock_cv, PR_INTERVAL_NO_TIMEOUT);
+    if (fd->secret->lockCount == 0) {
+        fd->secret->lockCount = -1;
+        PR_Unlock(_pr_flock_lock);
+        status = _PR_MD_LOCKFILE(fd->secret->md.osfd);
+        PR_Lock(_pr_flock_lock);
+        fd->secret->lockCount = (status == PR_SUCCESS) ? 1 : 0;
+        PR_NotifyAllCondVar(_pr_flock_cv);
+    } else {
+        fd->secret->lockCount++;
+    }
+    PR_Unlock(_pr_flock_lock);
+ 
+    return status;
+}
+
+PR_IMPLEMENT(PRStatus) PR_TLockFile(PRFileDesc *fd)
+{
+    PRStatus status = PR_SUCCESS;
+
+#ifdef WINNT
+    if (!fd->secret->md.io_model_committed) {
+        PRInt32 rv;
+        rv = _md_Associate((HANDLE)fd->secret->md.osfd);
+        PR_ASSERT(0 != rv);
+        fd->secret->md.io_model_committed = PR_TRUE;
+    }
+#endif
+
+    PR_Lock(_pr_flock_lock);
+    if (fd->secret->lockCount == 0) {
+        status = _PR_MD_TLOCKFILE(fd->secret->md.osfd);
+        PR_ASSERT(status == PR_SUCCESS || fd->secret->lockCount == 0);
+        if (status == PR_SUCCESS)
+            fd->secret->lockCount = 1;
+    } else {
+        fd->secret->lockCount++;
+    }
+    PR_Unlock(_pr_flock_lock);
+
+    return status;
+}
+
+PR_IMPLEMENT(PRStatus) PR_UnlockFile(PRFileDesc *fd)
+{
+    PRStatus rv = PR_SUCCESS;
+
+    PR_Lock(_pr_flock_lock);
+    if (fd->secret->lockCount == 1) {
+        rv = _PR_MD_UNLOCKFILE(fd->secret->md.osfd);
+        if (rv == PR_SUCCESS) 
+            fd->secret->lockCount = 0;
+    } else {
+        fd->secret->lockCount--;
+    }
+    PR_Unlock(_pr_flock_lock);
+
+    return rv;
+}
+
+PR_IMPLEMENT(PRStatus) PR_CreatePipe(
+    PRFileDesc **readPipe,
+    PRFileDesc **writePipe
+)
+{
+#if defined(WIN32) && !defined(WINCE)
+    HANDLE readEnd, writeEnd;
+    SECURITY_ATTRIBUTES pipeAttributes;
+
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+
+    ZeroMemory(&pipeAttributes, sizeof(pipeAttributes));
+    pipeAttributes.nLength = sizeof(pipeAttributes);
+    pipeAttributes.bInheritHandle = TRUE;
+    if (CreatePipe(&readEnd, &writeEnd, &pipeAttributes, 0) == 0) {
+        PR_SetError(PR_UNKNOWN_ERROR, GetLastError());
+        return PR_FAILURE;
+    }
+    *readPipe = PR_AllocFileDesc((PROsfd)readEnd, &_pr_pipeMethods);
+    if (NULL == *readPipe) {
+        CloseHandle(readEnd);
+        CloseHandle(writeEnd);
+        return PR_FAILURE;
+    }
+    *writePipe = PR_AllocFileDesc((PROsfd)writeEnd, &_pr_pipeMethods);
+    if (NULL == *writePipe) {
+        PR_Close(*readPipe);
+        CloseHandle(writeEnd);
+        return PR_FAILURE;
+    }
+#ifdef WINNT
+    (*readPipe)->secret->md.sync_file_io = PR_TRUE;
+    (*writePipe)->secret->md.sync_file_io = PR_TRUE;
+#endif
+    (*readPipe)->secret->inheritable = _PR_TRI_TRUE;
+    (*writePipe)->secret->inheritable = _PR_TRI_TRUE;
+    return PR_SUCCESS;
+#elif defined(XP_UNIX) || defined(XP_OS2) || defined(XP_BEOS)
+#ifdef XP_OS2
+    HFILE pipefd[2];
+#else
+    int pipefd[2];
+#endif
+
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+
+#ifdef XP_OS2
+    if (DosCreatePipe(&pipefd[0], &pipefd[1], 4096) != 0) {
+#else
+    if (pipe(pipefd) == -1) {
+#endif
+        /* XXX map pipe error */
+        PR_SetError(PR_UNKNOWN_ERROR, errno);
+        return PR_FAILURE;
+    }
+    *readPipe = PR_AllocFileDesc(pipefd[0], &_pr_pipeMethods);
+    if (NULL == *readPipe) {
+        close(pipefd[0]);
+        close(pipefd[1]);
+        return PR_FAILURE;
+    }
+    *writePipe = PR_AllocFileDesc(pipefd[1], &_pr_pipeMethods);
+    if (NULL == *writePipe) {
+        PR_Close(*readPipe);
+        close(pipefd[1]);
+        return PR_FAILURE;
+    }
+#ifndef XP_BEOS /* Pipes are nonblocking on BeOS */
+    _PR_MD_MAKE_NONBLOCK(*readPipe);
+#endif
+    _PR_MD_INIT_FD_INHERITABLE(*readPipe, PR_FALSE);
+#ifndef XP_BEOS /* Pipes are nonblocking on BeOS */
+    _PR_MD_MAKE_NONBLOCK(*writePipe);
+#endif
+    _PR_MD_INIT_FD_INHERITABLE(*writePipe, PR_FALSE);
+    return PR_SUCCESS;
+#else
+    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+    return PR_FAILURE;
+#endif
+}
+
+#ifdef MOZ_UNICODE
+/* ================ UTF16 Interfaces ================================ */
+PR_IMPLEMENT(PRFileDesc*) PR_OpenFileUTF16(
+    const PRUnichar *name, PRIntn flags, PRIntn mode)
+{ 
+    PROsfd osfd;
+    PRFileDesc *fd = 0;
+#if !defined(_PR_HAVE_O_APPEND)
+    PRBool  appendMode = ( PR_APPEND & flags )? PR_TRUE : PR_FALSE;
+#endif
+   
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+  
+    /* Map pr open flags and mode to os specific flags */
+    osfd = _PR_MD_OPEN_FILE_UTF16(name, flags, mode);
+    if (osfd != -1) {
+        fd = PR_AllocFileDesc(osfd, &_pr_fileMethods);
+        if (!fd) {
+            (void) _PR_MD_CLOSE_FILE(osfd);
+        } else {
+#if !defined(_PR_HAVE_O_APPEND)
+            fd->secret->appendMode = appendMode;
+#endif
+            _PR_MD_INIT_FD_INHERITABLE(fd, PR_FALSE);
+        }
+    }
+    return fd;
+}
+ 
+PR_IMPLEMENT(PRStatus) PR_GetFileInfo64UTF16(const PRUnichar *fn, PRFileInfo64 *info)
+{
+    PRInt32 rv;
+
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+    rv = _PR_MD_GETFILEINFO64_UTF16(fn, info);
+    if (rv < 0) {
+        return PR_FAILURE;
+    } else {
+        return PR_SUCCESS;
+    }
+}
+
+/* ================ UTF16 Interfaces ================================ */
+#endif /* MOZ_UNICODE */
diff --git a/pr/src/io/prio.c b/pr/src/io/prio.c
new file mode 100644
index 0000000..78cbdf5
--- /dev/null
+++ b/pr/src/io/prio.c
@@ -0,0 +1,180 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "primpl.h"
+
+#include <string.h> /* for memset() */
+
+
+/************************************************************************/
+
+PRLock *_pr_flock_lock;
+PRCondVar *_pr_flock_cv;
+
+#ifdef WINCE
+/*
+ * There are no stdin, stdout, stderr in Windows CE.  INVALID_HANDLE_VALUE
+ * should cause all I/O functions on the handle to fail.
+ */
+#define STD_INPUT_HANDLE  ((DWORD)-10)
+#define STD_OUTPUT_HANDLE ((DWORD)-11)
+#define STD_ERROR_HANDLE  ((DWORD)-12)
+
+static HANDLE GetStdHandle(DWORD nStdHandle)
+{
+    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+    return INVALID_HANDLE_VALUE;
+}
+#endif
+
+void _PR_InitIO(void)
+{
+    const PRIOMethods *methods = PR_GetFileMethods();
+
+    _PR_InitFdCache();
+
+    _pr_flock_lock = PR_NewLock();
+    _pr_flock_cv = PR_NewCondVar(_pr_flock_lock);
+
+#ifdef WIN32
+    _pr_stdin = PR_AllocFileDesc((PROsfd)GetStdHandle(STD_INPUT_HANDLE),
+            methods);
+    _pr_stdout = PR_AllocFileDesc((PROsfd)GetStdHandle(STD_OUTPUT_HANDLE),
+            methods);
+    _pr_stderr = PR_AllocFileDesc((PROsfd)GetStdHandle(STD_ERROR_HANDLE),
+            methods);
+#ifdef WINNT
+    _pr_stdin->secret->md.sync_file_io = PR_TRUE;
+    _pr_stdout->secret->md.sync_file_io = PR_TRUE;
+    _pr_stderr->secret->md.sync_file_io = PR_TRUE;
+#endif
+#else
+    _pr_stdin = PR_AllocFileDesc(0, methods);
+    _pr_stdout = PR_AllocFileDesc(1, methods);
+    _pr_stderr = PR_AllocFileDesc(2, methods);
+#endif
+    _PR_MD_INIT_FD_INHERITABLE(_pr_stdin, PR_TRUE);
+    _PR_MD_INIT_FD_INHERITABLE(_pr_stdout, PR_TRUE);
+    _PR_MD_INIT_FD_INHERITABLE(_pr_stderr, PR_TRUE);
+
+    _PR_MD_INIT_IO();
+}
+
+void _PR_CleanupIO(void)
+{
+    PR_FreeFileDesc(_pr_stdin);
+    _pr_stdin = NULL;
+    PR_FreeFileDesc(_pr_stdout);
+    _pr_stdout = NULL;
+    PR_FreeFileDesc(_pr_stderr);
+    _pr_stderr = NULL;
+
+    if (_pr_flock_cv) {
+        PR_DestroyCondVar(_pr_flock_cv);
+        _pr_flock_cv = NULL;
+    }
+    if (_pr_flock_lock) {
+        PR_DestroyLock(_pr_flock_lock);
+        _pr_flock_lock = NULL;
+    }
+
+    _PR_CleanupFdCache();
+}
+
+PR_IMPLEMENT(PRFileDesc*) PR_GetSpecialFD(PRSpecialFD osfd)
+{
+    PRFileDesc *result = NULL;
+    PR_ASSERT((int) osfd >= PR_StandardInput && osfd <= PR_StandardError);
+
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+    
+    switch (osfd)
+    {
+        case PR_StandardInput: result = _pr_stdin; break;
+        case PR_StandardOutput: result = _pr_stdout; break;
+        case PR_StandardError: result = _pr_stderr; break;
+        default:
+            (void)PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+    }
+    return result;
+}
+
+PR_IMPLEMENT(PRFileDesc*) PR_AllocFileDesc(
+    PROsfd osfd, const PRIOMethods *methods)
+{
+    PRFileDesc *fd;
+
+#ifdef XP_UNIX
+	/*
+	 * Assert that the file descriptor is small enough to fit in the
+	 * fd_set passed to select
+	 */
+	PR_ASSERT(osfd < FD_SETSIZE);
+#endif
+    fd = _PR_Getfd();
+    if (fd) {
+        /* Initialize the members of PRFileDesc and PRFilePrivate */
+        fd->methods = methods;
+        fd->secret->state = _PR_FILEDESC_OPEN;
+	fd->secret->md.osfd = osfd;
+        _PR_MD_INIT_FILEDESC(fd);
+    } else {
+	    PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+    }
+
+    return fd;
+}
+
+PR_IMPLEMENT(void) PR_FreeFileDesc(PRFileDesc *fd)
+{
+    PR_ASSERT(fd);
+    _PR_Putfd(fd);
+}
+
+/*
+** Wait for some i/o to finish on one or more more poll descriptors.
+*/
+PR_IMPLEMENT(PRInt32) PR_Poll(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
+{
+	return(_PR_MD_PR_POLL(pds, npds, timeout));
+}
+
+/*
+** Set the inheritance attribute of a file descriptor.
+*/
+PR_IMPLEMENT(PRStatus) PR_SetFDInheritable(
+    PRFileDesc *fd,
+    PRBool inheritable)
+{
+#if defined(XP_UNIX) || defined(WIN32) || defined(XP_OS2) || defined(XP_BEOS)
+    /*
+     * Only a non-layered, NSPR file descriptor can be inherited
+     * by a child process.
+     */
+    if (fd->identity != PR_NSPR_IO_LAYER) {
+        PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+        return PR_FAILURE;
+    }
+    if (fd->secret->inheritable != inheritable) {
+        if (_PR_MD_SET_FD_INHERITABLE(fd, inheritable) == PR_FAILURE) {
+            return PR_FAILURE;
+        }
+        fd->secret->inheritable = inheritable;
+    }
+    return PR_SUCCESS;
+#else
+    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+    return PR_FAILURE;
+#endif
+}
+
+/*
+** This function only has a useful implementation in the debug build of
+** the pthreads version.
+*/
+PR_IMPLEMENT(void) PT_FPrintStats(PRFileDesc *debug_out, const char *msg)
+{
+    /* do nothing */
+}  /* PT_FPrintStats */
diff --git a/pr/src/io/priometh.c b/pr/src/io/priometh.c
new file mode 100644
index 0000000..4208767
--- /dev/null
+++ b/pr/src/io/priometh.c
@@ -0,0 +1,596 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#include "primpl.h"
+
+#include <string.h>
+
+/*****************************************************************************/
+/************************** Invalid I/O method object ************************/
+/*****************************************************************************/
+PRIOMethods _pr_faulty_methods = {
+    (PRDescType)0,
+    (PRCloseFN)_PR_InvalidStatus,
+    (PRReadFN)_PR_InvalidInt,
+    (PRWriteFN)_PR_InvalidInt,
+    (PRAvailableFN)_PR_InvalidInt,
+    (PRAvailable64FN)_PR_InvalidInt64,
+    (PRFsyncFN)_PR_InvalidStatus,
+    (PRSeekFN)_PR_InvalidInt,
+    (PRSeek64FN)_PR_InvalidInt64,
+    (PRFileInfoFN)_PR_InvalidStatus,
+    (PRFileInfo64FN)_PR_InvalidStatus,
+    (PRWritevFN)_PR_InvalidInt,        
+    (PRConnectFN)_PR_InvalidStatus,        
+    (PRAcceptFN)_PR_InvalidDesc,        
+    (PRBindFN)_PR_InvalidStatus,        
+    (PRListenFN)_PR_InvalidStatus,        
+    (PRShutdownFN)_PR_InvalidStatus,    
+    (PRRecvFN)_PR_InvalidInt,        
+    (PRSendFN)_PR_InvalidInt,        
+    (PRRecvfromFN)_PR_InvalidInt,    
+    (PRSendtoFN)_PR_InvalidInt,        
+    (PRPollFN)_PR_InvalidInt16,
+    (PRAcceptreadFN)_PR_InvalidInt,   
+    (PRTransmitfileFN)_PR_InvalidInt, 
+    (PRGetsocknameFN)_PR_InvalidStatus,    
+    (PRGetpeernameFN)_PR_InvalidStatus,    
+    (PRReservedFN)_PR_InvalidInt,    
+    (PRReservedFN)_PR_InvalidInt,    
+    (PRGetsocketoptionFN)_PR_InvalidStatus,
+    (PRSetsocketoptionFN)_PR_InvalidStatus,
+    (PRSendfileFN)_PR_InvalidInt, 
+    (PRConnectcontinueFN)_PR_InvalidStatus,
+    (PRReservedFN)_PR_InvalidInt,
+    (PRReservedFN)_PR_InvalidInt,
+    (PRReservedFN)_PR_InvalidInt,
+    (PRReservedFN)_PR_InvalidInt
+};
+
+PRIntn _PR_InvalidInt(void)
+{
+    PR_NOT_REACHED("I/O method is invalid");
+    PR_SetError(PR_INVALID_METHOD_ERROR, 0);
+    return -1;
+}  /* _PR_InvalidInt */
+
+PRInt16 _PR_InvalidInt16(void)
+{
+    PR_NOT_REACHED("I/O method is invalid");
+    PR_SetError(PR_INVALID_METHOD_ERROR, 0);
+    return -1;
+}  /* _PR_InvalidInt */
+
+PRInt64 _PR_InvalidInt64(void)
+{
+    PRInt64 rv;
+    LL_I2L(rv, -1);
+    PR_NOT_REACHED("I/O method is invalid");
+    PR_SetError(PR_INVALID_METHOD_ERROR, 0);
+    return rv;
+}  /* _PR_InvalidInt */
+
+/*
+ * An invalid method that returns PRStatus
+ */
+
+PRStatus _PR_InvalidStatus(void)
+{
+    PR_NOT_REACHED("I/O method is invalid");
+    PR_SetError(PR_INVALID_METHOD_ERROR, 0);
+    return PR_FAILURE;
+}  /* _PR_InvalidDesc */
+
+/*
+ * An invalid method that returns a pointer
+ */
+
+PRFileDesc *_PR_InvalidDesc(void)
+{
+    PR_NOT_REACHED("I/O method is invalid");
+    PR_SetError(PR_INVALID_METHOD_ERROR, 0);
+    return NULL;
+}  /* _PR_InvalidDesc */
+
+PR_IMPLEMENT(PRDescType) PR_GetDescType(PRFileDesc *file)
+{
+    return file->methods->file_type;
+}
+
+PR_IMPLEMENT(PRStatus) PR_Close(PRFileDesc *fd)
+{
+    return (fd->methods->close)(fd);
+}
+
+PR_IMPLEMENT(PRInt32) PR_Read(PRFileDesc *fd, void *buf, PRInt32 amount)
+{
+	return((fd->methods->read)(fd,buf,amount));
+}
+
+PR_IMPLEMENT(PRInt32) PR_Write(PRFileDesc *fd, const void *buf, PRInt32 amount)
+{
+	return((fd->methods->write)(fd,buf,amount));
+}
+
+PR_IMPLEMENT(PRInt32) PR_Seek(PRFileDesc *fd, PRInt32 offset, PRSeekWhence whence)
+{
+	return((fd->methods->seek)(fd, offset, whence));
+}
+
+PR_IMPLEMENT(PRInt64) PR_Seek64(PRFileDesc *fd, PRInt64 offset, PRSeekWhence whence)
+{
+	return((fd->methods->seek64)(fd, offset, whence));
+}
+
+PR_IMPLEMENT(PRInt32) PR_Available(PRFileDesc *fd)
+{
+	return((fd->methods->available)(fd));
+}
+
+PR_IMPLEMENT(PRInt64) PR_Available64(PRFileDesc *fd)
+{
+	return((fd->methods->available64)(fd));
+}
+
+PR_IMPLEMENT(PRStatus) PR_GetOpenFileInfo(PRFileDesc *fd, PRFileInfo *info)
+{
+	return((fd->methods->fileInfo)(fd, info));
+}
+
+PR_IMPLEMENT(PRStatus) PR_GetOpenFileInfo64(PRFileDesc *fd, PRFileInfo64 *info)
+{
+	return((fd->methods->fileInfo64)(fd, info));
+}
+
+PR_IMPLEMENT(PRStatus) PR_Sync(PRFileDesc *fd)
+{
+	return((fd->methods->fsync)(fd));
+}
+
+PR_IMPLEMENT(PRStatus) PR_Connect(
+    PRFileDesc *fd, const PRNetAddr *addr, PRIntervalTime timeout)
+{
+	return((fd->methods->connect)(fd,addr,timeout));
+}
+
+PR_IMPLEMENT(PRStatus) PR_ConnectContinue(
+    PRFileDesc *fd, PRInt16 out_flags)
+{
+	return((fd->methods->connectcontinue)(fd,out_flags));
+}
+
+PR_IMPLEMENT(PRFileDesc*) PR_Accept(PRFileDesc *fd, PRNetAddr *addr,
+PRIntervalTime timeout)
+{
+	return((fd->methods->accept)(fd,addr,timeout));
+}
+
+PR_IMPLEMENT(PRStatus) PR_Bind(PRFileDesc *fd, const PRNetAddr *addr)
+{
+	return((fd->methods->bind)(fd,addr));
+}
+
+PR_IMPLEMENT(PRStatus) PR_Shutdown(PRFileDesc *fd, PRShutdownHow how)
+{
+	return((fd->methods->shutdown)(fd,how));
+}
+
+PR_IMPLEMENT(PRStatus) PR_Listen(PRFileDesc *fd, PRIntn backlog)
+{
+	return((fd->methods->listen)(fd,backlog));
+}
+
+PR_IMPLEMENT(PRInt32) PR_Recv(PRFileDesc *fd, void *buf, PRInt32 amount,
+PRIntn flags, PRIntervalTime timeout)
+{
+	return((fd->methods->recv)(fd,buf,amount,flags,timeout));
+}
+
+PR_IMPLEMENT(PRInt32) PR_Send(PRFileDesc *fd, const void *buf, PRInt32 amount,
+PRIntn flags, PRIntervalTime timeout)
+{
+	return((fd->methods->send)(fd,buf,amount,flags,timeout));
+}
+
+PR_IMPLEMENT(PRInt32) PR_Writev(PRFileDesc *fd, const PRIOVec *iov,
+PRInt32 iov_size, PRIntervalTime timeout)
+{
+    if (iov_size > PR_MAX_IOVECTOR_SIZE)
+    {
+        PR_SetError(PR_BUFFER_OVERFLOW_ERROR, 0);
+        return -1;
+    }
+	return((fd->methods->writev)(fd,iov,iov_size,timeout));
+}
+
+PR_IMPLEMENT(PRInt32) PR_RecvFrom(PRFileDesc *fd, void *buf, PRInt32 amount,
+PRIntn flags, PRNetAddr *addr, PRIntervalTime timeout)
+{
+	return((fd->methods->recvfrom)(fd,buf,amount,flags,addr,timeout));
+}
+
+PR_IMPLEMENT(PRInt32) PR_SendTo(
+    PRFileDesc *fd, const void *buf, PRInt32 amount,
+    PRIntn flags, const PRNetAddr *addr, PRIntervalTime timeout)
+{
+	return((fd->methods->sendto)(fd,buf,amount,flags,addr,timeout));
+}
+
+PR_IMPLEMENT(PRInt32) PR_TransmitFile(
+    PRFileDesc *sd, PRFileDesc *fd, const void *hdr, PRInt32 hlen,
+    PRTransmitFileFlags flags, PRIntervalTime timeout)
+{
+	return((sd->methods->transmitfile)(sd,fd,hdr,hlen,flags,timeout));
+}
+
+PR_IMPLEMENT(PRInt32) PR_AcceptRead(
+    PRFileDesc *sd, PRFileDesc **nd, PRNetAddr **raddr,
+    void *buf, PRInt32 amount, PRIntervalTime timeout)
+{
+	return((sd->methods->acceptread)(sd, nd, raddr, buf, amount,timeout));
+}
+
+PR_IMPLEMENT(PRStatus) PR_GetSockName(PRFileDesc *fd, PRNetAddr *addr)
+{
+	return((fd->methods->getsockname)(fd,addr));
+}
+
+PR_IMPLEMENT(PRStatus) PR_GetPeerName(PRFileDesc *fd, PRNetAddr *addr)
+{
+	return((fd->methods->getpeername)(fd,addr));
+}
+
+PR_IMPLEMENT(PRStatus) PR_GetSocketOption(
+    PRFileDesc *fd, PRSocketOptionData *data)
+{
+	return((fd->methods->getsocketoption)(fd, data));
+}
+
+PR_IMPLEMENT(PRStatus) PR_SetSocketOption(
+    PRFileDesc *fd, const PRSocketOptionData *data)
+{
+	return((fd->methods->setsocketoption)(fd, data));
+}
+
+PR_IMPLEMENT(PRInt32) PR_SendFile(
+	PRFileDesc *sd, PRSendFileData *sfd,
+	PRTransmitFileFlags flags, PRIntervalTime timeout)
+{
+	return((sd->methods->sendfile)(sd,sfd,flags,timeout));
+}
+
+PR_IMPLEMENT(PRInt32) PR_EmulateAcceptRead(
+    PRFileDesc *sd, PRFileDesc **nd, PRNetAddr **raddr,
+    void *buf, PRInt32 amount, PRIntervalTime timeout)
+{
+    PRInt32 rv = -1;
+    PRNetAddr remote;
+    PRFileDesc *accepted = NULL;
+
+    /*
+    ** The timeout does not apply to the accept portion of the
+    ** operation - it waits indefinitely.
+    */
+    accepted = PR_Accept(sd, &remote, PR_INTERVAL_NO_TIMEOUT);
+    if (NULL == accepted) return rv;
+
+    rv = PR_Recv(accepted, buf, amount, 0, timeout);
+    if (rv >= 0)
+    {
+        /* copy the new info out where caller can see it */
+#define AMASK ((PRPtrdiff)7)  /* mask for alignment of PRNetAddr */
+        PRPtrdiff aligned = (PRPtrdiff)buf + amount + AMASK;
+        *raddr = (PRNetAddr*)(aligned & ~AMASK);
+        memcpy(*raddr, &remote, PR_NETADDR_SIZE(&remote));
+        *nd = accepted;
+        return rv;
+    }
+
+    PR_Close(accepted);
+    return rv;
+}
+
+/*
+ * PR_EmulateSendFile
+ *
+ *    Send file sfd->fd across socket sd. If header/trailer are specified
+ *    they are sent before and after the file, respectively.
+ *
+ *    PR_TRANSMITFILE_CLOSE_SOCKET flag - close socket after sending file
+ *    
+ *    return number of bytes sent or -1 on error
+ *
+ */
+
+#if defined(XP_UNIX) || defined(WIN32)
+
+/*
+ * An implementation based on memory-mapped files
+ */
+
+#define SENDFILE_MMAP_CHUNK	(256 * 1024)
+
+PR_IMPLEMENT(PRInt32) PR_EmulateSendFile(
+    PRFileDesc *sd, PRSendFileData *sfd,
+    PRTransmitFileFlags flags, PRIntervalTime timeout)
+{
+    PRInt32 rv, count = 0;
+    PRInt32 len, file_bytes, index = 0;
+    PRFileInfo info;
+    PRIOVec iov[3];
+    PRFileMap *mapHandle = NULL;
+    void *addr = (void*)0; /* initialized to some arbitrary value. Keeps compiler warnings down. */
+    PRUint32 file_mmap_offset, alignment;
+    PRInt64 zero64;
+    PROffset64 file_mmap_offset64;
+    PRUint32 addr_offset, mmap_len;
+
+    /* Get file size */
+    if (PR_SUCCESS != PR_GetOpenFileInfo(sfd->fd, &info)) {
+        count = -1;
+        goto done;
+    }
+    if (sfd->file_nbytes &&
+            (info.size < (sfd->file_offset + sfd->file_nbytes))) {
+        /*
+         * there are fewer bytes in file to send than specified
+         */
+        PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+        count = -1;
+        goto done;
+    }
+    if (sfd->file_nbytes)
+        file_bytes = sfd->file_nbytes;
+    else
+        file_bytes = info.size - sfd->file_offset;
+
+    alignment = PR_GetMemMapAlignment();
+
+    /* number of initial bytes to skip in mmap'd segment */
+    addr_offset = sfd->file_offset % alignment;
+
+    /* find previous mmap alignment boundary */
+    file_mmap_offset = sfd->file_offset - addr_offset;
+
+    /*
+     * If the file is large, mmap and send the file in chunks so as
+     * to not consume too much virtual address space
+     */
+    mmap_len = PR_MIN(file_bytes + addr_offset, SENDFILE_MMAP_CHUNK);
+    len = mmap_len - addr_offset;
+
+    /*
+     * Map in (part of) file. Take care of zero-length files.
+     */
+    if (len) {
+        LL_I2L(zero64, 0);
+        mapHandle = PR_CreateFileMap(sfd->fd, zero64, PR_PROT_READONLY);
+        if (!mapHandle) {
+            count = -1;
+            goto done;
+        }
+        LL_I2L(file_mmap_offset64, file_mmap_offset);
+        addr = PR_MemMap(mapHandle, file_mmap_offset64, mmap_len);
+        if (!addr) {
+            count = -1;
+            goto done;
+        }
+    }
+    /*
+     * send headers first, followed by the file
+     */
+    if (sfd->hlen) {
+        iov[index].iov_base = (char *) sfd->header;
+        iov[index].iov_len = sfd->hlen;
+        index++;
+    }
+    if (len) {
+        iov[index].iov_base = (char*)addr + addr_offset;
+        iov[index].iov_len = len;
+        index++;
+    }
+    if ((file_bytes == len) && (sfd->tlen)) {
+        /*
+         * all file data is mapped in; send the trailer too
+         */
+        iov[index].iov_base = (char *) sfd->trailer;
+        iov[index].iov_len = sfd->tlen;
+        index++;
+    }
+    rv = PR_Writev(sd, iov, index, timeout);
+    if (len)
+        PR_MemUnmap(addr, mmap_len);
+    if (rv < 0) {
+        count = -1;
+        goto done;
+    }
+
+    PR_ASSERT(rv == sfd->hlen + len + ((len == file_bytes) ? sfd->tlen : 0));
+
+    file_bytes -= len;
+    count += rv;
+    if (!file_bytes)    /* header, file and trailer are sent */
+        goto done;
+
+    /*
+     * send remaining bytes of the file, if any
+     */
+    len = PR_MIN(file_bytes, SENDFILE_MMAP_CHUNK);
+    while (len > 0) {
+        /*
+         * Map in (part of) file
+         */
+        file_mmap_offset = sfd->file_offset + count - sfd->hlen;
+        PR_ASSERT((file_mmap_offset % alignment) == 0);
+
+        LL_I2L(file_mmap_offset64, file_mmap_offset);
+        addr = PR_MemMap(mapHandle, file_mmap_offset64, len);
+        if (!addr) {
+            count = -1;
+            goto done;
+        }
+        rv = PR_Send(sd, addr, len, 0, timeout);
+        PR_MemUnmap(addr, len);
+        if (rv < 0) {
+            count = -1;
+            goto done;
+        }
+
+        PR_ASSERT(rv == len);
+        file_bytes -= rv;
+        count += rv;
+        len = PR_MIN(file_bytes, SENDFILE_MMAP_CHUNK);
+    }
+    PR_ASSERT(0 == file_bytes);
+    if (sfd->tlen) {
+        rv = PR_Send(sd, sfd->trailer, sfd->tlen, 0, timeout);
+        if (rv >= 0) {
+            PR_ASSERT(rv == sfd->tlen);
+            count += rv;
+        } else
+            count = -1;
+    }
+done:
+    if (mapHandle)
+        PR_CloseFileMap(mapHandle);
+    if ((count >= 0) && (flags & PR_TRANSMITFILE_CLOSE_SOCKET))
+        PR_Close(sd);
+    return count;
+}
+
+#else
+
+PR_IMPLEMENT(PRInt32) PR_EmulateSendFile(
+    PRFileDesc *sd, PRSendFileData *sfd,
+    PRTransmitFileFlags flags, PRIntervalTime timeout)
+{
+    PRInt32 rv, count = 0;
+    PRInt32 rlen;
+    const void * buffer;
+    PRInt32 buflen;
+    PRInt32 sendbytes, readbytes;
+    char *buf;
+
+#define _SENDFILE_BUFSIZE   (16 * 1024)
+
+    buf = (char*)PR_MALLOC(_SENDFILE_BUFSIZE);
+    if (buf == NULL) {
+        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+        return -1;
+    }
+
+    /*
+     * send header first
+     */
+    buflen = sfd->hlen;
+    buffer = sfd->header;
+    while (buflen) {
+        rv = PR_Send(sd, buffer, buflen, 0, timeout);
+        if (rv < 0) {
+            /* PR_Send() has invoked PR_SetError(). */
+            rv = -1;
+            goto done;
+        } else {
+            count += rv;
+            buffer = (const void*) ((const char*)buffer + rv);
+            buflen -= rv;
+        }
+    }
+
+    /*
+     * send file next
+     */
+    if (PR_Seek(sfd->fd, sfd->file_offset, PR_SEEK_SET) < 0) {
+        rv = -1;
+        goto done;
+    }
+    sendbytes = sfd->file_nbytes;
+    if (sendbytes == 0) {
+        /* send entire file */
+        while ((rlen = PR_Read(sfd->fd, buf, _SENDFILE_BUFSIZE)) > 0) {
+            while (rlen) {
+                char *bufptr = buf;
+
+                rv =  PR_Send(sd, bufptr, rlen, 0, timeout);
+                if (rv < 0) {
+                    /* PR_Send() has invoked PR_SetError(). */
+                    rv = -1;
+                    goto done;
+                } else {
+                    count += rv;
+                    bufptr = ((char*)bufptr + rv);
+                    rlen -= rv;
+                }
+            }
+        }
+        if (rlen < 0) {
+            /* PR_Read() has invoked PR_SetError(). */
+            rv = -1;
+            goto done;
+        }
+    } else {
+        readbytes = PR_MIN(sendbytes, _SENDFILE_BUFSIZE);
+        while (readbytes && ((rlen = PR_Read(sfd->fd, buf, readbytes)) > 0)) {
+            while (rlen) {
+                char *bufptr = buf;
+
+                rv =  PR_Send(sd, bufptr, rlen, 0, timeout);
+                if (rv < 0) {
+                    /* PR_Send() has invoked PR_SetError(). */
+                    rv = -1;
+                    goto done;
+                } else {
+                    count += rv;
+                    sendbytes -= rv;
+                    bufptr = ((char*)bufptr + rv);
+                    rlen -= rv;
+                }
+            }
+            readbytes = PR_MIN(sendbytes, _SENDFILE_BUFSIZE);
+        }
+        if (rlen < 0) {
+            /* PR_Read() has invoked PR_SetError(). */
+            rv = -1;
+            goto done;
+        } else if (sendbytes != 0) {
+            /*
+             * there are fewer bytes in file to send than specified
+             */
+            PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+            rv = -1;
+            goto done;
+        }
+    }
+
+    /*
+     * send trailer last
+     */
+    buflen = sfd->tlen;
+    buffer = sfd->trailer;
+    while (buflen) {
+        rv =  PR_Send(sd, buffer, buflen, 0, timeout);
+        if (rv < 0) {
+            /* PR_Send() has invoked PR_SetError(). */
+            rv = -1;
+            goto done;
+        } else {
+            count += rv;
+            buffer = (const void*) ((const char*)buffer + rv);
+            buflen -= rv;
+        }
+    }
+    rv = count;
+
+done:
+    if (buf)
+        PR_DELETE(buf);
+    if ((rv >= 0) && (flags & PR_TRANSMITFILE_CLOSE_SOCKET))
+        PR_Close(sd);
+    return rv;
+}
+
+#endif
+
+/* priometh.c */
diff --git a/pr/src/io/pripv6.c b/pr/src/io/pripv6.c
new file mode 100644
index 0000000..af7de49
--- /dev/null
+++ b/pr/src/io/pripv6.c
@@ -0,0 +1,364 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** File:        pripv6.c
+** Description: Support for various functions unique to IPv6
+*/
+#include "primpl.h"
+#include <string.h>
+
+#if !defined(_PR_INET6) || defined(_PR_INET6_PROBE)
+
+static PRIOMethods ipv6_to_v4_tcpMethods;
+static PRIOMethods ipv6_to_v4_udpMethods;
+static PRDescIdentity _pr_ipv6_to_ipv4_id;
+extern PRBool IsValidNetAddr(const PRNetAddr *addr);
+extern PRIPv6Addr _pr_in6addr_any;
+extern PRIPv6Addr _pr_in6addr_loopback;
+
+/*
+ * convert an IPv4-mapped IPv6 addr to an IPv4 addr
+ */
+static void _PR_ConvertToIpv4NetAddr(const PRNetAddr *src_v6addr,
+											PRNetAddr *dst_v4addr)
+{
+const PRUint8 *srcp;
+
+	PR_ASSERT(PR_AF_INET6 == src_v6addr->ipv6.family);
+
+	if (PR_IsNetAddrType(src_v6addr, PR_IpAddrV4Mapped)) {
+		srcp = src_v6addr->ipv6.ip.pr_s6_addr;
+		memcpy((char *) &dst_v4addr->inet.ip, srcp + 12, 4);
+    } else if (PR_IsNetAddrType(src_v6addr, PR_IpAddrAny)) {
+        dst_v4addr->inet.ip = htonl(INADDR_ANY);
+    } else if (PR_IsNetAddrType(src_v6addr, PR_IpAddrLoopback)) {
+        dst_v4addr->inet.ip = htonl(INADDR_LOOPBACK);
+    }
+	dst_v4addr->inet.family = PR_AF_INET;
+	dst_v4addr->inet.port = src_v6addr->ipv6.port;
+}
+
+/*
+ * convert an IPv4 addr to an IPv4-mapped IPv6 addr
+ */
+static void _PR_ConvertToIpv6NetAddr(const PRNetAddr *src_v4addr,
+                                            PRNetAddr *dst_v6addr)
+{
+PRUint8 *dstp;
+
+	PR_ASSERT(PR_AF_INET == src_v4addr->inet.family);
+	dst_v6addr->ipv6.family = PR_AF_INET6;
+	dst_v6addr->ipv6.port = src_v4addr->inet.port;
+
+ 	if (htonl(INADDR_ANY) == src_v4addr->inet.ip) {
+		dst_v6addr->ipv6.ip = _pr_in6addr_any;
+	} else {
+		dstp = dst_v6addr->ipv6.ip.pr_s6_addr;
+		memset(dstp, 0, 10);
+		memset(dstp + 10, 0xff, 2);
+		memcpy(dstp + 12,(char *) &src_v4addr->inet.ip, 4);
+	}
+}
+
+static PRStatus PR_CALLBACK Ipv6ToIpv4SocketBind(PRFileDesc *fd,
+								const PRNetAddr *addr)
+{
+	PRNetAddr tmp_ipv4addr;
+	const PRNetAddr *tmp_addrp;
+	PRFileDesc *lo = fd->lower;
+
+	if (PR_AF_INET6 != addr->raw.family) {
+        PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, 0);
+		return PR_FAILURE;
+	}
+	if (PR_IsNetAddrType(addr, PR_IpAddrV4Mapped) ||
+    			PR_IsNetAddrType(addr, PR_IpAddrAny)) {
+		_PR_ConvertToIpv4NetAddr(addr, &tmp_ipv4addr);
+		tmp_addrp = &tmp_ipv4addr;
+	} else {
+        PR_SetError(PR_NETWORK_UNREACHABLE_ERROR, 0);
+		return PR_FAILURE;
+	}
+	return((lo->methods->bind)(lo,tmp_addrp));
+}
+
+static PRStatus PR_CALLBACK Ipv6ToIpv4SocketConnect(
+    PRFileDesc *fd, const PRNetAddr *addr, PRIntervalTime timeout)
+{
+	PRNetAddr tmp_ipv4addr;
+	const PRNetAddr *tmp_addrp;
+
+	if (PR_AF_INET6 != addr->raw.family) {
+        PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, 0);
+		return PR_FAILURE;
+	}
+	if (PR_IsNetAddrType(addr, PR_IpAddrV4Mapped) ||
+			PR_IsNetAddrType(addr, PR_IpAddrLoopback)) {
+		_PR_ConvertToIpv4NetAddr(addr, &tmp_ipv4addr);
+		tmp_addrp = &tmp_ipv4addr;
+	} else {
+        PR_SetError(PR_NETWORK_UNREACHABLE_ERROR, 0);
+		return PR_FAILURE;
+	}
+	return (fd->lower->methods->connect)(fd->lower, tmp_addrp, timeout);
+}
+
+static PRInt32 PR_CALLBACK Ipv6ToIpv4SocketSendTo(
+    PRFileDesc *fd, const void *buf, PRInt32 amount,
+    PRIntn flags, const PRNetAddr *addr, PRIntervalTime timeout)
+{
+	PRNetAddr tmp_ipv4addr;
+	const PRNetAddr *tmp_addrp;
+
+	if (PR_AF_INET6 != addr->raw.family) {
+        PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, 0);
+		return PR_FAILURE;
+	}
+	if (PR_IsNetAddrType(addr, PR_IpAddrV4Mapped) ||
+			PR_IsNetAddrType(addr, PR_IpAddrLoopback)) {
+		_PR_ConvertToIpv4NetAddr(addr, &tmp_ipv4addr);
+		tmp_addrp = &tmp_ipv4addr;
+	} else {
+        PR_SetError(PR_NETWORK_UNREACHABLE_ERROR, 0);
+		return PR_FAILURE;
+	}
+    return (fd->lower->methods->sendto)(
+        fd->lower, buf, amount, flags, tmp_addrp, timeout);
+}
+
+static PRFileDesc* PR_CALLBACK Ipv6ToIpv4SocketAccept (
+    PRFileDesc *fd, PRNetAddr *addr, PRIntervalTime timeout)
+{
+    PRStatus rv;
+    PRFileDesc *newfd;
+    PRFileDesc *newstack;
+	PRNetAddr tmp_ipv4addr;
+    PRNetAddr *addrlower = NULL;
+
+    PR_ASSERT(fd != NULL);
+    PR_ASSERT(fd->lower != NULL);
+
+    newstack = PR_NEW(PRFileDesc);
+    if (NULL == newstack)
+    {
+        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+        return NULL;
+    }
+    *newstack = *fd;  /* make a copy of the accepting layer */
+
+    if (addr)
+        addrlower = &tmp_ipv4addr;
+    newfd = (fd->lower->methods->accept)(fd->lower, addrlower, timeout);
+    if (NULL == newfd)
+    {
+        PR_DELETE(newstack);
+        return NULL;
+    }
+    if (addr)
+        _PR_ConvertToIpv6NetAddr(&tmp_ipv4addr, addr);
+
+    rv = PR_PushIOLayer(newfd, PR_TOP_IO_LAYER, newstack);
+    PR_ASSERT(PR_SUCCESS == rv);
+    return newfd;  /* that's it */
+}
+
+static PRInt32 PR_CALLBACK Ipv6ToIpv4SocketAcceptRead(PRFileDesc *sd,
+			PRFileDesc **nd, PRNetAddr **ipv6_raddr, void *buf, PRInt32 amount,
+							PRIntervalTime timeout)
+{
+    PRInt32 nbytes;
+    PRStatus rv;
+	PRNetAddr tmp_ipv4addr;
+    PRFileDesc *newstack;
+
+    PR_ASSERT(sd != NULL);
+    PR_ASSERT(sd->lower != NULL);
+
+    newstack = PR_NEW(PRFileDesc);
+    if (NULL == newstack)
+    {
+        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+        return -1;
+    }
+    *newstack = *sd;  /* make a copy of the accepting layer */
+
+    nbytes = sd->lower->methods->acceptread(
+        sd->lower, nd, ipv6_raddr, buf, amount, timeout);
+    if (-1 == nbytes)
+    {
+        PR_DELETE(newstack);
+        return nbytes;
+    }
+	tmp_ipv4addr = **ipv6_raddr;	/* copy */
+	_PR_ConvertToIpv6NetAddr(&tmp_ipv4addr, *ipv6_raddr);
+
+    /* this PR_PushIOLayer call cannot fail */
+    rv = PR_PushIOLayer(*nd, PR_TOP_IO_LAYER, newstack);
+    PR_ASSERT(PR_SUCCESS == rv);
+    return nbytes;
+}
+
+static PRStatus PR_CALLBACK Ipv6ToIpv4SocketGetName(PRFileDesc *fd,
+										PRNetAddr *ipv6addr)
+{
+	PRStatus result;
+	PRNetAddr tmp_ipv4addr;
+
+	result = (fd->lower->methods->getsockname)(fd->lower, &tmp_ipv4addr);
+	if (PR_SUCCESS == result) {
+		_PR_ConvertToIpv6NetAddr(&tmp_ipv4addr, ipv6addr);
+		PR_ASSERT(IsValidNetAddr(ipv6addr) == PR_TRUE);
+	}
+	return result;
+}
+
+static PRStatus PR_CALLBACK Ipv6ToIpv4SocketGetPeerName(PRFileDesc *fd,
+										PRNetAddr *ipv6addr)
+{
+	PRStatus result;
+	PRNetAddr tmp_ipv4addr;
+
+	result = (fd->lower->methods->getpeername)(fd->lower, &tmp_ipv4addr);
+	if (PR_SUCCESS == result) {
+		_PR_ConvertToIpv6NetAddr(&tmp_ipv4addr, ipv6addr);
+		PR_ASSERT(IsValidNetAddr(ipv6addr) == PR_TRUE);
+	}
+	return result;
+}
+
+static PRInt32 PR_CALLBACK Ipv6ToIpv4SocketRecvFrom(PRFileDesc *fd, void *buf,
+			PRInt32 amount, PRIntn flags, PRNetAddr *ipv6addr,
+				PRIntervalTime timeout)
+{
+	PRNetAddr tmp_ipv4addr;
+	PRInt32 result;
+
+    result = (fd->lower->methods->recvfrom)(
+        fd->lower, buf, amount, flags, &tmp_ipv4addr, timeout);
+	if (-1 != result) {
+		_PR_ConvertToIpv6NetAddr(&tmp_ipv4addr, ipv6addr);
+		PR_ASSERT(IsValidNetAddr(ipv6addr) == PR_TRUE);
+	}
+	return result;
+}
+
+#if defined(_PR_INET6_PROBE)
+static PRBool ipv6_is_present;
+extern PRBool _pr_test_ipv6_socket(void);
+
+#if !defined(_PR_INET6) && defined(_PR_HAVE_GETIPNODEBYNAME)
+extern PRStatus _pr_find_getipnodebyname(void);
+#endif
+
+#if !defined(_PR_INET6) && defined(_PR_HAVE_GETADDRINFO)
+extern PRStatus _pr_find_getaddrinfo(void);
+#endif
+
+static PRBool
+_pr_probe_ipv6_presence(void)
+{
+#if !defined(_PR_INET6) && defined(_PR_HAVE_GETIPNODEBYNAME)
+    if (_pr_find_getipnodebyname() != PR_SUCCESS)
+        return PR_FALSE;
+#endif
+
+#if !defined(_PR_INET6) && defined(_PR_HAVE_GETADDRINFO)
+    if (_pr_find_getaddrinfo() != PR_SUCCESS)
+        return PR_FALSE;
+#endif
+
+    return _pr_test_ipv6_socket();
+}
+#endif  /* _PR_INET6_PROBE */
+
+static PRCallOnceType _pr_init_ipv6_once;
+
+static PRStatus PR_CALLBACK _pr_init_ipv6(void)
+{
+    const PRIOMethods *stubMethods;
+
+#if defined(_PR_INET6_PROBE)
+    ipv6_is_present = _pr_probe_ipv6_presence();
+    if (ipv6_is_present)
+        return PR_SUCCESS;
+#endif
+
+    _pr_ipv6_to_ipv4_id = PR_GetUniqueIdentity("Ipv6_to_Ipv4 layer");
+    PR_ASSERT(PR_INVALID_IO_LAYER != _pr_ipv6_to_ipv4_id);
+
+	stubMethods = PR_GetDefaultIOMethods();
+
+	ipv6_to_v4_tcpMethods = *stubMethods;  /* first get the entire batch */
+	/* then override the ones we care about */
+	ipv6_to_v4_tcpMethods.connect = Ipv6ToIpv4SocketConnect;
+	ipv6_to_v4_tcpMethods.bind = Ipv6ToIpv4SocketBind;
+	ipv6_to_v4_tcpMethods.accept = Ipv6ToIpv4SocketAccept;
+	ipv6_to_v4_tcpMethods.acceptread = Ipv6ToIpv4SocketAcceptRead;
+	ipv6_to_v4_tcpMethods.getsockname = Ipv6ToIpv4SocketGetName;
+	ipv6_to_v4_tcpMethods.getpeername = Ipv6ToIpv4SocketGetPeerName;
+/*
+	ipv6_to_v4_tcpMethods.getsocketoption = Ipv6ToIpv4GetSocketOption;
+	ipv6_to_v4_tcpMethods.setsocketoption = Ipv6ToIpv4SetSocketOption;
+*/
+	ipv6_to_v4_udpMethods = *stubMethods;  /* first get the entire batch */
+	/* then override the ones we care about */
+	ipv6_to_v4_udpMethods.connect = Ipv6ToIpv4SocketConnect;
+	ipv6_to_v4_udpMethods.bind = Ipv6ToIpv4SocketBind;
+	ipv6_to_v4_udpMethods.sendto = Ipv6ToIpv4SocketSendTo;
+	ipv6_to_v4_udpMethods.recvfrom = Ipv6ToIpv4SocketRecvFrom;
+	ipv6_to_v4_udpMethods.getsockname = Ipv6ToIpv4SocketGetName;
+	ipv6_to_v4_udpMethods.getpeername = Ipv6ToIpv4SocketGetPeerName;
+/*
+	ipv6_to_v4_udpMethods.getsocketoption = Ipv6ToIpv4GetSocketOption;
+	ipv6_to_v4_udpMethods.setsocketoption = Ipv6ToIpv4SetSocketOption;
+*/
+	return PR_SUCCESS;
+}
+
+#if defined(_PR_INET6_PROBE)
+PRBool _pr_ipv6_is_present(void)
+{
+    if (PR_CallOnce(&_pr_init_ipv6_once, _pr_init_ipv6) != PR_SUCCESS)
+        return PR_FALSE;
+    return ipv6_is_present;
+}
+#endif
+
+PR_IMPLEMENT(PRStatus) _pr_push_ipv6toipv4_layer(PRFileDesc *fd)
+{
+	PRFileDesc *ipv6_fd = NULL;
+
+	if (PR_CallOnce(&_pr_init_ipv6_once, _pr_init_ipv6) != PR_SUCCESS)
+		return PR_FAILURE;
+
+	/*
+	 * For platforms with no support for IPv6 
+	 * create layered socket for IPv4-mapped IPv6 addresses
+	 */
+	if (fd->methods->file_type == PR_DESC_SOCKET_TCP)
+		ipv6_fd = PR_CreateIOLayerStub(_pr_ipv6_to_ipv4_id,
+									&ipv6_to_v4_tcpMethods);
+	else
+		ipv6_fd = PR_CreateIOLayerStub(_pr_ipv6_to_ipv4_id,
+									&ipv6_to_v4_udpMethods);
+	if (NULL == ipv6_fd) {
+		goto errorExit;
+	} 
+	ipv6_fd->secret = NULL;
+
+	if (PR_PushIOLayer(fd, PR_TOP_IO_LAYER, ipv6_fd) == PR_FAILURE) {
+		goto errorExit;
+	}
+
+	return PR_SUCCESS;
+errorExit:
+
+	if (ipv6_fd)
+		ipv6_fd->dtor(ipv6_fd);
+	return PR_FAILURE;
+}
+
+#endif /* !defined(_PR_INET6) || defined(_PR_INET6_PROBE) */
diff --git a/pr/src/io/prlayer.c b/pr/src/io/prlayer.c
new file mode 100644
index 0000000..cadb7ca
--- /dev/null
+++ b/pr/src/io/prlayer.c
@@ -0,0 +1,757 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** File:        prlayer.c
+** Description: Routines for handling pushable protocol modules on sockets.
+*/
+
+#include "primpl.h"
+#include "prerror.h"
+#include "prmem.h"
+#include "prlock.h"
+#include "prlog.h"
+#include "prio.h"
+
+#include <string.h> /* for memset() */
+static PRStatus _PR_DestroyIOLayer(PRFileDesc *stack);
+
+void PR_CALLBACK pl_FDDestructor(PRFileDesc *fd)
+{
+    PR_ASSERT(fd != NULL);
+    if (NULL != fd->lower) fd->lower->higher = fd->higher;
+    if (NULL != fd->higher) fd->higher->lower = fd->lower;
+    PR_DELETE(fd);
+}
+
+/*
+** Default methods that just call down to the next fd.
+*/
+static PRStatus PR_CALLBACK pl_TopClose (PRFileDesc *fd)
+{
+    PRFileDesc *top, *lower;
+	PRStatus rv;
+
+    PR_ASSERT(fd != NULL);
+    PR_ASSERT(fd->lower != NULL);
+    PR_ASSERT(fd->secret == NULL);
+    PR_ASSERT(fd->methods->file_type == PR_DESC_LAYERED);
+
+	if (PR_IO_LAYER_HEAD == fd->identity) {
+		/*
+		 * new style stack; close all the layers, before deleting the
+		 * stack head
+		 */
+		rv = fd->lower->methods->close(fd->lower);
+		_PR_DestroyIOLayer(fd);
+		return rv;
+	} else if ((fd->higher) && (PR_IO_LAYER_HEAD == fd->higher->identity)) {
+		/*
+		 * lower layers of new style stack
+		 */
+		lower = fd->lower;
+		/*
+		 * pop and cleanup current layer
+		 */
+    	top = PR_PopIOLayer(fd->higher, PR_TOP_IO_LAYER);
+		top->dtor(top);
+		/*
+		 * then call lower layer
+		 */
+		return (lower->methods->close(lower));
+	} else {
+		/* old style stack */
+    	top = PR_PopIOLayer(fd, PR_TOP_IO_LAYER);
+		top->dtor(top);
+		return (fd->methods->close)(fd);
+	}
+}
+
+static PRInt32 PR_CALLBACK pl_DefRead (PRFileDesc *fd, void *buf, PRInt32 amount)
+{
+    PR_ASSERT(fd != NULL);
+    PR_ASSERT(fd->lower != NULL);
+
+    return (fd->lower->methods->read)(fd->lower, buf, amount);
+}
+
+static PRInt32 PR_CALLBACK pl_DefWrite (
+    PRFileDesc *fd, const void *buf, PRInt32 amount)
+{
+    PR_ASSERT(fd != NULL);
+    PR_ASSERT(fd->lower != NULL);
+
+    return (fd->lower->methods->write)(fd->lower, buf, amount);
+}
+
+static PRInt32 PR_CALLBACK pl_DefAvailable (PRFileDesc *fd)
+{
+    PR_ASSERT(fd != NULL);
+    PR_ASSERT(fd->lower != NULL);
+
+    return (fd->lower->methods->available)(fd->lower);
+}
+
+static PRInt64 PR_CALLBACK pl_DefAvailable64 (PRFileDesc *fd)
+{
+    PR_ASSERT(fd != NULL);
+    PR_ASSERT(fd->lower != NULL);
+
+    return (fd->lower->methods->available64)(fd->lower);
+}
+
+static PRStatus PR_CALLBACK pl_DefFsync (PRFileDesc *fd)
+{
+    PR_ASSERT(fd != NULL);
+    PR_ASSERT(fd->lower != NULL);
+
+    return (fd->lower->methods->fsync)(fd->lower);
+}
+
+static PRInt32 PR_CALLBACK pl_DefSeek (
+    PRFileDesc *fd, PRInt32 offset, PRSeekWhence how)
+{
+    PR_ASSERT(fd != NULL);
+    PR_ASSERT(fd->lower != NULL);
+
+    return (fd->lower->methods->seek)(fd->lower, offset, how);
+}
+
+static PRInt64 PR_CALLBACK pl_DefSeek64 (
+    PRFileDesc *fd, PRInt64 offset, PRSeekWhence how)
+{
+    PR_ASSERT(fd != NULL);
+    PR_ASSERT(fd->lower != NULL);
+
+    return (fd->lower->methods->seek64)(fd->lower, offset, how);
+}
+
+static PRStatus PR_CALLBACK pl_DefFileInfo (PRFileDesc *fd, PRFileInfo *info)
+{
+    PR_ASSERT(fd != NULL);
+    PR_ASSERT(fd->lower != NULL);
+
+    return (fd->lower->methods->fileInfo)(fd->lower, info);
+}
+
+static PRStatus PR_CALLBACK pl_DefFileInfo64 (PRFileDesc *fd, PRFileInfo64 *info)
+{
+    PR_ASSERT(fd != NULL);
+    PR_ASSERT(fd->lower != NULL);
+
+    return (fd->lower->methods->fileInfo64)(fd->lower, info);
+}
+
+static PRInt32 PR_CALLBACK pl_DefWritev (PRFileDesc *fd, const PRIOVec *iov,
+    PRInt32 size, PRIntervalTime timeout)
+{
+    PR_ASSERT(fd != NULL);
+    PR_ASSERT(fd->lower != NULL);
+
+    return (fd->lower->methods->writev)(fd->lower, iov, size, timeout);
+}
+
+static PRStatus PR_CALLBACK pl_DefConnect (
+    PRFileDesc *fd, const PRNetAddr *addr, PRIntervalTime timeout)
+{
+    PR_ASSERT(fd != NULL);
+    PR_ASSERT(fd->lower != NULL);
+
+    return (fd->lower->methods->connect)(fd->lower, addr, timeout);
+}
+
+static PRStatus PR_CALLBACK pl_DefConnectcontinue (
+    PRFileDesc *fd, PRInt16 out_flags)
+{
+    PR_ASSERT(fd != NULL);
+    PR_ASSERT(fd->lower != NULL);
+
+    return (fd->lower->methods->connectcontinue)(fd->lower, out_flags);
+}
+
+static PRFileDesc* PR_CALLBACK pl_TopAccept (
+    PRFileDesc *fd, PRNetAddr *addr, PRIntervalTime timeout)
+{
+    PRStatus rv;
+    PRFileDesc *newfd, *layer = fd;
+    PRFileDesc *newstack;
+	PRBool newstyle_stack = PR_FALSE;
+
+    PR_ASSERT(fd != NULL);
+    PR_ASSERT(fd->lower != NULL);
+
+	/* test for new style stack */
+	while (NULL != layer->higher)
+		layer = layer->higher;
+	newstyle_stack = (PR_IO_LAYER_HEAD == layer->identity) ? PR_TRUE : PR_FALSE;
+    newstack = PR_NEW(PRFileDesc);
+    if (NULL == newstack)
+    {
+        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+        return NULL;
+    }
+    *newstack = *fd;  /* make a copy of the accepting layer */
+
+    newfd = (fd->lower->methods->accept)(fd->lower, addr, timeout);
+    if (NULL == newfd)
+    {
+        PR_DELETE(newstack);
+        return NULL;
+    }
+
+    if (newstyle_stack) {
+		newstack->lower = newfd;
+		newfd->higher = newstack;
+		return newstack;
+	} else {
+		/* this PR_PushIOLayer call cannot fail */
+		rv = PR_PushIOLayer(newfd, PR_TOP_IO_LAYER, newstack);
+		PR_ASSERT(PR_SUCCESS == rv);
+    	return newfd;  /* that's it */
+	}
+}
+
+static PRStatus PR_CALLBACK pl_DefBind (PRFileDesc *fd, const PRNetAddr *addr)
+{
+    PR_ASSERT(fd != NULL);
+    PR_ASSERT(fd->lower != NULL);
+
+    return (fd->lower->methods->bind)(fd->lower, addr);
+}
+
+static PRStatus PR_CALLBACK pl_DefListen (PRFileDesc *fd, PRIntn backlog)
+{
+    PR_ASSERT(fd != NULL);
+    PR_ASSERT(fd->lower != NULL);
+
+    return (fd->lower->methods->listen)(fd->lower, backlog);
+}
+
+static PRStatus PR_CALLBACK pl_DefShutdown (PRFileDesc *fd, PRIntn how)
+{
+    PR_ASSERT(fd != NULL);
+    PR_ASSERT(fd->lower != NULL);
+
+    return (fd->lower->methods->shutdown)(fd->lower, how);
+}
+
+static PRInt32 PR_CALLBACK pl_DefRecv (
+    PRFileDesc *fd, void *buf, PRInt32 amount,
+    PRIntn flags, PRIntervalTime timeout)
+{
+    PR_ASSERT(fd != NULL);
+    PR_ASSERT(fd->lower != NULL);
+
+    return (fd->lower->methods->recv)(
+        fd->lower, buf, amount, flags, timeout);
+}
+
+static PRInt32 PR_CALLBACK pl_DefSend (
+    PRFileDesc *fd, const void *buf,
+    PRInt32 amount, PRIntn flags, PRIntervalTime timeout)
+{
+    PR_ASSERT(fd != NULL);
+    PR_ASSERT(fd->lower != NULL);
+
+    return (fd->lower->methods->send)(fd->lower, buf, amount, flags, timeout);
+}
+
+static PRInt32 PR_CALLBACK pl_DefRecvfrom (
+    PRFileDesc *fd, void *buf, PRInt32 amount,
+    PRIntn flags, PRNetAddr *addr, PRIntervalTime timeout)
+{
+    PR_ASSERT(fd != NULL);
+    PR_ASSERT(fd->lower != NULL);
+
+    return (fd->lower->methods->recvfrom)(
+        fd->lower, buf, amount, flags, addr, timeout);
+}
+
+static PRInt32 PR_CALLBACK pl_DefSendto (
+    PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
+    const PRNetAddr *addr, PRIntervalTime timeout)
+{
+    PR_ASSERT(fd != NULL);
+    PR_ASSERT(fd->lower != NULL);
+
+    return (fd->lower->methods->sendto)(
+        fd->lower, buf, amount, flags, addr, timeout);
+}
+
+static PRInt16 PR_CALLBACK pl_DefPoll (
+    PRFileDesc *fd, PRInt16 in_flags, PRInt16 *out_flags)
+{
+    PR_ASSERT(fd != NULL);
+    PR_ASSERT(fd->lower != NULL);
+
+    return (fd->lower->methods->poll)(fd->lower, in_flags, out_flags);
+}
+
+static PRInt32 PR_CALLBACK pl_DefAcceptread (
+    PRFileDesc *sd, PRFileDesc **nd, PRNetAddr **raddr, void *buf,
+    PRInt32 amount, PRIntervalTime t)
+{
+    PRInt32 nbytes;
+    PRStatus rv;
+    PRFileDesc *newstack;
+    PRFileDesc *layer = sd;
+	PRBool newstyle_stack = PR_FALSE;
+
+    PR_ASSERT(sd != NULL);
+    PR_ASSERT(sd->lower != NULL);
+
+	/* test for new style stack */
+	while (NULL != layer->higher)
+		layer = layer->higher;
+	newstyle_stack = (PR_IO_LAYER_HEAD == layer->identity) ? PR_TRUE : PR_FALSE;
+    newstack = PR_NEW(PRFileDesc);
+    if (NULL == newstack)
+    {
+        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+        return -1;
+    }
+    *newstack = *sd;  /* make a copy of the accepting layer */
+
+    nbytes = sd->lower->methods->acceptread(
+        sd->lower, nd, raddr, buf, amount, t);
+    if (-1 == nbytes)
+    {
+        PR_DELETE(newstack);
+        return nbytes;
+    }
+    if (newstyle_stack) {
+		newstack->lower = *nd;
+		(*nd)->higher = newstack;
+		*nd = newstack;
+		return nbytes;
+	} else {
+		/* this PR_PushIOLayer call cannot fail */
+		rv = PR_PushIOLayer(*nd, PR_TOP_IO_LAYER, newstack);
+		PR_ASSERT(PR_SUCCESS == rv);
+		return nbytes;
+	}
+}
+
+static PRInt32 PR_CALLBACK pl_DefTransmitfile (
+    PRFileDesc *sd, PRFileDesc *fd, const void *headers, PRInt32 hlen,
+    PRTransmitFileFlags flags, PRIntervalTime t)
+{
+    PR_ASSERT(sd != NULL);
+    PR_ASSERT(sd->lower != NULL);
+
+    return sd->lower->methods->transmitfile(
+        sd->lower, fd, headers, hlen, flags, t);
+}
+
+static PRStatus PR_CALLBACK pl_DefGetsockname (PRFileDesc *fd, PRNetAddr *addr)
+{
+    PR_ASSERT(fd != NULL);
+    PR_ASSERT(fd->lower != NULL);
+
+    return (fd->lower->methods->getsockname)(fd->lower, addr);
+}
+
+static PRStatus PR_CALLBACK pl_DefGetpeername (PRFileDesc *fd, PRNetAddr *addr)
+{
+    PR_ASSERT(fd != NULL);
+    PR_ASSERT(fd->lower != NULL);
+
+    return (fd->lower->methods->getpeername)(fd->lower, addr);
+}
+
+static PRStatus PR_CALLBACK pl_DefGetsocketoption (
+    PRFileDesc *fd, PRSocketOptionData *data)
+{
+    PR_ASSERT(fd != NULL);
+    PR_ASSERT(fd->lower != NULL);
+
+    return (fd->lower->methods->getsocketoption)(fd->lower, data);
+}
+
+static PRStatus PR_CALLBACK pl_DefSetsocketoption (
+    PRFileDesc *fd, const PRSocketOptionData *data)
+{
+    PR_ASSERT(fd != NULL);
+    PR_ASSERT(fd->lower != NULL);
+
+    return (fd->lower->methods->setsocketoption)(fd->lower, data);
+}
+
+static PRInt32 PR_CALLBACK pl_DefSendfile (
+	PRFileDesc *sd, PRSendFileData *sfd,
+	PRTransmitFileFlags flags, PRIntervalTime timeout)
+{
+    PR_ASSERT(sd != NULL);
+    PR_ASSERT(sd->lower != NULL);
+
+    return sd->lower->methods->sendfile(
+        sd->lower, sfd, flags, timeout);
+}
+
+/* Methods for the top of the stack.  Just call down to the next fd. */
+static PRIOMethods pl_methods = {
+    PR_DESC_LAYERED,
+    pl_TopClose,
+    pl_DefRead,
+    pl_DefWrite,
+    pl_DefAvailable,
+    pl_DefAvailable64,
+    pl_DefFsync,
+    pl_DefSeek,
+    pl_DefSeek64,
+    pl_DefFileInfo,
+    pl_DefFileInfo64,
+    pl_DefWritev,
+    pl_DefConnect,
+    pl_TopAccept,
+    pl_DefBind,
+    pl_DefListen,
+    pl_DefShutdown,
+    pl_DefRecv,
+    pl_DefSend,
+    pl_DefRecvfrom,
+    pl_DefSendto,
+    pl_DefPoll,
+    pl_DefAcceptread,
+    pl_DefTransmitfile,
+    pl_DefGetsockname,
+    pl_DefGetpeername,
+    (PRReservedFN)_PR_InvalidInt,
+    (PRReservedFN)_PR_InvalidInt,
+    pl_DefGetsocketoption,
+    pl_DefSetsocketoption,
+    pl_DefSendfile,
+    pl_DefConnectcontinue,
+    (PRReservedFN)_PR_InvalidInt,
+    (PRReservedFN)_PR_InvalidInt,
+    (PRReservedFN)_PR_InvalidInt,
+    (PRReservedFN)_PR_InvalidInt
+};
+
+PR_IMPLEMENT(const PRIOMethods*) PR_GetDefaultIOMethods(void)
+{
+    return &pl_methods;
+}  /* PR_GetDefaultIOMethods */
+
+PR_IMPLEMENT(PRFileDesc*) PR_CreateIOLayerStub(
+    PRDescIdentity ident, const PRIOMethods *methods)
+{
+    PRFileDesc *fd = NULL;
+    PR_ASSERT((PR_NSPR_IO_LAYER != ident) && (PR_TOP_IO_LAYER != ident));
+    if ((PR_NSPR_IO_LAYER == ident) || (PR_TOP_IO_LAYER == ident))
+        PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+    else
+    {
+        fd = PR_NEWZAP(PRFileDesc);
+        if (NULL == fd)
+            PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+        else
+        {
+            fd->methods = methods;
+            fd->dtor = pl_FDDestructor;
+            fd->identity = ident;
+        }
+    }
+    return fd;
+}  /* PR_CreateIOLayerStub */
+
+/*
+ * PR_CreateIOLayer
+ *		Create a new style stack, where the stack top is a dummy header.
+ *		Unlike the old style stacks, the contents of the stack head
+ *		are not modified when a layer is pushed onto or popped from a new
+ *		style stack.
+ */
+
+PR_IMPLEMENT(PRFileDesc*) PR_CreateIOLayer(PRFileDesc *top)
+{
+    PRFileDesc *fd = NULL;
+
+	fd = PR_NEWZAP(PRFileDesc);
+	if (NULL == fd)
+		PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+	else
+	{
+		fd->methods = &pl_methods;
+		fd->dtor = pl_FDDestructor;
+		fd->identity = PR_IO_LAYER_HEAD;
+		fd->higher = NULL;
+		fd->lower = top;
+		top->higher = fd;
+		top->lower = NULL;
+	}
+    return fd;
+}  /* PR_CreateIOLayer */
+
+/*
+ * _PR_DestroyIOLayer
+ *		Delete the stack head of a new style stack.
+ */
+
+static PRStatus _PR_DestroyIOLayer(PRFileDesc *stack)
+{
+    if (NULL == stack)
+        return PR_FAILURE;
+    else {
+        PR_DELETE(stack);
+    	return PR_SUCCESS;
+    }
+}  /* _PR_DestroyIOLayer */
+
+PR_IMPLEMENT(PRStatus) PR_PushIOLayer(
+    PRFileDesc *stack, PRDescIdentity id, PRFileDesc *fd)
+{
+    PRFileDesc *insert = PR_GetIdentitiesLayer(stack, id);
+
+    PR_ASSERT(fd != NULL);
+    PR_ASSERT(stack != NULL);
+    PR_ASSERT(insert != NULL);
+    PR_ASSERT(PR_IO_LAYER_HEAD != id);
+    if ((NULL == stack) || (NULL == fd) || (NULL == insert))
+    {
+        PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+        return PR_FAILURE;
+    }
+
+    if (stack == insert)
+    {
+		/* going on top of the stack */
+		/* old-style stack */	
+		PRFileDesc copy = *stack;
+		*stack = *fd;
+		*fd = copy;
+		fd->higher = stack;
+		if (fd->lower)
+		{
+			PR_ASSERT(fd->lower->higher == stack);
+			fd->lower->higher = fd;
+		}
+		stack->lower = fd;
+		stack->higher = NULL;
+	} else {
+        /*
+		 * going somewhere in the middle of the stack for both old and new
+		 * style stacks, or going on top of stack for new style stack
+		 */
+        fd->lower = insert;
+        fd->higher = insert->higher;
+
+        insert->higher->lower = fd;
+        insert->higher = fd;
+    }
+
+    return PR_SUCCESS;
+}
+
+PR_IMPLEMENT(PRFileDesc*) PR_PopIOLayer(PRFileDesc *stack, PRDescIdentity id)
+{
+    PRFileDesc *extract = PR_GetIdentitiesLayer(stack, id);
+
+    PR_ASSERT(0 != id);
+    PR_ASSERT(NULL != stack);
+    PR_ASSERT(NULL != extract);
+    if ((NULL == stack) || (0 == id) || (NULL == extract))
+    {
+        PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+        return NULL;
+    }
+
+    if (extract == stack) {
+        /* popping top layer of the stack */
+		/* old style stack */
+        PRFileDesc copy = *stack;
+        extract = stack->lower;
+        *stack = *extract;
+        *extract = copy;
+        stack->higher = NULL;
+        if (stack->lower) {
+            PR_ASSERT(stack->lower->higher == extract);
+            stack->lower->higher = stack;
+        }
+	} else if ((PR_IO_LAYER_HEAD == stack->identity) &&
+					(extract == stack->lower) && (extract->lower == NULL)) {
+			/*
+			 * new style stack
+			 * popping the only layer in the stack; delete the stack too
+			 */
+			stack->lower = NULL;
+			_PR_DestroyIOLayer(stack);
+	} else {
+		/* for both kinds of stacks */
+        extract->lower->higher = extract->higher;
+        extract->higher->lower = extract->lower;
+    }
+    extract->higher = extract->lower = NULL;
+    return extract;
+}  /* PR_PopIOLayer */
+
+#define ID_CACHE_INCREMENT 16
+typedef struct _PRIdentity_cache
+{
+    PRLock *ml;
+    char **name;
+    PRIntn length;
+    PRDescIdentity ident;
+} _PRIdentity_cache;
+
+static _PRIdentity_cache identity_cache;
+
+PR_IMPLEMENT(PRDescIdentity) PR_GetUniqueIdentity(const char *layer_name)
+{
+    PRDescIdentity identity, length;
+    char **names = NULL, *name = NULL, **old = NULL;
+
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+
+    PR_ASSERT((PRDescIdentity)0x7fff > identity_cache.ident);
+
+    if (NULL != layer_name)
+    {
+        name = (char*)PR_Malloc(strlen(layer_name) + 1);
+        if (NULL == name)
+        {
+            PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+            return PR_INVALID_IO_LAYER;
+        }
+        strcpy(name, layer_name);
+    }
+
+    /* this initial code runs unsafe */
+retry:
+    PR_ASSERT(NULL == names);
+    /*
+     * In the initial round, both identity_cache.ident and
+     * identity_cache.length are 0, so (identity_cache.ident + 1) is greater
+     * than length.  In later rounds, identity_cache.ident is always less
+     * than length, so (identity_cache.ident + 1) can be equal to but cannot
+     * be greater than length.
+     */
+    length = identity_cache.length;
+    if ((identity_cache.ident + 1) >= length)
+    {
+        length += ID_CACHE_INCREMENT;
+        names = (char**)PR_CALLOC(length * sizeof(char*));
+        if (NULL == names)
+        {
+            if (NULL != name) PR_DELETE(name);
+            PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+            return PR_INVALID_IO_LAYER;
+        }
+    }
+
+    /* now we get serious about thread safety */
+    PR_Lock(identity_cache.ml);
+    PR_ASSERT(identity_cache.length == 0 ||
+              identity_cache.ident < identity_cache.length);
+    identity = identity_cache.ident + 1;
+    if (identity >= identity_cache.length)  /* there's no room */
+    {
+        /* we have to do something - hopefully it's already done */
+        if ((NULL != names) && (identity < length))
+        {
+            /* what we did is still okay */
+            memcpy(
+                names, identity_cache.name,
+                identity_cache.length * sizeof(char*));
+            old = identity_cache.name;
+            identity_cache.name = names;
+            identity_cache.length = length;
+            names = NULL;
+        }
+        else
+        {
+            PR_Unlock(identity_cache.ml);
+            if (NULL != names) PR_DELETE(names);
+            goto retry;
+        }
+    }
+    if (NULL != name) /* there's a name to be stored */
+    {
+        identity_cache.name[identity] = name;
+    }
+    identity_cache.ident = identity;
+    PR_ASSERT(identity_cache.ident < identity_cache.length);
+    PR_Unlock(identity_cache.ml);
+
+    if (NULL != old) PR_DELETE(old);
+    if (NULL != names) PR_DELETE(names);
+
+    return identity;
+}  /* PR_GetUniqueIdentity */
+
+PR_IMPLEMENT(const char*) PR_GetNameForIdentity(PRDescIdentity ident)
+{
+    const char *rv = NULL;
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+
+    if ((PR_TOP_IO_LAYER != ident) && (ident >= 0)) {
+      PR_Lock(identity_cache.ml);
+      PR_ASSERT(ident <= identity_cache.ident);
+      rv = (ident > identity_cache.ident) ? NULL : identity_cache.name[ident];
+      PR_Unlock(identity_cache.ml);
+    }
+
+    return rv;
+}  /* PR_GetNameForIdentity */
+
+PR_IMPLEMENT(PRDescIdentity) PR_GetLayersIdentity(PRFileDesc* fd)
+{
+    PR_ASSERT(NULL != fd);
+    if (PR_IO_LAYER_HEAD == fd->identity) {
+    	PR_ASSERT(NULL != fd->lower);
+    	return fd->lower->identity;
+	} else
+    	return fd->identity;
+}  /* PR_GetLayersIdentity */
+
+PR_IMPLEMENT(PRFileDesc*) PR_GetIdentitiesLayer(PRFileDesc* fd, PRDescIdentity id)
+{
+    PRFileDesc *layer = fd;
+
+    if (PR_TOP_IO_LAYER == id) {
+    	if (PR_IO_LAYER_HEAD == fd->identity)
+			return fd->lower;
+		else 
+			return fd;
+	}
+
+    for (layer = fd; layer != NULL; layer = layer->lower)
+    {
+        if (id == layer->identity) return layer;
+    }
+    for (layer = fd; layer != NULL; layer = layer->higher)
+    {
+        if (id == layer->identity) return layer;
+    }
+    return NULL;
+}  /* PR_GetIdentitiesLayer */
+
+void _PR_InitLayerCache(void)
+{
+    memset(&identity_cache, 0, sizeof(identity_cache));
+    identity_cache.ml = PR_NewLock();
+    PR_ASSERT(NULL != identity_cache.ml);
+}  /* _PR_InitLayerCache */
+
+void _PR_CleanupLayerCache(void)
+{
+    if (identity_cache.ml)
+    {
+        PR_DestroyLock(identity_cache.ml);
+        identity_cache.ml = NULL;
+    }
+
+    if (identity_cache.name)
+    {
+        PRDescIdentity ident;
+
+        for (ident = 0; ident <= identity_cache.ident; ident++)
+            PR_DELETE(identity_cache.name[ident]);
+
+        PR_DELETE(identity_cache.name);
+    }
+}  /* _PR_CleanupLayerCache */
+
+/* prlayer.c */
diff --git a/pr/src/io/prlog.c b/pr/src/io/prlog.c
new file mode 100644
index 0000000..6098460
--- /dev/null
+++ b/pr/src/io/prlog.c
@@ -0,0 +1,554 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "primpl.h"
+#include "prenv.h"
+#include "prprf.h"
+#include <string.h>
+#ifdef ANDROID
+#include <android/log.h>
+#endif
+
+/*
+ * Lock used to lock the log.
+ *
+ * We can't define _PR_LOCK_LOG simply as PR_Lock because PR_Lock may
+ * contain assertions.  We have to avoid assertions in _PR_LOCK_LOG
+ * because PR_ASSERT calls PR_LogPrint, which in turn calls _PR_LOCK_LOG.
+ * This can lead to infinite recursion.
+ */
+static PRLock *_pr_logLock;
+#if defined(_PR_PTHREADS) || defined(_PR_BTHREADS)
+#define _PR_LOCK_LOG() PR_Lock(_pr_logLock);
+#define _PR_UNLOCK_LOG() PR_Unlock(_pr_logLock);
+#elif defined(_PR_GLOBAL_THREADS_ONLY)
+#define _PR_LOCK_LOG() { _PR_LOCK_LOCK(_pr_logLock)
+#define _PR_UNLOCK_LOG() _PR_LOCK_UNLOCK(_pr_logLock); }
+#else
+
+#define _PR_LOCK_LOG() \
+{ \
+    PRIntn _is; \
+    PRThread *_me = _PR_MD_CURRENT_THREAD(); \
+    if (!_PR_IS_NATIVE_THREAD(_me)) \
+        _PR_INTSOFF(_is); \
+    _PR_LOCK_LOCK(_pr_logLock)
+
+#define _PR_UNLOCK_LOG() \
+    _PR_LOCK_UNLOCK(_pr_logLock); \
+    PR_ASSERT(_me == _PR_MD_CURRENT_THREAD()); \
+    if (!_PR_IS_NATIVE_THREAD(_me)) \
+        _PR_INTSON(_is); \
+}
+
+#endif
+
+#if defined(XP_PC)
+#define strcasecmp stricmp
+#endif
+
+/*
+ * On NT, we can't define _PUT_LOG as PR_Write or _PR_MD_WRITE,
+ * because every asynchronous file io operation leads to a fiber context
+ * switch.  So we define _PUT_LOG as fputs (from stdio.h).  A side
+ * benefit is that fputs handles the LF->CRLF translation.  This
+ * code can also be used on other platforms with file stream io.
+ */
+#if defined(WIN32) || defined(XP_OS2)
+#define _PR_USE_STDIO_FOR_LOGGING
+#endif
+
+/*
+** Coerce Win32 log output to use OutputDebugString() when
+** NSPR_LOG_FILE is set to "WinDebug".
+*/
+#if defined(XP_PC)
+#define WIN32_DEBUG_FILE (FILE*)-2
+#endif
+
+#ifdef WINCE
+static void OutputDebugStringA(const char* msg) {
+    int len = MultiByteToWideChar(CP_ACP, 0, msg, -1, 0, 0);
+    WCHAR *wMsg = (WCHAR *)PR_Malloc(len * sizeof(WCHAR));
+    MultiByteToWideChar(CP_ACP, 0, msg, -1, wMsg, len);
+    OutputDebugStringW(wMsg);
+    PR_Free(wMsg);
+}
+#endif
+
+/* Macros used to reduce #ifdef pollution */
+
+#if defined(_PR_USE_STDIO_FOR_LOGGING) && defined(XP_PC)
+#define _PUT_LOG(fd, buf, nb) \
+    PR_BEGIN_MACRO \
+    if (logFile == WIN32_DEBUG_FILE) { \
+        char savebyte = buf[nb]; \
+        buf[nb] = '\0'; \
+        OutputDebugStringA(buf); \
+        buf[nb] = savebyte; \
+    } else { \
+        fwrite(buf, 1, nb, fd); \
+        fflush(fd); \
+    } \
+    PR_END_MACRO
+#elif defined(_PR_USE_STDIO_FOR_LOGGING)
+#define _PUT_LOG(fd, buf, nb) {fwrite(buf, 1, nb, fd); fflush(fd);}
+#elif defined(ANDROID)
+#define _PUT_LOG(fd, buf, nb)                                \
+    PR_BEGIN_MACRO                                           \
+    if (fd == _pr_stderr) {                                  \
+        char savebyte = buf[nb];                             \
+        buf[nb] = '\0';                                      \
+        __android_log_write(ANDROID_LOG_INFO, "PRLog", buf); \
+        buf[nb] = savebyte;                                  \
+    } else {                                                 \
+        PR_Write(fd, buf, nb);                               \
+    }                                                        \
+    PR_END_MACRO
+#elif defined(_PR_PTHREADS)
+#define _PUT_LOG(fd, buf, nb) PR_Write(fd, buf, nb)
+#else
+#define _PUT_LOG(fd, buf, nb) _PR_MD_WRITE(fd, buf, nb)
+#endif
+
+/************************************************************************/
+
+static PRLogModuleInfo *logModules;
+
+static char *logBuf = NULL;
+static char *logp;
+static char *logEndp;
+#ifdef _PR_USE_STDIO_FOR_LOGGING
+static FILE *logFile = NULL;
+#else
+static PRFileDesc *logFile = 0;
+#endif
+static PRBool outputTimeStamp = PR_FALSE;
+static PRBool appendToLog = PR_FALSE;
+
+#define LINE_BUF_SIZE           512
+#define DEFAULT_BUF_SIZE        16384
+
+#ifdef _PR_NEED_STRCASECMP
+
+/*
+ * strcasecmp is defined in /usr/ucblib/libucb.a on some platforms
+ * such as NCR and Unixware.  Linking with both libc and libucb
+ * may cause some problem, so I just provide our own implementation
+ * of strcasecmp here.
+ */
+
+static const unsigned char uc[] =
+{
+    '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
+    '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
+    '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
+    '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
+    ' ',    '!',    '"',    '#',    '$',    '%',    '&',    '\'',
+    '(',    ')',    '*',    '+',    ',',    '-',    '.',    '/',
+    '0',    '1',    '2',    '3',    '4',    '5',    '6',    '7',
+    '8',    '9',    ':',    ';',    '<',    '=',    '>',    '?',
+    '@',    'A',    'B',    'C',    'D',    'E',    'F',    'G',
+    'H',    'I',    'J',    'K',    'L',    'M',    'N',    'O',
+    'P',    'Q',    'R',    'S',    'T',    'U',    'V',    'W',
+    'X',    'Y',    'Z',    '[',    '\\',   ']',    '^',    '_',
+    '`',    'A',    'B',    'C',    'D',    'E',    'F',    'G',
+    'H',    'I',    'J',    'K',    'L',    'M',    'N',    'O',
+    'P',    'Q',    'R',    'S',    'T',    'U',    'V',    'W',
+    'X',    'Y',    'Z',    '{',    '|',    '}',    '~',    '\177'
+};
+
+PRIntn strcasecmp(const char *a, const char *b)
+{
+    const unsigned char *ua = (const unsigned char *)a;
+    const unsigned char *ub = (const unsigned char *)b;
+
+    if( ((const char *)0 == a) || (const char *)0 == b ) 
+        return (PRIntn)(a-b);
+
+    while( (uc[*ua] == uc[*ub]) && ('\0' != *a) )
+    {
+        a++;
+        ua++;
+        ub++;
+    }
+
+    return (PRIntn)(uc[*ua] - uc[*ub]);
+}
+
+#endif /* _PR_NEED_STRCASECMP */
+
+void _PR_InitLog(void)
+{
+    char *ev;
+
+    _pr_logLock = PR_NewLock();
+
+    ev = PR_GetEnv("NSPR_LOG_MODULES");
+    if (ev && ev[0]) {
+        char module[64];  /* Security-Critical: If you change this
+                           * size, you must also change the sscanf
+                           * format string to be size-1.
+                           */
+        PRBool isSync = PR_FALSE;
+        PRIntn evlen = strlen(ev), pos = 0;
+        PRInt32 bufSize = DEFAULT_BUF_SIZE;
+        while (pos < evlen) {
+            PRIntn level = 1, count = 0, delta = 0;
+            count = sscanf(&ev[pos], "%63[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-]%n:%d%n",
+                           module, &delta, &level, &delta);
+            pos += delta;
+            if (count == 0) break;
+
+            /*
+            ** If count == 2, then we got module and level. If count
+            ** == 1, then level defaults to 1 (module enabled).
+            */
+            if (strcasecmp(module, "sync") == 0) {
+                isSync = PR_TRUE;
+            } else if (strcasecmp(module, "bufsize") == 0) {
+                if (level >= LINE_BUF_SIZE) {
+                    bufSize = level;
+                }
+            } else if (strcasecmp(module, "timestamp") == 0) {
+                outputTimeStamp = PR_TRUE;
+            } else if (strcasecmp(module, "append") == 0) {
+                appendToLog = PR_TRUE;
+            } else {
+                PRLogModuleInfo *lm = logModules;
+                PRBool skip_modcheck =
+                    (0 == strcasecmp (module, "all")) ? PR_TRUE : PR_FALSE;
+
+                while (lm != NULL) {
+                    if (skip_modcheck) lm -> level = (PRLogModuleLevel)level;
+                    else if (strcasecmp(module, lm->name) == 0) {
+                        lm->level = (PRLogModuleLevel)level;
+                        break;
+                    }
+                    lm = lm->next;
+                }
+            }
+            /*found:*/
+            count = sscanf(&ev[pos], " , %n", &delta);
+            pos += delta;
+            if (count == EOF) break;
+        }
+        PR_SetLogBuffering(isSync ? 0 : bufSize);
+
+        ev = PR_GetEnvSecure("NSPR_LOG_FILE");
+        if (ev && ev[0]) {
+            if (!PR_SetLogFile(ev)) {
+#ifdef XP_PC
+                char* str = PR_smprintf("Unable to create nspr log file '%s'\n", ev);
+                if (str) {
+                    OutputDebugStringA(str);
+                    PR_smprintf_free(str);
+                }
+#else
+                fprintf(stderr, "Unable to create nspr log file '%s'\n", ev);
+#endif
+            }
+        } else {
+#ifdef _PR_USE_STDIO_FOR_LOGGING
+            logFile = stderr;
+#else
+            logFile = _pr_stderr;
+#endif
+        }
+    }
+}
+
+void _PR_LogCleanup(void)
+{
+    PRLogModuleInfo *lm = logModules;
+
+    PR_LogFlush();
+
+#ifdef _PR_USE_STDIO_FOR_LOGGING
+    if (logFile
+        && logFile != stdout
+        && logFile != stderr
+#ifdef XP_PC
+        && logFile != WIN32_DEBUG_FILE
+#endif
+        ) {
+        fclose(logFile);
+    }
+#else
+    if (logFile && logFile != _pr_stdout && logFile != _pr_stderr) {
+        PR_Close(logFile);
+    }
+#endif
+    logFile = NULL;
+
+    if (logBuf)
+        PR_DELETE(logBuf);
+
+    while (lm != NULL) {
+        PRLogModuleInfo *next = lm->next;
+        free((/*const*/ char *)lm->name);
+        PR_Free(lm);
+        lm = next;
+    }
+    logModules = NULL;
+
+    if (_pr_logLock) {
+        PR_DestroyLock(_pr_logLock);
+        _pr_logLock = NULL;
+    }
+}
+
+static void _PR_SetLogModuleLevel( PRLogModuleInfo *lm )
+{
+    char *ev;
+
+    ev = PR_GetEnv("NSPR_LOG_MODULES");
+    if (ev && ev[0]) {
+        char module[64];  /* Security-Critical: If you change this
+                           * size, you must also change the sscanf
+                           * format string to be size-1.
+                           */
+        PRIntn evlen = strlen(ev), pos = 0;
+        while (pos < evlen) {
+            PRIntn level = 1, count = 0, delta = 0;
+
+            count = sscanf(&ev[pos], "%63[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-]%n:%d%n",
+                           module, &delta, &level, &delta);
+            pos += delta;
+            if (count == 0) break;
+
+            /*
+            ** If count == 2, then we got module and level. If count
+            ** == 1, then level defaults to 1 (module enabled).
+            */
+            if (lm != NULL)
+            {
+                if ((strcasecmp(module, "all") == 0)
+                    || (strcasecmp(module, lm->name) == 0))
+                {
+                    lm->level = (PRLogModuleLevel)level;
+                }
+            }
+            count = sscanf(&ev[pos], " , %n", &delta);
+            pos += delta;
+            if (count == EOF) break;
+        }
+    }
+} /* end _PR_SetLogModuleLevel() */
+
+PR_IMPLEMENT(PRLogModuleInfo*) PR_NewLogModule(const char *name)
+{
+    PRLogModuleInfo *lm;
+
+        if (!_pr_initialized) _PR_ImplicitInitialization();
+
+    lm = PR_NEWZAP(PRLogModuleInfo);
+    if (lm) {
+        lm->name = strdup(name);
+        lm->level = PR_LOG_NONE;
+        lm->next = logModules;
+        logModules = lm;
+        _PR_SetLogModuleLevel(lm);
+    }
+    return lm;
+}
+
+PR_IMPLEMENT(PRBool) PR_SetLogFile(const char *file)
+{
+#ifdef _PR_USE_STDIO_FOR_LOGGING
+    FILE *newLogFile;
+
+#ifdef XP_PC
+    if ( strcmp( file, "WinDebug") == 0)
+    {
+        newLogFile = WIN32_DEBUG_FILE;
+    }
+    else
+#endif
+    {
+        const char *mode = appendToLog ? "a" : "w";
+        newLogFile = fopen(file, mode);
+        if (!newLogFile)
+            return PR_FALSE;
+
+#ifndef WINCE  /* _IONBF does not exist in the Windows Mobile 6 SDK. */
+        /* We do buffering ourselves. */
+        setvbuf(newLogFile, NULL, _IONBF, 0);
+#endif
+    }
+    if (logFile
+        && logFile != stdout
+        && logFile != stderr
+#ifdef XP_PC
+        && logFile != WIN32_DEBUG_FILE
+#endif
+        ) {
+        fclose(logFile);
+    }
+    logFile = newLogFile;
+    return PR_TRUE;
+#else
+    PRFileDesc *newLogFile;
+    PRIntn flags = PR_WRONLY|PR_CREATE_FILE;
+    if (appendToLog) {
+        flags |= PR_APPEND;
+    } else {
+        flags |= PR_TRUNCATE;
+    }
+
+    newLogFile = PR_Open(file, flags, 0666);
+    if (newLogFile) {
+        if (logFile && logFile != _pr_stdout && logFile != _pr_stderr) {
+            PR_Close(logFile);
+        }
+        logFile = newLogFile;
+    }
+    return (PRBool) (newLogFile != 0);
+#endif /* _PR_USE_STDIO_FOR_LOGGING */
+}
+
+PR_IMPLEMENT(void) PR_SetLogBuffering(PRIntn buffer_size)
+{
+    PR_LogFlush();
+
+    if (logBuf)
+        PR_DELETE(logBuf);
+
+    if (buffer_size >= LINE_BUF_SIZE) {
+        logp = logBuf = (char*) PR_MALLOC(buffer_size);
+        logEndp = logp + buffer_size;
+    }
+}
+
+PR_IMPLEMENT(void) PR_LogPrint(const char *fmt, ...)
+{
+    va_list ap;
+    char line[LINE_BUF_SIZE];
+    char *line_long = NULL;
+    PRUint32 nb_tid = 0, nb;
+    PRThread *me;
+    PRExplodedTime now;
+
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+
+    if (!logFile) {
+        return;
+    }
+
+    if (outputTimeStamp) {
+        PR_ExplodeTime(PR_Now(), PR_GMTParameters, &now);
+        nb_tid = PR_snprintf(line, sizeof(line)-1,
+                             "%04d-%02d-%02d %02d:%02d:%02d.%06d UTC - ",
+                             now.tm_year, now.tm_month + 1, now.tm_mday,
+                             now.tm_hour, now.tm_min, now.tm_sec,
+                             now.tm_usec);
+    }
+
+    me = PR_GetCurrentThread();
+    nb_tid += PR_snprintf(line+nb_tid, sizeof(line)-nb_tid-1, "%ld[%p]: ",
+#if defined(_PR_BTHREADS)
+                          me, me);
+#else
+                          me ? me->id : 0L, me);
+#endif
+
+    va_start(ap, fmt);
+    nb = nb_tid + PR_vsnprintf(line+nb_tid, sizeof(line)-nb_tid-1, fmt, ap);
+    va_end(ap);
+
+    /*
+     * Check if we might have run out of buffer space (in case we have a
+     * long line), and malloc a buffer just this once.
+     */
+    if (nb == sizeof(line)-2) {
+        va_start(ap, fmt);
+        line_long = PR_vsmprintf(fmt, ap);
+        va_end(ap);
+        /* If this failed, we'll fall back to writing the truncated line. */
+    }
+
+    if (line_long) {
+        nb = strlen(line_long);
+        _PR_LOCK_LOG();
+        if (logBuf != 0) {
+            _PUT_LOG(logFile, logBuf, logp - logBuf);
+            logp = logBuf;
+        }
+        /*
+         * Write out the thread id (with an optional timestamp) and the
+         * malloc'ed buffer.
+         */
+        _PUT_LOG(logFile, line, nb_tid);
+        _PUT_LOG(logFile, line_long, nb);
+        /* Ensure there is a trailing newline. */
+        if (!nb || (line_long[nb-1] != '\n')) {
+            char eol[2];
+            eol[0] = '\n';
+            eol[1] = '\0';
+            _PUT_LOG(logFile, eol, 1);
+        }
+        _PR_UNLOCK_LOG();
+        PR_smprintf_free(line_long);
+    } else {
+        /* Ensure there is a trailing newline. */
+        if (nb && (line[nb-1] != '\n')) {
+            line[nb++] = '\n';
+            line[nb] = '\0';
+        }
+        _PR_LOCK_LOG();
+        if (logBuf == 0) {
+            _PUT_LOG(logFile, line, nb);
+        } else {
+            /* If nb can't fit into logBuf, write out logBuf first. */
+            if (logp + nb > logEndp) {
+                _PUT_LOG(logFile, logBuf, logp - logBuf);
+                logp = logBuf;
+            }
+            /* nb is guaranteed to fit into logBuf. */
+            memcpy(logp, line, nb);
+            logp += nb;
+        }
+        _PR_UNLOCK_LOG();
+    }
+    PR_LogFlush();
+}
+
+PR_IMPLEMENT(void) PR_LogFlush(void)
+{
+    if (logBuf && logFile) {
+        _PR_LOCK_LOG();
+            if (logp > logBuf) {
+                _PUT_LOG(logFile, logBuf, logp - logBuf);
+                logp = logBuf;
+            }
+        _PR_UNLOCK_LOG();
+    }
+}
+
+PR_IMPLEMENT(void) PR_Abort(void)
+{
+    PR_LogPrint("Aborting");
+#ifdef ANDROID
+    __android_log_write(ANDROID_LOG_ERROR, "PRLog", "Aborting");
+#endif
+    abort();
+}
+
+PR_IMPLEMENT(void) PR_Assert(const char *s, const char *file, PRIntn ln)
+{
+    PR_LogPrint("Assertion failure: %s, at %s:%d\n", s, file, ln);
+    fprintf(stderr, "Assertion failure: %s, at %s:%d\n", s, file, ln);
+    fflush(stderr);
+#ifdef WIN32
+    DebugBreak();
+#elif defined(XP_OS2)
+    asm("int $3");
+#elif defined(ANDROID)
+    __android_log_assert(NULL, "PRLog", "Assertion failure: %s, at %s:%d\n",
+                         s, file, ln);
+#endif
+    abort();
+}
diff --git a/pr/src/io/prmapopt.c b/pr/src/io/prmapopt.c
new file mode 100644
index 0000000..f92a76b
--- /dev/null
+++ b/pr/src/io/prmapopt.c
@@ -0,0 +1,458 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+ * This file defines _PR_MapOptionName().  The purpose of putting
+ * _PR_MapOptionName() in a separate file is to work around a Winsock
+ * header file problem on Windows NT.
+ *
+ * On Windows NT, if we define _WIN32_WINNT to be 0x0400 (in order
+ * to use Service Pack 3 extensions), windows.h includes winsock2.h
+ * (instead of winsock.h), which doesn't define many socket options
+ * defined in winsock.h.
+ *
+ * We need the socket options defined in winsock.h.  So this file
+ * includes winsock.h, with _WIN32_WINNT undefined.
+ */
+
+#if defined(WINNT) || defined(__MINGW32__)
+#include <winsock.h>
+#endif
+
+/* MinGW doesn't define these in its winsock.h. */
+#ifdef __MINGW32__
+#ifndef IP_TTL
+#define IP_TTL 7
+#endif
+#ifndef IP_TOS
+#define IP_TOS 8
+#endif
+#endif
+
+#include "primpl.h"
+
+#ifdef HAVE_NETINET_TCP_H
+#include <netinet/tcp.h>  /* TCP_NODELAY, TCP_MAXSEG */
+#endif
+
+#ifndef _PR_PTHREADS
+
+PRStatus PR_CALLBACK _PR_SocketGetSocketOption(PRFileDesc *fd, PRSocketOptionData *data)
+{
+    PRStatus rv;
+    PRInt32 length;
+    PRInt32 level, name;
+
+    /*
+     * PR_SockOpt_Nonblocking is a special case that does not
+     * translate to a getsockopt() call
+     */
+    if (PR_SockOpt_Nonblocking == data->option)
+    {
+        data->value.non_blocking = fd->secret->nonblocking;
+        return PR_SUCCESS;
+    }
+
+    rv = _PR_MapOptionName(data->option, &level, &name);
+    if (PR_SUCCESS == rv)
+    {
+        switch (data->option)
+        {
+            case PR_SockOpt_Linger:
+            {
+#if !defined(XP_BEOS) || defined(BONE_VERSION)
+                struct linger linger;
+                length = sizeof(linger);
+                rv = _PR_MD_GETSOCKOPT(
+                    fd, level, name, (char *) &linger, &length);
+                if (PR_SUCCESS == rv)
+                {
+                    PR_ASSERT(sizeof(linger) == length);
+                    data->value.linger.polarity =
+                        (linger.l_onoff) ? PR_TRUE : PR_FALSE;
+                    data->value.linger.linger =
+                        PR_SecondsToInterval(linger.l_linger);
+                }
+                break;
+#else
+                PR_SetError( PR_NOT_IMPLEMENTED_ERROR, 0 );
+                return PR_FAILURE;
+#endif
+            }
+            case PR_SockOpt_Reuseaddr:
+            case PR_SockOpt_Keepalive:
+            case PR_SockOpt_NoDelay:
+            case PR_SockOpt_Broadcast:
+            case PR_SockOpt_Reuseport:
+            {
+#ifdef WIN32 /* Winsock */
+                BOOL value;
+#else
+                PRIntn value;
+#endif
+                length = sizeof(value);
+                rv = _PR_MD_GETSOCKOPT(
+                    fd, level, name, (char*)&value, &length);
+                if (PR_SUCCESS == rv)
+                    data->value.reuse_addr = (0 == value) ? PR_FALSE : PR_TRUE;
+                break;
+            }
+            case PR_SockOpt_McastLoopback:
+            {
+#ifdef WIN32 /* Winsock */
+                BOOL bool;
+#else
+                PRUint8 bool;
+#endif
+                length = sizeof(bool);
+                rv = _PR_MD_GETSOCKOPT(
+                    fd, level, name, (char*)&bool, &length);
+                if (PR_SUCCESS == rv)
+                    data->value.mcast_loopback = (0 == bool) ? PR_FALSE : PR_TRUE;
+                break;
+            }
+            case PR_SockOpt_RecvBufferSize:
+            case PR_SockOpt_SendBufferSize:
+            case PR_SockOpt_MaxSegment:
+            {
+                PRIntn value;
+                length = sizeof(value);
+                rv = _PR_MD_GETSOCKOPT(
+                    fd, level, name, (char*)&value, &length);
+                if (PR_SUCCESS == rv)
+                    data->value.recv_buffer_size = value;
+                break;
+            }
+            case PR_SockOpt_IpTimeToLive:
+            case PR_SockOpt_IpTypeOfService:
+            {
+                /* These options should really be an int (or PRIntn). */
+                length = sizeof(PRUintn);
+                rv = _PR_MD_GETSOCKOPT(
+                    fd, level, name, (char*)&data->value.ip_ttl, &length);
+                break;
+            }
+            case PR_SockOpt_McastTimeToLive:
+            {
+#ifdef WIN32 /* Winsock */
+                int ttl;
+#else
+                PRUint8 ttl;
+#endif
+                length = sizeof(ttl);
+                rv = _PR_MD_GETSOCKOPT(
+                    fd, level, name, (char*)&ttl, &length);
+                if (PR_SUCCESS == rv)
+                    data->value.mcast_ttl = ttl;
+                break;
+            }
+#ifdef IP_ADD_MEMBERSHIP
+            case PR_SockOpt_AddMember:
+            case PR_SockOpt_DropMember:
+            {
+                struct ip_mreq mreq;
+                length = sizeof(mreq);
+                rv = _PR_MD_GETSOCKOPT(
+                    fd, level, name, (char*)&mreq, &length);
+                if (PR_SUCCESS == rv)
+                {
+                    data->value.add_member.mcaddr.inet.ip =
+                        mreq.imr_multiaddr.s_addr;
+                    data->value.add_member.ifaddr.inet.ip =
+                        mreq.imr_interface.s_addr;
+                }
+                break;
+            }
+#endif /* IP_ADD_MEMBERSHIP */
+            case PR_SockOpt_McastInterface:
+            {
+                /* This option is a struct in_addr. */
+                length = sizeof(data->value.mcast_if.inet.ip);
+                rv = _PR_MD_GETSOCKOPT(
+                    fd, level, name,
+                    (char*)&data->value.mcast_if.inet.ip, &length);
+                break;
+            }
+            default:
+                PR_NOT_REACHED("Unknown socket option");
+                break;
+        }  
+    }
+    return rv;
+}  /* _PR_SocketGetSocketOption */
+
+PRStatus PR_CALLBACK _PR_SocketSetSocketOption(PRFileDesc *fd, const PRSocketOptionData *data)
+{
+    PRStatus rv;
+    PRInt32 level, name;
+
+    /*
+     * PR_SockOpt_Nonblocking is a special case that does not
+     * translate to a setsockopt call.
+     */
+    if (PR_SockOpt_Nonblocking == data->option)
+    {
+#ifdef WINNT
+        PR_ASSERT((fd->secret->md.io_model_committed == PR_FALSE)
+            || (fd->secret->nonblocking == data->value.non_blocking));
+        if (fd->secret->md.io_model_committed
+            && (fd->secret->nonblocking != data->value.non_blocking))
+        {
+            /*
+             * On NT, once we have associated a socket with the io
+             * completion port, we can't disassociate it.  So we
+             * can't change the nonblocking option of the socket
+             * afterwards.
+             */
+            PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+            return PR_FAILURE;
+        }
+#endif
+        fd->secret->nonblocking = data->value.non_blocking;
+        return PR_SUCCESS;
+    }
+
+    rv = _PR_MapOptionName(data->option, &level, &name);
+    if (PR_SUCCESS == rv)
+    {
+        switch (data->option)
+        {
+            case PR_SockOpt_Linger:
+            {
+#if !defined(XP_BEOS) || defined(BONE_VERSION)
+                struct linger linger;
+                linger.l_onoff = data->value.linger.polarity;
+                linger.l_linger = PR_IntervalToSeconds(data->value.linger.linger);
+                rv = _PR_MD_SETSOCKOPT(
+                    fd, level, name, (char*)&linger, sizeof(linger));
+                break;
+#else
+                PR_SetError( PR_NOT_IMPLEMENTED_ERROR, 0 );
+                return PR_FAILURE;
+#endif
+            }
+            case PR_SockOpt_Reuseaddr:
+            case PR_SockOpt_Keepalive:
+            case PR_SockOpt_NoDelay:
+            case PR_SockOpt_Broadcast:
+            case PR_SockOpt_Reuseport:
+            {
+#ifdef WIN32 /* Winsock */
+                BOOL value;
+#else
+                PRIntn value;
+#endif
+                value = (data->value.reuse_addr) ? 1 : 0;
+                rv = _PR_MD_SETSOCKOPT(
+                    fd, level, name, (char*)&value, sizeof(value));
+                break;
+            }
+            case PR_SockOpt_McastLoopback:
+            {
+#ifdef WIN32 /* Winsock */
+                BOOL bool;
+#else
+                PRUint8 bool;
+#endif
+                bool = data->value.mcast_loopback ? 1 : 0;
+                rv = _PR_MD_SETSOCKOPT(
+                    fd, level, name, (char*)&bool, sizeof(bool));
+                break;
+            }
+            case PR_SockOpt_RecvBufferSize:
+            case PR_SockOpt_SendBufferSize:
+            case PR_SockOpt_MaxSegment:
+            {
+                PRIntn value = data->value.recv_buffer_size;
+                rv = _PR_MD_SETSOCKOPT(
+                    fd, level, name, (char*)&value, sizeof(value));
+                break;
+            }
+            case PR_SockOpt_IpTimeToLive:
+            case PR_SockOpt_IpTypeOfService:
+            {
+                /* These options should really be an int (or PRIntn). */
+                rv = _PR_MD_SETSOCKOPT(
+                    fd, level, name, (char*)&data->value.ip_ttl, sizeof(PRUintn));
+                break;
+            }
+            case PR_SockOpt_McastTimeToLive:
+            {
+#ifdef WIN32 /* Winsock */
+                int ttl;
+#else
+                PRUint8 ttl;
+#endif
+                ttl = data->value.mcast_ttl;
+                rv = _PR_MD_SETSOCKOPT(
+                    fd, level, name, (char*)&ttl, sizeof(ttl));
+                break;
+            }
+#ifdef IP_ADD_MEMBERSHIP
+            case PR_SockOpt_AddMember:
+            case PR_SockOpt_DropMember:
+            {
+                struct ip_mreq mreq;
+                mreq.imr_multiaddr.s_addr =
+                    data->value.add_member.mcaddr.inet.ip;
+                mreq.imr_interface.s_addr =
+                    data->value.add_member.ifaddr.inet.ip;
+                rv = _PR_MD_SETSOCKOPT(
+                    fd, level, name, (char*)&mreq, sizeof(mreq));
+                break;
+            }
+#endif /* IP_ADD_MEMBERSHIP */
+            case PR_SockOpt_McastInterface:
+            {
+                /* This option is a struct in_addr. */
+                rv = _PR_MD_SETSOCKOPT(
+                    fd, level, name, (char*)&data->value.mcast_if.inet.ip,
+                    sizeof(data->value.mcast_if.inet.ip));
+                break;
+            }
+            default:
+                PR_NOT_REACHED("Unknown socket option");
+                break;
+        }  
+    }
+    return rv;
+}  /* _PR_SocketSetSocketOption */
+
+#endif /* ! _PR_PTHREADS */
+
+/*
+ *********************************************************************
+ *********************************************************************
+ **
+ ** Make sure that the following is at the end of this file,
+ ** because we will be playing with macro redefines.
+ **
+ *********************************************************************
+ *********************************************************************
+ */
+
+/*
+ * Not every platform has all the socket options we want to
+ * support.  Some older operating systems such as SunOS 4.1.3
+ * don't have the IP multicast socket options.  Win32 doesn't
+ * have TCP_MAXSEG.
+ *
+ * To deal with this problem, we define the missing socket
+ * options as _PR_NO_SUCH_SOCKOPT.  _PR_MapOptionName() fails with
+ * PR_OPERATION_NOT_SUPPORTED_ERROR if a socket option not
+ * available on the platform is requested.
+ */
+
+/*
+ * Sanity check.  SO_LINGER and TCP_NODELAY should be available
+ * on all platforms.  Just to make sure we have included the
+ * appropriate header files.  Then any undefined socket options
+ * are really missing.
+ */
+
+#if !defined(SO_LINGER)
+#error "SO_LINGER is not defined"
+#endif
+
+#if !defined(TCP_NODELAY)
+#error "TCP_NODELAY is not defined"
+#endif
+
+/*
+ * Make sure the value of _PR_NO_SUCH_SOCKOPT is not
+ * a valid socket option.
+ */
+#define _PR_NO_SUCH_SOCKOPT -1
+
+#ifndef SO_KEEPALIVE
+#define SO_KEEPALIVE        _PR_NO_SUCH_SOCKOPT
+#endif
+
+#ifndef SO_SNDBUF
+#define SO_SNDBUF           _PR_NO_SUCH_SOCKOPT
+#endif
+
+#ifndef SO_RCVBUF
+#define SO_RCVBUF           _PR_NO_SUCH_SOCKOPT
+#endif
+
+#ifndef IP_MULTICAST_IF                 /* set/get IP multicast interface   */
+#define IP_MULTICAST_IF     _PR_NO_SUCH_SOCKOPT
+#endif
+
+#ifndef IP_MULTICAST_TTL                /* set/get IP multicast timetolive  */
+#define IP_MULTICAST_TTL    _PR_NO_SUCH_SOCKOPT
+#endif
+
+#ifndef IP_MULTICAST_LOOP               /* set/get IP multicast loopback    */
+#define IP_MULTICAST_LOOP   _PR_NO_SUCH_SOCKOPT
+#endif
+
+#ifndef IP_ADD_MEMBERSHIP               /* add  an IP group membership      */
+#define IP_ADD_MEMBERSHIP   _PR_NO_SUCH_SOCKOPT
+#endif
+
+#ifndef IP_DROP_MEMBERSHIP              /* drop an IP group membership      */
+#define IP_DROP_MEMBERSHIP  _PR_NO_SUCH_SOCKOPT
+#endif
+
+#ifndef IP_TTL                          /* set/get IP Time To Live          */
+#define IP_TTL              _PR_NO_SUCH_SOCKOPT
+#endif
+
+#ifndef IP_TOS                          /* set/get IP Type Of Service       */
+#define IP_TOS              _PR_NO_SUCH_SOCKOPT
+#endif
+
+#ifndef TCP_NODELAY                     /* don't delay to coalesce data     */
+#define TCP_NODELAY         _PR_NO_SUCH_SOCKOPT
+#endif
+
+#ifndef TCP_MAXSEG                      /* maxumum segment size for tcp     */
+#define TCP_MAXSEG          _PR_NO_SUCH_SOCKOPT
+#endif
+
+#ifndef SO_BROADCAST                    /* enable broadcast on UDP sockets  */
+#define SO_BROADCAST        _PR_NO_SUCH_SOCKOPT
+#endif
+
+#ifndef SO_REUSEPORT                    /* allow local address & port reuse */
+#define SO_REUSEPORT        _PR_NO_SUCH_SOCKOPT
+#endif
+
+PRStatus _PR_MapOptionName(
+    PRSockOption optname, PRInt32 *level, PRInt32 *name)
+{
+    static PRInt32 socketOptions[PR_SockOpt_Last] =
+    {
+        0, SO_LINGER, SO_REUSEADDR, SO_KEEPALIVE, SO_RCVBUF, SO_SNDBUF,
+        IP_TTL, IP_TOS, IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP,
+        IP_MULTICAST_IF, IP_MULTICAST_TTL, IP_MULTICAST_LOOP,
+        TCP_NODELAY, TCP_MAXSEG, SO_BROADCAST, SO_REUSEPORT
+    };
+    static PRInt32 socketLevels[PR_SockOpt_Last] =
+    {
+        0, SOL_SOCKET, SOL_SOCKET, SOL_SOCKET, SOL_SOCKET, SOL_SOCKET,
+        IPPROTO_IP, IPPROTO_IP, IPPROTO_IP, IPPROTO_IP,
+        IPPROTO_IP, IPPROTO_IP, IPPROTO_IP,
+        IPPROTO_TCP, IPPROTO_TCP, SOL_SOCKET, SOL_SOCKET
+    };
+
+    if ((optname < PR_SockOpt_Linger)
+    || (optname >= PR_SockOpt_Last))
+    {
+        PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+        return PR_FAILURE;
+    }
+
+    if (socketOptions[optname] == _PR_NO_SUCH_SOCKOPT)
+    {
+        PR_SetError(PR_OPERATION_NOT_SUPPORTED_ERROR, 0);
+        return PR_FAILURE;
+    }
+    *name = socketOptions[optname];
+    *level = socketLevels[optname];
+    return PR_SUCCESS;
+}  /* _PR_MapOptionName */
diff --git a/pr/src/io/prmmap.c b/pr/src/io/prmmap.c
new file mode 100644
index 0000000..6ffc133
--- /dev/null
+++ b/pr/src/io/prmmap.c
@@ -0,0 +1,69 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+ *********************************************************************
+ *
+ * Memory-mapped files
+ *
+ *********************************************************************
+ */
+
+#include "primpl.h"
+
+PR_IMPLEMENT(PRFileMap *) PR_CreateFileMap(
+    PRFileDesc *fd,
+    PRInt64 size,
+    PRFileMapProtect prot)
+{
+    PRFileMap *fmap;
+
+    PR_ASSERT(prot == PR_PROT_READONLY || prot == PR_PROT_READWRITE
+            || prot == PR_PROT_WRITECOPY);
+    fmap = PR_NEWZAP(PRFileMap);
+    if (NULL == fmap) {
+	PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+	return NULL;
+    }
+    fmap->fd = fd;
+    fmap->prot = prot;
+    if (_PR_MD_CREATE_FILE_MAP(fmap, size) == PR_SUCCESS) {
+	return fmap;
+    } else {
+	PR_DELETE(fmap);
+	return NULL;
+    }
+}
+
+PR_IMPLEMENT(PRInt32) PR_GetMemMapAlignment(void)
+{
+    return _PR_MD_GET_MEM_MAP_ALIGNMENT();
+}
+
+PR_IMPLEMENT(void *) PR_MemMap(
+    PRFileMap *fmap,
+    PROffset64 offset,
+    PRUint32 len)
+{
+    return _PR_MD_MEM_MAP(fmap, offset, len);
+}
+
+PR_IMPLEMENT(PRStatus) PR_MemUnmap(void *addr, PRUint32 len)
+{
+    return _PR_MD_MEM_UNMAP(addr, len);
+}
+
+PR_IMPLEMENT(PRStatus) PR_CloseFileMap(PRFileMap *fmap)
+{
+    return _PR_MD_CLOSE_FILE_MAP(fmap);
+}
+
+PR_IMPLEMENT(PRStatus) PR_SyncMemMap(
+    PRFileDesc *fd,
+    void *addr,
+    PRUint32 len)
+{
+  return _PR_MD_SYNC_MEM_MAP(fd, addr, len);
+}
diff --git a/pr/src/io/prmwait.c b/pr/src/io/prmwait.c
new file mode 100644
index 0000000..ab32fb5
--- /dev/null
+++ b/pr/src/io/prmwait.c
@@ -0,0 +1,1457 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "primpl.h"
+#include "pprmwait.h"
+
+#define _MW_REHASH_MAX 11
+
+static PRLock *mw_lock = NULL;
+static _PRGlobalState *mw_state = NULL;
+
+static PRIntervalTime max_polling_interval;
+
+#ifdef WINNT
+
+typedef struct TimerEvent {
+    PRIntervalTime absolute;
+    void (*func)(void *);
+    void *arg;
+    LONG ref_count;
+    PRCList links;
+} TimerEvent;
+
+#define TIMER_EVENT_PTR(_qp) \
+    ((TimerEvent *) ((char *) (_qp) - offsetof(TimerEvent, links)))
+
+struct {
+    PRLock *ml;
+    PRCondVar *new_timer;
+    PRCondVar *cancel_timer;
+    PRThread *manager_thread;
+    PRCList timer_queue;
+} tm_vars;
+
+static PRStatus TimerInit(void);
+static void TimerManager(void *arg);
+static TimerEvent *CreateTimer(PRIntervalTime timeout,
+    void (*func)(void *), void *arg);
+static PRBool CancelTimer(TimerEvent *timer);
+
+static void TimerManager(void *arg)
+{
+    PRIntervalTime now;
+    PRIntervalTime timeout;
+    PRCList *head;
+    TimerEvent *timer;
+
+    PR_Lock(tm_vars.ml);
+    while (1)
+    {
+        if (PR_CLIST_IS_EMPTY(&tm_vars.timer_queue))
+        {
+            PR_WaitCondVar(tm_vars.new_timer, PR_INTERVAL_NO_TIMEOUT);
+        }
+        else
+        {
+            now = PR_IntervalNow();
+            head = PR_LIST_HEAD(&tm_vars.timer_queue);
+            timer = TIMER_EVENT_PTR(head);
+            if ((PRInt32) (now - timer->absolute) >= 0)
+            {
+                PR_REMOVE_LINK(head);
+                /*
+                 * make its prev and next point to itself so that
+                 * it's obvious that it's not on the timer_queue.
+                 */
+                PR_INIT_CLIST(head);
+                PR_ASSERT(2 == timer->ref_count);
+                PR_Unlock(tm_vars.ml);
+                timer->func(timer->arg);
+                PR_Lock(tm_vars.ml);
+                timer->ref_count -= 1;
+                if (0 == timer->ref_count)
+                {
+                    PR_NotifyAllCondVar(tm_vars.cancel_timer);
+                }
+            }
+            else
+            {
+                timeout = (PRIntervalTime)(timer->absolute - now);
+                PR_WaitCondVar(tm_vars.new_timer, timeout);
+            } 
+        }
+    }
+    PR_Unlock(tm_vars.ml);
+}
+
+static TimerEvent *CreateTimer(
+    PRIntervalTime timeout,
+    void (*func)(void *),
+    void *arg)
+{
+    TimerEvent *timer;
+    PRCList *links, *tail;
+    TimerEvent *elem;
+
+    timer = PR_NEW(TimerEvent);
+    if (NULL == timer)
+    {
+        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+        return timer;
+    }
+    timer->absolute = PR_IntervalNow() + timeout;
+    timer->func = func;
+    timer->arg = arg;
+    timer->ref_count = 2;
+    PR_Lock(tm_vars.ml);
+    tail = links = PR_LIST_TAIL(&tm_vars.timer_queue);
+    while (links->prev != tail)
+    {
+        elem = TIMER_EVENT_PTR(links);
+        if ((PRInt32)(timer->absolute - elem->absolute) >= 0)
+        {
+            break;
+        }
+        links = links->prev;
+    }
+    PR_INSERT_AFTER(&timer->links, links);
+    PR_NotifyCondVar(tm_vars.new_timer);
+    PR_Unlock(tm_vars.ml);
+    return timer;
+}
+
+static PRBool CancelTimer(TimerEvent *timer)
+{
+    PRBool canceled = PR_FALSE;
+
+    PR_Lock(tm_vars.ml);
+    timer->ref_count -= 1;
+    if (timer->links.prev == &timer->links)
+    {
+        while (timer->ref_count == 1)
+        {
+            PR_WaitCondVar(tm_vars.cancel_timer, PR_INTERVAL_NO_TIMEOUT);
+        }
+    }
+    else
+    {
+        PR_REMOVE_LINK(&timer->links);
+        canceled = PR_TRUE;
+    }
+    PR_Unlock(tm_vars.ml);
+    PR_DELETE(timer);
+    return canceled; 
+}
+
+static PRStatus TimerInit(void)
+{
+    tm_vars.ml = PR_NewLock();
+    if (NULL == tm_vars.ml)
+    {
+        goto failed;
+    }
+    tm_vars.new_timer = PR_NewCondVar(tm_vars.ml);
+    if (NULL == tm_vars.new_timer)
+    {
+        goto failed;
+    }
+    tm_vars.cancel_timer = PR_NewCondVar(tm_vars.ml);
+    if (NULL == tm_vars.cancel_timer)
+    {
+        goto failed;
+    }
+    PR_INIT_CLIST(&tm_vars.timer_queue);
+    tm_vars.manager_thread = PR_CreateThread(
+        PR_SYSTEM_THREAD, TimerManager, NULL, PR_PRIORITY_NORMAL,
+        PR_LOCAL_THREAD, PR_UNJOINABLE_THREAD, 0);
+    if (NULL == tm_vars.manager_thread)
+    {
+        goto failed;
+    }
+    return PR_SUCCESS;
+
+failed:
+    if (NULL != tm_vars.cancel_timer)
+    {
+        PR_DestroyCondVar(tm_vars.cancel_timer);
+    }
+    if (NULL != tm_vars.new_timer)
+    {
+        PR_DestroyCondVar(tm_vars.new_timer);
+    }
+    if (NULL != tm_vars.ml)
+    {
+        PR_DestroyLock(tm_vars.ml);
+    }
+    return PR_FAILURE;
+}
+
+#endif /* WINNT */
+
+/******************************************************************/
+/******************************************************************/
+/************************ The private portion *********************/
+/******************************************************************/
+/******************************************************************/
+void _PR_InitMW(void)
+{
+#ifdef WINNT
+    /*
+     * We use NT 4's InterlockedCompareExchange() to operate
+     * on PRMWStatus variables.
+     */
+    PR_ASSERT(sizeof(LONG) == sizeof(PRMWStatus));
+    TimerInit();
+#endif
+    mw_lock = PR_NewLock();
+    PR_ASSERT(NULL != mw_lock);
+    mw_state = PR_NEWZAP(_PRGlobalState);
+    PR_ASSERT(NULL != mw_state);
+    PR_INIT_CLIST(&mw_state->group_list);
+    max_polling_interval = PR_MillisecondsToInterval(MAX_POLLING_INTERVAL);
+}  /* _PR_InitMW */
+
+void _PR_CleanupMW(void)
+{
+    PR_DestroyLock(mw_lock);
+    mw_lock = NULL;
+    if (mw_state->group) {
+        PR_DestroyWaitGroup(mw_state->group);
+        /* mw_state->group is set to NULL as a side effect. */
+    }
+    PR_DELETE(mw_state);
+}  /* _PR_CleanupMW */
+
+static PRWaitGroup *MW_Init2(void)
+{
+    PRWaitGroup *group = mw_state->group;  /* it's the null group */
+    if (NULL == group)  /* there is this special case */
+    {
+        group = PR_CreateWaitGroup(_PR_DEFAULT_HASH_LENGTH);
+        if (NULL == group) goto failed_alloc;
+        PR_Lock(mw_lock);
+        if (NULL == mw_state->group)
+        {
+            mw_state->group = group;
+            group = NULL;
+        }
+        PR_Unlock(mw_lock);
+        if (group != NULL) (void)PR_DestroyWaitGroup(group);
+        group = mw_state->group;  /* somebody beat us to it */
+    }
+failed_alloc:
+    return group;  /* whatever */
+}  /* MW_Init2 */
+
+static _PR_HashStory MW_AddHashInternal(PRRecvWait *desc, _PRWaiterHash *hash)
+{
+    /*
+    ** The entries are put in the table using the fd (PRFileDesc*) of
+    ** the receive descriptor as the key. This allows us to locate
+    ** the appropriate entry aqain when the poll operation finishes.
+    **
+    ** The pointer to the file descriptor object is first divided by
+    ** the natural alignment of a pointer in the belief that object
+    ** will have at least that many zeros in the low order bits.
+    ** This may not be a good assuption.
+    **
+    ** We try to put the entry in by rehashing _MW_REHASH_MAX times. After
+    ** that we declare defeat and force the table to be reconstructed.
+    ** Since some fds might be added more than once, won't that cause
+    ** collisions even in an empty table?
+    */
+    PRIntn rehash = _MW_REHASH_MAX;
+    PRRecvWait **waiter;
+    PRUintn hidx = _MW_HASH(desc->fd, hash->length);
+    PRUintn hoffset = 0;
+
+    while (rehash-- > 0)
+    {
+        waiter = &hash->recv_wait;
+        if (NULL == waiter[hidx])
+        {
+            waiter[hidx] = desc;
+            hash->count += 1;
+#if 0
+            printf("Adding 0x%x->0x%x ", desc, desc->fd);
+            printf(
+                "table[%u:%u:*%u]: 0x%x->0x%x\n",
+                hidx, hash->count, hash->length, waiter[hidx], waiter[hidx]->fd);
+#endif
+            return _prmw_success;
+        }
+        if (desc == waiter[hidx])
+        {
+            PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);  /* desc already in table */
+            return _prmw_error;
+        }
+#if 0
+        printf("Failing 0x%x->0x%x ", desc, desc->fd);
+        printf(
+            "table[*%u:%u:%u]: 0x%x->0x%x\n",
+            hidx, hash->count, hash->length, waiter[hidx], waiter[hidx]->fd);
+#endif
+        if (0 == hoffset)
+        {
+            hoffset = _MW_HASH2(desc->fd, hash->length);
+            PR_ASSERT(0 != hoffset);
+        }
+        hidx = (hidx + hoffset) % (hash->length);
+    }
+    return _prmw_rehash;    
+}  /* MW_AddHashInternal */
+
+static _PR_HashStory MW_ExpandHashInternal(PRWaitGroup *group)
+{
+    PRRecvWait **desc;
+    PRUint32 pidx, length;
+    _PRWaiterHash *newHash, *oldHash = group->waiter;
+    PRBool retry;
+    _PR_HashStory hrv;
+
+    static const PRInt32 prime_number[] = {
+        _PR_DEFAULT_HASH_LENGTH, 179, 521, 907, 1427,
+        2711, 3917, 5021, 8219, 11549, 18911, 26711, 33749, 44771};
+    PRUintn primes = (sizeof(prime_number) / sizeof(PRInt32));
+
+    /* look up the next size we'd like to use for the hash table */
+    for (pidx = 0; pidx < primes; ++pidx)
+    {
+        if (prime_number[pidx] == oldHash->length)
+        {
+            break;
+        }
+    }
+    /* table size must be one of the prime numbers */
+    PR_ASSERT(pidx < primes);
+
+    /* if pidx == primes - 1, we can't expand the table any more */
+    while (pidx < primes - 1)
+    {
+        /* next size */
+        ++pidx;
+        length = prime_number[pidx];
+
+        /* allocate the new hash table and fill it in with the old */
+        newHash = (_PRWaiterHash*)PR_CALLOC(
+            sizeof(_PRWaiterHash) + (length * sizeof(PRRecvWait*)));
+        if (NULL == newHash)
+        {
+            PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+            return _prmw_error;
+        }
+
+        newHash->length = length;
+        retry = PR_FALSE;
+        for (desc = &oldHash->recv_wait;
+            newHash->count < oldHash->count; ++desc)
+        {
+            PR_ASSERT(desc < &oldHash->recv_wait + oldHash->length);
+            if (NULL != *desc)
+            {
+                hrv = MW_AddHashInternal(*desc, newHash);
+                PR_ASSERT(_prmw_error != hrv);
+                if (_prmw_success != hrv)
+                {
+                    PR_DELETE(newHash);
+                    retry = PR_TRUE;
+                    break;
+                }
+            }
+        }
+        if (retry) continue;
+
+        PR_DELETE(group->waiter);
+        group->waiter = newHash;
+        group->p_timestamp += 1;
+        return _prmw_success;
+    }
+
+    PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+    return _prmw_error;  /* we're hosed */
+}  /* MW_ExpandHashInternal */
+
+#ifndef WINNT
+static void _MW_DoneInternal(
+    PRWaitGroup *group, PRRecvWait **waiter, PRMWStatus outcome)
+{
+    /*
+    ** Add this receive wait object to the list of finished I/O
+    ** operations for this particular group. If there are other
+    ** threads waiting on the group, notify one. If not, arrange
+    ** for this thread to return.
+    */
+
+#if 0
+    printf("Removing 0x%x->0x%x\n", *waiter, (*waiter)->fd);
+#endif
+    (*waiter)->outcome = outcome;
+    PR_APPEND_LINK(&((*waiter)->internal), &group->io_ready);
+    PR_NotifyCondVar(group->io_complete);
+    PR_ASSERT(0 != group->waiter->count);
+    group->waiter->count -= 1;
+    *waiter = NULL;
+}  /* _MW_DoneInternal */
+#endif /* WINNT */
+
+static PRRecvWait **_MW_LookupInternal(PRWaitGroup *group, PRFileDesc *fd)
+{
+    /*
+    ** Find the receive wait object corresponding to the file descriptor.
+    ** Only search the wait group specified.
+    */
+    PRRecvWait **desc;
+    PRIntn rehash = _MW_REHASH_MAX;
+    _PRWaiterHash *hash = group->waiter;
+    PRUintn hidx = _MW_HASH(fd, hash->length);
+    PRUintn hoffset = 0;
+    
+    while (rehash-- > 0)
+    {
+        desc = (&hash->recv_wait) + hidx;
+        if ((*desc != NULL) && ((*desc)->fd == fd)) return desc;
+        if (0 == hoffset)
+        {
+            hoffset = _MW_HASH2(fd, hash->length);
+            PR_ASSERT(0 != hoffset);
+        }
+        hidx = (hidx + hoffset) % (hash->length);
+    }
+    return NULL;
+}  /* _MW_LookupInternal */
+
+#ifndef WINNT
+static PRStatus _MW_PollInternal(PRWaitGroup *group)
+{
+    PRRecvWait **waiter;
+    PRStatus rv = PR_FAILURE;
+    PRInt32 count, count_ready;
+    PRIntervalTime polling_interval;
+
+    group->poller = PR_GetCurrentThread();
+
+    while (PR_TRUE)
+    {
+        PRIntervalTime now, since_last_poll;
+        PRPollDesc *poll_list;
+
+        while (0 == group->waiter->count)
+        {
+            PRStatus st;
+            st = PR_WaitCondVar(group->new_business, PR_INTERVAL_NO_TIMEOUT);
+            if (_prmw_running != group->state)
+            {
+                PR_SetError(PR_INVALID_STATE_ERROR, 0);
+                goto aborted;
+            }
+            if (_MW_ABORTED(st)) goto aborted;
+        }
+
+        /*
+        ** There's something to do. See if our existing polling list
+        ** is large enough for what we have to do?
+        */
+
+        while (group->polling_count < group->waiter->count)
+        {
+            PRUint32 old_count = group->waiter->count;
+            PRUint32 new_count = PR_ROUNDUP(old_count, _PR_POLL_COUNT_FUDGE);
+            PRSize new_size = sizeof(PRPollDesc) * new_count;
+            PRPollDesc *old_polling_list = group->polling_list;
+
+            PR_Unlock(group->ml);
+            poll_list = (PRPollDesc*)PR_CALLOC(new_size);
+            if (NULL == poll_list)
+            {
+                PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+                PR_Lock(group->ml);
+                goto failed_alloc;
+            }
+            if (NULL != old_polling_list)
+                PR_DELETE(old_polling_list);
+            PR_Lock(group->ml);
+            if (_prmw_running != group->state)
+            {
+                PR_DELETE(poll_list);
+                PR_SetError(PR_INVALID_STATE_ERROR, 0);
+                goto aborted;
+            }
+            group->polling_list = poll_list;
+            group->polling_count = new_count;
+        }
+
+        now = PR_IntervalNow();
+        polling_interval = max_polling_interval;
+        since_last_poll = now - group->last_poll;
+
+        waiter = &group->waiter->recv_wait;
+        poll_list = group->polling_list;
+        for (count = 0; count < group->waiter->count; ++waiter)
+        {
+            PR_ASSERT(waiter < &group->waiter->recv_wait
+                + group->waiter->length);
+            if (NULL != *waiter)  /* a live one! */
+            {
+                if ((PR_INTERVAL_NO_TIMEOUT != (*waiter)->timeout)
+                && (since_last_poll >= (*waiter)->timeout))
+                    _MW_DoneInternal(group, waiter, PR_MW_TIMEOUT);
+                else
+                {
+                    if (PR_INTERVAL_NO_TIMEOUT != (*waiter)->timeout)
+                    {
+                        (*waiter)->timeout -= since_last_poll;
+                        if ((*waiter)->timeout < polling_interval)
+                            polling_interval = (*waiter)->timeout;
+                    }
+                    PR_ASSERT(poll_list < group->polling_list
+                        + group->polling_count);
+                    poll_list->fd = (*waiter)->fd;
+                    poll_list->in_flags = PR_POLL_READ;
+                    poll_list->out_flags = 0;
+#if 0
+                    printf(
+                        "Polling 0x%x[%d]: [fd: 0x%x, tmo: %u]\n",
+                        poll_list, count, poll_list->fd, (*waiter)->timeout);
+#endif
+                    poll_list += 1;
+                    count += 1;
+                }
+            }
+        } 
+
+        PR_ASSERT(count == group->waiter->count);
+
+        /*
+        ** If there are no more threads waiting for completion,
+        ** we need to return.
+        */
+        if ((!PR_CLIST_IS_EMPTY(&group->io_ready))
+        && (1 == group->waiting_threads)) break;
+
+        if (0 == count) continue;  /* wait for new business */
+
+        group->last_poll = now;
+
+        PR_Unlock(group->ml);
+
+        count_ready = PR_Poll(group->polling_list, count, polling_interval);
+
+        PR_Lock(group->ml);
+
+        if (_prmw_running != group->state)
+        {
+            PR_SetError(PR_INVALID_STATE_ERROR, 0);
+            goto aborted;
+        }
+        if (-1 == count_ready)
+        {
+            goto failed_poll;  /* that's a shame */
+        }
+        else if (0 < count_ready)
+        {
+            for (poll_list = group->polling_list; count > 0;
+            poll_list++, count--)
+            {
+                PR_ASSERT(
+                    poll_list < group->polling_list + group->polling_count);
+                if (poll_list->out_flags != 0)
+                {
+                    waiter = _MW_LookupInternal(group, poll_list->fd);
+                    /*
+                    ** If 'waiter' is NULL, that means the wait receive
+                    ** descriptor has been canceled.
+                    */
+                    if (NULL != waiter)
+                        _MW_DoneInternal(group, waiter, PR_MW_SUCCESS);
+                }
+            }
+        }
+        /*
+        ** If there are no more threads waiting for completion,
+        ** we need to return.
+        ** This thread was "borrowed" to do the polling, but it really
+        ** belongs to the client.
+        */
+        if ((!PR_CLIST_IS_EMPTY(&group->io_ready))
+        && (1 == group->waiting_threads)) break;
+    }
+
+    rv = PR_SUCCESS;
+
+aborted:
+failed_poll:
+failed_alloc:
+    group->poller = NULL;  /* we were that, not we ain't */
+    if ((_prmw_running == group->state) && (group->waiting_threads > 1))
+    {
+        /* Wake up one thread to become the new poller. */
+        PR_NotifyCondVar(group->io_complete);
+    }
+    return rv;  /* we return with the lock held */
+}  /* _MW_PollInternal */
+#endif /* !WINNT */
+
+static PRMWGroupState MW_TestForShutdownInternal(PRWaitGroup *group)
+{
+    PRMWGroupState rv = group->state;
+    /*
+    ** Looking at the group's fields is safe because
+    ** once the group's state is no longer running, it
+    ** cannot revert and there is a safe check on entry
+    ** to make sure no more threads are made to wait.
+    */
+    if ((_prmw_stopping == rv)
+    && (0 == group->waiting_threads))
+    {
+        rv = group->state = _prmw_stopped;
+        PR_NotifyCondVar(group->mw_manage);
+    }
+    return rv;
+}  /* MW_TestForShutdownInternal */
+
+#ifndef WINNT
+static void _MW_InitialRecv(PRCList *io_ready)
+{
+    PRRecvWait *desc = (PRRecvWait*)io_ready;
+    if ((NULL == desc->buffer.start)
+    || (0 == desc->buffer.length))
+        desc->bytesRecv = 0;
+    else
+    {
+        desc->bytesRecv = (desc->fd->methods->recv)(
+            desc->fd, desc->buffer.start,
+            desc->buffer.length, 0, desc->timeout);
+        if (desc->bytesRecv < 0)  /* SetError should already be there */
+            desc->outcome = PR_MW_FAILURE;
+    }
+}  /* _MW_InitialRecv */
+#endif
+
+#ifdef WINNT
+static void NT_TimeProc(void *arg)
+{
+    _MDOverlapped *overlapped = (_MDOverlapped *)arg;
+    PRRecvWait *desc =  overlapped->data.mw.desc;
+    PRFileDesc *bottom;
+    
+    if (InterlockedCompareExchange((LONG *)&desc->outcome,
+        (LONG)PR_MW_TIMEOUT, (LONG)PR_MW_PENDING) != (LONG)PR_MW_PENDING)
+    {
+        /* This wait recv descriptor has already completed. */
+        return;
+    }
+
+    /* close the osfd to abort the outstanding async io request */
+    /* $$$$
+    ** Little late to be checking if NSPR's on the bottom of stack,
+    ** but if we don't check, we can't assert that the private data
+    ** is what we think it is.
+    ** $$$$
+    */
+    bottom = PR_GetIdentitiesLayer(desc->fd, PR_NSPR_IO_LAYER);
+    PR_ASSERT(NULL != bottom);
+    if (NULL != bottom)  /* now what!?!?! */
+    {
+        bottom->secret->state = _PR_FILEDESC_CLOSED;
+        if (closesocket(bottom->secret->md.osfd) == SOCKET_ERROR)
+        {
+            fprintf(stderr, "closesocket failed: %d\n", WSAGetLastError());
+            PR_NOT_REACHED("What shall I do?");
+        }
+    }
+    return;
+}  /* NT_TimeProc */
+
+static PRStatus NT_HashRemove(PRWaitGroup *group, PRFileDesc *fd)
+{
+    PRRecvWait **waiter;
+
+    _PR_MD_LOCK(&group->mdlock);
+    waiter = _MW_LookupInternal(group, fd);
+    if (NULL != waiter)
+    {
+        group->waiter->count -= 1;
+        *waiter = NULL;
+    }
+    _PR_MD_UNLOCK(&group->mdlock);
+    return (NULL != waiter) ? PR_SUCCESS : PR_FAILURE;
+}
+
+PRStatus NT_HashRemoveInternal(PRWaitGroup *group, PRFileDesc *fd)
+{
+    PRRecvWait **waiter;
+
+    waiter = _MW_LookupInternal(group, fd);
+    if (NULL != waiter)
+    {
+        group->waiter->count -= 1;
+        *waiter = NULL;
+    }
+    return (NULL != waiter) ? PR_SUCCESS : PR_FAILURE;
+}
+#endif /* WINNT */
+
+/******************************************************************/
+/******************************************************************/
+/********************** The public API portion ********************/
+/******************************************************************/
+/******************************************************************/
+PR_IMPLEMENT(PRStatus) PR_AddWaitFileDesc(
+    PRWaitGroup *group, PRRecvWait *desc)
+{
+    _PR_HashStory hrv;
+    PRStatus rv = PR_FAILURE;
+#ifdef WINNT
+    _MDOverlapped *overlapped;
+    HANDLE hFile;
+    BOOL bResult;
+    DWORD dwError;
+    PRFileDesc *bottom;
+#endif
+
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+    if ((NULL == group) && (NULL == (group = MW_Init2())))
+    {
+        return rv;
+    }
+
+    PR_ASSERT(NULL != desc->fd);
+
+    desc->outcome = PR_MW_PENDING;  /* nice, well known value */
+    desc->bytesRecv = 0;  /* likewise, though this value is ambiguious */
+
+    PR_Lock(group->ml);
+
+    if (_prmw_running != group->state)
+    {
+        /* Not allowed to add after cancelling the group */
+        desc->outcome = PR_MW_INTERRUPT;
+        PR_SetError(PR_INVALID_STATE_ERROR, 0);
+        PR_Unlock(group->ml);
+        return rv;
+    }
+
+#ifdef WINNT
+    _PR_MD_LOCK(&group->mdlock);
+#endif
+
+    /*
+    ** If the waiter count is zero at this point, there's no telling
+    ** how long we've been idle. Therefore, initialize the beginning
+    ** of the timing interval. As long as the list doesn't go empty,
+    ** it will maintain itself.
+    */
+    if (0 == group->waiter->count)
+        group->last_poll = PR_IntervalNow();
+
+    do
+    {
+        hrv = MW_AddHashInternal(desc, group->waiter);
+        if (_prmw_rehash != hrv) break;
+        hrv = MW_ExpandHashInternal(group);  /* gruesome */
+        if (_prmw_success != hrv) break;
+    } while (PR_TRUE);
+
+#ifdef WINNT
+    _PR_MD_UNLOCK(&group->mdlock);
+#endif
+
+    PR_NotifyCondVar(group->new_business);  /* tell the world */
+    rv = (_prmw_success == hrv) ? PR_SUCCESS : PR_FAILURE;
+    PR_Unlock(group->ml);
+
+#ifdef WINNT
+    overlapped = PR_NEWZAP(_MDOverlapped);
+    if (NULL == overlapped)
+    {
+        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+        NT_HashRemove(group, desc->fd);
+        return rv;
+    }
+    overlapped->ioModel = _MD_MultiWaitIO;
+    overlapped->data.mw.desc = desc;
+    overlapped->data.mw.group = group;
+    if (desc->timeout != PR_INTERVAL_NO_TIMEOUT)
+    {
+        overlapped->data.mw.timer = CreateTimer(
+            desc->timeout,
+            NT_TimeProc,
+            overlapped);
+        if (0 == overlapped->data.mw.timer)
+        {
+            NT_HashRemove(group, desc->fd);
+            PR_DELETE(overlapped);
+            /*
+             * XXX It appears that a maximum of 16 timer events can
+             * be outstanding. GetLastError() returns 0 when I try it.
+             */
+            PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, GetLastError());
+            return PR_FAILURE;
+        }
+    }
+
+    /* Reach to the bottom layer to get the OS fd */
+    bottom = PR_GetIdentitiesLayer(desc->fd, PR_NSPR_IO_LAYER);
+    PR_ASSERT(NULL != bottom);
+    if (NULL == bottom)
+    {
+        PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+        return PR_FAILURE;
+    }
+    hFile = (HANDLE)bottom->secret->md.osfd; 
+    if (!bottom->secret->md.io_model_committed)
+    {
+        PRInt32 st;
+        st = _md_Associate(hFile);
+        PR_ASSERT(0 != st);
+        bottom->secret->md.io_model_committed = PR_TRUE;
+    }
+    bResult = ReadFile(hFile,
+        desc->buffer.start,
+        (DWORD)desc->buffer.length,
+        NULL,
+        &overlapped->overlapped);
+    if (FALSE == bResult && (dwError = GetLastError()) != ERROR_IO_PENDING)
+    {
+        if (desc->timeout != PR_INTERVAL_NO_TIMEOUT)
+        {
+            if (InterlockedCompareExchange((LONG *)&desc->outcome,
+                (LONG)PR_MW_FAILURE, (LONG)PR_MW_PENDING)
+                == (LONG)PR_MW_PENDING)
+            {
+                CancelTimer(overlapped->data.mw.timer);
+            }
+            NT_HashRemove(group, desc->fd);
+            PR_DELETE(overlapped);
+        }
+        _PR_MD_MAP_READ_ERROR(dwError);
+        rv = PR_FAILURE;
+    }
+#endif
+
+    return rv;
+}  /* PR_AddWaitFileDesc */
+
+PR_IMPLEMENT(PRRecvWait*) PR_WaitRecvReady(PRWaitGroup *group)
+{
+    PRCList *io_ready = NULL;
+#ifdef WINNT
+    PRThread *me = _PR_MD_CURRENT_THREAD();
+    _MDOverlapped *overlapped;    
+#endif
+
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+    if ((NULL == group) && (NULL == (group = MW_Init2()))) goto failed_init;
+
+    PR_Lock(group->ml);
+
+    if (_prmw_running != group->state)
+    {
+        PR_SetError(PR_INVALID_STATE_ERROR, 0);
+        goto invalid_state;
+    }
+
+    group->waiting_threads += 1;  /* the polling thread is counted */
+
+#ifdef WINNT
+    _PR_MD_LOCK(&group->mdlock);
+    while (PR_CLIST_IS_EMPTY(&group->io_ready))
+    {
+        _PR_THREAD_LOCK(me);
+        me->state = _PR_IO_WAIT;
+        PR_APPEND_LINK(&me->waitQLinks, &group->wait_list);
+        if (!_PR_IS_NATIVE_THREAD(me))
+        {
+            _PR_SLEEPQ_LOCK(me->cpu);
+            _PR_ADD_SLEEPQ(me, PR_INTERVAL_NO_TIMEOUT);
+            _PR_SLEEPQ_UNLOCK(me->cpu);
+        }
+        _PR_THREAD_UNLOCK(me);
+        _PR_MD_UNLOCK(&group->mdlock);
+        PR_Unlock(group->ml);
+        _PR_MD_WAIT(me, PR_INTERVAL_NO_TIMEOUT);
+        me->state = _PR_RUNNING;
+        PR_Lock(group->ml);
+        _PR_MD_LOCK(&group->mdlock);
+        if (_PR_PENDING_INTERRUPT(me)) {
+            PR_REMOVE_LINK(&me->waitQLinks);
+            _PR_MD_UNLOCK(&group->mdlock);
+            me->flags &= ~_PR_INTERRUPT;
+            me->io_suspended = PR_FALSE;
+            PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+            goto aborted;
+        }
+    }
+    io_ready = PR_LIST_HEAD(&group->io_ready);
+    PR_ASSERT(io_ready != NULL);
+    PR_REMOVE_LINK(io_ready);
+    _PR_MD_UNLOCK(&group->mdlock);
+    overlapped = (_MDOverlapped *)
+        ((char *)io_ready - offsetof(_MDOverlapped, data));
+    io_ready = &overlapped->data.mw.desc->internal;
+#else
+    do
+    {
+        /*
+        ** If the I/O ready list isn't empty, have this thread
+        ** return with the first receive wait object that's available.
+        */
+        if (PR_CLIST_IS_EMPTY(&group->io_ready))
+        {
+            /*
+            ** Is there a polling thread yet? If not, grab this thread
+            ** and use it.
+            */
+            if (NULL == group->poller)
+            {
+                /*
+                ** This thread will stay do polling until it becomes the only one
+                ** left to service a completion. Then it will return and there will
+                ** be none left to actually poll or to run completions.
+                **
+                ** The polling function should only return w/ failure or
+                ** with some I/O ready.
+                */
+                if (PR_FAILURE == _MW_PollInternal(group)) goto failed_poll;
+            }
+            else
+            {
+                /*
+                ** There are four reasons a thread can be awakened from
+                ** a wait on the io_complete condition variable.
+                ** 1. Some I/O has completed, i.e., the io_ready list
+                **    is nonempty.
+                ** 2. The wait group is canceled.
+                ** 3. The thread is interrupted.
+                ** 4. The current polling thread has to leave and needs
+                **    a replacement.
+                ** The logic to find a new polling thread is made more
+                ** complicated by all the other possible events.
+                ** I tried my best to write the logic clearly, but
+                ** it is still full of if's with continue and goto.
+                */
+                PRStatus st;
+                do 
+                {
+                    st = PR_WaitCondVar(group->io_complete, PR_INTERVAL_NO_TIMEOUT);
+                    if (_prmw_running != group->state)
+                    {
+                        PR_SetError(PR_INVALID_STATE_ERROR, 0);
+                        goto aborted;
+                    }
+                    if (_MW_ABORTED(st) || (NULL == group->poller)) break;
+                } while (PR_CLIST_IS_EMPTY(&group->io_ready));
+
+                /*
+                ** The thread is interrupted and has to leave.  It might
+                ** have also been awakened to process ready i/o or be the
+                ** new poller.  To be safe, if either condition is true,
+                ** we awaken another thread to take its place.
+                */
+                if (_MW_ABORTED(st))
+                {
+                    if ((NULL == group->poller
+                    || !PR_CLIST_IS_EMPTY(&group->io_ready))
+                    && group->waiting_threads > 1)
+                        PR_NotifyCondVar(group->io_complete);
+                    goto aborted;
+                }
+
+                /*
+                ** A new poller is needed, but can I be the new poller?
+                ** If there is no i/o ready, sure.  But if there is any
+                ** i/o ready, it has a higher priority.  I want to
+                ** process the ready i/o first and wake up another
+                ** thread to be the new poller.
+                */ 
+                if (NULL == group->poller)
+                {
+                    if (PR_CLIST_IS_EMPTY(&group->io_ready))
+                        continue;
+                    if (group->waiting_threads > 1)
+                        PR_NotifyCondVar(group->io_complete);
+                }
+            }
+            PR_ASSERT(!PR_CLIST_IS_EMPTY(&group->io_ready));
+        }
+        io_ready = PR_LIST_HEAD(&group->io_ready);
+        PR_NotifyCondVar(group->io_taken);
+        PR_ASSERT(io_ready != NULL);
+        PR_REMOVE_LINK(io_ready);
+    } while (NULL == io_ready);
+
+failed_poll:
+
+#endif
+
+aborted:
+
+    group->waiting_threads -= 1;
+invalid_state:
+    (void)MW_TestForShutdownInternal(group);
+    PR_Unlock(group->ml);
+
+failed_init:
+    if (NULL != io_ready)
+    {
+        /* If the operation failed, record the reason why */
+        switch (((PRRecvWait*)io_ready)->outcome)
+        {
+            case PR_MW_PENDING:
+                PR_ASSERT(0);
+                break;
+            case PR_MW_SUCCESS:
+#ifndef WINNT
+                _MW_InitialRecv(io_ready);
+#endif
+                break;
+#ifdef WINNT
+            case PR_MW_FAILURE:
+                _PR_MD_MAP_READ_ERROR(overlapped->data.mw.error);
+                break;
+#endif
+            case PR_MW_TIMEOUT:
+                PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
+                break;
+            case PR_MW_INTERRUPT:
+                PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+                break;
+            default: break;
+        }
+#ifdef WINNT
+        if (NULL != overlapped->data.mw.timer)
+        {
+            PR_ASSERT(PR_INTERVAL_NO_TIMEOUT
+                != overlapped->data.mw.desc->timeout);
+            CancelTimer(overlapped->data.mw.timer);
+        }
+        else
+        {
+            PR_ASSERT(PR_INTERVAL_NO_TIMEOUT
+                == overlapped->data.mw.desc->timeout);
+        }
+        PR_DELETE(overlapped);
+#endif
+    }
+    return (PRRecvWait*)io_ready;
+}  /* PR_WaitRecvReady */
+
+PR_IMPLEMENT(PRStatus) PR_CancelWaitFileDesc(PRWaitGroup *group, PRRecvWait *desc)
+{
+#if !defined(WINNT)
+    PRRecvWait **recv_wait;
+#endif
+    PRStatus rv = PR_SUCCESS;
+    if (NULL == group) group = mw_state->group;
+    PR_ASSERT(NULL != group);
+    if (NULL == group)
+    {
+        PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+        return PR_FAILURE;
+    }
+
+    PR_Lock(group->ml);
+
+    if (_prmw_running != group->state)
+    {
+        PR_SetError(PR_INVALID_STATE_ERROR, 0);
+        rv = PR_FAILURE;
+        goto unlock;
+    }
+
+#ifdef WINNT
+    if (InterlockedCompareExchange((LONG *)&desc->outcome,
+        (LONG)PR_MW_INTERRUPT, (LONG)PR_MW_PENDING) == (LONG)PR_MW_PENDING)
+    {
+        PRFileDesc *bottom = PR_GetIdentitiesLayer(desc->fd, PR_NSPR_IO_LAYER);
+        PR_ASSERT(NULL != bottom);
+        if (NULL == bottom)
+        {
+            PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+            goto unlock;
+        }
+        bottom->secret->state = _PR_FILEDESC_CLOSED;
+#if 0
+        fprintf(stderr, "cancel wait recv: closing socket\n");
+#endif
+        if (closesocket(bottom->secret->md.osfd) == SOCKET_ERROR)
+        {
+            fprintf(stderr, "closesocket failed: %d\n", WSAGetLastError());
+            exit(1);
+        }
+    }
+#else
+    if (NULL != (recv_wait = _MW_LookupInternal(group, desc->fd)))
+    {
+        /* it was in the wait table */
+        _MW_DoneInternal(group, recv_wait, PR_MW_INTERRUPT);
+        goto unlock;
+    }
+    if (!PR_CLIST_IS_EMPTY(&group->io_ready))
+    {
+        /* is it already complete? */
+        PRCList *head = PR_LIST_HEAD(&group->io_ready);
+        do
+        {
+            PRRecvWait *done = (PRRecvWait*)head;
+            if (done == desc) goto unlock;
+            head = PR_NEXT_LINK(head);
+        } while (head != &group->io_ready);
+    }
+    PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+    rv = PR_FAILURE;
+
+#endif
+unlock:
+    PR_Unlock(group->ml);
+    return rv;
+}  /* PR_CancelWaitFileDesc */
+
+PR_IMPLEMENT(PRRecvWait*) PR_CancelWaitGroup(PRWaitGroup *group)
+{
+    PRRecvWait **desc;
+    PRRecvWait *recv_wait = NULL;
+#ifdef WINNT
+    _MDOverlapped *overlapped;
+    PRRecvWait **end;
+    PRThread *me = _PR_MD_CURRENT_THREAD();
+#endif
+
+    if (NULL == group) group = mw_state->group;
+    PR_ASSERT(NULL != group);
+    if (NULL == group)
+    {
+        PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+        return NULL;
+    }
+
+    PR_Lock(group->ml);
+    if (_prmw_stopped != group->state)
+    {
+        if (_prmw_running == group->state)
+            group->state = _prmw_stopping;  /* so nothing new comes in */
+        if (0 == group->waiting_threads)  /* is there anybody else? */
+            group->state = _prmw_stopped;  /* we can stop right now */
+        else
+        {
+            PR_NotifyAllCondVar(group->new_business);
+            PR_NotifyAllCondVar(group->io_complete);
+        }
+        while (_prmw_stopped != group->state)
+            (void)PR_WaitCondVar(group->mw_manage, PR_INTERVAL_NO_TIMEOUT);
+    }
+
+#ifdef WINNT
+    _PR_MD_LOCK(&group->mdlock);
+#endif
+    /* make all the existing descriptors look done/interrupted */
+#ifdef WINNT
+    end = &group->waiter->recv_wait + group->waiter->length;
+    for (desc = &group->waiter->recv_wait; desc < end; ++desc)
+    {
+        if (NULL != *desc)
+        {
+            if (InterlockedCompareExchange((LONG *)&(*desc)->outcome,
+                (LONG)PR_MW_INTERRUPT, (LONG)PR_MW_PENDING)
+                == (LONG)PR_MW_PENDING)
+            {
+                PRFileDesc *bottom = PR_GetIdentitiesLayer(
+                    (*desc)->fd, PR_NSPR_IO_LAYER);
+                PR_ASSERT(NULL != bottom);
+                if (NULL == bottom)
+                {
+                    PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+                    goto invalid_arg;
+                }
+                bottom->secret->state = _PR_FILEDESC_CLOSED;
+#if 0
+                fprintf(stderr, "cancel wait group: closing socket\n");
+#endif
+                if (closesocket(bottom->secret->md.osfd) == SOCKET_ERROR)
+                {
+                    fprintf(stderr, "closesocket failed: %d\n",
+                        WSAGetLastError());
+                    exit(1);
+                }
+            }
+        }
+    }
+    while (group->waiter->count > 0)
+    {
+        _PR_THREAD_LOCK(me);
+        me->state = _PR_IO_WAIT;
+        PR_APPEND_LINK(&me->waitQLinks, &group->wait_list);
+        if (!_PR_IS_NATIVE_THREAD(me))
+        {
+            _PR_SLEEPQ_LOCK(me->cpu);
+            _PR_ADD_SLEEPQ(me, PR_INTERVAL_NO_TIMEOUT);
+            _PR_SLEEPQ_UNLOCK(me->cpu);
+        }
+        _PR_THREAD_UNLOCK(me);
+        _PR_MD_UNLOCK(&group->mdlock);
+        PR_Unlock(group->ml);
+        _PR_MD_WAIT(me, PR_INTERVAL_NO_TIMEOUT);
+        me->state = _PR_RUNNING;
+        PR_Lock(group->ml);
+        _PR_MD_LOCK(&group->mdlock);
+    }
+#else
+    for (desc = &group->waiter->recv_wait; group->waiter->count > 0; ++desc)
+    {
+        PR_ASSERT(desc < &group->waiter->recv_wait + group->waiter->length);
+        if (NULL != *desc)
+            _MW_DoneInternal(group, desc, PR_MW_INTERRUPT);
+    }
+#endif
+
+    /* take first element of finished list and return it or NULL */
+    if (PR_CLIST_IS_EMPTY(&group->io_ready))
+        PR_SetError(PR_GROUP_EMPTY_ERROR, 0);
+    else
+    {
+        PRCList *head = PR_LIST_HEAD(&group->io_ready);
+        PR_REMOVE_AND_INIT_LINK(head);
+#ifdef WINNT
+        overlapped = (_MDOverlapped *)
+            ((char *)head - offsetof(_MDOverlapped, data));
+        head = &overlapped->data.mw.desc->internal;
+        if (NULL != overlapped->data.mw.timer)
+        {
+            PR_ASSERT(PR_INTERVAL_NO_TIMEOUT
+                != overlapped->data.mw.desc->timeout);
+            CancelTimer(overlapped->data.mw.timer);
+        }
+        else
+        {
+            PR_ASSERT(PR_INTERVAL_NO_TIMEOUT
+                == overlapped->data.mw.desc->timeout);
+        }
+        PR_DELETE(overlapped);
+#endif
+        recv_wait = (PRRecvWait*)head;
+    }
+#ifdef WINNT
+invalid_arg:
+    _PR_MD_UNLOCK(&group->mdlock);
+#endif
+    PR_Unlock(group->ml);
+
+    return recv_wait;
+}  /* PR_CancelWaitGroup */
+
+PR_IMPLEMENT(PRWaitGroup*) PR_CreateWaitGroup(PRInt32 size /* ignored */)
+{
+    PRWaitGroup *wg;
+
+    if (NULL == (wg = PR_NEWZAP(PRWaitGroup)))
+    {
+        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+        goto failed;
+    }
+    /* the wait group itself */
+    wg->ml = PR_NewLock();
+    if (NULL == wg->ml) goto failed_lock;
+    wg->io_taken = PR_NewCondVar(wg->ml);
+    if (NULL == wg->io_taken) goto failed_cvar0;
+    wg->io_complete = PR_NewCondVar(wg->ml);
+    if (NULL == wg->io_complete) goto failed_cvar1;
+    wg->new_business = PR_NewCondVar(wg->ml);
+    if (NULL == wg->new_business) goto failed_cvar2;
+    wg->mw_manage = PR_NewCondVar(wg->ml);
+    if (NULL == wg->mw_manage) goto failed_cvar3;
+
+    PR_INIT_CLIST(&wg->group_link);
+    PR_INIT_CLIST(&wg->io_ready);
+
+    /* the waiters sequence */
+    wg->waiter = (_PRWaiterHash*)PR_CALLOC(
+        sizeof(_PRWaiterHash) +
+        (_PR_DEFAULT_HASH_LENGTH * sizeof(PRRecvWait*)));
+    if (NULL == wg->waiter)
+    {
+        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+        goto failed_waiter;
+    }
+    wg->waiter->count = 0;
+    wg->waiter->length = _PR_DEFAULT_HASH_LENGTH;
+
+#ifdef WINNT
+    _PR_MD_NEW_LOCK(&wg->mdlock);
+    PR_INIT_CLIST(&wg->wait_list);
+#endif /* WINNT */
+
+    PR_Lock(mw_lock);
+    PR_APPEND_LINK(&wg->group_link, &mw_state->group_list);
+    PR_Unlock(mw_lock);
+    return wg;
+
+failed_waiter:
+    PR_DestroyCondVar(wg->mw_manage);
+failed_cvar3:
+    PR_DestroyCondVar(wg->new_business);
+failed_cvar2:
+    PR_DestroyCondVar(wg->io_complete);
+failed_cvar1:
+    PR_DestroyCondVar(wg->io_taken);
+failed_cvar0:
+    PR_DestroyLock(wg->ml);
+failed_lock:
+    PR_DELETE(wg);
+    wg = NULL;
+
+failed:
+    return wg;
+}  /* MW_CreateWaitGroup */
+
+PR_IMPLEMENT(PRStatus) PR_DestroyWaitGroup(PRWaitGroup *group)
+{
+    PRStatus rv = PR_SUCCESS;
+    if (NULL == group) group = mw_state->group;
+    PR_ASSERT(NULL != group);
+    if (NULL != group)
+    {
+        PR_Lock(group->ml);
+        if ((group->waiting_threads == 0)
+        && (group->waiter->count == 0)
+        && PR_CLIST_IS_EMPTY(&group->io_ready))
+        {
+            group->state = _prmw_stopped;
+        }
+        else
+        {
+            PR_SetError(PR_INVALID_STATE_ERROR, 0);
+            rv = PR_FAILURE;
+        }
+        PR_Unlock(group->ml);
+        if (PR_FAILURE == rv) return rv;
+
+        PR_Lock(mw_lock);
+        PR_REMOVE_LINK(&group->group_link);
+        PR_Unlock(mw_lock);
+
+#ifdef WINNT
+        /*
+         * XXX make sure wait_list is empty and waiter is empty.
+         * These must be checked while holding mdlock.
+         */
+        _PR_MD_FREE_LOCK(&group->mdlock);
+#endif
+
+        PR_DELETE(group->waiter);
+        PR_DELETE(group->polling_list);
+        PR_DestroyCondVar(group->mw_manage);
+        PR_DestroyCondVar(group->new_business);
+        PR_DestroyCondVar(group->io_complete);
+        PR_DestroyCondVar(group->io_taken);
+        PR_DestroyLock(group->ml);
+        if (group == mw_state->group) mw_state->group = NULL;
+        PR_DELETE(group);
+    }
+    else
+    {
+        /* The default wait group is not created yet. */
+        PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+        rv = PR_FAILURE;
+    }
+    return rv;
+}  /* PR_DestroyWaitGroup */
+
+/**********************************************************************
+***********************************************************************
+******************** Wait group enumerations **************************
+***********************************************************************
+**********************************************************************/
+
+PR_IMPLEMENT(PRMWaitEnumerator*) PR_CreateMWaitEnumerator(PRWaitGroup *group)
+{
+    PRMWaitEnumerator *enumerator = PR_NEWZAP(PRMWaitEnumerator);
+    if (NULL == enumerator) PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+    else
+    {
+        enumerator->group = group;
+        enumerator->seal = _PR_ENUM_SEALED;
+    }
+    return enumerator;
+}  /* PR_CreateMWaitEnumerator */
+
+PR_IMPLEMENT(PRStatus) PR_DestroyMWaitEnumerator(PRMWaitEnumerator* enumerator)
+{
+    PR_ASSERT(NULL != enumerator);
+    PR_ASSERT(_PR_ENUM_SEALED == enumerator->seal);
+    if ((NULL == enumerator) || (_PR_ENUM_SEALED != enumerator->seal))
+    {
+        PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+        return PR_FAILURE;
+    }
+    enumerator->seal = _PR_ENUM_UNSEALED;
+    PR_Free(enumerator);
+    return PR_SUCCESS;
+}  /* PR_DestroyMWaitEnumerator */
+
+PR_IMPLEMENT(PRRecvWait*) PR_EnumerateWaitGroup(
+    PRMWaitEnumerator *enumerator, const PRRecvWait *previous)
+{
+    PRRecvWait *result = NULL;
+    
+    /* entry point sanity checking */
+    PR_ASSERT(NULL != enumerator);
+    PR_ASSERT(_PR_ENUM_SEALED == enumerator->seal);
+    if ((NULL == enumerator)
+    || (_PR_ENUM_SEALED != enumerator->seal)) goto bad_argument;
+
+    /* beginning of enumeration */
+    if (NULL == previous)
+    {
+        if (NULL == enumerator->group)
+        {
+            enumerator->group = mw_state->group;
+            if (NULL == enumerator->group)
+            {
+                PR_SetError(PR_GROUP_EMPTY_ERROR, 0);
+                return NULL;
+            }
+        }
+        enumerator->waiter = &enumerator->group->waiter->recv_wait;
+        enumerator->p_timestamp = enumerator->group->p_timestamp;
+        enumerator->thread = PR_GetCurrentThread();
+        enumerator->index = 0;
+    }
+    /* continuing an enumeration */
+    else
+    {
+        PRThread *me = PR_GetCurrentThread();
+        PR_ASSERT(me == enumerator->thread);
+        if (me != enumerator->thread) goto bad_argument;
+
+        /* need to restart the enumeration */
+        if (enumerator->p_timestamp != enumerator->group->p_timestamp)
+            return PR_EnumerateWaitGroup(enumerator, NULL);
+    }
+
+    /* actually progress the enumeration */
+#if defined(WINNT)
+    _PR_MD_LOCK(&enumerator->group->mdlock);
+#else
+    PR_Lock(enumerator->group->ml);
+#endif
+    while (enumerator->index++ < enumerator->group->waiter->length)
+    {
+        if (NULL != (result = *(enumerator->waiter)++)) break;
+    }
+#if defined(WINNT)
+    _PR_MD_UNLOCK(&enumerator->group->mdlock);
+#else
+    PR_Unlock(enumerator->group->ml);
+#endif
+
+    return result;  /* what we live for */
+
+bad_argument:
+    PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+    return NULL;  /* probably ambiguous */
+}  /* PR_EnumerateWaitGroup */
+
+/* prmwait.c */
diff --git a/pr/src/io/prpolevt.c b/pr/src/io/prpolevt.c
new file mode 100644
index 0000000..ac3eb10
--- /dev/null
+++ b/pr/src/io/prpolevt.c
@@ -0,0 +1,230 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+ *********************************************************************
+ *
+ * Pollable events
+ *
+ * Pollable events are implemented using layered I/O.  The only
+ * I/O methods that are implemented for pollable events are poll
+ * and close.  No other methods can be invoked on a pollable
+ * event.
+ *
+ * A pipe or socket pair is created and the pollable event layer
+ * is pushed onto the read end.  A pointer to the write end is
+ * saved in the PRFilePrivate structure of the pollable event.
+ *
+ *********************************************************************
+ */
+
+#include "prinit.h"
+#include "prio.h"
+#include "prmem.h"
+#include "prerror.h"
+#include "prlog.h"
+
+/*
+ * These internal functions are declared in primpl.h,
+ * but we can't include primpl.h because the definition
+ * of struct PRFilePrivate in this file (for the pollable
+ * event layer) will conflict with the definition of
+ * struct PRFilePrivate in primpl.h (for the NSPR layer).
+ */
+extern PRIntn _PR_InvalidInt(void);
+extern PRInt64 _PR_InvalidInt64(void);
+extern PRStatus _PR_InvalidStatus(void);
+extern PRFileDesc *_PR_InvalidDesc(void);
+
+/*
+ * PRFilePrivate structure for the NSPR pollable events layer
+ */
+struct PRFilePrivate {
+    PRFileDesc *writeEnd;  /* the write end of the pipe/socketpair */
+};
+
+static PRStatus PR_CALLBACK _pr_PolEvtClose(PRFileDesc *fd);
+
+static PRInt16 PR_CALLBACK _pr_PolEvtPoll(
+    PRFileDesc *fd, PRInt16 in_flags, PRInt16 *out_flags);
+
+static PRIOMethods _pr_polevt_methods = {
+    PR_DESC_LAYERED,
+    _pr_PolEvtClose,
+    (PRReadFN)_PR_InvalidInt,
+    (PRWriteFN)_PR_InvalidInt,
+    (PRAvailableFN)_PR_InvalidInt,
+    (PRAvailable64FN)_PR_InvalidInt64,
+    (PRFsyncFN)_PR_InvalidStatus,
+    (PRSeekFN)_PR_InvalidInt,
+    (PRSeek64FN)_PR_InvalidInt64,
+    (PRFileInfoFN)_PR_InvalidStatus,
+    (PRFileInfo64FN)_PR_InvalidStatus,
+    (PRWritevFN)_PR_InvalidInt,        
+    (PRConnectFN)_PR_InvalidStatus,        
+    (PRAcceptFN)_PR_InvalidDesc,        
+    (PRBindFN)_PR_InvalidStatus,        
+    (PRListenFN)_PR_InvalidStatus,        
+    (PRShutdownFN)_PR_InvalidStatus,    
+    (PRRecvFN)_PR_InvalidInt,        
+    (PRSendFN)_PR_InvalidInt,        
+    (PRRecvfromFN)_PR_InvalidInt,    
+    (PRSendtoFN)_PR_InvalidInt,        
+    _pr_PolEvtPoll,
+    (PRAcceptreadFN)_PR_InvalidInt,   
+    (PRTransmitfileFN)_PR_InvalidInt, 
+    (PRGetsocknameFN)_PR_InvalidStatus,    
+    (PRGetpeernameFN)_PR_InvalidStatus,    
+    (PRReservedFN)_PR_InvalidInt,    
+    (PRReservedFN)_PR_InvalidInt,    
+    (PRGetsocketoptionFN)_PR_InvalidStatus,
+    (PRSetsocketoptionFN)_PR_InvalidStatus,
+    (PRSendfileFN)_PR_InvalidInt, 
+    (PRConnectcontinueFN)_PR_InvalidStatus, 
+    (PRReservedFN)_PR_InvalidInt, 
+    (PRReservedFN)_PR_InvalidInt, 
+    (PRReservedFN)_PR_InvalidInt, 
+    (PRReservedFN)_PR_InvalidInt
+};
+
+static PRDescIdentity _pr_polevt_id;
+static PRCallOnceType _pr_polevt_once_control;
+static PRStatus PR_CALLBACK _pr_PolEvtInit(void);
+
+static PRInt16 PR_CALLBACK _pr_PolEvtPoll(
+    PRFileDesc *fd, PRInt16 in_flags, PRInt16 *out_flags)
+{
+    return (fd->lower->methods->poll)(fd->lower, in_flags, out_flags);
+}
+
+static PRStatus PR_CALLBACK _pr_PolEvtInit(void)
+{
+    _pr_polevt_id = PR_GetUniqueIdentity("NSPR pollable events");
+    if (PR_INVALID_IO_LAYER == _pr_polevt_id) {
+        return PR_FAILURE;
+    }
+    return PR_SUCCESS;
+}
+
+#if !defined(XP_UNIX)
+#define USE_TCP_SOCKETPAIR
+#endif
+
+PR_IMPLEMENT(PRFileDesc *) PR_NewPollableEvent(void)
+{
+    PRFileDesc *event;
+    PRFileDesc *fd[2]; /* fd[0] is the read end; fd[1] is the write end */
+#ifdef USE_TCP_SOCKETPAIR
+    PRSocketOptionData socket_opt;
+    PRStatus rv;
+#endif
+
+    fd[0] = fd[1] = NULL;
+
+    if (PR_CallOnce(&_pr_polevt_once_control, _pr_PolEvtInit) == PR_FAILURE) {
+        return NULL;
+    }
+
+    event = PR_CreateIOLayerStub(_pr_polevt_id, &_pr_polevt_methods);
+    if (NULL == event) {
+        goto errorExit;
+    } 
+    event->secret = PR_NEW(PRFilePrivate);
+    if (event->secret == NULL) {
+        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+        goto errorExit;
+    }
+
+#ifndef USE_TCP_SOCKETPAIR
+    if (PR_CreatePipe(&fd[0], &fd[1]) == PR_FAILURE) {
+        fd[0] = fd[1] = NULL;
+        goto errorExit;
+    }
+#else
+    if (PR_NewTCPSocketPair(fd) == PR_FAILURE) {
+        fd[0] = fd[1] = NULL;
+        goto errorExit;
+    }
+	/*
+	 * set the TCP_NODELAY option to reduce notification latency
+	 */
+    socket_opt.option = PR_SockOpt_NoDelay;
+    socket_opt.value.no_delay = PR_TRUE;
+    rv = PR_SetSocketOption(fd[1], &socket_opt);
+    PR_ASSERT(PR_SUCCESS == rv);
+#endif
+
+    event->secret->writeEnd = fd[1];
+    if (PR_PushIOLayer(fd[0], PR_TOP_IO_LAYER, event) == PR_FAILURE) {
+        goto errorExit;
+    }
+
+    return fd[0];
+
+errorExit:
+    if (fd[0]) {
+        PR_Close(fd[0]);
+        PR_Close(fd[1]);
+    }
+    if (event) {
+        PR_DELETE(event->secret);
+        event->dtor(event);
+    }
+    return NULL;
+}
+
+static PRStatus PR_CALLBACK _pr_PolEvtClose(PRFileDesc *fd)
+{
+    PRFileDesc *event;
+
+    event = PR_PopIOLayer(fd, PR_TOP_IO_LAYER);
+    PR_ASSERT(NULL == event->higher && NULL == event->lower);
+    PR_Close(fd);
+    PR_Close(event->secret->writeEnd);
+    PR_DELETE(event->secret);
+    event->dtor(event);
+    return PR_SUCCESS;
+}
+
+PR_IMPLEMENT(PRStatus) PR_DestroyPollableEvent(PRFileDesc *event)
+{
+    return PR_Close(event);
+}
+
+static const char magicChar = '\x38';
+
+PR_IMPLEMENT(PRStatus) PR_SetPollableEvent(PRFileDesc *event)
+{
+    if (PR_Write(event->secret->writeEnd, &magicChar, 1) != 1) {
+        return PR_FAILURE;
+    }
+    return PR_SUCCESS;
+}
+
+PR_IMPLEMENT(PRStatus) PR_WaitForPollableEvent(PRFileDesc *event)
+{
+    char buf[1024];
+    PRInt32 nBytes;
+#ifdef DEBUG
+    PRIntn i;
+#endif
+
+    nBytes = PR_Read(event->lower, buf, sizeof(buf));
+    if (nBytes == -1) {
+        return PR_FAILURE;
+    }
+
+#ifdef DEBUG
+    /*
+     * Make sure people do not write to the pollable event fd
+     * directly.
+     */
+    for (i = 0; i < nBytes; i++) {
+        PR_ASSERT(buf[i] == magicChar);
+    }
+#endif
+
+    return PR_SUCCESS;
+}
diff --git a/pr/src/io/prprf.c b/pr/src/io/prprf.c
new file mode 100644
index 0000000..8475c77
--- /dev/null
+++ b/pr/src/io/prprf.c
@@ -0,0 +1,1290 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+** Portable safe sprintf code.
+**
+** Author: Kipp E.B. Hickman
+*/
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
+#include "primpl.h"
+#include "prprf.h"
+#include "prlong.h"
+#include "prlog.h"
+#include "prmem.h"
+
+#if defined(_MSC_VER) && _MSC_VER < 1900
+#define snprintf _snprintf
+#endif
+
+/*
+** WARNING: This code may *NOT* call PR_LOG (because PR_LOG calls it)
+*/
+
+/*
+** XXX This needs to be internationalized!
+*/
+
+typedef struct SprintfStateStr SprintfState;
+
+struct SprintfStateStr {
+    int (*stuff)(SprintfState *ss, const char *sp, PRUint32 len);
+
+    char *base;
+    char *cur;
+    PRUint32 maxlen;  /* Must not exceed PR_INT32_MAX. */
+
+    int (*func)(void *arg, const char *sp, PRUint32 len);
+    void *arg;
+};
+
+/*
+** Numbered Argument
+*/
+struct NumArg {
+    int type;           /* type of the numbered argument    */
+    union {             /* the numbered argument            */
+	int i;
+	unsigned int ui;
+	PRInt32 i32;
+	PRUint32 ui32;
+	PRInt64 ll;
+	PRUint64 ull;
+	double d;
+	const char *s;
+	int *ip;
+#ifdef WIN32
+	const WCHAR *ws;
+#endif
+    } u;
+};
+
+#define NAS_DEFAULT_NUM 20  /* default number of NumberedArgument array */
+
+/*
+** For numeric types, the signed versions must have even values,
+** and their corresponding unsigned versions must have the subsequent
+** odd value.
+*/
+#define TYPE_INT16	0
+#define TYPE_UINT16	1
+#define TYPE_INTN	2
+#define TYPE_UINTN	3
+#define TYPE_INT32	4
+#define TYPE_UINT32	5
+#define TYPE_INT64	6
+#define TYPE_UINT64	7
+#define TYPE_STRING	8
+#define TYPE_DOUBLE	9
+#define TYPE_INTSTR	10
+#ifdef WIN32
+#define TYPE_WSTRING	11
+#endif
+#define TYPE_UNKNOWN	20
+
+#define FLAG_LEFT	0x1
+#define FLAG_SIGNED	0x2
+#define FLAG_SPACED	0x4
+#define FLAG_ZEROS	0x8
+#define FLAG_NEG	0x10
+
+/*
+** Fill into the buffer using the data in src
+*/
+static int fill2(SprintfState *ss, const char *src, int srclen, int width,
+		int flags)
+{
+    char space = ' ';
+    int rv;
+
+    width -= srclen;
+    if ((width > 0) && ((flags & FLAG_LEFT) == 0)) {	/* Right adjusting */
+	if (flags & FLAG_ZEROS) {
+	    space = '0';
+	}
+	while (--width >= 0) {
+	    rv = (*ss->stuff)(ss, &space, 1);
+	    if (rv < 0) {
+		return rv;
+	    }
+	}
+    }
+
+    /* Copy out the source data */
+    rv = (*ss->stuff)(ss, src, srclen);
+    if (rv < 0) {
+	return rv;
+    }
+
+    if ((width > 0) && ((flags & FLAG_LEFT) != 0)) {	/* Left adjusting */
+	while (--width >= 0) {
+	    rv = (*ss->stuff)(ss, &space, 1);
+	    if (rv < 0) {
+		return rv;
+	    }
+	}
+    }
+    return 0;
+}
+
+/*
+** Fill a number. The order is: optional-sign zero-filling conversion-digits
+*/
+static int fill_n(SprintfState *ss, const char *src, int srclen, int width,
+		  int prec, int type, int flags)
+{
+    int zerowidth = 0;
+    int precwidth = 0;
+    int signwidth = 0;
+    int leftspaces = 0;
+    int rightspaces = 0;
+    int cvtwidth;
+    int rv;
+    char sign;
+
+    if ((type & 1) == 0) {
+	if (flags & FLAG_NEG) {
+	    sign = '-';
+	    signwidth = 1;
+	} else if (flags & FLAG_SIGNED) {
+	    sign = '+';
+	    signwidth = 1;
+	} else if (flags & FLAG_SPACED) {
+	    sign = ' ';
+	    signwidth = 1;
+	}
+    }
+    cvtwidth = signwidth + srclen;
+
+    if (prec > 0) {
+	if (prec > srclen) {
+	    precwidth = prec - srclen;		/* Need zero filling */
+	    cvtwidth += precwidth;
+	}
+    }
+
+    if ((flags & FLAG_ZEROS) && (prec < 0)) {
+	if (width > cvtwidth) {
+	    zerowidth = width - cvtwidth;	/* Zero filling */
+	    cvtwidth += zerowidth;
+	}
+    }
+
+    if (flags & FLAG_LEFT) {
+	if (width > cvtwidth) {
+	    /* Space filling on the right (i.e. left adjusting) */
+	    rightspaces = width - cvtwidth;
+	}
+    } else {
+	if (width > cvtwidth) {
+	    /* Space filling on the left (i.e. right adjusting) */
+	    leftspaces = width - cvtwidth;
+	}
+    }
+    while (--leftspaces >= 0) {
+	rv = (*ss->stuff)(ss, " ", 1);
+	if (rv < 0) {
+	    return rv;
+	}
+    }
+    if (signwidth) {
+	rv = (*ss->stuff)(ss, &sign, 1);
+	if (rv < 0) {
+	    return rv;
+	}
+    }
+    while (--precwidth >= 0) {
+	rv = (*ss->stuff)(ss, "0", 1);
+	if (rv < 0) {
+	    return rv;
+	}
+    }
+    while (--zerowidth >= 0) {
+	rv = (*ss->stuff)(ss, "0", 1);
+	if (rv < 0) {
+	    return rv;
+	}
+    }
+    rv = (*ss->stuff)(ss, src, srclen);
+    if (rv < 0) {
+	return rv;
+    }
+    while (--rightspaces >= 0) {
+	rv = (*ss->stuff)(ss, " ", 1);
+	if (rv < 0) {
+	    return rv;
+	}
+    }
+    return 0;
+}
+
+/*
+** Convert a long into its printable form
+*/
+static int cvt_l(SprintfState *ss, long num, int width, int prec, int radix,
+		 int type, int flags, const char *hexp)
+{
+    char cvtbuf[100];
+    char *cvt;
+    int digits;
+
+    /* according to the man page this needs to happen */
+    if ((prec == 0) && (num == 0)) {
+	return 0;
+    }
+
+    /*
+    ** Converting decimal is a little tricky. In the unsigned case we
+    ** need to stop when we hit 10 digits. In the signed case, we can
+    ** stop when the number is zero.
+    */
+    cvt = cvtbuf + sizeof(cvtbuf);
+    digits = 0;
+    while (num) {
+	int digit = (((unsigned long)num) % radix) & 0xF;
+	*--cvt = hexp[digit];
+	digits++;
+	num = (long)(((unsigned long)num) / radix);
+    }
+    if (digits == 0) {
+	*--cvt = '0';
+	digits++;
+    }
+
+    /*
+    ** Now that we have the number converted without its sign, deal with
+    ** the sign and zero padding.
+    */
+    return fill_n(ss, cvt, digits, width, prec, type, flags);
+}
+
+/*
+** Convert a 64-bit integer into its printable form
+*/
+static int cvt_ll(SprintfState *ss, PRInt64 num, int width, int prec, int radix,
+		  int type, int flags, const char *hexp)
+{
+    char cvtbuf[100];
+    char *cvt;
+    int digits;
+    PRInt64 rad;
+
+    /* according to the man page this needs to happen */
+    if ((prec == 0) && (LL_IS_ZERO(num))) {
+	return 0;
+    }
+
+    /*
+    ** Converting decimal is a little tricky. In the unsigned case we
+    ** need to stop when we hit 10 digits. In the signed case, we can
+    ** stop when the number is zero.
+    */
+    LL_I2L(rad, radix);
+    cvt = cvtbuf + sizeof(cvtbuf);
+    digits = 0;
+    while (!LL_IS_ZERO(num)) {
+	PRInt32 digit;
+	PRInt64 quot, rem;
+	LL_UDIVMOD(&quot, &rem, num, rad);
+	LL_L2I(digit, rem);
+	*--cvt = hexp[digit & 0xf];
+	digits++;
+	num = quot;
+    }
+    if (digits == 0) {
+	*--cvt = '0';
+	digits++;
+    }
+
+    /*
+    ** Now that we have the number converted without its sign, deal with
+    ** the sign and zero padding.
+    */
+    return fill_n(ss, cvt, digits, width, prec, type, flags);
+}
+
+/*
+** Convert a double precision floating point number into its printable
+** form.
+**
+** XXX stop using snprintf to convert floating point
+*/
+static int cvt_f(SprintfState *ss, double d, const char *fmt0, const char *fmt1)
+{
+    char fin[20];
+    char fout[300];
+    int amount = fmt1 - fmt0;
+
+    if (amount <= 0 || amount >= sizeof(fin)) {
+	/* Totally bogus % command to snprintf. Just ignore it */
+	return 0;
+    }
+    memcpy(fin, fmt0, amount);
+    fin[amount] = 0;
+
+    /* Convert floating point using the native snprintf code */
+#ifdef DEBUG
+    {
+        const char *p = fin;
+        while (*p) {
+            PR_ASSERT(*p != 'L');
+            p++;
+        }
+    }
+#endif
+    memset(fout, 0, sizeof(fout));
+    snprintf(fout, sizeof(fout), fin, d);
+    /* Explicitly null-terminate fout because on Windows snprintf doesn't
+     * append a null-terminator if the buffer is too small. */
+    fout[sizeof(fout) - 1] = '\0';
+
+    return (*ss->stuff)(ss, fout, strlen(fout));
+}
+
+/*
+** Convert a string into its printable form.  "width" is the output
+** width. "prec" is the maximum number of characters of "s" to output,
+** where -1 means until NUL.
+*/
+static int cvt_s(SprintfState *ss, const char *str, int width, int prec,
+		 int flags)
+{
+    int slen;
+
+    if (prec == 0)
+	return 0;
+
+    /* Limit string length by precision value */
+    if (!str) {
+    	str = "(null)";
+    } 
+    if (prec > 0) {
+	/* this is:  slen = strnlen(str, prec); */
+	register const char *s;
+
+	for(s = str; prec && *s; s++, prec-- )
+	    ;
+	slen = s - str;
+    } else {
+	slen = strlen(str);
+    }
+
+    /* and away we go */
+    return fill2(ss, str, slen, width, flags);
+}
+
+/*
+** BuildArgArray stands for Numbered Argument list Sprintf
+** for example,
+**	fmt = "%4$i, %2$d, %3s, %1d";
+** the number must start from 1, and no gap among them
+*/
+
+static struct NumArg* BuildArgArray( const char *fmt, va_list ap, int* rv, struct NumArg* nasArray )
+{
+    int number = 0, cn = 0, i;
+    const char* p;
+    char  c;
+    struct NumArg* nas;
+    
+
+    /*
+    **	first pass:
+    **	determine how many legal % I have got, then allocate space
+    */
+
+    p = fmt;
+    *rv = 0;
+    i = 0;
+    while( ( c = *p++ ) != 0 ){
+	if( c != '%' )
+	    continue;
+	if( ( c = *p++ ) == '%' )	/* skip %% case */
+	    continue;
+
+	while( c != 0 ){
+	    if( c > '9' || c < '0' ){
+		if( c == '$' ){		/* numbered argument case */
+		    if( i > 0 ){
+			*rv = -1;
+			return NULL;
+		    }
+		    number++;
+		} else{			/* non-numbered argument case */
+		    if( number > 0 ){
+			*rv = -1;
+			return NULL;
+		    }
+		    i = 1;
+		}
+		break;
+	    }
+
+	    c = *p++;
+	}
+    }
+
+    if( number == 0 ){
+	return NULL;
+    }
+
+    
+    if( number > NAS_DEFAULT_NUM ){
+	nas = (struct NumArg*)PR_MALLOC( number * sizeof( struct NumArg ) );
+	if( !nas ){
+	    *rv = -1;
+	    return NULL;
+	}
+    } else {
+	nas = nasArray;
+    }
+
+    for( i = 0; i < number; i++ ){
+	nas[i].type = TYPE_UNKNOWN;
+    }
+
+
+    /*
+    ** second pass:
+    ** set nas[].type
+    */
+
+    p = fmt;
+    while( ( c = *p++ ) != 0 ){
+    	if( c != '%' )	continue;
+	    c = *p++;
+	if( c == '%' )	continue;
+
+	cn = 0;
+	while( c && c != '$' ){	    /* should improve error check later */
+	    cn = cn*10 + c - '0';
+	    c = *p++;
+	}
+
+	if( !c || cn < 1 || cn > number ){
+	    *rv = -1;
+	    break;
+        }
+
+	/* nas[cn] starts from 0, and make sure nas[cn].type is not assigned */
+        cn--;
+	if( nas[cn].type != TYPE_UNKNOWN )
+	    continue;
+
+        c = *p++;
+
+        /* width */
+        if (c == '*') {
+	    /* not supported feature, for the argument is not numbered */
+	    *rv = -1;
+	    break;
+	}
+
+	while ((c >= '0') && (c <= '9')) {
+	    c = *p++;
+	}
+
+	/* precision */
+	if (c == '.') {
+	    c = *p++;
+	    if (c == '*') {
+	        /* not supported feature, for the argument is not numbered */
+	        *rv = -1;
+	        break;
+	    }
+
+	    while ((c >= '0') && (c <= '9')) {
+		c = *p++;
+	    }
+	}
+
+	/* size */
+	nas[cn].type = TYPE_INTN;
+	if (c == 'h') {
+	    nas[cn].type = TYPE_INT16;
+	    c = *p++;
+	} else if (c == 'L') {
+	    /* XXX not quite sure here */
+	    nas[cn].type = TYPE_INT64;
+	    c = *p++;
+	} else if (c == 'l') {
+	    nas[cn].type = TYPE_INT32;
+	    c = *p++;
+	    if (c == 'l') {
+	        nas[cn].type = TYPE_INT64;
+	        c = *p++;
+	    }
+	} else if (c == 'z') {
+	    if (sizeof(size_t) == sizeof(PRInt32)) {
+	        nas[ cn ].type = TYPE_INT32;
+	    } else if (sizeof(size_t) == sizeof(PRInt64)) {
+	        nas[ cn ].type = TYPE_INT64;
+	    } else {
+		nas[ cn ].type = TYPE_UNKNOWN;
+	    }
+	    c = *p++;
+	}
+
+	/* format */
+	switch (c) {
+	case 'd':
+	case 'c':
+	case 'i':
+	case 'o':
+	case 'u':
+	case 'x':
+	case 'X':
+	    break;
+
+	case 'e':
+	case 'f':
+	case 'g':
+	    nas[ cn ].type = TYPE_DOUBLE;
+	    break;
+
+	case 'p':
+	    /* XXX should use cpp */
+	    if (sizeof(void *) == sizeof(PRInt32)) {
+		nas[ cn ].type = TYPE_UINT32;
+	    } else if (sizeof(void *) == sizeof(PRInt64)) {
+	        nas[ cn ].type = TYPE_UINT64;
+	    } else if (sizeof(void *) == sizeof(PRIntn)) {
+	        nas[ cn ].type = TYPE_UINTN;
+	    } else {
+	        nas[ cn ].type = TYPE_UNKNOWN;
+	    }
+	    break;
+
+	case 'S':
+#ifdef WIN32
+	    nas[ cn ].type = TYPE_WSTRING;
+	    break;
+#endif
+	case 'C':
+	case 'E':
+	case 'G':
+	    /* XXX not supported I suppose */
+	    PR_ASSERT(0);
+	    nas[ cn ].type = TYPE_UNKNOWN;
+	    break;
+
+	case 's':
+	    nas[ cn ].type = TYPE_STRING;
+	    break;
+
+	case 'n':
+	    nas[ cn ].type = TYPE_INTSTR;
+	    break;
+
+	default:
+	    PR_ASSERT(0);
+	    nas[ cn ].type = TYPE_UNKNOWN;
+	    break;
+	}
+
+	/* get a legal para. */
+	if( nas[ cn ].type == TYPE_UNKNOWN ){
+	    *rv = -1;
+	    break;
+	}
+    }
+
+
+    /*
+    ** third pass
+    ** fill the nas[cn].ap
+    */
+
+    if( *rv < 0 ){
+	if( nas != nasArray )
+	    PR_DELETE( nas );
+	return NULL;
+    }
+
+    cn = 0;
+    while( cn < number ){
+	if( nas[cn].type == TYPE_UNKNOWN ){
+	    cn++;
+	    continue;
+	}
+
+	switch( nas[cn].type ){
+	case TYPE_INT16:
+	case TYPE_UINT16:
+	case TYPE_INTN:
+	    nas[cn].u.i = va_arg( ap, int );
+	    break;
+
+	case TYPE_UINTN:
+	    nas[cn].u.ui = va_arg( ap, unsigned int );
+	    break;
+
+	case TYPE_INT32:
+	    nas[cn].u.i32 = va_arg( ap, PRInt32 );
+	    break;
+
+	case TYPE_UINT32:
+	    nas[cn].u.ui32 = va_arg( ap, PRUint32 );
+	    break;
+
+	case TYPE_INT64:
+	    nas[cn].u.ll = va_arg( ap, PRInt64 );
+	    break;
+
+	case TYPE_UINT64:
+	    nas[cn].u.ull = va_arg( ap, PRUint64 );
+	    break;
+
+	case TYPE_STRING:
+	    nas[cn].u.s = va_arg( ap, char* );
+	    break;
+
+#ifdef WIN32
+	case TYPE_WSTRING:
+	    nas[cn].u.ws = va_arg( ap, WCHAR* );
+	    break;
+#endif
+
+	case TYPE_INTSTR:
+	    nas[cn].u.ip = va_arg( ap, int* );
+	    break;
+
+	case TYPE_DOUBLE:
+	    nas[cn].u.d = va_arg( ap, double );
+	    break;
+
+	default:
+	    if( nas != nasArray )
+		PR_DELETE( nas );
+	    *rv = -1;
+	    return NULL;
+	}
+
+	cn++;
+    }
+
+
+    return nas;
+}
+
+/*
+** The workhorse sprintf code.
+*/
+static int dosprintf(SprintfState *ss, const char *fmt, va_list ap)
+{
+    char c;
+    int flags, width, prec, radix, type;
+    union {
+	char ch;
+	int i;
+	long l;
+	PRInt64 ll;
+	double d;
+	const char *s;
+	int *ip;
+#ifdef WIN32
+	const WCHAR *ws;
+#endif
+    } u;
+    const char *fmt0;
+    static char *hex = "0123456789abcdef";
+    static char *HEX = "0123456789ABCDEF";
+    char *hexp;
+    int rv, i;
+    struct NumArg* nas = NULL;
+    struct NumArg* nap = NULL;
+    struct NumArg  nasArray[ NAS_DEFAULT_NUM ];
+    char  pattern[20];
+    const char* dolPt = NULL;  /* in "%4$.2f", dolPt will point to . */
+#ifdef WIN32
+    char *pBuf = NULL;
+#endif
+
+    /*
+    ** build an argument array, IF the fmt is numbered argument
+    ** list style, to contain the Numbered Argument list pointers
+    */
+
+    nas = BuildArgArray( fmt, ap, &rv, nasArray );
+    if( rv < 0 ){
+	/* the fmt contains error Numbered Argument format, jliu@netscape.com */
+	PR_ASSERT(0);
+	return rv;
+    }
+
+    while ((c = *fmt++) != 0) {
+	if (c != '%') {
+	    rv = (*ss->stuff)(ss, fmt - 1, 1);
+	    if (rv < 0) {
+		return rv;
+	    }
+	    continue;
+	}
+	fmt0 = fmt - 1;
+
+	/*
+	** Gobble up the % format string. Hopefully we have handled all
+	** of the strange cases!
+	*/
+	flags = 0;
+	c = *fmt++;
+	if (c == '%') {
+	    /* quoting a % with %% */
+	    rv = (*ss->stuff)(ss, fmt - 1, 1);
+	    if (rv < 0) {
+		return rv;
+	    }
+	    continue;
+	}
+
+	if( nas != NULL ){
+	    /* the fmt contains the Numbered Arguments feature */
+	    i = 0;
+	    while( c && c != '$' ){	    /* should improve error check later */
+		i = ( i * 10 ) + ( c - '0' );
+		c = *fmt++;
+	    }
+
+	    if( nas[i-1].type == TYPE_UNKNOWN ){
+		if( nas && ( nas != nasArray ) )
+		    PR_DELETE( nas );
+		return -1;
+	    }
+
+	    nap = &nas[i-1];
+	    dolPt = fmt;
+	    c = *fmt++;
+	}
+
+	/*
+	 * Examine optional flags.  Note that we do not implement the
+	 * '#' flag of sprintf().  The ANSI C spec. of the '#' flag is
+	 * somewhat ambiguous and not ideal, which is perhaps why
+	 * the various sprintf() implementations are inconsistent
+	 * on this feature.
+	 */
+	while ((c == '-') || (c == '+') || (c == ' ') || (c == '0')) {
+	    if (c == '-') flags |= FLAG_LEFT;
+	    if (c == '+') flags |= FLAG_SIGNED;
+	    if (c == ' ') flags |= FLAG_SPACED;
+	    if (c == '0') flags |= FLAG_ZEROS;
+	    c = *fmt++;
+	}
+	if (flags & FLAG_SIGNED) flags &= ~FLAG_SPACED;
+	if (flags & FLAG_LEFT) flags &= ~FLAG_ZEROS;
+
+	/* width */
+	if (c == '*') {
+	    c = *fmt++;
+	    width = va_arg(ap, int);
+	} else {
+	    width = 0;
+	    while ((c >= '0') && (c <= '9')) {
+		width = (width * 10) + (c - '0');
+		c = *fmt++;
+	    }
+	}
+
+	/* precision */
+	prec = -1;
+	if (c == '.') {
+	    c = *fmt++;
+	    if (c == '*') {
+		c = *fmt++;
+		prec = va_arg(ap, int);
+	    } else {
+		prec = 0;
+		while ((c >= '0') && (c <= '9')) {
+		    prec = (prec * 10) + (c - '0');
+		    c = *fmt++;
+		}
+	    }
+	}
+
+	/* size */
+	type = TYPE_INTN;
+	if (c == 'h') {
+	    type = TYPE_INT16;
+	    c = *fmt++;
+	} else if (c == 'L') {
+	    /* XXX not quite sure here */
+	    type = TYPE_INT64;
+	    c = *fmt++;
+	} else if (c == 'l') {
+	    type = TYPE_INT32;
+	    c = *fmt++;
+	    if (c == 'l') {
+		type = TYPE_INT64;
+		c = *fmt++;
+	    }
+	} else if (c == 'z') {
+	    if (sizeof(size_t) == sizeof(PRInt32)) {
+	    	type = TYPE_INT32;
+	    } else if (sizeof(size_t) == sizeof(PRInt64)) {
+	    	type = TYPE_INT64;
+	    }
+	    c = *fmt++;
+	}
+
+	/* format */
+	hexp = hex;
+	switch (c) {
+	  case 'd': case 'i':			/* decimal/integer */
+	    radix = 10;
+	    goto fetch_and_convert;
+
+	  case 'o':				/* octal */
+	    radix = 8;
+	    type |= 1;
+	    goto fetch_and_convert;
+
+	  case 'u':				/* unsigned decimal */
+	    radix = 10;
+	    type |= 1;
+	    goto fetch_and_convert;
+
+	  case 'x':				/* unsigned hex */
+	    radix = 16;
+	    type |= 1;
+	    goto fetch_and_convert;
+
+	  case 'X':				/* unsigned HEX */
+	    radix = 16;
+	    hexp = HEX;
+	    type |= 1;
+	    goto fetch_and_convert;
+
+	  fetch_and_convert:
+	    switch (type) {
+	      case TYPE_INT16:
+		u.l = nas ? nap->u.i : va_arg(ap, int);
+		if (u.l < 0) {
+		    u.l = -u.l;
+		    flags |= FLAG_NEG;
+		}
+		goto do_long;
+	      case TYPE_UINT16:
+		u.l = (nas ? nap->u.i : va_arg(ap, int)) & 0xffff;
+		goto do_long;
+	      case TYPE_INTN:
+		u.l = nas ? nap->u.i : va_arg(ap, int);
+		if (u.l < 0) {
+		    u.l = -u.l;
+		    flags |= FLAG_NEG;
+		}
+		goto do_long;
+	      case TYPE_UINTN:
+		u.l = (long)(nas ? nap->u.ui : va_arg(ap, unsigned int));
+		goto do_long;
+
+	      case TYPE_INT32:
+		u.l = nas ? nap->u.i32 : va_arg(ap, PRInt32);
+		if (u.l < 0) {
+		    u.l = -u.l;
+		    flags |= FLAG_NEG;
+		}
+		goto do_long;
+	      case TYPE_UINT32:
+		u.l = (long)(nas ? nap->u.ui32 : va_arg(ap, PRUint32));
+	      do_long:
+		rv = cvt_l(ss, u.l, width, prec, radix, type, flags, hexp);
+		if (rv < 0) {
+		    return rv;
+		}
+		break;
+
+	      case TYPE_INT64:
+		u.ll = nas ? nap->u.ll : va_arg(ap, PRInt64);
+		if (!LL_GE_ZERO(u.ll)) {
+		    LL_NEG(u.ll, u.ll);
+		    flags |= FLAG_NEG;
+		}
+		goto do_longlong;
+	      case TYPE_UINT64:
+		u.ll = nas ? nap->u.ull : va_arg(ap, PRUint64);
+	      do_longlong:
+		rv = cvt_ll(ss, u.ll, width, prec, radix, type, flags, hexp);
+		if (rv < 0) {
+		    return rv;
+		}
+		break;
+	    }
+	    break;
+
+	  case 'e':
+	  case 'E':
+	  case 'f':
+	  case 'g':
+	    u.d = nas ? nap->u.d : va_arg(ap, double);
+	    if( nas != NULL ){
+		i = fmt - dolPt;
+		if( i < sizeof( pattern ) ){
+		    pattern[0] = '%';
+		    memcpy( &pattern[1], dolPt, i );
+		    rv = cvt_f(ss, u.d, pattern, &pattern[i+1] );
+		}
+	    } else
+		rv = cvt_f(ss, u.d, fmt0, fmt);
+
+	    if (rv < 0) {
+		return rv;
+	    }
+	    break;
+
+	  case 'c':
+	    u.ch = nas ? nap->u.i : va_arg(ap, int);
+            if ((flags & FLAG_LEFT) == 0) {
+                while (width-- > 1) {
+                    rv = (*ss->stuff)(ss, " ", 1);
+                    if (rv < 0) {
+                        return rv;
+                    }
+                }
+            }
+	    rv = (*ss->stuff)(ss, &u.ch, 1);
+	    if (rv < 0) {
+		return rv;
+	    }
+            if (flags & FLAG_LEFT) {
+                while (width-- > 1) {
+                    rv = (*ss->stuff)(ss, " ", 1);
+                    if (rv < 0) {
+                        return rv;
+                    }
+                }
+            }
+	    break;
+
+	  case 'p':
+	    if (sizeof(void *) == sizeof(PRInt32)) {
+	    	type = TYPE_UINT32;
+	    } else if (sizeof(void *) == sizeof(PRInt64)) {
+	    	type = TYPE_UINT64;
+	    } else if (sizeof(void *) == sizeof(int)) {
+		type = TYPE_UINTN;
+	    } else {
+		PR_ASSERT(0);
+		break;
+	    }
+	    radix = 16;
+	    goto fetch_and_convert;
+
+#ifndef WIN32
+	  case 'S':
+	    /* XXX not supported I suppose */
+	    PR_ASSERT(0);
+	    break;
+#endif
+
+#if 0
+	  case 'C':
+	  case 'E':
+	  case 'G':
+	    /* XXX not supported I suppose */
+	    PR_ASSERT(0);
+	    break;
+#endif
+
+#ifdef WIN32
+	  case 'S':
+	    u.ws = nas ? nap->u.ws : va_arg(ap, const WCHAR*);
+
+	    /* Get the required size in rv */
+	    rv = WideCharToMultiByte(CP_ACP, 0, u.ws, -1, NULL, 0, NULL, NULL);
+	    if (rv == 0)
+		rv = 1;
+	    pBuf = PR_MALLOC(rv);
+	    WideCharToMultiByte(CP_ACP, 0, u.ws, -1, pBuf, (int)rv, NULL, NULL);
+	    pBuf[rv-1] = '\0';
+
+	    rv = cvt_s(ss, pBuf, width, prec, flags);
+
+	    /* We don't need the allocated buffer anymore */
+	    PR_Free(pBuf);
+	    if (rv < 0) {
+		return rv;
+	    }
+	    break;
+
+#endif
+
+	  case 's':
+	    u.s = nas ? nap->u.s : va_arg(ap, const char*);
+	    rv = cvt_s(ss, u.s, width, prec, flags);
+	    if (rv < 0) {
+		return rv;
+	    }
+	    break;
+
+	  case 'n':
+	    u.ip = nas ? nap->u.ip : va_arg(ap, int*);
+	    if (u.ip) {
+		*u.ip = ss->cur - ss->base;
+	    }
+	    break;
+
+	  default:
+	    /* Not a % token after all... skip it */
+#if 0
+	    PR_ASSERT(0);
+#endif
+	    rv = (*ss->stuff)(ss, "%", 1);
+	    if (rv < 0) {
+		return rv;
+	    }
+	    rv = (*ss->stuff)(ss, fmt - 1, 1);
+	    if (rv < 0) {
+		return rv;
+	    }
+	}
+    }
+
+    /* Stuff trailing NUL */
+    rv = (*ss->stuff)(ss, "\0", 1);
+
+    if( nas && ( nas != nasArray ) ){
+	PR_DELETE( nas );
+    }
+
+    return rv;
+}
+
+/************************************************************************/
+
+static int FuncStuff(SprintfState *ss, const char *sp, PRUint32 len)
+{
+    int rv;
+
+    /*
+    ** We will add len to ss->maxlen at the end of the function. First check
+    ** if ss->maxlen + len would overflow or be greater than PR_INT32_MAX.
+    */
+    if (PR_UINT32_MAX - ss->maxlen < len || ss->maxlen + len > PR_INT32_MAX) {
+	return -1;
+    }
+    rv = (*ss->func)(ss->arg, sp, len);
+    if (rv < 0) {
+	return rv;
+    }
+    ss->maxlen += len;
+    return 0;
+}
+
+PR_IMPLEMENT(PRUint32) PR_sxprintf(PRStuffFunc func, void *arg, 
+                                 const char *fmt, ...)
+{
+    va_list ap;
+    PRUint32 rv;
+
+    va_start(ap, fmt);
+    rv = PR_vsxprintf(func, arg, fmt, ap);
+    va_end(ap);
+    return rv;
+}
+
+PR_IMPLEMENT(PRUint32) PR_vsxprintf(PRStuffFunc func, void *arg, 
+                                  const char *fmt, va_list ap)
+{
+    SprintfState ss;
+    int rv;
+
+    ss.stuff = FuncStuff;
+    ss.func = func;
+    ss.arg = arg;
+    ss.maxlen = 0;
+    rv = dosprintf(&ss, fmt, ap);
+    return (rv < 0) ? (PRUint32)-1 : ss.maxlen;
+}
+
+/*
+** Stuff routine that automatically grows the malloc'd output buffer
+** before it overflows.
+*/
+static int GrowStuff(SprintfState *ss, const char *sp, PRUint32 len)
+{
+    ptrdiff_t off;
+    char *newbase;
+    PRUint32 newlen;
+
+    off = ss->cur - ss->base;
+    if (PR_UINT32_MAX - len < off) {
+	/* off + len would be too big. */
+	return -1;
+    }
+    if (off + len >= ss->maxlen) {
+	/* Grow the buffer */
+	PRUint32 increment = (len > 32) ? len : 32;
+	if (PR_UINT32_MAX - ss->maxlen < increment) {
+	    /* ss->maxlen + increment would overflow. */
+	    return -1;
+	}
+	newlen = ss->maxlen + increment;
+	if (newlen > PR_INT32_MAX) {
+	    return -1;
+	}
+	if (ss->base) {
+	    newbase = (char*) PR_REALLOC(ss->base, newlen);
+	} else {
+	    newbase = (char*) PR_MALLOC(newlen);
+	}
+	if (!newbase) {
+	    /* Ran out of memory */
+	    return -1;
+	}
+	ss->base = newbase;
+	ss->maxlen = newlen;
+	ss->cur = ss->base + off;
+    }
+
+    /* Copy data */
+    while (len) {
+	--len;
+	*ss->cur++ = *sp++;
+    }
+    PR_ASSERT((PRUint32)(ss->cur - ss->base) <= ss->maxlen);
+    return 0;
+}
+
+/*
+** sprintf into a malloc'd buffer
+*/
+PR_IMPLEMENT(char *) PR_smprintf(const char *fmt, ...)
+{
+    va_list ap;
+    char *rv;
+
+    va_start(ap, fmt);
+    rv = PR_vsmprintf(fmt, ap);
+    va_end(ap);
+    return rv;
+}
+
+/*
+** Free memory allocated, for the caller, by PR_smprintf
+*/
+PR_IMPLEMENT(void) PR_smprintf_free(char *mem)
+{
+	PR_DELETE(mem);
+}
+
+PR_IMPLEMENT(char *) PR_vsmprintf(const char *fmt, va_list ap)
+{
+    SprintfState ss;
+    int rv;
+
+    ss.stuff = GrowStuff;
+    ss.base = 0;
+    ss.cur = 0;
+    ss.maxlen = 0;
+    rv = dosprintf(&ss, fmt, ap);
+    if (rv < 0) {
+	if (ss.base) {
+	    PR_DELETE(ss.base);
+	}
+	return 0;
+    }
+    return ss.base;
+}
+
+/*
+** Stuff routine that discards overflow data
+*/
+static int LimitStuff(SprintfState *ss, const char *sp, PRUint32 len)
+{
+    PRUint32 limit = ss->maxlen - (ss->cur - ss->base);
+
+    if (len > limit) {
+	len = limit;
+    }
+    while (len) {
+	--len;
+	*ss->cur++ = *sp++;
+    }
+    return 0;
+}
+
+/*
+** sprintf into a fixed size buffer. Make sure there is a NUL at the end
+** when finished.
+*/
+PR_IMPLEMENT(PRUint32) PR_snprintf(char *out, PRUint32 outlen, const char *fmt, ...)
+{
+    va_list ap;
+    PRUint32 rv;
+
+    va_start(ap, fmt);
+    rv = PR_vsnprintf(out, outlen, fmt, ap);
+    va_end(ap);
+    return rv;
+}
+
+PR_IMPLEMENT(PRUint32) PR_vsnprintf(char *out, PRUint32 outlen,const char *fmt,
+                                  va_list ap)
+{
+    SprintfState ss;
+    PRUint32 n;
+
+    PR_ASSERT(outlen != 0 && outlen <= PR_INT32_MAX);
+    if (outlen == 0 || outlen > PR_INT32_MAX) {
+	return 0;
+    }
+
+    ss.stuff = LimitStuff;
+    ss.base = out;
+    ss.cur = out;
+    ss.maxlen = outlen;
+    (void) dosprintf(&ss, fmt, ap);
+
+    /* If we added chars, and we didn't append a null, do it now. */
+    if( (ss.cur != ss.base) && (*(ss.cur - 1) != '\0') )
+        *(ss.cur - 1) = '\0';
+
+    n = ss.cur - ss.base;
+    return n ? n - 1 : n;
+}
+
+PR_IMPLEMENT(char *) PR_sprintf_append(char *last, const char *fmt, ...)
+{
+    va_list ap;
+    char *rv;
+
+    va_start(ap, fmt);
+    rv = PR_vsprintf_append(last, fmt, ap);
+    va_end(ap);
+    return rv;
+}
+
+PR_IMPLEMENT(char *) PR_vsprintf_append(char *last, const char *fmt, va_list ap)
+{
+    SprintfState ss;
+    int rv;
+
+    ss.stuff = GrowStuff;
+    if (last) {
+	size_t lastlen = strlen(last);
+	if (lastlen > PR_INT32_MAX) {
+	    return 0;
+	}
+	ss.base = last;
+	ss.cur = last + lastlen;
+	ss.maxlen = lastlen;
+    } else {
+	ss.base = 0;
+	ss.cur = 0;
+	ss.maxlen = 0;
+    }
+    rv = dosprintf(&ss, fmt, ap);
+    if (rv < 0) {
+	if (ss.base) {
+	    PR_DELETE(ss.base);
+	}
+	return 0;
+    }
+    return ss.base;
+}
+
diff --git a/pr/src/io/prscanf.c b/pr/src/io/prscanf.c
new file mode 100644
index 0000000..9d75d82
--- /dev/null
+++ b/pr/src/io/prscanf.c
@@ -0,0 +1,634 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/*
+ * Scan functions for NSPR types
+ *
+ * Author: Wan-Teh Chang
+ *
+ * Acknowledgment: The implementation is inspired by the source code
+ * in P.J. Plauger's "The Standard C Library," Prentice-Hall, 1992.
+ */
+
+#include <limits.h>
+#include <ctype.h>
+#include <string.h>
+#include <stdlib.h>
+#include "prprf.h"
+#include "prdtoa.h"
+#include "prlog.h"
+#include "prerror.h"
+
+/*
+ * A function that reads a character from 'stream'.
+ * Returns the character read, or EOF if end of stream is reached.
+ */
+typedef int (*_PRGetCharFN)(void *stream);
+
+/*
+ * A function that pushes the character 'ch' back to 'stream'.
+ */
+typedef void (*_PRUngetCharFN)(void *stream, int ch); 
+
+/*
+ * The size specifier for the integer and floating point number
+ * conversions in format control strings.
+ */
+typedef enum {
+    _PR_size_none,  /* No size specifier is given */
+    _PR_size_h,     /* The 'h' specifier, suggesting "short" */
+    _PR_size_l,     /* The 'l' specifier, suggesting "long" */
+    _PR_size_L,     /* The 'L' specifier, meaning a 'long double' */
+    _PR_size_ll     /* The 'll' specifier, suggesting "long long" */
+} _PRSizeSpec;
+
+/*
+ * The collection of data that is passed between the scan function
+ * and its subordinate functions.  The fields of this structure
+ * serve as the input or output arguments for these functions.
+ */
+typedef struct {
+    _PRGetCharFN get;        /* get a character from input stream */
+    _PRUngetCharFN unget;    /* unget (push back) a character */
+    void *stream;            /* argument for get and unget */
+    va_list ap;              /* the variable argument list */
+    int nChar;               /* number of characters read from 'stream' */
+
+    PRBool assign;           /* assign, or suppress assignment? */
+    int width;               /* field width */
+    _PRSizeSpec sizeSpec;    /* 'h', 'l', 'L', or 'll' */
+
+    PRBool converted;        /* is the value actually converted? */
+} ScanfState;
+
+#define GET(state) ((state)->nChar++, (state)->get((state)->stream))
+#define UNGET(state, ch) \
+        ((state)->nChar--, (state)->unget((state)->stream, ch))
+
+/*
+ * The following two macros, GET_IF_WITHIN_WIDTH and WITHIN_WIDTH,
+ * are always used together.
+ *
+ * GET_IF_WITHIN_WIDTH calls the GET macro and assigns its return
+ * value to 'ch' only if we have not exceeded the field width of
+ * 'state'.  Therefore, after GET_IF_WITHIN_WIDTH, the value of
+ * 'ch' is valid only if the macro WITHIN_WIDTH evaluates to true.
+ */
+
+#define GET_IF_WITHIN_WIDTH(state, ch) \
+        if (--(state)->width >= 0) { \
+            (ch) = GET(state); \
+        }
+#define WITHIN_WIDTH(state) ((state)->width >= 0)
+
+/*
+ * _pr_strtoull:
+ *     Convert a string to an unsigned 64-bit integer.  The string
+ *     'str' is assumed to be a representation of the integer in
+ *     base 'base'.
+ *
+ * Warning: 
+ *     - Only handle base 8, 10, and 16.
+ *     - No overflow checking.
+ */
+
+static PRUint64
+_pr_strtoull(const char *str, char **endptr, int base)
+{
+    static const int BASE_MAX = 16;
+    static const char digits[] = "0123456789abcdef";
+    char *digitPtr;
+    PRUint64 x;    /* return value */
+    PRInt64 base64;
+    const char *cPtr;
+    PRBool negative;
+    const char *digitStart;
+
+    PR_ASSERT(base == 0 || base == 8 || base == 10 || base == 16);
+    if (base < 0 || base == 1 || base > BASE_MAX) {
+        if (endptr) {
+            *endptr = (char *) str;
+            return LL_ZERO;
+        }
+    }
+
+    cPtr = str;
+    while (isspace(*cPtr)) {
+        ++cPtr;
+    }
+
+    negative = PR_FALSE;
+    if (*cPtr == '-') {
+        negative = PR_TRUE;
+        cPtr++;
+    } else if (*cPtr == '+') {
+        cPtr++;
+    }
+
+    if (base == 16) {
+        if (*cPtr == '0' && (cPtr[1] == 'x' || cPtr[1] == 'X')) {
+            cPtr += 2;
+        }
+    } else if (base == 0) {
+        if (*cPtr != '0') {
+            base = 10;
+        } else if (cPtr[1] == 'x' || cPtr[1] == 'X') {
+            base = 16;
+            cPtr += 2;
+        } else {
+            base = 8;
+        } 
+    }
+    PR_ASSERT(base != 0);
+    LL_I2L(base64, base);
+    digitStart = cPtr;
+
+    /* Skip leading zeros */
+    while (*cPtr == '0') {
+        cPtr++;
+    }
+
+    LL_I2L(x, 0);
+    while ((digitPtr = (char*)memchr(digits, tolower(*cPtr), base)) != NULL) {
+        PRUint64 d;
+
+        LL_I2L(d, (digitPtr - digits));
+        LL_MUL(x, x, base64);
+        LL_ADD(x, x, d);
+        cPtr++;
+    }
+
+    if (cPtr == digitStart) {
+        if (endptr) {
+            *endptr = (char *) str;
+        }
+        return LL_ZERO;
+    }
+
+    if (negative) {
+#ifdef HAVE_LONG_LONG
+        /* The cast to a signed type is to avoid a compiler warning */
+        x = -(PRInt64)x;
+#else
+        LL_NEG(x, x);
+#endif
+    }
+
+    if (endptr) {
+        *endptr = (char *) cPtr;
+    }
+    return x;
+}
+
+/*
+ * The maximum field width (in number of characters) that is enough
+ * (may be more than necessary) to represent a 64-bit integer or
+ * floating point number.
+ */
+#define FMAX 31
+#define DECIMAL_POINT '.'
+
+static PRStatus
+GetInt(ScanfState *state, int code)
+{
+    char buf[FMAX + 1], *p;
+    int ch = 0;
+    static const char digits[] = "0123456789abcdefABCDEF";
+    PRBool seenDigit = PR_FALSE;
+    int base;
+    int dlen;
+
+    switch (code) {
+        case 'd': case 'u':
+            base = 10;
+            break;
+        case 'i':
+            base = 0;
+            break;
+        case 'x': case 'X': case 'p':
+            base = 16;
+            break;
+        case 'o':
+            base = 8;
+            break;
+        default:
+            return PR_FAILURE;
+    }
+    if (state->width == 0 || state->width > FMAX) {
+        state->width = FMAX;
+    }
+    p = buf;
+    GET_IF_WITHIN_WIDTH(state, ch);
+    if (WITHIN_WIDTH(state) && (ch == '+' || ch == '-')) {
+        *p++ = ch;
+        GET_IF_WITHIN_WIDTH(state, ch);
+    }
+    if (WITHIN_WIDTH(state) && ch == '0') {
+        seenDigit = PR_TRUE;
+        *p++ = ch;
+        GET_IF_WITHIN_WIDTH(state, ch);
+        if (WITHIN_WIDTH(state)
+                && (ch == 'x' || ch == 'X')
+                && (base == 0 || base == 16)) {
+            base = 16;
+            *p++ = ch;
+            GET_IF_WITHIN_WIDTH(state, ch);
+        } else if (base == 0) {
+            base = 8;
+        }
+    }
+    if (base == 0 || base == 10) {
+        dlen = 10;
+    } else if (base == 8) {
+        dlen = 8;
+    } else {
+        PR_ASSERT(base == 16);
+        dlen = 16 + 6; /* 16 digits, plus 6 in uppercase */
+    }
+    while (WITHIN_WIDTH(state) && memchr(digits, ch, dlen)) {
+        *p++ = ch;
+        GET_IF_WITHIN_WIDTH(state, ch);
+        seenDigit = PR_TRUE;
+    }
+    if (WITHIN_WIDTH(state)) {
+        UNGET(state, ch);
+    }
+    if (!seenDigit) {
+        return PR_FAILURE;
+    }
+    *p = '\0';
+    if (state->assign) {
+        if (code == 'd' || code == 'i') {
+            if (state->sizeSpec == _PR_size_ll) {
+                PRInt64 llval = _pr_strtoull(buf, NULL, base);
+                *va_arg(state->ap, PRInt64 *) = llval;
+            } else {
+                long lval = strtol(buf, NULL, base);
+
+                if (state->sizeSpec == _PR_size_none) {
+                    *va_arg(state->ap, PRIntn *) = lval;
+                } else if (state->sizeSpec == _PR_size_h) {
+                    *va_arg(state->ap, PRInt16 *) = (PRInt16)lval;
+                } else if (state->sizeSpec == _PR_size_l) {
+                    *va_arg(state->ap, PRInt32 *) = lval;
+                } else {
+                    return PR_FAILURE;
+                }
+            }
+        } else {
+            if (state->sizeSpec == _PR_size_ll) {
+                PRUint64 llval = _pr_strtoull(buf, NULL, base);
+                *va_arg(state->ap, PRUint64 *) = llval;
+            } else {
+                unsigned long lval = strtoul(buf, NULL, base);
+
+                if (state->sizeSpec == _PR_size_none) {
+                    *va_arg(state->ap, PRUintn *) = lval;
+                } else if (state->sizeSpec == _PR_size_h) {
+                    *va_arg(state->ap, PRUint16 *) = (PRUint16)lval;
+                } else if (state->sizeSpec == _PR_size_l) {
+                    *va_arg(state->ap, PRUint32 *) = lval;
+                } else {
+                    return PR_FAILURE;
+                }
+            }
+        }
+        state->converted = PR_TRUE;
+    }
+    return PR_SUCCESS;
+}
+
+static PRStatus
+GetFloat(ScanfState *state)
+{
+    char buf[FMAX + 1], *p;
+    int ch = 0;
+    PRBool seenDigit = PR_FALSE;
+
+    if (state->width == 0 || state->width > FMAX) {
+        state->width = FMAX;
+    }
+    p = buf;
+    GET_IF_WITHIN_WIDTH(state, ch);
+    if (WITHIN_WIDTH(state) && (ch == '+' || ch == '-')) {
+        *p++ = ch;
+        GET_IF_WITHIN_WIDTH(state, ch);
+    }
+    while (WITHIN_WIDTH(state) && isdigit(ch)) {
+        *p++ = ch;
+        GET_IF_WITHIN_WIDTH(state, ch);
+        seenDigit = PR_TRUE;
+    }
+    if (WITHIN_WIDTH(state) && ch == DECIMAL_POINT) {
+        *p++ = ch;
+        GET_IF_WITHIN_WIDTH(state, ch);
+        while (WITHIN_WIDTH(state) && isdigit(ch)) {
+            *p++ = ch;
+            GET_IF_WITHIN_WIDTH(state, ch);
+            seenDigit = PR_TRUE;
+        }
+    }
+
+    /*
+     * This is not robust.  For example, "1.2e+" would confuse
+     * the code below to read 'e' and '+', only to realize that
+     * it should have stopped at "1.2".  But we can't push back
+     * more than one character, so there is nothing I can do.
+     */
+
+    /* Parse exponent */
+    if (WITHIN_WIDTH(state) && (ch == 'e' || ch == 'E') && seenDigit) {
+        *p++ = ch;
+        GET_IF_WITHIN_WIDTH(state, ch);
+        if (WITHIN_WIDTH(state) && (ch == '+' || ch == '-')) {
+            *p++ = ch;
+            GET_IF_WITHIN_WIDTH(state, ch);
+        }
+        while (WITHIN_WIDTH(state) && isdigit(ch)) {
+            *p++ = ch;
+            GET_IF_WITHIN_WIDTH(state, ch);
+        }
+    }
+    if (WITHIN_WIDTH(state)) {
+        UNGET(state, ch);
+    }
+    if (!seenDigit) {
+        return PR_FAILURE;
+    }
+    *p = '\0';
+    if (state->assign) {
+        PRFloat64 dval = PR_strtod(buf, NULL);
+
+        state->converted = PR_TRUE;
+        if (state->sizeSpec == _PR_size_l) {
+            *va_arg(state->ap, PRFloat64 *) = dval;
+        } else if (state->sizeSpec == _PR_size_L) {
+#if defined(OSF1) || defined(IRIX)
+            *va_arg(state->ap, double *) = dval;
+#else
+            *va_arg(state->ap, long double *) = dval;
+#endif
+        } else {
+            *va_arg(state->ap, float *) = (float) dval;
+        }
+    }
+    return PR_SUCCESS;
+}
+
+/*
+ * Convert, and return the end of the conversion spec.
+ * Return NULL on error.
+ */
+
+static const char *
+Convert(ScanfState *state, const char *fmt)
+{
+    const char *cPtr;
+    int ch;
+    char *cArg = NULL;
+
+    state->converted = PR_FALSE;
+    cPtr = fmt;
+    if (*cPtr != 'c' && *cPtr != 'n' && *cPtr != '[') {
+        do {
+            ch = GET(state);
+        } while (isspace(ch));
+        UNGET(state, ch);
+    }
+    switch (*cPtr) {
+        case 'c':
+            if (state->assign) {
+                cArg = va_arg(state->ap, char *);
+            }
+            if (state->width == 0) {
+                state->width = 1;
+            }
+            for (; state->width > 0; state->width--) {
+                ch = GET(state);
+                if (ch == EOF) {
+                    return NULL;
+                } else if (state->assign) {
+                    *cArg++ = ch;
+                }
+            }
+            if (state->assign) {
+                state->converted = PR_TRUE;
+            }
+            break;
+        case 'p':
+        case 'd': case 'i': case 'o':
+        case 'u': case 'x': case 'X':
+            if (GetInt(state, *cPtr) == PR_FAILURE) {
+                return NULL;
+            }
+            break;
+        case 'e': case 'E': case 'f':
+        case 'g': case 'G':
+            if (GetFloat(state) == PR_FAILURE) {
+                return NULL;
+            }
+            break;
+        case 'n':
+            /* do not consume any input */
+            if (state->assign) {
+                switch (state->sizeSpec) {
+                    case _PR_size_none:
+                        *va_arg(state->ap, PRIntn *) = state->nChar;
+                        break;
+                    case _PR_size_h:
+                        *va_arg(state->ap, PRInt16 *) = state->nChar;
+                        break;
+                    case _PR_size_l:
+                        *va_arg(state->ap, PRInt32 *) = state->nChar;
+                        break;
+                    case _PR_size_ll:
+                        LL_I2L(*va_arg(state->ap, PRInt64 *), state->nChar);
+                        break;
+                    default:
+                        PR_ASSERT(0);
+                }
+            }
+            break;
+        case 's':
+            if (state->width == 0) {
+                state->width = INT_MAX;
+            }
+            if (state->assign) {
+                cArg = va_arg(state->ap, char *);
+            }
+            for (; state->width > 0; state->width--) {
+                ch = GET(state);
+                if ((ch == EOF) || isspace(ch)) {
+                    UNGET(state, ch);
+                    break;
+                }
+                if (state->assign) {
+                    *cArg++ = ch;
+                }
+            }
+            if (state->assign) {
+                *cArg = '\0';
+                state->converted = PR_TRUE;
+            }
+            break;
+        case '%':
+            ch = GET(state);
+            if (ch != '%') {
+                UNGET(state, ch);
+                return NULL;
+            }
+            break;
+        case '[':
+            {
+                PRBool complement = PR_FALSE;
+                const char *closeBracket;
+                size_t n;
+
+                if (*++cPtr == '^') {
+                    complement = PR_TRUE;
+                    cPtr++;
+                }
+                closeBracket = strchr(*cPtr == ']' ? cPtr + 1 : cPtr, ']');
+                if (closeBracket == NULL) {
+                    return NULL;
+                }
+                n = closeBracket - cPtr;
+                if (state->width == 0) {
+                    state->width = INT_MAX;
+                }
+                if (state->assign) {
+                    cArg = va_arg(state->ap, char *);
+                }
+                for (; state->width > 0; state->width--) {
+                    ch = GET(state);
+                    if ((ch == EOF) 
+                            || (!complement && !memchr(cPtr, ch, n))
+                            || (complement && memchr(cPtr, ch, n))) {
+                        UNGET(state, ch);
+                        break;
+                    }
+                    if (state->assign) {
+                        *cArg++ = ch;
+                    }
+                }
+                if (state->assign) {
+                    *cArg = '\0';
+                    state->converted = PR_TRUE;
+                }
+                cPtr = closeBracket;
+            }
+            break;
+        default:
+            return NULL;
+    }
+    return cPtr;
+}
+
+static PRInt32
+DoScanf(ScanfState *state, const char *fmt)
+{
+    PRInt32 nConverted = 0;
+    const char *cPtr;
+    int ch;
+
+    state->nChar = 0;
+    cPtr = fmt;
+    while (1) {
+        if (isspace(*cPtr)) {
+            /* white space: skip */
+            do {
+                cPtr++;
+            } while (isspace(*cPtr));
+            do {
+                ch = GET(state);
+            } while (isspace(ch));
+            UNGET(state, ch);
+        } else if (*cPtr == '%') {
+            /* format spec: convert */
+            cPtr++;
+            state->assign = PR_TRUE;
+            if (*cPtr == '*') {
+                cPtr++;
+                state->assign = PR_FALSE;
+            }
+            for (state->width = 0; isdigit(*cPtr); cPtr++) {
+                state->width = state->width * 10 + *cPtr - '0';
+            }
+            state->sizeSpec = _PR_size_none;
+            if (*cPtr == 'h') {
+                cPtr++;
+                state->sizeSpec = _PR_size_h;
+            } else if (*cPtr == 'l') {
+                cPtr++;
+                if (*cPtr == 'l') {
+                    cPtr++;
+                    state->sizeSpec = _PR_size_ll;
+                } else {
+                    state->sizeSpec = _PR_size_l;
+                }
+            } else if (*cPtr == 'L') {
+                cPtr++;
+                state->sizeSpec = _PR_size_L;
+            }
+            cPtr = Convert(state, cPtr);
+            if (cPtr == NULL) {
+                return (nConverted > 0 ? nConverted : EOF);
+            }
+            if (state->converted) {
+                nConverted++;
+            }
+            cPtr++;
+        } else {
+            /* others: must match */
+            if (*cPtr == '\0') {
+                return nConverted;
+            }
+            ch = GET(state);
+            if (ch != *cPtr) {
+                UNGET(state, ch);
+                return nConverted;
+            }
+            cPtr++;
+        }
+    }
+}
+
+static int
+StringGetChar(void *stream)
+{
+    char *cPtr = *((char **) stream);
+
+    if (*cPtr == '\0') {
+        return EOF;
+    } else {
+        *((char **) stream) = cPtr + 1;
+        return (unsigned char) *cPtr;
+    }
+}
+
+static void
+StringUngetChar(void *stream, int ch)
+{
+    char *cPtr = *((char **) stream);
+
+    if (ch != EOF) {
+        *((char **) stream) = cPtr - 1;
+    }
+}
+
+PR_IMPLEMENT(PRInt32)
+PR_sscanf(const char *buf, const char *fmt, ...)
+{
+    PRInt32 rv;
+    ScanfState state;
+
+    state.get = &StringGetChar;
+    state.unget = &StringUngetChar;
+    state.stream = (void *) &buf;
+    va_start(state.ap, fmt);
+    rv = DoScanf(&state, fmt);
+    va_end(state.ap);
+    return rv;
+}
diff --git a/pr/src/io/prsocket.c b/pr/src/io/prsocket.c
new file mode 100644
index 0000000..be97024
--- /dev/null
+++ b/pr/src/io/prsocket.c
@@ -0,0 +1,1794 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "primpl.h"
+
+#include <string.h>
+
+/************************************************************************/
+
+/* These two functions are only used in assertions. */
+#if defined(DEBUG)
+
+PRBool IsValidNetAddr(const PRNetAddr *addr)
+{
+    if ((addr != NULL)
+#if defined(XP_UNIX) || defined(XP_OS2)
+	    && (addr->raw.family != PR_AF_LOCAL)
+#endif
+	    && (addr->raw.family != PR_AF_INET6)
+	    && (addr->raw.family != PR_AF_INET)) {
+        return PR_FALSE;
+    }
+    return PR_TRUE;
+}
+
+static PRBool IsValidNetAddrLen(const PRNetAddr *addr, PRInt32 addr_len)
+{
+    /*
+     * The definition of the length of a Unix domain socket address
+     * is not uniform, so we don't check it.
+     */
+    if ((addr != NULL)
+#if defined(XP_UNIX) || defined(XP_OS2)
+            && (addr->raw.family != AF_UNIX)
+#endif
+            && (PR_NETADDR_SIZE(addr) != addr_len)) {
+#if defined(LINUX) && __GLIBC__ == 2 && __GLIBC_MINOR__ == 1
+        /*
+         * In glibc 2.1, struct sockaddr_in6 is 24 bytes.  In glibc 2.2
+         * and in the 2.4 kernel, struct sockaddr_in6 has the scope_id
+         * field and is 28 bytes.  It is possible for socket functions
+         * to return an addr_len greater than sizeof(struct sockaddr_in6).
+         * We need to allow that.  (Bugzilla bug #77264)
+         */
+        if ((PR_AF_INET6 == addr->raw.family)
+                && (sizeof(addr->ipv6) == addr_len)) {
+            return PR_TRUE;
+        }
+#endif
+        /*
+         * The accept(), getsockname(), etc. calls on some platforms
+         * do not set the actual socket address length on return.
+         * In this case, we verifiy addr_len is still the value we
+         * passed in (i.e., sizeof(PRNetAddr)).
+         */
+#if defined(QNX)
+        if (sizeof(PRNetAddr) == addr_len) {
+            return PR_TRUE;
+        }
+#endif
+        return PR_FALSE;
+    }
+    return PR_TRUE;
+}
+
+#endif /* DEBUG */
+
+static PRInt32 PR_CALLBACK SocketWritev(PRFileDesc *fd, const PRIOVec *iov,
+PRInt32 iov_size, PRIntervalTime timeout)
+{
+	PRThread *me = _PR_MD_CURRENT_THREAD();
+	int w = 0;
+	const PRIOVec *tmp_iov;
+#define LOCAL_MAXIOV    8
+	PRIOVec local_iov[LOCAL_MAXIOV];
+	PRIOVec *iov_copy = NULL;
+	int tmp_out;
+	int index, iov_cnt;
+	int count=0, sz = 0;    /* 'count' is the return value. */
+
+	if (_PR_PENDING_INTERRUPT(me)) {
+		me->flags &= ~_PR_INTERRUPT;
+		PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+		return -1;
+	}
+	if (_PR_IO_PENDING(me)) {
+		PR_SetError(PR_IO_PENDING_ERROR, 0);
+		return -1;
+	}
+
+    /*
+     * Assume the first writev will succeed.  Copy iov's only on
+     * failure.
+     */
+    tmp_iov = iov;
+    for (index = 0; index < iov_size; index++)
+        sz += iov[index].iov_len;
+
+	iov_cnt = iov_size;
+
+	while (sz > 0) {
+
+		w = _PR_MD_WRITEV(fd, tmp_iov, iov_cnt, timeout);
+		if (w < 0) {
+			count = -1;
+			break;
+		}
+		count += w;
+		if (fd->secret->nonblocking) {
+			break;
+		}
+		sz -= w;
+
+		if (sz > 0) {
+			/* find the next unwritten vector */
+			for ( index = 0, tmp_out = count;
+				tmp_out >= iov[index].iov_len;
+				tmp_out -= iov[index].iov_len, index++){;} /* nothing to execute */
+
+			if (tmp_iov == iov) {
+				/*
+				 * The first writev failed so we
+				 * must copy iov's around.
+				 * Avoid calloc/free if there
+				 * are few enough iov's.
+				 */
+				if (iov_size - index <= LOCAL_MAXIOV)
+					iov_copy = local_iov;
+				else if ((iov_copy = (PRIOVec *) PR_CALLOC((iov_size - index) *
+					sizeof *iov_copy)) == NULL) {
+					PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+					return -1;
+				}
+				tmp_iov = iov_copy;
+			}
+
+			PR_ASSERT(tmp_iov == iov_copy);
+
+			/* fill in the first partial read */
+			iov_copy[0].iov_base = &(((char *)iov[index].iov_base)[tmp_out]);
+			iov_copy[0].iov_len = iov[index].iov_len - tmp_out;
+			index++;
+
+			/* copy the remaining vectors */
+			for (iov_cnt=1; index<iov_size; iov_cnt++, index++) {
+				iov_copy[iov_cnt].iov_base = iov[index].iov_base;
+				iov_copy[iov_cnt].iov_len = iov[index].iov_len;
+			}
+		}
+	}
+
+	if (iov_copy != local_iov)
+		PR_DELETE(iov_copy);
+	return count;
+}
+
+/************************************************************************/
+
+PR_IMPLEMENT(PRFileDesc *) PR_ImportTCPSocket(PROsfd osfd)
+{
+PRFileDesc *fd;
+
+	if (!_pr_initialized) _PR_ImplicitInitialization();
+	fd = PR_AllocFileDesc(osfd, PR_GetTCPMethods());
+	if (fd != NULL) {
+		_PR_MD_MAKE_NONBLOCK(fd);
+		_PR_MD_INIT_FD_INHERITABLE(fd, PR_TRUE);
+#ifdef _PR_NEED_SECRET_AF
+		/* this means we can only import IPv4 sockets here.
+		 * but this is what the function in ptio.c does.
+		 * We need a way to import IPv6 sockets, too.
+		 */
+		fd->secret->af = AF_INET;
+#endif
+	} else
+		_PR_MD_CLOSE_SOCKET(osfd);
+	return(fd);
+}
+
+PR_IMPLEMENT(PRFileDesc *) PR_ImportUDPSocket(PROsfd osfd)
+{
+PRFileDesc *fd;
+
+	if (!_pr_initialized) _PR_ImplicitInitialization();
+	fd = PR_AllocFileDesc(osfd, PR_GetUDPMethods());
+	if (fd != NULL) {
+		_PR_MD_MAKE_NONBLOCK(fd);
+		_PR_MD_INIT_FD_INHERITABLE(fd, PR_TRUE);
+	} else
+		_PR_MD_CLOSE_SOCKET(osfd);
+	return(fd);
+}
+
+
+static const PRIOMethods* PR_GetSocketPollFdMethods(void);
+
+PR_IMPLEMENT(PRFileDesc*) PR_CreateSocketPollFd(PROsfd osfd)
+{
+    PRFileDesc *fd;
+
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+
+    fd = _PR_Getfd();
+
+    if (fd == NULL) PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+    else
+    {
+        fd->secret->md.osfd = osfd;
+        fd->secret->inheritable = _PR_TRI_FALSE;
+    	fd->secret->state = _PR_FILEDESC_OPEN;
+        fd->methods = PR_GetSocketPollFdMethods();
+    }
+
+    return fd;
+}  /* PR_CreateSocketPollFD */
+
+PR_IMPLEMENT(PRStatus) PR_DestroySocketPollFd(PRFileDesc *fd)
+{
+    if (NULL == fd)
+    {
+        PR_SetError(PR_BAD_DESCRIPTOR_ERROR, 0);
+        return PR_FAILURE;
+    }
+    fd->secret->state = _PR_FILEDESC_CLOSED;
+    _PR_Putfd(fd);
+    return PR_SUCCESS;
+}  /* PR_DestroySocketPollFd */
+
+static PRStatus PR_CALLBACK SocketConnect(
+    PRFileDesc *fd, const PRNetAddr *addr, PRIntervalTime timeout)
+{
+	PRInt32 rv;    /* Return value of _PR_MD_CONNECT */
+    const PRNetAddr *addrp = addr;
+#if defined(_PR_INET6)
+	PRNetAddr addrCopy;
+#endif
+	PRThread *me = _PR_MD_CURRENT_THREAD();
+
+	if (_PR_PENDING_INTERRUPT(me)) {
+		me->flags &= ~_PR_INTERRUPT;
+		PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+		return PR_FAILURE;
+	}
+#if defined(_PR_INET6)
+	if (addr->raw.family == PR_AF_INET6) {
+		addrCopy = *addr;
+		addrCopy.raw.family = AF_INET6;
+		addrp = &addrCopy;
+	}
+#endif
+
+	rv = _PR_MD_CONNECT(fd, addrp, PR_NETADDR_SIZE(addr), timeout);
+	PR_LOG(_pr_io_lm, PR_LOG_MAX, ("connect -> %d", rv));
+	if (rv == 0)
+		return PR_SUCCESS;
+	else
+		return PR_FAILURE;
+}
+
+static PRStatus PR_CALLBACK SocketConnectContinue(
+    PRFileDesc *fd, PRInt16 out_flags)
+{
+    PROsfd osfd;
+    int err;
+
+    if (out_flags & PR_POLL_NVAL) {
+        PR_SetError(PR_BAD_DESCRIPTOR_ERROR, 0);
+        return PR_FAILURE;
+    }
+    if ((out_flags & (PR_POLL_WRITE | PR_POLL_EXCEPT | PR_POLL_ERR)) == 0) {
+        PR_ASSERT(out_flags == 0);
+        PR_SetError(PR_IN_PROGRESS_ERROR, 0);
+        return PR_FAILURE;
+    }
+
+    osfd = fd->secret->md.osfd;
+
+#if defined(XP_UNIX)
+
+    err = _MD_unix_get_nonblocking_connect_error(osfd);
+    if (err != 0) {
+        _PR_MD_MAP_CONNECT_ERROR(err);
+        return PR_FAILURE;
+    }
+    return PR_SUCCESS;
+
+#elif defined(WIN32) || defined(WIN16)
+
+    if (out_flags & PR_POLL_EXCEPT) {
+        int len = sizeof(err);
+        if (getsockopt(osfd, (int)SOL_SOCKET, SO_ERROR, (char *) &err, &len)
+                == SOCKET_ERROR) {
+            _PR_MD_MAP_GETSOCKOPT_ERROR(WSAGetLastError());
+            return PR_FAILURE;
+        }
+        if (err != 0) {
+            _PR_MD_MAP_CONNECT_ERROR(err);
+        } else {
+            PR_SetError(PR_UNKNOWN_ERROR, 0);
+        }
+        return PR_FAILURE;
+    }
+
+    PR_ASSERT(out_flags & PR_POLL_WRITE);
+    return PR_SUCCESS;
+
+#elif defined(XP_OS2)
+
+    err = _MD_os2_get_nonblocking_connect_error(osfd);
+    if (err != 0) {
+        _PR_MD_MAP_CONNECT_ERROR(err);
+        return PR_FAILURE;
+    }
+    return PR_SUCCESS;
+
+#elif defined(XP_BEOS)
+
+#ifdef BONE_VERSION  /* bug 122364 */
+    /* temporary workaround until getsockopt(SO_ERROR) works in BONE */
+    if (out_flags & PR_POLL_EXCEPT) {
+        PR_SetError(PR_CONNECT_REFUSED_ERROR, 0);
+        return PR_FAILURE;
+    }
+    PR_ASSERT(out_flags & PR_POLL_WRITE);
+    return PR_SUCCESS;
+#else
+    err = _MD_beos_get_nonblocking_connect_error(fd);
+    if( err != 0 ) {
+        _PR_MD_MAP_CONNECT_ERROR(err);
+        return PR_FAILURE;
+    }
+    else
+        return PR_SUCCESS;
+#endif /* BONE_VERSION */
+
+#else
+    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+    return PR_FAILURE;
+#endif
+}
+
+PR_IMPLEMENT(PRStatus) PR_GetConnectStatus(const PRPollDesc *pd)
+{
+    /* Find the NSPR layer and invoke its connectcontinue method */
+    PRFileDesc *bottom = PR_GetIdentitiesLayer(pd->fd, PR_NSPR_IO_LAYER);
+
+    if (NULL == bottom) {
+        PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+        return PR_FAILURE;
+    }
+    return SocketConnectContinue(bottom, pd->out_flags);
+}
+
+static PRFileDesc* PR_CALLBACK SocketAccept(PRFileDesc *fd, PRNetAddr *addr,
+PRIntervalTime timeout)
+{
+	PROsfd osfd;
+	PRFileDesc *fd2;
+	PRUint32 al;
+	PRThread *me = _PR_MD_CURRENT_THREAD();
+#ifdef WINNT
+	PRNetAddr addrCopy;
+#endif
+
+	if (_PR_PENDING_INTERRUPT(me)) {
+		me->flags &= ~_PR_INTERRUPT;
+		PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+		return 0;
+	}
+	if (_PR_IO_PENDING(me)) {
+		PR_SetError(PR_IO_PENDING_ERROR, 0);
+		return 0;
+	}
+
+#ifdef WINNT
+	if (addr == NULL) {
+		addr = &addrCopy;
+	}
+#endif
+	al = sizeof(PRNetAddr);
+	osfd = _PR_MD_ACCEPT(fd, addr, &al, timeout);
+	if (osfd == -1)
+		return 0;
+
+	fd2 = PR_AllocFileDesc(osfd, PR_GetTCPMethods());
+	if (!fd2) {
+		_PR_MD_CLOSE_SOCKET(osfd);
+		return NULL;
+	}
+
+	fd2->secret->nonblocking = fd->secret->nonblocking;
+	fd2->secret->inheritable = fd->secret->inheritable;
+#ifdef WINNT
+	if (!fd2->secret->nonblocking && fd2->secret->inheritable != _PR_TRI_TRUE) {
+		/*
+		 * The new socket has been associated with an I/O
+		 * completion port.  There is no going back.
+		 */
+		fd2->secret->md.io_model_committed = PR_TRUE;
+	}
+	PR_ASSERT(al == PR_NETADDR_SIZE(addr));
+	fd2->secret->md.accepted_socket = PR_TRUE;
+	memcpy(&fd2->secret->md.peer_addr, addr, al);
+#endif
+
+	/*
+	 * On some platforms, the new socket created by accept()
+	 * inherits the nonblocking (or overlapped io) attribute
+	 * of the listening socket.  As an optimization, these
+	 * platforms can skip the following _PR_MD_MAKE_NONBLOCK
+	 * call.
+	 */
+#if !defined(SOLARIS) && !defined(IRIX) && !defined(WINNT)
+	_PR_MD_MAKE_NONBLOCK(fd2);
+#endif
+
+#ifdef _PR_INET6
+	if (addr && (AF_INET6 == addr->raw.family))
+        addr->raw.family = PR_AF_INET6;
+#endif
+	PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
+	PR_ASSERT(IsValidNetAddrLen(addr, al) == PR_TRUE);
+
+	return fd2;
+}
+
+#ifdef WINNT
+PR_IMPLEMENT(PRFileDesc*) PR_NTFast_Accept(PRFileDesc *fd, PRNetAddr *addr,
+PRIntervalTime timeout)
+{
+	PROsfd osfd;
+	PRFileDesc *fd2;
+	PRIntn al;
+	PRThread *me = _PR_MD_CURRENT_THREAD();
+	PRNetAddr addrCopy;
+
+	if (_PR_PENDING_INTERRUPT(me)) {
+		me->flags &= ~_PR_INTERRUPT;
+		PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+		return 0;
+	}
+	if (_PR_IO_PENDING(me)) {
+		PR_SetError(PR_IO_PENDING_ERROR, 0);
+		return 0;
+	}
+
+		if (addr == NULL) {
+			addr = &addrCopy;
+		}
+		al = PR_NETADDR_SIZE(addr);
+		osfd = _PR_MD_FAST_ACCEPT(fd, addr, &al, timeout, PR_TRUE, NULL, NULL);
+		if (osfd == -1) {
+			return 0;
+		}
+
+	fd2 = PR_AllocFileDesc(osfd, PR_GetTCPMethods());
+	if (!fd2) {
+		_PR_MD_CLOSE_SOCKET(osfd);
+	} else {
+		fd2->secret->nonblocking = fd->secret->nonblocking;
+		fd2->secret->md.io_model_committed = PR_TRUE;
+	        PR_ASSERT(al == PR_NETADDR_SIZE(addr));
+        	fd2->secret->md.accepted_socket = PR_TRUE;
+        	memcpy(&fd2->secret->md.peer_addr, addr, al);
+#ifdef _PR_INET6
+		if (AF_INET6 == addr->raw.family)
+        	addr->raw.family = PR_AF_INET6;
+#endif
+#ifdef _PR_NEED_SECRET_AF
+		fd2->secret->af = fd->secret->af;
+#endif
+	}
+	return fd2;
+}
+#endif /* WINNT */
+
+
+static PRStatus PR_CALLBACK SocketBind(PRFileDesc *fd, const PRNetAddr *addr)
+{
+	PRInt32 result;
+    const PRNetAddr *addrp = addr;
+#if defined(_PR_INET6)
+	PRNetAddr addrCopy;
+#endif
+
+	PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
+
+#ifdef XP_UNIX
+	if (addr->raw.family == AF_UNIX) {
+		/* Disallow relative pathnames */
+		if (addr->local.path[0] != '/') {
+			PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+			return PR_FAILURE;
+		}
+	}
+#endif /* XP_UNIX */
+
+#if defined(_PR_INET6)
+	if (addr->raw.family == PR_AF_INET6) {
+		addrCopy = *addr;
+		addrCopy.raw.family = AF_INET6;
+		addrp = &addrCopy;
+	}
+#endif
+	result = _PR_MD_BIND(fd, addrp, PR_NETADDR_SIZE(addr));
+	if (result < 0) {
+		return PR_FAILURE;
+	}
+	return PR_SUCCESS;
+}
+
+static PRStatus PR_CALLBACK SocketListen(PRFileDesc *fd, PRIntn backlog)
+{
+	PRInt32 result;
+
+	result = _PR_MD_LISTEN(fd, backlog);
+	if (result < 0) {
+		return PR_FAILURE;
+	}
+	return PR_SUCCESS;
+}
+
+static PRStatus PR_CALLBACK SocketShutdown(PRFileDesc *fd, PRIntn how)
+{
+	PRInt32 result;
+
+	result = _PR_MD_SHUTDOWN(fd, how);
+	if (result < 0) {
+		return PR_FAILURE;
+	}
+	return PR_SUCCESS;
+}
+
+static PRInt32 PR_CALLBACK SocketRecv(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
+PRIntervalTime timeout)
+{
+	PRInt32 rv;
+	PRThread *me = _PR_MD_CURRENT_THREAD();
+
+	if ((flags != 0) && (flags != PR_MSG_PEEK)) {
+		PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+		return -1;
+	}
+	if (_PR_PENDING_INTERRUPT(me)) {
+		me->flags &= ~_PR_INTERRUPT;
+		PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+		return -1;
+	}
+	if (_PR_IO_PENDING(me)) {
+		PR_SetError(PR_IO_PENDING_ERROR, 0);
+		return -1;
+	}
+
+	PR_LOG(_pr_io_lm, PR_LOG_MAX,
+		("recv: fd=%p osfd=%" PR_PRIdOSFD " buf=%p amount=%d flags=%d",
+		fd, fd->secret->md.osfd, buf, amount, flags));
+
+#ifdef _PR_HAVE_PEEK_BUFFER
+	if (fd->secret->peekBytes != 0) {
+		rv = (amount < fd->secret->peekBytes) ?
+			amount : fd->secret->peekBytes;
+		memcpy(buf, fd->secret->peekBuffer, rv);
+		if (flags == 0) {
+			/* consume the bytes in the peek buffer */
+			fd->secret->peekBytes -= rv;
+			if (fd->secret->peekBytes != 0) {
+				memmove(fd->secret->peekBuffer,
+					fd->secret->peekBuffer + rv,
+					fd->secret->peekBytes);
+			}
+		}
+		return rv;
+	}
+
+	/* allocate peek buffer, if necessary */
+	if ((PR_MSG_PEEK == flags) && _PR_FD_NEED_EMULATE_MSG_PEEK(fd)) {
+		PR_ASSERT(0 == fd->secret->peekBytes);
+		/* impose a max size on the peek buffer */
+		if (amount > _PR_PEEK_BUFFER_MAX) {
+			amount = _PR_PEEK_BUFFER_MAX;
+		}
+		if (fd->secret->peekBufSize < amount) {
+			if (fd->secret->peekBuffer) {
+				PR_Free(fd->secret->peekBuffer);
+			}
+			fd->secret->peekBufSize = amount;
+			fd->secret->peekBuffer = PR_Malloc(amount);
+			if (NULL == fd->secret->peekBuffer) {
+				fd->secret->peekBufSize = 0;
+				PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+				return -1;
+			}
+		}
+	}
+#endif
+
+	rv = _PR_MD_RECV(fd, buf, amount, flags, timeout);
+	PR_LOG(_pr_io_lm, PR_LOG_MAX, ("recv -> %d, error = %d, os error = %d",
+		rv, PR_GetError(), PR_GetOSError()));
+
+#ifdef _PR_HAVE_PEEK_BUFFER
+	if ((PR_MSG_PEEK == flags) && _PR_FD_NEED_EMULATE_MSG_PEEK(fd)) {
+		if (rv > 0) {
+			memcpy(fd->secret->peekBuffer, buf, rv);
+			fd->secret->peekBytes = rv;
+		}
+	}
+#endif
+
+	return rv;
+}
+
+static PRInt32 PR_CALLBACK SocketRead(PRFileDesc *fd, void *buf, PRInt32 amount)
+{
+	return SocketRecv(fd, buf, amount, 0, PR_INTERVAL_NO_TIMEOUT);
+}
+
+static PRInt32 PR_CALLBACK SocketSend(PRFileDesc *fd, const void *buf, PRInt32 amount,
+PRIntn flags, PRIntervalTime timeout)
+{
+	PRInt32 temp, count;
+	PRThread *me = _PR_MD_CURRENT_THREAD();
+
+	if (_PR_PENDING_INTERRUPT(me)) {
+		me->flags &= ~_PR_INTERRUPT;
+		PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+		return -1;
+	}
+	if (_PR_IO_PENDING(me)) {
+		PR_SetError(PR_IO_PENDING_ERROR, 0);
+		return -1;
+	}
+
+	count = 0;
+	while (amount > 0) {
+		PR_LOG(_pr_io_lm, PR_LOG_MAX,
+		    ("send: fd=%p osfd=%" PR_PRIdOSFD " buf=%p amount=%d",
+		    fd, fd->secret->md.osfd, buf, amount));
+		temp = _PR_MD_SEND(fd, buf, amount, flags, timeout);
+		if (temp < 0) {
+					count = -1;
+					break;
+				}
+
+		count += temp;
+		if (fd->secret->nonblocking) {
+			break;
+		}
+		buf = (const void*) ((const char*)buf + temp);
+
+		amount -= temp;
+	}
+	PR_LOG(_pr_io_lm, PR_LOG_MAX, ("send -> %d", count));
+	return count;
+}
+
+static PRInt32 PR_CALLBACK SocketWrite(PRFileDesc *fd, const void *buf, PRInt32 amount)
+{
+	return SocketSend(fd, buf, amount, 0, PR_INTERVAL_NO_TIMEOUT);
+}
+
+static PRStatus PR_CALLBACK SocketClose(PRFileDesc *fd)
+{
+	if (!fd || !fd->secret
+			|| (fd->secret->state != _PR_FILEDESC_OPEN
+			&& fd->secret->state != _PR_FILEDESC_CLOSED)) {
+		PR_SetError(PR_BAD_DESCRIPTOR_ERROR, 0);
+		return PR_FAILURE;
+	}
+
+	if (fd->secret->state == _PR_FILEDESC_OPEN) {
+		if (_PR_MD_CLOSE_SOCKET(fd->secret->md.osfd) < 0) {
+			return PR_FAILURE;
+		}
+		fd->secret->state = _PR_FILEDESC_CLOSED;
+	}
+
+#ifdef _PR_HAVE_PEEK_BUFFER
+	if (fd->secret->peekBuffer) {
+		PR_ASSERT(fd->secret->peekBufSize > 0);
+		PR_DELETE(fd->secret->peekBuffer);
+		fd->secret->peekBufSize = 0;
+		fd->secret->peekBytes = 0;
+	}
+#endif
+
+	PR_FreeFileDesc(fd);
+	return PR_SUCCESS;
+}
+
+static PRInt32 PR_CALLBACK SocketAvailable(PRFileDesc *fd)
+{
+	PRInt32 rv;
+#ifdef _PR_HAVE_PEEK_BUFFER
+	if (fd->secret->peekBytes != 0) {
+		return fd->secret->peekBytes;
+	}
+#endif
+	rv =  _PR_MD_SOCKETAVAILABLE(fd);
+	return rv;		
+}
+
+static PRInt64 PR_CALLBACK SocketAvailable64(PRFileDesc *fd)
+{
+    PRInt64 rv;
+#ifdef _PR_HAVE_PEEK_BUFFER
+    if (fd->secret->peekBytes != 0) {
+        LL_I2L(rv, fd->secret->peekBytes);
+        return rv;
+    }
+#endif
+    LL_I2L(rv, _PR_MD_SOCKETAVAILABLE(fd));
+	return rv;		
+}
+
+static PRStatus PR_CALLBACK SocketSync(PRFileDesc *fd)
+{
+	return PR_SUCCESS;
+}
+
+static PRInt32 PR_CALLBACK SocketSendTo(
+    PRFileDesc *fd, const void *buf, PRInt32 amount,
+    PRIntn flags, const PRNetAddr *addr, PRIntervalTime timeout)
+{
+	PRInt32 temp, count;
+    const PRNetAddr *addrp = addr;
+#if defined(_PR_INET6)
+	PRNetAddr addrCopy;
+#endif
+	PRThread *me = _PR_MD_CURRENT_THREAD();
+
+	if (_PR_PENDING_INTERRUPT(me)) {
+		me->flags &= ~_PR_INTERRUPT;
+		PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+		return -1;
+	}
+	if (_PR_IO_PENDING(me)) {
+		PR_SetError(PR_IO_PENDING_ERROR, 0);
+		return -1;
+	}
+
+	PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
+#if defined(_PR_INET6)
+	if (addr->raw.family == PR_AF_INET6) {
+		addrCopy = *addr;
+		addrCopy.raw.family = AF_INET6;
+		addrp = &addrCopy;
+	}
+#endif
+
+	count = 0;
+	while (amount > 0) {
+		temp = _PR_MD_SENDTO(fd, buf, amount, flags,
+		    addrp, PR_NETADDR_SIZE(addr), timeout);
+		if (temp < 0) {
+					count = -1;
+					break;
+				}
+		count += temp;
+		if (fd->secret->nonblocking) {
+			break;
+		}
+		buf = (const void*) ((const char*)buf + temp);
+		amount -= temp;
+	}
+	return count;
+}
+
+static PRInt32 PR_CALLBACK SocketRecvFrom(PRFileDesc *fd, void *buf, PRInt32 amount,
+PRIntn flags, PRNetAddr *addr, PRIntervalTime timeout)
+{
+	PRInt32 rv;
+	PRUint32 al;
+	PRThread *me = _PR_MD_CURRENT_THREAD();
+
+	if (_PR_PENDING_INTERRUPT(me)) {
+		me->flags &= ~_PR_INTERRUPT;
+		PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+		return -1;
+	}
+	if (_PR_IO_PENDING(me)) {
+		PR_SetError(PR_IO_PENDING_ERROR, 0);
+		return -1;
+	}
+
+	al = sizeof(PRNetAddr);
+	rv = _PR_MD_RECVFROM(fd, buf, amount, flags, addr, &al, timeout);
+#ifdef _PR_INET6
+	if (addr && (AF_INET6 == addr->raw.family))
+        addr->raw.family = PR_AF_INET6;
+#endif
+	return rv;
+}
+
+static PRInt32 PR_CALLBACK SocketAcceptRead(PRFileDesc *sd, PRFileDesc **nd, 
+PRNetAddr **raddr, void *buf, PRInt32 amount,
+PRIntervalTime timeout)
+{
+	PRInt32 rv;
+	PRThread *me = _PR_MD_CURRENT_THREAD();
+
+	if (_PR_PENDING_INTERRUPT(me)) {
+		me->flags &= ~_PR_INTERRUPT;
+		PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+		return -1;
+	}
+	if (_PR_IO_PENDING(me)) {
+		PR_SetError(PR_IO_PENDING_ERROR, 0);
+		return -1;
+	}
+	/* The socket must be in blocking mode. */
+	if (sd->secret->nonblocking) {
+		PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+		return -1;
+	}
+	*nd = NULL;
+
+#if defined(WINNT)
+	{
+	PROsfd newSock;
+	PRNetAddr *raddrCopy;
+
+	if (raddr == NULL) {
+		raddr = &raddrCopy;
+	}
+	rv = _PR_MD_ACCEPT_READ(sd, &newSock, raddr, buf, amount, timeout);
+	if (rv < 0) {
+		rv = -1;
+	} else {
+		/* Successfully accepted and read; create the new PRFileDesc */
+		*nd = PR_AllocFileDesc(newSock, PR_GetTCPMethods());
+		if (*nd == 0) {
+			_PR_MD_CLOSE_SOCKET(newSock);
+			/* PR_AllocFileDesc() has invoked PR_SetError(). */
+			rv = -1;
+		} else {
+			(*nd)->secret->md.io_model_committed = PR_TRUE;
+			(*nd)->secret->md.accepted_socket = PR_TRUE;
+			memcpy(&(*nd)->secret->md.peer_addr, *raddr,
+				PR_NETADDR_SIZE(*raddr));
+#ifdef _PR_INET6
+			if (AF_INET6 == *raddr->raw.family)
+        		*raddr->raw.family = PR_AF_INET6;
+#endif
+		}
+	}
+	}
+#else
+	rv = PR_EmulateAcceptRead(sd, nd, raddr, buf, amount, timeout);
+#endif
+	return rv;
+}
+
+#ifdef WINNT
+PR_IMPLEMENT(PRInt32) PR_NTFast_AcceptRead(PRFileDesc *sd, PRFileDesc **nd, 
+PRNetAddr **raddr, void *buf, PRInt32 amount,
+PRIntervalTime timeout)
+{
+	PRInt32 rv;
+	PROsfd newSock;
+	PRThread *me = _PR_MD_CURRENT_THREAD();
+	PRNetAddr *raddrCopy;
+
+	if (_PR_PENDING_INTERRUPT(me)) {
+		me->flags &= ~_PR_INTERRUPT;
+		PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+		return -1;
+	}
+	if (_PR_IO_PENDING(me)) {
+		PR_SetError(PR_IO_PENDING_ERROR, 0);
+		return -1;
+	}
+	*nd = NULL;
+
+	if (raddr == NULL) {
+		raddr = &raddrCopy;
+	}
+	rv = _PR_MD_FAST_ACCEPT_READ(sd, &newSock, raddr, buf, amount, 
+	    timeout, PR_TRUE, NULL, NULL);
+	if (rv < 0) {
+		rv = -1;
+	} else {
+		/* Successfully accepted and read; create the new PRFileDesc */
+		*nd = PR_AllocFileDesc(newSock, PR_GetTCPMethods());
+		if (*nd == 0) {
+			_PR_MD_CLOSE_SOCKET(newSock);
+			/* PR_AllocFileDesc() has invoked PR_SetError(). */
+			rv = -1;
+		} else {
+			(*nd)->secret->md.io_model_committed = PR_TRUE;
+			(*nd)->secret->md.accepted_socket = PR_TRUE;
+			memcpy(&(*nd)->secret->md.peer_addr, *raddr,
+				PR_NETADDR_SIZE(*raddr));
+#ifdef _PR_INET6
+			if (AF_INET6 == *raddr->raw.family)
+        		*raddr->raw.family = PR_AF_INET6;
+#endif
+#ifdef _PR_NEED_SECRET_AF
+			(*nd)->secret->af = sd->secret->af;
+#endif
+		}
+	}
+	return rv;
+}
+
+PR_IMPLEMENT(PRInt32) PR_NTFast_AcceptRead_WithTimeoutCallback(
+PRFileDesc *sd, PRFileDesc **nd, 
+PRNetAddr **raddr, void *buf, PRInt32 amount,
+PRIntervalTime timeout,
+_PR_AcceptTimeoutCallback callback,
+void *callbackArg)
+{
+	PRInt32 rv;
+	PROsfd newSock;
+	PRThread *me = _PR_MD_CURRENT_THREAD();
+	PRNetAddr *raddrCopy;
+
+	if (_PR_PENDING_INTERRUPT(me)) {
+		me->flags &= ~_PR_INTERRUPT;
+		PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+		return -1;
+	}
+	if (_PR_IO_PENDING(me)) {
+		PR_SetError(PR_IO_PENDING_ERROR, 0);
+		return -1;
+	}
+	*nd = NULL;
+
+	if (raddr == NULL) {
+		raddr = &raddrCopy;
+	}
+	rv = _PR_MD_FAST_ACCEPT_READ(sd, &newSock, raddr, buf, amount,
+	    timeout, PR_TRUE, callback, callbackArg);
+	if (rv < 0) {
+		rv = -1;
+	} else {
+		/* Successfully accepted and read; create the new PRFileDesc */
+		*nd = PR_AllocFileDesc(newSock, PR_GetTCPMethods());
+		if (*nd == 0) {
+			_PR_MD_CLOSE_SOCKET(newSock);
+			/* PR_AllocFileDesc() has invoked PR_SetError(). */
+			rv = -1;
+		} else {
+			(*nd)->secret->md.io_model_committed = PR_TRUE;
+			(*nd)->secret->md.accepted_socket = PR_TRUE;
+			memcpy(&(*nd)->secret->md.peer_addr, *raddr,
+				PR_NETADDR_SIZE(*raddr));
+#ifdef _PR_INET6
+			if (AF_INET6 == *raddr->raw.family)
+        		*raddr->raw.family = PR_AF_INET6;
+#endif
+#ifdef _PR_NEED_SECRET_AF
+			(*nd)->secret->af = sd->secret->af;
+#endif
+		}
+	}
+	return rv;
+}
+#endif /* WINNT */
+
+#ifdef WINNT
+PR_IMPLEMENT(void)
+PR_NTFast_UpdateAcceptContext(PRFileDesc *socket, PRFileDesc *acceptSocket)
+{
+	_PR_MD_UPDATE_ACCEPT_CONTEXT(
+		socket->secret->md.osfd, acceptSocket->secret->md.osfd);
+}
+#endif /* WINNT */
+
+static PRInt32 PR_CALLBACK SocketSendFile(
+    PRFileDesc *sd, PRSendFileData *sfd,
+    PRTransmitFileFlags flags, PRIntervalTime timeout)
+{
+	PRInt32 rv;
+	PRThread *me = _PR_MD_CURRENT_THREAD();
+
+	if (_PR_PENDING_INTERRUPT(me)) {
+		me->flags &= ~_PR_INTERRUPT;
+		PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+		return -1;
+	}
+	if (_PR_IO_PENDING(me)) {
+		PR_SetError(PR_IO_PENDING_ERROR, 0);
+		return -1;
+	}
+	/* The socket must be in blocking mode. */
+	if (sd->secret->nonblocking) {
+		PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+		return -1;
+	}
+#if defined(WINNT)
+	rv = _PR_MD_SENDFILE(sd, sfd, flags, timeout);
+	if ((rv >= 0) && (flags == PR_TRANSMITFILE_CLOSE_SOCKET)) {
+		/*
+		 * This should be kept the same as SocketClose, except
+		 * that _PR_MD_CLOSE_SOCKET(sd->secret->md.osfd) should
+		 * not be called because the socket will be recycled.
+		 */
+		PR_FreeFileDesc(sd);
+	}
+#else
+	rv = PR_EmulateSendFile(sd, sfd, flags, timeout);
+#endif	/* WINNT */
+
+	return rv;
+}
+
+static PRInt32 PR_CALLBACK SocketTransmitFile(PRFileDesc *sd, PRFileDesc *fd, 
+const void *headers, PRInt32 hlen, PRTransmitFileFlags flags,
+PRIntervalTime timeout)
+{
+	PRSendFileData sfd;
+
+	sfd.fd = fd;
+	sfd.file_offset = 0;
+	sfd.file_nbytes = 0;
+	sfd.header = headers;
+	sfd.hlen = hlen;
+	sfd.trailer = NULL;
+	sfd.tlen = 0;
+
+	return(SocketSendFile(sd, &sfd, flags, timeout));
+}
+
+static PRStatus PR_CALLBACK SocketGetName(PRFileDesc *fd, PRNetAddr *addr)
+{
+	PRInt32 result;
+	PRUint32 addrlen;
+
+	addrlen = sizeof(PRNetAddr);
+	result = _PR_MD_GETSOCKNAME(fd, addr, &addrlen);
+	if (result < 0) {
+		return PR_FAILURE;
+	}
+#ifdef _PR_INET6
+	if (AF_INET6 == addr->raw.family)
+        addr->raw.family = PR_AF_INET6;
+#endif
+	PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
+	PR_ASSERT(IsValidNetAddrLen(addr, addrlen) == PR_TRUE);
+	return PR_SUCCESS;
+}
+
+static PRStatus PR_CALLBACK SocketGetPeerName(PRFileDesc *fd, PRNetAddr *addr)
+{
+	PRInt32 result;
+	PRUint32 addrlen;
+
+	addrlen = sizeof(PRNetAddr);
+	result = _PR_MD_GETPEERNAME(fd, addr, &addrlen);
+	if (result < 0) {
+		return PR_FAILURE;
+	}
+#ifdef _PR_INET6
+	if (AF_INET6 == addr->raw.family)
+        addr->raw.family = PR_AF_INET6;
+#endif
+	PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
+	PR_ASSERT(IsValidNetAddrLen(addr, addrlen) == PR_TRUE);
+	return PR_SUCCESS;
+}
+
+static PRInt16 PR_CALLBACK SocketPoll(
+    PRFileDesc *fd, PRInt16 in_flags, PRInt16 *out_flags)
+{
+    *out_flags = 0;
+    return in_flags;
+}  /* SocketPoll */
+
+static PRIOMethods tcpMethods = {
+	PR_DESC_SOCKET_TCP,
+	SocketClose,
+	SocketRead,
+	SocketWrite,
+	SocketAvailable,
+	SocketAvailable64,
+	SocketSync,
+	(PRSeekFN)_PR_InvalidInt,
+	(PRSeek64FN)_PR_InvalidInt64,
+	(PRFileInfoFN)_PR_InvalidStatus,
+	(PRFileInfo64FN)_PR_InvalidStatus,
+	SocketWritev,
+	SocketConnect,
+	SocketAccept,
+	SocketBind,
+	SocketListen,
+	SocketShutdown,
+	SocketRecv,
+	SocketSend,
+	(PRRecvfromFN)_PR_InvalidInt,
+	(PRSendtoFN)_PR_InvalidInt,
+	SocketPoll,
+	SocketAcceptRead,
+	SocketTransmitFile,
+	SocketGetName,
+	SocketGetPeerName,
+	(PRReservedFN)_PR_InvalidInt,
+	(PRReservedFN)_PR_InvalidInt,
+	_PR_SocketGetSocketOption,
+	_PR_SocketSetSocketOption,
+    SocketSendFile, 
+    SocketConnectContinue,
+    (PRReservedFN)_PR_InvalidInt, 
+    (PRReservedFN)_PR_InvalidInt, 
+    (PRReservedFN)_PR_InvalidInt, 
+    (PRReservedFN)_PR_InvalidInt
+};
+
+static PRIOMethods udpMethods = {
+	PR_DESC_SOCKET_UDP,
+	SocketClose,
+	SocketRead,
+	SocketWrite,
+	SocketAvailable,
+	SocketAvailable64,
+	SocketSync,
+	(PRSeekFN)_PR_InvalidInt,
+	(PRSeek64FN)_PR_InvalidInt64,
+	(PRFileInfoFN)_PR_InvalidStatus,
+	(PRFileInfo64FN)_PR_InvalidStatus,
+	SocketWritev,
+	SocketConnect,
+	(PRAcceptFN)_PR_InvalidDesc,
+	SocketBind,
+	SocketListen,
+	SocketShutdown,
+	SocketRecv,
+	SocketSend,
+	SocketRecvFrom,
+	SocketSendTo,
+	SocketPoll,
+	(PRAcceptreadFN)_PR_InvalidInt,
+	(PRTransmitfileFN)_PR_InvalidInt,
+	SocketGetName,
+	SocketGetPeerName,
+	(PRReservedFN)_PR_InvalidInt,
+	(PRReservedFN)_PR_InvalidInt,
+	_PR_SocketGetSocketOption,
+	_PR_SocketSetSocketOption,
+    (PRSendfileFN)_PR_InvalidInt, 
+    (PRConnectcontinueFN)_PR_InvalidStatus, 
+    (PRReservedFN)_PR_InvalidInt, 
+    (PRReservedFN)_PR_InvalidInt, 
+    (PRReservedFN)_PR_InvalidInt, 
+    (PRReservedFN)_PR_InvalidInt
+};
+
+
+static PRIOMethods socketpollfdMethods = {
+    (PRDescType) 0,
+    (PRCloseFN)_PR_InvalidStatus,
+    (PRReadFN)_PR_InvalidInt,
+    (PRWriteFN)_PR_InvalidInt,
+    (PRAvailableFN)_PR_InvalidInt,
+    (PRAvailable64FN)_PR_InvalidInt64,
+    (PRFsyncFN)_PR_InvalidStatus,
+    (PRSeekFN)_PR_InvalidInt,
+    (PRSeek64FN)_PR_InvalidInt64,
+    (PRFileInfoFN)_PR_InvalidStatus,
+    (PRFileInfo64FN)_PR_InvalidStatus,
+    (PRWritevFN)_PR_InvalidInt,        
+    (PRConnectFN)_PR_InvalidStatus,        
+    (PRAcceptFN)_PR_InvalidDesc,        
+    (PRBindFN)_PR_InvalidStatus,        
+    (PRListenFN)_PR_InvalidStatus,        
+    (PRShutdownFN)_PR_InvalidStatus,    
+    (PRRecvFN)_PR_InvalidInt,        
+    (PRSendFN)_PR_InvalidInt,        
+    (PRRecvfromFN)_PR_InvalidInt,    
+    (PRSendtoFN)_PR_InvalidInt,        
+	SocketPoll,
+    (PRAcceptreadFN)_PR_InvalidInt,   
+    (PRTransmitfileFN)_PR_InvalidInt, 
+    (PRGetsocknameFN)_PR_InvalidStatus,    
+    (PRGetpeernameFN)_PR_InvalidStatus,    
+    (PRReservedFN)_PR_InvalidInt,    
+    (PRReservedFN)_PR_InvalidInt,    
+    (PRGetsocketoptionFN)_PR_InvalidStatus,
+    (PRSetsocketoptionFN)_PR_InvalidStatus,
+    (PRSendfileFN)_PR_InvalidInt, 
+    (PRConnectcontinueFN)_PR_InvalidStatus, 
+    (PRReservedFN)_PR_InvalidInt, 
+    (PRReservedFN)_PR_InvalidInt, 
+    (PRReservedFN)_PR_InvalidInt, 
+    (PRReservedFN)_PR_InvalidInt
+};
+
+PR_IMPLEMENT(const PRIOMethods*) PR_GetTCPMethods()
+{
+	return &tcpMethods;
+}
+
+PR_IMPLEMENT(const PRIOMethods*) PR_GetUDPMethods()
+{
+	return &udpMethods;
+}
+
+static const PRIOMethods* PR_GetSocketPollFdMethods()
+{
+    return &socketpollfdMethods;
+}  /* PR_GetSocketPollFdMethods */
+
+#if !defined(_PR_INET6) || defined(_PR_INET6_PROBE)
+PR_EXTERN(PRStatus) _pr_push_ipv6toipv4_layer(PRFileDesc *fd);
+
+#if defined(_PR_INET6_PROBE)
+
+extern PRBool _pr_ipv6_is_present(void);
+
+PR_IMPLEMENT(PRBool) _pr_test_ipv6_socket()
+{
+	PROsfd osfd;
+
+	osfd = _PR_MD_SOCKET(AF_INET6, SOCK_STREAM, 0);
+	if (osfd != -1) {
+		_PR_MD_CLOSE_SOCKET(osfd);
+		return PR_TRUE;
+	}
+	return PR_FALSE;
+}
+#endif	/* _PR_INET6_PROBE */
+
+#endif
+
+PR_IMPLEMENT(PRFileDesc*) PR_Socket(PRInt32 domain, PRInt32 type, PRInt32 proto)
+{
+	PROsfd osfd;
+	PRFileDesc *fd;
+	PRInt32 tmp_domain = domain;
+
+	if (!_pr_initialized) _PR_ImplicitInitialization();
+	if (PR_AF_INET != domain
+			&& PR_AF_INET6 != domain
+#if defined(XP_UNIX) || defined(XP_OS2)
+			&& PR_AF_LOCAL != domain
+#endif
+			) {
+		PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, 0);
+		return NULL;
+	}
+
+#if defined(_PR_INET6_PROBE)
+	if (PR_AF_INET6 == domain)
+		domain = _pr_ipv6_is_present() ? AF_INET6 : AF_INET;
+#elif defined(_PR_INET6)
+	if (PR_AF_INET6 == domain)
+		domain = AF_INET6;
+#else
+	if (PR_AF_INET6 == domain)
+		domain = AF_INET;
+#endif	/* _PR_INET6 */
+	osfd = _PR_MD_SOCKET(domain, type, proto);
+	if (osfd == -1) {
+		return 0;
+	}
+	if (type == SOCK_STREAM)
+		fd = PR_AllocFileDesc(osfd, PR_GetTCPMethods());
+	else
+		fd = PR_AllocFileDesc(osfd, PR_GetUDPMethods());
+	/*
+	 * Make the sockets non-blocking
+	 */
+	if (fd != NULL) {
+		_PR_MD_MAKE_NONBLOCK(fd);
+		_PR_MD_INIT_FD_INHERITABLE(fd, PR_FALSE);
+#ifdef _PR_NEED_SECRET_AF
+		fd->secret->af = domain;
+#endif
+#if defined(_PR_INET6_PROBE) || !defined(_PR_INET6)
+		/*
+		 * For platforms with no support for IPv6 
+		 * create layered socket for IPv4-mapped IPv6 addresses
+		 */
+		if (PR_AF_INET6 == tmp_domain && PR_AF_INET == domain) {
+			if (PR_FAILURE == _pr_push_ipv6toipv4_layer(fd)) {
+				PR_Close(fd);
+				fd = NULL;
+			}
+		}
+#endif
+	} else
+		_PR_MD_CLOSE_SOCKET(osfd);
+
+	return fd;
+}
+
+PR_IMPLEMENT(PRFileDesc *) PR_NewTCPSocket(void)
+{
+	PRInt32 domain = AF_INET;
+
+	return PR_Socket(domain, SOCK_STREAM, 0);
+}
+
+PR_IMPLEMENT(PRFileDesc*) PR_NewUDPSocket(void)
+{
+	PRInt32 domain = AF_INET;
+
+	return PR_Socket(domain, SOCK_DGRAM, 0);
+}
+
+PR_IMPLEMENT(PRFileDesc *) PR_OpenTCPSocket(PRIntn af)
+{
+	return PR_Socket(af, SOCK_STREAM, 0);
+}
+
+PR_IMPLEMENT(PRFileDesc*) PR_OpenUDPSocket(PRIntn af)
+{
+	return PR_Socket(af, SOCK_DGRAM, 0);
+}
+
+PR_IMPLEMENT(PRStatus) PR_NewTCPSocketPair(PRFileDesc *f[])
+{
+#ifdef XP_UNIX
+	PRInt32 rv, osfd[2];
+
+	if (!_pr_initialized) _PR_ImplicitInitialization();
+
+	rv = _PR_MD_SOCKETPAIR(AF_UNIX, SOCK_STREAM, 0, osfd);
+	if (rv == -1) {
+		return PR_FAILURE;
+	}
+
+	f[0] = PR_AllocFileDesc(osfd[0], PR_GetTCPMethods());
+	if (!f[0]) {
+		_PR_MD_CLOSE_SOCKET(osfd[0]);
+		_PR_MD_CLOSE_SOCKET(osfd[1]);
+		/* PR_AllocFileDesc() has invoked PR_SetError(). */
+		return PR_FAILURE;
+	}
+	f[1] = PR_AllocFileDesc(osfd[1], PR_GetTCPMethods());
+	if (!f[1]) {
+		PR_Close(f[0]);
+		_PR_MD_CLOSE_SOCKET(osfd[1]);
+		/* PR_AllocFileDesc() has invoked PR_SetError(). */
+		return PR_FAILURE;
+	}
+	_PR_MD_MAKE_NONBLOCK(f[0]);
+	_PR_MD_INIT_FD_INHERITABLE(f[0], PR_FALSE);
+	_PR_MD_MAKE_NONBLOCK(f[1]);
+	_PR_MD_INIT_FD_INHERITABLE(f[1], PR_FALSE);
+	return PR_SUCCESS;
+#elif defined(WINNT)
+    /*
+     * A socket pair is often used for interprocess communication,
+     * so we need to make sure neither socket is associated with
+     * the I/O completion port; otherwise it can't be used by a
+     * child process.
+     *
+     * The default implementation below cannot be used for NT
+     * because PR_Accept would have associated the I/O completion
+     * port with the listening and accepted sockets.
+     */
+    SOCKET listenSock;
+    SOCKET osfd[2];
+    struct sockaddr_in selfAddr, peerAddr;
+    int addrLen;
+
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+
+    osfd[0] = osfd[1] = INVALID_SOCKET;
+    listenSock = socket(AF_INET, SOCK_STREAM, 0);
+    if (listenSock == INVALID_SOCKET) {
+        goto failed;
+    }
+    selfAddr.sin_family = AF_INET;
+    selfAddr.sin_port = 0;
+    selfAddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); /* BugZilla: 35408 */
+    addrLen = sizeof(selfAddr);
+    if (bind(listenSock, (struct sockaddr *) &selfAddr,
+            addrLen) == SOCKET_ERROR) {
+        goto failed;
+    }
+    if (getsockname(listenSock, (struct sockaddr *) &selfAddr,
+            &addrLen) == SOCKET_ERROR) {
+        goto failed;
+    }
+    if (listen(listenSock, 5) == SOCKET_ERROR) {
+        goto failed;
+    }
+    osfd[0] = socket(AF_INET, SOCK_STREAM, 0);
+    if (osfd[0] == INVALID_SOCKET) {
+        goto failed;
+    }
+    selfAddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+
+    /*
+     * Only a thread is used to do the connect and accept.
+     * I am relying on the fact that connect returns
+     * successfully as soon as the connect request is put
+     * into the listen queue (but before accept is called).
+     * This is the behavior of the BSD socket code.  If
+     * connect does not return until accept is called, we
+     * will need to create another thread to call connect.
+     */
+    if (connect(osfd[0], (struct sockaddr *) &selfAddr,
+            addrLen) == SOCKET_ERROR) {
+        goto failed;
+    }
+    /*
+     * A malicious local process may connect to the listening
+     * socket, so we need to verify that the accepted connection
+     * is made from our own socket osfd[0].
+     */
+    if (getsockname(osfd[0], (struct sockaddr *) &selfAddr,
+            &addrLen) == SOCKET_ERROR) {
+        goto failed;
+    }
+    osfd[1] = accept(listenSock, (struct sockaddr *) &peerAddr, &addrLen);
+    if (osfd[1] == INVALID_SOCKET) {
+        goto failed;
+    }
+    if (peerAddr.sin_port != selfAddr.sin_port) {
+        /* the connection we accepted is not from osfd[0] */
+        PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
+        goto failed;
+    }
+    closesocket(listenSock);
+
+    f[0] = PR_AllocFileDesc(osfd[0], PR_GetTCPMethods());
+    if (!f[0]) {
+        closesocket(osfd[0]);
+        closesocket(osfd[1]);
+        /* PR_AllocFileDesc() has invoked PR_SetError(). */
+        return PR_FAILURE;
+    }
+    f[1] = PR_AllocFileDesc(osfd[1], PR_GetTCPMethods());
+    if (!f[1]) {
+        PR_Close(f[0]);
+        closesocket(osfd[1]);
+        /* PR_AllocFileDesc() has invoked PR_SetError(). */
+        return PR_FAILURE;
+    }
+    _PR_MD_INIT_FD_INHERITABLE(f[0], PR_FALSE);
+    _PR_MD_INIT_FD_INHERITABLE(f[1], PR_FALSE);
+    return PR_SUCCESS;
+
+failed:
+    if (listenSock != INVALID_SOCKET) {
+        closesocket(listenSock);
+    }
+    if (osfd[0] != INVALID_SOCKET) {
+        closesocket(osfd[0]);
+    }
+    if (osfd[1] != INVALID_SOCKET) {
+        closesocket(osfd[1]);
+    }
+    return PR_FAILURE;
+#else /* not Unix or NT */
+    /*
+     * default implementation
+     */
+    PRFileDesc *listenSock;
+    PRNetAddr selfAddr, peerAddr;
+    PRUint16 port;
+
+    f[0] = f[1] = NULL;
+    listenSock = PR_NewTCPSocket();
+    if (listenSock == NULL) {
+        goto failed;
+    }
+    PR_InitializeNetAddr(PR_IpAddrLoopback, 0, &selfAddr); /* BugZilla: 35408 */
+    if (PR_Bind(listenSock, &selfAddr) == PR_FAILURE) {
+        goto failed;
+    }
+    if (PR_GetSockName(listenSock, &selfAddr) == PR_FAILURE) {
+        goto failed;
+    }
+    port = ntohs(selfAddr.inet.port);
+    if (PR_Listen(listenSock, 5) == PR_FAILURE) {
+        goto failed;
+    }
+    f[0] = PR_NewTCPSocket();
+    if (f[0] == NULL) {
+        goto failed;
+    }
+#ifdef _PR_CONNECT_DOES_NOT_BIND
+    /*
+     * If connect does not implicitly bind the socket (e.g., on
+     * BeOS), we have to bind the socket so that we can get its
+     * port with getsockname later.
+     */
+    PR_InitializeNetAddr(PR_IpAddrLoopback, 0, &selfAddr);
+    if (PR_Bind(f[0], &selfAddr) == PR_FAILURE) {
+        goto failed;
+    }
+#endif
+    PR_InitializeNetAddr(PR_IpAddrLoopback, port, &selfAddr);
+
+    /*
+     * Only a thread is used to do the connect and accept.
+     * I am relying on the fact that PR_Connect returns
+     * successfully as soon as the connect request is put
+     * into the listen queue (but before PR_Accept is called).
+     * This is the behavior of the BSD socket code.  If
+     * connect does not return until accept is called, we
+     * will need to create another thread to call connect.
+     */
+    if (PR_Connect(f[0], &selfAddr, PR_INTERVAL_NO_TIMEOUT)
+            == PR_FAILURE) {
+        goto failed;
+    }
+    /*
+     * A malicious local process may connect to the listening
+     * socket, so we need to verify that the accepted connection
+     * is made from our own socket f[0].
+     */
+    if (PR_GetSockName(f[0], &selfAddr) == PR_FAILURE) {
+        goto failed;
+    }
+    f[1] = PR_Accept(listenSock, &peerAddr, PR_INTERVAL_NO_TIMEOUT);
+    if (f[1] == NULL) {
+        goto failed;
+    }
+    if (peerAddr.inet.port != selfAddr.inet.port) {
+        /* the connection we accepted is not from f[0] */
+        PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
+        goto failed;
+    }
+    PR_Close(listenSock);
+    return PR_SUCCESS;
+
+failed:
+    if (listenSock) {
+        PR_Close(listenSock);
+    }
+    if (f[0]) {
+        PR_Close(f[0]);
+    }
+    if (f[1]) {
+        PR_Close(f[1]);
+    }
+    return PR_FAILURE;
+#endif
+}
+
+PR_IMPLEMENT(PROsfd)
+PR_FileDesc2NativeHandle(PRFileDesc *fd)
+{
+    if (fd) {
+        fd = PR_GetIdentitiesLayer(fd, PR_NSPR_IO_LAYER);
+    }
+    if (!fd) {
+        PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+        return -1;
+    }
+    return fd->secret->md.osfd;
+}
+
+PR_IMPLEMENT(void)
+PR_ChangeFileDescNativeHandle(PRFileDesc *fd, PROsfd handle)
+{
+	if (fd)
+		fd->secret->md.osfd = handle;
+}
+
+/*
+** Select compatibility
+**
+*/
+
+PR_IMPLEMENT(void) PR_FD_ZERO(PR_fd_set *set)
+{
+	memset(set, 0, sizeof(PR_fd_set));
+}
+
+PR_IMPLEMENT(void) PR_FD_SET(PRFileDesc *fh, PR_fd_set *set)
+{
+	PR_ASSERT( set->hsize < PR_MAX_SELECT_DESC );
+
+	set->harray[set->hsize++] = fh;
+}
+
+PR_IMPLEMENT(void) PR_FD_CLR(PRFileDesc *fh, PR_fd_set *set)
+{
+	PRUint32 index, index2;
+
+	for (index = 0; index<set->hsize; index++)
+		if (set->harray[index] == fh) {
+			for (index2=index; index2 < (set->hsize-1); index2++) {
+				set->harray[index2] = set->harray[index2+1];
+			}
+			set->hsize--;
+			break;
+		}
+}
+
+PR_IMPLEMENT(PRInt32) PR_FD_ISSET(PRFileDesc *fh, PR_fd_set *set)
+{
+	PRUint32 index;
+	for (index = 0; index<set->hsize; index++)
+		if (set->harray[index] == fh) {
+			return 1;
+		}
+	return 0;
+}
+
+PR_IMPLEMENT(void) PR_FD_NSET(PROsfd fd, PR_fd_set *set)
+{
+	PR_ASSERT( set->nsize < PR_MAX_SELECT_DESC );
+
+	set->narray[set->nsize++] = fd;
+}
+
+PR_IMPLEMENT(void) PR_FD_NCLR(PROsfd fd, PR_fd_set *set)
+{
+	PRUint32 index, index2;
+
+	for (index = 0; index<set->nsize; index++)
+		if (set->narray[index] == fd) {
+			for (index2=index; index2 < (set->nsize-1); index2++) {
+				set->narray[index2] = set->narray[index2+1];
+			}
+			set->nsize--;
+			break;
+		}
+}
+
+PR_IMPLEMENT(PRInt32) PR_FD_NISSET(PROsfd fd, PR_fd_set *set)
+{
+	PRUint32 index;
+	for (index = 0; index<set->nsize; index++)
+		if (set->narray[index] == fd) {
+			return 1;
+		}
+	return 0;
+}
+
+
+#if !defined(NEED_SELECT)
+#include "obsolete/probslet.h"
+
+#define PD_INCR 20
+
+static PRPollDesc *_pr_setfd(
+    PR_fd_set *set, PRInt16 flags, PRPollDesc *polldesc)
+{
+    PRUintn fsidx, pdidx;
+    PRPollDesc *poll = polldesc;
+
+    if (NULL == set) return poll;
+
+	/* First set the pr file handle osfds */
+	for (fsidx = 0; fsidx < set->hsize; fsidx++)
+	{
+	    for (pdidx = 0; 1; pdidx++)
+        {
+            if ((PRFileDesc*)-1 == poll[pdidx].fd)
+            {
+                /* our vector is full - extend and condition it */
+                poll = (PRPollDesc*)PR_Realloc(
+                    poll, (pdidx + 1 + PD_INCR) * sizeof(PRPollDesc));
+                if (NULL == poll) goto out_of_memory;
+                memset(
+                    poll + pdidx * sizeof(PRPollDesc),
+                    0, PD_INCR * sizeof(PRPollDesc));
+                poll[pdidx + PD_INCR].fd = (PRFileDesc*)-1;
+            }
+            if ((NULL == poll[pdidx].fd)
+            || (poll[pdidx].fd == set->harray[fsidx]))
+            {
+                /* PR_ASSERT(0 == (poll[pdidx].in_flags & flags)); */
+                /* either empty or prevously defined */
+                poll[pdidx].fd = set->harray[fsidx];  /* possibly redundant */
+                poll[pdidx].in_flags |= flags;  /* possibly redundant */
+                break;
+            }
+        }
+	}
+
+#if 0
+	/* Second set the native osfds */
+	for (fsidx = 0; fsidx < set->nsize; fsidx++)
+	{
+	    for (pdidx = 0; ((PRFileDesc*)-1 != poll[pdidx].fd); pdidx++)
+        {
+            if ((PRFileDesc*)-1 == poll[pdidx].fd)
+            {
+                /* our vector is full - extend and condition it */
+                poll = PR_Realloc(
+                    poll, (pdidx + PD_INCR) * sizeof(PRPollDesc));
+                if (NULL == poll) goto out_of_memory;
+                memset(
+                    poll + pdidx * sizeof(PRPollDesc),
+                    0, PD_INCR * sizeof(PRPollDesc));
+                poll[(pdidx + PD_INCR)].fd = (PRFileDesc*)-1;
+            }
+            if ((NULL == poll[pdidx].fd)
+            || (poll[pdidx].fd == set->narray[fsidx]))
+            {
+                /* either empty or prevously defined */
+                poll[pdidx].fd = set->narray[fsidx];
+                PR_ASSERT(0 == (poll[pdidx].in_flags & flags));
+                poll[pdidx].in_flags |= flags;
+                break;
+            }
+        }
+	}
+#endif /* 0 */
+
+	return poll;
+
+out_of_memory:
+    if (NULL != polldesc) PR_DELETE(polldesc);
+    return NULL;
+}  /* _pr_setfd */
+
+#endif /* !defined(NEED_SELECT) */
+
+PR_IMPLEMENT(PRInt32) PR_Select(
+    PRInt32 unused, PR_fd_set *pr_rd, PR_fd_set *pr_wr, 
+    PR_fd_set *pr_ex, PRIntervalTime timeout)
+{
+
+#if !defined(NEED_SELECT)
+    PRInt32 npds = 0; 
+    /*
+    ** Find out how many fds are represented in the three lists.
+    ** Then allocate a polling descriptor for the logical union
+    ** (there can't be any overlapping) and call PR_Poll().
+    */
+
+    PRPollDesc *copy, *poll;
+
+    static PRBool warning = PR_TRUE;
+    if (warning) warning = _PR_Obsolete( "PR_Select()", "PR_Poll()");
+
+    /* try to get an initial guesss at how much space we need */
+    npds = 0;
+    if ((NULL != pr_rd) && ((pr_rd->hsize + pr_rd->nsize - npds) > 0))
+        npds = pr_rd->hsize + pr_rd->nsize;
+    if ((NULL != pr_wr) && ((pr_wr->hsize + pr_wr->nsize - npds) > 0))
+        npds = pr_wr->hsize + pr_wr->nsize;
+    if ((NULL != pr_ex) && ((pr_ex->hsize + pr_ex->nsize - npds) > 0))
+        npds = pr_ex->hsize + pr_ex->nsize;
+
+    if (0 == npds)
+    {
+        PR_Sleep(timeout);
+        return 0;
+    }
+
+    copy = poll = (PRPollDesc*)PR_Calloc(npds + PD_INCR, sizeof(PRPollDesc));
+    if (NULL == poll) goto out_of_memory;
+    poll[npds + PD_INCR - 1].fd = (PRFileDesc*)-1;
+
+    poll = _pr_setfd(pr_rd, PR_POLL_READ, poll);
+    if (NULL == poll) goto out_of_memory;
+    poll = _pr_setfd(pr_wr, PR_POLL_WRITE, poll);
+    if (NULL == poll) goto out_of_memory;
+    poll = _pr_setfd(pr_ex, PR_POLL_EXCEPT, poll);
+    if (NULL == poll) goto out_of_memory;
+    unused = 0;
+    while (NULL != poll[unused].fd && (PRFileDesc*)-1 != poll[unused].fd)
+    {
+        ++unused;
+    }
+
+    PR_ASSERT(unused > 0);
+    npds = PR_Poll(poll, unused, timeout);
+
+    if (npds > 0)
+    {
+        /* Copy the results back into the fd sets */
+        if (NULL != pr_rd) pr_rd->nsize = pr_rd->hsize = 0;
+        if (NULL != pr_wr) pr_wr->nsize = pr_wr->hsize = 0;
+        if (NULL != pr_ex) pr_ex->nsize = pr_ex->hsize = 0;
+        for (copy = &poll[unused - 1]; copy >= poll; --copy)
+        {
+            if (copy->out_flags & PR_POLL_NVAL)
+            {
+                PR_SetError(PR_BAD_DESCRIPTOR_ERROR, 0);
+                npds = -1;
+                break;
+            }
+            if (copy->out_flags & PR_POLL_READ)
+                if (NULL != pr_rd) pr_rd->harray[pr_rd->hsize++] = copy->fd;
+            if (copy->out_flags & PR_POLL_WRITE)
+                if (NULL != pr_wr) pr_wr->harray[pr_wr->hsize++] = copy->fd;
+            if (copy->out_flags & PR_POLL_EXCEPT)
+                if (NULL != pr_ex) pr_ex->harray[pr_ex->hsize++] = copy->fd;
+        }
+    }
+    PR_DELETE(poll);
+
+    return npds;
+out_of_memory:
+    PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+    return -1;    
+
+#endif /* !defined(NEED_SELECT) */
+    
+}
diff --git a/pr/src/io/prstdio.c b/pr/src/io/prstdio.c
new file mode 100644
index 0000000..74b85d9
--- /dev/null
+++ b/pr/src/io/prstdio.c
@@ -0,0 +1,74 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "primpl.h"
+
+#include <string.h>
+
+/*
+** fprintf to a PRFileDesc
+*/
+PR_IMPLEMENT(PRUint32) PR_fprintf(PRFileDesc* fd, const char *fmt, ...)
+{
+    va_list ap;
+    PRUint32 rv;
+
+    va_start(ap, fmt);
+    rv = PR_vfprintf(fd, fmt, ap);
+    va_end(ap);
+    return rv;
+}
+
+PR_IMPLEMENT(PRUint32) PR_vfprintf(PRFileDesc* fd, const char *fmt, va_list ap)
+{
+    /* XXX this could be better */
+    PRUint32 rv, len;
+    char* msg = PR_vsmprintf(fmt, ap);
+    if (NULL == msg) {
+        return -1;
+    }
+    len = strlen(msg);
+#ifdef XP_OS2
+    /*
+     * OS/2 really needs a \r for every \n.
+     * In the future we should try to use scatter-gather instead of a
+     * succession of PR_Write.
+     */
+    if (isatty(PR_FileDesc2NativeHandle(fd))) {
+        PRUint32 last = 0, idx;
+        PRInt32 tmp;
+        rv = 0;
+        for (idx = 0; idx < len+1; idx++) {
+            if ((idx - last > 0) && (('\n' == msg[idx]) || (idx == len))) {
+                tmp = PR_Write(fd, msg + last, idx - last);
+                if (tmp >= 0) {
+                    rv += tmp;
+                }
+                last = idx;
+            }
+            /*
+             * if current character is \n, and
+             * previous character isn't \r, and
+             * next character isn't \r
+             */
+            if (('\n' == msg[idx]) &&
+                ((0 == idx) || ('\r' != msg[idx-1])) &&
+                ('\r' != msg[idx+1])) {
+                /* add extra \r */
+                tmp = PR_Write(fd, "\r", 1);
+                if (tmp >= 0) {
+                    rv += tmp;
+                }
+            }
+        }
+    } else {
+        rv = PR_Write(fd, msg, len);
+    }
+#else
+    rv = PR_Write(fd, msg, len);
+#endif
+    PR_DELETE(msg);
+    return rv;
+}
diff --git a/pr/src/linking/.cvsignore b/pr/src/linking/.cvsignore
new file mode 100644
index 0000000..f3c7a7c
--- /dev/null
+++ b/pr/src/linking/.cvsignore
@@ -0,0 +1 @@
+Makefile
diff --git a/pr/src/linking/Makefile.in b/pr/src/linking/Makefile.in
new file mode 100644
index 0000000..9292e9e
--- /dev/null
+++ b/pr/src/linking/Makefile.in
@@ -0,0 +1,31 @@
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+#! gmake
+
+MOD_DEPTH	= ../../..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+
+include $(MOD_DEPTH)/config/autoconf.mk
+
+include $(topsrcdir)/config/config.mk
+
+CSRCS =           \
+	prlink.c   \
+	$(NULL)
+
+TARGETS	= $(OBJS)
+
+INCLUDES = -I$(dist_includedir) -I$(topsrcdir)/pr/include -I$(topsrcdir)/pr/include/private
+
+DEFINES += -D_NSPR_BUILD_
+
+include $(topsrcdir)/config/rules.mk
+
+export:: $(TARGETS)
+
diff --git a/pr/src/linking/prlink.c b/pr/src/linking/prlink.c
new file mode 100644
index 0000000..4715460
--- /dev/null
+++ b/pr/src/linking/prlink.c
@@ -0,0 +1,1608 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "primpl.h"
+
+#include <string.h>
+
+#ifdef XP_BEOS
+#include <image.h>
+#endif
+
+#if defined(XP_MACOSX) && defined(USE_MACH_DYLD)
+#include <Carbon/Carbon.h>
+#include <CoreFoundation/CoreFoundation.h>
+#endif
+
+#ifdef XP_UNIX
+#ifdef USE_DLFCN
+#include <dlfcn.h>
+/* Define these on systems that don't have them. */
+#ifndef RTLD_NOW
+#define RTLD_NOW 0
+#endif
+#ifndef RTLD_LAZY
+#define RTLD_LAZY RTLD_NOW
+#endif
+#ifndef RTLD_GLOBAL
+#define RTLD_GLOBAL 0
+#endif
+#ifndef RTLD_LOCAL
+#define RTLD_LOCAL 0
+#endif
+#ifdef AIX
+#include <sys/ldr.h>
+#ifndef L_IGNOREUNLOAD /* AIX 4.3.3 does not have L_IGNOREUNLOAD. */
+#define L_IGNOREUNLOAD 0x10000000
+#endif
+#endif
+#ifdef OSF1
+#include <loader.h>
+#include <rld_interface.h>
+#endif
+#elif defined(USE_HPSHL)
+#include <dl.h>
+#elif defined(USE_MACH_DYLD)
+#include <mach-o/dyld.h>
+#endif
+#endif /* XP_UNIX */
+
+#define _PR_DEFAULT_LD_FLAGS PR_LD_LAZY
+
+/*
+ * On these platforms, symbols have a leading '_'.
+ */
+#if (defined(DARWIN) && defined(USE_MACH_DYLD)) \
+    || defined(XP_OS2) \
+    || ((defined(OPENBSD) || defined(NETBSD)) && !defined(__ELF__))
+#define NEED_LEADING_UNDERSCORE
+#endif
+
+#define PR_LD_PATHW 0x8000  /* for PR_LibSpec_PathnameU */
+
+/************************************************************************/
+
+struct PRLibrary {
+    char*                       name;  /* Our own copy of the name string */
+    PRLibrary*                  next;
+    int                         refCount;
+    const PRStaticLinkTable*    staticTable;
+
+#ifdef XP_PC
+#ifdef XP_OS2
+    HMODULE                     dlh;
+#else
+    HINSTANCE                   dlh;
+#endif
+#endif
+
+#if defined(XP_MACOSX) && defined(USE_MACH_DYLD)
+    CFragConnectionID           connection;
+    CFBundleRef                 bundle;
+    Ptr                         main;
+    CFMutableDictionaryRef      wrappers;
+    const struct mach_header*   image;
+#endif
+
+#ifdef XP_UNIX
+#if defined(USE_HPSHL)
+    shl_t                       dlh;
+#elif defined(USE_MACH_DYLD)
+    NSModule                    dlh;
+#else
+    void*                       dlh;
+#endif 
+#endif 
+
+#ifdef XP_BEOS
+    void*                       dlh;
+    void*                       stub_dlh;
+#endif
+};
+
+static PRLibrary *pr_loadmap;
+static PRLibrary *pr_exe_loadmap;
+static PRMonitor *pr_linker_lock;
+static char* _pr_currentLibPath = NULL;
+
+static PRLibrary *pr_LoadLibraryByPathname(const char *name, PRIntn flags);
+
+/************************************************************************/
+
+#if !defined(USE_DLFCN) && !defined(HAVE_STRERROR)
+#define ERR_STR_BUF_LENGTH    20
+#endif
+
+static void DLLErrorInternal(PRIntn oserr)
+/*
+** This whole function, and most of the code in this file, are run
+** with a big hairy lock wrapped around it. Not the best of situations,
+** but will eventually come up with the right answer.
+*/
+{
+    const char *error = NULL;
+#ifdef USE_DLFCN
+    error = dlerror();  /* $$$ That'll be wrong some of the time - AOF */
+#elif defined(HAVE_STRERROR)
+    error = strerror(oserr);  /* this should be okay */
+#else
+    char errStrBuf[ERR_STR_BUF_LENGTH];
+    PR_snprintf(errStrBuf, sizeof(errStrBuf), "error %d", oserr);
+    error = errStrBuf;
+#endif
+    if (NULL != error)
+        PR_SetErrorText(strlen(error), error);
+}  /* DLLErrorInternal */
+
+void _PR_InitLinker(void)
+{
+    PRLibrary *lm = NULL;
+#if defined(XP_UNIX)
+    void *h;
+#endif
+
+    if (!pr_linker_lock) {
+        pr_linker_lock = PR_NewNamedMonitor("linker-lock");
+    }
+    PR_EnterMonitor(pr_linker_lock);
+
+#if defined(XP_PC)
+    lm = PR_NEWZAP(PRLibrary);
+    lm->name = strdup("Executable");
+#if defined(XP_OS2)
+    lm->dlh = NULLHANDLE;
+#else
+    /* A module handle for the executable. */
+    lm->dlh = GetModuleHandle(NULL);
+#endif /* ! XP_OS2 */
+
+    lm->refCount    = 1;
+    lm->staticTable = NULL;
+    pr_exe_loadmap  = lm;
+    pr_loadmap      = lm;
+
+#elif defined(XP_UNIX)
+#ifdef HAVE_DLL
+#if defined(USE_DLFCN) && !defined(NO_DLOPEN_NULL)
+    h = dlopen(0, RTLD_LAZY);
+    if (!h) {
+        char *error;
+        
+        DLLErrorInternal(_MD_ERRNO());
+        error = (char*)PR_MALLOC(PR_GetErrorTextLength());
+        (void) PR_GetErrorText(error);
+        fprintf(stderr, "failed to initialize shared libraries [%s]\n",
+            error);
+        PR_DELETE(error);
+        abort();/* XXX */
+    }
+#elif defined(USE_HPSHL)
+    h = NULL;
+    /* don't abort with this NULL */
+#elif defined(USE_MACH_DYLD) || defined(NO_DLOPEN_NULL)
+    h = NULL; /* XXXX  toshok */ /* XXXX  vlad */
+#else
+#error no dll strategy
+#endif /* USE_DLFCN */
+
+    lm = PR_NEWZAP(PRLibrary);
+    if (lm) {
+        lm->name = strdup("a.out");
+        lm->refCount = 1;
+        lm->dlh = h;
+        lm->staticTable = NULL;
+    }
+    pr_exe_loadmap = lm;
+    pr_loadmap = lm;
+#endif /* HAVE_DLL */
+#endif /* XP_UNIX */
+
+    if (lm) {
+        PR_LOG(_pr_linker_lm, PR_LOG_MIN,
+            ("Loaded library %s (init)", lm->name));
+    }
+
+    PR_ExitMonitor(pr_linker_lock);
+}
+
+/*
+ * _PR_ShutdownLinker does not unload the dlls loaded by the application
+ * via calls to PR_LoadLibrary.  Any dlls that still remain on the
+ * pr_loadmap list when NSPR shuts down are application programming errors.
+ * The only exception is pr_exe_loadmap, which was added to the list by
+ * NSPR and hence should be cleaned up by NSPR.
+ */
+void _PR_ShutdownLinker(void)
+{
+    /* FIXME: pr_exe_loadmap should be destroyed. */
+    
+    PR_DestroyMonitor(pr_linker_lock);
+    pr_linker_lock = NULL;
+
+    if (_pr_currentLibPath) {
+        free(_pr_currentLibPath);
+        _pr_currentLibPath = NULL;
+    }
+}
+
+/******************************************************************************/
+
+PR_IMPLEMENT(PRStatus) PR_SetLibraryPath(const char *path)
+{
+    PRStatus rv = PR_SUCCESS;
+
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+    PR_EnterMonitor(pr_linker_lock);
+    if (_pr_currentLibPath) {
+        free(_pr_currentLibPath);
+    }
+    if (path) {
+        _pr_currentLibPath = strdup(path);
+        if (!_pr_currentLibPath) {
+            PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+        rv = PR_FAILURE;
+        }
+    } else {
+        _pr_currentLibPath = 0;
+    }
+    PR_ExitMonitor(pr_linker_lock);
+    return rv;
+}
+
+/*
+** Return the library path for finding shared libraries.
+*/
+PR_IMPLEMENT(char *) 
+PR_GetLibraryPath(void)
+{
+    char *ev;
+    char *copy = NULL;  /* a copy of _pr_currentLibPath */
+
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+    PR_EnterMonitor(pr_linker_lock);
+    if (_pr_currentLibPath != NULL) {
+        goto exit;
+    }
+
+    /* initialize pr_currentLibPath */
+
+#ifdef XP_PC
+    ev = getenv("LD_LIBRARY_PATH");
+    if (!ev) {
+    ev = ".;\\lib";
+    }
+    ev = strdup(ev);
+#endif
+
+#if defined(XP_UNIX) || defined(XP_BEOS)
+#if defined(USE_DLFCN) || defined(USE_MACH_DYLD) || defined(XP_BEOS)
+    {
+    char *p=NULL;
+    int len;
+
+#ifdef XP_BEOS
+    ev = getenv("LIBRARY_PATH");
+    if (!ev) {
+        ev = "%A/lib:/boot/home/config/lib:/boot/beos/system/lib";
+    }
+#else
+    ev = getenv("LD_LIBRARY_PATH");
+    if (!ev) {
+        ev = "/usr/lib:/lib";
+    }
+#endif
+    len = strlen(ev) + 1;        /* +1 for the null */
+
+    p = (char*) malloc(len);
+    if (p) {
+        strcpy(p, ev);
+    }   /* if (p)  */
+    ev = p;
+    PR_LOG(_pr_io_lm, PR_LOG_NOTICE, ("linker path '%s'", ev));
+
+    }
+#else
+    /* AFAIK there isn't a library path with the HP SHL interface --Rob */
+    ev = strdup("");
+#endif
+#endif
+
+    /*
+     * If ev is NULL, we have run out of memory
+     */
+    _pr_currentLibPath = ev;
+
+  exit:
+    if (_pr_currentLibPath) {
+        copy = strdup(_pr_currentLibPath);
+    }
+    PR_ExitMonitor(pr_linker_lock);
+    if (!copy) {
+        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+    }
+    return copy;
+}
+
+/*
+** Build library name from path, lib and extensions
+*/
+PR_IMPLEMENT(char*) 
+PR_GetLibraryName(const char *path, const char *lib)
+{
+    char *fullname;
+
+#ifdef XP_PC
+    if (strstr(lib, PR_DLL_SUFFIX) == NULL)
+    {
+        if (path) {
+            fullname = PR_smprintf("%s\\%s%s", path, lib, PR_DLL_SUFFIX);
+        } else {
+            fullname = PR_smprintf("%s%s", lib, PR_DLL_SUFFIX);
+        }
+    } else {
+        if (path) {
+            fullname = PR_smprintf("%s\\%s", path, lib);
+        } else {
+            fullname = PR_smprintf("%s", lib);
+        }
+    }
+#endif /* XP_PC */
+#if defined(XP_UNIX) || defined(XP_BEOS)
+    if (strstr(lib, PR_DLL_SUFFIX) == NULL)
+    {
+        if (path) {
+            fullname = PR_smprintf("%s/lib%s%s", path, lib, PR_DLL_SUFFIX);
+        } else {
+            fullname = PR_smprintf("lib%s%s", lib, PR_DLL_SUFFIX);
+        }
+    } else {
+        if (path) {
+            fullname = PR_smprintf("%s/%s", path, lib);
+        } else {
+            fullname = PR_smprintf("%s", lib);
+        }
+    }
+#endif /* XP_UNIX || XP_BEOS */
+    return fullname;
+}
+
+/*
+** Free the memory allocated, for the caller, by PR_GetLibraryName
+*/
+PR_IMPLEMENT(void) 
+PR_FreeLibraryName(char *mem)
+{
+    PR_smprintf_free(mem);
+}
+
+static PRLibrary* 
+pr_UnlockedFindLibrary(const char *name)
+{
+    PRLibrary* lm = pr_loadmap;
+    const char* np = strrchr(name, PR_DIRECTORY_SEPARATOR);
+    np = np ? np + 1 : name;
+    while (lm) {
+    const char* cp = strrchr(lm->name, PR_DIRECTORY_SEPARATOR);
+    cp = cp ? cp + 1 : lm->name;
+#ifdef WIN32
+        /* Windows DLL names are case insensitive... */
+    if (strcmpi(np, cp) == 0) 
+#elif defined(XP_OS2)
+    if (stricmp(np, cp) == 0)
+#else
+    if (strcmp(np, cp)  == 0) 
+#endif
+    {
+        /* found */
+        lm->refCount++;
+        PR_LOG(_pr_linker_lm, PR_LOG_MIN,
+           ("%s incr => %d (find lib)",
+            lm->name, lm->refCount));
+        return lm;
+    }
+    lm = lm->next;
+    }
+    return NULL;
+}
+
+PR_IMPLEMENT(PRLibrary*)
+PR_LoadLibraryWithFlags(PRLibSpec libSpec, PRIntn flags)
+{
+    if (flags == 0) {
+        flags = _PR_DEFAULT_LD_FLAGS;
+    }
+    switch (libSpec.type) {
+        case PR_LibSpec_Pathname:
+            return pr_LoadLibraryByPathname(libSpec.value.pathname, flags);
+#ifdef WIN32
+        case PR_LibSpec_PathnameU:
+            /*
+             * cast to |char *| and set PR_LD_PATHW flag so that
+             * it can be cast back to PRUnichar* in the callee.
+             */
+            return pr_LoadLibraryByPathname((const char*) 
+                                            libSpec.value.pathname_u, 
+                                            flags | PR_LD_PATHW);
+#endif
+        default:
+            PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+            return NULL;
+    }
+}
+            
+PR_IMPLEMENT(PRLibrary*) 
+PR_LoadLibrary(const char *name)
+{
+    PRLibSpec libSpec;
+
+    libSpec.type = PR_LibSpec_Pathname;
+    libSpec.value.pathname = name;
+    return PR_LoadLibraryWithFlags(libSpec, 0);
+}
+
+#if defined(USE_MACH_DYLD)
+static NSModule
+pr_LoadMachDyldModule(const char *name)
+{
+    NSObjectFileImage ofi;
+    NSModule h = NULL;
+    if (NSCreateObjectFileImageFromFile(name, &ofi)
+            == NSObjectFileImageSuccess) {
+        h = NSLinkModule(ofi, name, NSLINKMODULE_OPTION_PRIVATE
+                         | NSLINKMODULE_OPTION_RETURN_ON_ERROR);
+        if (h == NULL) {
+            NSLinkEditErrors linkEditError;
+            int errorNum;
+            const char *fileName;
+            const char *errorString;
+            NSLinkEditError(&linkEditError, &errorNum, &fileName, &errorString);
+            PR_LOG(_pr_linker_lm, PR_LOG_MIN, 
+                   ("LoadMachDyldModule error %d:%d for file %s:\n%s",
+                    linkEditError, errorNum, fileName, errorString));
+        }
+        if (NSDestroyObjectFileImage(ofi) == FALSE) {
+            if (h) {
+                (void)NSUnLinkModule(h, NSUNLINKMODULE_OPTION_NONE);
+                h = NULL;
+            }
+        }
+    }
+    return h;
+}
+#endif
+
+#if defined(XP_MACOSX) && defined(USE_MACH_DYLD)
+
+/*
+** macLibraryLoadProc is a function definition for a Mac shared library
+** loading method. The "name" param is the same full or partial pathname
+** that was passed to pr_LoadLibraryByPathName. The function must fill
+** in the fields of "lm" which apply to its library type. Returns
+** PR_SUCCESS if successful.
+*/
+
+typedef PRStatus (*macLibraryLoadProc)(const char *name, PRLibrary *lm);
+
+#ifdef __ppc__
+
+/*
+** CFM and its TVectors only exist on PowerPC.  Other OS X architectures
+** only use Mach-O as a native binary format.
+*/
+
+static void* TV2FP(CFMutableDictionaryRef dict, const char* name, void *tvp)
+{
+    static uint32 glue[6] = { 0x3D800000, 0x618C0000, 0x800C0000, 0x804C0004, 0x7C0903A6, 0x4E800420 };
+    uint32* newGlue = NULL;
+
+    if (tvp != NULL) {
+        CFStringRef nameRef = CFStringCreateWithCString(NULL, name, kCFStringEncodingASCII);
+        if (nameRef) {
+            CFMutableDataRef glueData = (CFMutableDataRef) CFDictionaryGetValue(dict, nameRef);
+            if (glueData == NULL) {
+                glueData = CFDataCreateMutable(NULL, sizeof(glue));
+                if (glueData != NULL) {
+                    newGlue = (uint32*) CFDataGetMutableBytePtr(glueData);
+                    memcpy(newGlue, glue, sizeof(glue));
+                    newGlue[0] |= ((UInt32)tvp >> 16);
+                    newGlue[1] |= ((UInt32)tvp & 0xFFFF);
+                    MakeDataExecutable(newGlue, sizeof(glue));
+                    CFDictionaryAddValue(dict, nameRef, glueData);
+                    CFRelease(glueData);
+
+                    PR_LOG(_pr_linker_lm, PR_LOG_MIN, ("TV2FP: created wrapper for CFM function %s().", name));
+                }
+            } else {
+                PR_LOG(_pr_linker_lm, PR_LOG_MIN, ("TV2FP: found wrapper for CFM function %s().", name));
+
+                newGlue = (uint32*) CFDataGetMutableBytePtr(glueData);
+            }
+            CFRelease(nameRef);
+        }
+    }
+    
+    return newGlue;
+}
+
+static PRStatus
+pr_LoadViaCFM(const char *name, PRLibrary *lm)
+{
+    OSErr err;
+    Str255 errName;
+    FSRef ref;
+    FSSpec fileSpec;
+    Boolean tempUnusedBool;
+
+    /*
+     * Make an FSSpec from the path name and call GetDiskFragment.
+     */
+
+    /* Use direct conversion of POSIX path to FSRef to FSSpec. */
+    err = FSPathMakeRef((const UInt8*)name, &ref, NULL);
+    if (err != noErr)
+        return PR_FAILURE;
+    err = FSGetCatalogInfo(&ref, kFSCatInfoNone, NULL, NULL,
+                           &fileSpec, NULL);
+    if (err != noErr)
+        return PR_FAILURE;
+
+    /* Resolve an alias if this was one */
+    err = ResolveAliasFile(&fileSpec, true, &tempUnusedBool,
+                           &tempUnusedBool);
+    if (err != noErr)
+        return PR_FAILURE;
+
+    /* Finally, try to load the library */
+    err = GetDiskFragment(&fileSpec, 0, kCFragGoesToEOF, fileSpec.name,
+                          kLoadCFrag, &lm->connection, &lm->main, errName);
+
+    if (err == noErr && lm->connection) {
+        /*
+         * if we're a mach-o binary, need to wrap all CFM function
+         * pointers. need a hash-table of already seen function
+         * pointers, etc.
+         */
+        lm->wrappers = CFDictionaryCreateMutable(NULL, 16,
+                       &kCFTypeDictionaryKeyCallBacks,
+                       &kCFTypeDictionaryValueCallBacks);
+        if (lm->wrappers) {
+            lm->main = TV2FP(lm->wrappers, "main", lm->main);
+        } else
+            err = memFullErr;
+    }
+    return (err == noErr) ? PR_SUCCESS : PR_FAILURE;
+}
+#endif /* __ppc__ */
+
+/*
+** Creates a CFBundleRef if the pathname refers to a Mac OS X bundle
+** directory. The caller is responsible for calling CFRelease() to
+** deallocate.
+*/
+
+static PRStatus
+pr_LoadCFBundle(const char *name, PRLibrary *lm)
+{
+    CFURLRef bundleURL;
+    CFBundleRef bundle = NULL;
+    char pathBuf[PATH_MAX];
+    const char *resolvedPath;
+    CFStringRef pathRef;
+
+    /* Takes care of relative paths and symlinks */
+    resolvedPath = realpath(name, pathBuf);
+    if (!resolvedPath)
+        return PR_FAILURE;
+        
+    pathRef = CFStringCreateWithCString(NULL, pathBuf, kCFStringEncodingUTF8);
+    if (pathRef) {
+        bundleURL = CFURLCreateWithFileSystemPath(NULL, pathRef,
+                                                  kCFURLPOSIXPathStyle, true);
+        if (bundleURL) {
+            bundle = CFBundleCreate(NULL, bundleURL);
+            CFRelease(bundleURL);
+        }
+        CFRelease(pathRef);
+    }
+
+    lm->bundle = bundle;
+    return (bundle != NULL) ? PR_SUCCESS : PR_FAILURE;
+}
+
+static PRStatus
+pr_LoadViaDyld(const char *name, PRLibrary *lm)
+{
+    lm->dlh = pr_LoadMachDyldModule(name);
+    if (lm->dlh == NULL) {
+        lm->image = NSAddImage(name, NSADDIMAGE_OPTION_RETURN_ON_ERROR
+                               | NSADDIMAGE_OPTION_WITH_SEARCHING);
+        if (lm->image == NULL) {
+            NSLinkEditErrors linkEditError;
+            int errorNum;
+            const char *fileName;
+            const char *errorString;
+            NSLinkEditError(&linkEditError, &errorNum, &fileName, &errorString);
+            PR_LOG(_pr_linker_lm, PR_LOG_MIN, 
+                   ("LoadMachDyldModule error %d:%d for file %s:\n%s",
+                    linkEditError, errorNum, fileName, errorString));
+        }
+    }
+    return (lm->dlh != NULL || lm->image != NULL) ? PR_SUCCESS : PR_FAILURE;
+}
+
+#endif /* XP_MACOSX && USE_MACH_DYLD */
+
+/*
+** Dynamically load a library. Only load libraries once, so scan the load
+** map first.
+*/
+static PRLibrary*
+pr_LoadLibraryByPathname(const char *name, PRIntn flags)
+{
+    PRLibrary *lm;
+    PRLibrary* result = NULL;
+    PRInt32 oserr;
+#ifdef WIN32
+    char utf8name_stack[MAX_PATH];
+    char *utf8name_malloc = NULL;
+    char *utf8name = utf8name_stack;
+    PRUnichar wname_stack[MAX_PATH];
+    PRUnichar *wname_malloc = NULL;
+    PRUnichar *wname = wname_stack;
+    int len;
+#endif
+
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+
+    /* See if library is already loaded */
+    PR_EnterMonitor(pr_linker_lock);
+
+#ifdef WIN32
+    if (flags & PR_LD_PATHW) {
+        /* cast back what's cast to |char *| for the argument passing. */
+        wname = (LPWSTR) name;
+    } else {
+        int wlen = MultiByteToWideChar(CP_ACP, 0, name, -1, NULL, 0);
+        if (wlen > MAX_PATH)
+            wname = wname_malloc = PR_Malloc(wlen * sizeof(PRUnichar));
+        if (wname == NULL ||
+            !MultiByteToWideChar(CP_ACP, 0,  name, -1, wname, wlen)) {
+            oserr = _MD_ERRNO();
+            goto unlock;
+        }
+    }
+    len = WideCharToMultiByte(CP_UTF8, 0, wname, -1, NULL, 0, NULL, NULL);
+    if (len > MAX_PATH)
+        utf8name = utf8name_malloc = PR_Malloc(len);
+    if (utf8name == NULL ||
+        !WideCharToMultiByte(CP_UTF8, 0, wname, -1,
+                             utf8name, len, NULL, NULL)) {
+        oserr = _MD_ERRNO();
+        goto unlock;
+    }
+    /* the list of loaded library names are always kept in UTF-8 
+     * on Win32 platforms */
+    result = pr_UnlockedFindLibrary(utf8name);
+#else
+    result = pr_UnlockedFindLibrary(name);
+#endif
+
+    if (result != NULL) goto unlock;
+
+    lm = PR_NEWZAP(PRLibrary);
+    if (lm == NULL) {
+        oserr = _MD_ERRNO();
+        goto unlock;
+    }
+    lm->staticTable = NULL;
+
+#ifdef XP_OS2  /* Why isn't all this stuff in MD code?! */
+    {
+        HMODULE h;
+        UCHAR pszError[_MAX_PATH];
+        ULONG ulRc = NO_ERROR;
+
+          ulRc = DosLoadModule(pszError, _MAX_PATH, (PSZ) name, &h);
+          if (ulRc != NO_ERROR) {
+              oserr = ulRc;
+              PR_DELETE(lm);
+              goto unlock;
+          }
+          lm->name = strdup(name);
+          lm->dlh  = h;
+          lm->next = pr_loadmap;
+          pr_loadmap = lm;
+    }
+#endif /* XP_OS2 */
+
+#ifdef WIN32
+    {
+    HINSTANCE h;
+
+    h = LoadLibraryExW(wname, NULL,
+                       (flags & PR_LD_ALT_SEARCH_PATH) ?
+                       LOAD_WITH_ALTERED_SEARCH_PATH : 0);
+    if (h == NULL) {
+        oserr = _MD_ERRNO();
+        PR_DELETE(lm);
+        goto unlock;
+    }
+    lm->name = strdup(utf8name);
+    lm->dlh = h;
+    lm->next = pr_loadmap;
+    pr_loadmap = lm;
+    }
+#endif /* WIN32 */
+
+#if defined(XP_MACOSX) && defined(USE_MACH_DYLD)
+    {
+    int     i;
+    PRStatus status;
+
+    static const macLibraryLoadProc loadProcs[] = {
+#ifdef __ppc__
+        pr_LoadViaDyld, pr_LoadCFBundle, pr_LoadViaCFM
+#else  /* __ppc__ */
+        pr_LoadViaDyld, pr_LoadCFBundle
+#endif /* __ppc__ */
+    };
+
+    for (i = 0; i < sizeof(loadProcs) / sizeof(loadProcs[0]); i++) {
+        if ((status = loadProcs[i](name, lm)) == PR_SUCCESS)
+            break;
+    }
+    if (status != PR_SUCCESS) {
+        oserr = cfragNoLibraryErr;
+        PR_DELETE(lm);
+        goto unlock;        
+    }
+    lm->name = strdup(name);
+    lm->next = pr_loadmap;
+    pr_loadmap = lm;
+    }
+#endif
+
+#if defined(XP_UNIX) && !(defined(XP_MACOSX) && defined(USE_MACH_DYLD))
+#ifdef HAVE_DLL
+    {
+#if defined(USE_DLFCN)
+#ifdef NTO
+    /* Neutrino needs RTLD_GROUP to load Netscape plugins. (bug 71179) */
+    int dl_flags = RTLD_GROUP;
+#elif defined(AIX)
+    /* AIX needs RTLD_MEMBER to load an archive member.  (bug 228899) */
+    int dl_flags = RTLD_MEMBER;
+#else
+    int dl_flags = 0;
+#endif
+    void *h = NULL;
+
+    if (flags & PR_LD_LAZY) {
+        dl_flags |= RTLD_LAZY;
+    }
+    if (flags & PR_LD_NOW) {
+        dl_flags |= RTLD_NOW;
+    }
+    if (flags & PR_LD_GLOBAL) {
+        dl_flags |= RTLD_GLOBAL;
+    }
+    if (flags & PR_LD_LOCAL) {
+        dl_flags |= RTLD_LOCAL;
+    }
+#if defined(DARWIN)
+    /* ensure the file exists if it contains a slash character i.e. path */
+    /* DARWIN's dlopen ignores the provided path and checks for the */
+    /* plain filename in DYLD_LIBRARY_PATH */
+    if (strchr(name, PR_DIRECTORY_SEPARATOR) == NULL ||
+        PR_Access(name, PR_ACCESS_EXISTS) == PR_SUCCESS) {
+            h = dlopen(name, dl_flags);
+        }
+#else
+    h = dlopen(name, dl_flags);
+#endif
+#elif defined(USE_HPSHL)
+    int shl_flags = 0;
+    shl_t h;
+
+    /*
+     * Use the DYNAMIC_PATH flag only if 'name' is a plain file
+     * name (containing no directory) to match the behavior of
+     * dlopen().
+     */
+    if (strchr(name, PR_DIRECTORY_SEPARATOR) == NULL) {
+        shl_flags |= DYNAMIC_PATH;
+    }
+    if (flags & PR_LD_LAZY) {
+        shl_flags |= BIND_DEFERRED;
+    }
+    if (flags & PR_LD_NOW) {
+        shl_flags |= BIND_IMMEDIATE;
+    }
+    /* No equivalent of PR_LD_GLOBAL and PR_LD_LOCAL. */
+    h = shl_load(name, shl_flags, 0L);
+#elif defined(USE_MACH_DYLD)
+    NSModule h = pr_LoadMachDyldModule(name);
+#else
+#error Configuration error
+#endif
+    if (!h) {
+        oserr = _MD_ERRNO();
+        PR_DELETE(lm);
+        goto unlock;
+    }
+    lm->name = strdup(name);
+    lm->dlh = h;
+    lm->next = pr_loadmap;
+    pr_loadmap = lm;
+    }
+#endif /* HAVE_DLL */
+#endif /* XP_UNIX && !(XP_MACOSX && USE_MACH_DYLD) */
+
+    lm->refCount = 1;
+
+#ifdef XP_BEOS
+    {
+        image_info info;
+        int32 cookie = 0;
+        image_id imageid = B_ERROR;
+        image_id stubid = B_ERROR;
+        PRLibrary *p;
+
+        for (p = pr_loadmap; p != NULL; p = p->next) {
+            /* hopefully, our caller will always use the same string
+               to refer to the same library */
+            if (strcmp(name, p->name) == 0) {
+                /* we've already loaded this library */
+                imageid = info.id;
+                lm->refCount++;
+                break;
+            }
+        }
+
+        if(imageid == B_ERROR) {
+            /* it appears the library isn't yet loaded - load it now */
+            char stubName [B_PATH_NAME_LENGTH + 1];
+
+            /* the following is a work-around to a "bug" in the beos -
+               the beos system loader allows only 32M (system-wide)
+               to be used by code loaded as "add-ons" (code loaded
+               through the 'load_add_on()' system call, which includes
+               mozilla components), but allows 256M to be used by
+               shared libraries.
+               
+               unfortunately, mozilla is too large to fit into the
+               "add-on" space, so we must trick the loader into
+               loading some of the components as shared libraries.  this
+               is accomplished by creating a "stub" add-on (an empty
+               shared object), and linking it with the component
+               (the actual .so file generated by the build process,
+               without any modifications).  when this stub is loaded
+               by load_add_on(), the loader will automatically load the
+               component into the shared library space.
+            */
+
+            strcpy(stubName, name);
+            strcat(stubName, ".stub");
+
+            /* first, attempt to load the stub (thereby loading the
+               component as a shared library */
+            if ((stubid = load_add_on(stubName)) > B_ERROR) {
+                /* the stub was loaded successfully. */
+                imageid = B_FILE_NOT_FOUND;
+
+                cookie = 0;
+                while (get_next_image_info(0, &cookie, &info) == B_OK) {
+                    const char *endOfSystemName = strrchr(info.name, '/');
+                    const char *endOfPassedName = strrchr(name, '/');
+                    if( 0 == endOfSystemName ) 
+                        endOfSystemName = info.name;
+                    else
+                        endOfSystemName++;
+                    if( 0 == endOfPassedName )
+                        endOfPassedName = name;
+                    else
+                        endOfPassedName++;
+                    if (strcmp(endOfSystemName, endOfPassedName) == 0) {
+                        /* this is the actual component - remember it */
+                        imageid = info.id;
+                        break;
+                    }
+                }
+
+            } else {
+                /* we failed to load the "stub" - try to load the
+                   component directly as an add-on */
+                stubid = B_ERROR;
+                imageid = load_add_on(name);
+            }
+        }
+
+        if (imageid <= B_ERROR) {
+            oserr = imageid;
+            PR_DELETE( lm );
+            goto unlock;
+        }
+        lm->name = strdup(name);
+        lm->dlh = (void*)imageid;
+        lm->stub_dlh = (void*)stubid;
+        lm->next = pr_loadmap;
+        pr_loadmap = lm;
+    }
+#endif
+
+    result = lm;    /* success */
+    PR_LOG(_pr_linker_lm, PR_LOG_MIN, ("Loaded library %s (load lib)", lm->name));
+
+  unlock:
+    if (result == NULL) {
+        PR_SetError(PR_LOAD_LIBRARY_ERROR, oserr);
+        DLLErrorInternal(oserr);  /* sets error text */
+    }
+#ifdef WIN32
+    if (utf8name_malloc) 
+        PR_Free(utf8name_malloc);
+    if (wname_malloc)
+        PR_Free(wname_malloc);
+#endif
+    PR_ExitMonitor(pr_linker_lock);
+    return result;
+}
+
+/*
+** Unload a shared library which was loaded via PR_LoadLibrary
+*/
+PR_IMPLEMENT(PRStatus) 
+PR_UnloadLibrary(PRLibrary *lib)
+{
+    int result = 0;
+    PRStatus status = PR_SUCCESS;
+
+    if (lib == 0) {
+        PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+        return PR_FAILURE;
+    }
+
+    PR_EnterMonitor(pr_linker_lock);
+
+    if (lib->refCount <= 0) {
+        PR_ExitMonitor(pr_linker_lock);
+        PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+        return PR_FAILURE;
+    }
+
+    if (--lib->refCount > 0) {
+    PR_LOG(_pr_linker_lm, PR_LOG_MIN,
+           ("%s decr => %d",
+        lib->name, lib->refCount));
+    goto done;
+    }
+
+#ifdef XP_BEOS
+    if(((image_id)lib->stub_dlh) == B_ERROR)
+        unload_add_on( (image_id) lib->dlh );
+    else
+        unload_add_on( (image_id) lib->stub_dlh);
+#endif
+
+#ifdef XP_UNIX
+#ifdef HAVE_DLL
+#ifdef USE_DLFCN
+    result = dlclose(lib->dlh);
+#elif defined(USE_HPSHL)
+    result = shl_unload(lib->dlh);
+#elif defined(USE_MACH_DYLD)
+    if (lib->dlh)
+        result = NSUnLinkModule(lib->dlh, NSUNLINKMODULE_OPTION_NONE) ? 0 : -1;
+#else
+#error Configuration error
+#endif
+#endif /* HAVE_DLL */
+#endif /* XP_UNIX */
+#ifdef XP_PC
+    if (lib->dlh) {
+        FreeLibrary((HINSTANCE)(lib->dlh));
+        lib->dlh = (HINSTANCE)NULL;
+    }
+#endif  /* XP_PC */
+
+#if defined(XP_MACOSX) && defined(USE_MACH_DYLD)
+    /* Close the connection */
+    if (lib->connection)
+        CloseConnection(&(lib->connection));
+    if (lib->bundle)
+        CFRelease(lib->bundle);
+    if (lib->wrappers)
+        CFRelease(lib->wrappers);
+    /* No way to unload an image (lib->image) */
+#endif
+
+    /* unlink from library search list */
+    if (pr_loadmap == lib)
+        pr_loadmap = pr_loadmap->next;
+    else if (pr_loadmap != NULL) {
+        PRLibrary* prev = pr_loadmap;
+        PRLibrary* next = pr_loadmap->next;
+        while (next != NULL) {
+            if (next == lib) {
+                prev->next = next->next;
+                goto freeLib;
+            }
+            prev = next;
+            next = next->next;
+        }
+        /*
+         * fail (the library is not on the _pr_loadmap list),
+         * but don't wipe out an error from dlclose/shl_unload.
+         */
+        PR_NOT_REACHED("_pr_loadmap and lib->refCount inconsistent");
+        if (result == 0) {
+            PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+            status = PR_FAILURE;
+        }
+    }
+    /*
+     * We free the PRLibrary structure whether dlclose/shl_unload
+     * succeeds or not.
+     */
+
+  freeLib:
+    PR_LOG(_pr_linker_lm, PR_LOG_MIN, ("Unloaded library %s", lib->name));
+    free(lib->name);
+    lib->name = NULL;
+    PR_DELETE(lib);
+    if (result != 0) {
+        PR_SetError(PR_UNLOAD_LIBRARY_ERROR, _MD_ERRNO());
+        DLLErrorInternal(_MD_ERRNO());
+        status = PR_FAILURE;
+    }
+
+done:
+    PR_ExitMonitor(pr_linker_lock);
+    return status;
+}
+
+static void* 
+pr_FindSymbolInLib(PRLibrary *lm, const char *name)
+{
+    void *f = NULL;
+#ifdef XP_OS2
+    int rc;
+#endif
+
+    if (lm->staticTable != NULL) {
+        const PRStaticLinkTable* tp;
+        for (tp = lm->staticTable; tp->name; tp++) {
+            if (strcmp(name, tp->name) == 0) {
+                return (void*) tp->fp;
+            }
+        }
+        /* 
+        ** If the symbol was not found in the static table then check if
+        ** the symbol was exported in the DLL... Win16 only!!
+        */
+#if !defined(WIN16) && !defined(XP_BEOS)
+        PR_SetError(PR_FIND_SYMBOL_ERROR, 0);
+        return (void*)NULL;
+#endif
+    }
+    
+#ifdef XP_OS2
+    rc = DosQueryProcAddr(lm->dlh, 0, (PSZ) name, (PFN *) &f);
+#if defined(NEED_LEADING_UNDERSCORE)
+    /*
+     * Older plugins (not built using GCC) will have symbols that are not
+     * underscore prefixed.  We check for that here.
+     */
+    if (rc != NO_ERROR) {
+        name++;
+        DosQueryProcAddr(lm->dlh, 0, (PSZ) name, (PFN *) &f);
+    }
+#endif
+#endif  /* XP_OS2 */
+
+#ifdef WIN32
+    f = GetProcAddress(lm->dlh, name);
+#endif  /* WIN32 */
+
+#if defined(XP_MACOSX) && defined(USE_MACH_DYLD)
+/* add this offset to skip the leading underscore in name */
+#define SYM_OFFSET 1
+    if (lm->bundle) {
+        CFStringRef nameRef = CFStringCreateWithCString(NULL, name + SYM_OFFSET, kCFStringEncodingASCII);
+        if (nameRef) {
+            f = CFBundleGetFunctionPointerForName(lm->bundle, nameRef);
+            CFRelease(nameRef);
+        }
+    }
+    if (lm->connection) {
+        Ptr                 symAddr;
+        CFragSymbolClass    symClass;
+        Str255              pName;
+        
+        PR_LOG(_pr_linker_lm, PR_LOG_MIN, ("Looking up symbol: %s", name + SYM_OFFSET));
+        
+        c2pstrcpy(pName, name + SYM_OFFSET);
+        
+        f = (FindSymbol(lm->connection, pName, &symAddr, &symClass) == noErr) ? symAddr : NULL;
+        
+#ifdef __ppc__
+        /* callers expect mach-o function pointers, so must wrap tvectors with glue. */
+        if (f && symClass == kTVectorCFragSymbol) {
+            f = TV2FP(lm->wrappers, name + SYM_OFFSET, f);
+        }
+#endif /* __ppc__ */
+        
+        if (f == NULL && strcmp(name + SYM_OFFSET, "main") == 0) f = lm->main;
+    }
+    if (lm->image) {
+        NSSymbol symbol;
+        symbol = NSLookupSymbolInImage(lm->image, name,
+                 NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
+                 | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
+        if (symbol != NULL)
+            f = NSAddressOfSymbol(symbol);
+        else
+            f = NULL;
+    }
+#undef SYM_OFFSET
+#endif /* XP_MACOSX && USE_MACH_DYLD */
+
+#ifdef XP_BEOS
+    if( B_NO_ERROR != get_image_symbol( (image_id)lm->dlh, name, B_SYMBOL_TYPE_TEXT, &f ) ) {
+        f = NULL;
+    }
+#endif
+
+#ifdef XP_UNIX
+#ifdef HAVE_DLL
+#ifdef USE_DLFCN
+    f = dlsym(lm->dlh, name);
+#elif defined(USE_HPSHL)
+    if (shl_findsym(&lm->dlh, name, TYPE_PROCEDURE, &f) == -1) {
+        f = NULL;
+    }
+#elif defined(USE_MACH_DYLD)
+    if (lm->dlh) {
+        NSSymbol symbol;
+        symbol = NSLookupSymbolInModule(lm->dlh, name);
+        if (symbol != NULL)
+            f = NSAddressOfSymbol(symbol);
+        else
+            f = NULL;
+    }
+#endif
+#endif /* HAVE_DLL */
+#endif /* XP_UNIX */
+    if (f == NULL) {
+        PR_SetError(PR_FIND_SYMBOL_ERROR, _MD_ERRNO());
+        DLLErrorInternal(_MD_ERRNO());
+    }
+    return f;
+}
+
+/*
+** Called by class loader to resolve missing native's
+*/
+PR_IMPLEMENT(void*) 
+PR_FindSymbol(PRLibrary *lib, const char *raw_name)
+{
+    void *f = NULL;
+#if defined(NEED_LEADING_UNDERSCORE)
+    char *name;
+#else
+    const char *name;
+#endif
+    /*
+    ** Mangle the raw symbol name in any way that is platform specific.
+    */
+#if defined(NEED_LEADING_UNDERSCORE)
+    /* Need a leading _ */
+    name = PR_smprintf("_%s", raw_name);
+#elif defined(AIX)
+    /*
+    ** AIX with the normal linker put's a "." in front of the symbol
+    ** name.  When use "svcc" and "svld" then the "." disappears. Go
+    ** figure.
+    */
+    name = raw_name;
+#else
+    name = raw_name;
+#endif
+
+    PR_EnterMonitor(pr_linker_lock);
+    PR_ASSERT(lib != NULL);
+    f = pr_FindSymbolInLib(lib, name);
+
+#if defined(NEED_LEADING_UNDERSCORE)
+    PR_smprintf_free(name);
+#endif
+
+    PR_ExitMonitor(pr_linker_lock);
+    return f;
+}
+
+/*
+** Return the address of the function 'raw_name' in the library 'lib'
+*/
+PR_IMPLEMENT(PRFuncPtr) 
+PR_FindFunctionSymbol(PRLibrary *lib, const char *raw_name)
+{
+    return ((PRFuncPtr) PR_FindSymbol(lib, raw_name));
+}
+
+PR_IMPLEMENT(void*) 
+PR_FindSymbolAndLibrary(const char *raw_name, PRLibrary* *lib)
+{
+    void *f = NULL;
+#if defined(NEED_LEADING_UNDERSCORE)
+    char *name;
+#else
+    const char *name;
+#endif
+    PRLibrary* lm;
+
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+    /*
+    ** Mangle the raw symbol name in any way that is platform specific.
+    */
+#if defined(NEED_LEADING_UNDERSCORE)
+    /* Need a leading _ */
+    name = PR_smprintf("_%s", raw_name);
+#elif defined(AIX)
+    /*
+    ** AIX with the normal linker put's a "." in front of the symbol
+    ** name.  When use "svcc" and "svld" then the "." disappears. Go
+    ** figure.
+    */
+    name = raw_name;
+#else
+    name = raw_name;
+#endif
+
+    PR_EnterMonitor(pr_linker_lock);
+
+    /* search all libraries */
+    for (lm = pr_loadmap; lm != NULL; lm = lm->next) {
+        f = pr_FindSymbolInLib(lm, name);
+        if (f != NULL) {
+            *lib = lm;
+            lm->refCount++;
+            PR_LOG(_pr_linker_lm, PR_LOG_MIN,
+                       ("%s incr => %d (for %s)",
+                    lm->name, lm->refCount, name));
+            break;
+        }
+    }
+#if defined(NEED_LEADING_UNDERSCORE)
+    PR_smprintf_free(name);
+#endif
+
+    PR_ExitMonitor(pr_linker_lock);
+    return f;
+}
+
+PR_IMPLEMENT(PRFuncPtr) 
+PR_FindFunctionSymbolAndLibrary(const char *raw_name, PRLibrary* *lib)
+{
+    return ((PRFuncPtr) PR_FindSymbolAndLibrary(raw_name, lib));
+}
+
+/*
+** Add a static library to the list of loaded libraries. If LoadLibrary
+** is called with the name then we will pretend it was already loaded
+*/
+PR_IMPLEMENT(PRLibrary*) 
+PR_LoadStaticLibrary(const char *name, const PRStaticLinkTable *slt)
+{
+    PRLibrary *lm=NULL;
+    PRLibrary* result = NULL;
+
+    if (!_pr_initialized) _PR_ImplicitInitialization();
+
+    /* See if library is already loaded */
+    PR_EnterMonitor(pr_linker_lock);
+
+    /* If the lbrary is already loaded, then add the static table information... */
+    result = pr_UnlockedFindLibrary(name);
+    if (result != NULL) {
+        PR_ASSERT( (result->staticTable == NULL) || (result->staticTable == slt) );
+        result->staticTable = slt;
+        goto unlock;
+    }
+
+    /* Add library to list...Mark it static */
+    lm = PR_NEWZAP(PRLibrary);
+    if (lm == NULL) goto unlock;
+
+    lm->name = strdup(name);
+    lm->refCount    = 1;
+    lm->dlh         = pr_exe_loadmap ? pr_exe_loadmap->dlh : 0;
+    lm->staticTable = slt;
+    lm->next        = pr_loadmap;
+    pr_loadmap      = lm;
+
+    result = lm;    /* success */
+    PR_ASSERT(lm->refCount == 1);
+    PR_LOG(_pr_linker_lm, PR_LOG_MIN, ("Loaded library %s (static lib)", lm->name));
+  unlock:
+    PR_ExitMonitor(pr_linker_lock);
+    return result;
+}
+
+PR_IMPLEMENT(char *)
+PR_GetLibraryFilePathname(const char *name, PRFuncPtr addr)
+{
+#if defined(USE_DLFCN) && defined(HAVE_DLADDR)
+    Dl_info dli;
+    char *result;
+
+    if (dladdr((void *)addr, &dli) == 0) {
+        PR_SetError(PR_LIBRARY_NOT_LOADED_ERROR, _MD_ERRNO());
+        DLLErrorInternal(_MD_ERRNO());
+        return NULL;
+    }
+    result = PR_Malloc(strlen(dli.dli_fname)+1);
+    if (result != NULL) {
+        strcpy(result, dli.dli_fname);
+    }
+    return result;
+#elif defined(USE_MACH_DYLD)
+    char *result;
+    const char *image_name;
+    int i, count = _dyld_image_count();
+
+    for (i = 0; i < count; i++) {
+        image_name = _dyld_get_image_name(i);
+        if (strstr(image_name, name) != NULL) {
+            result = PR_Malloc(strlen(image_name)+1);
+            if (result != NULL) {
+                strcpy(result, image_name);
+            }
+            return result;
+        }
+    }
+    PR_SetError(PR_LIBRARY_NOT_LOADED_ERROR, 0);
+    return NULL;
+#elif defined(AIX)
+    char *result;
+#define LD_INFO_INCREMENT 64
+    struct ld_info *info;
+    unsigned int info_length = LD_INFO_INCREMENT * sizeof(struct ld_info);
+    struct ld_info *infop;
+    int loadflags = L_GETINFO | L_IGNOREUNLOAD;
+
+    for (;;) {
+        info = PR_Malloc(info_length);
+        if (info == NULL) {
+            return NULL;
+        }
+        /* If buffer is too small, loadquery fails with ENOMEM. */
+        if (loadquery(loadflags, info, info_length) != -1) {
+            break;
+        }
+        /*
+         * Calling loadquery when compiled for 64-bit with the
+         * L_IGNOREUNLOAD flag can cause an invalid argument error
+         * on AIX 5.1. Detect this error the first time that
+         * loadquery is called, and try calling it again without
+         * this flag set.
+         */
+        if (errno == EINVAL && (loadflags & L_IGNOREUNLOAD)) {
+            loadflags &= ~L_IGNOREUNLOAD;
+            if (loadquery(loadflags, info, info_length) != -1) {
+                break;
+            }
+        }
+        PR_Free(info);
+        if (errno != ENOMEM) {
+            /* should not happen */
+            _PR_MD_MAP_DEFAULT_ERROR(_MD_ERRNO());
+            return NULL;
+        }
+        /* retry with a larger buffer */
+        info_length += LD_INFO_INCREMENT * sizeof(struct ld_info);
+    }
+
+    for (infop = info;
+         ;
+         infop = (struct ld_info *)((char *)infop + infop->ldinfo_next)) {
+        unsigned long start = (unsigned long)infop->ldinfo_dataorg;
+        unsigned long end = start + infop->ldinfo_datasize;
+        if (start <= (unsigned long)addr && end > (unsigned long)addr) {
+            result = PR_Malloc(strlen(infop->ldinfo_filename)+1);
+            if (result != NULL) {
+                strcpy(result, infop->ldinfo_filename);
+            }
+            break;
+        }
+        if (!infop->ldinfo_next) {
+            PR_SetError(PR_LIBRARY_NOT_LOADED_ERROR, 0);
+            result = NULL;
+            break;
+        }
+    }
+    PR_Free(info);
+    return result;
+#elif defined(OSF1)
+    /* Contributed by Steve Streeter of HP */
+    ldr_process_t process, ldr_my_process();
+    ldr_module_t mod_id;
+    ldr_module_info_t info;
+    ldr_region_t regno;
+    ldr_region_info_t reginfo;
+    size_t retsize;
+    int rv;
+    char *result;
+
+    /* Get process for which dynamic modules will be listed */
+
+    process = ldr_my_process();
+
+    /* Attach to process */
+
+    rv = ldr_xattach(process);
+    if (rv) {
+        /* should not happen */
+        _PR_MD_MAP_DEFAULT_ERROR(_MD_ERRNO());
+        return NULL;
+    }
+
+    /* Print information for list of modules */
+
+    mod_id = LDR_NULL_MODULE;
+
+    for (;;) {
+
+        /* Get information for the next module in the module list. */
+
+        ldr_next_module(process, &mod_id);
+        if (ldr_inq_module(process, mod_id, &info, sizeof(info),
+                           &retsize) != 0) {
+            /* No more modules */
+            break;
+        }
+        if (retsize < sizeof(info)) {
+            continue;
+        }
+
+        /*
+         * Get information for each region in the module and check if any
+         * contain the address of this function.
+         */
+
+        for (regno = 0; ; regno++) {
+            if (ldr_inq_region(process, mod_id, regno, &reginfo,
+                               sizeof(reginfo), &retsize) != 0) {
+                /* No more regions */
+                break;
+            }
+            if (((unsigned long)reginfo.lri_mapaddr <=
+                (unsigned long)addr) &&
+                (((unsigned long)reginfo.lri_mapaddr + reginfo.lri_size) >
+                (unsigned long)addr)) {
+                /* Found it. */
+                result = PR_Malloc(strlen(info.lmi_name)+1);
+                if (result != NULL) {
+                    strcpy(result, info.lmi_name);
+                }
+                return result;
+            }
+        }
+    }
+    PR_SetError(PR_LIBRARY_NOT_LOADED_ERROR, 0);
+    return NULL;
+#elif defined(HPUX) && defined(USE_HPSHL)
+    int index;
+    struct shl_descriptor desc;
+    char *result;
+
+    for (index = 0; shl_get_r(index, &desc) == 0; index++) {
+        if (strstr(desc.filename, name) != NULL) {
+            result = PR_Malloc(strlen(desc.filename)+1);
+            if (result != NULL) {
+                strcpy(result, desc.filename);
+            }
+            return result;
+        }
+    }
+    /*
+     * Since the index value of a library is decremented if
+     * a library preceding it in the shared library search
+     * list was unloaded, it is possible that we missed some
+     * libraries as we went up the list.  So we should go
+     * down the list to be sure that we not miss anything.
+     */
+    for (index--; index >= 0; index--) {
+        if ((shl_get_r(index, &desc) == 0)
+                && (strstr(desc.filename, name) != NULL)) {
+            result = PR_Malloc(strlen(desc.filename)+1);
+            if (result != NULL) {
+                strcpy(result, desc.filename);
+            }
+            return result;
+        }
+    }
+    PR_SetError(PR_LIBRARY_NOT_LOADED_ERROR, 0);
+    return NULL;
+#elif defined(HPUX) && defined(USE_DLFCN)
+    struct load_module_desc desc;
+    char *result;
+    const char *module_name;
+
+    if (dlmodinfo((unsigned long)addr, &desc, sizeof desc, NULL, 0, 0) == 0) {
+        PR_SetError(PR_LIBRARY_NOT_LOADED_ERROR, _MD_ERRNO());
+        DLLErrorInternal(_MD_ERRNO());
+        return NULL;
+    }
+    module_name = dlgetname(&desc, sizeof desc, NULL, 0, 0);
+    if (module_name == NULL) {
+        /* should not happen */
+        _PR_MD_MAP_DEFAULT_ERROR(_MD_ERRNO());
+        DLLErrorInternal(_MD_ERRNO());
+        return NULL;
+    }
+    result = PR_Malloc(strlen(module_name)+1);
+    if (result != NULL) {
+        strcpy(result, module_name);
+    }
+    return result;
+#elif defined(WIN32)
+    PRUnichar wname[MAX_PATH];
+    HMODULE handle = NULL;
+    PRUnichar module_name[MAX_PATH];
+    int len;
+    char *result;
+
+    if (MultiByteToWideChar(CP_ACP, 0, name, -1, wname, MAX_PATH)) {
+        handle = GetModuleHandleW(wname);
+    }
+    if (handle == NULL) {
+        PR_SetError(PR_LIBRARY_NOT_LOADED_ERROR, _MD_ERRNO());
+        DLLErrorInternal(_MD_ERRNO());
+        return NULL;
+    }
+    if (GetModuleFileNameW(handle, module_name, MAX_PATH) == 0) {
+        /* should not happen */
+        _PR_MD_MAP_DEFAULT_ERROR(_MD_ERRNO());
+        return NULL;
+    }
+    len = WideCharToMultiByte(CP_ACP, 0, module_name, -1,
+                              NULL, 0, NULL, NULL);
+    if (len == 0) {
+        _PR_MD_MAP_DEFAULT_ERROR(_MD_ERRNO());
+        return NULL;
+    }
+    result = PR_Malloc(len * sizeof(PRUnichar));
+    if (result != NULL) {
+        WideCharToMultiByte(CP_ACP, 0, module_name, -1,
+                            result, len, NULL, NULL);
+    }
+    return result;
+#elif defined(XP_OS2)
+    HMODULE module = NULL;
+    char module_name[_MAX_PATH];
+    char *result;
+    APIRET ulrc = DosQueryModFromEIP(&module, NULL, 0, NULL, NULL, (ULONG) addr);
+    if ((NO_ERROR != ulrc) || (NULL == module) ) {
+        PR_SetError(PR_LIBRARY_NOT_LOADED_ERROR, _MD_ERRNO());
+        DLLErrorInternal(_MD_ERRNO());
+        return NULL;
+    }
+    ulrc = DosQueryModuleName(module, sizeof module_name, module_name);
+    if (NO_ERROR != ulrc) {
+        /* should not happen */
+        _PR_MD_MAP_DEFAULT_ERROR(_MD_ERRNO());
+        return NULL;
+    }
+    result = PR_Malloc(strlen(module_name)+1);
+    if (result != NULL) {
+        strcpy(result, module_name);
+    }
+    return result;
+#else
+    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+    return NULL;
+#endif
+}
diff --git a/pr/src/malloc/.cvsignore b/pr/src/malloc/.cvsignore
new file mode 100644
index 0000000..f3c7a7c
--- /dev/null
+++ b/pr/src/malloc/.cvsignore
@@ -0,0 +1 @@
+Makefile
diff --git a/pr/src/malloc/Makefile.in b/pr/src/malloc/Makefile.in
new file mode 100644
index 0000000..51f2a5a
--- /dev/null
+++ b/pr/src/malloc/Makefile.in
@@ -0,0 +1,28 @@
+# 
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#! gmake
+
+MOD_DEPTH	= ../../..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+
+include $(MOD_DEPTH)/config/autoconf.mk
+
+include $(topsrcdir)/config/config.mk
+
+TARGETS	= $(OBJS)
+
+INCLUDES = -I$(dist_includedir) -I$(topsrcdir)/pr/include -I$(topsrcdir)/pr/include/private
+
+DEFINES += -D_NSPR_BUILD_
+
+CSRCS = prmalloc.c prmem.c
+
+include $(topsrcdir)/config/rules.mk
+
+export:: $(TARGETS)
+
diff --git a/pr/src/malloc/prmalloc.c b/pr/src/malloc/prmalloc.c
new file mode 100644
index 0000000..174d0da
--- /dev/null
+++ b/pr/src/malloc/prmalloc.c
@@ -0,0 +1,1142 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "primpl.h"
+
+/*
+** We override malloc etc. on any platform which has preemption +
+** nspr20 user level threads.  When we're debugging, we can make our
+** version of malloc fail occasionally.
+*/
+#ifdef _PR_OVERRIDE_MALLOC
+
+/*
+** Thread safe version of malloc, calloc, realloc, free
+*/
+#include <stdarg.h>
+
+#ifdef DEBUG
+#define SANITY
+#define EXTRA_SANITY
+#else
+#undef SANITY
+#undef EXTRA_SANITY
+#endif
+
+/* Forward decls */
+void *_PR_UnlockedMalloc(size_t size);
+void _PR_UnlockedFree(void *ptr);
+void *_PR_UnlockedRealloc(void *ptr, size_t size);
+void *_PR_UnlockedCalloc(size_t n, size_t elsize);
+
+/************************************************************************/
+
+/*
+ * ----------------------------------------------------------------------------
+ * "THE BEER-WARE LICENSE" (Revision 42):
+ * <phk@FreeBSD.ORG> wrote this file.  As long as you retain this notice you
+ * can do whatever you want with this stuff. If we meet some day, and you think
+ * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
+ * ----------------------------------------------------------------------------
+ *
+ */
+
+/*
+ * Defining SANITY will enable some checks which will tell you if the users
+ * program did botch something
+ */
+
+/*
+ * Defining EXTRA_SANITY will enable some checks which are mostly related
+ * to internal conditions in malloc.c
+ */
+
+/*
+ * Very verbose progress on stdout...
+ */
+#if 0
+#  define TRACE(foo)    printf  foo
+static int malloc_event;
+#else
+#  define TRACE(foo)	
+#endif
+
+/* XXX Pick a number, any number */
+#   define malloc_pagesize		4096UL
+#   define malloc_pageshift		12UL
+
+#ifdef XP_UNIX
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#endif
+
+/*
+ * This structure describes a page's worth of chunks.
+ */
+
+struct pginfo {
+    struct pginfo	*next;	/* next on the free list */
+    char		*page;	/* Pointer to the page */
+    u_short		size;	/* size of this page's chunks */
+    u_short		shift;	/* How far to shift for this size chunks */
+    u_short		free;	/* How many free chunks */
+    u_short		total;	/* How many chunk */
+    u_long		bits[1]; /* Which chunks are free */
+};
+
+struct pgfree {
+    struct pgfree	*next;	/* next run of free pages */
+    struct pgfree	*prev;	/* prev run of free pages */
+    char		*page;	/* pointer to free pages */
+    char		*end;	/* pointer to end of free pages */
+    u_long		size;	/* number of bytes free */
+};
+
+/*
+ * How many bits per u_long in the bitmap.
+ * Change only if not 8 bits/byte
+ */
+#define	MALLOC_BITS	(8*sizeof(u_long))
+
+/*
+ * Magic values to put in the page_directory
+ */
+#define MALLOC_NOT_MINE	((struct pginfo*) 0)
+#define MALLOC_FREE 	((struct pginfo*) 1)
+#define MALLOC_FIRST	((struct pginfo*) 2)
+#define MALLOC_FOLLOW	((struct pginfo*) 3)
+#define MALLOC_MAGIC	((struct pginfo*) 4)
+
+/*
+ * Set to one when malloc_init has been called
+ */
+static	unsigned	initialized;
+
+/*
+ * The size of a page.
+ * Must be a integral multiplum of the granularity of mmap(2).
+ * Your toes will curl if it isn't a power of two
+ */
+#define malloc_pagemask	((malloc_pagesize)-1)
+
+/*
+ * The size of the largest chunk.
+ * Half a page.
+ */
+#define malloc_maxsize	((malloc_pagesize)>>1)
+
+/*
+ * malloc_pagesize == 1 << malloc_pageshift
+ */
+#ifndef malloc_pageshift
+static	unsigned	malloc_pageshift;
+#endif /* malloc_pageshift */
+
+/*
+ * The smallest allocation we bother about.
+ * Must be power of two
+ */
+#ifndef malloc_minsize
+static	unsigned  malloc_minsize;
+#endif /* malloc_minsize */
+
+/*
+ * The largest chunk we care about.
+ * Must be smaller than pagesize
+ * Must be power of two
+ */
+#ifndef malloc_maxsize
+static	unsigned  malloc_maxsize;
+#endif /* malloc_maxsize */
+
+#ifndef malloc_cache
+static	unsigned  malloc_cache;
+#endif /* malloc_cache */
+
+/*
+ * The offset from pagenumber to index into the page directory
+ */
+static	u_long  malloc_origo;
+
+/*
+ * The last index in the page directory we care about
+ */
+static	u_long  last_index;
+
+/*
+ * Pointer to page directory.
+ * Allocated "as if with" malloc
+ */
+static	struct	pginfo **page_dir;
+
+/*
+ * How many slots in the page directory
+ */
+static	unsigned	malloc_ninfo;
+
+/*
+ * Free pages line up here 
+ */
+static struct pgfree	free_list;
+
+/*
+ * Abort() if we fail to get VM ?
+ */
+static int malloc_abort;
+
+#ifdef SANITY
+/*
+ * Are we trying to die ?
+ */
+static int suicide;
+#endif
+
+/*
+ * dump statistics
+ */
+static int malloc_stats;
+
+/*
+ * always realloc ?
+ */
+static int malloc_realloc;
+
+/*
+ * my last break.
+ */
+static void *malloc_brk;
+
+/*
+ * one location cache for free-list holders
+ */
+static struct pgfree *px;
+
+static int set_pgdir(void *ptr, struct  pginfo *info);
+static int extend_page_directory(u_long index);
+
+#ifdef SANITY
+void
+malloc_dump(FILE *fd)
+{
+    struct pginfo **pd;
+    struct pgfree *pf;
+    int j;
+
+    pd = page_dir;
+
+    /* print out all the pages */
+    for(j=0;j<=last_index;j++) {
+	fprintf(fd,"%08lx %5d ",(j+malloc_origo) << malloc_pageshift,j);
+	if (pd[j] == MALLOC_NOT_MINE) {
+	    for(j++;j<=last_index && pd[j] == MALLOC_NOT_MINE;j++)
+		;
+	    j--;
+	    fprintf(fd,".. %5d not mine\n",	j);
+	} else if (pd[j] == MALLOC_FREE) {
+	    for(j++;j<=last_index && pd[j] == MALLOC_FREE;j++)
+		;
+	    j--;
+	    fprintf(fd,".. %5d free\n", j);
+	} else if (pd[j] == MALLOC_FIRST) {
+	    for(j++;j<=last_index && pd[j] == MALLOC_FOLLOW;j++)
+		;
+	    j--;
+	    fprintf(fd,".. %5d in use\n", j);
+	} else if (pd[j] < MALLOC_MAGIC) {
+	    fprintf(fd,"(%p)\n", pd[j]);
+	} else {
+	    fprintf(fd,"%p %d (of %d) x %d @ %p --> %p\n",
+		pd[j],pd[j]->free, pd[j]->total, 
+		pd[j]->size, pd[j]->page, pd[j]->next);
+	}
+    }
+
+    for(pf=free_list.next; pf; pf=pf->next) {
+	fprintf(fd,"Free: @%p [%p...%p[ %ld ->%p <-%p\n",
+		pf,pf->page,pf->end,pf->size,pf->prev,pf->next);
+	if (pf == pf->next) {
+		fprintf(fd,"Free_list loops.\n");
+		break;
+	}
+    }
+
+    /* print out various info */
+    fprintf(fd,"Minsize\t%d\n",malloc_minsize);
+    fprintf(fd,"Maxsize\t%ld\n",malloc_maxsize);
+    fprintf(fd,"Pagesize\t%ld\n",malloc_pagesize);
+    fprintf(fd,"Pageshift\t%ld\n",malloc_pageshift);
+    fprintf(fd,"FirstPage\t%ld\n",malloc_origo);
+    fprintf(fd,"LastPage\t%ld %lx\n",last_index+malloc_pageshift,
+	(last_index + malloc_pageshift) << malloc_pageshift);
+    fprintf(fd,"Break\t%ld\n",(u_long)sbrk(0) >> malloc_pageshift);
+}
+
+static void wrterror(char *fmt, ...)
+{
+    char *q = "malloc() error: ";
+    char buf[100];
+    va_list ap;
+
+    suicide = 1;
+
+    va_start(ap, fmt);
+    PR_vsnprintf(buf, sizeof(buf), fmt, ap);
+    va_end(ap);
+    fputs(q, stderr);
+    fputs(buf, stderr);
+
+    malloc_dump(stderr);
+    PR_Abort();
+}
+
+static void wrtwarning(char *fmt, ...)
+{
+    char *q = "malloc() warning: ";
+    char buf[100];
+    va_list ap;
+
+    va_start(ap, fmt);
+    PR_vsnprintf(buf, sizeof(buf), fmt, ap);
+    va_end(ap);
+    fputs(q, stderr);
+    fputs(buf, stderr);
+}
+#endif /* SANITY */
+
+
+/*
+ * Allocate a number of pages from the OS
+ */
+static caddr_t
+map_pages(int pages, int update)
+{
+    caddr_t result,tail;
+
+    result = ((caddr_t)sbrk(0)) + malloc_pagemask - 1;
+    result = (caddr_t) ((u_long)result & ~malloc_pagemask);
+    tail = result + (pages << malloc_pageshift);
+    if (!brk(tail)) {
+	last_index = ((u_long)tail >> malloc_pageshift) - malloc_origo -1;
+	malloc_brk = tail;
+	TRACE(("%6d S %p .. %p\n",malloc_event++, result, tail));
+	if (!update || last_index < malloc_ninfo ||
+	  extend_page_directory(last_index))
+	    return result;
+    }
+    TRACE(("%6d s %d %p %d\n",malloc_event++,pages,sbrk(0),errno));
+#ifdef EXTRA_SANITY
+    wrterror("map_pages fails\n");
+#endif
+    return 0;
+}
+
+#define set_bit(_pi,_bit) \
+    (_pi)->bits[(_bit)/MALLOC_BITS] |= 1L<<((_bit)%MALLOC_BITS)
+
+#define clr_bit(_pi,_bit) \
+    (_pi)->bits[(_bit)/MALLOC_BITS] &= ~(1L<<((_bit)%MALLOC_BITS));
+
+#define tst_bit(_pi,_bit) \
+    ((_pi)->bits[(_bit)/MALLOC_BITS] & (1L<<((_bit)%MALLOC_BITS)))
+
+/*
+ * Extend page directory
+ */
+static int
+extend_page_directory(u_long index)
+{
+    struct  pginfo **young, **old;
+    int i;
+
+    TRACE(("%6d E %lu\n",malloc_event++,index));
+    
+    /* Make it this many pages */
+    i = index * sizeof *page_dir;
+    i /= malloc_pagesize;
+    i += 2;
+
+    /* Get new pages, if you used this much mem you don't care :-) */
+    young = (struct pginfo**) map_pages(i,0);
+    if (!young)
+	return 0;
+
+    /* Copy the old stuff */
+    memset(young, 0, i * malloc_pagesize);
+    memcpy(young, page_dir,
+	    malloc_ninfo * sizeof *page_dir);
+
+    /* register the new size */
+    malloc_ninfo = i * malloc_pagesize / sizeof *page_dir;
+
+    /* swap the pointers */
+    old = page_dir;
+    page_dir = young;
+
+    /* Mark the pages */
+    index = ((u_long)young >> malloc_pageshift) - malloc_origo;
+    page_dir[index] = MALLOC_FIRST;
+    while (--i) {
+	page_dir[++index] = MALLOC_FOLLOW;
+    }
+
+    /* Now free the old stuff */
+    _PR_UnlockedFree(old);
+    return 1;
+}
+
+/*
+ * Set entry in page directory.
+ * Extend page directory if need be.
+ */
+static int
+set_pgdir(void *ptr, struct  pginfo *info)
+{
+    u_long index = ((u_long)ptr >> malloc_pageshift) - malloc_origo;
+
+    if (index >= malloc_ninfo && !extend_page_directory(index))
+	return 0;
+    page_dir[index] = info;
+    return 1;
+}
+
+/*
+ * Initialize the world
+ */
+static void
+malloc_init (void)
+{
+    int i;
+    char *p;
+
+    TRACE(("%6d I\n",malloc_event++));
+#ifdef DEBUG
+    for (p=getenv("MALLOC_OPTIONS"); p && *p; p++) {
+	switch (*p) {
+	    case 'a': malloc_abort = 0; break;
+	    case 'A': malloc_abort = 1; break;
+	    case 'd': malloc_stats = 0; break;
+	    case 'D': malloc_stats = 1; break;
+	    case 'r': malloc_realloc = 0; break;
+	    case 'R': malloc_realloc = 1; break;
+	    default:
+		wrtwarning("Unknown chars in MALLOC_OPTIONS\n");
+		break;
+	}
+    }
+#endif
+
+#ifndef malloc_pagesize
+    /* determine our pagesize */
+    malloc_pagesize = getpagesize();
+#endif /* malloc_pagesize */
+
+#ifndef malloc_pageshift
+    /* determine how much we shift by to get there */
+    for (i = malloc_pagesize; i > 1; i >>= 1)
+	malloc_pageshift++;
+#endif /* malloc_pageshift */
+
+#ifndef malloc_cache
+    malloc_cache = 50 << malloc_pageshift;	
+#endif /* malloc_cache */
+
+#ifndef malloc_minsize
+    /*
+     * find the smallest size allocation we will bother about.
+     * this is determined as the smallest allocation that can hold
+     * it's own pginfo;
+     */
+    i = 2;
+    for(;;) {
+	int j;
+
+	/* Figure out the size of the bits */
+	j = malloc_pagesize/i;
+	j /= 8;
+	if (j < sizeof(u_long))
+		j = sizeof (u_long);
+	if (sizeof(struct pginfo) + j - sizeof (u_long) <= i)
+		break;
+	i += i;
+    }
+    malloc_minsize = i;
+#endif /* malloc_minsize */
+
+
+    /* Allocate one page for the page directory */
+    page_dir = (struct pginfo **) map_pages(1,0);
+#ifdef SANITY
+    if (!page_dir)
+	wrterror("fatal: my first mmap failed.  (check limits ?)\n");
+#endif
+
+    /*
+     * We need a maximum of malloc_pageshift buckets, steal these from the
+     * front of the page_directory;
+     */
+    malloc_origo = (u_long) page_dir >> malloc_pageshift;
+    malloc_origo -= malloc_pageshift;
+
+    /* Clear it */
+    memset(page_dir,0,malloc_pagesize);
+
+    /* Find out how much it tells us */
+    malloc_ninfo = malloc_pagesize / sizeof *page_dir;
+
+    /* Plug the page directory into itself */
+    i = set_pgdir(page_dir,MALLOC_FIRST);
+#ifdef SANITY
+    if (!i)
+	wrterror("fatal: couldn't set myself in the page directory\n");
+#endif
+
+    /* Been here, done that */
+    initialized++;
+}
+
+/*
+ * Allocate a number of complete pages
+ */
+static void *malloc_pages(size_t size)
+{
+    void *p,*delay_free = 0;
+    int i;
+    struct pgfree *pf;
+    u_long index;
+
+    /* How many pages ? */
+    size += (malloc_pagesize-1);
+    size &= ~malloc_pagemask;
+
+    p = 0;
+    /* Look for free pages before asking for more */