MCPcopy Create free account
hub / github.com/ValveSoftware/openvr / Path_GetExecutablePath

Function Path_GetExecutablePath

src/vrcore/pathtools_public.cpp:34–73  ·  view source on GitHub ↗

Returns the path (including filename) to the current executable */

Source from the content-addressed store, hash-verified

32
33/** Returns the path (including filename) to the current executable */
34std::string Path_GetExecutablePath()
35{
36#if defined( _WIN32 )
37 wchar_t *pwchPath = new wchar_t[MAX_UNICODE_PATH];
38 char *pchPath = new char[MAX_UNICODE_PATH_IN_UTF8];
39 ::GetModuleFileNameW( NULL, pwchPath, MAX_UNICODE_PATH );
40 WideCharToMultiByte( CP_UTF8, 0, pwchPath, -1, pchPath, MAX_UNICODE_PATH_IN_UTF8, NULL, NULL );
41 delete[] pwchPath;
42
43 std::string sPath = pchPath;
44 delete[] pchPath;
45 return sPath;
46#elif defined( OSX )
47 char rchPath[1024];
48 uint32_t nBuff = sizeof( rchPath );
49 bool bSuccess = _NSGetExecutablePath(rchPath, &nBuff) == 0;
50 rchPath[nBuff-1] = '\0';
51 if( bSuccess )
52 return rchPath;
53 else
54 return "";
55#elif defined LINUX
56 char rchPath[1024];
57 size_t nBuff = sizeof( rchPath );
58 ssize_t nRead = readlink("/proc/self/exe", rchPath, nBuff-1 );
59 if ( nRead != -1 )
60 {
61 rchPath[ nRead ] = 0;
62 return rchPath;
63 }
64 else
65 {
66 return "";
67 }
68#else
69 AssertMsg( false, "Implement Plat_GetExecutablePath" );
70 return "";
71#endif
72
73}
74
75/** Returns the filename (excluding directory and extension) of the current executable */
76std::string Path_GetExecutableName()

Callers 1

Path_GetExecutableNameFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected