From 9909c0cec3f15fa764f2ccb10ffc1ea0a3343b2b Mon Sep 17 00:00:00 2001 From: Eric Scharff Date: Mon, 26 Apr 2010 10:24:53 -0600 Subject: [PATCH] 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. --- src/posix.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/posix.cpp b/src/posix.cpp index 569f0b08f9..0d34e2828a 100644 --- a/src/posix.cpp +++ b/src/posix.cpp @@ -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(allocate(s, pathSize)); if (CFStringGetFileSystemRepresentation(path, buffer, pathSize)) {