Clean up the path implementation and a few other things.
This commit is contained in:
parent
a5cdf4e5f9
commit
4c8cac13aa
7 changed files with 63 additions and 21 deletions
|
@ -56,18 +56,15 @@ std::string path::separator()
|
|||
std::string path::executable_path()
|
||||
{
|
||||
std::string result;
|
||||
|
||||
const size_t MAXPATHLEN = 2048;
|
||||
std::vector<char> buf(MAXPATHLEN);
|
||||
|
||||
#if defined(__APPLE__)
|
||||
CFURLRef bundleURL;
|
||||
CFStringRef pathStr;
|
||||
|
||||
CFBundleRef mainBundle = CFBundleGetMainBundle();
|
||||
|
||||
bundleURL = CFBundleCopyExecutableURL(mainBundle);
|
||||
pathStr = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle);
|
||||
CFStringGetCString(pathStr, path, MAXPATHLEN, kCFStringEncodingASCII);
|
||||
|
||||
result.assign(&path[0]);
|
||||
CFURLRef bundleURL = CFBundleCopyExecutableURL(mainBundle);
|
||||
CFStringRef pathStr = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle);
|
||||
CFStringGetCString(pathStr, buf.data(), buf.size(), kCFStringEncodingASCII);
|
||||
|
||||
CFRelease(pathStr);
|
||||
CFRelease(bundleURL);
|
||||
|
@ -77,11 +74,10 @@ std::string path::executable_path()
|
|||
DWORD ret = GetModuleFileName( NULL, &lpFname[0], MAXPATHLEN );
|
||||
result.assign(&lpFname[0]);
|
||||
#elif defined(__USE_POSIX)
|
||||
const size_t MAXPATHLEN = 2048;
|
||||
std::vector<char> buf(MAXPATHLEN);
|
||||
readlink("/proc/self/exe", buf.data(), buf.size());
|
||||
result.assign(buf.data());
|
||||
#endif
|
||||
result.assign(buf.data());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue