From 4825bbf7a61a589cb0073ba34550375010b34414 Mon Sep 17 00:00:00 2001 From: "law%netscape.com" Date: Tue, 23 Feb 1999 19:56:57 +0000 Subject: [PATCH] Landing LIBREG990212_BRANCH to get libreg building on Mac git-svn-id: svn://10.0.0.236/trunk@21645 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/build/mac/BuildList.pm | 3 + mozilla/build/mac/NGLayoutBuildList.pm | 2 + mozilla/config/mac/DefinesMozilla.h | 14 +- mozilla/modules/libreg/src/VerReg.c | 12 +- mozilla/modules/libreg/src/makefile.win | 2 +- mozilla/modules/libreg/src/reg.c | 76 ++++++++++- mozilla/modules/libreg/src/vr_stubs.c | 109 +++++++++++----- mozilla/modules/libreg/src/vr_stubs.h | 165 +++++++++++++++++------- 8 files changed, 291 insertions(+), 92 deletions(-) diff --git a/mozilla/build/mac/BuildList.pm b/mozilla/build/mac/BuildList.pm index d596167fba4..1631ff5913e 100644 --- a/mozilla/build/mac/BuildList.pm +++ b/mozilla/build/mac/BuildList.pm @@ -88,6 +88,9 @@ sub BuildMozilla() BuildProject(":mozilla:lib:mac:NSStdLib:NSStdLib.mcp", "NSStdLib$D.shlb"); MakeAlias(":mozilla:lib:mac:NSStdLib:NSStdLib$D.shlb", "$dist_dir"); + BuildProject(":mozilla:modules:libreg:macbuild:libreg.mcp", "libreg$D.shlb"); + MakeAlias(":mozilla:modules:libreg:macbuild:libreg$D.shlb", "$dist_dir"); + BuildProject(":mozilla:xpcom:macbuild:xpcomPPC.mcp", "xpcom$D.shlb"); MakeAlias(":mozilla:xpcom:macbuild:xpcom$D.shlb", "$dist_dir"); diff --git a/mozilla/build/mac/NGLayoutBuildList.pm b/mozilla/build/mac/NGLayoutBuildList.pm index 013cdadbfba..6577b08cadb 100644 --- a/mozilla/build/mac/NGLayoutBuildList.pm +++ b/mozilla/build/mac/NGLayoutBuildList.pm @@ -460,6 +460,8 @@ sub BuildCommonProjects() BuildOneProject(":mozilla:jpeg:macbuild:JPEG.mcp", "JPEG$D.shlb", "JPEG.toc", 1, $main::ALIAS_SYM_FILES); + BuildOneProject(":mozilla:modules:libreg:macbuild:libreg.mcp", "libreg$D.shlb", "", 1, $main::ALIAS_SYM_FILES); + BuildOneProject(":mozilla:xpcom:macbuild:xpcomPPC.mcp", "xpcom$D.shlb", "xpcom.toc", 1, $main::ALIAS_SYM_FILES); BuildOneProject(":mozilla:js:macbuild:JavaScript.mcp", "JavaScript$D.shlb", "JavaScript.toc", 1, $main::ALIAS_SYM_FILES); diff --git a/mozilla/config/mac/DefinesMozilla.h b/mozilla/config/mac/DefinesMozilla.h index dbf45c14e08..90d3dddce3f 100644 --- a/mozilla/config/mac/DefinesMozilla.h +++ b/mozilla/config/mac/DefinesMozilla.h @@ -16,17 +16,17 @@ * Reserved. */ -// ΡΡΡ Security +// ——— Security //#define NADA_VERSION //#define EXPORT_VERSION #define US_VERSION -// ΡΡΡ Misc +// ——— Misc //#define NO_DBM // define this to kill DBM #define NEW_BOOKMARKS // Enables us to switch profiling from project preferences -// ΡΡΡ Version +// ——— Version //#define ALPHA //#define BETA // Comment out both ALPHA and BETA for the final version @@ -47,10 +47,11 @@ // 98-10-14 joe -- temporary item to turn on ENDER MIME support before it fully lands #define MOZ_ENDER_MIME 1 +#define USE_NSREG 1 -// ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ -// ₯ You typically will not need to change things below here -// ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡ +// ——————————————————————————————————————————————————————————————————————————— +// • You typically will not need to change things below here +// ——————————————————————————————————————————————————————————————————————————— #define MOCHA #define MOZILLA_CLIENT 1 @@ -66,6 +67,7 @@ #endif #define LAYERS 1 +// #define NU_CACHE 1 // uncomment to turn on new memory cache features #define CASTED_READ_OBJECT(stream, type, reference) (reference = NULL) diff --git a/mozilla/modules/libreg/src/VerReg.c b/mozilla/modules/libreg/src/VerReg.c index b1ec4915828..df0295f6e6f 100644 --- a/mozilla/modules/libreg/src/VerReg.c +++ b/mozilla/modules/libreg/src/VerReg.c @@ -37,10 +37,12 @@ #include #endif +#ifdef STANDALONE_REGISTRY #include #include #include #include +#endif /*STANDALONE_REGISTRY*/ #include "reg.h" #include "NSReg.h" @@ -135,8 +137,10 @@ static REGERR vr_Init(void) REGERR err = REGERR_OK; char *regname = ""; +#if defined(XP_UNIX) || defined(STANDALONE_REGISTRY) char curstr[MAXREGNAMELEN]; RKEY navKey; +#endif #ifdef XP_UNIX char *regbuf = NULL; #endif @@ -663,7 +667,9 @@ VR_INTERFACE(REGERR) VR_CreateRegistry( char *installation, char *programPath, c { FILEHANDLE fh; REGERR err; +#ifndef STANDALONE_REGISTRY XP_StatStruct st; +#endif char * regname = ""; #ifdef XP_UNIX char * regbuf = NULL; @@ -974,7 +980,9 @@ VR_INTERFACE(REGERR) VR_InRegistry(char *component_path) REGERR err; RKEY rootkey; RKEY key; +#if !defined(STANDALONE_REGISTRY) && defined(XP_UNIX) HREG hreg; +#endif err = vr_Init(); if (err != REGERR_OK) @@ -995,8 +1003,10 @@ VR_INTERFACE(REGERR) VR_ValidateComponent(char *component_path) REGERR err; RKEY rootkey; RKEY key; - HREG hreg; char path[MAXREGPATHLEN]; +#if !defined(STANDALONE_REGISTRY) && defined(XP_UNIX) + HREG hreg; +#endif #ifdef USE_CHECKSUM diff --git a/mozilla/modules/libreg/src/makefile.win b/mozilla/modules/libreg/src/makefile.win index 52fd99898b9..b67892e12fe 100644 --- a/mozilla/modules/libreg/src/makefile.win +++ b/mozilla/modules/libreg/src/makefile.win @@ -72,7 +72,7 @@ LIBRARY= .\$(OBJDIR)\$(LIBNAME).lib #//------------------------------------------------------------------------ LCFLAGS = $(LCFLAGS) -LLIBS = $(LLIBS) $(LIBNSPR) +LLIBS = $(LLIBS) $(LIBNSPR) $(DIST)\lib\libplc21.lib !if "$(MOZ_BITS)"=="32" && defined(MOZ_DEBUG) && defined(GLOWCODE) LLIBS=$(LLIBS) $(GLOWDIR)\glowcode.lib diff --git a/mozilla/modules/libreg/src/reg.c b/mozilla/modules/libreg/src/reg.c index 0e316994794..dcab526e65a 100644 --- a/mozilla/modules/libreg/src/reg.c +++ b/mozilla/modules/libreg/src/reg.c @@ -39,19 +39,40 @@ #define VERIFY_READ 1 #endif +#ifdef STANDALONE_REGISTRY #include #include #include #include #include -#ifdef SUNOS4 +#if defined(XP_MAC) + #include +#endif + +#if defined(SUNOS4) #include /* for SEEK_SET */ #endif /* SUNOS4 */ +#else + +#include "prerror.h" + +#endif /*STANDALONE_REGISTRY*/ + #include "reg.h" #include "NSReg.h" +#if !defined(STANDALONE_REGISTRY) && defined(SEEK_SET) + /* Undo the damage caused by xp_core.h, which is included by NSReg.h */ + #undef SEEK_SET + #undef SEEK_CUR + #undef SEEK_END + #define SEEK_SET PR_SEEK_SET + #define SEEK_CUR PR_SEEK_CUR + #define SEEK_END PR_SEEK_END +#endif + #if defined(XP_UNIX) #ifndef MAX_PATH #define MAX_PATH 1024 @@ -300,8 +321,7 @@ static REGERR nr_UnlockRange(FILEHANDLE fh, REGOFF offset, int32 len); static int32 nr_GetFileLength(FILEHANDLE fh); /* -------------------------------------------------------------------- */ - - +#ifdef STANDALONE_REGISTRY static REGERR nr_OpenFile(char *path, FILEHANDLE *fh) { XP_ASSERT( path != NULL ); @@ -313,10 +333,18 @@ static REGERR nr_OpenFile(char *path, FILEHANDLE *fh) { switch (errno) { +#ifdef XP_MAC + case fnfErr: +#else case ENOENT: /* file not found */ +#endif return REGERR_NOFILE; +#ifdef XP_MAC + case opWrErr: +#else case EACCES: /* file in use */ +#endif /* DVNOTE: should we try read only? */ (*fh) = vr_fileOpen(path, XP_FILE_READ_BIN); if ( VALID_FILEHANDLE(*fh) ) @@ -334,7 +362,39 @@ static REGERR nr_OpenFile(char *path, FILEHANDLE *fh) return REGERR_OK; } /* OpenFile */ +#else +static REGERR nr_OpenFile(char *path, FILEHANDLE *fh) +{ + PR_ASSERT( path != NULL ); + PR_ASSERT( fh != NULL ); + /* Open the file for exclusive random read/write */ + (*fh) = PR_Open(path, PR_RDWR, 00700); + if ( !VALID_FILEHANDLE(*fh) ) + { + switch (PR_GetError()) + { + case PR_FILE_NOT_FOUND_ERROR: /* file not found */ + return REGERR_NOFILE; + + case PR_FILE_IS_BUSY_ERROR: /* file in use */ + case PR_FILE_IS_LOCKED_ERROR: + case PR_ILLEGAL_ACCESS_ERROR: + /* DVNOTE: should we try read only? */ + (*fh) = PR_Open(path, PR_RDONLY, 00700); + if ( VALID_FILEHANDLE(*fh) ) + return REGERR_READONLY; + else + return REGERR_FAIL; + default: + return REGERR_FAIL; + } + } + + return REGERR_OK; + +} /* OpenFile */ +#endif static REGERR nr_CloseFile(FILEHANDLE *fh) @@ -379,9 +439,15 @@ static REGERR nr_ReadFile(FILEHANDLE fh, REGOFF offset, int32 len, void *buffer) readlen = XP_FileRead(buffer, len, fh ); /* PR_READ() returns an unreliable length, check EOF separately */ if (readlen < 0) { +#if !defined(STANDALONE_REGISTRY) || !defined(XP_MAC) + #if defined(STANDALONE_REGISTRY) if (errno == EBADF) /* bad file handle, not open for read, etc. */ + #else + if (PR_GetError() == PR_BAD_DESCRIPTOR_ERROR) + #endif err = REGERR_FAIL; else +#endif err = REGERR_BADREAD; } else if (readlen < len) { @@ -3485,10 +3551,6 @@ extern XP_Bool bGlobalRegistry; VR_INTERFACE(void) NR_StartupRegistry(void) { HREG reg; - RKEY key; - REGERR err; - REGENUM state; - XP_Bool removeFromList; if (bRegStarted) return; diff --git a/mozilla/modules/libreg/src/vr_stubs.c b/mozilla/modules/libreg/src/vr_stubs.c index 869e822d408..c900c7e0b1d 100644 --- a/mozilla/modules/libreg/src/vr_stubs.c +++ b/mozilla/modules/libreg/src/vr_stubs.c @@ -20,12 +20,17 @@ * into a stand-alone library for use with our installers */ +#ifdef STANDALONE_REGISTRY + #include #include -#ifndef STANDALONE_REGISTRY +#else + #include "prtypes.h" -#endif +#include "plstr.h" + +#endif /*STANDALONE_REGISTRY*/ #include "vr_stubs.h" @@ -47,6 +52,7 @@ extern char* globalRegName; #define INCL_DOS #include +#ifdef STANDALONE_REGISTRY extern XP_File vr_fileOpen (const char *name, const char * mode) { XP_File fh = NULL; @@ -61,6 +67,7 @@ extern XP_File vr_fileOpen (const char *name, const char * mode) return fh; } +#endif /*STANDALONE_REGISTRY*/ extern void vr_findGlobalRegName () { @@ -92,6 +99,7 @@ extern void vr_findGlobalRegName () #include "windows.h" #define PATHLEN 260 +#ifdef STANDALONE_REGISTRY extern XP_File vr_fileOpen (const char *name, const char * mode) { XP_File fh = NULL; @@ -106,6 +114,7 @@ extern XP_File vr_fileOpen (const char *name, const char * mode) return fh; } +#endif /*STANDALONE_REGISTRY*/ extern void vr_findGlobalRegName () { @@ -148,13 +157,18 @@ int FAR PASCAL _export WEP(int nParam) #include #include "FullPath.h" -extern XP_File vr_fileOpen (const char *name, const char * mode) +#ifdef STANDALONE_REGISTRY +extern XP_File vr_fileOpen(const char *name, const char * mode) { XP_File fh = NULL; struct stat st; OSErr anErr; FSSpec newFSSpec; +#ifdef STANDALONE_REGISTRY + errno = 0; // reset errno (only if we're using stdio) +#endif + anErr = FSpLocationFromFullPath(strlen(name), name, &newFSSpec); if (anErr == -43) @@ -178,38 +192,60 @@ extern XP_File vr_fileOpen (const char *name, const char * mode) fh = fopen( name, XP_FILE_WRITE_BIN ); } } +#ifdef STANDALONE_REGISTRY + if (anErr != noErr) + errno = anErr; +#endif return fh; } +#endif /*STANDALONE_REGISTRY*/ -extern void vr_findGlobalRegName () +extern void vr_findGlobalRegName() { FSSpec regSpec; OSErr err; short foundVRefNum; long foundDirID; - short pathLen; - Handle thePath; int bCreate = 0; - Ptr finalPath; err = FindFolder(kOnSystemDisk,'pref', false, &foundVRefNum, &foundDirID); - if (!err) { - + if (!err) + { err = FSMakeFSSpec(foundVRefNum, foundDirID, "\pNetscape Registry", ®Spec); - if (err == -43) { /* if file doesn't exist */ + if (err == -43) /* if file doesn't exist */ + { err = FSpCreate(®Spec, 'MOSS', 'REGS', smSystemScript); bCreate = 1; } - if (err == noErr) { + if (err == noErr) + { + Handle thePath; + short pathLen; err = FSpGetFullPath(®Spec, &pathLen, &thePath); - - finalPath = NewPtrClear(pathLen+1); - BlockMoveData(*thePath, finalPath, pathLen); - globalRegName = XP_STRDUP(finalPath); - DisposePtr(finalPath); + if (err == noErr && thePath) + { + #ifdef STANDALONE_REGISTRY + globalRegName = XP_STRDUP(*(char**)thePath); + #else + /* Since we're now using NSPR, this HAS to be a unix path! */ + const char* src; + char* dst; + globalRegName = (char*)XP_ALLOC(pathLen + 2); + src = *(char**)thePath; + dst = globalRegName; + *dst++ = '/'; + while (pathLen--) + { + char c = *src++; + *dst++ = (c == ':') ? '/' : c; + } + *dst = '\0'; + #endif + } + DisposeHandle(thePath); } } } @@ -225,13 +261,15 @@ extern int nr_RenameFile(char *from, char *to) FSSpec destDirSpec; FSSpec beforeRenameSpec; - errno = 0; // reset errno - +#ifdef STANDALONE_REGISTRY + errno = 0; // reset errno (only if we're using stdio) +#endif + if (from && to) { - err = FSpLocationFromFullPath(strlen(from), from, &fromSpec); + err = FSpLocationFromFullPath(XP_STRLEN(from), from, &fromSpec); if (err != noErr) goto exit; - err = FSpLocationFromFullPath(strlen(to), to, &toSpec); + err = FSpLocationFromFullPath(XP_STRLEN(to), to, &toSpec); if (err != noErr && err != fnfErr) goto exit; // make an FSSpec for the destination directory @@ -251,13 +289,15 @@ extern int nr_RenameFile(char *from, char *to) } exit: +#ifdef STANDALONE_REGISTRY if (err != noErr) errno = err; +#endif return (err == noErr ? 0 : -1); } -#if 1 +#if 0 /* Uncomment the following for older Mac build environments * that don't support these functions */ @@ -343,16 +383,18 @@ int strncasecmp(const char *str1, const char *str2, int length) * ------------------------------------------------------------------ */ -/*allow OS/2 to use this main to test...*/ -#if defined(XP_UNIX) || defined(XP_OS2) +/*allow OS/2 and Macintosh to use this main to test...*/ +#if (defined(STANDALONE_REGISTRY) && defined(XP_MAC)) || defined(XP_UNIX) || defined(XP_OS2) #include + #ifdef XP_OS2 #include #define W_OK 0x02 /*evil hack from the docs...*/ #else #include #endif + #include "NSReg.h" #include "VerReg.h" @@ -360,7 +402,7 @@ char *TheRegistry = "registry"; char *Flist; /* WARNING: build hackery */ -#ifdef STANDALONE_REGISTRY +#if defined(STANDALONE_REGISTRY) && !defined(XP_MAC) long BUILDNUM = #include "../../../build/build_number" ; @@ -374,6 +416,7 @@ int main(int argc, char *argv[]); #define DEF_REG "/.netscape/registry" +#ifdef STANDALONE_REGISTRY extern XP_File vr_fileOpen (const char *name, const char * mode) { XP_File fh = NULL; @@ -388,6 +431,7 @@ extern XP_File vr_fileOpen (const char *name, const char * mode) return fh; } +#endif /*STANDALONE_REGISTRY*/ extern void vr_findGlobalRegName () { @@ -409,13 +453,12 @@ extern void vr_findGlobalRegName () XP_FREEIF(def); #else globalRegName = TheRegistry; -#endif +#endif /*STANDALONE_REGISTRY*/ } -#endif +#endif /*XP_UNIX*/ - -#ifdef STANDALONE_REGISTRY +#if defined(STANDALONE_REGISTRY) && (defined(XP_UNIX) || defined(XP_OS2) || defined(XP_MAC)) int main(int argc, char *argv[]) { @@ -448,7 +491,8 @@ int main(int argc, char *argv[]) strcpy(buff, TheRegistry); - if ( p = strrchr( buff, '/' )) + p = strrchr( buff, '/' ); + if ( p ) { char pwd[1024]; @@ -468,11 +512,12 @@ int main(int argc, char *argv[]) VR_SetRegDirectory(buff); +#ifndef XP_MAC if ( -1 == (access( TheRegistry, W_OK )) ) { sprintf(ver,"4.50.0.%ld",BUILDNUM); VR_CreateRegistry("Communicator", buff, ver); } - +#endif if ( !(fh = fopen( Flist, "r" )) ) { @@ -504,8 +549,6 @@ int main(int argc, char *argv[]) return 0; } -#endif /* STANDALONE_REGISTRY */ +#endif /* STANDALONE_REGISTRY && (XP_UNIX || XP_OS2 || XP_MAC) */ #endif /* XP_UNIX || XP_OS2 */ - - diff --git a/mozilla/modules/libreg/src/vr_stubs.h b/mozilla/modules/libreg/src/vr_stubs.h index a2e5b7ecbd5..14e5df84923 100644 --- a/mozilla/modules/libreg/src/vr_stubs.h +++ b/mozilla/modules/libreg/src/vr_stubs.h @@ -24,12 +24,22 @@ #ifndef _VR_STUBS_H_ #define _VR_STUBS_H_ +#ifdef STANDALONE_REGISTRY + #include #include #ifdef XP_MAC #include "macstdlibextras.h" /* For strcasecmp and strncasecmp */ #endif +#else + +#include "prio.h" +#include "prmem.h" +#include "plstr.h" + +#endif /* STANDALONE_REGISTRY*/ + #ifdef XP_MAC #include #else @@ -39,6 +49,7 @@ #include #endif + #ifndef FALSE #define FALSE 0 #endif @@ -46,28 +57,6 @@ #define TRUE 1 #endif -#define XP_FILE_READ "r" -#define XP_FILE_READ_BIN "rb" -#define XP_FILE_WRITE "w" -#define XP_FILE_WRITE_BIN "wb" -#define XP_FILE_UPDATE "r+" -#define XP_FILE_TRUNCATE "w+" -#ifdef SUNOS4 -/* XXX SunOS4 hack -- make this universal by using r+b and w+b */ -#define XP_FILE_UPDATE_BIN "r+" -#define XP_FILE_TRUNCATE_BIN "w+" -#else -#define XP_FILE_UPDATE_BIN "rb+" -#define XP_FILE_TRUNCATE_BIN "wb+" -#endif - -#define XP_FileSeek(file,offset,whence) fseek ((file), (offset), (whence)) -#define XP_FileRead(dest,count,file) fread ((dest), 1, (count), (file)) -#define XP_FileWrite(src,count,file) fwrite ((src), 1, (count), (file)) -#define XP_FileTell(file) ftell(file) -#define XP_FileFlush(file) fflush(file) -#define XP_FileClose(file) fclose(file) - #if defined(__cplusplus) # define XP_CPLUSPLUS # define XP_IS_CPLUSPLUS 1 @@ -83,12 +72,33 @@ # define XP_END_PROTOS #endif + #ifdef STANDALONE_REGISTRY -#define XP_ASSERT(x) ((void)0) + +#define XP_FILE_READ "r" +#define XP_FILE_READ_BIN "rb" +#define XP_FILE_WRITE "w" +#define XP_FILE_WRITE_BIN "wb" +#define XP_FILE_UPDATE "r+" +#define XP_FILE_TRUNCATE "w+" +#ifdef SUNOS4 +/* XXX SunOS4 hack -- make this universal by using r+b and w+b */ +#define XP_FILE_UPDATE_BIN "r+" +#define XP_FILE_TRUNCATE_BIN "w+" #else -#define XP_ASSERT(x) PR_ASSERT((x)) +#define XP_FILE_UPDATE_BIN "rb+" +#define XP_FILE_TRUNCATE_BIN "wb+" #endif +#define XP_FileSeek(file,offset,whence) fseek((file), (offset), (whence)) +#define XP_FileRead(dest,count,file) fread((dest), 1, (count), (file)) +#define XP_FileWrite(src,count,file) fwrite((src), 1, (count), (file)) +#define XP_FileTell(file) ftell(file) +#define XP_FileFlush(file) fflush(file) +#define XP_FileClose(file) fclose(file) + +#define XP_ASSERT(x) ((void)0) + #define XP_STRCAT(a,b) strcat((a),(b)) #define XP_ATOI atoi #define XP_STRCPY(a,b) strcpy((a),(b)) @@ -101,7 +111,7 @@ #define XP_STRNCMP(x,y,n) strncmp((x),(y),(n)) #define XP_STRDUP(s) strdup((s)) #define XP_MEMCPY(d, s, l) memcpy((d), (s), (l)) -#define XP_MEMSET(d, c, l) memset((d), (c), (l)) +#define XP_MEMSET(d, c, l) memset((d), (c), (l)) #ifdef XP_PC #define XP_STRCASECMP(x,y) stricmp((x),(y)) @@ -109,10 +119,66 @@ #else #define XP_STRCASECMP(x,y) strcasecmp((x),(y)) #define XP_STRNCASECMP(x,y,n) strncasecmp((x),(y),(n)) -#endif +#endif /*XP_PC*/ typedef FILE * XP_File; +#else /* if not standalone, use NSPR */ + +#define XP_FILE_READ PR_RDONLY, 0700 +#define XP_FILE_READ_BIN PR_RDONLY, 0700 +#define XP_FILE_WRITE PR_WRONLY, 0700 +#define XP_FILE_WRITE_BIN PR_WRONLY, 0700 +#define XP_FILE_UPDATE PR_RDWR +#define XP_FILE_TRUNCATE (PR_WRONLY | PR_TRUNCATE), 0700 + +#define XP_FILE_UPDATE_BIN PR_RDWR, 0700 +#define XP_FILE_TRUNCATE_BIN (PR_RDWR | PR_TRUNCATE), 0700 + +#ifdef SEEK_SET + #undef SEEK_SET + #undef SEEK_CUR + #undef SEEK_END + #define SEEK_SET PR_SEEK_SET + #define SEEK_CUR PR_SEEK_CUR + #define SEEK_END PR_SEEK_END +#endif +/* +** Note that PR_Seek returns the offset (if successful) and -1 otherwise. So +** to make this code work +** if (XP_FileSeek(fh, offset, SEEK_SET) != 0) { error handling } +** we return 1 if PR_Seek() returns a negative value, and 0 otherwise +*/ +#define XP_FileSeek(file,offset,whence) (PR_Seek((file), (offset), (whence)) < 0) +#define XP_FileRead(dest,count,file) PR_Read((file), (dest), (count)) +#define XP_FileWrite(src,count,file) PR_Write((file), (src), (count)) +#define XP_FileTell(file) PR_Seek(file, 0, PR_SEEK_CUR) +#define XP_FileFlush(file) PR_Sync(file) +#define XP_FileClose(file) PR_Close(file) + +#define XP_ASSERT(x) PR_ASSERT((x)) + +#define XP_STRCAT(a,b) PL_strcat((a),(b)) +#define XP_ATOI PL_atoi +#define XP_STRCPY(a,b) PL_strcpy((a),(b)) +#define XP_STRLEN(x) PL_strlen(x) +#define XP_SPRINTF sprintf +#define XP_FREE(x) PR_Free((x)) +#define XP_ALLOC(x) PR_Malloc((x)) +#define XP_FREEIF(x) PR_FREEIF(x) +#define XP_STRCMP(x,y) PL_strcmp((x),(y)) +#define XP_STRNCMP(x,y,n) PL_strncmp((x),(y),(n)) +#define XP_STRDUP(s) PL_strdup((s)) +#define XP_MEMCPY(d, s, l) memcpy((d), (s), (l)) +#define XP_MEMSET(d, c, l) memset((d), (c), (l)) + +#define XP_STRCASECMP(x,y) PL_strcasecmp((x),(y)) +#define XP_STRNCASECMP(x,y,n) PL_strncasecmp((x),(y),(n)) + +typedef PRFileDesc* XP_File; + +#endif /*STANDALONE_REGISTRY*/ + #ifdef STANDALONE_REGISTRY /* included from prmon.h otherwise */ #include "prtypes.h" @@ -141,9 +207,9 @@ typedef unsigned char uint8; typedef char Bool; typedef char XP_Bool; -#endif -#endif -#endif +#endif /* XP_MAC */ +#endif /* 0 */ +#endif /*STANDALONE_REGISTRY*/ #ifdef XP_PC typedef struct _stat XP_StatStruct; @@ -151,26 +217,37 @@ typedef unsigned char uint8; #else typedef struct stat XP_StatStruct; #define XP_Stat(file,data,type) stat((file),(data)) -#endif - -#ifndef XP_MAC - #define nr_RenameFile(from, to) rename((from), (to)) -#endif - - - -XP_BEGIN_PROTOS -extern XP_File vr_fileOpen (const char *name, const char * mode); -extern void vr_findGlobalRegName (); - -#if !defined(XP_PC) && !(defined(__GLIBC__) && __GLIBC__ >= 2) -extern char * strdup (const char * s); -#endif +#endif /*XP_PC*/ #ifdef XP_MAC extern int nr_RenameFile(char *from, char *to); +#else + XP_BEGIN_PROTOS + #define nr_RenameFile(from, to) rename((from), (to)) + XP_END_PROTOS +#endif + +#ifdef STANDALONE_REGISTRY /* included from prmon.h otherwise */ + +XP_BEGIN_PROTOS +extern XP_File vr_fileOpen(const char *name, const char * mode); +extern void vr_findGlobalRegName(); + +#if !defined(XP_PC) && !(defined(__GLIBC__) && __GLIBC__ >= 2) +extern char * strdup(const char * s); #endif XP_END_PROTOS +#else + +#define vr_fileOpen PR_Open + +XP_BEGIN_PROTOS +extern void vr_findGlobalRegName(); +XP_END_PROTOS + +#endif /* STANDALONE_REGISTRY */ + + #endif /* _VR_STUBS_H_ */