From 140516cd5f213f5743bbd2d5ce42ca8b19ad1479 Mon Sep 17 00:00:00 2001 From: "dveditz%netscape.com" Date: Sun, 17 Oct 1999 21:47:53 +0000 Subject: [PATCH] Added NR_RegFlush (14909, required for 16283/16600); warning cleanup (15626) r=shaver --- modules/libreg/include/NSReg.h | 13 ++++++ modules/libreg/src/VerReg.c | 47 ++++++++-------------- modules/libreg/src/nr_bufio.c | 21 +++++----- modules/libreg/src/reg.c | 72 ++++++++++++++++++++++++++++++---- modules/libreg/src/vr_stubs.h | 5 +-- 5 files changed, 105 insertions(+), 53 deletions(-) diff --git a/modules/libreg/include/NSReg.h b/modules/libreg/include/NSReg.h index a66dd4a392dc..d8e10b16d134 100644 --- a/modules/libreg/include/NSReg.h +++ b/modules/libreg/include/NSReg.h @@ -160,6 +160,19 @@ VR_INTERFACE(REGERR) NR_RegClose( ); +/* --------------------------------------------------------------------- + * NR_RegFlush - Manually flush data in a netscape XP registry + * + * Parameters: + * hReg - handle of open registry to be flushed. + * + * --------------------------------------------------------------------- + */ +VR_INTERFACE(REGERR) NR_RegFlush( + HREG hReg /* handle of open registry to flush */ + ); + + /* --------------------------------------------------------------------- * NR_RegIsWritable - Check read/write status of open registry * diff --git a/modules/libreg/src/VerReg.c b/modules/libreg/src/VerReg.c index 7a6c0e98b5bd..26f1b79f3088 100644 --- a/modules/libreg/src/VerReg.c +++ b/modules/libreg/src/VerReg.c @@ -1058,7 +1058,7 @@ VR_INTERFACE(REGERR) VR_SetRefCount(char *component_path, int refcount) { REGERR err; RKEY rootKey; - RKEY key; + RKEY key = 0; char rcstr[MAXREGNAMELEN]; err = vr_Init(); @@ -1312,7 +1312,7 @@ static REGERR vr_unmanglePackageName(char *mangledPackageName, char *regPackageN VR_INTERFACE(REGERR) VR_UninstallCreateNode(char *regPackageName, char *userPackageName) { REGERR err; - RKEY key; + RKEY key = 0; char *regbuf; uint32 regbuflen = 0; @@ -1345,7 +1345,7 @@ VR_INTERFACE(REGERR) VR_UninstallCreateNode(char *regPackageName, char *userPack } if (err == REGERR_OK) - err = NR_RegSetEntryString( vreg, key, PACKAGENAMESTR, userPackageName ); + err = NR_RegSetEntryString(vreg, key, PACKAGENAMESTR, userPackageName); return err; @@ -1354,7 +1354,7 @@ VR_INTERFACE(REGERR) VR_UninstallCreateNode(char *regPackageName, char *userPack VR_INTERFACE(REGERR) VR_GetUninstallUserName(char *regPackageName, char *outbuf, uint32 buflen) { REGERR err; - RKEY key; + RKEY key = 0; char *regbuf = NULL; char *convertedName = NULL; uint32 convertedDataLength = 0; @@ -1402,7 +1402,7 @@ VR_INTERFACE(REGERR) VR_GetUninstallUserName(char *regPackageName, char *outbuf, VR_INTERFACE(REGERR) VR_UninstallAddFileToList(char *regPackageName, char *vrName) { REGERR err; - RKEY key; + RKEY key = 0; char *regbuf; uint32 regbuflen = 0; uint32 curregbuflen = 0; @@ -1442,12 +1442,8 @@ VR_INTERFACE(REGERR) VR_UninstallAddFileToList(char *regPackageName, char *vrNam err = REGERR_MEMORY; } - if (err != REGERR_OK) - { - return err; - } - - err = NR_RegSetEntryString( vreg, key, vrName, ""); + if (err == REGERR_OK) + err = NR_RegSetEntryString( vreg, key, vrName, ""); return err; @@ -1456,7 +1452,7 @@ VR_INTERFACE(REGERR) VR_UninstallAddFileToList(char *regPackageName, char *vrNam VR_INTERFACE(REGERR) VR_UninstallFileExistsInList(char *regPackageName, char *vrName) { REGERR err; - RKEY key; + RKEY key = 0; char *regbuf; char sharedfilesstr[MAXREGNAMELEN]; uint32 regbuflen = 0; @@ -1497,12 +1493,8 @@ VR_INTERFACE(REGERR) VR_UninstallFileExistsInList(char *regPackageName, char *vr err = REGERR_MEMORY; } - if (err != REGERR_OK) - { - return err; - } - - err = NR_RegGetEntryString( vreg, key, vrName, sharedfilesstr, + if (err == REGERR_OK) + err = NR_RegGetEntryString( vreg, key, vrName, sharedfilesstr, sizeof(sharedfilesstr) ); return err; @@ -1512,7 +1504,7 @@ VR_INTERFACE(REGERR) VR_UninstallEnumSharedFiles(char *component_path, REGENUM * char *buffer, uint32 buflen) { REGERR err; - RKEY key; + RKEY key = 0; char *regbuf; char *converted_component_path; uint32 convertedDataLength = 0; @@ -1566,10 +1558,8 @@ VR_INTERFACE(REGERR) VR_UninstallEnumSharedFiles(char *component_path, REGENUM * XP_FREE(converted_component_path); - if (err != REGERR_OK) - return err; - - err = NR_RegEnumEntries( vreg, key, state, buffer, buflen, NULL); + if (err == REGERR_OK) + err = NR_RegEnumEntries( vreg, key, state, buffer, buflen, NULL); return err; @@ -1578,7 +1568,7 @@ VR_INTERFACE(REGERR) VR_UninstallEnumSharedFiles(char *component_path, REGENUM * VR_INTERFACE(REGERR) VR_UninstallDeleteFileFromList(char *component_path, char *vrName) { REGERR err; - RKEY key; + RKEY key = 0; char *regbuf; char *converted_component_path; uint32 convertedDataLength = 0; @@ -1635,12 +1625,9 @@ VR_INTERFACE(REGERR) VR_UninstallDeleteFileFromList(char *component_path, char * XP_FREE(converted_component_path); - if (err != REGERR_OK) - { - return err; - } - - err = NR_RegDeleteEntry( vreg, key, vrName); + if (err == REGERR_OK) + err = NR_RegDeleteEntry( vreg, key, vrName); + return err; } /* UninstallDeleteFileFromList */ diff --git a/modules/libreg/src/nr_bufio.c b/modules/libreg/src/nr_bufio.c index da16aca0c423..425749900ff2 100644 --- a/modules/libreg/src/nr_bufio.c +++ b/modules/libreg/src/nr_bufio.c @@ -83,7 +83,7 @@ struct BufioFileStruct PRInt32 dirtystart; PRInt32 dirtyend; PRBool readOnly; /* whether the file allows writing or not */ -#ifdef DEBUG_dveditz +#ifdef DEBUG_dveditzbuf PRUint32 reads; PRUint32 writes; #endif @@ -103,7 +103,6 @@ BufioFile* bufio_Open(const char* name, const char* mode) { FILE *fd; BufioFile *file = NULL; - PRBool cleanup = PR_FALSE; fd = fopen( name, mode ); @@ -284,7 +283,7 @@ PRUint32 bufio_Read(BufioFile* file, char* dest, PRUint32 count) memcpy( dest, file->data + startOffset, bytesCopied ); retcount = bytesCopied; file->fpos += bytesCopied; -#ifdef DEBUG_dveditz +#ifdef DEBUG_dveditzbuf file->reads++; #endif @@ -318,7 +317,7 @@ PRUint32 bufio_Read(BufioFile* file, char* dest, PRUint32 count) memcpy( dest+bytesCopied, file->data+startOffset, bytesRead ); file->fpos += bytesRead; retcount += bytesRead; -#ifdef DEBUG_dveditz +#ifdef DEBUG_dveditzbuf file->reads++; #endif } @@ -357,7 +356,7 @@ PRUint32 bufio_Read(BufioFile* file, char* dest, PRUint32 count) /* the tail end of the range we want is already buffered */ /* first copy the buffered data to the dest area */ memcpy( dest+leftover, file->data, bytesCopied ); -#ifdef DEBUG_dveditz +#ifdef DEBUG_dveditzbuf file->reads++; #endif } @@ -380,7 +379,7 @@ PRUint32 bufio_Read(BufioFile* file, char* dest, PRUint32 count) if ( bytesRead ) { memcpy( dest, file->data+startOffset, bytesRead ); -#ifdef DEBUG_dveditz +#ifdef DEBUG_dveditzbuf file->reads++; #endif } @@ -445,7 +444,7 @@ PRUint32 bufio_Write(BufioFile* file, const char* src, PRUint32 count) endOffset = startOffset + bytesCopied; file->dirtystart = PR_MIN( startOffset, file->dirtystart ); file->dirtyend = PR_MAX( endOffset, file->dirtyend ); -#ifdef DEBUG_dveditz +#ifdef DEBUG_dveditzbuf file->writes++; #endif @@ -477,7 +476,7 @@ PRUint32 bufio_Write(BufioFile* file, const char* src, PRUint32 count) file->bufdirty = PR_TRUE; file->dirtystart = 0; file->dirtyend = PR_MAX( endOffset, file->dirtyend ); -#ifdef DEBUG_dveditz +#ifdef DEBUG_dveditzbuf file->writes++; #endif @@ -499,7 +498,7 @@ PRUint32 bufio_Write(BufioFile* file, const char* src, PRUint32 count) file->bufdirty = PR_TRUE; file->dirtystart = startOffset; file->dirtyend = endOffset; -#ifdef DEBUG_dveditz +#ifdef DEBUG_dveditzbuf file->writes++; #endif if ( endOffset > file->datasize ) @@ -596,7 +595,7 @@ static PRBool _bufio_loadBuf( BufioFile* file, PRUint32 count ) file->bufdirty = PR_FALSE; file->dirtystart = BUFIO_BUFSIZE; file->dirtyend = 0; -#ifdef DEBUG_dveditz +#ifdef DEBUG_dveditzbuf printf("REG: buffer read %d (%d) after %d reads\n",startBuf,file->fpos,file->reads); file->reads = 0; file->writes = 0; @@ -624,7 +623,7 @@ static int _bufio_flushBuf( BufioFile* file ) written = fwrite( file->data+file->dirtystart, 1, dirtyamt, file->fd ); if ( written == dirtyamt ) { -#ifdef DEBUG_dveditz +#ifdef DEBUG_dveditzbuf printf("REG: buffer flush %d - %d after %d writes\n",startpos,startpos+written,file->writes); file->writes = 0; #endif diff --git a/modules/libreg/src/reg.c b/modules/libreg/src/reg.c index 709e83fea34e..928f3d458d49 100644 --- a/modules/libreg/src/reg.c +++ b/modules/libreg/src/reg.c @@ -78,7 +78,7 @@ #define MAX_PATH 1024 #endif #elif defined(WIN32) -#include /* for MAX_PATH */ +#define MAX_PATH _MAX_PATH #elif defined(XP_MAC) #define MAX_PATH 512 #elif defined(XP_BEOS) @@ -2119,6 +2119,11 @@ static REGERR nr_RegClose( HREG hReg ) { XP_ASSERT( VALID_FILEHANDLE(reg->fh) ); + /* save changed header info */ + if ( reg->hdrDirty ) { + nr_WriteHdr( reg ); + } + /* lower REGFILE user count */ reg->refCount--; @@ -2126,14 +2131,16 @@ static REGERR nr_RegClose( HREG hReg ) if ( reg->refCount < 1 ) { /* ...then close the file */ - if ( reg->hdrDirty ) { - nr_WriteHdr( reg ); - } nr_CloseFile( &(reg->fh) ); /* ...and mark REGFILE node for deletion from list */ needDelete = TRUE; } + else + { + /* ...otherwise make sure any writes are flushed */ + XP_FileFlush( reg->fh ); + } reghnd->magic = 0; /* prevent accidental re-use */ PR_Unlock( reg->lock ); @@ -2306,6 +2313,51 @@ VR_INTERFACE(REGERR) NR_RegClose( HREG hReg ) + +/* --------------------------------------------------------------------- + * NR_RegFlush - Manually flush data in a netscape XP registry + * + * Parameters: + * hReg - handle of open registry to be flushed. + * --------------------------------------------------------------------- + */ +VR_INTERFACE(REGERR) NR_RegFlush( HREG hReg ) +{ + REGERR err; + REGFILE* reg; + + /* verify parameters */ + err = VERIFY_HREG( hReg ); + if ( err != REGERR_OK ) + return err; + + reg = ((REGHANDLE*)hReg)->pReg; + + /* can't flush a read-only registry */ + if ( reg->readOnly ) + return REGERR_READONLY; + + /* lock the registry file */ + err = nr_Lock( reg ); + if ( err == REGERR_OK ) + { + if ( reg->hdrDirty ) { + nr_WriteHdr( reg ); + } + + XP_FileFlush( reg->fh ); + + /* unlock the registry */ + nr_Unlock( reg ); + } + + return err; + +} /* NR_RegFlush */ + + + + /* --------------------------------------------------------------------- * NR_RegIsWritable - Check read/write status of open registry * @@ -3238,6 +3290,9 @@ VR_INTERFACE(REGERR) NR_RegEnumSubkeys( HREG hReg, RKEY key, REGENUM *state, if ( err != REGERR_OK ) return err; + desc.down = 0; /* initialize to quiet warnings */ + desc.location = 0; + /* verify starting key */ key = nr_TranslateKey( reg, key ); if ( key == 0 ) @@ -3521,6 +3576,7 @@ VR_INTERFACE(REGERR) NR_RegEnumEntries( HREG hReg, RKEY key, REGENUM *state, #ifndef STANDALONE_REGISTRY #include "VerReg.h" +#ifdef RESURRECT_LATER static REGERR nr_createTempRegName( char *filename, uint32 filesize ); static REGERR nr_addNodesToNewReg( HREG hReg, RKEY rootkey, HREG hRegNew, void *userData, nr_RegPackCallbackFunc fn ); /* -------------------------------------------------------------------- */ @@ -3528,7 +3584,7 @@ static REGERR nr_createTempRegName( char *filename, uint32 filesize ) { struct stat statbuf; XP_Bool nameFound = FALSE; - char tmpname[MAX_PATH]; + char tmpname[MAX_PATH+1]; uint32 len; int err; @@ -3634,8 +3690,8 @@ static REGERR nr_addNodesToNewReg( HREG hReg, RKEY rootkey, HREG hRegNew, void * XP_FREEIF(buffer); return err; - } +#endif /* RESURRECT_LATER */ @@ -3654,8 +3710,8 @@ VR_INTERFACE(REGERR) NR_RegPack( HREG hReg, void *userData, nr_RegPackCallbackFu XP_File fh; REGFILE* reg; HREG hRegTemp; - char tempfilename[MAX_PATH] = {0}; - char oldfilename[MAX_PATH] = {0}; + char tempfilename[MAX_PATH+1] = {0}; + char oldfilename[MAX_PATH+1] = {0}; XP_Bool bCloseTempFile = FALSE; diff --git a/modules/libreg/src/vr_stubs.h b/modules/libreg/src/vr_stubs.h index 5372f25376c2..70e1bafc9e05 100644 --- a/modules/libreg/src/vr_stubs.h +++ b/modules/libreg/src/vr_stubs.h @@ -158,7 +158,7 @@ typedef MmioFile* XP_File; #define XP_FileTell(file) bufio_Tell(file) #define XP_FileClose(file) bufio_Close(file) #define XP_FileOpen(path, mode) bufio_Open((path), (mode)) -#define XP_FileFlush(file) ((void)1) +#define XP_FileFlush(file) bufio_Flush(file) @@ -181,10 +181,7 @@ typedef BufioFile* XP_File; #define XP_FileTell(file) PR_Seek(file, 0, PR_SEEK_CUR) #define XP_FileOpen(path, mode) PR_Open((path), mode ) #define XP_FileClose(file) PR_Close(file) -#ifdef XP_MAC #define XP_FileFlush(file) PR_Sync(file) -#else -#define XP_FileFlush(file) ((void)1) #endif typedef PRFileDesc* XP_File;