Merge "Fix building on modern versions of Xcode and OS X."

This commit is contained in:
Elliott Hughes 2014-11-19 21:48:31 +00:00 committed by Gerrit Code Review
commit 20860a28c5
2 changed files with 16 additions and 15 deletions

View file

@ -19,12 +19,12 @@
void get_my_path(char *s, size_t maxLen) void get_my_path(char *s, size_t maxLen)
{ {
ProcessSerialNumber psn; CFBundleRef mainBundle = CFBundleGetMainBundle();
GetCurrentProcess(&psn); CFURLRef bundleURL = CFBundleCopyBundleURL(mainBundle);
CFDictionaryRef dict; CFStringRef bundlePathString = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle);
dict = ProcessInformationCopyDictionary(&psn, 0xffffffff); CFRelease(bundleURL);
CFStringRef value = (CFStringRef)CFDictionaryGetValue(dict,
CFSTR("CFBundleExecutable")); CFStringGetCString(bundlePathString, s, maxLen, kCFStringEncodingASCII);
CFStringGetCString(value, s, maxLen, kCFStringEncodingUTF8); CFRelease(bundlePathString);
} }

View file

@ -31,14 +31,15 @@
void get_my_path(char s[PATH_MAX]) void get_my_path(char s[PATH_MAX])
{ {
char *x; CFBundleRef mainBundle = CFBundleGetMainBundle();
ProcessSerialNumber psn; CFURLRef bundleURL = CFBundleCopyBundleURL(mainBundle);
GetCurrentProcess(&psn); CFStringRef bundlePathString = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle);
CFDictionaryRef dict; CFRelease(bundleURL);
dict = ProcessInformationCopyDictionary(&psn, 0xffffffff);
CFStringRef value = (CFStringRef)CFDictionaryGetValue(dict, CFStringGetCString(bundlePathString, s, PATH_MAX - 1, kCFStringEncodingASCII);
CFSTR("CFBundleExecutable")); CFRelease(bundlePathString);
CFStringGetCString(value, s, PATH_MAX - 1, kCFStringEncodingUTF8);
char *x;
x = strrchr(s, '/'); x = strrchr(s, '/');
if(x) x[1] = 0; if(x) x[1] = 0;
} }