NATRON_NAMESPACE_ANONYMOUS_EXIT QString ProcInfo::applicationFilePath(const char* argv0Param) { #if defined(Q_WS_WIN) //The only viable solution return applicationFileName(); #elif defined(Q_WS_MAC) //First guess this way, then use the fallback solution QString appFile = applicationFileName(); if ( !appFile.isEmpty() ) { return appFile; } else { return applicationFilePath_fromArgv(argv0Param); } #elif defined(Q_OS_LINUX) // Try looking for a /proc/<pid>/exe symlink first which points to // the absolute path of the executable std::stringstream ss; ss << "/proc/" << getpid() << "/exe"; std::string filename = ss.str(); char buf[2048] = {0}; ssize_t sizeofbuf = sizeof(char) * 2048; ssize_t size = readlink(filename.c_str(), buf, sizeofbuf); if ( (size != 0) && (size != sizeofbuf) ) { //detected symlink return QString::fromUtf8( QByteArray(buf) ); } else { return applicationFilePath_fromArgv(argv0Param); } #endif }
NATRON_NAMESPACE_ANONYMOUS_EXIT QString ProcInfo::applicationFilePath(const char* argv0Param) { #if defined(Q_OS_WIN) Q_UNUSED(argv0Param); //The only viable solution return applicationFileName(); #elif defined(Q_OS_MAC) //First guess this way, then use the fallback solution static QString appFileName; if ( appFileName.isEmpty() ) { NatronCFType<CFURLRef> bundleURL( CFBundleCopyExecutableURL( CFBundleGetMainBundle() ) ); if (bundleURL) { NatronCFString cfPath( CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle) ); if (cfPath) { appFileName = cfPath; } } } if ( !appFileName.isEmpty() ) { return appFileName; } else { return applicationFilePath_fromArgv(argv0Param); } #elif defined(Q_OS_LINUX) // Try looking for a /proc/<pid>/exe symlink first which points to // the absolute path of the executable std::stringstream ss; ss << "/proc/" << getpid() << "/exe"; std::string filename = ss.str(); char buf[2048] = {0}; ssize_t sizeofbuf = sizeof(char) * 2048; ssize_t size = readlink(filename.c_str(), buf, sizeofbuf); if ( (size != 0) && (size != sizeofbuf) ) { //detected symlink return QString::fromUtf8( QByteArray(buf) ); } else { return applicationFilePath_fromArgv(argv0Param); } #endif }