Last active
October 2, 2015 11:28
-
-
Save nickdowell/2236186 to your computer and use it in GitHub Desktop.
GetPluginBundle()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <CoreFoundation/CoreFoundation.h> | |
#include <dlfcn.h> | |
static CFBundleRef GetPluginBundle() | |
{ | |
static CFBundleRef bundle; | |
if (bundle) { | |
return bundle; | |
} | |
Dl_info dl_info = {}; | |
if (dladdr((void *)(&GetPluginBundle), &dl_info) == 0) { | |
return NULL; | |
} | |
char *end = strstr(dl_info.dli_fname, "/Contents/MacOS/"); | |
if (!end) { | |
return NULL; | |
} | |
CFURLRef url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (UInt8 *)dl_info.dli_fname, end - dl_info.dli_fname, TRUE); | |
if (!url) { | |
return NULL; | |
} | |
bundle = CFBundleCreate(kCFAllocatorDefault, url); | |
CFRelease(url); | |
return bundle; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment