jberry      2004/01/25 15:30:07

  Modified:    c/src/xercesc/util/Platforms/MacOS MacOSPlatformUtils.cpp
  Log:
  Fix Bug #26419 reported by Pedro Custodio: Mac OS partial paths were being resolved 
using the Carbon file manager's concept of current directory, which defaults to the 
location of the executable; we now use getcwd where possible in order to pick up the 
cwd from any invoking shell.
  
  Revision  Changes    Path
  1.23      +53 -20    
xml-xerces/c/src/xercesc/util/Platforms/MacOS/MacOSPlatformUtils.cpp
  
  Index: MacOSPlatformUtils.cpp
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/c/src/xercesc/util/Platforms/MacOS/MacOSPlatformUtils.cpp,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- MacOSPlatformUtils.cpp    24 Dec 2003 15:24:14 -0000      1.22
  +++ MacOSPlatformUtils.cpp    25 Jan 2004 23:30:07 -0000      1.23
  @@ -169,8 +169,12 @@
   //
   // gUsePosixFiles
   //   True if we're using XMLMacPosixFile rather than XMLMacCarbonFile.
  +//
  +// gUseGETCWD
  +//   True if we can rely on getcwd to get the current directory path.
   //----------------------------------------------------------------------------
   bool gFileSystemCompatible   = false;
  +bool gMacOSXOrBetter         = false;
   bool gHasFSSpecAPIs                  = false;
   bool gHasFS2TBAPIs                   = false;
   bool gHasHFSPlusAPIs         = false;
  @@ -178,6 +182,7 @@
   bool gPathAPIsUsePosixPaths  = false;
   bool gHasMPAPIs                              = false;
   bool gUsePosixFiles                  = false;
  +bool gUseGETCWD                              = false;
   
   
   // ---------------------------------------------------------------------------
  @@ -352,8 +357,13 @@
   {
        //      Get a newly allocated path to the current directory
        FSSpec spec;
  +
  +     //  Parse to path to determine current directory: this allows the
  +     //  path parsing routines to determine best way to find the current
  +     //  directory.
  +     XMLCh curDirPath[] = { '.', 0 };
        XMLCh* path =
  -             (noErr == FSMakeFSSpec(0, 0, NULL, &spec))
  +             (XMLParsePathToFSSpec(curDirPath, spec, manager))
                        ? XMLCreateFullPathFromFSSpec(spec, manager)
                        : NULL;
                        
  @@ -525,6 +535,11 @@
   
        //      Detect available functions
        
  +     //  Check whether we're on OS X
  +     gMacOSXOrBetter                 = noErr == Gestalt(gestaltSystemVersion, 
&value)
  +                                                       && value >= 0x00001000
  +                                                       ;
  +     
       //       Look for file system services
       if (noErr == Gestalt(gestaltFSAttr, &value))
       {
  @@ -551,9 +566,15 @@
        #if __MSL__ && (__MSL__ < 0x08000 || _MSL_CARBON_FILE_APIS)
        gUsePosixFiles                  = false;
        #else
  -     gUsePosixFiles                  = noErr == Gestalt(gestaltSystemVersion, 
&value)
  -                                                       && value >= 0x00001000
  -                                                       ;
  +     gUsePosixFiles                  = gMacOSXOrBetter;
  +     #endif
  +     
  +     //  Determine whether to use getcwd or not. We use it only if we're not using 
MSL,
  +     //  and we're on a Mac OS X system.
  +     #if __MSL__
  +     gUseGETCWD                              = false;
  +     #else
  +     gUseGETCWD                              = gMacOSXOrBetter;
        #endif
   
       //       Look for MP
  @@ -808,25 +829,37 @@
        {
                //      Right justify the user path to make room for the pre-pended 
path
                std::memmove(p + kMaxMacStaticPathChars - pathLen, p, pathLen);
  +             *p = '\0';
                                
                //      Get the current directory
  -        FSSpec spec;
  -             if (err == noErr)
  -                     err = FSMakeFSSpec(0, 0, NULL, &spec);
  -        if (err == noErr)
  -            err = FSpMakeFSRef(&spec, &ref);
  -             
  -             //      Get pathname to the current directory
  -             if (err == noErr)
  -                     err = FSRefMakePath(&ref, reinterpret_cast<UInt8*>(p), 
kMaxMacStaticPathChars - pathLen - 1);   // leave room for one '/'
  -             std::size_t prefixLen = std::strlen(p);
  -                     
  -             //      Now munge the two paths back together
  -             if (err == noErr)
  +             if (gUseGETCWD)
                {
  -                     p[prefixLen++] = '/';
  -                     std::memmove(p + prefixLen, p + kMaxMacStaticPathChars - 
pathLen, pathLen);
  +                     //      Get current directory path, leaving room for one '/' 
after
  +                     if (err == noErr)
  +                             getcwd(p, kMaxMacStaticPathChars - pathLen - 1);
                }
  +             else
  +             {
  +                     //      Get current directory path, leaving room for one '/' 
after
  +
  +                     //      We quiz the carbon file manager for the current 
directory.
  +                     //      Note that carbon defaults its concept of the current 
directory
  +                     //  to the location of the executable.
  +             FSSpec spec;
  +                     if (err == noErr)
  +                             err = FSMakeFSSpec(0, 0, NULL, &spec);
  +             if (err == noErr)
  +                 err = FSpMakeFSRef(&spec, &ref);
  +                     
  +                     //      Get current directory path, leaving room for one '/' 
after
  +                     if (err == noErr)
  +                             err = FSRefMakePath(&ref, reinterpret_cast<UInt8*>(p), 
kMaxMacStaticPathChars - pathLen - 1);
  +             }
  +                                     
  +             //      Now munge the two paths back together
  +             std::size_t prefixLen = std::strlen(p);
  +             p[prefixLen++] = '/';
  +             std::memmove(p + prefixLen, p + kMaxMacStaticPathChars - pathLen, 
pathLen);
                
                //      We now have a path from an absolute starting point
        }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to