fixup commit for branch 'GECKO181_20090605_RELBRANCH' GECKO181_20090605_RELBRANCH
authorcvs2hg
Wed, 07 Nov 2007 22:25:26 +0000
branchGECKO181_20090605_RELBRANCH
changeset 3890 5fc09e995150
parent 3453 1d28b84ca031
push idunknown
push userunknown
push dateunknown
fixup commit for branch 'GECKO181_20090605_RELBRANCH'
Makefile.in
admin/repackage.sh
config/autoconf.mk.in
config/rules.mk
configure
configure.in
lib/ds/Makefile.in
lib/libc/src/Makefile.in
lib/msgc/src/Makefile.in
lib/prstreams/Makefile.in
pkg/linux/Makefile.in
pkg/solaris/SUNWprd/prototype
pr/include/md/_beos.cfg
pr/include/md/_darwin.cfg
pr/include/md/_darwin.h
pr/include/md/_hpux.h
pr/include/md/_netbsd.h
pr/include/md/_openvms.h
pr/include/md/_pth.h
pr/include/md/_win95.h
pr/include/md/_winnt.h
pr/include/obsolete/probslet.h
pr/include/obsolete/protypes.h
pr/include/prinet.h
pr/include/prinit.h
pr/include/private/primpl.h
pr/include/prlink.h
pr/include/prsystem.h
pr/include/prtypes.h
pr/src/Makefile.in
pr/src/io/prfdcach.c
pr/src/io/prfile.c
pr/src/io/prlog.c
pr/src/io/prprf.c
pr/src/io/prsocket.c
pr/src/linking/Makefile.in
pr/src/linking/prlink.c
pr/src/md/beos/bfile.c
pr/src/md/beos/brng.c
pr/src/md/os2/os2thred.c
pr/src/md/unix/os_Darwin_x86.s
pr/src/md/unix/os_HPUX_ia64.s
pr/src/md/unix/unix.c
pr/src/md/unix/unix_errors.c
pr/src/md/windows/ntinrval.c
pr/src/md/windows/ntio.c
pr/src/md/windows/w95io.c
pr/src/md/windows/w95sock.c
pr/src/md/windows/w95thred.c
pr/src/md/windows/win32_errors.c
pr/src/misc/pratom.c
pr/src/misc/prdtoa.c
pr/src/misc/prinit.c
pr/src/misc/prnetdb.c
pr/src/misc/prsystem.c
pr/src/misc/prtime.c
pr/src/misc/prtrace.c
pr/src/pthreads/Makefile.in
pr/src/pthreads/ptio.c
pr/src/pthreads/ptthread.c
pr/tests/dll/Makefile.in
pr/tests/testfile.c
pr/tests/timetest.c
pr/tests/tmocon.c
pr/tests/vercheck.c
--- a/Makefile.in
+++ b/Makefile.in
@@ -80,16 +80,17 @@ 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"; \
--- a/admin/repackage.sh
+++ b/admin/repackage.sh
@@ -59,56 +59,52 @@
 # Note! Files written with Gnu tar are not readable by some non-Gnu
 # versions. Sun, in particular.
 # 
 # 
 # 
 # 
 # ------------------------------------------------------------------
 
-FROMTOP=/share/builds/components/nspr20/v4.6.1
-TOTOP=./v4.6.1
-NSPRDIR=nspr-4.6.1
-SOURCETAG=NSPR_4_6_1_RTM
+FROMTOP=/share/builds/components/nspr20/v4.6.8
+TOTOP=./v4.6.8
+NSPRDIR=nspr-4.6.8
+SOURCETAG=NSPR_4_6_8_RTM
 
 #
 # enumerate Unix object directories on /s/b/c
 UNIX_OBJDIRS="
-AIX4.3_64_DBG.OBJ
-AIX4.3_64_OPT.OBJ
-AIX4.3_DBG.OBJ
-AIX4.3_OPT.OBJ
-HP-UXB.11.00_64_DBG.OBJ
-HP-UXB.11.00_64_OPT.OBJ
-HP-UXB.11.00_DBG.OBJ
-HP-UXB.11.00_OPT.OBJ
-IRIX6.5_n32_PTH_DBG.OBJ
-IRIX6.5_n32_PTH_OPT.OBJ
-Linux2.2_x86_glibc_PTH_DBG.OBJ
-Linux2.2_x86_glibc_PTH_OPT.OBJ
+HP-UXB.11.11_64_DBG.OBJ
+HP-UXB.11.11_64_OPT.OBJ
+HP-UXB.11.11_DBG.OBJ
+HP-UXB.11.11_OPT.OBJ
+HP-UXB.11.23_ia64_32_DBG.OBJ
+HP-UXB.11.23_ia64_32_OPT.OBJ
+HP-UXB.11.23_ia64_64_DBG.OBJ
+HP-UXB.11.23_ia64_64_OPT.OBJ
 Linux2.4_x86_glibc_PTH_DBG.OBJ
 Linux2.4_x86_glibc_PTH_OPT.OBJ
-OSF1V5.0_DBG.OBJ
-OSF1V5.0_OPT.OBJ
-SunOS5.6_DBG.OBJ
-SunOS5.6_OPT.OBJ
-SunOS5.8_64_DBG.OBJ
-SunOS5.8_64_OPT.OBJ
-SunOS5.8_DBG.OBJ
-SunOS5.8_OPT.OBJ
+Linux2.6_x86_64_glibc_PTH_DBG.OBJ
+Linux2.6_x86_64_glibc_PTH_OPT.OBJ
+Linux2.6_x86_glibc_PTH_DBG.OBJ
+Linux2.6_x86_glibc_PTH_OPT.OBJ
+SunOS5.9_64_DBG.OBJ
+SunOS5.9_64_OPT.OBJ
+SunOS5.9_DBG.OBJ
+SunOS5.9_OPT.OBJ
 "
 #
 # enumerate Windows object directories on /s/b/c
 WIN_OBJDIRS="
 WIN954.0_DBG.OBJ
 WIN954.0_DBG.OBJD
 WIN954.0_OPT.OBJ
-WINNT4.0_DBG.OBJ
-WINNT4.0_DBG.OBJD
-WINNT4.0_OPT.OBJ
+WINNT5.0_DBG.OBJ
+WINNT5.0_DBG.OBJD
+WINNT5.0_OPT.OBJ
 "
 
 #
 # Create the destination directory.
 #
 echo "removing directory $TOTOP"
 rm -rf $TOTOP
 echo "creating directory $TOTOP"
@@ -178,17 +174,17 @@ for OBJDIR in $WIN_OBJDIRS; do
 
     echo "copying $FROMTOP/$OBJDIR/lib"
     cp -r $FROMTOP/$OBJDIR/lib $NSPRDIR
 
     echo "copying $FROMTOP/$OBJDIR/bin"
     cp -r $FROMTOP/$OBJDIR/bin $NSPRDIR
 
     echo "creating directory $TOTOP/$OBJDIR"
-    mkdir $TOTOP/$OBJDIR
+    mkdir -p $TOTOP/$OBJDIR
     echo "creating $TOTOP/$OBJDIR/$NSPRDIR.zip"
     zip -r $TOTOP/$OBJDIR/$NSPRDIR.zip $NSPRDIR
 done
 
 #
 # package the source from CVS
 #
 echo "Packaging source"
--- a/config/autoconf.mk.in
+++ b/config/autoconf.mk.in
@@ -83,16 +83,17 @@ OPTIMIZER	= @OPTIMIZER@
 MKSHLIB		= @MKSHLIB@
 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@
@@ -114,8 +115,15 @@ 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@
+
+NEXT_ROOT = @NEXT_ROOT@
+ifdef NEXT_ROOT
+export NEXT_ROOT
+endif
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -82,16 +82,17 @@ 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
--- a/configure
+++ b/configure
@@ -35,19 +35,21 @@ ac_help="$ac_help
   --enable-debug-rtl      Use the MSVC debug runtime library"
 ac_help="$ac_help
   --enable-n32            Enable n32 ABI support (IRIX only)"
 ac_help="$ac_help
   --enable-64bit          Enable 64-bit support (on certain platforms)"
 ac_help="$ac_help
   --enable-mdupdate       Enable use of certain compilers' mdupdate feature"
 ac_help="$ac_help
+  --with-macos-sdk=dir    Location of platform SDK to use (Mac OS X only)"
+ac_help="$ac_help
   --enable-macos-target=VER
                           Set the minimum MacOS version needed at runtime
-                          [10.1 for ppc, 10.4 for x86]"
+                          [10.2 for ppc, 10.4 for x86]"
 ac_help="$ac_help
   --enable-strip          Enable stripping of shared libs and programs"
 ac_help="$ac_help
   --with-pthreads         Use system pthreads library as thread subsystem"
 ac_help="$ac_help
   --enable-user-pthreads  Build using userland pthreads"
 ac_help="$ac_help
   --enable-nspr-threads   Build using classic nspr threads"
@@ -616,17 +618,17 @@ esac
 
 
 # Make sure we can run config.sub.
 if ${CONFIG_SHELL-/bin/sh} $ac_config_sub sun4 >/dev/null 2>&1; then :
 else { echo "configure: error: can not run $ac_config_sub" 1>&2; exit 1; }
 fi
 
 echo $ac_n "checking host system type""... $ac_c" 1>&6
-echo "configure:625: checking host system type" >&5
+echo "configure:627: checking host system type" >&5
 
 host_alias=$host
 case "$host_alias" in
 NONE)
   case $nonopt in
   NONE)
     if host_alias=`${CONFIG_SHELL-/bin/sh} $ac_config_guess`; then :
     else { echo "configure: error: can not guess host type; you must specify one" 1>&2; exit 1; }
@@ -637,17 +639,17 @@ esac
 
 host=`${CONFIG_SHELL-/bin/sh} $ac_config_sub $host_alias`
 host_cpu=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
 host_vendor=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
 host_os=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
 echo "$ac_t""$host" 1>&6
 
 echo $ac_n "checking target system type""... $ac_c" 1>&6
-echo "configure:646: checking target system type" >&5
+echo "configure:648: checking target system type" >&5
 
 target_alias=$target
 case "$target_alias" in
 NONE)
   case $nonopt in
   NONE) target_alias=$host_alias ;;
   *) target_alias=$nonopt ;;
   esac ;;
@@ -655,17 +657,17 @@ esac
 
 target=`${CONFIG_SHELL-/bin/sh} $ac_config_sub $target_alias`
 target_cpu=`echo $target | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
 target_vendor=`echo $target | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
 target_os=`echo $target | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
 echo "$ac_t""$target" 1>&6
 
 echo $ac_n "checking build system type""... $ac_c" 1>&6
-echo "configure:664: checking build system type" >&5
+echo "configure:666: checking build system type" >&5
 
 build_alias=$build
 case "$build_alias" in
 NONE)
   case $nonopt in
   NONE) build_alias=$host_alias ;;
   *) build_alias=$nonopt ;;
   esac ;;
@@ -680,17 +682,17 @@ echo "$ac_t""$build" 1>&6
 test "$host_alias" != "$target_alias" &&
   test "$program_prefix$program_suffix$program_transform_name" = \
     NONENONEs,x,x, &&
   program_prefix=${target_alias}-
 
 
 MOD_MAJOR_VERSION=4
 MOD_MINOR_VERSION=6
-MOD_PATCH_VERSION=1
+MOD_PATCH_VERSION=8
 NSPR_MODNAME=nspr20
 _HAVE_PTHREADS=
 USE_PTHREADS=
 USE_USER_PTHREADS=
 USE_NSPR_THREADS=
 USE_N32=
 USE_64=
 USE_CPLUS=
@@ -704,16 +706,18 @@ MOZ_OPTIMIZE=
 OBJDIR=.
 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=
 
 RESOLVE_LINK_SYMBOLS=
 
 CFLAGS="${CFLAGS=}"
 CXXFLAGS="${CXXFLAGS=}"
 LDFLAGS="${LDFLAGS=}"
 HOST_CFLAGS="${HOST_CFLAGS=}"
 HOST_LDFLAGS="${HOST_LDFLAGS=}"
@@ -722,17 +726,17 @@ case "$target" in
 *-cygwin*|*-mingw*)
     # 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
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:731: checking for $ac_word" >&5
+echo "configure:735: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   if test -n "$CC"; then
   ac_cv_prog_CC="$CC" # Let the user override the test.
 else
   IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
   ac_dummy="$PATH"
@@ -918,16 +922,23 @@ fi
 if test "${enable_mdupdate+set}" = set; then
   enableval="$enable_mdupdate"
    if test "$enableval" = "yes"; then
 	    USE_MDUPDATE=1
       fi 
 fi
 
 
+# Check whether --with-macos-sdk or --without-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 or --disable-macos-target was given.
 if test "${enable_macos_target+set}" = set; then
   enableval="$enable_macos_target"
   _MACOSX_DEPLOYMENT_TARGET=$enableval
 fi
 
 
 case "$target" in
@@ -1022,17 +1033,17 @@ if test -z "$CXX"; then
 
     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
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1031: checking for $ac_word" >&5
+echo "configure:1042: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_path_WHOAMI'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   case "$WHOAMI" in
   /*)
   ac_cv_path_WHOAMI="$WHOAMI" # Let the user override the test with a path.
   ;;
   ?:/*)			 
@@ -1093,23 +1104,23 @@ if test "$target" != "$host"; then
     echo "cross compiling from $host to $target"
     cross_compiling=yes
 
     _SAVE_CC="$CC"
     _SAVE_CFLAGS="$CFLAGS"
     _SAVE_LDFLAGS="$LDFLAGS"
 
     echo $ac_n "checking for $host compiler""... $ac_c" 1>&6
-echo "configure:1102: checking for $host compiler" >&5
+echo "configure:1113: checking for $host compiler" >&5
     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
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1108: checking for $ac_word" >&5
+echo "configure:1119: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_HOST_CC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   if test -n "$HOST_CC"; then
   ac_cv_prog_HOST_CC="$HOST_CC" # Let the user override the test.
 else
   IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
   ac_dummy="$PATH"
@@ -1145,46 +1156,55 @@ test -n "$HOST_CC" || HOST_CC=""""
         HOST_LDFLAGS="$LDFLAGS"
     fi
 
     CC="$HOST_CC"
     CFLAGS="$HOST_CFLAGS"
     LDFLAGS="$HOST_LDFLAGS"
 
     echo $ac_n "checking whether the $host compiler ($HOST_CC $HOST_CFLAGS $HOST_LDFLAGS) works""... $ac_c" 1>&6
-echo "configure:1154: checking whether the $host compiler ($HOST_CC $HOST_CFLAGS $HOST_LDFLAGS) works" >&5
+echo "configure:1165: checking whether the $host compiler ($HOST_CC $HOST_CFLAGS $HOST_LDFLAGS) works" >&5
     cat > conftest.$ac_ext <<EOF
-#line 1156 "configure"
+#line 1167 "configure"
 #include "confdefs.h"
 
 int main() {
 return(0);
 ; return 0; }
 EOF
-if { (eval echo configure:1163: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:1174: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   ac_cv_prog_host_cc_works=1 echo "$ac_t""yes" 1>&6
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   { echo "configure: error: installation or configuration problem: $host compiler $HOST_CC cannot create executables." 1>&2; exit 1; } 
 fi
 rm -f conftest*
 
     CC=$_SAVE_CC
     CFLAGS=$_SAVE_CFLAGS
     LDFLAGS=$_SAVE_LDFLAGS
 
+    case "$build:$target" in 
+      powerpc-apple-darwin8*:i?86-apple-darwin*)
+                                                _SAVE_CFLAGS=$CFLAGS 
+        _SAVE_CXXFLAGS=$CXXLAGS
+        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
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1183: checking for $ac_word" >&5
+echo "configure:1203: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   if test -n "$CC"; then
   ac_cv_prog_CC="$CC" # Let the user override the test.
 else
   IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
   ac_dummy="$PATH"
@@ -1208,17 +1228,17 @@ fi
 test -n "$CC" && break
 done
 test -n "$CC" || CC="echo"
 
     unset ac_cv_prog_CC
     # Extract the first word of "gcc", so it can be a program name with args.
 set dummy gcc; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1217: checking for $ac_word" >&5
+echo "configure:1237: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   if test -n "$CC"; then
   ac_cv_prog_CC="$CC" # Let the user override the test.
 else
   IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
   ac_dummy="$PATH"
@@ -1238,17 +1258,17 @@ if test -n "$CC"; then
 else
   echo "$ac_t""no" 1>&6
 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
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1247: checking for $ac_word" >&5
+echo "configure:1267: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   if test -n "$CC"; then
   ac_cv_prog_CC="$CC" # Let the user override the test.
 else
   IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
   ac_prog_rejected=no
@@ -1289,17 +1309,17 @@ else
 fi
 
   if test -z "$CC"; then
     case "`uname -s`" in
     *win32* | *WIN32*)
       # Extract the first word of "cl", so it can be a program name with args.
 set dummy cl; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1298: checking for $ac_word" >&5
+echo "configure:1318: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   if test -n "$CC"; then
   ac_cv_prog_CC="$CC" # Let the user override the test.
 else
   IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
   ac_dummy="$PATH"
@@ -1321,33 +1341,33 @@ else
 fi
  ;;
     esac
   fi
   test -z "$CC" && { echo "configure: error: no acceptable cc found in \$PATH" 1>&2; exit 1; }
 fi
 
 echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6
-echo "configure:1330: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
+echo "configure:1350: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
 
 ac_ext=c
 # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
 ac_cpp='$CPP $CPPFLAGS'
 ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
 ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
 cross_compiling=$ac_cv_prog_cc_cross
 
 cat > conftest.$ac_ext << EOF
 
-#line 1341 "configure"
+#line 1361 "configure"
 #include "confdefs.h"
 
 main(){return(0);}
 EOF
-if { (eval echo configure:1346: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1366: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   ac_cv_prog_cc_works=yes
   # If we can't run a trivial program, we are probably using a cross compiler.
   if (./conftest; exit) 2>/dev/null; then
     ac_cv_prog_cc_cross=no
   else
     ac_cv_prog_cc_cross=yes
   fi
 else
@@ -1363,31 +1383,31 @@ ac_compile='${CC-cc} -c $CFLAGS $CPPFLAG
 ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
 cross_compiling=$ac_cv_prog_cc_cross
 
 echo "$ac_t""$ac_cv_prog_cc_works" 1>&6
 if test $ac_cv_prog_cc_works = no; then
   { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; }
 fi
 echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6
-echo "configure:1372: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
+echo "configure:1392: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
 echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6
 cross_compiling=$ac_cv_prog_cc_cross
 
 echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6
-echo "configure:1377: checking whether we are using GNU C" >&5
+echo "configure:1397: checking whether we are using GNU C" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.c <<EOF
 #ifdef __GNUC__
   yes;
 #endif
 EOF
-if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:1386: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
+if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:1406: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
   ac_cv_prog_gcc=yes
 else
   ac_cv_prog_gcc=no
 fi
 fi
 
 echo "$ac_t""$ac_cv_prog_gcc" 1>&6
 
@@ -1396,17 +1416,17 @@ if test $ac_cv_prog_gcc = yes; then
 else
   GCC=
 fi
 
 ac_test_CFLAGS="${CFLAGS+set}"
 ac_save_CFLAGS="$CFLAGS"
 CFLAGS=
 echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6
-echo "configure:1405: checking whether ${CC-cc} accepts -g" >&5
+echo "configure:1425: checking whether ${CC-cc} accepts -g" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   echo 'void f(){}' > conftest.c
 if test -z "`${CC-cc} -g -c conftest.c 2>&1`"; then
   ac_cv_prog_cc_g=yes
 else
   ac_cv_prog_cc_g=no
@@ -1432,17 +1452,17 @@ else
   fi
 fi
 
     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
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1441: checking for $ac_word" >&5
+echo "configure:1461: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CXX'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   if test -n "$CXX"; then
   ac_cv_prog_CXX="$CXX" # Let the user override the test.
 else
   IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
   ac_dummy="$PATH"
@@ -1468,17 +1488,17 @@ done
 test -n "$CXX" || CXX="echo"
 
     unset ac_cv_prog_CXX
     for ac_prog in $CCC c++ g++ gcc CC cxx cc++ 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
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1477: checking for $ac_word" >&5
+echo "configure:1497: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CXX'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   if test -n "$CXX"; then
   ac_cv_prog_CXX="$CXX" # Let the user override the test.
 else
   IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
   ac_dummy="$PATH"
@@ -1500,33 +1520,33 @@ else
 fi
 
 test -n "$CXX" && break
 done
 test -n "$CXX" || CXX="gcc"
 
 
 echo $ac_n "checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works""... $ac_c" 1>&6
-echo "configure:1509: checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works" >&5
+echo "configure:1529: checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works" >&5
 
 ac_ext=C
 # CXXFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
 ac_cpp='$CXXCPP $CPPFLAGS'
 ac_compile='${CXX-g++} -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
 ac_link='${CXX-g++} -o conftest${ac_exeext} $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
 cross_compiling=$ac_cv_prog_cxx_cross
 
 cat > conftest.$ac_ext << EOF
 
-#line 1520 "configure"
+#line 1540 "configure"
 #include "confdefs.h"
 
 int main(){return(0);}
 EOF
-if { (eval echo configure:1525: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1545: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   ac_cv_prog_cxx_works=yes
   # If we can't run a trivial program, we are probably using a cross compiler.
   if (./conftest; exit) 2>/dev/null; then
     ac_cv_prog_cxx_cross=no
   else
     ac_cv_prog_cxx_cross=yes
   fi
 else
@@ -1542,31 +1562,31 @@ ac_compile='${CC-cc} -c $CFLAGS $CPPFLAG
 ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
 cross_compiling=$ac_cv_prog_cc_cross
 
 echo "$ac_t""$ac_cv_prog_cxx_works" 1>&6
 if test $ac_cv_prog_cxx_works = no; then
   { echo "configure: error: installation or configuration problem: C++ compiler cannot create executables." 1>&2; exit 1; }
 fi
 echo $ac_n "checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6
-echo "configure:1551: checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) is a cross-compiler" >&5
+echo "configure:1571: checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) is a cross-compiler" >&5
 echo "$ac_t""$ac_cv_prog_cxx_cross" 1>&6
 cross_compiling=$ac_cv_prog_cxx_cross
 
 echo $ac_n "checking whether we are using GNU C++""... $ac_c" 1>&6
-echo "configure:1556: checking whether we are using GNU C++" >&5
+echo "configure:1576: checking whether we are using GNU C++" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_gxx'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.C <<EOF
 #ifdef __GNUC__
   yes;
 #endif
 EOF
-if { ac_try='${CXX-g++} -E conftest.C'; { (eval echo configure:1565: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
+if { ac_try='${CXX-g++} -E conftest.C'; { (eval echo configure:1585: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
   ac_cv_prog_gxx=yes
 else
   ac_cv_prog_gxx=no
 fi
 fi
 
 echo "$ac_t""$ac_cv_prog_gxx" 1>&6
 
@@ -1575,17 +1595,17 @@ if test $ac_cv_prog_gxx = yes; then
 else
   GXX=
 fi
 
 ac_test_CXXFLAGS="${CXXFLAGS+set}"
 ac_save_CXXFLAGS="$CXXFLAGS"
 CXXFLAGS=
 echo $ac_n "checking whether ${CXX-g++} accepts -g""... $ac_c" 1>&6
-echo "configure:1584: checking whether ${CXX-g++} accepts -g" >&5
+echo "configure:1604: checking whether ${CXX-g++} accepts -g" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_cxx_g'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   echo 'void f(){}' > conftest.cc
 if test -z "`${CXX-g++} -g -c conftest.cc 2>&1`"; then
   ac_cv_prog_cxx_g=yes
 else
   ac_cv_prog_cxx_g=no
@@ -1606,22 +1626,30 @@ elif test $ac_cv_prog_cxx_g = yes; then
 else
   if test "$GXX" = yes; then
     CXXFLAGS="-O2"
   else
     CXXFLAGS=
   fi
 fi
 
+
+    case "$build:$target" in
+      powerpc-apple-darwin8*:i?86-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
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1620: checking for $ac_word" >&5
+echo "configure:1648: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_RANLIB'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   if test -n "$RANLIB"; then
   ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
 else
   IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
   ac_dummy="$PATH"
@@ -1646,17 +1674,17 @@ 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
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1655: checking for $ac_word" >&5
+echo "configure:1683: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_AR'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   if test -n "$AR"; then
   ac_cv_prog_AR="$AR" # Let the user override the test.
 else
   IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
   ac_dummy="$PATH"
@@ -1681,17 +1709,17 @@ 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
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1690: checking for $ac_word" >&5
+echo "configure:1718: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_AS'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   if test -n "$AS"; then
   ac_cv_prog_AS="$AS" # Let the user override the test.
 else
   IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
   ac_dummy="$PATH"
@@ -1716,17 +1744,17 @@ 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
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1725: checking for $ac_word" >&5
+echo "configure:1753: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_LD'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   if test -n "$LD"; then
   ac_cv_prog_LD="$LD" # Let the user override the test.
 else
   IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
   ac_dummy="$PATH"
@@ -1751,17 +1779,17 @@ 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
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1760: checking for $ac_word" >&5
+echo "configure:1788: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_STRIP'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   if test -n "$STRIP"; then
   ac_cv_prog_STRIP="$STRIP" # Let the user override the test.
 else
   IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
   ac_dummy="$PATH"
@@ -1786,17 +1814,17 @@ 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
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1795: checking for $ac_word" >&5
+echo "configure:1823: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_WINDRES'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   if test -n "$WINDRES"; then
   ac_cv_prog_WINDRES="$WINDRES" # Let the user override the test.
 else
   IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
   ac_dummy="$PATH"
@@ -1823,17 +1851,17 @@ test -n "$WINDRES" || WINDRES="echo"
 
 
 else
     for ac_prog in $CCC c++ g++ gcc CC cxx cc++ 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
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1832: checking for $ac_word" >&5
+echo "configure:1860: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CXX'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   if test -n "$CXX"; then
   ac_cv_prog_CXX="$CXX" # Let the user override the test.
 else
   IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
   ac_dummy="$PATH"
@@ -1855,33 +1883,33 @@ else
 fi
 
 test -n "$CXX" && break
 done
 test -n "$CXX" || CXX="gcc"
 
 
 echo $ac_n "checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works""... $ac_c" 1>&6
-echo "configure:1864: checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works" >&5
+echo "configure:1892: checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works" >&5
 
 ac_ext=C
 # CXXFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
 ac_cpp='$CXXCPP $CPPFLAGS'
 ac_compile='${CXX-g++} -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
 ac_link='${CXX-g++} -o conftest${ac_exeext} $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
 cross_compiling=$ac_cv_prog_cxx_cross
 
 cat > conftest.$ac_ext << EOF
 
-#line 1875 "configure"
+#line 1903 "configure"
 #include "confdefs.h"
 
 int main(){return(0);}
 EOF
-if { (eval echo configure:1880: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1908: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   ac_cv_prog_cxx_works=yes
   # If we can't run a trivial program, we are probably using a cross compiler.
   if (./conftest; exit) 2>/dev/null; then
     ac_cv_prog_cxx_cross=no
   else
     ac_cv_prog_cxx_cross=yes
   fi
 else
@@ -1897,31 +1925,31 @@ ac_compile='${CC-cc} -c $CFLAGS $CPPFLAG
 ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
 cross_compiling=$ac_cv_prog_cc_cross
 
 echo "$ac_t""$ac_cv_prog_cxx_works" 1>&6
 if test $ac_cv_prog_cxx_works = no; then
   { echo "configure: error: installation or configuration problem: C++ compiler cannot create executables." 1>&2; exit 1; }
 fi
 echo $ac_n "checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6
-echo "configure:1906: checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) is a cross-compiler" >&5
+echo "configure:1934: checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) is a cross-compiler" >&5
 echo "$ac_t""$ac_cv_prog_cxx_cross" 1>&6
 cross_compiling=$ac_cv_prog_cxx_cross
 
 echo $ac_n "checking whether we are using GNU C++""... $ac_c" 1>&6
-echo "configure:1911: checking whether we are using GNU C++" >&5
+echo "configure:1939: checking whether we are using GNU C++" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_gxx'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.C <<EOF
 #ifdef __GNUC__
   yes;
 #endif
 EOF
-if { ac_try='${CXX-g++} -E conftest.C'; { (eval echo configure:1920: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
+if { ac_try='${CXX-g++} -E conftest.C'; { (eval echo configure:1948: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
   ac_cv_prog_gxx=yes
 else
   ac_cv_prog_gxx=no
 fi
 fi
 
 echo "$ac_t""$ac_cv_prog_gxx" 1>&6
 
@@ -1930,17 +1958,17 @@ if test $ac_cv_prog_gxx = yes; then
 else
   GXX=
 fi
 
 ac_test_CXXFLAGS="${CXXFLAGS+set}"
 ac_save_CXXFLAGS="$CXXFLAGS"
 CXXFLAGS=
 echo $ac_n "checking whether ${CXX-g++} accepts -g""... $ac_c" 1>&6
-echo "configure:1939: checking whether ${CXX-g++} accepts -g" >&5
+echo "configure:1967: checking whether ${CXX-g++} accepts -g" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_cxx_g'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   echo 'void f(){}' > conftest.cc
 if test -z "`${CXX-g++} -g -c conftest.cc 2>&1`"; then
   ac_cv_prog_cxx_g=yes
 else
   ac_cv_prog_cxx_g=no
@@ -1967,17 +1995,17 @@ else
 fi
 
     if test "$CXX" = "cl" -a -z "$CC"; then
         CC=$CXX
     else        
         # Extract the first word of "gcc", so it can be a program name with args.
 set dummy gcc; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1976: checking for $ac_word" >&5
+echo "configure:2004: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   if test -n "$CC"; then
   ac_cv_prog_CC="$CC" # Let the user override the test.
 else
   IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
   ac_dummy="$PATH"
@@ -1997,17 +2025,17 @@ if test -n "$CC"; then
 else
   echo "$ac_t""no" 1>&6
 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
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:2006: checking for $ac_word" >&5
+echo "configure:2034: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   if test -n "$CC"; then
   ac_cv_prog_CC="$CC" # Let the user override the test.
 else
   IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
   ac_prog_rejected=no
@@ -2048,17 +2076,17 @@ else
 fi
 
   if test -z "$CC"; then
     case "`uname -s`" in
     *win32* | *WIN32*)
       # Extract the first word of "cl", so it can be a program name with args.
 set dummy cl; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:2057: checking for $ac_word" >&5
+echo "configure:2085: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   if test -n "$CC"; then
   ac_cv_prog_CC="$CC" # Let the user override the test.
 else
   IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
   ac_dummy="$PATH"
@@ -2080,33 +2108,33 @@ else
 fi
  ;;
     esac
   fi
   test -z "$CC" && { echo "configure: error: no acceptable cc found in \$PATH" 1>&2; exit 1; }
 fi
 
 echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6
-echo "configure:2089: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
+echo "configure:2117: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
 
 ac_ext=c
 # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
 ac_cpp='$CPP $CPPFLAGS'
 ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
 ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
 cross_compiling=$ac_cv_prog_cc_cross
 
 cat > conftest.$ac_ext << EOF
 
-#line 2100 "configure"
+#line 2128 "configure"
 #include "confdefs.h"
 
 main(){return(0);}
 EOF
-if { (eval echo configure:2105: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:2133: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   ac_cv_prog_cc_works=yes
   # If we can't run a trivial program, we are probably using a cross compiler.
   if (./conftest; exit) 2>/dev/null; then
     ac_cv_prog_cc_cross=no
   else
     ac_cv_prog_cc_cross=yes
   fi
 else
@@ -2122,31 +2150,31 @@ ac_compile='${CC-cc} -c $CFLAGS $CPPFLAG
 ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
 cross_compiling=$ac_cv_prog_cc_cross
 
 echo "$ac_t""$ac_cv_prog_cc_works" 1>&6
 if test $ac_cv_prog_cc_works = no; then
   { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; }
 fi
 echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6
-echo "configure:2131: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
+echo "configure:2159: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
 echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6
 cross_compiling=$ac_cv_prog_cc_cross
 
 echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6
-echo "configure:2136: checking whether we are using GNU C" >&5
+echo "configure:2164: checking whether we are using GNU C" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.c <<EOF
 #ifdef __GNUC__
   yes;
 #endif
 EOF
-if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:2145: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
+if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:2173: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
   ac_cv_prog_gcc=yes
 else
   ac_cv_prog_gcc=no
 fi
 fi
 
 echo "$ac_t""$ac_cv_prog_gcc" 1>&6
 
@@ -2155,17 +2183,17 @@ if test $ac_cv_prog_gcc = yes; then
 else
   GCC=
 fi
 
 ac_test_CFLAGS="${CFLAGS+set}"
 ac_save_CFLAGS="$CFLAGS"
 CFLAGS=
 echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6
-echo "configure:2164: checking whether ${CC-cc} accepts -g" >&5
+echo "configure:2192: checking whether ${CC-cc} accepts -g" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   echo 'void f(){}' > conftest.c
 if test -z "`${CC-cc} -g -c conftest.c 2>&1`"; then
   ac_cv_prog_cc_g=yes
 else
   ac_cv_prog_cc_g=no
@@ -2188,72 +2216,72 @@ else
     CFLAGS="-O2"
   else
     CFLAGS=
   fi
 fi
 
     fi
     echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6
-echo "configure:2197: checking how to run the C preprocessor" >&5
+echo "configure:2225: checking how to run the C preprocessor" >&5
 # On Suns, sometimes $CPP names a directory.
 if test -n "$CPP" && test -d "$CPP"; then
   CPP=
 fi
 if test -z "$CPP"; then
 if eval "test \"`echo '$''{'ac_cv_prog_CPP'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
     # This must be in double quotes, not single quotes, because CPP may get
   # substituted into the Makefile and "${CC-cc}" will confuse make.
   CPP="${CC-cc} -E"
   # On the NeXT, cc -E runs the code through the compiler's parser,
   # not just through cpp.
   cat > conftest.$ac_ext <<EOF
-#line 2212 "configure"
+#line 2240 "configure"
 #include "confdefs.h"
 #include <assert.h>
 Syntax Error
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:2218: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:2246: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   :
 else
   echo "$ac_err" >&5
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   CPP="${CC-cc} -E -traditional-cpp"
   cat > conftest.$ac_ext <<EOF
-#line 2229 "configure"
+#line 2257 "configure"
 #include "confdefs.h"
 #include <assert.h>
 Syntax Error
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:2235: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:2263: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   :
 else
   echo "$ac_err" >&5
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   CPP="${CC-cc} -nologo -E"
   cat > conftest.$ac_ext <<EOF
-#line 2246 "configure"
+#line 2274 "configure"
 #include "confdefs.h"
 #include <assert.h>
 Syntax Error
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:2252: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:2280: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   :
 else
   echo "$ac_err" >&5
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
@@ -2270,17 +2298,17 @@ fi
 else
   ac_cv_prog_CPP="$CPP"
 fi
 echo "$ac_t""$CPP" 1>&6
 
     # Extract the first word of "ranlib", so it can be a program name with args.
 set dummy ranlib; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:2279: checking for $ac_word" >&5
+echo "configure:2307: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_RANLIB'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   if test -n "$RANLIB"; then
   ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
 else
   IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
   ac_dummy="$PATH"
@@ -2302,17 +2330,17 @@ else
   echo "$ac_t""no" 1>&6
 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
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:2311: checking for $ac_word" >&5
+echo "configure:2339: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_path_AS'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   case "$AS" in
   /*)
   ac_cv_path_AS="$AS" # Let the user override the test with a path.
   ;;
   ?:/*)			 
@@ -2343,17 +2371,17 @@ 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
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:2352: checking for $ac_word" >&5
+echo "configure:2380: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_path_AR'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   case "$AR" in
   /*)
   ac_cv_path_AR="$AR" # Let the user override the test with a path.
   ;;
   ?:/*)			 
@@ -2384,17 +2412,17 @@ 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
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:2393: checking for $ac_word" >&5
+echo "configure:2421: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_path_LD'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   case "$LD" in
   /*)
   ac_cv_path_LD="$LD" # Let the user override the test with a path.
   ;;
   ?:/*)			 
@@ -2425,17 +2453,17 @@ 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
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:2434: checking for $ac_word" >&5
+echo "configure:2462: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_path_STRIP'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   case "$STRIP" in
   /*)
   ac_cv_path_STRIP="$STRIP" # Let the user override the test with a path.
   ;;
   ?:/*)			 
@@ -2466,17 +2494,17 @@ 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
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:2475: checking for $ac_word" >&5
+echo "configure:2503: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_path_WINDRES'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   case "$WINDRES" in
   /*)
   ac_cv_path_WINDRES="$WINDRES" # Let the user override the test with a path.
   ;;
   ?:/*)			 
@@ -2521,46 +2549,52 @@ 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
 
 echo $ac_n "checking for gcc -pipe support""... $ac_c" 1>&6
-echo "configure:2537: checking for gcc -pipe support" >&5
+echo "configure:2571: checking for gcc -pipe support" >&5
 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 > conftest.$ac_ext <<EOF
-#line 2552 "configure"
+#line 2586 "configure"
 #include "confdefs.h"
  #include <stdio.h> 
 int main() {
 printf("Hello World\n");
 ; return 0; }
 EOF
-if { (eval echo configure:2559: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:2593: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   _res_gcc_pipe="yes"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   _res_gcc_pipe="no" 
 fi
@@ -2577,17 +2611,17 @@ rm -f conftest*
     rm -f dummy-hello.c dummy-hello.s dummy-hello.S dummy-hello a.out
     echo "$ac_t""$_res" 1>&6
 else
     echo "$ac_t""no" 1>&6
 fi
 
 if test "$GNU_CC"; then
     echo $ac_n "checking for visibility(hidden) attribute""... $ac_c" 1>&6
-echo "configure:2586: checking for visibility(hidden) attribute" >&5
+echo "configure:2620: checking for visibility(hidden) attribute" >&5
 if eval "test \"`echo '$''{'ac_cv_visibility_hidden'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&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
@@ -2601,17 +2635,17 @@ fi
 
 echo "$ac_t""$ac_cv_visibility_hidden" 1>&6
     if test "$ac_cv_visibility_hidden" = "yes"; then
         cat >> confdefs.h <<\EOF
 #define HAVE_VISIBILITY_HIDDEN_ATTRIBUTE 1
 EOF
 
         echo $ac_n "checking for visibility pragma support""... $ac_c" 1>&6
-echo "configure:2610: checking for visibility pragma support" >&5
+echo "configure:2644: checking for visibility pragma support" >&5
 if eval "test \"`echo '$''{'ac_cv_visibility_pragma'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.c <<EOF
 #pragma GCC visibility push(hidden)
             int foo_hidden = 1;
 #pragma GCC visibility push(default)
             int foo_default = 1;
@@ -2654,17 +2688,17 @@ 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
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:2663: checking for $ac_word" >&5
+echo "configure:2697: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_path_PERL'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   case "$PERL" in
   /*)
   ac_cv_path_PERL="$PERL" # Let the user override the test with a path.
   ;;
   ?:/*)			 
@@ -2714,16 +2748,17 @@ 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 ;;
+        darwin*)      OS_ARCH=Darwin ;;
     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
@@ -2900,27 +2935,27 @@ EOF
 
     cat >> confdefs.h <<\EOF
 #define SYSV 1
 EOF
 
     DSO_LDOPTS='-brtl -bnortllib -bM:SRE -bnoentry -bexpall -blibpath:/usr/lib:/lib'
     ac_safe=`echo "sys/atomic_op.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for sys/atomic_op.h""... $ac_c" 1>&6
-echo "configure:2909: checking for sys/atomic_op.h" >&5
+echo "configure:2944: checking for sys/atomic_op.h" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2914 "configure"
+#line 2949 "configure"
 #include "confdefs.h"
 #include <sys/atomic_op.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:2919: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:2954: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
   eval "ac_cv_header_$ac_safe=yes"
 else
   echo "$ac_err" >&5
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
@@ -3067,36 +3102,36 @@ EOF
     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 $@'
         echo $ac_n "checking for gethostbyaddr in -lbind""... $ac_c" 1>&6
-echo "configure:3076: checking for gethostbyaddr in -lbind" >&5
+echo "configure:3111: checking for gethostbyaddr in -lbind" >&5
 ac_lib_var=`echo bind'_'gethostbyaddr | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   ac_save_LIBS="$LIBS"
 LIBS="-lbind  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 3084 "configure"
+#line 3119 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
     builtin and then its argument prototype would still apply.  */
 char gethostbyaddr();
 
 int main() {
 gethostbyaddr()
 ; return 0; }
 EOF
-if { (eval echo configure:3095: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3130: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=no"
 fi
@@ -3267,95 +3302,124 @@ EOF
 #define DARWIN 1
 EOF
 
     cat >> confdefs.h <<\EOF
 #define HAVE_BSD_FLOCK 1
 EOF
 
     CFLAGS="$CFLAGS -Wmost -fno-common"
-    if echo $OS_TEST | grep -c 86 2>/dev/null; then
-        cat >> confdefs.h <<\EOF
+    case "${target_cpu}" in
+        i*86*)
+            cat >> confdefs.h <<\EOF
 #define i386 1
 EOF
 
-        CPU_ARCH=i386
-    else
-        cat >> confdefs.h <<\EOF
+            CPU_ARCH=i386
+            PR_MD_ASFILES=os_Darwin_x86.s
+            ;;
+        *)
+            cat >> confdefs.h <<\EOF
 #define ppc 1
 EOF
 
-        CPU_ARCH=ppc
-    fi
+            CPU_ARCH=ppc
+            PR_MD_ASFILES=os_Darwin_ppc.s
+            ;;
+    esac
     DSO_CFLAGS=-fPIC
     DSO_LDOPTS='-dynamiclib -compatibility_version 1 -current_version 1 -all_load -install_name @executable_path/$@ -headerpad_max_install_names'
     # Use the standard preprocessor (cpp)
     CFLAGS="$CFLAGS -no-cpp-precomp"
-    MKSHLIB='$(CC) -arch $(CPU_ARCH) $(DSO_LDOPTS) -o $@'
+    MKSHLIB='$(CC) $(DSO_LDOPTS) -o $@'
     STRIP="$STRIP -x -S"
     DLL_SUFFIX=dylib
     USE_PTHREADS=1
     MDCPUCFG_H=_darwin.cfg
     PR_MD_CSRCS=darwin.c
-    if test "$CPU_ARCH" = "ppc"; then
-        PR_MD_ASFILES=os_Darwin_ppc.s
-    fi
 
     # Add Mac OS X support for loading CFM & CFBundle plugins
     if test -f /System/Library/Frameworks/Carbon.framework/Carbon; then
         cat >> confdefs.h <<\EOF
 #define XP_MACOSX 1
 EOF
 
         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.1
+                                        export MACOSX_DEPLOYMENT_TARGET=10.2
                     ;;
                 i*86*)
                                         export MACOSX_DEPLOYMENT_TARGET=10.4
                     ;;
             esac
         fi
-    fi
-
-    # do the right thing for SDK support
-    if test "$NEXT_ROOT"; then
+
+                        
+        if test "$MACOS_SDK_DIR"; then
+            
+            if test ! -d "$MACOS_SDK_DIR"; then
+                { echo "configure: 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." 1>&2; exit 1; }
+            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}"
+
                 
-                                
-        
-        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
-                        TARGET_ARCH_LIB="darwin"
-            TARGET_ARCH_INCLUDE="ppc-darwin"
-            SDK_C_INCLUDE="-isystem ${NEXT_ROOT}/usr/include/gcc/darwin/${GCC_VERSION} -isystem ${NEXT_ROOT}/usr/include -F${NEXT_ROOT}/System/Library/Frameworks"
-        else
-                                                                                    TARGET_ARCH_LIB=${target_cpu}-${target_vendor}-darwin`echo $NEXT_ROOT | $PERL -pe 's/MacOSX10\.(\d*)//;if ($1) {$_=$1+4;} else {$_="'${target_os}'";s/(\d+)//;$_=$1;}'`
-            TARGET_ARCH_INCLUDE=$TARGET_ARCH_LIB
-            SDK_C_INCLUDE="-isystem ${NEXT_ROOT}/usr/lib/gcc/${TARGET_ARCH_LIB}/${GCC_VERSION_FULL}/include -isystem ${NEXT_ROOT}/usr/include -F${NEXT_ROOT}/System/Library/Frameworks"
+                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"
+                DSO_LDOPTS="${MACOS_SDK_LIBS} $DSO_LDOPTS"
+                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}"
+                    DSO_LDOPTS="$DSO_LDOPTS -isysroot ${MACOS_SDK_DIR}"
+                else
+                                                            LDFLAGS="$LDFLAGS -Wl,-syslibroot,${MACOS_SDK_DIR}"
+                    DSO_LDOPTS="$DSO_LDOPTS -Wl,-syslibroot,${MACOS_SDK_DIR}"
+                fi
+            fi
         fi
-
-        if test -d "${NEXT_ROOT}/Library/Frameworks" ; then
-            SDK_C_INCLUDE="$SDK_C_INCLUDE -F${NEXT_ROOT}/Library/Frameworks"
-        fi
-
-        CFLAGS="$CFLAGS -nostdinc ${SDK_C_INCLUDE}"
-
-                CPP="$CPP -nostdinc ${SDK_C_INCLUDE}"
-
-        OS_LIBS="-L${NEXT_ROOT}/usr/lib/gcc/${TARGET_ARCH_LIB} -L${NEXT_ROOT}/usr/lib/gcc/${TARGET_ARCH_LIB}/${GCC_VERSION_FULL} -L${NEXT_ROOT}/usr/lib $OS_LIBS"
     fi
     ;;
 
 *-dgux*)
     cat >> confdefs.h <<\EOF
 #define XP_UNIX 1
 EOF
 
@@ -3432,36 +3496,44 @@ EOF
     cat >> confdefs.h <<\EOF
 #define HPUX 1
 EOF
 
     cat >> confdefs.h <<\EOF
 #define _HPUX_SOURCE 1
 EOF
 
-    cat >> confdefs.h <<\EOF
-#define hppa 1
-EOF
-
     # 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.
     cat >> confdefs.h <<\EOF
 #define _PR_POLL_WITH_SELECT 1
 EOF
 
     cat >> confdefs.h <<\EOF
 #define _USE_BIG_FDS 1
 EOF
 
-    DLL_SUFFIX=sl
     DSO_LDOPTS='-b +h $(notdir $@)'
     PR_MD_CSRCS=hpux.c
-    if test "$OS_TEST" != "ia64"; then
+    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
+        cat >> confdefs.h <<\EOF
+#define hppa 1
+EOF
+
+        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
@@ -3512,20 +3584,20 @@ EOF
 
     if echo "$OS_RELEASE" | egrep '^(B.10.30|B.11)' >/dev/null; then
         cat >> confdefs.h <<\EOF
 #define HAVE_POINTER_LOCALTIME_R 1
 EOF
 
     fi
 
-    # HP-UX 11i (B.11.11) or higher
+    # HP-UX 11i v2 (B.11.23) or higher
     
     case "$OS_RELEASE" in
-    [C-Z]*|B.[2-9]*|B.1[2-9]*|B.11.[2-9]*|B.11.1[1-9]*)
+    [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
         cat >> confdefs.h <<\EOF
 #define HPUX10 1
@@ -3769,41 +3841,29 @@ EOF
         USE_PTHREADS=1
         IMPL_STRATEGY=_PTH
     fi
     cat >> confdefs.h <<\EOF
 #define XP_UNIX 1
 EOF
 
     cat >> confdefs.h <<\EOF
-#define _POSIX_SOURCE 1
-EOF
-
-    cat >> confdefs.h <<\EOF
-#define _BSD_SOURCE 1
-EOF
-
-    cat >> confdefs.h <<\EOF
-#define _SVID_SOURCE 1
-EOF
-
-    cat >> confdefs.h <<\EOF
-#define _LARGEFILE64_SOURCE 1
+#define _GNU_SOURCE 1
 EOF
 
     cat >> confdefs.h <<\EOF
 #define HAVE_FCNTL_FILE_LOCKING 1
 EOF
 
     cat >> confdefs.h <<\EOF
 #define LINUX 1
 EOF
 
-    CFLAGS="$CFLAGS -ansi -Wall"
-    CXXFLAGS="$CXXFLAGS -ansi -Wall"
+    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
@@ -4331,27 +4391,27 @@ EOF
     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_safe=`echo "machine/builtins.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for machine/builtins.h""... $ac_c" 1>&6
-echo "configure:4340: checking for machine/builtins.h" >&5
+echo "configure:4400: checking for machine/builtins.h" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 4345 "configure"
+#line 4405 "configure"
 #include "confdefs.h"
 #include <machine/builtins.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:4350: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:4410: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
   eval "ac_cv_header_$ac_safe=yes"
 else
   echo "$ac_err" >&5
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
@@ -4903,63 +4963,63 @@ if test -z "$SKIP_LIBRARY_CHECKS"; then
 
 
 
 case $target in
 *-darwin*)
     ;;
 *)
     echo $ac_n "checking for dlopen in -ldl""... $ac_c" 1>&6
-echo "configure:4912: checking for dlopen in -ldl" >&5
+echo "configure:4972: checking for dlopen in -ldl" >&5
 ac_lib_var=`echo dl'_'dlopen | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   ac_save_LIBS="$LIBS"
 LIBS="-ldl  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 4920 "configure"
+#line 4980 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
     builtin and then its argument prototype would still apply.  */
 char dlopen();
 
 int main() {
 dlopen()
 ; return 0; }
 EOF
-if { (eval echo configure:4931: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4991: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=no"
 fi
 rm -f conftest*
 LIBS="$ac_save_LIBS"
 
 fi
 if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
   echo "$ac_t""yes" 1>&6
   ac_safe=`echo "dlfcn.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for dlfcn.h""... $ac_c" 1>&6
-echo "configure:4948: checking for dlfcn.h" >&5
+echo "configure:5008: checking for dlfcn.h" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 4953 "configure"
+#line 5013 "configure"
 #include "confdefs.h"
 #include <dlfcn.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:4958: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:5018: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
   eval "ac_cv_header_$ac_safe=yes"
 else
   echo "$ac_err" >&5
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
@@ -4982,23 +5042,23 @@ fi
     ;;
 esac
 
 
 
 
 if test $ac_cv_prog_gcc = yes; then
     echo $ac_n "checking whether ${CC-cc} needs -traditional""... $ac_c" 1>&6
-echo "configure:4991: checking whether ${CC-cc} needs -traditional" >&5
+echo "configure:5051: checking whether ${CC-cc} needs -traditional" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_gcc_traditional'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
     ac_pattern="Autoconf.*'x'"
   cat > conftest.$ac_ext <<EOF
-#line 4997 "configure"
+#line 5057 "configure"
 #include "confdefs.h"
 #include <sgtty.h>
 Autoconf TIOCGETP
 EOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
   egrep "$ac_pattern" >/dev/null 2>&1; then
   rm -rf conftest*
   ac_cv_prog_gcc_traditional=yes
@@ -5006,17 +5066,17 @@ else
   rm -rf conftest*
   ac_cv_prog_gcc_traditional=no
 fi
 rm -f conftest*
 
 
   if test $ac_cv_prog_gcc_traditional = no; then
     cat > conftest.$ac_ext <<EOF
-#line 5015 "configure"
+#line 5075 "configure"
 #include "confdefs.h"
 #include <termio.h>
 Autoconf TCGETA
 EOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
   egrep "$ac_pattern" >/dev/null 2>&1; then
   rm -rf conftest*
   ac_cv_prog_gcc_traditional=yes
@@ -5030,22 +5090,22 @@ echo "$ac_t""$ac_cv_prog_gcc_traditional
   if test $ac_cv_prog_gcc_traditional = yes; then
     CC="$CC -traditional"
   fi
 fi
 
 for ac_func in lchown strerror
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:5039: checking for $ac_func" >&5
+echo "configure:5099: checking for $ac_func" >&5
 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 5044 "configure"
+#line 5104 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char $ac_func(); below.  */
 #include <assert.h>
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
     builtin and then its argument prototype would still apply.  */
 char $ac_func();
@@ -5058,17 +5118,17 @@ int main() {
 #if defined (__stub_$ac_func) || defined (__stub___$ac_func)
 choke me
 #else
 $ac_func();
 #endif
 
 ; return 0; }
 EOF
-if { (eval echo configure:5067: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:5127: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=yes"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=no"
 fi
@@ -5099,17 +5159,17 @@ if test "${enable_strip+set}" = set; the
 fi
 
 
 case "${target_os}" in
 hpux*)
 if test -z "$GNU_CC"; then
 
     echo $ac_n "checking for +Olit support""... $ac_c" 1>&6
-echo "configure:5108: checking for +Olit support" >&5
+echo "configure:5168: checking for +Olit support" >&5
 if eval "test \"`echo '$''{'ac_cv_hpux_usable_olit_option'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&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
@@ -5138,17 +5198,17 @@ esac
 
 case "$target_os" in
 darwin*)
     _HAVE_PTHREADS=1
     ;;
 *)
     
 echo $ac_n "checking for pthread_create in -lpthreads""... $ac_c" 1>&6
-echo "configure:5147: checking for pthread_create in -lpthreads" >&5
+echo "configure:5207: checking for pthread_create in -lpthreads" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { return v; } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -5160,17 +5220,17 @@ echo "
     rm -f dummy.c dummy${ac_exeext} ;
     if test "$_res" = "0"; then
         echo "$ac_t""yes" 1>&6
         _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthreads"
     else
         echo "$ac_t""no" 1>&6
         
 echo $ac_n "checking for pthread_create in -lpthread""... $ac_c" 1>&6
-echo "configure:5169: checking for pthread_create in -lpthread" >&5
+echo "configure:5229: checking for pthread_create in -lpthread" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { return v; } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -5182,17 +5242,17 @@ echo "
     rm -f dummy.c dummy${ac_exeext} ;
     if test "$_res" = "0"; then
         echo "$ac_t""yes" 1>&6
         _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthread"
     else
         echo "$ac_t""no" 1>&6
         
 echo $ac_n "checking for pthread_create in -lc_r""... $ac_c" 1>&6
-echo "configure:5191: checking for pthread_create in -lc_r" >&5
+echo "configure:5251: checking for pthread_create in -lc_r" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { return v; } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -5204,17 +5264,17 @@ echo "
     rm -f dummy.c dummy${ac_exeext} ;
     if test "$_res" = "0"; then
         echo "$ac_t""yes" 1>&6
         _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lc_r"
     else
         echo "$ac_t""no" 1>&6
         
 echo $ac_n "checking for pthread_create in -lc""... $ac_c" 1>&6
-echo "configure:5213: checking for pthread_create in -lc" >&5
+echo "configure:5273: checking for pthread_create in -lc" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { return v; } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -5358,17 +5418,17 @@ EOF
     fi
 fi
 
 
 if test -n "$USE_PTHREADS"; then
       rm -f conftest*
    ac_cv_have_dash_pthread=no
    echo $ac_n "checking whether ${CC-cc} accepts -pthread""... $ac_c" 1>&6
-echo "configure:5367: checking whether ${CC-cc} accepts -pthread" >&5
+echo "configure:5427: checking whether ${CC-cc} accepts -pthread" >&5
    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
@@ -5381,17 +5441,17 @@ echo "configure:5367: checking whether $
 	fi
     fi
     rm -f conftest*
     echo "$ac_t""$ac_cv_have_dash_pthread" 1>&6
 
 			    ac_cv_have_dash_pthreads=no
     if test "$ac_cv_have_dash_pthread" = "no"; then
 	    echo $ac_n "checking whether ${CC-cc} accepts -pthreads""... $ac_c" 1>&6
-echo "configure:5390: checking whether ${CC-cc} accepts -pthreads" >&5
+echo "configure:5450: checking whether ${CC-cc} accepts -pthreads" >&5
     	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
@@ -5797,16 +5857,19 @@ esac
 
 
 
 
 
 
 
 
+
+
+
 MAKEFILES="
 Makefile 
 config/Makefile
 config/autoconf.mk
 config/nsprincl.mk
 config/nsprincl.sh
 config/nspr-config
 lib/Makefile 
@@ -5846,16 +5909,18 @@ elif test -n "$USE_PTHREADS"; then
 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
+
 trap '' 1 2 15
 cat > confcache <<\EOF
 # 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.  It is not useful on other systems.
 # If it contains results you don't want to keep, you may remove or edit it.
 #
 # By default, configure uses ./config.cache as the cache file,
@@ -6024,16 +6089,17 @@ s%@AS@%$AS%g
 s%@LD@%$LD%g
 s%@STRIP@%$STRIP%g
 s%@WINDRES@%$WINDRES%g
 s%@CPP@%$CPP%g
 s%@PERL@%$PERL%g
 s%@SHELL_OVERRIDE@%$SHELL_OVERRIDE%g
 s%@MOZILLA_CLIENT@%$MOZILLA_CLIENT%g
 s%@HOST_CFLAGS@%$HOST_CFLAGS%g
+s%@HOST_LDFLAGS@%$HOST_LDFLAGS%g
 s%@GNU_CC@%$GNU_CC%g
 s%@GCC_USE_GNU_LD@%$GCC_USE_GNU_LD%g
 s%@MSC_VER@%$MSC_VER%g
 s%@CROSS_COMPILE@%$CROSS_COMPILE%g
 s%@MOZ_OPTIMIZE@%$MOZ_OPTIMIZE%g
 s%@USE_CPLUS@%$USE_CPLUS%g
 s%@USE_IPV6@%$USE_IPV6%g
 s%@USE_N32@%$USE_N32%g
@@ -6088,16 +6154,18 @@ s%@OPTIMIZER@%$OPTIMIZER%g
 s%@RC@%$RC%g
 s%@RCFLAGS@%$RCFLAGS%g
 s%@DLLFLAGS@%$DLLFLAGS%g
 s%@EXEFLAGS@%$EXEFLAGS%g
 s%@OS_DLLFLAGS@%$OS_DLLFLAGS%g
 s%@CYGWIN_WRAPPER@%$CYGWIN_WRAPPER%g
 s%@VISIBILITY_FLAGS@%$VISIBILITY_FLAGS%g
 s%@WRAP_SYSTEM_INCLUDES@%$WRAP_SYSTEM_INCLUDES%g
+s%@MACOS_SDK_DIR@%$MACOS_SDK_DIR%g
+s%@NEXT_ROOT@%$NEXT_ROOT%g
 
 CEOF
 EOF
 
 cat >> $CONFIG_STATUS <<\EOF
 
 # Split the substitutions into bite-sized pieces for seds with
 # small command number limits, like on Digital OSF/1 and HP-UX.
--- a/configure.in
+++ b/configure.in
@@ -1,56 +1,61 @@
 dnl -*- Mode: Autoconf; tab-width: 4; indent-tabs-mode: nil; -*-
 dnl 
-dnl The contents of this file are subject to the Mozilla Public
-dnl License Version 1.1 (the "License"); you may not use this file
-dnl except in compliance with the License. You may obtain a copy of
-dnl the License at http://www.mozilla.org/MPL/
-dnl 
-dnl Software distributed under the License is distributed on an "AS
-dnl IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
-dnl implied. See the License for the specific language governing
-dnl rights and limitations under the License.
-dnl 
+dnl ***** BEGIN LICENSE BLOCK *****
+dnl Version: MPL 1.1/GPL 2.0/LGPL 2.1
+dnl
+dnl The contents of this file are subject to the Mozilla Public License Version
+dnl 1.1 (the "License"); you may not use this file except in compliance with
+dnl the License. You may obtain a copy of the License at
+dnl http://www.mozilla.org/MPL/
+dnl
+dnl Software distributed under the License is distributed on an "AS IS" basis,
+dnl WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+dnl for the specific language governing rights and limitations under the
+dnl License.
+dnl
 dnl The Original Code is the Netscape Portable Runtime (NSPR).
-dnl 
-dnl The Initial Developer of the Original Code is Netscape
-dnl Communications Corporation.  Portions created by Netscape are 
-dnl Copyright (C) 1998o-2000 Netscape Communications Corporation.  All
-dnl Rights Reserved.
-dnl 
+dnl
+dnl The Initial Developer of the Original Code is
+dnl Netscape Communications Corporation.
+dnl Portions created by the Initial Developer are Copyright (C) 1998
+dnl the Initial Developer. All Rights Reserved.
+dnl
 dnl Contributor(s):
-dnl     Christopher Seawood <cls@seawood.org>
-dnl     Howard Chu <hyc@symas.com>
-dnl 
-dnl Alternatively, the contents of this file may be used under the
-dnl terms of the GNU General Public License Version 2 or later (the
-dnl "GPL"), in which case the provisions of the GPL are applicable 
-dnl instead of those above.  If you wish to allow use of your 
-dnl version of this file only under the terms of the GPL and not to
-dnl allow others to use your version of this file under the MPL,
-dnl indicate your decision by deleting the provisions above and
-dnl replace them with the notice and other provisions required by
-dnl the GPL.  If you do not delete the provisions above, a recipient
-dnl may use your version of this file under either the MPL or the
-dnl GPL.
-dnl 
+dnl   Christopher Seawood <cls@seawood.org>
+dnl   Howard Chu <hyc@symas.com>
+dnl   Mark Mentovai <mark@moxienet.com>
+dnl
+dnl Alternatively, the contents of this file may be used under the terms of
+dnl either the GNU General Public License Version 2 or later (the "GPL"), or
+dnl the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+dnl in which case the provisions of the GPL or the LGPL are applicable instead
+dnl of those above. If you wish to allow use of your version of this file only
+dnl under the terms of either the GPL or the LGPL, and not to allow others to
+dnl use your version of this file under the terms of the MPL, indicate your
+dnl decision by deleting the provisions above and replace them with the notice
+dnl and other provisions required by the GPL or the LGPL. If you do not delete
+dnl the provisions above, a recipient may use your version of this file under
+dnl the terms of any one of the MPL, the GPL or the LGPL.
+dnl
+dnl ***** END LICENSE BLOCK *****
 
 AC_PREREQ(2.12)
 AC_INIT(config/libc_r.h)
 
 AC_CONFIG_AUX_DIR(${srcdir}/build/autoconf)
 AC_CANONICAL_SYSTEM
 
 dnl ========================================================
 dnl = Defaults
 dnl ========================================================
 MOD_MAJOR_VERSION=4
 MOD_MINOR_VERSION=6
-MOD_PATCH_VERSION=1
+MOD_PATCH_VERSION=8
 NSPR_MODNAME=nspr20
 _HAVE_PTHREADS=
 USE_PTHREADS=
 USE_USER_PTHREADS=
 USE_NSPR_THREADS=
 USE_N32=
 USE_64=
 USE_CPLUS=
@@ -64,16 +69,18 @@ MOZ_OPTIMIZE=
 OBJDIR=.
 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=
 
 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 =
@@ -221,20 +228,27 @@ AC_ARG_ENABLE(64bit,
       fi ])
 
 AC_ARG_ENABLE(mdupdate,
     [  --enable-mdupdate       Enable use of certain compilers' mdupdate feature],
     [ if test "$enableval" = "yes"; then
 	    USE_MDUPDATE=1
       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.1 for ppc, 10.4 for x86]],
+                          [10.2 for ppc, 10.4 for x86]],
              [_MACOSX_DEPLOYMENT_TARGET=$enableval])
 
 dnl ========================================================
 dnl =
 dnl = Set the threading model
 dnl =
 dnl ========================================================
 case "$target" in
@@ -397,22 +411,47 @@ if test "$target" != "$host"; then
     AC_TRY_COMPILE([], [return(0);], 
         [ac_cv_prog_host_cc_works=1 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
 
+    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=$CXXLAGS
+        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
     AC_PROG_CC
     AC_CHECK_PROGS(CXX, $CXX "${target_alias}-g++" "${target}-g++", echo)
     unset ac_cv_prog_CXX
     AC_PROG_CXX
+
+    case "$build:$target" in
+      powerpc-apple-darwin8*:i?86-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)
 
 else
@@ -443,16 +482,25 @@ 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
@@ -576,16 +624,17 @@ 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 ;;
+        darwin*)      OS_ARCH=Darwin ;;
     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
@@ -912,106 +961,160 @@ case "$target" in
 
     ;;
 
 *-darwin*)
     AC_DEFINE(XP_UNIX)
     AC_DEFINE(DARWIN)
     AC_DEFINE(HAVE_BSD_FLOCK)
     CFLAGS="$CFLAGS -Wmost -fno-common"
-    if echo $OS_TEST | grep -c 86 2>/dev/null; then
-        AC_DEFINE(i386)
-        CPU_ARCH=i386
-    else
-        AC_DEFINE(ppc)
-        CPU_ARCH=ppc
-    fi
+    case "${target_cpu}" in
+        i*86*)
+            AC_DEFINE(i386)
+            CPU_ARCH=i386
+            PR_MD_ASFILES=os_Darwin_x86.s
+            ;;
+        *)
+            AC_DEFINE(ppc)
+            CPU_ARCH=ppc
+            PR_MD_ASFILES=os_Darwin_ppc.s
+            ;;
+    esac
     DSO_CFLAGS=-fPIC
     DSO_LDOPTS='-dynamiclib -compatibility_version 1 -current_version 1 -all_load -install_name @executable_path/$@ -headerpad_max_install_names'
     # Use the standard preprocessor (cpp)
     CFLAGS="$CFLAGS -no-cpp-precomp"
-    MKSHLIB='$(CC) -arch $(CPU_ARCH) $(DSO_LDOPTS) -o $@'
+    MKSHLIB='$(CC) $(DSO_LDOPTS) -o $@'
     STRIP="$STRIP -x -S"
     DLL_SUFFIX=dylib
     USE_PTHREADS=1
     MDCPUCFG_H=_darwin.cfg
     PR_MD_CSRCS=darwin.c
-    if test "$CPU_ARCH" = "ppc"; then
-        PR_MD_ASFILES=os_Darwin_ppc.s
-    fi
 
     # Add Mac OS X support for loading CFM & CFBundle plugins
     if test -f /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.1
-                    export MACOSX_DEPLOYMENT_TARGET=10.1
+                    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
-    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.
 
-    # do the right thing for SDK support
-    if test "$NEXT_ROOT"; then
-        dnl Synced to the MACOS_SDK_DIR block in Mozilla's top-level
-        dnl configure.in
+        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
 
-        dnl Current known valid versions for GCC_VERSION are 2.95.2 3.1 3.3 4.0.
-        dnl 4.0 identifies itself as 4.0.x, so strip the decidecimal for
-        dnl the environment and includedir purposes (when using an SDK, below),
-        dnl but remember the full version number for the libdir (SDK).
+            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
 
-        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/;'`
+                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}"
 
-        if test "$GCC_VERSION_MAJOR" -lt "4" ; then
-            dnl gcc < 4.0 only supports PowerPC, OK to hard-code
-            TARGET_ARCH_LIB="darwin"
-            TARGET_ARCH_INCLUDE="ppc-darwin"
-            SDK_C_INCLUDE="-isystem ${NEXT_ROOT}/usr/include/gcc/darwin/${GCC_VERSION} -isystem ${NEXT_ROOT}/usr/include -F${NEXT_ROOT}/System/Library/Frameworks"
-        else
-            dnl If gcc >= 4, use cpu-apple-darwin#, where # is the version
-            dnl of the Darwin release corresponding to the target Mac OS X
-            dnl release.  For OS X >= 10.1.1, take the minor version number and
-            dnl add 4 to get the Darwin major version number.  If it can't be 
-            dnl determined, use current Darwin major version number and hope
-            dnl that there's a symlink.
-            TARGET_ARCH_LIB=${target_cpu}-${target_vendor}-darwin`echo $NEXT_ROOT | $PERL -pe 's/MacOSX10\.([\d]*)//;if ($1) {$_=$1+4;} else {$_="'${target_os}'";s/(\d+)//;$_=$1;}'`
-            TARGET_ARCH_INCLUDE=$TARGET_ARCH_LIB
-            SDK_C_INCLUDE="-isystem ${NEXT_ROOT}/usr/lib/gcc/${TARGET_ARCH_LIB}/${GCC_VERSION_FULL}/include -isystem ${NEXT_ROOT}/usr/include -F${NEXT_ROOT}/System/Library/Frameworks"
+                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
+
+                dnl LDFLAGS is for the utilities built in config (now and
+                dnl nsinstall).  DSO_LDOPTS is used when linking shared
+                dnl libraries.
+                LDFLAGS="${MACOS_SDK_LIBS} $LDFLAGS"
+                DSO_LDOPTS="${MACOS_SDK_LIBS} $DSO_LDOPTS"
+                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.
+                dnl
+                dnl Both LDFLAGS and DSO_LDOPTS are set here, see the
+                dnl gcc < 4.0 case for the explanation.
+                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}"
+                    DSO_LDOPTS="$DSO_LDOPTS -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}"
+                    DSO_LDOPTS="$DSO_LDOPTS -Wl,-syslibroot,${MACOS_SDK_DIR}"
+                fi
+            fi
         fi
-
-        if test -d "${NEXT_ROOT}/Library/Frameworks" ; then
-            SDK_C_INCLUDE="$SDK_C_INCLUDE -F${NEXT_ROOT}/Library/Frameworks"
-        fi
-
-        CFLAGS="$CFLAGS -nostdinc ${SDK_C_INCLUDE}"
-
-        dnl CPP needs to be set for AC_CHECK_HEADER.
-        CPP="$CPP -nostdinc ${SDK_C_INCLUDE}"
-
-        OS_LIBS="-L${NEXT_ROOT}/usr/lib/gcc/${TARGET_ARCH_LIB} -L${NEXT_ROOT}/usr/lib/gcc/${TARGET_ARCH_LIB}/${GCC_VERSION_FULL} -L${NEXT_ROOT}/usr/lib $OS_LIBS"
     fi
     ;;
 
 *-dgux*)
     AC_DEFINE(XP_UNIX)
     AC_DEFINE(_PR_LOCAL_THREADS_ONLY)
     AC_DEFINE(SVR4)
     AC_DEFINE(SYSV)
@@ -1046,27 +1149,35 @@ case "$target" in
     MDCPUCFG_H=_freebsd.cfg
     PR_MD_CSRCS=freebsd.c
     ;;
 
 *-hpux*)
     AC_DEFINE(XP_UNIX)
     AC_DEFINE(HPUX)
     AC_DEFINE(_HPUX_SOURCE)
-    AC_DEFINE(hppa)
     # 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)
-    DLL_SUFFIX=sl
     DSO_LDOPTS='-b +h $(notdir $@)'
     PR_MD_CSRCS=hpux.c
-    if test "$OS_TEST" != "ia64"; then
+    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
@@ -1099,20 +1210,20 @@ case "$target" in
     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 (B.11.11) or higher
+    # 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.[2-9]*|B.11.1[1-9]*)
+    [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
@@ -1287,24 +1398,21 @@ case "$target" in
     ;;
 
 *-linux*)
     if test -z "$USE_NSPR_THREADS"; then
         USE_PTHREADS=1
         IMPL_STRATEGY=_PTH
     fi
     AC_DEFINE(XP_UNIX)
-    AC_DEFINE(_POSIX_SOURCE)
-    AC_DEFINE(_BSD_SOURCE)
-    AC_DEFINE(_SVID_SOURCE)
-    AC_DEFINE(_LARGEFILE64_SOURCE)
+    AC_DEFINE(_GNU_SOURCE)
     AC_DEFINE(HAVE_FCNTL_FILE_LOCKING)
     AC_DEFINE(LINUX)
-    CFLAGS="$CFLAGS -ansi -Wall"
-    CXXFLAGS="$CXXFLAGS -ansi -Wall"
+    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
@@ -2573,16 +2681,17 @@ 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(USE_CPLUS)
@@ -2654,16 +2763,18 @@ 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(NEXT_ROOT)
 
 dnl ========================================================
 dnl Generate output files.
 dnl ========================================================
 MAKEFILES="
 Makefile 
 config/Makefile
 config/autoconf.mk
@@ -2710,9 +2821,11 @@ elif test -n "$USE_PTHREADS"; then
 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_OUTPUT([$MAKEFILES], [chmod +x config/nspr-config])
--- a/lib/ds/Makefile.in
+++ b/lib/ds/Makefile.in
@@ -58,21 +58,16 @@ HEADERS = \
 	plarenas.h \
 	plarena.h \
 	plhash.h \
 	$(NULL)
 
 HEADERS := $(addprefix $(srcdir)/, $(HEADERS))
 
 ifeq ($(OS_ARCH), WINNT)
-ifdef NS_USE_GCC
-DLLBASE=-Wl,--image-base -Wl,0x30000000
-else
-DLLBASE=-BASE:0x30000000
-endif # GCC
 RES=$(OBJDIR)/plds.res
 RESNAME=plds.rc
 endif # WINNT
 
 ifeq ($(OS_ARCH), AIX)
 ifeq ($(CLASSIC_NSPR),1)
 OS_LIBS = -lc
 else
--- a/lib/libc/src/Makefile.in
+++ b/lib/libc/src/Makefile.in
@@ -68,21 +68,16 @@ CSRCS =\
 	$(NULL)
 
 LIBRARY_NAME	= plc
 LIBRARY_VERSION	= $(MOD_MAJOR_VERSION)
 
 RELEASE_LIBS = $(TARGETS)
 
 ifeq ($(OS_ARCH),WINNT)
-ifdef NS_USE_GCC
-DLLBASE=-Wl,--image-base -Wl,0x30000000
-else
-DLLBASE=-BASE:0x30000000
-endif
 RES=$(OBJDIR)/plc.res
 RESNAME=plc.rc
 endif # WINNT
 
 ifeq ($(OS_ARCH), AIX)
 ifeq ($(CLASSIC_NSPR),1)
 OS_LIBS = -lc
 else
--- a/lib/msgc/src/Makefile.in
+++ b/lib/msgc/src/Makefile.in
@@ -64,21 +64,16 @@ NSPR_VERSION = $(MOD_MAJOR_VERSION)
 
 EXTRA_LIBS = $(LIBNSPR)
 
 ifdef RESOLVE_LINK_SYMBOLS
 EXTRA_LIBS += $(OS_LIBS)
 endif
 
 ifeq ($(OS_ARCH), WINNT)
-ifdef NS_USE_GCC
-DLLBASE=-Wl,--image-base -Wl,0x30000000
-else
-DLLBASE=-BASE:0x30000000
-endif # GCC
 #RES=$(OBJDIR)/ds.res
 #RESNAME=$(MOD_DEPTH)/pr/src/nspr.rc
 #OS_LIBS = user32.lib
 endif # WINNT
 
 LIBRARY_NAME = msgc
 LIBRARY_VERSION = $(MOD_MAJOR_VERSION)
 
--- a/lib/prstreams/Makefile.in
+++ b/lib/prstreams/Makefile.in
@@ -83,17 +83,16 @@ CSRCS = \
 
 CXXSRCS = \
 	prstrms.cpp \
 	$(NULL)
 
 OBJS = $(addprefix $(OBJDIR)/,$(CSRCS:.c=.$(OBJ_SUFFIX)) $(CXXSRCS:.cpp=.$(OBJ_SUFFIX)))
 
 ifeq ($(OS_ARCH), WINNT)
-        DLLBASE=-BASE:0x30000000
         RES=$(OBJDIR)/prstrms.res
         RESNAME=prstrms.rc
         OS_LIBS = user32.lib
 else
     ifeq ($(OS_ARCH),OS2)
       ifneq ($(MOZ_OS2_TOOLS),VACPP)
          OS_LIBS = -lstdcpp
       endif
--- a/pkg/linux/Makefile.in
+++ b/pkg/linux/Makefile.in
@@ -42,17 +42,19 @@
 #
 
 MOD_DEPTH = ../..
 topsrcdir   = @top_srcdir@
 srcdir	    = @srcdir@
 VPATH	    = @srcdir@
 
 NAME        = sun-nspr
-RELEASE     = 1
+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
 
@@ -71,17 +73,17 @@ publish:
 	| (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 private obsolete/pralarm.h obsolete/probslet.h obsolete/prsem.h)
 	tar czvf SOURCES/$(NAME)-$(VERSION).tar.gz opt
 	echo "%define name $(NAME)" >$(SPECFILE)
 	echo "%define version $(VERSION)" >>$(SPECFILE)
-	echo "%define release $(RELEASE)" >>$(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)
--- a/pkg/solaris/SUNWprd/prototype
+++ b/pkg/solaris/SUNWprd/prototype
@@ -1,12 +1,13 @@
 # 
 # Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
+# ***** BEGIN LICENSE BLOCK *****
 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
 #
 # The contents of this file are subject to the Mozilla Public License Version
 # 1.1 (the "License"); you may not use this file except in compliance with
 # the License. You may obtain a copy of the License at
 # http://www.mozilla.org/MPL/
 #
 # Software distributed under the License is distributed on an "AS IS" basis,
--- a/pr/include/md/_beos.cfg
+++ b/pr/include/md/_beos.cfg
@@ -1,41 +1,44 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 
- * The contents of this file are subject to the Mozilla Public
- * License Version 1.1 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.mozilla.org/MPL/
- * 
- * Software distributed under the License is distributed on an "AS
- * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
- * implied. See the License for the specific language governing
- * rights and limitations under the License.
- * 
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
  * The Original Code is the Netscape Portable Runtime (NSPR).
- * 
- * The Initial Developer of the Original Code is Netscape
- * Communications Corporation.  Portions created by Netscape are 
- * Copyright (C) 1998-2000 Netscape Communications Corporation.  All
- * Rights Reserved.
- * 
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 1998-2000
+ * the Initial Developer. All Rights Reserved.
+ *
  * Contributor(s):
- * 
- * Alternatively, the contents of this file may be used under the
- * terms of the GNU General Public License Version 2 or later (the
- * "GPL"), in which case the provisions of the GPL are applicable 
- * instead of those above.  If you wish to allow use of your 
- * version of this file only under the terms of the GPL and not to
- * allow others to use your version of this file under the MPL,
- * indicate your decision by deleting the provisions above and
- * replace them with the notice and other provisions required by
- * the GPL.  If you do not delete the provisions above, a recipient
- * may use your version of this file under either the MPL or the
- * GPL.
- */
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
 
 #ifndef nspr_cpucfg___
 #define nspr_cpucfg___
 
 #ifndef XP_BEOS
 #define XP_BEOS
 #undef XP_UNIX
 #endif
--- a/pr/include/md/_darwin.cfg
+++ b/pr/include/md/_darwin.cfg
@@ -89,16 +89,17 @@
 
 #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
 
 #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
--- a/pr/include/md/_darwin.h
+++ b/pr/include/md/_darwin.h
@@ -43,34 +43,34 @@
 #include <sys/syscall.h>
 
 #ifdef XP_MACOSX
 #include <AvailabilityMacros.h>
 #endif
 
 #define PR_LINKER_ARCH	"darwin"
 #define _PR_SI_SYSNAME  "DARWIN"
-#ifdef i386
+#ifdef __i386__
 #define _PR_SI_ARCHITECTURE "x86"
-#else
+#elif defined(__ppc__)
 #define _PR_SI_ARCHITECTURE "ppc"
 #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
 #define USE_MACH_DYLD
 #define _PR_HAVE_SOCKADDR_LEN  
 #define _PR_STAT_HAS_ST_ATIMESPEC
-#define _PR_NO_LARGE_FILES
+#define _PR_HAVE_LARGE_OFF_T
 #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.
  */
@@ -108,17 +108,28 @@
 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__ */
+#elif defined(__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__ */
 
 #define USE_SETJMP
 
 #if !defined(_PR_PTHREADS)
 
 #include <setjmp.h>
 
 #define PR_CONTEXT_TYPE	jmp_buf
--- a/pr/include/md/_hpux.h
+++ b/pr/include/md/_hpux.h
@@ -39,18 +39,28 @@
 #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.
@@ -75,24 +85,54 @@
 #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
 
-#undef _PR_HAVE_ATOMIC_OPS
+#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
 
-#ifdef _PR_INET6
-#define _PR_HAVE_INET_NTOP
 #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
+#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
--- a/pr/include/md/_netbsd.h
+++ b/pr/include/md/_netbsd.h
@@ -1,41 +1,44 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 
- * The contents of this file are subject to the Mozilla Public
- * License Version 1.1 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.mozilla.org/MPL/
- * 
- * Software distributed under the License is distributed on an "AS
- * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
- * implied. See the License for the specific language governing
- * rights and limitations under the License.
- * 
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
  * The Original Code is the Netscape Portable Runtime (NSPR).
- * 
- * The Initial Developer of the Original Code is Netscape
- * Communications Corporation.  Portions created by Netscape are 
- * Copyright (C) 1998-2000 Netscape Communications Corporation.  All
- * Rights Reserved.
- * 
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 1998-2000
+ * the Initial Developer. All Rights Reserved.
+ *
  * Contributor(s):
- * 
- * Alternatively, the contents of this file may be used under the
- * terms of the GNU General Public License Version 2 or later (the
- * "GPL"), in which case the provisions of the GPL are applicable 
- * instead of those above.  If you wish to allow use of your 
- * version of this file only under the terms of the GPL and not to
- * allow others to use your version of this file under the MPL,
- * indicate your decision by deleting the provisions above and
- * replace them with the notice and other provisions required by
- * the GPL.  If you do not delete the provisions above, a recipient
- * may use your version of this file under either the MPL or the
- * GPL.
- */
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
 
 #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"
@@ -99,109 +102,49 @@
 
 #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
 */
-#ifdef __i386__
-#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)			\
-{									\
-    sigsetjmp(CONTEXT(_thread), 1);					\
-    CONTEXT(_thread)[2] = (unsigned char*) ((_sp) - 128);		\
-    CONTEXT(_thread)[0] = (int) _main;					\
-    *status = PR_TRUE;							\
-}
-#define	_MD_GET_SP(_thread)	CONTEXT(_thread)[2]
-#endif
-#ifdef __sparc_v9__
-#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)			\
-{									\
-    sigsetjmp(CONTEXT(_thread), 1);					\
-    CONTEXT(_thread)[1] = (unsigned char*) ((_sp) - 176 - 0x7ff);	\
-    CONTEXT(_thread)[2] = (long) _main;					\
-    CONTEXT(_thread)[3] = (long) _main + 4;				\
-    *status = PR_TRUE;							\
-}
-#define	_MD_GET_SP(_thread)	(CONTEXT(_thread)[2]+0x7ff)
-#elif defined(__sparc__)
-#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)			\
-{									\
-    sigsetjmp(CONTEXT(_thread), 1);					\
-    CONTEXT(_thread)[2] = (unsigned char*) ((_sp) - 128);		\
-    CONTEXT(_thread)[3] = (int) _main;					\
-    CONTEXT(_thread)[4] = (int) _main + 4;				\
-    *status = PR_TRUE;							\
-}
-#define	_MD_GET_SP(_thread)	CONTEXT(_thread)[2]
-#endif
-#ifdef __powerpc__
-#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)			\
-{									\
-    sigsetjmp(CONTEXT(_thread), 1);					\
-    CONTEXT(_thread)[3] = (unsigned char*) ((_sp) - 128);		\
-    CONTEXT(_thread)[4] = (int) _main;					\
-    *status = PR_TRUE;							\
+#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_GET_SP(_thread)	CONTEXT(_thread)[3]
-#endif
-#ifdef __m68k__
-#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)			\
-{									\
-    sigsetjmp(CONTEXT(_thread), 1);					\
-    CONTEXT(_thread)[2] = (unsigned char*) ((_sp) - 128);		\
-    CONTEXT(_thread)[5] = (int) _main;					\
-    *status = PR_TRUE;							\
-}
-#define	_MD_GET_SP(_thread)	CONTEXT(_thread)[2]
-#endif
-#ifdef __mips__
-#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)			\
-{									\
-    sigsetjmp(CONTEXT(_thread), 1);					\
-    CONTEXT(_thread)[32] = (unsigned char*) ((_sp) - 128);		\
-    CONTEXT(_thread)[2] = (int) _main;					\
-    CONTEXT(_thread)[28] = (int) _main;					\
-    *status = PR_TRUE;							\
-}
-#define	_MD_GET_SP(_thread)	CONTEXT(_thread)[32]
-#endif
-#if defined(__arm32__) || defined(__arm__) || defined(__armel__) \
-    || defined(__armeb__)
-#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)			\
-{									\
-    sigsetjmp(CONTEXT(_thread), 1);					\
-    CONTEXT(_thread)[23] = (unsigned char*) ((_sp) - 128);		\
-    CONTEXT(_thread)[24] = (int) _main;					\
-    *status = PR_TRUE;							\
-}
-#define	_MD_GET_SP(_thread)	CONTEXT(_thread)[23]
-#endif
-#ifdef __alpha__
-#define _MD_INIT_CONTEXT(_thread, _sp, _main, status)			\
-{									\
-    sigsetjmp(CONTEXT(_thread), 1);					\
-    CONTEXT(_thread)[34] = (unsigned char*) ((_sp) - 128);		\
-    CONTEXT(_thread)[2] = (long) _main;					\
-    CONTEXT(_thread)[30] = (long) _main;				\
-    CONTEXT(_thread)[31] = (long) _main;				\
-    *status = PR_TRUE;							\
-}
-#define	_MD_GET_SP(_thread)	CONTEXT(_thread)[34]
-#endif
-#ifndef _MD_INIT_CONTEXT
-#error "Need to define _MD_INIT_CONTEXT for this platform"
-#endif
-
-#define PR_NUM_GCREGS	_JBLEN
 
 #define _MD_SWITCH_CONTEXT(_thread)  \
     if (!sigsetjmp(CONTEXT(_thread), 1)) {  \
         (_thread)->md.errcode = errno;  \
         _PR_Schedule();  \
     }
 
 /*
--- a/pr/include/md/_openvms.h
+++ b/pr/include/md/_openvms.h
@@ -96,16 +96,17 @@ struct ip_mreq {
 #define HAVE_DLL
 #define USE_DLFCN
 
 #define _PR_POLL_AVAILABLE
 #define _PR_USE_POLL
 #define _PR_STAT_HAS_ONLY_ST_ATIME
 #define _PR_NO_LARGE_FILES
 #define _PR_STRICT_ADDR_LEN
+#define _PR_NEED_SECRET_AF
 
 /* IPv6 support */
 #ifdef _SOCKADDR_LEN
 #define _PR_HAVE_SOCKADDR_LEN
 #endif
 #define _PR_HAVE_GETIPNODEBYNAME
 #define _PR_HAVE_GETIPNODEBYADDR
 #define _PR_HAVE_GETADDRINFO
--- a/pr/include/md/_pth.h
+++ b/pr/include/md/_pth.h
@@ -197,23 +197,16 @@
  */
 #if (defined(AIX) && !defined(AIX4_3_PLUS)) || defined(LINUX) \
 	|| defined(FREEBSD) || defined(NETBSD) || defined(OPENBSD) \
 	|| defined(BSDI) || defined(VMS) || defined(UNIXWARE) \
 	|| defined(DARWIN)
 #define PT_NO_SIGTIMEDWAIT
 #endif
 
-/*
- * These platforms don't have pthread_kill()
- */
-#if defined(DARWIN)
-#define pthread_kill(thread, sig) ENOSYS
-#endif
-
 #if defined(OSF1) || defined(VMS)
 #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)
--- a/pr/include/md/_win95.h
+++ b/pr/include/md/_win95.h
@@ -260,26 +260,29 @@ extern PRInt32 _MD_CloseFile(PRInt32 osf
 #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 --- */
+extern PRBool _pr_useUnicode;
 #ifdef MOZ_UNICODE
-/* --- UTF16 IO stuff --- */
 #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
--- a/pr/include/md/_winnt.h
+++ b/pr/include/md/_winnt.h
@@ -107,16 +107,17 @@ struct _md_sockaddr_in6 {
 #define _PR_HAVE_THREADSAFE_GETHOST
 #define _PR_HAVE_ATOMIC_OPS
 #define _PR_HAVE_ATOMIC_CAS
 #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 *);
--- a/pr/include/obsolete/probslet.h
+++ b/pr/include/obsolete/probslet.h
@@ -153,16 +153,25 @@ NSPR_API(PRInt32) PR_Select(
 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(PRInt32 osfd, PR_fd_set *set);
 NSPR_API(void)        PR_FD_NCLR(PRInt32 osfd, PR_fd_set *set);
 NSPR_API(PRInt32)     PR_FD_NISSET(PRInt32 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
 #ifdef XP_MAC
 #include <stat.h>
 #else
 #include <sys/stat.h>
 #endif
 
 NSPR_API(PRInt32) PR_Stat(const char *path, struct stat *buf);
--- a/pr/include/obsolete/protypes.h
+++ b/pr/include/obsolete/protypes.h
@@ -147,24 +147,22 @@ typedef PRInt64 int64;
 
 /*
  * int32
  */
 
 #if !defined(XP_BEOS) && !defined(VMS) \
     && !defined(_PR_AIX_HAVE_BSD_INT_TYPES) \
     && !defined(HPUX)
-#if !defined(WIN32) || !defined(_WINSOCK2API_)  /* defines its own "int32" */
 #if !defined(XP_MAC) && !defined(_WIN32) && !defined(XP_OS2) && !defined(NTO)
 typedef PRInt32 int32;
 #else
 typedef long int32;
 #endif
 #endif
-#endif
 
 /*
  * int16
  */
 
 #if !defined(XP_BEOS) && !defined(VMS) \
     && !defined(_PR_AIX_HAVE_BSD_INT_TYPES) \
     && !defined(HPUX)
--- a/pr/include/prinet.h
+++ b/pr/include/prinet.h
@@ -55,20 +55,16 @@
  *     This file is intended to be included by nspr20 public header
  *     files, such as prio.h.  One should not include this file directly.
  */
 
 #ifndef prinet_h__
 #define prinet_h__
 
 #if defined(XP_UNIX) || defined(XP_OS2) || defined(XP_BEOS)
-#ifdef LINUX
-#undef __STRICT_ANSI__
-#define __STRICT_ANSI__
-#endif
 #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
--- a/pr/include/prinit.h
+++ b/pr/include/prinit.h
@@ -58,21 +58,21 @@ PR_BEGIN_EXTERN_C
 /*
 ** 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.6.1 Beta"
+#define PR_VERSION  "4.6.8"
 #define PR_VMAJOR   4
 #define PR_VMINOR   6
-#define PR_VPATCH   1
-#define PR_BETA     PR_TRUE
+#define PR_VPATCH   8
+#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.
 **
--- a/pr/include/private/primpl.h
+++ b/pr/include/private/primpl.h
@@ -1740,22 +1740,20 @@ struct PRFilePrivate {
 #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_STRICT_ADDR_LEN
-    PRUint16 af;        /* If the platform requires passing the exact
-                         * length of the sockaddr structure for the
-                         * address family of the socket to socket
-                         * functions like accept(), we need to save
-                         * the address family of the socket. */
+#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
 };
 
 struct PRDir {
     PRDirEntry d;
     _MDDir md;
 };
 
@@ -1775,22 +1773,24 @@ 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_NotifyCondVar(PRCondVar *cvar, PRThread *me);
 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_CleanupNet(void);
 extern void _PR_CleanupLayerCache(void);
 extern void _PR_CleanupStacks(void);
 #ifdef WINNT
--- a/pr/include/prlink.h
+++ b/pr/include/prlink.h
@@ -113,25 +113,26 @@ NSPR_API(PRLibrary*) PR_LoadLibrary(cons
 ** for a particular platform.
 **
 ** On some operating systems such as Mac OS, 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 three types of library specification:
-** a pathname, a Mac code fragment by name, and a Mac code fragment
-** by 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_MacIndexedFragment, /* obsolete (for Mac OS Classic) */
+    PR_LibSpec_PathnameU           /* supported only on Win32 */ 
 } PRLibSpecType;
 
 struct FSSpec; /* Mac OS FSSpec */
 
 typedef struct PRLibSpec {
     PRLibSpecType type;
     union {
         /* if type is PR_LibSpec_Pathname */
@@ -143,29 +144,33 @@ typedef struct PRLibSpec {
             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 */
+/*                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 */
--- a/pr/include/prsystem.h
+++ b/pr/include/prsystem.h
@@ -65,20 +65,23 @@ NSPR_API(char) PR_GetDirectorySepartor(v
 **  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,
+    PR_SI_HOSTNAME,  /* the hostname with the domain name (if any)
+                      * removed */
     PR_SI_SYSNAME,
     PR_SI_RELEASE,
-    PR_SI_ARCHITECTURE
+    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().
 **
--- a/pr/include/prtypes.h
+++ b/pr/include/prtypes.h
@@ -173,17 +173,19 @@
 #define PR_EXTERN_DATA(__type) extern __type
 #define PR_IMPLEMENT_DATA(__type) __type
 #define PR_CALLBACK _Optlink
 #define PR_CALLBACK_DECL
 #define PR_STATIC_CALLBACK(__x) static __x PR_CALLBACK
 
 #else /* Unix */
 
-#ifdef HAVE_VISIBILITY_PRAGMA
+/* 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
@@ -463,29 +465,24 @@ typedef PRIntn PRBool;
 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;
 
-#ifdef MOZ_UNICODE
-/*
- * EXPERIMENTAL: This type may be removed in a future release.
- */
 #ifndef __PRUNICHAR__
 #define __PRUNICHAR__
 #if defined(WIN32) || defined(XP_MAC)
 typedef wchar_t PRUnichar;
 #else
 typedef PRUint16 PRUnichar;
 #endif
 #endif
-#endif /* MOZ_UNICODE */
 
 /*
 ** 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
--- a/pr/src/Makefile.in
+++ b/pr/src/Makefile.in
@@ -193,19 +193,19 @@ OS_LIBS		= -lsocket -lc
 endif
 
 ifeq ($(OS_ARCH),NEWS-OS)
 OS_LIBS		= -lsocket -lnsl -lgen -lresolv
 endif
 
 ifeq ($(OS_ARCH),WINNT)
 ifdef NS_USE_GCC
-OS_LIBS		= -ladvapi32 -lwsock32
+OS_LIBS		= -ladvapi32 -lwsock32 -lwinmm
 else
-OS_LIBS		= advapi32.lib wsock32.lib
+OS_LIBS		= advapi32.lib wsock32.lib winmm.lib
 endif
 endif
 
 ifeq ($(OS_TARGET),MacOSX)
 OS_LIBS		= -framework CoreServices -framework CoreFoundation
 endif
 
 ifdef GC_LEAK_DETECTOR
@@ -311,21 +311,16 @@ OBJS += \
 	cplus/$(OBJDIR)/rctime.$(OBJ_SUFFIX)
 endif
 
 ifdef GC_LEAK_DETECTOR
 OBJS += memory/$(OBJDIR)/prgcleak.$(OBJ_SUFFIX)
 endif
 
 ifeq ($(OS_ARCH), WINNT)
-ifdef NS_USE_GCC
-DLLBASE=-Wl,--image-base -Wl,0x30000000
-else
-DLLBASE=-BASE:0x30000000
-endif # GCC
 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
--- a/pr/src/io/prfdcach.c
+++ b/pr/src/io/prfdcach.c
@@ -272,16 +272,24 @@ void _PR_InitFdCache(void)
     _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_fd_cache.stack = PR_CreateStack("FD");
     PR_ASSERT(NULL != _pr_fd_cache.stack);
 
--- a/pr/src/io/prfile.c
+++ b/pr/src/io/prfile.c
@@ -94,20 +94,19 @@ static PRInt32 PR_CALLBACK FileWrite(PRF
         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 ( PR_TRUE == fd->secret->appendMode ) {
-        rv = PR_Seek(fd, 0, PR_SEEK_END );
-        if ( -1 == rv )  {
-            return rv;
+    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;
@@ -407,17 +406,17 @@ PR_IMPLEMENT(PRFileDesc*) PR_OpenFile(
             fd->secret->appendMode = appendMode;
 #endif
             _PR_MD_INIT_FD_INHERITABLE(fd, PR_FALSE);
         }
     }
     return fd;
 }
 
-PRInt32 PR_GetSysfdTableMax(void)
+PR_IMPLEMENT(PRInt32) PR_GetSysfdTableMax(void)
 {
 #if defined(XP_UNIX) && !defined(AIX) && !defined(NEXTSTEP) && !defined(QNX)
     struct rlimit rlim;
 
     if ( getrlimit(RLIMIT_NOFILE, &rlim) < 0) {
        /* XXX need to call PR_SetError() */
        return -1;
     }
@@ -440,17 +439,17 @@ PRInt32 PR_GetSysfdTableMax(void)
 #elif defined (XP_MAC) || defined(XP_BEOS)
     PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
    return -1;
 #else
     write me;
 #endif
 }
 
-PRInt32 PR_SetSysfdTableSize(int table_size)
+PR_IMPLEMENT(PRInt32) PR_SetSysfdTableSize(int table_size)
 {
 #if defined(XP_UNIX) && !defined(AIX) && !defined(NEXTSTEP) && !defined(QNX)
     struct rlimit rlim;
     PRInt32 tableMax = PR_GetSysfdTableMax();
 
     if (tableMax < 0) 
         return -1;
 
--- a/pr/src/io/prlog.c
+++ b/pr/src/io/prlog.c
@@ -250,16 +250,22 @@ void _PR_InitLog(void)
             }
             /*found:*/
             count = sscanf(&ev[pos], " , %n", &delta);
             pos += delta;
             if (count == EOF) break;
         }
         PR_SetLogBuffering(isSync ? bufSize : 0);
 
+#ifdef XP_UNIX
+        if ((getuid() != geteuid()) || (getgid() != getegid())) {
+            return;
+        }
+#endif /* XP_UNIX */
+
         ev = PR_GetEnv("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) {
                     OutputDebugString(str);
                     PR_smprintf_free(str);
@@ -288,20 +294,22 @@ void _PR_LogCleanup(void)
     if (logFile
         && logFile != stdout
         && logFile != stderr
 #ifdef XP_PC
         && logFile != WIN32_DEBUG_FILE
 #endif
         ) {
         fclose(logFile);
+        logFile = NULL;
     }
 #else
     if (logFile && logFile != _pr_stdout && logFile != _pr_stderr) {
         PR_Close(logFile);
+        logFile = NULL;
     }
 #endif
 
     while (lm != NULL) {
         PRLogModuleInfo *next = lm->next;
         free((/*const*/ char *)lm->name);
         PR_Free(lm);
         lm = next;
--- a/pr/src/io/prprf.c
+++ b/pr/src/io/prprf.c
@@ -368,34 +368,41 @@ static int cvt_f(SprintfState *ss, doubl
     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 *s, int width, int prec,
+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 */
-    slen = s ? strlen(s) : 6;
+    if (!str) {
+    	str = "(null)";
+    } 
     if (prec > 0) {
-	if (prec < slen) {
-	    slen = prec;
-	}
+	/* 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, s ? s : "(null)", slen, width, flags);
+    return fill2(ss, str, slen, width, flags);
 }
 
 /*
 ** BuildArgArray stands for Numbered Argument list Sprintf
 ** for example,  
 **	fmp = "%4$i, %2$d, %3s, %1d";
 ** the number must start from 1, and no gap among them
 */
--- a/pr/src/io/prsocket.c
+++ b/pr/src/io/prsocket.c
@@ -194,16 +194,23 @@ PR_IMPLEMENT(PRFileDesc *) PR_ImportTCPS
 {
 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(PRInt32 osfd)
 {
 PRFileDesc *fd;
@@ -509,16 +516,19 @@ PRIntervalTime timeout)
 		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)
 {
@@ -938,16 +948,19 @@ PRIntervalTime timeout)
 			(*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,
@@ -989,16 +1002,19 @@ void *callbackArg)
 			(*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)
@@ -1307,16 +1323,19 @@ PR_IMPLEMENT(PRFileDesc*) PR_Socket(PRIn
 	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);
--- a/pr/src/linking/Makefile.in
+++ b/pr/src/linking/Makefile.in
@@ -57,24 +57,19 @@ endif
 CSRCS =           \
 	prlink.c   \
 	$(NULL)
 
 TARGETS	= $(OBJS)
 
 INCLUDES = -I$(dist_includedir) -I$(topsrcdir)/pr/include -I$(topsrcdir)/pr/include/private
 
-# For Dl_info and dladdr.
-ifeq ($(OS_TARGET),Linux)
-DEFINES    += -D_GNU_SOURCE
-endif
-
 # On Mac OS X use flat #includes.
 ifeq ($(OS_TARGET),MacOSX)
-INCLUDES    += -I$(NEXT_ROOT)/Developer/Headers/FlatCarbon
+INCLUDES    += -I$(MACOS_SDK_DIR)/Developer/Headers/FlatCarbon
 endif
 
 DEFINES += -D_NSPR_BUILD_
 
 include $(topsrcdir)/config/rules.mk
 
 export:: $(TARGETS)
 
--- a/pr/src/linking/prlink.c
+++ b/pr/src/linking/prlink.c
@@ -1,41 +1,45 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 
- * The contents of this file are subject to the Mozilla Public
- * License Version 1.1 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.mozilla.org/MPL/
- * 
- * Software distributed under the License is distributed on an "AS
- * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
- * implied. See the License for the specific language governing
- * rights and limitations under the License.
- * 
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
  * The Original Code is the Netscape Portable Runtime (NSPR).
- * 
- * The Initial Developer of the Original Code is Netscape
- * Communications Corporation.  Portions created by Netscape are 
- * Copyright (C) 1998-2000 Netscape Communications Corporation.  All
- * Rights Reserved.
- * 
- * Contributor(s): Steve Streeter (Hewlett-Packard Company)
- * 
- * Alternatively, the contents of this file may be used under the
- * terms of the GNU General Public License Version 2 or later (the
- * "GPL"), in which case the provisions of the GPL are applicable 
- * instead of those above.  If you wish to allow use of your 
- * version of this file only under the terms of the GPL and not to
- * allow others to use your version of this file under the MPL,
- * indicate your decision by deleting the provisions above and
- * replace them with the notice and other provisions required by
- * the GPL.  If you do not delete the provisions above, a recipient
- * may use your version of this file under either the MPL or the
- * GPL.
- */
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 1998-2000
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Steve Streeter (Hewlett-Packard Company)
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
 
 #include "primpl.h"
 
 #include <string.h>
 
 #ifdef XP_BEOS
 #include <image.h>
 #endif
@@ -152,16 +156,18 @@ struct _imcb *IAC$GL_IMAGE_LIST = NULL;
  * On these platforms, symbols have a leading '_'.
  */
 #if defined(SUNOS4) || defined(DARWIN) || defined(NEXTSTEP) \
     || defined(WIN16) || 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;
 
@@ -199,16 +205,26 @@ struct PRLibrary {
 
 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);
 
+#ifdef WIN95
+typedef HMODULE (WINAPI *LoadLibraryWFn)(LPCWSTR);
+static HMODULE WINAPI EmulateLoadLibraryW(LPCWSTR);
+static LoadLibraryWFn loadLibraryW = LoadLibraryW;
+#endif
+
+#ifdef WIN32
+static int pr_ConvertUTF16toUTF8(LPCWSTR wname, LPSTR name, int len);
+#endif
+
 /************************************************************************/
 
 #if !defined(USE_DLFCN) && !defined(HAVE_STRERROR)
 static char* errStrBuf = NULL;
 #define ERR_STR_BUF_LENGTH    20
 static char* errno_string(PRIntn oserr)
 {
     if (errStrBuf == NULL)
@@ -239,16 +255,22 @@ static void DLLErrorInternal(PRIntn oser
 
 void _PR_InitLinker(void)
 {
     PRLibrary *lm = NULL;
 #if defined(XP_UNIX)
     void *h;
 #endif
 
+#ifdef WIN95
+    if (!_pr_useUnicode) {
+        loadLibraryW = EmulateLoadLibraryW;
+    }
+#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");
@@ -551,16 +573,26 @@ 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)
@@ -739,33 +771,89 @@ pr_LoadViaDyld(const char *name, PRLibra
          * error information.
          */
     }
     return (lm->dlh != NULL || lm->image != NULL) ? PR_SUCCESS : PR_FAILURE;
 }
 
 #endif /* XP_MACOSX */
 
+#ifdef WIN95
+static HMODULE WINAPI
+EmulateLoadLibraryW(LPCWSTR lpLibFileName)
+{
+    HMODULE h;
+    char nameA[MAX_PATH];
+
+    if (!WideCharToMultiByte(CP_ACP, 0, lpLibFileName, -1,
+                             nameA, sizeof nameA, NULL, NULL)) {
+        return NULL;
+    }
+    /* Perhaps it's better to add a check for characters 
+     * not representable in CP_ACP.
+     */
+    h = LoadLibraryA(nameA);
+    return h;
+}
+#endif /* WIN95 */
+
 /*
 ** 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;
+    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 = pr_ConvertUTF16toUTF8(wname, NULL, 0);
+    if (len > MAX_PATH)
+        utf8name = utf8name_malloc = PR_Malloc(len);
+    if (utf8name == NULL ||
+        !pr_ConvertUTF16toUTF8(wname, utf8name, len)) {
+        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;
@@ -788,23 +876,41 @@ pr_LoadLibraryByPathname(const char *nam
           pr_loadmap = lm;
     }
 #endif /* XP_OS2 */
 
 #if defined(WIN32) || defined(WIN16)
     {
     HINSTANCE h;
 
+#ifdef WIN32
+#ifdef WIN95
+    if (flags & PR_LD_PATHW)
+        h = loadLibraryW(wname);
+    else
+        h = LoadLibraryA(name);
+#else
+    if (flags & PR_LD_PATHW)
+        h = LoadLibraryW(wname);
+    else
+        h = LoadLibraryA(name);
+#endif /* WIN95 */
+#else 
     h = LoadLibrary(name);
+#endif
     if (h < (HINSTANCE)HINSTANCE_ERROR) {
         oserr = _MD_ERRNO();
         PR_DELETE(lm);
         goto unlock;
     }
+#ifdef WIN32
+    lm->name = strdup(utf8name);
+#else
     lm->name = strdup(name);
+#endif
     lm->dlh = h;
     lm->next = pr_loadmap;
     pr_loadmap = lm;
     }
 #endif /* WIN32 || WIN16 */
 
 #ifdef XP_MACOSX
     {
@@ -991,20 +1097,145 @@ pr_LoadLibraryByPathname(const char *nam
     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;
 }
 
+#ifdef WIN32
+#ifdef WIN95
+/*
+ * CP_UTF8 is not supported by WideCharToMultiByte on Windows 95 so that 
+ * we have to emulate it
+ */
+static PRStatus 
+pr_ConvertSingleCharToUTF8(PRUint32 usv, PRUint16 offset, int bufLen,
+                           int *utf8Len, char * *buf)
+{
+    char* p = *buf;
+    PR_ASSERT(!bufLen || *buf);
+    if (!bufLen) {
+        *utf8Len += offset;
+        return PR_SUCCESS;
+    }
+
+    if (*utf8Len + offset >= bufLen)
+        return PR_FAILURE;
+
+    *utf8Len += offset;
+    if (offset == 1) {
+        *p++ = (char) usv;
+    } else if (offset == 2) {
+        *p++ = (char)0xc0 | (usv >> 6);
+        *p++ = (char)0x80 | (usv & 0x003f);
+    } else if (offset == 3) {
+        *p++ = (char)0xe0 | (usv >> 12);
+        *p++ = (char)0x80 | ((usv >> 6) & 0x003f);
+        *p++ = (char)0x80 | (usv & 0x003f);
+    } else { /* offset = 4 */
+        *p++ = (char)0xf0 | (usv >> 18);
+        *p++ = (char)0x80 | ((usv >> 12) & 0x003f);
+        *p++ = (char)0x80 | ((usv >> 6) & 0x003f);
+        *p++ = (char)0x80 | (usv & 0x003f);
+    }
+
+    *buf = p;
+    return PR_SUCCESS;
+}
+
+static int pr_ConvertUTF16toUTF8(LPCWSTR wname, LPSTR name, int len)
+{
+    LPCWSTR pw = wname;
+    LPSTR p = name;
+    int utf8Len = 0;
+    PRBool highSurrogate = PR_FALSE;
+
+    utf8Len = WideCharToMultiByte(CP_UTF8, 0, wname, -1, name, len, 
+                                  NULL, NULL);
+    /*
+     * Windows 95 and NT 3.51 don't support CP_UTF8.
+     * WideCharToMultiByte(CP_UTF8, ...) fails with the error code
+     * ERROR_INVALID_PARAMETER on Windows 95 and NT 3.51.
+     */
+    if (utf8Len || GetLastError() != ERROR_INVALID_PARAMETER)
+        return utf8Len;
+
+    if (!wname || len < 0 || (len > 0 && !name)) {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return 0;
+    }
+
+    while (*pw) {
+        PRStatus status = PR_SUCCESS;
+        if (highSurrogate) {
+            if (*pw >= (PRUnichar) 0xDC00 && *pw < (PRUnichar) 0xE000) {
+                /* found a matching low surrogate */
+                /* convert a surrogate pair to UCS4 */
+                PRUint32 usv = ((*(pw-1) - (PRUnichar)0xD800) << 10) + 
+                               (*pw - (PRUnichar)0xDC00) + (PRUint32)0x10000;
+                if (pr_ConvertSingleCharToUTF8(usv, 4, len, &utf8Len, &p) ==
+                    PR_FAILURE)
+                    return 0;
+                highSurrogate = PR_FALSE;
+                ++pw;
+                continue;
+            } else {
+                /*
+                 * silently ignore a lone high surrogate
+                 * as is done by WideCharToMultiByte by default
+                 */
+                highSurrogate = PR_FALSE;
+            }
+        }
+        if (*pw <= 0x7f) 
+            status = pr_ConvertSingleCharToUTF8(*pw, 1, len, &utf8Len, &p);
+        else if (*pw <= 0x07ff)
+            status = pr_ConvertSingleCharToUTF8(*pw, 2, len, &utf8Len, &p);
+        else if (*pw < (PRUnichar) 0xD800 || *pw >= (PRUnichar) 0xE000)
+            status = pr_ConvertSingleCharToUTF8(*pw, 3, len, &utf8Len, &p);
+        else if (*pw < (PRUnichar) 0xDC00)
+            highSurrogate = PR_TRUE;
+        /* else */
+        /* silently ignore a lone low surrogate as is done by 
+         * WideCharToMultiByte by default */
+
+        if (status == PR_FAILURE) {
+            SetLastError(ERROR_INSUFFICIENT_BUFFER);
+            return 0;
+        }
+        ++pw;
+    }
+
+    /* if we're concerned with a lone high surrogate,
+     * we have to take care of it here, but we just drop it 
+     */
+    if (len > 0)
+        *p = '\0';
+    return utf8Len + 1;
+}
+#else
+static int pr_ConvertUTF16toUTF8(LPCWSTR wname, LPSTR name, int len)
+{
+    return WideCharToMultiByte(CP_UTF8, 0, wname, -1, name, len, NULL, NULL);
+}
+#endif /* WIN95 */
+#endif /* WIN32 */
+
 /*
 ** Unload a shared library which was loaded via PR_LoadLibrary
 */
 PR_IMPLEMENT(PRStatus) 
 PR_UnloadLibrary(PRLibrary *lib)
 {
     int result = 0;
     PRStatus status = PR_SUCCESS;
@@ -1031,17 +1262,18 @@ PR_UnloadLibrary(PRLibrary *lib)
 
 #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)
-    result = NSUnLinkModule(lib->dlh, NSUNLINKMODULE_OPTION_NONE) ? 0 : -1;
+    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));
--- a/pr/src/md/beos/bfile.c
+++ b/pr/src/md/beos/bfile.c
@@ -1,41 +1,44 @@
 /* -*- Mode: C++; tab-width: 8; c-basic-offset: 8 -*- */
-/* 
- * The contents of this file are subject to the Mozilla Public
- * License Version 1.1 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.mozilla.org/MPL/
- * 
- * Software distributed under the License is distributed on an "AS
- * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
- * implied. See the License for the specific language governing
- * rights and limitations under the License.
- * 
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
  * The Original Code is the Netscape Portable Runtime (NSPR).
- * 
- * The Initial Developer of the Original Code is Netscape
- * Communications Corporation.  Portions created by Netscape are 
- * Copyright (C) 1998-2000 Netscape Communications Corporation.  All
- * Rights Reserved.
- * 
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 1998-2000
+ * the Initial Developer. All Rights Reserved.
+ *
  * Contributor(s):
- * 
- * Alternatively, the contents of this file may be used under the
- * terms of the GNU General Public License Version 2 or later (the
- * "GPL"), in which case the provisions of the GPL are applicable 
- * instead of those above.  If you wish to allow use of your 
- * version of this file only under the terms of the GPL and not to
- * allow others to use your version of this file under the MPL,
- * indicate your decision by deleting the provisions above and
- * replace them with the notice and other provisions required by
- * the GPL.  If you do not delete the provisions above, a recipient
- * may use your version of this file under either the MPL or the
- * GPL.
- */
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
 
 #include "primpl.h"
 
 /*
 ** Global lock variable used to bracket calls into rusty libraries that
 ** aren't thread safe (like libc, libX, etc).
 */
 static PRLock *_pr_rename_lock = NULL; 
--- a/pr/src/md/beos/brng.c
+++ b/pr/src/md/beos/brng.c
@@ -1,41 +1,44 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 
- * The contents of this file are subject to the Mozilla Public
- * License Version 1.1 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.mozilla.org/MPL/
- * 
- * Software distributed under the License is distributed on an "AS
- * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
- * implied. See the License for the specific language governing
- * rights and limitations under the License.
- * 
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
  * The Original Code is the Netscape Portable Runtime (NSPR).
- * 
- * The Initial Developer of the Original Code is Netscape
- * Communications Corporation.  Portions created by Netscape are 
- * Copyright (C) 1999-2000 Netscape Communications Corporation.  All
- * Rights Reserved.
- * 
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 1999-2000
+ * the Initial Developer. All Rights Reserved.
+ *
  * Contributor(s):
- * 
- * Alternatively, the contents of this file may be used under the
- * terms of the GNU General Public License Version 2 or later (the
- * "GPL"), in which case the provisions of the GPL are applicable 
- * instead of those above.  If you wish to allow use of your 
- * version of this file only under the terms of the GPL and not to
- * allow others to use your version of this file under the MPL,
- * indicate your decision by deleting the provisions above and
- * replace them with the notice and other provisions required by
- * the GPL.  If you do not delete the provisions above, a recipient
- * may use your version of this file under either the MPL or the
- * GPL.
- */
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
 
 
 #include <stdio.h>
 #include <string.h>
 #include <signal.h>
 #include <unistd.h>
 #include <errno.h>
 #include <stdlib.h>
--- a/pr/src/md/os2/os2thred.c
+++ b/pr/src/md/os2/os2thred.c
@@ -256,41 +256,39 @@ void
 {
     /* Isn't there some problem with DosSleep(0) on OS/2? */
     DosSleep(0);
 }
 
 void
 _PR_MD_SET_PRIORITY(_MDThread *thread, PRThreadPriority newPri)
 {
-    int nativePri;
+    int nativePri = PRTYC_NOCHANGE;
     BOOL rv;
 
     if (newPri < PR_PRIORITY_FIRST) {
         newPri = PR_PRIORITY_FIRST;
     } else if (newPri > PR_PRIORITY_LAST) {
         newPri = PR_PRIORITY_LAST;
     }
     switch (newPri) {
         case PR_PRIORITY_LOW:
-            nativePri = PRTYC_IDLETIME;
-            break;
         case PR_PRIORITY_NORMAL:
             nativePri = PRTYC_REGULAR;
             break;
         case PR_PRIORITY_HIGH:
             nativePri = PRTYC_FOREGROUNDSERVER;
             break;
         case PR_PRIORITY_URGENT:
             nativePri = PRTYC_TIMECRITICAL;
     }
     rv = DosSetPriority(PRTYS_THREAD, nativePri, 0, thread->handle);
     PR_ASSERT(rv == NO_ERROR);
     if (rv != NO_ERROR) {
-	PR_LOG(_pr_thread_lm, PR_LOG_MIN,
+        PR_LOG(_pr_thread_lm, PR_LOG_MIN,
                 ("PR_SetThreadPriority: can't set thread priority\n"));
     }
     return;
 }
 
 void
 _PR_MD_CLEAN_THREAD(PRThread *thread)
 {
new file mode 100644
--- /dev/null
+++ b/pr/src/md/unix/os_Darwin_x86.s
@@ -0,0 +1,105 @@
+# -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+#
+# The contents of this file are subject to the Mozilla Public
+# License Version 1.1 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.mozilla.org/MPL/
+# 
+# Software distributed under the License is distributed on an "AS
+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# rights and limitations under the License.
+#
+# The Original Code is the Netscape Portable Runtime (NSPR).
+# 
+# The Initial Developer of the Original Code is Netscape
+# Communications Corporation.  Portions created by Netscape are
+# Copyright (C) 2003 Netscape Communications Corporation.  All
+# Rights Reserved.
+#
+# Contributor(s):
+#   Josh Aas <josh@mozilla.com>
+#
+# Alternatively, the contents of this file may be used under the
+# terms of the GNU General Public License Version 2 or later (the
+# "GPL"), in which case the provisions of the GPL are applicable
+# instead of those above.  If you wish to allow use of your
+# version of this file only under the terms of the GPL and not to
+# allow others to use your version of this file under the MPL,
+# indicate your decision by deleting the provisions above and
+# replace them with the notice and other provisions required by
+# the GPL.  If you do not delete the provisions above, a recipient
+# may use your version of this file under either the MPL or the
+# GPL.
+#
+
+#
+# Based on os_Linux_x86.s
+#
+
+#
+# PRInt32 __PR_Darwin_x86_AtomicIncrement(PRInt32 *val);
+#
+# Atomically increment the integer pointed to by 'val' and return
+# the result of the increment.
+#
+    .text
+    .globl __PR_Darwin_x86_AtomicIncrement
+    .align 4
+__PR_Darwin_x86_AtomicIncrement:
+    movl 4(%esp), %ecx
+    movl $1, %eax
+    lock
+    xaddl %eax, (%ecx)
+    incl %eax
+    ret
+
+#
+# PRInt32 __PR_Darwin_x86_AtomicDecrement(PRInt32 *val);
+#
+# Atomically decrement the integer pointed to by 'val' and return
+# the result of the decrement.
+#
+    .text
+    .globl __PR_Darwin_x86_AtomicDecrement
+    .align 4
+__PR_Darwin_x86_AtomicDecrement:
+    movl 4(%esp), %ecx
+    movl $-1, %eax
+    lock
+    xaddl %eax, (%ecx)
+    decl %eax
+    ret
+
+#
+# PRInt32 __PR_Darwin_x86_AtomicSet(PRInt32 *val, PRInt32 newval);
+#
+# Atomically set the integer pointed to by 'val' to the new
+# value 'newval' and return the old value.
+#
+    .text
+    .globl __PR_Darwin_x86_AtomicSet
+    .align 4
+__PR_Darwin_x86_AtomicSet:
+    movl 4(%esp), %ecx
+    movl 8(%esp), %eax
+    xchgl %eax, (%ecx)
+    ret
+
+#
+# PRInt32 __PR_Darwin_x86_AtomicAdd(PRInt32 *ptr, PRInt32 val);
+#
+# Atomically add 'val' to the integer pointed to by 'ptr'
+# and return the result of the addition.
+#
+    .text
+    .globl __PR_Darwin_x86_AtomicAdd
+    .align 4
+__PR_Darwin_x86_AtomicAdd:
+    movl 4(%esp), %ecx
+    movl 8(%esp), %eax
+    movl %eax, %edx
+    lock
+    xaddl %eax, (%ecx)
+    addl %edx, %eax
+    ret
new file mode 100644
--- /dev/null
+++ b/pr/src/md/unix/os_HPUX_ia64.s
@@ -0,0 +1,108 @@
+// -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+// 
+// The contents of this file are subject to the Mozilla Public
+// License Version 1.1 (the "License"); you may not use this file
+// except in compliance with the License. You may obtain a copy of
+// the License at http://www.mozilla.org/MPL/
+// 
+// Software distributed under the License is distributed on an "AS
+// IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+// implied. See the License for the specific language governing
+// rights and limitations under the License.
+// 
+// The Original Code is the Netscape Portable Runtime (NSPR).
+// 
+// The Initial Developer of the Original Code is Netscape
+// Communications Corporation.  Portions created by Netscape are 
+// Copyright (C) 2000 Netscape Communications Corporation.  All
+// Rights Reserved.
+// 
+// Contributor(s):
+// 
+// Alternatively, the contents of this file may be used under the
+// terms of the GNU General Public License Version 2 or later (the
+// "GPL"), in which case the provisions of the GPL are applicable 
+// instead of those above.  If you wish to allow use of your 
+// version of this file only under the terms of the GPL and not to
+// allow others to use your version of this file under the MPL,
+// indicate your decision by deleting the provisions above and
+// replace them with the notice and other provisions required by
+// the GPL.  If you do not delete the provisions above, a recipient
+// may use your version of this file under either the MPL or the
+// GPL.
+//
+
+.text
+
+// PRInt32 _PR_ia64_AtomicIncrement(PRInt32 *val)
+//
+// Atomically increment the integer pointed to by 'val' and return
+// the result of the increment.
+//
+        .align 16
+        .global _PR_ia64_AtomicIncrement#
+        .proc _PR_ia64_AtomicIncrement#
+_PR_ia64_AtomicIncrement:
+#ifndef _LP64
+        addp4 r32 = 0, r32  ;;
+#endif
+        fetchadd4.acq r8 = [r32], 1  ;;
+        adds r8 = 1, r8
+        br.ret.sptk.many b0
+        .endp _PR_ia64_AtomicIncrement#
+
+// PRInt32 _PR_ia64_AtomicDecrement(PRInt32 *val)
+//
+// Atomically decrement the integer pointed to by 'val' and return
+// the result of the decrement.
+//
+        .align 16
+        .global _PR_ia64_AtomicDecrement#
+        .proc _PR_ia64_AtomicDecrement#
+_PR_ia64_AtomicDecrement:
+#ifndef _LP64
+        addp4 r32 = 0, r32  ;;
+#endif
+        fetchadd4.rel r8 = [r32], -1  ;;
+        adds r8 = -1, r8
+        br.ret.sptk.many b0
+        .endp _PR_ia64_AtomicDecrement#
+
+// PRInt32 _PR_ia64_AtomicAdd(PRInt32 *ptr, PRInt32 val)
+//
+// Atomically add 'val' to the integer pointed to by 'ptr'
+// and return the result of the addition.
+//
+        .align 16
+        .global _PR_ia64_AtomicAdd#
+        .proc _PR_ia64_AtomicAdd#
+_PR_ia64_AtomicAdd:
+#ifndef _LP64
+        addp4 r32 = 0, r32  ;;
+#endif
+        ld4 r15 = [r32]  ;;
+.L3:
+        mov r14 = r15
+        mov ar.ccv = r15
+        add r8 = r15, r33  ;;
+        cmpxchg4.acq r15 = [r32], r8, ar.ccv  ;;
+        cmp4.ne p6, p7 =  r15, r14
+        (p6) br.cond.dptk .L3
+        br.ret.sptk.many b0
+        .endp _PR_ia64_AtomicAdd#
+
+// PRInt32 _PR_ia64_AtomicSet(PRInt32 *val, PRInt32 newval)
+//
+// Atomically set the integer pointed to by 'val' to the new
+// value 'newval' and return the old value.
+//
+        .align 16
+        .global _PR_ia64_AtomicSet#
+        .proc _PR_ia64_AtomicSet#
+_PR_ia64_AtomicSet:
+#ifndef _LP64
+        addp4 r32 = 0, r32  ;;
+#endif
+        xchg4 r8 = [r32], r33
+        br.ret.sptk.many b0
+        .endp _PR_ia64_AtomicSet#
--- a/pr/src/md/unix/unix.c
+++ b/pr/src/md/unix/unix.c
@@ -1,41 +1,44 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 
- * The contents of this file are subject to the Mozilla Public
- * License Version 1.1 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.mozilla.org/MPL/
- * 
- * Software distributed under the License is distributed on an "AS
- * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
- * implied. See the License for the specific language governing
- * rights and limitations under the License.
- * 
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
  * The Original Code is the Netscape Portable Runtime (NSPR).
- * 
- * The Initial Developer of the Original Code is Netscape
- * Communications Corporation.  Portions created by Netscape are 
- * Copyright (C) 1998-2000 Netscape Communications Corporation.  All
- * Rights Reserved.
- * 
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 1998-2000
+ * the Initial Developer. All Rights Reserved.
+ *
  * Contributor(s):
- * 
- * Alternatively, the contents of this file may be used under the
- * terms of the GNU General Public License Version 2 or later (the
- * "GPL"), in which case the provisions of the GPL are applicable 
- * instead of those above.  If you wish to allow use of your 
- * version of this file only under the terms of the GPL and not to
- * allow others to use your version of this file under the MPL,
- * indicate your decision by deleting the provisions above and
- * replace them with the notice and other provisions required by
- * the GPL.  If you do not delete the provisions above, a recipient
- * may use your version of this file under either the MPL or the
- * GPL.
- */
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
 
 #include "primpl.h"
 
 #include <string.h>
 #include <signal.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/types.h>
--- a/pr/src/md/unix/unix_errors.c
+++ b/pr/src/md/unix/unix_errors.c
@@ -846,17 +846,31 @@ void _MD_hpux_map_sendfile_error(int err
 {
     _MD_unix_map_default_error(err);
 }
 #endif /* HPUX11 */
 
 #ifdef SOLARIS
 void _MD_solaris_map_sendfile_error(int err)
 {
-    _MD_unix_map_default_error(err) ;
+    PRErrorCode prError;
+
+    switch (err) {
+        /*
+         * Solaris defines a 0 return value for sendfile to mean end-of-file.
+         */
+        case 0:
+            prError = PR_END_OF_FILE_ERROR;
+            break;
+
+        default:
+            _MD_unix_map_default_error(err) ;
+            return;
+    }
+    PR_SetError(prError, err);
 }
 #endif /* SOLARIS */
 
 #ifdef LINUX
 void _MD_linux_map_sendfile_error(int err)
 {
     _MD_unix_map_default_error(err) ;
 }
--- a/pr/src/md/windows/ntinrval.c
+++ b/pr/src/md/windows/ntinrval.c
@@ -37,88 +37,24 @@
 
 /*
  * NT interval timers
  *
  */
 
 #include "primpl.h"
 
-#if defined(WIN16)
-#include <win/compobj.h>
-#define QueryPerformanceFrequency(x)   FALSE
-#define QueryPerformanceCounter(x)     FALSE
-#endif
-
-static PRIntn _nt_bitShift = 0;
-static PRInt32 _nt_ticksPerSec = -1;
-
 void
 _PR_MD_INTERVAL_INIT()
 {
-    LARGE_INTEGER count;
-
-    if (QueryPerformanceFrequency(&count)) {
-        /*
-         * HighPart is signed (LONG).  Assert that its sign bit is 0
-         * because we will be right shifting it.  LowPart is unsigned
-         * (DWORD).
-         */
-        PR_ASSERT(count.HighPart >= 0);
-        while(count.HighPart) {
-            count.LowPart = (count.HighPart << 31) + (count.LowPart >> 1);
-            count.HighPart >>= 1;
-            _nt_bitShift++;
-        }
-        while(count.LowPart > PR_INTERVAL_MAX) {
-            count.LowPart >>= 1;
-            _nt_bitShift++;
-        }
-
-        /*
-         * We can't use the performance counter if after
-         * normalization we are left with fewer than 32 bits.
-         */
-        if (_nt_bitShift <= 32) {
-            _nt_ticksPerSec = count.LowPart;
-            PR_ASSERT(_nt_ticksPerSec > PR_INTERVAL_MIN);
-            return;
-        }
-    }
-    _nt_ticksPerSec = -1;
 }
 
 PRIntervalTime 
 _PR_MD_GET_INTERVAL()
 {
-    LARGE_INTEGER count;
-
-   /* Sadly; nspr requires the interval to range from 1000 ticks per second
-    * to only 100000 ticks per second; QueryPerformanceCounter is too high
-    * resolution...
-    */
-    if (_nt_ticksPerSec != -1) {
-        (void)QueryPerformanceCounter(&count);
-        PR_ASSERT(_nt_bitShift <= 32);
-        if (_nt_bitShift == 32) {
-            return (PRUint32)count.HighPart;
-        } else {
-            return (PRUint32)((count.HighPart << (32 - _nt_bitShift))
-                    + (count.LowPart >> _nt_bitShift));
-        }
-    } else
-#if defined(__MINGW32__)
-        return time();
-#elif defined(WIN16)
-        return clock();        /* milliseconds since application start */
-#else
-        return GetTickCount();  /* milliseconds since system start */
-#endif
+    return timeGetTime();  /* milliseconds since system start */
 }
 
 PRIntervalTime 
 _PR_MD_INTERVAL_PER_SEC()
 {
-    if (_nt_ticksPerSec != -1)
-        return _nt_ticksPerSec;
-    else
-        return 1000;
+    return 1000;
 }
--- a/pr/src/md/windows/ntio.c
+++ b/pr/src/md/windows/ntio.c
@@ -15,16 +15,17 @@
  * The Original Code is the Netscape Portable Runtime (NSPR).
  *
  * The Initial Developer of the Original Code is
  * Netscape Communications Corporation.
  * Portions created by the Initial Developer are Copyright (C) 1998-2000
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
+ *   Masayuki Nakano <masayuki@d-toybox.com>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either the GNU General Public License Version 2 or later (the "GPL"), or
  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
  * of those above. If you wish to allow use of your version of this file only
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
@@ -58,18 +59,20 @@
 #include <direct.h>
 #include <mbstring.h>
 
 static HANDLE                _pr_completion_port;
 static PRThread             *_pr_io_completion_thread;
 
 #define RECYCLE_SIZE 512
 static struct _MDLock        _pr_recycle_lock;
-static PRInt32               _pr_recycle_array[RECYCLE_SIZE];
-static PRInt32               _pr_recycle_tail = 0; 
+static PRInt32               _pr_recycle_INET_array[RECYCLE_SIZE];
+static PRInt32               _pr_recycle_INET_tail = 0; 
+static PRInt32               _pr_recycle_INET6_array[RECYCLE_SIZE];
+static PRInt32               _pr_recycle_INET6_tail = 0; 
 
 __declspec(thread) PRThread *_pr_io_restarted_io = NULL;
 DWORD _pr_io_restartedIOIndex;  /* The thread local storage slot for each
                                  * thread is initialized to NULL. */
 
 PRBool                       _nt_version_gets_lockfile_completion;
 
 struct _MDLock               _pr_ioq_lock;
@@ -103,16 +106,18 @@ static DWORD dirAccessTable[] = {
  * This constant is used by _PR_FileTimeToPRTime().
  */
 #ifdef __GNUC__
 static const PRTime _pr_filetime_offset = 116444736000000000LL;
 #else
 static const PRTime _pr_filetime_offset = 116444736000000000i64;
 #endif
 
+static PRBool IsPrevCharSlash(const char *str, const char *current);
+
 #define _NEED_351_FILE_LOCKING_HACK
 #ifdef _NEED_351_FILE_LOCKING_HACK
 #define _PR_LOCAL_FILE 1
 #define _PR_REMOTE_FILE 2
 PRBool IsFileLocalInit();
 PRInt32 IsFileLocal(HANDLE hFile);
 #endif /* _NEED_351_FILE_LOCKING_HACK */
 
@@ -955,25 +960,30 @@ void
 /* --- SOCKET IO --------------------------------------------------------- */
 
 /* _md_get_recycled_socket()
  * Get a socket from the recycle bin; if no sockets are in the bin,
  * create one.  The socket will be passed to AcceptEx() as the
  * second argument.
  */
 static SOCKET
-_md_get_recycled_socket()
+_md_get_recycled_socket(int af)
 {
     SOCKET rv;
-    int af = AF_INET;
 
     _MD_LOCK(&_pr_recycle_lock);
-    if (_pr_recycle_tail) {
-        _pr_recycle_tail--;
-        rv = _pr_recycle_array[_pr_recycle_tail];
+    if (af == AF_INET && _pr_recycle_INET_tail) {
+        _pr_recycle_INET_tail--;
+        rv = _pr_recycle_INET_array[_pr_recycle_INET_tail];
+        _MD_UNLOCK(&_pr_recycle_lock);
+        return rv;
+    }
+    if (af == AF_INET6 && _pr_recycle_INET6_tail) {
+        _pr_recycle_INET6_tail--;
+        rv = _pr_recycle_INET6_array[_pr_recycle_INET6_tail];
         _MD_UNLOCK(&_pr_recycle_lock);
         return rv;
     }
     _MD_UNLOCK(&_pr_recycle_lock);
 
     rv = _PR_MD_SOCKET(af, SOCK_STREAM, 0);
     if (rv != INVALID_SOCKET && _md_Associate((HANDLE)rv) == 0) {
         closesocket(rv);
@@ -981,24 +991,29 @@ static SOCKET
     }
     return rv;
 }
 
 /* _md_put_recycled_socket()
  * Add a socket to the recycle bin.
  */
 static void
-_md_put_recycled_socket(SOCKET newsock)
+_md_put_recycled_socket(SOCKET newsock, int af)
 {
-    PR_ASSERT(_pr_recycle_tail >= 0);
+    PR_ASSERT(_pr_recycle_INET_tail >= 0);
+    PR_ASSERT(_pr_recycle_INET6_tail >= 0);
 
     _MD_LOCK(&_pr_recycle_lock);
-    if (_pr_recycle_tail < RECYCLE_SIZE) {
-        _pr_recycle_array[_pr_recycle_tail] = newsock;
-        _pr_recycle_tail++;
+    if (af == AF_INET && _pr_recycle_INET_tail < RECYCLE_SIZE) {
+        _pr_recycle_INET_array[_pr_recycle_INET_tail] = newsock;
+        _pr_recycle_INET_tail++;
+        _MD_UNLOCK(&_pr_recycle_lock);
+    } else if (af == AF_INET6 && _pr_recycle_INET6_tail < RECYCLE_SIZE) {
+        _pr_recycle_INET6_array[_pr_recycle_INET6_tail] = newsock;
+        _pr_recycle_INET6_tail++;
         _MD_UNLOCK(&_pr_recycle_lock);
     } else {
         _MD_UNLOCK(&_pr_recycle_lock);
         closesocket(newsock);
     }
  
     return;
 }
@@ -1317,17 +1332,17 @@ PRInt32
     if (!me->md.acceptex_buf) {
         me->md.acceptex_buf = PR_MALLOC(2*INET_ADDR_PADDED);
         if (!me->md.acceptex_buf) {
             PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
             return -1;
         }
     }
 
-    accept_sock = _md_get_recycled_socket();
+    accept_sock = _md_get_recycled_socket(fd->secret->af);
     if (accept_sock == INVALID_SOCKET)
         return -1;
 
     memset(&(me->md.overlapped.overlapped), 0, sizeof(OVERLAPPED));
 	if (_native_threads_only)
 		me->md.overlapped.overlapped.hEvent = me->md.thr_event;
 
     _PR_THREAD_LOCK(me);
@@ -1347,17 +1362,17 @@ PRInt32
                   accept_sock,
                   me->md.acceptex_buf,
                   0,
                   INET_ADDR_PADDED,
                   INET_ADDR_PADDED,
                   &bytes,
                   &(me->md.overlapped.overlapped));
 
-    if ( (rv == 0) && ((err = GetLastError()) != ERROR_IO_PENDING))  {
+    if ( (rv == 0) && ((err = WSAGetLastError()) != ERROR_IO_PENDING))  {
         /* Argh! The IO failed */
 		closesocket(accept_sock);
 		_PR_THREAD_LOCK(me);
 		me->io_pending = PR_FALSE;
 		me->state = _PR_RUNNING;
 		if (_PR_PENDING_INTERRUPT(me)) {
 			me->flags &= ~_PR_INTERRUPT;
 			PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
@@ -1440,17 +1455,17 @@ PRInt32
     }
 
     if (!sd->secret->md.io_model_committed) {
         rv = _md_Associate((HANDLE)sock);
         PR_ASSERT(0 != rv);
         sd->secret->md.io_model_committed = PR_TRUE;
     }
 
-    *newSock = _md_get_recycled_socket();
+    *newSock = _md_get_recycled_socket(sd->secret->af);
     if (*newSock == INVALID_SOCKET)
         return -1;
 
     memset(&(me->md.overlapped.overlapped), 0, sizeof(OVERLAPPED));
 	if (_native_threads_only)
 		me->md.overlapped.overlapped.hEvent = me->md.thr_event;
 
     _PR_THREAD_LOCK(me);
@@ -1690,17 +1705,17 @@ PRInt32
     }
 
     if (me->md.blocked_io_status == 0) {
 		_PR_MD_MAP_TRANSMITFILE_ERROR(me->md.blocked_io_error);
         return -1;
     }
 
     if (flags & PR_TRANSMITFILE_CLOSE_SOCKET) {
-        _md_put_recycled_socket(sock->secret->md.osfd);
+        _md_put_recycled_socket(sock->secret->md.osfd, sock->secret->af);
     }
 
     PR_ASSERT(me->io_pending == PR_FALSE);
 
     return me->md.blocked_io_bytes;
 }
 
 PRInt32
@@ -2764,17 +2779,17 @@ PRStatus
         return PR_FAILURE;
     }
     strcpy(filename, name);
 
     /*
      * If 'name' ends in a slash or backslash, do not append
      * another backslash.
      */
-    if (filename[len - 1] == '/' || filename[len - 1] == '\\') {
+    if (IsPrevCharSlash(filename, filename + len)) {
         len--;
     }
     strcpy(&filename[len], "\\*.*");
     FlipSlashes( filename, strlen(filename) );
 
     d->d_hdl = FindFirstFile( filename, &(d->d_entry) );
     if ( d->d_hdl == INVALID_HANDLE_VALUE ) {
 		_PR_MD_MAP_OPENDIR_ERROR(GetLastError());
@@ -2902,33 +2917,44 @@ PRInt32
          * can be handled by _stat() on NT but not on Win95.
          *
          * We remove the backslash or slash at the end and
          * try again.
          */
 
         int len = strlen(fn);
         if (len > 0 && len <= _MAX_PATH
-                && (fn[len - 1] == '\\' || fn[len - 1] == '/')) {
+                && IsPrevCharSlash(fn, fn + len)) {
             char newfn[_MAX_PATH + 1];
 
             strcpy(newfn, fn);
             newfn[len - 1] = '\0';
             rv = _stat(newfn, (struct _stat *)info);
         }
     }
 
     if (-1 == rv) {
         _PR_MD_MAP_STAT_ERROR(errno);
     }
     return rv;
 }
 
 #define _PR_IS_SLASH(ch) ((ch) == '/' || (ch) == '\\')
 
+static PRBool
+IsPrevCharSlash(const char *str, const char *current)
+{
+    const char *prev;
+
+    if (str >= current)
+        return PR_FALSE;
+    prev = _mbsdec(str, current);
+    return (prev == current - 1) && _PR_IS_SLASH(*prev);
+}
+
 /*
  * IsRootDirectory --
  *
  * Return PR_TRUE if the pathname 'fn' is a valid root directory,
  * else return PR_FALSE.  The char buffer pointed to by 'fn' must
  * be writable.  During the execution of this function, the contents
  * of the buffer pointed to by 'fn' may be modified, but on return
  * the original contents will be restored.  'buflen' is the size of
@@ -2965,31 +2991,31 @@ IsRootDirectory(char *fn, size_t buflen)
         /* The 'server' part should have at least one character. */
         p = &fn[2];
         if (*p == '\0' || _PR_IS_SLASH(*p)) {
             return PR_FALSE;
         }
 
         /* look for the next slash */
         do {
-            p++;
+            p = _mbsinc(p);
         } while (*p != '\0' && !_PR_IS_SLASH(*p));
         if (*p == '\0') {
             return PR_FALSE;
         }
 
         /* The 'share' part should have at least one character. */
         p++;
         if (*p == '\0' || _PR_IS_SLASH(*p)) {
             return PR_FALSE;
         }
 
         /* look for the final slash */
         do {
-            p++;
+            p = _mbsinc(p);
         } while (*p != '\0' && !_PR_IS_SLASH(*p));
         if (_PR_IS_SLASH(*p) && p[1] != '\0') {
             return PR_FALSE;
         }
         if (*p == '\0') {
             /*
              * GetDriveType() doesn't work correctly if the
              * path is of the form \\server\share, so we add
@@ -3069,17 +3095,17 @@ PRInt32
             info->size = 0;
             /*
              * These timestamps don't make sense for root directories.
              */
             info->modifyTime = 0;
             info->creationTime = 0;
             return 0;
         }
-        if (!_PR_IS_SLASH(pathbuf[len - 1])) {
+        if (!IsPrevCharSlash(pathbuf, pathbuf + len)) {
             _PR_MD_MAP_OPENDIR_ERROR(GetLastError());
             return -1;
         } else {
             pathbuf[len - 1] = '\0';
             hFindFile = FindFirstFile(pathbuf, &findFileData);
             if (INVALID_HANDLE_VALUE == hFindFile) {
                 _PR_MD_MAP_OPENDIR_ERROR(GetLastError());
                 return -1;
--- a/pr/src/md/windows/w95io.c
+++ b/pr/src/md/windows/w95io.c
@@ -15,16 +15,17 @@
  * The Original Code is the Netscape Portable Runtime (NSPR).
  *
  * The Initial Developer of the Original Code is
  * Netscape Communications Corporation.
  * Portions created by the Initial Developer are Copyright (C) 1998-2000
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
+ *   Masayuki Nakano <masayuki@d-toybox.com>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either the GNU General Public License Version 2 or later (the "GPL"), or
  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
  * of those above. If you wish to allow use of your version of this file only
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
@@ -75,19 +76,19 @@ static DWORD dirAccessTable[] = {
  * This constant is used by _PR_FileTimeToPRTime().
  */
 #if defined(__MINGW32__)
 static const PRTime _pr_filetime_offset = 116444736000000000LL;
 #else
 static const PRTime _pr_filetime_offset = 116444736000000000i64;
 #endif
 
-#ifdef MOZ_UNICODE
 static void InitUnicodeSupport(void);
-#endif
+
+static PRBool IsPrevCharSlash(const char *str, const char *current);
 
 void
 _PR_MD_INIT_IO()
 {
     WORD WSAVersion = 0x0101;
     WSADATA WSAData;
     int err;
 
@@ -116,19 +117,19 @@ void
         rv = SystemTimeToFileTime(&systime, &filetime.ft);
         PR_ASSERT(0 != rv);
         PR_ASSERT(filetime.prt == _pr_filetime_offset);
     }
 #endif /* DEBUG */
 
     _PR_NT_InitSids();
 
-#ifdef MOZ_UNICODE
     InitUnicodeSupport();
-#endif
+
+    _PR_MD_InitSockets();
 }
 
 PRStatus
 _PR_MD_WAIT(PRThread *thread, PRIntervalTime ticks)
 {
     DWORD rv;
 
     PRUint32 msecs = (ticks == PR_INTERVAL_NO_TIMEOUT) ?
@@ -511,17 +512,17 @@ PRStatus
         return PR_FAILURE;
     }
     strcpy(filename, name);
 
     /*
      * If 'name' ends in a slash or backslash, do not append
      * another backslash.
      */
-    if (filename[len - 1] == '/' || filename[len - 1] == '\\') {
+    if (IsPrevCharSlash(filename, filename + len)) {
         len--;
     }
     strcpy(&filename[len], "\\*.*");
     FlipSlashes( filename, strlen(filename) );
 
     d->d_hdl = FindFirstFile( filename, &(d->d_entry) );
     if ( d->d_hdl == INVALID_HANDLE_VALUE ) {
 		_PR_MD_MAP_OPENDIR_ERROR(GetLastError());
@@ -649,33 +650,44 @@ PRInt32
          * can be handled by _stat() on NT but not on Win95.
          *
          * We remove the backslash or slash at the end and
          * try again.
          */
 
         int len = strlen(fn);
         if (len > 0 && len <= _MAX_PATH
-                && (fn[len - 1] == '\\' || fn[len - 1] == '/')) {
+                && IsPrevCharSlash(fn, fn + len)) {
             char newfn[_MAX_PATH + 1];
 
             strcpy(newfn, fn);
             newfn[len - 1] = '\0';
             rv = _stat(newfn, (struct _stat *)info);
         }
     }
 
     if (-1 == rv) {
         _PR_MD_MAP_STAT_ERROR(errno);
     }
     return rv;
 }
 
 #define _PR_IS_SLASH(ch) ((ch) == '/' || (ch) == '\\')
 
+static PRBool
+IsPrevCharSlash(const char *str, const char *current)
+{
+    const char *prev;
+
+    if (str >= current)
+        return PR_FALSE;
+    prev = _mbsdec(str, current);
+    return (prev == current - 1) && _PR_IS_SLASH(*prev);
+}
+
 /*
  * IsRootDirectory --
  *
  * Return PR_TRUE if the pathname 'fn' is a valid root directory,
  * else return PR_FALSE.  The char buffer pointed to by 'fn' must
  * be writable.  During the execution of this function, the contents
  * of the buffer pointed to by 'fn' may be modified, but on return
  * the original contents will be restored.  'buflen' is the size of
@@ -712,31 +724,31 @@ IsRootDirectory(char *fn, size_t buflen)
         /* The 'server' part should have at least one character. */
         p = &fn[2];
         if (*p == '\0' || _PR_IS_SLASH(*p)) {
             return PR_FALSE;
         }
 
         /* look for the next slash */
         do {
-            p++;
+            p = _mbsinc(p);
         } while (*p != '\0' && !_PR_IS_SLASH(*p));
         if (*p == '\0') {
             return PR_FALSE;
         }
 
         /* The 'share' part should have at least one character. */
         p++;
         if (*p == '\0' || _PR_IS_SLASH(*p)) {
             return PR_FALSE;
         }
 
         /* look for the final slash */
         do {
-            p++;
+            p = _mbsinc(p);
         } while (*p != '\0' && !_PR_IS_SLASH(*p));
         if (_PR_IS_SLASH(*p) && p[1] != '\0') {
             return PR_FALSE;
         }
         if (*p == '\0') {
             /*
              * GetDriveType() doesn't work correctly if the
              * path is of the form \\server\share, so we add
@@ -816,17 +828,17 @@ PRInt32
             info->size = 0;
             /*
              * These timestamps don't make sense for root directories.
              */
             info->modifyTime = 0;
             info->creationTime = 0;
             return 0;
         }
-        if (!_PR_IS_SLASH(pathbuf[len - 1])) {
+        if (!IsPrevCharSlash(pathbuf, pathbuf + len)) {
             _PR_MD_MAP_OPENDIR_ERROR(GetLastError());
             return -1;
         } else {
             pathbuf[len - 1] = '\0';
             hFindFile = FindFirstFile(pathbuf, &findFileData);
             if (INVALID_HANDLE_VALUE == hFindFile) {
                 _PR_MD_MAP_OPENDIR_ERROR(GetLastError());
                 return -1;
@@ -1101,48 +1113,59 @@ PRInt32
 	else
 		PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
     return -1;
 }
 
 #ifdef MOZ_UNICODE
 
 typedef HANDLE (WINAPI *CreateFileWFn) (LPCWSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES, DWORD, DWORD, HANDLE);
-static CreateFileWFn createFileW = NULL; 
+static CreateFileWFn createFileW = CreateFileW;
 typedef HANDLE (WINAPI *FindFirstFileWFn) (LPCWSTR, LPWIN32_FIND_DATAW);
-static FindFirstFileWFn findFirstFileW = NULL; 
+static FindFirstFileWFn findFirstFileW = FindFirstFileW;
 typedef BOOL (WINAPI *FindNextFileWFn) (HANDLE, LPWIN32_FIND_DATAW);
-static FindNextFileWFn findNextFileW = NULL; 
+static FindNextFileWFn findNextFileW = FindNextFileW;
 typedef DWORD (WINAPI *GetFullPathNameWFn) (LPCWSTR, DWORD, LPWSTR, LPWSTR *);
-static GetFullPathNameWFn getFullPathNameW = NULL; 
+static GetFullPathNameWFn getFullPathNameW = GetFullPathNameW;
 typedef UINT (WINAPI *GetDriveTypeWFn) (LPCWSTR);
-static GetDriveTypeWFn getDriveTypeW = NULL; 
+static GetDriveTypeWFn getDriveTypeW = GetDriveTypeW;
+
+#endif /* MOZ_UNICODE */
+
+PRBool _pr_useUnicode = PR_FALSE;
 
 static void InitUnicodeSupport(void)
 {
-    HMODULE module;
-
     /*
-     * The W functions do not exist on Win9x.  NSPR won't run on Win9x
-     * if we call the W functions directly.  Use GetProcAddress() to
-     * look up their addresses at run time.
+     * The W functions exist on Win9x as stubs that fail with the
+     * ERROR_CALL_NOT_IMPLEMENTED error.  We plan to emulate the
+     * MSLU W functions on Win9x in the future.
      */
 
-    module = GetModuleHandle("Kernel32.dll");
-    if (!module) {
-        return;
-    }
+    /* Find out if we are running on a Unicode enabled version of Windows */
+    OSVERSIONINFOA osvi = {0};
 
-    createFileW = (CreateFileWFn)GetProcAddress(module, "CreateFileW"); 
-    findFirstFileW = (FindFirstFileWFn)GetProcAddress(module, "FindFirstFileW"); 
-    findNextFileW = (FindNextFileWFn)GetProcAddress(module, "FindNextFileW"); 
-    getDriveTypeW = (GetDriveTypeWFn)GetProcAddress(module, "GetDriveTypeW"); 
-    getFullPathNameW = (GetFullPathNameWFn)GetProcAddress(module, "GetFullPathNameW"); 
+    osvi.dwOSVersionInfoSize = sizeof(osvi);
+    if (GetVersionExA(&osvi)) {
+        _pr_useUnicode = (osvi.dwPlatformId >= VER_PLATFORM_WIN32_NT);
+    } else {
+        _pr_useUnicode = PR_FALSE;
+    }
+#ifdef DEBUG
+    /*
+     * In debug builds, allow explicit use of ANSI methods to simulate
+     * a Win9x environment for testing purposes.
+     */
+    if (getenv("WINAPI_USE_ANSI"))
+        _pr_useUnicode = PR_FALSE;
+#endif
 }
 
+#ifdef MOZ_UNICODE
+
 /* ================ UTF16 Interfaces ================================ */
 void FlipSlashesW(PRUnichar *cp, int len)
 {
     while (--len >= 0) {
         if (cp[0] == L'/') {
             cp[0] = L'\\';
         }
         cp++;
@@ -1156,21 +1179,16 @@ PRInt32
     PRInt32 access = 0;
     PRInt32 flags = 0;
     PRInt32 flag6 = 0;
     SECURITY_ATTRIBUTES sa;
     LPSECURITY_ATTRIBUTES lpSA = NULL;
     PSECURITY_DESCRIPTOR pSD = NULL;
     PACL pACL = NULL;
 
-    if (!createFileW) {
-        PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
-        return -1;
-    }
- 
     if (osflags & PR_CREATE_FILE) {
         if (_PR_NT_MakeSecurityDescriptorACL(mode, fileAccessTable,
                 &pSD, &pACL) == PR_SUCCESS) {
             sa.nLength = sizeof(sa);
             sa.lpSecurityDescriptor = pSD;
             sa.bInheritHandle = FALSE;
             lpSA = &sa;
         }
@@ -1216,21 +1234,16 @@ PRInt32
 }
  
 PRStatus
 _PR_MD_OPEN_DIR_UTF16(_MDDirUTF16 *d, const PRUnichar *name)
 {
     PRUnichar filename[ MAX_PATH ];
     int len;
 
-    if (!findFirstFileW) {
-        PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
-        return PR_FAILURE;
-    }
-
     len = wcslen(name);
     /* Need 5 bytes for \*.* and the trailing null byte. */
     if (len + 5 > MAX_PATH) {
         PR_SetError(PR_NAME_TOO_LONG_ERROR, 0);
         return PR_FAILURE;
     }
     wcscpy(filename, name);
 
@@ -1256,21 +1269,16 @@ PRStatus
 
 PRUnichar *
 _PR_MD_READ_DIR_UTF16(_MDDirUTF16 *d, PRIntn flags)
 {
     PRInt32 err;
     BOOL rv;
     PRUnichar *fileName;
 
-    if (!findNextFileW) {
-        PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
-        return NULL;
-    }
-
     if ( d ) {
         while (1) {
             if (d->firstEntry) {
                 d->firstEntry = PR_FALSE;
                 rv = 1;
             } else {
                 rv = findNextFileW(d->d_hdl, &(d->d_entry));
             }
@@ -1406,21 +1414,16 @@ IsRootDirectoryW(PRUnichar *fn, size_t b
 
 PRInt32
 _PR_MD_GETFILEINFO64_UTF16(const PRUnichar *fn, PRFileInfo64 *info)
 {
     HANDLE hFindFile;
     WIN32_FIND_DATAW findFileData;
     PRUnichar pathbuf[MAX_PATH + 1];
 
-    if (!findFirstFileW || !getFullPathNameW || !getDriveTypeW) {
-        PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
-        return -1;
-    }
-    
     if (NULL == fn || L'\0' == *fn) {
         PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
         return -1;
     }
 
     /*
      * FindFirstFile() expands wildcard characters.  So
      * we make sure the pathname contains no wildcard.
--- a/pr/src/md/windows/w95sock.c
+++ b/pr/src/md/windows/w95sock.c
@@ -48,16 +48,105 @@
 static PRInt32 socket_io_wait(
     PRInt32 osfd, 
     PRInt32 fd_type,
     PRIntervalTime timeout);
 
 
 /* --- SOCKET IO --------------------------------------------------------- */
 
+/*
+ * we only want to call WSAIoctl() on Vista and later
+ * so don't pay for it at build time (and avoid including winsock2.h)
+ */
+
+/* from ws2def.h */
+#define IOC_IN                      0x80000000      /* copy in parameters */
+#define IOC_VENDOR                  0x18000000
+#define _WSAIOW(x,y)                (IOC_IN|(x)|(y))
+/* from MSWSockDef.h */
+#define SIO_SET_COMPATIBILITY_MODE  _WSAIOW(IOC_VENDOR,300)
+
+typedef enum _WSA_COMPATIBILITY_BEHAVIOR_ID {
+    WsaBehaviorAll = 0,
+    WsaBehaviorReceiveBuffering,
+    WsaBehaviorAutoTuning
+} WSA_COMPATIBILITY_BEHAVIOR_ID, *PWSA_COMPATIBILITY_BEHAVIOR_ID;
+
+/* from sdkddkver.h */
+#define NTDDI_LONGHORN                      0x06000000
+
+/* from winsock2.h */
+#define WSAEVENT                HANDLE
+
+#define WSAOVERLAPPED           OVERLAPPED
+typedef struct _OVERLAPPED *    LPWSAOVERLAPPED;
+
+typedef void (CALLBACK * LPWSAOVERLAPPED_COMPLETION_ROUTINE)(
+    IN DWORD dwError,
+    IN DWORD cbTransferred,
+    IN LPWSAOVERLAPPED lpOverlapped,
+    IN DWORD dwFlags
+);
+
+typedef int (__stdcall * WSAIOCTLPROC) (
+    SOCKET s,
+    DWORD dwIoControlCode,
+    LPVOID lpvInBuffer,
+    DWORD cbInBuffer,
+    LPVOID lpvOutBuffer,
+    DWORD cbOutBuffer,
+    LPDWORD lpcbBytesReturned,
+    LPWSAOVERLAPPED lpOverlapped,
+    LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
+);
+
+typedef struct _WSA_COMPATIBILITY_MODE {
+    WSA_COMPATIBILITY_BEHAVIOR_ID BehaviorId;
+    ULONG TargetOsVersion;
+} WSA_COMPATIBILITY_MODE, *PWSA_COMPATIBILITY_MODE;
+
+static HMODULE libWinsock2 = NULL;
+static WSAIOCTLPROC wsaioctlProc = NULL;
+static PRBool socketSetCompatMode = PR_FALSE;
+
+void _PR_MD_InitSockets(void)
+{
+    OSVERSIONINFO osvi;
+
+    memset(&osvi, 0, sizeof(osvi));
+    osvi.dwOSVersionInfoSize = sizeof(osvi);
+    GetVersionEx(&osvi);
+
+    /* if Vista or later... */
+    if (osvi.dwMajorVersion >= 6)
+    {
+        libWinsock2 = LoadLibrary("Ws2_32.dll");
+        if (libWinsock2)
+        {
+            wsaioctlProc = (WSAIOCTLPROC)GetProcAddress(libWinsock2, 
+                                                        "WSAIoctl");
+            if (wsaioctlProc)
+            {
+                socketSetCompatMode = PR_TRUE;
+            }
+        }
+    }
+}
+
+void _PR_MD_CleanupSockets(void)
+{
+    socketSetCompatMode = PR_FALSE;
+    wsaioctlProc = NULL;
+    if (libWinsock2)
+    {
+        FreeLibrary(libWinsock2);
+        libWinsock2 = NULL;
+    }
+}
 
 PRInt32
 _PR_MD_SOCKET(int af, int type, int flags)
 {
     SOCKET sock;
     u_long one = 1;
 
     sock = socket(af, type, flags);
@@ -73,16 +162,39 @@ PRInt32
     */
     if (ioctlsocket( sock, FIONBIO, &one) != 0)
     {
         PR_SetError(PR_UNKNOWN_ERROR, WSAGetLastError());
         closesocket(sock);
         return -1;
     }
 
+    if ((af == AF_INET || af == AF_INET6) && 
+        type == SOCK_STREAM && socketSetCompatMode)
+    {
+        WSA_COMPATIBILITY_MODE mode;
+        char dummy[4];
+        int ret_dummy;
+
+        mode.BehaviorId = WsaBehaviorAutoTuning;
+        mode.TargetOsVersion = NTDDI_LONGHORN;
+        if (wsaioctlProc(sock, SIO_SET_COMPATIBILITY_MODE,  
+                         (char *)&mode, sizeof(mode),
+                         dummy, 4, &ret_dummy, 0, NULL) == SOCKET_ERROR)
+        {
+            int err = WSAGetLastError();
+            PR_LOG(_pr_io_lm, PR_LOG_DEBUG, ("WSAIoctl() failed with %d", err));
+
+            /* SIO_SET_COMPATIBILITY_MODE may not be supported.
+            ** If the call to WSAIoctl() fails with WSAEOPNOTSUPP,
+            ** don't close the socket.
+            */ 
+        }
+    }
+
     return (PRInt32)sock;
 }
 
 /*
 ** _MD_CloseSocket() -- Close a socket
 **
 */
 PRInt32
--- a/pr/src/md/windows/w95thred.c
+++ b/pr/src/md/windows/w95thred.c
@@ -60,16 +60,18 @@ void
     _pr_currentCPUIndex = TlsAlloc();
 #endif
 }
 
 void _PR_MD_CLEANUP_BEFORE_EXIT(void)
 {
     _PR_NT_FreeSids();
 
+    _PR_MD_CleanupSockets();
+
     WSACleanup();
 
 #ifndef _PR_USE_STATIC_TLS
     TlsFree(_pr_currentThreadIndex);
     TlsFree(_pr_lastThreadIndex);
     TlsFree(_pr_currentCPUIndex);
 #endif
 }
--- a/pr/src/md/windows/win32_errors.c
+++ b/pr/src/md/windows/win32_errors.c
@@ -84,16 +84,19 @@ void _MD_win32_map_default_error(PRInt32
 
     switch (err) {
         case ERROR_ACCESS_DENIED:
             prError = PR_NO_ACCESS_RIGHTS_ERROR;
             break;
         case ERROR_ALREADY_EXISTS:
             prError = PR_FILE_EXISTS_ERROR;
             break;
+        case ERROR_CALL_NOT_IMPLEMENTED:
+            prError = PR_NOT_IMPLEMENTED_ERROR;
+            break;
         case ERROR_DISK_CORRUPT:
             prError = PR_IO_ERROR; 
             break;
         case ERROR_DISK_FULL:
             prError = PR_NO_DEVICE_SPACE_ERROR;
             break;
         case ERROR_DISK_OPERATION_FAILED:
             prError = PR_IO_ERROR;
--- a/pr/src/misc/pratom.c
+++ b/pr/src/misc/pratom.c
@@ -115,16 +115,18 @@ int index;
 	PR_ASSERT(PR_FloorLog2(DEFAULT_ATOMIC_LOCKS) ==
 							PR_CeilingLog2(DEFAULT_ATOMIC_LOCKS));
 
 	if (((eval = getenv("NSPR_ATOMIC_HASH_LOCKS")) != NULL)  &&
 		((num_atomic_locks = atoi(eval)) != DEFAULT_ATOMIC_LOCKS)) {
 
 		if (num_atomic_locks > MAX_ATOMIC_LOCKS)
 			num_atomic_locks = MAX_ATOMIC_LOCKS;
+		else if (num_atomic_locks < 1) 
+			num_atomic_locks = 1;
 		else {
 			num_atomic_locks = PR_FloorLog2(num_atomic_locks);
 			num_atomic_locks = 1L << num_atomic_locks;
 		}
 		atomic_locks = (pthread_mutex_t *) PR_Malloc(sizeof(pthread_mutex_t) *
 						num_atomic_locks);
 		if (atomic_locks) {
 			for (index = 0; index < num_atomic_locks; index++) {
--- a/pr/src/misc/prdtoa.c
+++ b/pr/src/misc/prdtoa.c
@@ -3062,17 +3062,17 @@ dtoa
 		/* Yes. */
 		ds = tens[k];
 		if (ndigits < 0 && ilim <= 0) {
 			S = mhi = 0;
 			if (ilim < 0 || dval(d) <= 5*ds)
 				goto no_digits;
 			goto one_digit;
 			}
-		for(i = 1;; i++, dval(d) *= 10.) {
+		for(i = 1; i <= k+1; i++, dval(d) *= 10.) {
 			L = (Long)(dval(d) / ds);
 			dval(d) -= L*ds;
 #ifdef Check_FLT_ROUNDS
 			/* If FLT_ROUNDS == 2, L will usually be high by 1 */
 			if (dval(d) < 0) {
 				L--;
 				dval(d) += ds;
 				}
--- a/pr/src/misc/prinit.c
+++ b/pr/src/misc/prinit.c
@@ -236,16 +236,17 @@ static void _PR_InitStuff(void)
 
     _PR_InitCMon();
     _PR_InitIO();
     _PR_InitNet();
     _PR_InitLog();
     _PR_InitLinker();
     _PR_InitCallOnce();
     _PR_InitDtoa();
+    _PR_InitTime();
     _PR_InitMW();
     _PR_InitRWLocks();
 
     nspr_InitializePRErrorTable();
 
 #if !defined(_PR_INET6) || defined(_PR_INET6_PROBE)
 	_pr_init_ipv6();
 #endif
@@ -415,16 +416,17 @@ PR_IMPLEMENT(PRStatus) PR_Cleanup()
 		_PR_MD_PRE_CLEANUP(me);
 		/*
 		 * The primordial thread must now be running on the primordial cpu
 		 */
     	PR_ASSERT((_PR_IS_NATIVE_THREAD(me)) || (me->cpu->id == 0));
 #endif
 
         _PR_CleanupMW();
+        _PR_CleanupTime();
         _PR_CleanupDtoa();
         _PR_CleanupCallOnce();
 		_PR_ShutdownLinker();
         /* Release the primordial thread's private data, etc. */
         _PR_CleanupThread(me);
 
         _PR_MD_STOP_INTERRUPTS();
 
--- a/pr/src/misc/prnetdb.c
+++ b/pr/src/misc/prnetdb.c
@@ -103,16 +103,21 @@ PRLock *_pr_dnsLock = NULL;
 #if defined(OSF1) \
         || defined(AIX4_3_PLUS) || (defined(AIX) && defined(_THREAD_SAFE)) \
 	|| (defined(HPUX10_10) && defined(_REENTRANT)) \
         || (defined(HPUX10_20) && defined(_REENTRANT))
 #define _PR_HAVE_GETPROTO_R
 #define _PR_HAVE_GETPROTO_R_INT
 #endif
 
+#if __FreeBSD_version >= 602000
+#define _PR_HAVE_GETPROTO_R
+#define _PR_HAVE_5_ARG_GETPROTO_R
+#endif
+
 #if (defined(LINUX) && defined(__GLIBC__) && __GLIBC__ >= 2)
 #define _PR_HAVE_GETPROTO_R
 #define _PR_HAVE_5_ARG_GETPROTO_R
 #endif
 
 #if !defined(_PR_HAVE_GETPROTO_R)
 PRLock* _getproto_lock = NULL;
 #endif
--- a/pr/src/misc/prsystem.c
+++ b/pr/src/misc/prsystem.c
@@ -129,18 +129,22 @@ PR_IMPLEMENT(PRStatus) PR_GetSystemInfo(
 {
     PRUintn len = 0;
 
     if (!_pr_initialized) _PR_ImplicitInitialization();
 
     switch(cmd)
     {
       case PR_SI_HOSTNAME:
+      case PR_SI_HOSTNAME_UNTRUNCATED:
         if (PR_FAILURE == _PR_MD_GETHOSTNAME(buf, (PRUintn)buflen))
             return PR_FAILURE;
+
+        if (cmd == PR_SI_HOSTNAME_UNTRUNCATED)
+            break;
         /*
          * On some platforms a system does not have a hostname and
          * its IP address is returned instead.   The following code
          * should be skipped on those platforms.
          */
 #ifndef _PR_GET_HOST_ADDR_AS_NAME
         /* Return the unqualified hostname */
             while (buf[len] && (len < buflen)) {
@@ -273,87 +277,85 @@ PR_IMPLEMENT(PRInt32) PR_GetNumberOfProc
 **     bytes is the returned value.
 **   for each platform's "if defined" section
 **     declare your local variable
 **     do your thing, assign to bytes.
 ** 
 */
 PR_IMPLEMENT(PRUint64) PR_GetPhysicalMemorySize(void)
 {
-    PRUint64 bytes = LL_ZERO;
+    PRUint64 bytes = 0;
 
 #if defined(LINUX) || defined(SOLARIS)
 
     long pageSize = sysconf(_SC_PAGESIZE);
     long pageCount = sysconf(_SC_PHYS_PAGES);
-    LL_I2L(bytes, pageSize * pageCount);
+    bytes = (PRUint64) pageSize * pageCount;
 
 #elif defined(HPUX)
 
     struct pst_static info;
     int result = pstat_getstatic(&info, sizeof(info), 1, 0);
     if (result == 1)
-        LL_I2L(bytes, info.physical_memory * info.page_size);
+        bytes = (PRUint64) info.physical_memory * info.page_size;
 
 #elif defined(DARWIN)
 
     struct host_basic_info hInfo;
     mach_msg_type_number_t count;
 
     int result = host_info(mach_host_self(),
                            HOST_BASIC_INFO,
                            (host_info_t) &hInfo,
                            &count);
     if (result == KERN_SUCCESS)
-        LL_I2L(bytes, hInfo.memory_size);
+        bytes = hInfo.memory_size;
 
 #elif defined(WIN32)
 
     /* Try to use the newer GlobalMemoryStatusEx API for Windows 2000+. */
     GlobalMemoryStatusExFn globalMemory = (GlobalMemoryStatusExFn) NULL;
     HMODULE module = GetModuleHandle("kernel32.dll");
 
     if (module) {
         globalMemory = (GlobalMemoryStatusExFn)GetProcAddress(module, "GlobalMemoryStatusEx");
 
         if (globalMemory) {
             PR_MEMORYSTATUSEX memStat;
             memStat.dwLength = sizeof(memStat);
 
             if (globalMemory(&memStat))
-                LL_UI2L(bytes, memStat.ullTotalPhys);
+                bytes = memStat.ullTotalPhys;
         }
     }
 
-    if (LL_EQ(bytes, LL_ZERO)) {
+    if (!bytes) {
         /* Fall back to the older API. */
         MEMORYSTATUS memStat;
         memset(&memStat, 0, sizeof(memStat));
         GlobalMemoryStatus(&memStat);
-        LL_I2L(bytes, memStat.dwTotalPhys);
+        bytes = memStat.dwTotalPhys;
     }
 
 #elif defined(OS2)
 
     ULONG ulPhysMem;
     DosQuerySysInfo(QSV_TOTPHYSMEM,
                     QSV_TOTPHYSMEM,
                     &ulPhysMem,
                     sizeof(ulPhysMem));
-    LL_I2L(bytes, ulPhysMem);
+    bytes = ulPhysMem;
 
 #elif defined(AIX)
 
     if (odm_initialize() == 0) {
         int how_many;
         struct CuAt *obj = getattr("sys0", "realmem", 0, &how_many);
         if (obj != NULL) {
-            PRUint64 kbytes;
-            LL_I2L(kbytes, atoi(obj->value));
-            LL_MUL(bytes, kbytes, 1024);
+            bytes = (PRUint64) atoi(obj->value) * 1024;
             free(obj);
         }
         odm_terminate();
     }
 
 #else
 
     PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
--- a/pr/src/misc/prtime.c
+++ b/pr/src/misc/prtime.c
@@ -564,31 +564,28 @@ PR_NormalizeTime(PRExplodedTime *time, P
 #define MT_safe_localtime localtime_r
 
 #else
 
 #if defined(XP_MAC)
 extern struct tm *Maclocaltime(const time_t * t);
 #endif
 
+#define HAVE_LOCALTIME_MONITOR 1  /* We use 'monitor' to serialize our calls
+                                   * to localtime(). */
 static PRLock *monitor = NULL;
 
 static struct tm *MT_safe_localtime(const time_t *clock, struct tm *result)
 {
     struct tm *tmPtr;
     int needLock = PR_Initialized();  /* We need to use a lock to protect
                                        * against NSPR threads only when the
                                        * NSPR thread system is activated. */
 
-    if (needLock) {
-        if (monitor == NULL) {
-            monitor = PR_NewLock();
-        }
-        PR_Lock(monitor);
-    }
+    if (needLock) PR_Lock(monitor);
 
     /*
      * Microsoft (all flavors) localtime() returns a NULL pointer if 'clock'
      * represents a time before midnight January 1, 1970.  In
      * that case, we also return a NULL pointer and the struct tm
      * object pointed to by 'result' is not modified.
      *
      * Watcom C/C++ 11.0 localtime() treats time_t as unsigned long
@@ -623,16 +620,33 @@ static struct tm *MT_safe_localtime(cons
 
     if (needLock) PR_Unlock(monitor);
 
     return result;
 }
 
 #endif  /* definition of MT_safe_localtime() */
 
+void _PR_InitTime(void)
+{
+#ifdef HAVE_LOCALTIME_MONITOR
+    monitor = PR_NewLock();
+#endif
+}
+
+void _PR_CleanupTime(void)
+{
+#ifdef HAVE_LOCALTIME_MONITOR
+    if (monitor) {
+        PR_DestroyLock(monitor);
+        monitor = NULL;
+    }
+#endif
+}
+
 #if defined(XP_UNIX) || defined(XP_PC) || defined(XP_BEOS)
 
 PR_IMPLEMENT(PRTimeParameters)
 PR_LocalTimeParameters(const PRExplodedTime *gmt)
 {
 
     PRTimeParameters retVal;
     struct tm localTime;
@@ -770,19 +784,63 @@ PR_LocalTimeParameters(const PRExplodedT
  *
  * PR_USPacificTimeParameters --
  *
  *     The time parameters function for the US Pacific Time Zone.
  *
  *------------------------------------------------------------------------
  */
 
+/*
+ * Returns the mday of the first sunday of the month, where
+ * mday and wday are for a given day in the month.
+ * mdays start with 1 (e.g. 1..31).  
+ * wdays start with 0 and are in the range 0..6.  0 = Sunday.
+ */
+#define firstSunday(mday, wday) (((mday - wday + 7 - 1) % 7) + 1)
+
+/*
+ * Returns the mday for the N'th Sunday of the month, where 
+ * mday and wday are for a given day in the month.
+ * mdays start with 1 (e.g. 1..31).  
+ * wdays start with 0 and are in the range 0..6.  0 = Sunday.
+ * N has the following values: 0 = first, 1 = second (etc), -1 = last.
+ * ndays is the number of days in that month, the same value as the 
+ * mday of the last day of the month.
+ */
+static PRInt32 
+NthSunday(PRInt32 mday, PRInt32 wday, PRInt32 N, PRInt32 ndays) 
+{
+    PRInt32 firstSun = firstSunday(mday, wday);
+
+    if (N < 0) 
+        N = (ndays - firstSun) / 7;
+    return firstSun + (7 * N);
+}
+
+typedef struct DSTParams {
+    PRInt8 dst_start_month;       /* 0 = January */
+    PRInt8 dst_start_Nth_Sunday;  /* N as defined above */
+    PRInt8 dst_start_month_ndays; /* ndays as defined above */
+    PRInt8 dst_end_month;         /* 0 = January */
+    PRInt8 dst_end_Nth_Sunday;    /* N as defined above */
+    PRInt8 dst_end_month_ndays;   /* ndays as defined above */
+} DSTParams;
+
+static const DSTParams dstParams[2] = {
+    /* year < 2007:  First April Sunday - Last October Sunday */
+    { 3, 0, 30, 9, -1, 31 },
+    /* year >= 2007: Second March Sunday - First November Sunday */
+    { 2, 1, 31, 10, 0, 30 }
+};
+
 PR_IMPLEMENT(PRTimeParameters)
 PR_USPacificTimeParameters(const PRExplodedTime *gmt)
 {
+    const DSTParams *dst;
     PRTimeParameters retVal;
     PRExplodedTime st;
 
     /*
      * Based on geographic location and GMT, figure out offset of
      * standard time from GMT.  In this example implementation, we
      * assume the local time zone is US Pacific Time.
      */
@@ -802,71 +860,61 @@ PR_USPacificTimeParameters(const PRExplo
     st.tm_month = gmt->tm_month;
     st.tm_year = gmt->tm_year;
     st.tm_wday = gmt->tm_wday;
     st.tm_yday = gmt->tm_yday;
 
     /* Apply the offset to GMT to obtain the local standard time */
     ApplySecOffset(&st, retVal.tp_gmt_offset);
 
+    if (st.tm_year < 2007) { /* first April Sunday - Last October Sunday */
+	dst = &dstParams[0];
+    } else {                 /* Second March Sunday - First November Sunday */
+	dst = &dstParams[1];
+    }
+
     /*
      * Apply the rules on standard time or GMT to obtain daylight saving
      * time offset.  In this implementation, we use the US DST rule.
      */
-    if (st.tm_month < 3) {
+    if (st.tm_month < dst->dst_start_month) {
         retVal.tp_dst_offset = 0L;
-    } else if (st.tm_month == 3) {
-        if (st.tm_wday == 0) {
-            /* A Sunday */
-            if (st.tm_mday <= 7) {
-                /* First Sunday */
-                /* 01:59:59 PST -> 03:00:00 PDT */
-                if (st.tm_hour < 2) {
-                    retVal.tp_dst_offset = 0L;
-                } else {
-                    retVal.tp_dst_offset = 3600L;
-                }
-            } else {
-                /* Not first Sunday */
-                retVal.tp_dst_offset = 3600L;
-            }
-        } else {
-            /* Not a Sunday.  See if before first Sunday or after */
-            if (st.tm_wday + 1 <= st.tm_mday) {
-                /* After first Sunday */
-                retVal.tp_dst_offset = 3600L;
-            } else {
-                /* Before first Sunday */
-                retVal.tp_dst_offset = 0L;
-            } 
+    } else if (st.tm_month == dst->dst_start_month) {
+	int NthSun = NthSunday(st.tm_mday, st.tm_wday, 
+			       dst->dst_start_Nth_Sunday, 
+			       dst->dst_start_month_ndays);
+	if (st.tm_mday < NthSun) {              /* Before starting Sunday */
+	    retVal.tp_dst_offset = 0L;
+        } else if (st.tm_mday == NthSun) {      /* Starting Sunday */
+	    /* 01:59:59 PST -> 03:00:00 PDT */
+	    if (st.tm_hour < 2) {
+		retVal.tp_dst_offset = 0L;
+	    } else {
+		retVal.tp_dst_offset = 3600L;
+	    }
+	} else {                                /* After starting Sunday */
+	    retVal.tp_dst_offset = 3600L;
         }
-    } else if (st.tm_month < 9) {
+    } else if (st.tm_month < dst->dst_end_month) {
         retVal.tp_dst_offset = 3600L;
-    } else if (st.tm_month == 9) {
-        if (st.tm_wday == 0) {
-            if (31 - st.tm_mday < 7) {
-                /* Last Sunday */
-                /* 01:59:59 PDT -> 01:00:00 PST */
-                if (st.tm_hour < 1) {
-                    retVal.tp_dst_offset = 3600L;
-                } else {
-                    retVal.tp_dst_offset = 0L;
-                }
-            } else {
-                /* Not last Sunday */
-                retVal.tp_dst_offset = 3600L;
-            }
-        } else {
-            /* See if before or after last Sunday */
-            if (7 - st.tm_wday <= 31 - st.tm_mday) {
-                /* before last Sunday */
-                retVal.tp_dst_offset = 3600L;
-            } else {
-                retVal.tp_dst_offset = 0L;
-            }
+    } else if (st.tm_month == dst->dst_end_month) {
+	int NthSun = NthSunday(st.tm_mday, st.tm_wday, 
+			       dst->dst_end_Nth_Sunday, 
+			       dst->dst_end_month_ndays);
+	if (st.tm_mday < NthSun) {              /* Before ending Sunday */
+	    retVal.tp_dst_offset = 3600L;
+        } else if (st.tm_mday == NthSun) {      /* Ending Sunday */
+	    /* 01:59:59 PDT -> 01:00:00 PST */
+	    if (st.tm_hour < 1) {
+		retVal.tp_dst_offset = 3600L;
+	    } else {
+		retVal.tp_dst_offset = 0L;
+	    }
+	} else {                                /* After ending Sunday */
+	    retVal.tp_dst_offset = 0L;
         }
     } else {
         retVal.tp_dst_offset = 0L;
     }
     return retVal;
 }
 
 /*
@@ -1237,23 +1285,19 @@ PR_ParseTimeString(
                                   /* it is [0-9][0-9][0-9]+: */
                                   break;
                                 else if ((end - rest) == 2)
                                   tmp_hour = ((rest[0]-'0')*10 +
                                                           (rest[1]-'0'));
                                 else
                                   tmp_hour = (rest[0]-'0');
 
-                                while (*rest && *rest != ':')
-                                  rest++;
-                                rest++;
-
                                 /* move over the colon, and parse minutes */
 
-                                end = rest + 1;
+                                rest = ++end;
                                 while (*end >= '0' && *end <= '9')
                                   end++;
 
                                 if (end == rest)
                                   /* no digits after first colon? */
                                   break;
                                 else if ((end - rest) > 2)
                                   /* it is [0-9][0-9][0-9]+: */
--- a/pr/src/misc/prtrace.c
+++ b/pr/src/misc/prtrace.c
@@ -40,25 +40,17 @@
 **
 ** Implement the API defined in prtrace.h
 **
 **
 **
 */
 
 #include <string.h>
-#include "prtrace.h"
-#include "prclist.h"
-#include "prlock.h"
-#include "prcvar.h"
-#include "prio.h"
-#include "prlog.h"
-#include "prenv.h"
-#include "prmem.h"
-#include "prerror.h"
+#include "primpl.h"
 
 
 #define DEFAULT_TRACE_BUFSIZE ( 1024 * 1024 )
 #define DEFAULT_BUFFER_SEGMENTS    2
 
 /*
 ** Enumerate states in a RName structure
 */
@@ -692,16 +684,22 @@ static PRFileDesc * InitializeRecording(
         _PR_InitializeTrace();
 
     PR_LOG( lm, PR_LOG_DEBUG,
         ("PR_RecordTraceEntries: begins"));
 
     logLostData = 0; /* reset at entry */
     logState = LogReset;
 
+#ifdef XP_UNIX
+    if ((getuid() != geteuid()) || (getgid() != getegid())) {
+        return NULL;
+    }
+#endif /* XP_UNIX */
+
     /* Get the filename for the logfile from the environment */
     logFileName = PR_GetEnv( "NSPR_TRACE_LOG" );
     if ( logFileName == NULL )
     {
         PR_LOG( lm, PR_LOG_ERROR,
             ("RecordTraceEntries: Environment variable not defined. Exiting"));
         return NULL;
     }
--- a/pr/src/pthreads/Makefile.in
+++ b/pr/src/pthreads/Makefile.in
@@ -62,18 +62,13 @@ CSRCS = \
 	$(NULL)
 
 TARGETS	= $(OBJS)
 
 INCLUDES = -I$(dist_includedir) -I$(topsrcdir)/pr/include -I$(topsrcdir)/pr/include/private
 
 DEFINES	+= -D_NSPR_BUILD_
 
-ifeq ($(OS_ARCH),Linux)
-# for pthread_mutexattr_settype
-DEFINES += -D_XOPEN_SOURCE=500
-endif
-
 include $(topsrcdir)/config/rules.mk
 
 export:: $(TARGETS)
 
 
--- a/pr/src/pthreads/ptio.c
+++ b/pr/src/pthreads/ptio.c
@@ -1066,16 +1066,25 @@ static PRBool pt_solaris_sendfile_cont(p
 
     if (count == -1) {
         if (op->syserrno != EWOULDBLOCK && op->syserrno != EAGAIN
                 && op->syserrno != EINTR) {
             op->result.code = -1;
             return PR_TRUE;
         }
         count = xferred;
+    } else if (count == 0) {
+        /* 
+         * We are now at EOF. The file was truncated. Solaris sendfile is
+         * supposed to return 0 and no error in this case, though some versions
+         * may return -1 and EINVAL .
+         */
+        op->result.code = -1;
+        op->syserrno = 0; /* will be treated as EOF */
+        return PR_TRUE;
     }
     PR_ASSERT(count <= op->nbytes_to_send);
     
     op->result.code += count;
     if (count < op->nbytes_to_send) {
         op->nbytes_to_send -= count;
 
         while (count >= vec->sfv_len) {
@@ -2414,16 +2423,24 @@ static PRInt32 pt_SolarisSendFile(PRFile
     PR_ASSERT((count == -1) || (count == xferred));
 
     if (count == -1) {
         syserrno = errno;
         if (syserrno == EINTR
                 || syserrno == EAGAIN || syserrno == EWOULDBLOCK) {
             count = xferred;
         }
+    } else if (count == 0) {
+        /*
+         * We are now at EOF. The file was truncated. Solaris sendfile is
+         * supposed to return 0 and no error in this case, though some versions
+         * may return -1 and EINVAL .
+         */
+        count = -1;
+        syserrno = 0;  /* will be treated as EOF */
     }
 
     if (count != -1 && count < nbytes_to_send) {
         pt_Continuation op;
         struct sendfilevec *vec = sfv_struct;
         PRInt32 rem = count;
 
         while (rem >= vec->sfv_len) {
@@ -3458,17 +3475,17 @@ PR_IMPLEMENT(PRFileDesc*) PR_Socket(PRIn
             int on = 0;
             (void)setsockopt(osfd, IPPROTO_IPV6, IPV6_V6ONLY,
                     &on, sizeof(on));
         }
 #endif
         fd = pt_SetMethods(osfd, ftype, PR_FALSE, PR_FALSE);
         if (fd == NULL) close(osfd);
     }
-#ifdef _PR_STRICT_ADDR_LEN
+#ifdef _PR_NEED_SECRET_AF
     if (fd != NULL) fd->secret->af = domain;
 #endif
 #if defined(_PR_INET6_PROBE) || !defined(_PR_INET6)
 	if (fd != NULL) {
 		/*
 		 * For platforms with no support for IPv6 
 		 * create layered socket for IPv4-mapped IPv6 addresses
 		 */
@@ -4446,17 +4463,17 @@ PR_IMPLEMENT(PRFileDesc*) PR_ImportPipe(
 
 PR_IMPLEMENT(PRFileDesc*) PR_ImportTCPSocket(PRInt32 osfd)
 {
     PRFileDesc *fd;
 
     if (!_pr_initialized) _PR_ImplicitInitialization();
     fd = pt_SetMethods(osfd, PR_DESC_SOCKET_TCP, PR_FALSE, PR_TRUE);
     if (NULL == fd) close(osfd);
-#ifdef _PR_STRICT_ADDR_LEN
+#ifdef _PR_NEED_SECRET_AF
     if (NULL != fd) fd->secret->af = PF_INET;
 #endif
     return fd;
 }  /* PR_ImportTCPSocket */
 
 PR_IMPLEMENT(PRFileDesc*) PR_ImportUDPSocket(PRInt32 osfd)
 {
     PRFileDesc *fd;
@@ -4578,31 +4595,31 @@ PR_IMPLEMENT(PRStatus) PR_UnlockFile(PRF
     return status;
 }
 
 /*
  * The next two entry points should not be in the API, but they are
  * defined here for historical (or hysterical) reasons.
  */
 
-PRInt32 PR_GetSysfdTableMax(void)
+PR_IMPLEMENT(PRInt32) PR_GetSysfdTableMax(void)
 {
 #if defined(XP_UNIX) && !defined(AIX) && !defined(VMS)
     struct rlimit rlim;
 
     if ( getrlimit(RLIMIT_NOFILE, &rlim) < 0) 
        return -1;
 
     return rlim.rlim_max;
 #elif defined(AIX) || defined(VMS)
     return sysconf(_SC_OPEN_MAX);
 #endif
 }
 
-PRInt32 PR_SetSysfdTableSize(PRIntn table_size)
+PR_IMPLEMENT(PRInt32) PR_SetSysfdTableSize(PRIntn table_size)
 {
 #if defined(XP_UNIX) && !defined(AIX) && !defined(VMS)
     struct rlimit rlim;
     PRInt32 tableMax = PR_GetSysfdTableMax();
 
     if (tableMax < 0) return -1;
     rlim.rlim_max = tableMax;
 
--- a/pr/src/pthreads/ptthread.c
+++ b/pr/src/pthreads/ptthread.c
@@ -933,16 +933,17 @@ PR_IMPLEMENT(PRStatus) PR_Cleanup(void)
     if (me->state & PT_THREAD_PRIMORD)
     {
         PR_Lock(pt_book.ml);
         while (pt_book.user > pt_book.this_many)
             PR_WaitCondVar(pt_book.cv, PR_INTERVAL_NO_TIMEOUT);
         PR_Unlock(pt_book.ml);
 
         _PR_CleanupMW();
+        _PR_CleanupTime();
         _PR_CleanupDtoa();
         _PR_CleanupCallOnce();
         _PR_ShutdownLinker();
         _PR_LogCleanup();
         _PR_CleanupNet();
         /* Close all the fd's before calling _PR_CleanupIO */
         _PR_CleanupIO();
 
--- a/pr/tests/dll/Makefile.in
+++ b/pr/tests/dll/Makefile.in
@@ -63,21 +63,16 @@ OBJS = $(OBJDIR)/mygetval.$(OBJ_SUFFIX) 
 ifeq ($(OS_TARGET), WIN16)
 W16OBJS = $(subst $(space),$(comma)$(space),$(OBJS))
 endif
 
 ifeq ($(OS_ARCH), WINNT)
 ifeq ($(OS_TARGET), WIN16)
 # do nothing
 else
-ifdef NS_USE_GCC
-DLLBASE=-Wl,--image-base -Wl,0x30000000
-else
-DLLBASE=-BASE:0x30000000
-endif
 RES=$(OBJDIR)/my.res
 RESNAME=../../../pr/src/nspr.rc
 endif
 endif
 
 ifeq (,$(filter-out WINNT OS2,$(OS_ARCH)))
 IMPORT_LIBRARY	= $(OBJDIR)/my.$(LIB_SUFFIX)
 SHARED_LIBRARY	= $(OBJDIR)/my.dll
--- a/pr/tests/testfile.c
+++ b/pr/tests/testfile.c
@@ -1,41 +1,44 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 
- * The contents of this file are subject to the Mozilla Public
- * License Version 1.1 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.mozilla.org/MPL/
- * 
- * Software distributed under the License is distributed on an "AS
- * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
- * implied. See the License for the specific language governing
- * rights and limitations under the License.
- * 
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
  * The Original Code is the Netscape Portable Runtime (NSPR).
- * 
- * The Initial Developer of the Original Code is Netscape
- * Communications Corporation.  Portions created by Netscape are 
- * Copyright (C) 1998-2000 Netscape Communications Corporation.  All
- * Rights Reserved.
- * 
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 1998-2000
+ * the Initial Developer. All Rights Reserved.
+ *
  * Contributor(s):
- * 
- * Alternatively, the contents of this file may be used under the
- * terms of the GNU General Public License Version 2 or later (the
- * "GPL"), in which case the provisions of the GPL are applicable 
- * instead of those above.  If you wish to allow use of your 
- * version of this file only under the terms of the GPL and not to
- * allow others to use your version of this file under the MPL,
- * indicate your decision by deleting the provisions above and
- * replace them with the notice and other provisions required by
- * the GPL.  If you do not delete the provisions above, a recipient
- * may use your version of this file under either the MPL or the
- * GPL.
- */
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
 
 #include "nspr.h"
 #include "prpriv.h"
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #ifdef WIN32
--- a/pr/tests/timetest.c
+++ b/pr/tests/timetest.c
@@ -500,97 +500,100 @@ int main(int argc, char** argv)
     }
 
     /*
      **************************************************************
      **
      **  Stress test
      *
      **      Go through four years, starting from
-     **      00:00:00 PST Jan. 1, 1993, incrementing
+     **      00:00:00 PST Jan. 1, 2005, incrementing
      **      every 10 minutes.
      **
      **************************************************************
      */
 
     {
 	PRExplodedTime et, et1, et2;
 	PRInt64 usecPer10Min;
 	int day, hour, min;
 	PRTime usecs;
 	int dstInEffect = 0;
 
 	if (debug_mode) {
 	printf("\n");
 	printf("*******************************************************\n");
 	printf("**                                                   **\n");
-	printf("**                 Stress test                       **\n");
-	printf("**  Starting from midnight Jan. 1, 1993 PST,         **\n");
+	printf("**        Stress test  Pacific Time                  **\n");
+	printf("**  Starting from midnight Jan. 1, 2005 PST,         **\n");
 	printf("**  going through four years in 10-minute increment  **\n");
 	printf("**                                                   **\n");
 	printf("*******************************************************\n\n");
 	}
 	LL_I2L(usecPer10Min, 600000000L);
 
-	/* 00:00:00 PST Jan. 1, 1993 */
+	/* 00:00:00 PST Jan. 1, 2005 */
 	et.tm_usec = 0;
 	et.tm_sec = 0;
 	et.tm_min = 0;
 	et.tm_hour = 0;
 	et.tm_mday = 1;
 	et.tm_month = 0;
-	et.tm_year = 1993;
+	et.tm_year = 2005;
 	et.tm_params.tp_gmt_offset = -8 * 3600;
 	et.tm_params.tp_dst_offset = 0;
 	usecs = PR_ImplodeTime(&et);
 
         for (day = 0; day < 4 * 365 + 1; day++) {
 	    for (hour = 0; hour < 24; hour++) {
 		for (min = 0; min < 60; min += 10) {
 	            LL_ADD(usecs, usecs, usecPer10Min);
 		    PR_ExplodeTime(usecs, PR_USPacificTimeParameters, &et1);
 
 		    et2 = et;
 		    et2.tm_usec += 600000000L;
 		    PR_NormalizeTime(&et2, PR_USPacificTimeParameters);
 
 		    if (!ExplodedTimeIsEqual(&et1, &et2)) {
-		        if (debug_mode) printf("ERROR: componentwise comparison failed\n");
+			printf("ERROR: componentwise comparison failed\n");
 			PrintExplodedTime(&et1);
-			if (debug_mode) printf("\n");
+			printf("\n");
 			PrintExplodedTime(&et2);
-			if (debug_mode) printf("\n");
+			printf("\n");
 			failed_already=1;
 		        return 1;
 		    }
 
 		    if (LL_NE(usecs, PR_ImplodeTime(&et1))) { 
-                        if (debug_mode)
-					printf("ERROR: PR_ExplodeTime and PR_ImplodeTime are not inverse\n");
+			printf("ERROR: PR_ExplodeTime and PR_ImplodeTime are not inverse\n");
 			PrintExplodedTime(&et1);
-			if (debug_mode) printf("\n");
+			printf("\n");
 			failed_already=1;
 		        return 1;
 		    }
 		    testParseTimeString(usecs);
 
 		    if (!dstInEffect && et1.tm_params.tp_dst_offset) {
 		        dstInEffect = 1;
-		        if (debug_mode) printf("DST changeover from ");
-			PrintExplodedTime(&et);
-			if (debug_mode) printf(" to ");
-			PrintExplodedTime(&et1);
-			if (debug_mode) printf(".\n");
+		        if (debug_mode) {
+			    printf("DST changeover from ");
+			    PrintExplodedTime(&et);
+			    printf(" to ");
+			    PrintExplodedTime(&et1);
+			    printf(".\n");
+		    	}
                     } else if (dstInEffect && !et1.tm_params.tp_dst_offset) {
 		        dstInEffect = 0;
-			if (debug_mode) printf("DST changeover from ");
-			PrintExplodedTime(&et);
-			if (debug_mode) printf(" to ");
-			PrintExplodedTime(&et1);
-			if (debug_mode) printf(".\n");
+			if (debug_mode) {
+			    printf("DST changeover from ");
+			    PrintExplodedTime(&et);
+			    printf(" to ");
+			    PrintExplodedTime(&et1);
+			    printf(".\n");
+			}
                     }
 
 		    et = et1;
 		}
 	    }
         }
 	if (debug_mode) printf("Test passed\n");
     }
@@ -604,79 +607,83 @@ int main(int argc, char** argv)
 	int day, hour, min;
 	PRTime usecs;
 	int dstInEffect = 0;
 
 	if (debug_mode) {
 	printf("\n");
 	printf("*******************************************************\n");
 	printf("**                                                   **\n");
-	printf("**                 Stress test                       **\n");
-	printf("**  Starting from midnight Jan. 1, 1993 PST,         **\n");
+	printf("**         Stress test    Local Time                 **\n");
+	printf("**  Starting from midnight Jan. 1, 2005 PST,         **\n");
 	printf("**  going through four years in 10-minute increment  **\n");
 	printf("**                                                   **\n");
 	printf("*******************************************************\n\n");
 	}
 	
 	LL_I2L(usecPer10Min, 600000000L);
 
-	/* 00:00:00 PST Jan. 1, 1993 */
+	/* 00:00:00 PST Jan. 1, 2005 */
 	et.tm_usec = 0;
 	et.tm_sec = 0;
 	et.tm_min = 0;
 	et.tm_hour = 0;
 	et.tm_mday = 1;
 	et.tm_month = 0;
-	et.tm_year = 1993;
+	et.tm_year = 2005;
 	et.tm_params.tp_gmt_offset = -8 * 3600;
 	et.tm_params.tp_dst_offset = 0;
 	usecs = PR_ImplodeTime(&et);
 
         for (day = 0; day < 4 * 365 + 1; day++) {
 	    for (hour = 0; hour < 24; hour++) {
 		for (min = 0; min < 60; min += 10) {
 	            LL_ADD(usecs, usecs, usecPer10Min);
 		    PR_ExplodeTime(usecs, PR_LocalTimeParameters, &et1);
 
 		    et2 = et;
 		    et2.tm_usec += 600000000L;
 		    PR_NormalizeTime(&et2, PR_LocalTimeParameters);
 
 		    if (!ExplodedTimeIsEqual(&et1, &et2)) {
-		        if (debug_mode) printf("ERROR: componentwise comparison failed\n");
+			printf("ERROR: componentwise comparison failed\n");
 			PrintExplodedTime(&et1);
-			if (debug_mode) printf("\n");
+			printf("\n");
 			PrintExplodedTime(&et2);
-			if (debug_mode) printf("\n");
+			printf("\n");
 		        return 1;
 		    }
 
 		    if (LL_NE(usecs, PR_ImplodeTime(&et1))) {
                         printf("ERROR: PR_ExplodeTime and PR_ImplodeTime are not inverse\n");
 			PrintExplodedTime(&et1);
-			if (debug_mode) printf("\n");
+			printf("\n");
 			failed_already=1;
 		        return 1;
 		    }
 		    testParseTimeString(usecs);
 
 		    if (!dstInEffect && et1.tm_params.tp_dst_offset) {
 		        dstInEffect = 1;
-		        if (debug_mode) printf("DST changeover from ");
-			PrintExplodedTime(&et);
-			if (debug_mode) printf(" to ");
-			PrintExplodedTime(&et1);
-			if (debug_mode) printf(".\n");
+		        if (debug_mode) {
+			    printf("DST changeover from ");
+			    PrintExplodedTime(&et);
+			    printf(" to ");
+			    PrintExplodedTime(&et1);
+			    printf(".\n");
+			}
                     } else if (dstInEffect && !et1.tm_params.tp_dst_offset) {
 		        dstInEffect = 0;
-			if (debug_mode) printf("DST changeover from ");
-			PrintExplodedTime(&et);
-			if (debug_mode) printf(" to ");
-			PrintExplodedTime(&et1);
-			if (debug_mode) printf(".\n");
+			if (debug_mode) {
+			    printf("DST changeover from ");
+			    PrintExplodedTime(&et);
+			    printf(" to ");
+			    PrintExplodedTime(&et1);
+			    printf(".\n");
+			}
                     }
 
 		    et = et1;
 		}
 	    }
         }
 	if (debug_mode) printf("Test passed\n");
     }
@@ -689,80 +696,83 @@ int main(int argc, char** argv)
 	int day, hour, min;
 	PRTime usecs;
 	int dstInEffect = 0;
 
 	if (debug_mode) {
 	printf("\n");
 	printf("*******************************************************\n");
 	printf("**                                                   **\n");
-	printf("**                 Stress test                       **\n");
-	printf("**  Starting from midnight Jan. 1, 1997 PST,         **\n");
+	printf("**           Stress test    Local Time               **\n");
+	printf("**  Starting from midnight Jan. 1, 2009 PST,         **\n");
 	printf("**  going back four years in 10-minute increment     **\n");
 	printf("**                                                   **\n");
 	printf("*******************************************************\n\n");
 	}
 
 	LL_I2L(usecPer10Min, 600000000L);
 
-	/* 00:00:00 PST Jan. 1, 1997 */
+	/* 00:00:00 PST Jan. 1, 2009 */
 	et.tm_usec = 0;
 	et.tm_sec = 0;
 	et.tm_min = 0;
 	et.tm_hour = 0;
 	et.tm_mday = 1;
 	et.tm_month = 0;
-	et.tm_year = 1997;
+	et.tm_year = 2009;
 	et.tm_params.tp_gmt_offset = -8 * 3600;
 	et.tm_params.tp_dst_offset = 0;
 	usecs = PR_ImplodeTime(&et);
 
         for (day = 0; day < 4 * 365 + 1; day++) {
 	    for (hour = 0; hour < 24; hour++) {
 		for (min = 0; min < 60; min += 10) {
 	            LL_SUB(usecs, usecs, usecPer10Min);
 		    PR_ExplodeTime(usecs, PR_LocalTimeParameters, &et1);
 
 		    et2 = et;
 		    et2.tm_usec -= 600000000L;
 		    PR_NormalizeTime(&et2, PR_LocalTimeParameters);
 
 		    if (!ExplodedTimeIsEqual(&et1, &et2)) {
-		        if (debug_mode) printf("ERROR: componentwise comparison failed\n");
+		        printf("ERROR: componentwise comparison failed\n");
 			PrintExplodedTime(&et1);
-			if (debug_mode) printf("\n");
+			printf("\n");
 			PrintExplodedTime(&et2);
-			if (debug_mode) printf("\n");
+			printf("\n");
 		        return 1;
 		    }
 
 		    if (LL_NE(usecs, PR_ImplodeTime(&et1))) {
-                   if (debug_mode)
-					printf("ERROR: PR_ExplodeTime and PR_ImplodeTime are not inverse\n");
+			printf("ERROR: PR_ExplodeTime and PR_ImplodeTime are not inverse\n");
 			PrintExplodedTime(&et1);
-			if (debug_mode) printf("\n");
+			printf("\n");
 			failed_already=1;
 		        return 1;
 		    }
 		    testParseTimeString(usecs);
 
 		    if (!dstInEffect && et1.tm_params.tp_dst_offset) {
 		        dstInEffect = 1;
-		        if (debug_mode) printf("DST changeover from ");
-			PrintExplodedTime(&et);
-			if (debug_mode) printf(" to ");
-			PrintExplodedTime(&et1);
-			if (debug_mode) printf(".\n");
+		        if (debug_mode) {
+			    printf("DST changeover from ");
+			    PrintExplodedTime(&et);
+			    printf(" to ");
+			    PrintExplodedTime(&et1);
+			    printf(".\n");
+			}
                     } else if (dstInEffect && !et1.tm_params.tp_dst_offset) {
 		        dstInEffect = 0;
-			if (debug_mode) printf("DST changeover from ");
-			PrintExplodedTime(&et);
-			if (debug_mode) printf(" to ");
-			PrintExplodedTime(&et1);
-			if (debug_mode) printf(".\n");
+			if (debug_mode) {
+			    printf("DST changeover from ");
+			    PrintExplodedTime(&et);
+			    printf(" to ");
+			    PrintExplodedTime(&et1);
+			    printf(".\n");
+			}
                     }
 
 		    et = et1;
 		}
 	    }
         }
     }
 
--- a/pr/tests/tmocon.c
+++ b/pr/tests/tmocon.c
@@ -1,41 +1,44 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 
- * The contents of this file are subject to the Mozilla Public
- * License Version 1.1 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.mozilla.org/MPL/
- * 
- * Software distributed under the License is distributed on an "AS
- * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
- * implied. See the License for the specific language governing
- * rights and limitations under the License.
- * 
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
  * The Original Code is the Netscape Portable Runtime (NSPR).
- * 
- * The Initial Developer of the Original Code is Netscape
- * Communications Corporation.  Portions created by Netscape are 
- * Copyright (C) 1998-2000 Netscape Communications Corporation.  All
- * Rights Reserved.
- * 
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 1998-2000
+ * the Initial Developer. All Rights Reserved.
+ *
  * Contributor(s):
- * 
- * Alternatively, the contents of this file may be used under the
- * terms of the GNU General Public License Version 2 or later (the
- * "GPL"), in which case the provisions of the GPL are applicable 
- * instead of those above.  If you wish to allow use of your 
- * version of this file only under the terms of the GPL and not to
- * allow others to use your version of this file under the MPL,
- * indicate your decision by deleting the provisions above and
- * replace them with the notice and other provisions required by
- * the GPL.  If you do not delete the provisions above, a recipient
- * may use your version of this file under either the MPL or the
- * GPL.
- */
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
 
 /***********************************************************************
 **
 ** Name: tmocon.c
 **
 ** Description: test client socket connection.
 **
 ** Modification History:
--- a/pr/tests/vercheck.c
+++ b/pr/tests/vercheck.c
@@ -47,39 +47,41 @@
  */
 
 #include "prinit.h"
 
 #include <stdio.h>
 #include <stdlib.h>
 
 /*
- * This release (4.6.1) is backward compatible with the
- * 4.0.x, 4.1.x, 4.2.x, 4.3.x, 4.4.x, 4.5.x, and 4.6 releases.
- * It, of course, is compatible with itself.
+ * This release (4.6.8) is backward compatible with the
+ * 4.0.x, 4.1.x, 4.2.x, 4.3.x, 4.4.x, 4.5.x, 4.6, 4.6.1, 4.6.2,
+ * 4.6.3, 4.6.4, 4.6.5, 4.6.6 and 4.6.7 releases.  It, of course,
+ * is compatible with itself.
  */
 static char *compatible_version[] = {
     "4.0", "4.0.1", "4.1", "4.1.1", "4.1.2", "4.1.3",
     "4.2", "4.2.1", "4.2.2", "4.3", "4.4", "4.4.1",
-    "4.5", "4.5.1", "4.6", PR_VERSION
+    "4.5", "4.5.1", "4.6", "4.6.1", "4.6.2", "4.6.3",
+    "4.6.4", "4.6.5", "4.6.6", "4.6.7", PR_VERSION
 };
 
 /*
  * This release is not backward compatible with the old
  * NSPR 2.1 and 3.x releases.
  *
  * Any release is incompatible with future releases and
  * patches.
  */
 static char *incompatible_version[] = {
     "2.1 19980529",
     "3.0", "3.0.1",
     "3.1", "3.1.1", "3.1.2", "3.1.3",
     "3.5", "3.5.1",
-    "4.6.3",
+    "4.6.99",
     "4.7", "4.7.1",
     "10.0", "11.1", "12.14.20"
 };
 
 int main()
 {
     int idx;
     int num_compatible = sizeof(compatible_version) / sizeof(char *);