Back to index

lightning-sunbird  0.9+nobinonly
Functions
macio.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

PR_BEGIN_EXTERN_C OSErr ConvertUnixPathToMacPath (const char *, char **)
OSErr ConvertUnixPathToFSSpec (const char *unixPath, FSSpec *fileSpec)

Function Documentation

OSErr ConvertUnixPathToFSSpec ( const char *  unixPath,
FSSpec fileSpec 
)

Definition at line 1504 of file macio.c.

{
    char*                   macPath;
    OSErr                   convertError;
    int                             len;
    
    convertError = ConvertUnixPathToMacPath(unixPath, &macPath);
    if (convertError != noErr)
       return convertError;

    len = strlen(macPath);

    if (*macPath == PR_PATH_SEPARATOR)
    {
        if (len < sizeof(Str255))
        {
            short   vRefNum;
            long    dirID;
            Str255  pascalMacPath;
            
            convertError = HGetVol(NULL, &vRefNum, &dirID);
            if (convertError == noErr)
            {
                PStrFromCStr(macPath, pascalMacPath);
                convertError = FSMakeFSSpec(vRefNum, dirID, pascalMacPath, fileSpec);
            }
        }
        else
            convertError = paramErr;
    }
    else
    {
       convertError = FSpLocationFromFullPath(len, macPath, fileSpec);
           if (convertError == fnfErr)
           {
                     CInfoPBRec           pb;
                     Str255 pascalMacPath;
                     OSErr err;
                     
                     PStrFromCStr(macPath, pascalMacPath);
                     /* 
                     FSpLocationFromFullPath does not work for directories unless there is
                     a ":" at the end.  We will make sure of an existence of a directory.
                     If so, the returned fileSpec is valid from FSpLocationFromFullPath eventhough
                     it returned an error.
                     */
                     pb.hFileInfo.ioNamePtr = pascalMacPath;
                     pb.hFileInfo.ioVRefNum = 0;
                     pb.hFileInfo.ioDirID = 0;
                     pb.hFileInfo.ioFDirIndex = 0;
                     
                     err = PBGetCatInfoSync(&pb);
                     if (err == noErr)
                            convertError = noErr;
              }
    }
    
    free(macPath);
    
    return (convertError);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PR_BEGIN_EXTERN_C OSErr ConvertUnixPathToMacPath ( const char *  ,
char **   
)

Definition at line 1252 of file macio.c.

{      
              OSErr         err = noErr;
              
       //     ******** HACK ALERT ********
       //
       //     Java really wants long file names (>31 chars).  We truncate file names 
       //     greater than 31 characters long.  Truncation is from the middle.
       //
       //     Convert UNIX style path names (with . and / separators) into a Macintosh
       //     style path (with :).
       //
       // There are also a couple of special paths that need to be dealt with
       // by translating them to the appropriate Mac special folders.  These include:
       //
       //                   /usr/tmp/file  =>  {TempFolder}file
       //
       // The file conversions we need to do are as follows:
       //
       //                   file                 =>            file
       //                   dir/file             =>            :dir:file
       //                   ./file               =>            file
       //                   ../file                     =>            ::file
       //                   ../dir/file          =>            ::dir:file
       //                   /file                =>            ::BootDrive:file
       //                   /dir/file            =>            ::BootDrive:dir:file
       
       
       if (!strcmp(unixPath, "."))
       {
              *macPath = malloc(sizeof(":"));
              if (*macPath == NULL)
                     err = memFullErr;
              (*macPath)[0] = ':';
              (*macPath)[1] = '\0';
       }
       else
       
       if (*unixPath != PR_DIRECTORY_SEPARATOR) {                            // Not root relative, just convert it.
              err = CreateMacPathFromUnixPath(unixPath, macPath);
       }
       
       else {
              // Were root-relative.  This is either a special Unix directory, or a 
              // full path (which well support on the Mac since they might be generated).
              // This is not condoning the use of full-paths on the Macintosh for file 
              // specification.
              
              FSSpec        foundSpec;
              short         pathBufferSize;
#if DEBUG     
              char          *temp;
#endif
              int           tempLen;

              // Are we dealing with the temp folder?
              if ((strncmp(unixPath, "/usr/tmp", strlen("/usr/tmp")) == 0) || 
                     ((strncmp(unixPath, "/tmp", strlen("/tmp")) == 0))) {
                  CInfoPBRec pb;

                     unixPath = PL_strchr(unixPath, PR_DIRECTORY_SEPARATOR);
                     if (strncmp(unixPath, "/tmp", strlen("/tmp")) == 0) // skip past temp spec
                            unixPath += 5;       
                     else
                            unixPath += 9;       
                                                 
                     err = FindFolder(kOnSystemDisk, kTemporaryFolderType, kCreateFolder,  // Create if needed
                                                        &foundSpec.vRefNum, &foundSpec.parID);
                     if (err == noErr) {
                            pb.dirInfo.ioCompletion = NULL;
                            pb.dirInfo.ioNamePtr = foundSpec.name;
                            pb.dirInfo.ioVRefNum = foundSpec.vRefNum;
                            pb.dirInfo.ioFDirIndex = -1;
                            pb.dirInfo.ioDrDirID = foundSpec.parID;
                            
                            err = PBGetCatInfoSync(&pb);
                            foundSpec.parID = pb.dirInfo.ioDrParID;
                     }
              }
              
              else if (!strncmp(unixPath, "/usr/local/netscape/", (tempLen = strlen("/usr/local/netscape/")))) {
                     
                     unixPath += tempLen;
                     
                     if (!strncmp(unixPath, "RequiredGuts/", (tempLen = strlen("RequiredGuts/"))))
                     {
                            unixPath += tempLen;
                            err = FindGutsFolder(&foundSpec);
                     }
                     else if (!strncmp(unixPath, "bin/", (tempLen = strlen("bin/"))))
                     {
                            unixPath += tempLen;
                            err = FindNetscapeFolder(&foundSpec);
                     }                    
                     else if (*unixPath == '\0')
                     {
                            // it's /usr/local/netscape
                            err = FindGutsFolder(&foundSpec);
                     }

              }
              
              else {
                     // This is a root relative directory, well just convert the whole thing.
                     err = CreateMacPathFromUnixPath(unixPath, macPath);
                     goto Exit_ConvertUnixPathToMacPath;
              }
       

              
              // Were dealing with a special folder
              if (err == noErr)
              {
                     Handle hPathStr;
                     // Get the path to the root-relative directory
                     err = FSpGetFullPath(&foundSpec, &pathBufferSize, &hPathStr);         // NewHandle's hPathStr
                      
                     if (noErr == err)
                     {
                            // convert handle to c-string
                            // add one for NULL termination
                            // pathBufferSize is now one greater than the length of the string
                            pathBufferSize++;    
                            
                            *macPath = (char*) malloc(sizeof(char) * pathBufferSize);
                            (*macPath)[pathBufferSize - 1] = '\0';
                            BlockMoveData(*hPathStr, *macPath, pathBufferSize - 1);
                     
                            DisposeHandle(hPathStr);
                     }
              }
              
              if (err == noErr)
              {
                     UInt32 unixPathLeft;
                     UInt32 macPathLen;

                     unixPathLeft =  strlen(unixPath);
                     macPathLen = strlen(*macPath);
                     

                     // copy over the remaining file name, converting
                     if (pathBufferSize - 1 < macPathLen + unixPathLeft) 
                     {
                            // need to grow string
                            *macPath = realloc(*macPath, macPathLen + unixPathLeft + 1);
                            err = (*macPath == NULL ? memFullErr : noErr);
                     }
                     
                     if (err == noErr)
                     {
                            // carefully remove the '/''s out of the unix path.  If we see an "escaped" /
                            // we will leave it in there, otherwise we take it out and replace it with a :
                            // we have to do this before we convert to a mac-path, so we can tell what is
                            // really a path separator and what is in the name of a file or directory
                            // Make sure that all of the /s are :s in the final pathname
                            // effectively we do a
                            // strcat(*macPath, unixPath); while replace all occurrences of / with : in unixPath
                            char*         dp;
                            const char*   sp;
                            
                            sp = unixPath;
                            dp = *macPath + macPathLen;
                            
                            for (;*sp != '\0'; sp++, dp++) 
                            {
                                   if (*sp == PR_DIRECTORY_SEPARATOR)
                                   {
                                          // if we can look at the previous character
                                          if (sp > unixPath)                               
                                          {
                                                 // check to see if previous character is an escape
                                                 if (sp[-1] == '\\')
                                                 {
                                                        // leave it in, and cycle
                                                        continue;
                                                 }
                                                 else
                                                 {
                                                        *dp = PR_PATH_SEPARATOR;
                                                 }
                                          }
                                          else                        
                                                 *dp = PR_PATH_SEPARATOR;
                                   }
                                   else
                                   {
                                          // just copy;
                                          *dp = *sp;
                                   }
                            }
                            
                            *dp = '\0';   // NULL terminate *macPath
                     }
#if DEBUG     
                     // we used to check here, now we check above, we leave this in
                     // the debug build to make sure we didn't screw up
                     // Make sure that all of the /s are :s in the final pathname
                     for (temp = *macPath + strlen(*macPath) - strlen(unixPath); *temp != '\0'; temp++) {

                            if (*temp == PR_DIRECTORY_SEPARATOR)
                            {
                                   DebugStr("\pFound a slash");       
                                   *temp = PR_PATH_SEPARATOR;
                            }
                     }
#endif
              }
       }
       
       
Exit_ConvertUnixPathToMacPath:

       return err;
}

Here is the call graph for this function:

Here is the caller graph for this function: