Fix Mac OS X specific path bug

In Mac OS X, if a path contains a space, the path of the main executable
will contain a special URL-encoded character (%20 in this case).  This
probably happens when any non-ASCII character is provided.

The fix is to use CFURLCreateStringByReplacingPercentEscapes which
creates a path that the POSIX API likes better.
This commit is contained in:
Eric Scharff 2010-04-26 10:24:53 -06:00
parent 3e5b2cbc7b
commit 9909c0cec3

View File

@ -93,6 +93,8 @@ pathOfExecutable(System* s, const char** retBuf, unsigned* size)
CFBundleRef bundle = CFBundleGetMainBundle();
CFURLRef url = CFBundleCopyExecutableURL(bundle);
CFStringRef path = CFURLCopyPath(url);
path = CFURLCreateStringByReplacingPercentEscapes(kCFAllocatorDefault,
path, CFSTR(""));
CFIndex pathSize = CFStringGetMaximumSizeOfFileSystemRepresentation(path);
char* buffer = reinterpret_cast<char*>(allocate(s, pathSize));
if (CFStringGetFileSystemRepresentation(path, buffer, pathSize)) {