MCPcopy Create free account
hub / github.com/SpartanJ/eepp / sGetProcessPath

Function sGetProcessPath

src/eepp/system/sys.cpp:595–697  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

593}
594
595static std::string sGetProcessPath() {
596#if EE_PLATFORM == EE_PLATFORM_MACOS
597 char pathbuf[PROC_PIDPATHINFO_MAXSIZE];
598 pid_t pid = getpid();
599 int ret = proc_pidpath( pid, pathbuf, sizeof( pathbuf ) );
600 if ( ret >= 0 )
601 return FileSystem::fileRemoveFileName( std::string( pathbuf ) );
602
603 char exe_file[PATH_MAX + 1];
604 CFBundleRef mainBundle = CFBundleGetMainBundle();
605 if ( mainBundle ) {
606 CFURLRef mainURL = CFBundleCopyBundleURL( mainBundle );
607
608 if ( mainURL ) {
609 int ok = CFURLGetFileSystemRepresentation( mainURL, ( Boolean ) true, (UInt8*)exe_file,
610 PATH_MAX );
611
612 if ( ok ) {
613 return std::string( exe_file ) + "/";
614 }
615 }
616 }
617
618 return "./";
619#elif EE_PLATFORM == EE_PLATFORM_LINUX
620 char exe_file[PATH_MAX + 1];
621 int size;
622 size = readlink( "/proc/self/exe", exe_file, PATH_MAX );
623 if ( size < 0 ) {
624 return "./";
625 } else {
626 exe_file[size] = '\0';
627 return std::string( dirname( exe_file ) ) + "/";
628 }
629#elif EE_PLATFORM == EE_PLATFORM_WIN
630#ifdef UNICODE
631 // Get path to executable:
632 char szDrive[_MAX_DRIVE];
633 char szDir[_MAX_DIR];
634 char szFilename[_MAX_DIR];
635 char szExt[_MAX_DIR];
636 std::wstring dllName( _MAX_DIR, 0 );
637
638 GetModuleFileName( 0, &dllName[0], _MAX_PATH );
639
640 std::string dllstrName( String( dllName ).toUtf8() );
641
642#ifdef EE_COMPILER_MSVC
643 _splitpath_s( dllstrName.c_str(), szDrive, _MAX_DRIVE, szDir, _MAX_DIR, szFilename, _MAX_DIR,
644 szExt, _MAX_DIR );
645#else
646 _splitpath( dllstrName.c_str(), szDrive, szDir, szFilename, szExt );
647#endif
648
649 return std::string( szDrive ) + std::string( szDir );
650#else
651 // Get path to executable:
652 TCHAR szDllName[_MAX_PATH];

Callers 1

getProcessPathMethod · 0.85

Calls 4

toUtf8Method · 0.80
c_strMethod · 0.80
getPlatformHelperMethod · 0.80

Tested by

no test coverage detected