| 403 | #endif // defined(__NATRON_OSX__) |
| 404 | |
| 405 | NATRON_NAMESPACE_ANONYMOUS_EXIT |
| 406 | |
| 407 | |
| 408 | std::string |
| 409 | ProcInfo::applicationFilePath(const char* argv0Param) |
| 410 | { |
| 411 | #if defined(__NATRON_WIN32__) |
| 412 | (void)argv0Param; |
| 413 | |
| 414 | //The only viable solution |
| 415 | return applicationFileName(); |
| 416 | #elif defined(__NATRON_OSX__) |
| 417 | //First guess this way, then use the fallback solution |
| 418 | static std::string appFileName; |
| 419 | |
| 420 | if ( appFileName.empty() ) { |
| 421 | NatronCFType<CFURLRef> bundleURL( CFBundleCopyExecutableURL( CFBundleGetMainBundle() ) ); |
| 422 | if (bundleURL) { |
| 423 | NatronCFString cfPath( CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle) ); |
| 424 | if (cfPath) { |
| 425 | appFileName = cfPath; |
| 426 | } |
| 427 | } |
| 428 | } |
| 429 | if ( !appFileName.empty() ) { |
| 430 | return appFileName; |
| 431 | } else { |
| 432 | return applicationFilePath_fromArgv(argv0Param); |
| 433 | } |
| 434 | #elif defined(__NATRON_LINUX__) |
| 435 | // Try looking for a /proc/<pid>/exe symlink first which points to |
| 436 | // the absolute path of the executable |
| 437 | std::stringstream ss; |
| 438 | ss << "/proc/" << getpid() << "/exe"; |
| 439 | std::string filename = ss.str(); |
| 440 | char buf[2048] = {0}; |
| 441 | ssize_t sizeofbuf = sizeof(char) * 2048; |
| 442 | ssize_t size = readlink(filename.c_str(), buf, sizeofbuf); |
| 443 | if ( (size != 0) && (size != sizeofbuf) ) { |
| 444 | //detected symlink |
| 445 | std::string ret(buf); |
| 446 | return ret; |
| 447 | } else { |
| 448 | return applicationFilePath_fromArgv(argv0Param); |
| 449 | } |
| 450 | #endif |
| 451 | } |
| 452 | |
| 453 | std::string |
| 454 | ProcInfo::applicationDirPath(const char* argv0Param) |
no test coverage detected