clean up Mac OS X macros in libreg's reg.c. r=cbarrett sr=luser
authorjoshmoz@gmail.com
Sat, 23 Jun 2007 18:07:21 -0700
changeset 2718 cd63835452bfcee6620df88aa706aec22a6ca118
parent 2717 11c7e3d4a4c21294c797480e99adc654198ab0de
child 2719 6597df7cf733bc0472e5dfaccc72f533d1c8ab00
push idunknown
push userunknown
push dateunknown
reviewerscbarrett, luser
milestone1.9a6pre
clean up Mac OS X macros in libreg's reg.c. r=cbarrett sr=luser
modules/libreg/src/reg.c
--- a/modules/libreg/src/reg.c
+++ b/modules/libreg/src/reg.c
@@ -60,44 +60,39 @@
 #define SELF_REPAIR     1
 #ifdef DEBUG
 #define VERIFY_READ     1
 #endif
 
 #include <stdio.h>
 #include <string.h>
 
+#ifdef XP_MACOSX
+#include <Carbon/Carbon.h>
+#endif
+
 #ifdef STANDALONE_REGISTRY
 #include <stdlib.h>
 #include <assert.h>
 #include <errno.h>
-
-#if defined(XP_MAC) || defined(XP_MACOSX)
-  #include <Errors.h>
-#endif
-
 #else
-
 #include "prtypes.h"
 #include "prlog.h"
 #include "prerror.h"
 #include "prprf.h"
-
 #endif /*STANDALONE_REGISTRY*/
 
 #if defined(SUNOS4)
 #include <unistd.h>  /* for SEEK_SET */
 #endif /* SUNOS4 */
 
 #include "reg.h"
 #include "NSReg.h"
 
-#if defined(XP_MAC)
-#define MAX_PATH 512
-#elif defined(XP_MACOSX)
+#if defined(XP_MACOSX)
 #define MAX_PATH PATH_MAX
 #elif defined(XP_UNIX)
 #ifndef MAX_PATH
 #define MAX_PATH 1024
 #endif
 #elif defined(XP_OS2)
 #ifndef MAX_PATH
 #define MAX_PATH 260
@@ -154,42 +149,32 @@ static PRLock   *reglist_lock = NULL;
 static REGFILE  *RegList = NULL;
 static int32    regStartCount = 0;
 char            *globalRegName = NULL;
 static char     *user_name = NULL;
 
 
 
 
-#if defined(XP_MAC) || defined(XP_MACOSX)
+#ifdef XP_MACOSX
 
 void nr_MacAliasFromPath(const char * fileName, void ** alias, int32 * length);
 char * nr_PathFromMacAlias(const void * alias, uint32 aliasLength);
 
-#include <Aliases.h>
-#include <TextUtils.h>
-#include <Memory.h>
-#include <Folders.h>
-
-#ifdef XP_MACOSX
-  #include "MoreFilesX.h"
-#else
-  #include "FullPath.h"
-#endif
+#include "MoreFilesX.h"
 
 static void copyCStringToPascal(Str255 dest, const char *src)
 {
     size_t copyLen = strlen(src);
     if (copyLen > 255)
         copyLen = 255;
     BlockMoveData(src, &dest[1], copyLen);
     dest[0] = copyLen;
 }
 
-#ifdef XP_MACOSX
 static OSErr isFileInTrash(FSRef *fsRef, PRBool *inTrash)
 {
     OSErr err;
     FSCatalogInfo catalogInfo;
 
     if (fsRef == NULL || inTrash == NULL)
         return paramErr;
     *inTrash = PR_FALSE;
@@ -211,62 +196,34 @@ static OSErr isFileInTrash(FSRef *fsRef,
                     *inTrash = PR_TRUE;
                     break;
                 }
             }
         }
     }
     return err;
 }
-#else
-static OSErr isFileInTrash(FSSpec *fileSpec, PRBool *inTrash)
-{
-    OSErr err;
-    short vRefNum;
-    long dirID;
-    
-    if (fileSpec == NULL || inTrash == NULL)
-        return paramErr;
-    *inTrash = PR_FALSE;
-    
-    /* XXX - Only works if the file is in the top level of the trash dir */
-    err = FindFolder(fileSpec->vRefNum, kTrashFolderType, false, &vRefNum, &dirID);
-    if (err == noErr)
-        if (dirID == fileSpec->parID)  /* File is inside the trash */
-            *inTrash = PR_TRUE;
-    
-    return err;
-}
-#endif
 
 /* returns an alias as a malloc'd pointer.
  * On failure, *alias is NULL
  */
 void nr_MacAliasFromPath(const char * fileName, void ** alias, int32 * length)
 {
     OSErr err;
     Str255 pascalName;
     FSRef fsRef;
     FSSpec fs;
     AliasHandle macAlias;
     *alias = NULL;
     *length = 0;
     
-#ifdef XP_MACOSX
     err = FSPathMakeRef((const UInt8*)fileName, &fsRef, NULL);
     if ( err != noErr )
         return;
     err = FSNewAlias(NULL, &fsRef, &macAlias);
-#else
-    copyCStringToPascal(pascalName, fileName);
-    err = FSMakeFSSpec(0, 0, pascalName, &fs);
-    if ( err != noErr )
-        return;
-    err = NewAlias(NULL, &fs, &macAlias);
-#endif
     
     if ( (err != noErr) || ( macAlias == NULL ))
         return;
     *length = GetHandleSize( (Handle) macAlias );
     *alias = XP_ALLOC( *length );
     if ( *alias == NULL )
     {
         DisposeHandle((Handle)macAlias);
@@ -306,58 +263,32 @@ char * nr_PathFromMacAlias(const void * 
     if ( h == NULL)
         goto fail;
         
         
     HLock( (Handle) h);
     XP_MEMCPY( *h, alias, aliasLength );
     HUnlock( (Handle) h);
     
-#ifdef XP_MACOSX
     err = FSResolveAlias(NULL, h, &fsRef, &wasChanged);
     if (err != noErr)
         goto fail;
 
     /* if the alias has changed and the file is now in the trash,
        assume that user has deleted it and that we do not want to look at it */
     if (wasChanged && (isFileInTrash(&fsRef, &inTrash) == noErr) && inTrash)
         goto fail;
     err = FSRefMakePath(&fsRef, pathBuf, sizeof(pathBuf));
     if (err != noErr)
         goto fail;
     fullPathLength = XP_STRLEN(pathBuf);
     cpath = (char*) XP_ALLOC(fullPathLength + 1);
     if ( cpath == NULL)
         goto fail;
     XP_MEMCPY(cpath, pathBuf, fullPathLength + 1);
-#else    
-    err = ResolveAlias(NULL, h, &fs, &wasChanged);
-    if (err != noErr)
-        goto fail;
-    
-    /* if the alias has changed and the file is now in the trash,
-       assume that user has deleted it and that we do not want to look at it */
-    if (wasChanged && (isFileInTrash(&fs, &inTrash) == noErr) && inTrash)
-        goto fail;
-    
-    /* Get the full path and create a char * out of it */
-
-    err = GetFullPath(fs.vRefNum, fs.parID,fs.name, &fullPathLength, &fullPath);
-    if ( (err != noErr) || (fullPath == NULL) )
-        goto fail;
-    
-    cpath = (char*) XP_ALLOC(fullPathLength + 1);
-    if ( cpath == NULL)
-        goto fail;
-    
-    HLock( fullPath );
-    XP_MEMCPY(cpath, *fullPath, fullPathLength);
-    cpath[fullPathLength] = 0;
-    HUnlock( fullPath );
-#endif    
     /* Drop through */
 fail:
     if (h != NULL)
         DisposeHandle( (Handle) h);
     if (fullPath != NULL)
         DisposeHandle( fullPath);
     return cpath;
 }
@@ -452,24 +383,24 @@ static REGERR nr_OpenFile(const char *pa
     XP_ASSERT( fh != NULL );
 
     /* Open the file for exclusive random read/write */
     (*fh) = vr_fileOpen(path, XP_FILE_UPDATE_BIN);
     if ( !VALID_FILEHANDLE(*fh) )
     {
         switch (errno)
         {
-#if defined(XP_MAC) || defined(XP_MACOSX)
+#ifdef XP_MACOSX
         case fnfErr:
 #else
         case ENOENT:    /* file not found */
 #endif
             return REGERR_NOFILE;
 
-#if defined(XP_MAC) || defined(XP_MACOSX)
+#ifdef XP_MACOSX
         case opWrErr:
 #else
         case EROFS:     /* read-only file system */
         case EACCES:    /* file in use or read-only file*/
 #endif
             /* try read only */
             (*fh) = vr_fileOpen(path, XP_FILE_READ_BIN);
             if ( VALID_FILEHANDLE(*fh) )
@@ -559,17 +490,17 @@ static REGERR nr_ReadFile(FILEHANDLE fh,
 
     if (XP_FileSeek(fh, offset, SEEK_SET) != 0 ) {
         err = REGERR_FAIL;
     }
     else {
         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) && !defined(XP_MACOSX))
+#if !defined(STANDALONE_REGISTRY) || (!defined(XP_MACOSX))
     #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
@@ -3142,17 +3073,17 @@ VR_INTERFACE(REGERR) NR_RegGetEntry( HRE
                     err = nr_ReadData( reg, &desc, *size, tmpbuf );
                     /* prevent run-away strings */
                     tmpbuf[(*size)-1] = '\0';
                     break;
 
                 case REGTYPE_ENTRY_FILE:
 
                     err = nr_ReadData( reg, &desc, *size, (char*)buffer );
-#if defined(XP_MAC) || defined(XP_MACOSX)
+#ifdef XP_MACOSX
                     if (err == 0)
                     {
                         tmpbuf = nr_PathFromMacAlias(buffer, *size);
                         if (tmpbuf == NULL) 
                         {
                             buffer = NULL;
                             err = REGERR_NOFILE; /* must match nr_GetPathname() in VerReg.c */
                         }
@@ -3304,17 +3235,17 @@ VR_INTERFACE(REGERR) NR_RegSetEntry( HRE
     switch (type)
     {
         case REGTYPE_ENTRY_BYTES:
             data = (char*)buffer;
             break;
 
         case REGTYPE_ENTRY_FILE:
 
-#if defined(XP_MAC) || defined(XP_MACOSX)
+#ifdef XP_MACOSX
             nr_MacAliasFromPath(buffer, (void **)&data, &datalen);
             if (data)
                 needFree = TRUE;
 #else
             data = (char*)buffer;   
 #endif
             break;
 
@@ -4033,21 +3964,16 @@ safe_exit:
         NR_RegClose(hRegTemp);
     }
     PR_Unlock( reglist_lock );
     nr_Unlock(reg);
     return err;
 #endif /* RESURRECT_LATER */
 }
 
-
-#ifdef XP_MAC
-#pragma export reset
-#endif
-
 #endif /* STANDALONE_REGISTRY */
 
 
 
 
 
 
 /* ---------------------------------------------------------------------
@@ -4064,20 +3990,16 @@ extern PRLock *vr_lock;
 #endif 
 
 
 
 #if defined(XP_UNIX) && !defined(XP_MACOSX) && !defined(STANDALONE_REGISTRY)
 extern XP_Bool bGlobalRegistry;
 #endif
 
-#ifdef XP_MAC
-#pragma export on
-#endif
-
 VR_INTERFACE(REGERR) NR_StartupRegistry(void)
 {
     REGERR status = REGERR_OK;
 
 #ifndef STANDALONE_REGISTRY
     if ( reglist_lock == NULL ) {
         reglist_lock = PR_NewLock();
     }
@@ -4167,13 +4089,9 @@ VR_INTERFACE(void) NR_ShutdownRegistry(v
 
         PR_DestroyLock(vr_lock);
         vr_lock = NULL;
     }
 #endif
 
 }   /* NR_ShutdownRegistry */
 
-#ifdef XP_MAC
-#pragma export reset
-#endif
-
 /* EOF: reg.c */