Merged HEAD branch changes to here. AUTOCONF_NSPR_WIN32_XCOMPILE_19990621_BRANCH
authorcls%seawood.org
Sat, 09 Oct 1999 03:51:28 +0000
branchAUTOCONF_NSPR_WIN32_XCOMPILE_19990621_BRANCH
changeset 861 77c0f52239ccc185e2877368bddc5b9126471ed2
parent 843 1097762ab7fa13041ea6069afa7865b9860454aa
push idunknown
push userunknown
push dateunknown
Merged HEAD branch changes to here.
lib/ds/Makefile.in
macbuild/NSPRConfig.h
pr/include/MANIFEST
pr/include/md/Makefile.in
pr/include/obsolete/protypes.h
pr/src/Makefile.in
pr/src/linking/prlink.c
pr/src/md/mac/macdll.c
pr/src/md/mac/macsockotpt.c
pr/src/md/mac/macthr.c
pr/src/md/mac/mactime.c
pr/src/md/unix/Makefile.in
pr/tests/Makefile.in
--- a/lib/ds/Makefile.in
+++ b/lib/ds/Makefile.in
@@ -167,18 +167,26 @@ endif
 # The Client build wants the shared libraries in $(DIST)/bin,
 # so we also install them there.
 #
 
 export:: $(TARGETS)
 	$(INSTALL) -m 444 $(HEADERS) $(DIST)/include
 	$(INSTALL) -m 444 $(TARGETS) $(DIST)/lib
 ifdef SHARED_LIBRARY
+ifeq ($(OS_ARCH),HP-UX)
+	$(INSTALL) -m 755 $(SHARED_LIBRARY) $(DIST)/lib
+	$(INSTALL) -m 755 $(SHARED_LIBRARY) $(DIST)/bin
+else
 	$(INSTALL) -m 444 $(SHARED_LIBRARY) $(DIST)/bin
 endif
+ifeq ($(OS_ARCH), OpenVMS)
+	$(INSTALL) -m 444 $(SHARED_LIBRARY:.$(DLL_SUFFIX)=.vms) $(DIST)/lib
+endif
+endif
 ifeq ($(MOZ_BITS),16)
 	$(INSTALL) -m 444 $(HEADERS) $(MOZ_INCL)
 	$(INSTALL) -m 444 $(TARGETS) $(MOZ_DIST)/lib
 	$(INSTALL) -m 444 $(TARGETS) $(MOZ_DIST)/bin
 endif
 
 install:: export
 
--- a/macbuild/NSPRConfig.h
+++ b/macbuild/NSPRConfig.h
@@ -18,9 +18,10 @@
 
 #define OLDROUTINELOCATIONS 0
 
 #define XP_MAC 1
 #define _PR_NO_PREEMPT 1
 #define _NO_FAST_STRING_INLINES_ 1
 #define FORCE_PR_LOG 1
 #define NSPR20 1
+#define NSPR_AS_SHARED_LIB
 
--- a/pr/include/MANIFEST
+++ b/pr/include/MANIFEST
@@ -33,15 +33,17 @@ prrwlock.h
 prsystem.h
 prthread.h
 prtime.h
 prtrace.h
 prtypes.h
 prvrsion.h
 prwin16.h
 
+prlink_mac.h
+
 obsolete/protypes.h
 obsolete/prsem.h
 obsolete/probslet.h
 
 private/prpriv.h
 private/pprio.h
 private/pprthred.h
--- a/pr/include/md/Makefile.in
+++ b/pr/include/md/Makefile.in
@@ -142,45 +142,47 @@ endif
 ifeq ($(OS_ARCH),DGUX)
 MDCPUCFG_H = _dgux.cfg
 endif
 
 ifeq ($(OS_ARCH),QNX)
 MDCPUCFG_H = _qnx.cfg
 endif
 
+ifeq ($(OS_TARGET),NTO)
+MDCPUCFG_H = _nto.cfg
+endif
+
 ifeq ($(OS_ARCH),BeOS)
 MDCPUCFG_H = _beos.cfg
 endif
 
 endif # ! USE_AUTOCONF
 
 export:: #$(MDCPUCFG_H)
 	$(INSTALL) -m 444 $(CONFIGS) $(DIST)/include/md
 #ifeq ($(MOZ_BITS),16)
 #	cp $(DIST)/include/$(MDCPUCFG_H) $(DIST)/include/prcpucfg.h
 #	$(INSTALL) -m 444 $(MDCPUCFG_H) $(MOZ_INCL)
 #	mv -f $(DIST)/include/$(MDCPUCFG_H) $(MOZ_INCL)/prcpucfg.h
 #else
+ifneq ($(OS_ARCH),OpenVMS)
 	@if cmp -s $(srcdir)/$(MDCPUCFG_H) $(DIST)/include/prcpucfg.h; then \
 	  echo $(DIST)/include/prcpucfg.h unchanged; \
 	else \
 	  echo cp -f $(srcdir)/$(MDCPUCFG_H) $(DIST)/include/prcpucfg.h; \
 	  cp -f $(srcdir)/$(MDCPUCFG_H) $(DIST)/include/prcpucfg.h; \
 	fi
-#endif
-ifeq ($(OS_ARCH),OpenVMS)
-# mv'ing a link causes the file itself to move, not the link, so fix it.
+else
+# mv'ing a link causes the file itself to move, not the link.
 	rm -f $(DIST)/include/$(MDCPUCFG_H)
-	if [ ! -L $(DIST)/include/prcpucfg.h ]; then \
-	  mv -f $(DIST)/include/prcpucfg.h $(MDCPUCFG_H); \
-	  ln -fs ../../../nsprpub/pr/include/md/$(MDCPUCFG_H) \
-	    $(DIST)/include/prcpucfg.h; \
-	fi
+	rm -f $(DIST)/include/prcpucfg.h
+	ln -fs `pwd`/$(MDCPUCFG_H) $(DIST)/include/prcpucfg.h
 endif
+#endif
 
 release:: export
 	@echo "Copying machine-dependent prcpucfg.h"
 	@if test -z "$(BUILD_NUMBER)"; then \
 		echo "BUILD_NUMBER must be defined"; \
 		false; \
 	fi
 	@if test ! -d $(RELEASE_INCLUDE_DIR); then \
--- a/pr/include/obsolete/protypes.h
+++ b/pr/include/obsolete/protypes.h
@@ -34,17 +34,17 @@ typedef PRIntn intn;
 /*
  * BeOS already defines the integer types below in its standard
  * header file SupportDefs.h.
  */
 #ifdef XP_BEOS
 
 #include <support/SupportDefs.h>
 
-#elif VMS
+#elif defined(VMS)
 /*
  * OpenVMS already defines the integer types below in its standard
  * header files ints.h and types.h.
  */
 #include <ints.h>
 #include <types.h>
 #else
 
--- a/pr/src/Makefile.in
+++ b/pr/src/Makefile.in
@@ -93,20 +93,16 @@ ifeq ($(OS_ARCH),AIX)
 ifneq (,$(filter-out 3.2 4.1,$(OS_RELEASE)))
 ifneq ($(USE_PTHREADS),1)
 BUILD_AIX_RTL_LIBC = 1
 AIX_RTL_LIBC	= $(OBJDIR)/libc.a
 endif
 endif
 endif
 
-ifeq ($(OS_ARCH),OpenVMS)
-OS_LIBS		= -lvms_jackets
-endif
-
 ifeq ($(OS_ARCH),OSF1)
 ifeq ($(USE_PTHREADS), 1)
 OS_LIBS 	= -lpthread -lrt
 endif
 ifneq ($(OS_RELEASE),V2.0)
 OS_LIBS		+= -lc_r
 endif
 ifeq ($(USE_IPV6), 1)
@@ -405,18 +401,26 @@ endif
 #
 # The Client build wants the shared libraries in $(DIST)/bin,
 # so we also install them there.
 #
 
 export:: $(TARGETS)
 	$(INSTALL) -m 444 $(TARGETS) $(DIST)/lib
 ifdef SHARED_LIBRARY
+ifeq ($(OS_ARCH),HP-UX)
+	$(INSTALL) -m 755 $(SHARED_LIBRARY) $(DIST)/lib
+	$(INSTALL) -m 755 $(SHARED_LIBRARY) $(DIST)/bin
+else
 	$(INSTALL) -m 444 $(SHARED_LIBRARY) $(DIST)/bin
 endif
+ifeq ($(OS_ARCH), OpenVMS)
+	$(INSTALL) -m 444 $(SHARED_LIBRARY:.$(DLL_SUFFIX)=.vms) $(DIST)/lib
+endif
+endif
 ifeq ($(MOZ_BITS),16)
 	$(INSTALL) -m 444 $(TARGETS) $(MOZ_DIST)/lib
 	$(INSTALL) -m 444 $(TARGETS) $(MOZ_DIST)/bin
 endif
 
 ifeq ($(BUILD_AIX_RTL_LIBC),1)
 $(AIX_RTL_LIBC): /usr/ccs/lib/libc.a
 	rtl_enable -o $@ $<
--- a/pr/src/linking/prlink.c
+++ b/pr/src/linking/prlink.c
@@ -24,16 +24,21 @@
 #include <image.h>
 #endif
 
 #ifdef XP_MAC
 #include <CodeFragments.h>
 #include <TextUtils.h>
 #include <Types.h>
 #include <Strings.h>
+#include <Aliases.h>
+
+#include "prlink_mac.h"
+#include "macdll.h"
+#include "mdmac.h"
 #endif
 
 #ifdef XP_UNIX
 #ifdef USE_DLFCN
 #include <dlfcn.h>
 #ifdef LINUX
 #define  _PR_DLOPEN_FLAGS RTLD_NOW
 #else
@@ -716,16 +721,136 @@ PR_FindLibrary(const char *name)
     PRLibrary* result;
 
     PR_EnterMonitor(pr_linker_lock);
     result = pr_UnlockedFindLibrary(name);
     PR_ExitMonitor(pr_linker_lock);
     return result;
 }
 
+
+#ifdef XP_MAC
+
+PR_IMPLEMENT(PRLibrary*) 
+PR_LoadNamedFragment(const FSSpec *fileSpec, const char* fragmentName)
+{
+	PRLibrary*					newLib = NULL;
+	PRLibrary* 					result;
+	FSSpec							resolvedSpec = *fileSpec;
+	CFragConnectionID		connectionID = 0;
+	Boolean							isFolder, wasAlias;
+	OSErr								err = noErr;
+	
+	if (!_pr_initialized) _PR_ImplicitInitialization();
+
+	/* See if library is already loaded */
+	PR_EnterMonitor(pr_linker_lock);
+
+	result = pr_UnlockedFindLibrary(fragmentName);
+	if (result != NULL) goto unlock;
+
+	newLib = PR_NEWZAP(PRLibrary);
+	if (newLib == NULL) goto unlock;
+	newLib->staticTable = NULL;
+
+
+	/* Resolve an alias if this was one */
+	err = ResolveAliasFile(&resolvedSpec, true, &isFolder, &wasAlias);
+	if (err != noErr)
+		goto unlock;
+
+  if (isFolder)
+  {
+  	err = fnfErr;
+  	goto unlock;
+  }
+    
+	/* Finally, try to load the library */
+	err = NSLoadNamedFragment(&resolvedSpec, fragmentName, &connectionID);
+	if (err != noErr)
+		goto unlock;
+
+  newLib->name = strdup(fragmentName);
+  newLib->dlh = connectionID;
+  newLib->next = pr_loadmap;
+  pr_loadmap = newLib;
+
+  result = newLib;    /* success */
+  PR_LOG(_pr_linker_lm, PR_LOG_MIN, ("Loaded library %s (load lib)", newLib->name));
+
+unlock:
+	if (result == NULL) {
+		PR_SetError(PR_LOAD_LIBRARY_ERROR, _MD_ERRNO());
+		DLLErrorInternal(_MD_ERRNO());  /* sets error text */
+	}
+	PR_ExitMonitor(pr_linker_lock);
+	return result;
+}
+
+
+PR_EXTERN(PRLibrary*)
+PR_LoadIndexedFragment(const FSSpec *fileSpec, PRUint32 fragIndex)
+{
+	PRLibrary*					newLib = NULL;
+	PRLibrary* 					result;
+	FSSpec							resolvedSpec = *fileSpec;
+	char*								fragmentName = NULL;
+	CFragConnectionID		connectionID = 0;
+	Boolean							isFolder, wasAlias;
+	OSErr								err = noErr;
+
+	if (!_pr_initialized) _PR_ImplicitInitialization();
+
+	/* See if library is already loaded */
+	PR_EnterMonitor(pr_linker_lock);
+
+	result = pr_UnlockedFindLibrary(fragmentName);
+	if (result != NULL) goto unlock;
+
+	newLib = PR_NEWZAP(PRLibrary);
+	if (newLib == NULL) goto unlock;
+	newLib->staticTable = NULL;
+
+
+	/* Resolve an alias if this was one */
+	err = ResolveAliasFile(&resolvedSpec, true, &isFolder, &wasAlias);
+	if (err != noErr)
+		goto unlock;
+
+  if (isFolder)
+  {
+  	err = fnfErr;
+  	goto unlock;
+  }
+    
+	/* Finally, try to load the library */
+	err = NSLoadIndexedFragment(&resolvedSpec, fragIndex, &fragmentName, &connectionID);
+	if (err != noErr)
+		goto unlock;
+
+  newLib->name = fragmentName;			/* was malloced in NSLoadIndexedFragment */
+  newLib->dlh = connectionID;
+  newLib->next = pr_loadmap;
+  pr_loadmap = newLib;
+
+  result = newLib;    /* success */
+  PR_LOG(_pr_linker_lm, PR_LOG_MIN, ("Loaded library %s (load lib)", newLib->name));
+
+unlock:
+	if (result == NULL) {
+		PR_SetError(PR_LOAD_LIBRARY_ERROR, _MD_ERRNO());
+		DLLErrorInternal(_MD_ERRNO());  /* sets error text */
+	}
+	PR_ExitMonitor(pr_linker_lock);
+	return result;
+}
+
+
+#endif
+
 /*
 ** Unload a shared library which was loaded via PR_LoadLibrary
 */
 PR_IMPLEMENT(PRStatus) 
 PR_UnloadLibrary(PRLibrary *lib)
 {
     int result = 0;
     PRStatus status = PR_SUCCESS;
--- a/pr/src/md/mac/macdll.c
+++ b/pr/src/md/mac/macdll.c
@@ -11,64 +11,35 @@
  * NPL.
  * 
  * The Initial Developer of this code under the NPL is Netscape
  * Communications Corporation.  Portions created by Netscape are
  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  * Reserved.
  */
 
-#undef OLDROUTINENAMES
-#define OLDROUTINENAMES 1
+#include <string.h>
 
 #include <Files.h>
 #include <Errors.h>
 #include <Folders.h>
 #include <CodeFragments.h>
 #include <Aliases.h>
+#include <Resources.h>
+
+#include "IterateDirectory.h"		/* MoreFiles */
 
 #include "MacErrorHandling.h"
+#include "macdll.h"
+#include "mdmac.h"
+#include "macio.h"
+
 #include "primpl.h"
 #include "plstr.h"
 
-typedef struct CfrgItem CfrgItem, *CfrgItemPtr;
-struct CfrgItem 
-{
-        OSType          fArchType;
-        UInt32          fUpdateLevel;
-        UInt32     		fCurVersion;
-        UInt32     		fOldDefVersion;
-        UInt32          fAppStackSize;
-        UInt16          fAppSubFolder;
-        UInt8       	fUsage;
-        UInt8           fLocation;
-        UInt32          fCodeOffset;
-        UInt32          fCodeLength;
-        UInt32          fReserved1;
-        UInt32          fReserved2;
-        UInt16          fItemSize; // %4 == 0
-        Str255          fName;
-        // Only make the final p-string as long as needed, then align to
-        // a longword boundary
-};
-
-typedef struct CfrgHeader CfrgHeader, *CfrgHeaderPtr, **CfrgHeaderHandle;
-struct CfrgHeader 
-{
-        UInt32          fReserved1;
-        UInt32          fReserved2;
-        UInt32          fVersion;
-        UInt32          fReserved3;
-        UInt32          fReserved4;
-        UInt32          fFiller1;
-        UInt32          fFiller2;
-        UInt32          fItemCount;
-        CfrgItem        fCfrgItemArray[1];
-};
-
 /*
 	turds used to iterate through the directories looking
 	for the desired library.
 */
 
 struct GetSharedLibraryFilterProcData
 {
 	Boolean				inRecursive;
@@ -88,17 +59,17 @@ GetSharedLibraryFilterProc(const CInfoPB
 /*
 	NSGetSharedLibrary
 	
 	Unfortunately CFM doesn't support user specified loader paths,
 	so we emulate the behavior.  Effectively this is a GetSharedLibrary
 	where the loader path is user defined.
 */
 
-extern OSErr
+OSErr
 NSGetSharedLibrary(Str255 inLibName, CFragConnectionID* outID, Ptr* outMainAddr)
 {
 	char*		curLibPath;
 	char*		freeCurLibPath;
 	OSErr		tempErr;
 	Boolean		recursive;
 	FSSpec		curFolder;	
 	GetSharedLibraryFilterProcData filterData;
@@ -108,19 +79,19 @@ NSGetSharedLibrary(Str255 inLibName, CFr
 	filterData.outFound = false;
 	filterData.outID = (CFragConnectionID)(-1);
 	filterData.outAddress = NULL;
 	filterData.inName = inLibName;
 		
 	freeCurLibPath = curLibPath = PR_GetLibraryPath();
 	
 	if (curLibPath == NULL)
-		return (fragLibNotFound);
+		return (cfragNoLibraryErr);
 	
-	tempErr = fragLibNotFound;
+	tempErr = cfragNoLibraryErr;
 	
 	do
 	{
 		endCurLibPath = PL_strchr(curLibPath, PR_PATH_SEPARATOR);
 		done = (endCurLibPath == NULL);
 
 #if 0
 		// we overload the first character of a path if it's :
@@ -156,17 +127,17 @@ NSGetSharedLibrary(Str255 inLibName, CFr
 			{
 				*outID = filterData.outID;
 				*outMainAddr = filterData.outAddress;
 				tempErr = noErr;
 				break;
 			}
 			else 
 			{
-				tempErr = fragLibNotFound;
+				tempErr = cfragNoLibraryErr;
 			}
 		}
 		
 		curLibPath = endCurLibPath + 1;	// skip to next path (past the '\0');
 	} while (!done);
 
 	free(freeCurLibPath);
 	return (tempErr);
@@ -226,17 +197,17 @@ GetSharedLibraryFilterProc(const CInfoPB
 		
 				break;
 			default:
 				return;
 		}
 	
 		// see if this symbol is in this fragment
 		if (LibInPefContainer(&fragSpec, pFilterData->inName, &codeOffset, &codeLength))
-			tempErr = GetDiskFragment(&fragSpec, codeOffset, codeLength, pFilterData->inName, kLoadLib, &pFilterData->outID, &pFilterData->outAddress, errName);
+			tempErr = GetDiskFragment(&fragSpec, codeOffset, codeLength, pFilterData->inName, kLoadCFrag, &pFilterData->outID, &pFilterData->outAddress, errName);
 		else
 			return;
 				
 		// stop if we found a library by that name
 		if (noErr == tempErr)
 		{			
 			*inWantQuit = true;
 			pFilterData->outFound = true;
@@ -253,50 +224,50 @@ GetSharedLibraryFilterProc(const CInfoPB
 	Tell whether library inName is contained it the file pointed to by inSpec.
 	Return the codeOffset and codeLength information, for a subsequent
 	call to GetDiskFragment.
 */
 
 static Boolean
 LibInPefContainer(const FSSpec* inSpec, StringPtr inName, UInt32* outCodeOffset, UInt32* outCodeLength)
 {
-	short				refNum;
-	CfrgHeaderHandle	hCfrg;
-	CfrgItem*			pCurItem;
-	UInt32				curLibIndex;
-	Boolean				found;
+	short					refNum;
+	CFragResourceHandle		hCfrg;
+	CFragResourceMember*	pCurItem;
+	UInt32					curLibIndex;
+	Boolean					found;
 	
 	// asume we didn't find it
 	found = false;
 	
 	// open the resource fork, if we can't bail
 	refNum = FSpOpenResFile(inSpec, fsRdPerm);
 	require(-1 != refNum, Exit);
 	
 	// grab out the alias record, if it's not there bail
-	hCfrg = (CfrgHeaderHandle) Get1Resource(kCFragResourceType, kCFragResourceID);
+	hCfrg = (CFragResourceHandle) Get1Resource(kCFragResourceType, kCFragResourceID);
 	require(NULL != hCfrg, CloseResourceAndExit);
 	
 	HLock((Handle)hCfrg);
 	
 	// get ptr to first item
-	pCurItem = &(*hCfrg)->fCfrgItemArray[0];
-	for (curLibIndex = 0; curLibIndex < (*hCfrg)->fItemCount; curLibIndex++)
+	pCurItem = &(*hCfrg)->firstMember;
+	for (curLibIndex = 0; curLibIndex < (*hCfrg)->memberCount; curLibIndex++)
 	{
 		// is this our library?
-		if ((pCurItem->fName[0] == inName[0]) &&
-			(strncmp((char*) inName + 1, (char*) pCurItem->fName + 1, PR_MIN(pCurItem->fName[0], inName[0])) == 0))
+		if ((pCurItem->name[0] == inName[0]) &&
+			(strncmp((char*) inName + 1, (char*) pCurItem->name + 1, PR_MIN(pCurItem->name[0], inName[0])) == 0))
 		{
-			*outCodeOffset = pCurItem->fCodeOffset;
-			*outCodeLength = pCurItem->fCodeLength;
+			*outCodeOffset = pCurItem->offset;
+			*outCodeLength = pCurItem->length;
 			found = true;
 		}
 		
 		// skip to next one
-		pCurItem = (CfrgItem*) ((char*) pCurItem + pCurItem->fItemSize);						
+		pCurItem = (CFragResourceMember*) ((char*) pCurItem + pCurItem->memberSize);						
 	}
 	
 	HUnlock((Handle)hCfrg);
 	
 CloseResourceAndExit:
 	CloseResFile(refNum);
 Exit:
 	return (found);
@@ -307,18 +278,18 @@ Exit:
 /*
 	NSFindSymbol
 	
 	Workaround bug in CFM FindSymbol (in at least 7.5.5) where symbols with lengths
 	greater than 63 chars cause a "paramErr".  We iterate through all symbols
 	in the library to find the desired symbol.
 */
 
-extern OSErr
-NSFindSymbol(CFragConnectionID inID, Str255 inSymName, Ptr*	outMainAddr, SymClass *outSymClass)
+OSErr
+NSFindSymbol(CFragConnectionID inID, Str255 inSymName, Ptr*	outMainAddr, CFragSymbolClass *outSymClass)
 {
 	OSErr	err;
 	
 	if (inSymName[0] > 63)
 	{
 		/* 
 			if there are greater than 63 characters in the
 			name, CFM FindSymbol fails, so let's iterate through all
@@ -343,19 +314,232 @@ NSFindSymbol(CFragConnectionID inID, Str
 				{
 					/* found our symbol */
 					found = true;
 				}
 			}
 			
 			/* if we didn't find it set the error code so below it won't take this symbol */
 			if (!found)
-				err = fragSymbolNotFound;
+				err = cfragNoSymbolErr;
 		}	
 	}
 	else
 	{	
 		err = FindSymbol(inID, inSymName, outMainAddr, outSymClass);
 	}
 	
 	return (err);
 }
 
+
+#pragma mark -
+
+
+/*-----------------------------------------------------------------
+
+	GetNamedFragmentOffsets
+
+	Get the offsets into the data fork of the named fragment,
+	by reading the 'cfrg' resoruce.
+
+-----------------------------------------------------------------*/
+static OSErr GetNamedFragmentOffsets(const FSSpec *fileSpec, const char* fragmentName,
+							UInt32 *outOffset, UInt32 *outLength)
+{
+	CFragResourceHandle		cFragHandle;
+	short									fileRefNum;
+	OSErr									err = noErr;
+	
+	fileRefNum = FSpOpenResFile(fileSpec, fsRdPerm);
+	err = ResError();
+	if (err != noErr) return err;
+
+	cFragHandle = (CFragResourceHandle)Get1Resource(kCFragResourceType, kCFragResourceID);	
+	if (!cFragHandle)
+	{
+		err = resNotFound;
+		goto done;
+	}
+	
+	/* nothing here moves memory, so no need to lock the handle */
+	
+	err = cfragNoLibraryErr;			/* in case of failure */
+	*outOffset = 0;
+	*outLength = 0;
+	
+	/* Now look for the named fragment */
+	if ((**cFragHandle).memberCount > 0)
+	{
+		CFragResourceMemberPtr	memberPtr;
+		UInt16									i;
+		
+		for (	i = 0, memberPtr = &(**cFragHandle).firstMember;
+					i < (**cFragHandle).memberCount;
+					i ++, memberPtr = (CFragResourceMemberPtr)((char *)memberPtr + memberPtr->memberSize))
+		{
+			char		memberName[256];
+			UInt16	nameLen = PR_MIN(memberPtr->name[0], 255);
+		
+			// avoid malloc here for speed
+			strncpy(memberName, (char *)&memberPtr->name[1], nameLen);
+			memberName[nameLen] = '\0';
+		
+			// fragment names are case insensitive, so act like the system
+			if (PL_strcasecmp(memberName, fragmentName) == 0)
+			{
+				*outOffset = memberPtr->offset;
+				*outLength = memberPtr->length;
+				err = noErr;
+				break;
+			}
+		}
+	}
+	
+	/* Resource handle will go away when the res fork is closed */
+	
+done:
+	CloseResFile(fileRefNum);
+	return err;
+}
+
+
+/*-----------------------------------------------------------------
+
+	GetIndexedFragmentOffsets
+	
+	Get the offsets into the data fork of the indexed fragment,
+	by reading the 'cfrg' resoruce.
+
+-----------------------------------------------------------------*/
+static OSErr GetIndexedFragmentOffsets(const FSSpec *fileSpec, UInt32 fragmentIndex,
+							UInt32 *outOffset, UInt32 *outLength, char **outFragmentName)
+{
+	CFragResourceHandle		cFragHandle;
+	short									fileRefNum;
+	OSErr									err = noErr;
+	
+	fileRefNum = FSpOpenResFile(fileSpec, fsRdPerm);
+	err = ResError();
+	if (err != noErr) return err;
+
+	cFragHandle = (CFragResourceHandle)Get1Resource(kCFragResourceType, kCFragResourceID);	
+	if (!cFragHandle)
+	{
+		err = resNotFound;
+		goto done;
+	}
+		
+	err = cfragNoLibraryErr;			/* in case of failure */
+	*outOffset = 0;
+	*outLength = 0;
+	*outFragmentName = NULL;
+	
+	/* the CStrFromPStr mallocs, so might move memory */
+	HLock((Handle)cFragHandle);
+	
+	/* Now look for the named fragment */
+	if ((**cFragHandle).memberCount > 0)
+	{
+		CFragResourceMemberPtr	memberPtr;
+		UInt16									i;
+		
+		for (	i = 0, memberPtr = &(**cFragHandle).firstMember;
+					i < (**cFragHandle).memberCount;
+					i ++, memberPtr = (CFragResourceMemberPtr)((char *)memberPtr + memberPtr->memberSize))
+		{
+			
+			if (i == fragmentIndex)
+			{
+				char	*fragmentStr;
+				CStrFromPStr(memberPtr->name, &fragmentStr);
+				if (!fragmentStr)		/* test for allocation failure */
+				{
+					err = memFullErr;
+					break;
+				}
+				
+				*outFragmentName = fragmentStr;
+				*outOffset = memberPtr->offset;
+				*outLength = memberPtr->length;
+				err = noErr;
+				break;
+			}
+		}
+	}
+	
+	HUnlock((Handle)cFragHandle);
+	
+	/* Resource handle will go away when the res fork is closed */
+	
+done:
+	CloseResFile(fileRefNum);
+	return err;
+}
+
+
+/*-----------------------------------------------------------------
+
+	NSLoadNamedFragment
+	
+	Load the named fragment from the specified file. Aliases must
+	have been resolved by this point.
+
+-----------------------------------------------------------------*/
+
+OSErr NSLoadNamedFragment(const FSSpec *fileSpec, const char* fragmentName, CFragConnectionID *outConnectionID)
+{
+	UInt32		fragOffset, fragLength;
+	Ptr				main;
+	Str255		fragName = "\p";
+	Str255		errName;
+	OSErr			err;
+	
+	err = GetNamedFragmentOffsets(fileSpec, fragmentName, &fragOffset, &fragLength);
+	if (err != noErr) return err;
+				
+	err = GetDiskFragment(fileSpec, fragOffset, fragLength, fragName, 
+					kLoadCFrag, outConnectionID, &main, errName);
+
+	return err;
+}
+
+
+/*-----------------------------------------------------------------
+
+	NSLoadIndexedFragment
+	
+	Load the indexed fragment from the specified file. Aliases must
+	have been resolved by this point.
+	
+	*outFragName is a malloc'd block containing the fragment name,
+	if returning noErr.
+
+-----------------------------------------------------------------*/
+
+OSErr NSLoadIndexedFragment(const FSSpec *fileSpec, PRUint32 fragmentIndex,
+							char** outFragName, CFragConnectionID *outConnectionID)
+{
+	UInt32		fragOffset, fragLength;
+	char			*fragNameBlock = NULL;
+	Ptr				main;
+	Str255		fragName = "\p";
+	Str255		errName;
+	OSErr			err;
+
+	*outFragName = NULL;
+	
+	err = GetIndexedFragmentOffsets(fileSpec, fragmentIndex, &fragOffset, &fragLength, &fragNameBlock);
+	if (err != noErr) return err;
+				
+	err = GetDiskFragment(fileSpec, fragOffset, fragLength, fragName, 
+					kLoadCFrag, outConnectionID, &main, errName);
+	if (err != noErr)
+	{
+		free(fragNameBlock);
+		return err;
+	}
+
+	*outFragName = fragNameBlock;
+	return noErr;
+}
+
+
--- a/pr/src/md/mac/macsockotpt.c
+++ b/pr/src/md/mac/macsockotpt.c
@@ -14,18 +14,21 @@
  * Communications Corporation.  Portions created by Netscape are
  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  * Reserved.
  */
 
 /* This turns on UNIX style errors in OT 1.1 headers */
 #define OTUNIXERRORS 1
 
+#include <string.h>
+
 #include <Gestalt.h>
 #include <OpenTransport.h>
+#include <OSUtils.h>
 
 #define GESTALT_OPEN_TPT_PRESENT        gestaltOpenTptPresentMask
 #define GESTALT_OPEN_TPT_TCP_PRESENT    gestaltOpenTptTCPPresentMask
 
 #include <OpenTptInternet.h>    // All the internet typedefs
 #include "primpl.h"
 
 typedef enum SndRcvOpCode {
@@ -529,17 +532,17 @@ TryAgain:
     err = me->md.osErrCode;
     if (err != kOTNoError)
         goto ErrorExit;
 
     return kOTNoError;
 
 ErrorExit:
     if ((err == kOTNoAddressErr) && (++retryCount <= 4)) {
-        long finalTicks;
+        unsigned long finalTicks;
     
         Delay(100,&finalTicks);
         goto TryAgain;
     }
     macsock_map_error(err);
     return -1;
 }
 
--- a/pr/src/md/mac/macthr.c
+++ b/pr/src/md/mac/macthr.c
@@ -13,16 +13,18 @@
  * The Initial Developer of this code under the NPL is Netscape
  * Communications Corporation.  Portions created by Netscape are
  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  * Reserved.
  */
 
 #include "primpl.h"
 
+#include <string.h>
+
 #include <Types.h>
 #include <Timer.h>
 #include <OSUtils.h>
 
 #include <LowMem.h>
 
 
 TimerUPP	gTimerCallbackUPP	= NULL;
--- a/pr/src/md/mac/mactime.c
+++ b/pr/src/md/mac/mactime.c
@@ -12,20 +12,22 @@
  * 
  * The Initial Developer of this code under the NPL is Netscape
  * Communications Corporation.  Portions created by Netscape are
  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  * Reserved.
  */
 
 #include <OSUtils.h>
-#include <time.h>
+#include <Timer.h>
 
 #include "primpl.h"
 
+#include "mactime.h"
+
 PR_IMPLEMENT(UnsignedWide) dstLocalBaseMicroseconds;
 PR_IMPLEMENT(unsigned long) gJanuaryFirst1970Seconds;
 
 /*
  * The geographic location and time zone information of a Mac
  * are stored in extended parameter RAM.  The ReadLocation
  * produdure uses the geographic location record, MachineLocation,
  * to read the geographic location and time zone information in
--- a/pr/src/md/unix/Makefile.in
+++ b/pr/src/md/unix/Makefile.in
@@ -131,16 +131,21 @@ SCOOS_CSRCS = \
 
 DGUX_CSRCS = \
 	dgux.c \
 	$(NULL)
 
 QNX_CSRCS = \
 	qnx.c \
 	$(NULL)
+
+NTO_CSRCS = \
+	nto.c \
+	$(NULL)
+
 endif # !USE_AUTOCONF
 
 ifeq ($(PTHREADS_USER),1)
 CSRCS += $(PTH_USER_CSRCS)
 endif
 
 ifndef USE_AUTOCONF
 
@@ -206,18 +211,22 @@ CSRCS += $(NCR_CSRCS)
 endif
 ifeq ($(OS_ARCH),SCOOS)
 CSRCS += $(SCOOS_CSRCS)
 endif
 ifeq ($(OS_ARCH),DGUX)
 CSRCS += $(DGUX_CSRCS)
 endif
 ifeq ($(OS_ARCH),QNX)
+ifeq ($(OS_TARGET),NTO)
+CSRCS += $(NTO_CSRCS)
+else
 CSRCS += $(QNX_CSRCS)
 endif
+endif
 
 #
 # Some Unix platforms have an assembly language file.
 # E.g., AIX 3.2, Solaris (both sparc and x86).
 #
 ifeq ($(OS_ARCH), AIX)
     ifeq ($(OS_RELEASE), 3.2)
 	ASFILES   = os_$(OS_ARCH).s
--- a/pr/tests/Makefile.in
+++ b/pr/tests/Makefile.in
@@ -479,17 +479,17 @@ ifeq ($(OS_TARGET),WIN16)
 	echo $(LIBPR),	     >>w16link
 	echo $(LIBPLC),		 >>w16link
 	echo winsock.lib     >>w16link
 	wlink @w16link.
 else
 ifeq ($(OS_TARGET),OS2)
 	$(LINK) $(EXEFLAGS) $(LDOPTS) $< $(LIBPLC) $(LIBPR) $(OS_LIBS) $(EXTRA_LIBS)
 else
-	link $(LDOPTS) $< $(LIBPLC) $(LIBPR) wsock32.lib -out:$@
+	link $(LDOPTS) $(EXTRA_LDOPTS) $< $(LIBPLC) $(LIBPR) $(EXTRA_LIBS) wsock32.lib -out:$@
 endif
 endif
 else
 	$(PURE) $(CC) $(XCFLAGS) $< $(LDOPTS) $(LIBPLC) $(LIBPR) $(EXTRA_LIBS) -o $@
 endif
 
 endif