Bug 200662 - [OSX]GetCurrentProcessDirectory can fail. r=/sr=sfraser.

This commit is contained in:
ccarlen@netscape.com
2003-04-07 14:29:56 +00:00
parent de08c0b441
commit 3aa6edc49b

View File

@@ -208,20 +208,18 @@ nsDirectoryService::GetCurrentProcessDirectory(nsILocalFile** aFile)
CFURLRef parentURL = CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault, bundleURL); CFURLRef parentURL = CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault, bundleURL);
if (parentURL) if (parentURL)
{ {
CFStringRef path = CFURLCopyFileSystemPath(parentURL, kCFURLPOSIXPathStyle); // Pass PR_TRUE for the "resolveAgainstBase" arg to CFURLGetFileSystemRepresentation.
if (path) // This will resolve the relative portion of the CFURL against it base, giving a full
// path, which CFURLCopyFileSystemPath doesn't do.
char buffer[PATH_MAX];
if (CFURLGetFileSystemRepresentation(parentURL, PR_TRUE, (UInt8 *)buffer, sizeof(buffer)))
{ {
char buffer[512];
if (CFStringGetCString(path, buffer, sizeof(buffer), kCFStringEncodingUTF8))
{
#ifdef DEBUG_conrad #ifdef DEBUG_conrad
printf("nsDirectoryService - CurrentProcessDir is: %s\n", buffer); printf("nsDirectoryService - CurrentProcessDir is: %s\n", buffer);
#endif #endif
rv = localFile->InitWithNativePath(nsDependentCString(buffer)); rv = localFile->InitWithNativePath(nsDependentCString(buffer));
if (NS_SUCCEEDED(rv)) if (NS_SUCCEEDED(rv))
*aFile = localFile; *aFile = localFile;
}
CFRelease(path);
} }
CFRelease(parentURL); CFRelease(parentURL);
} }