1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| Path File::GetWorkingDirectory()
{
Path l_return;
#if defined( _WIN32 )
TCHAR l_path[FILENAME_MAX];
DWORD l_result = GetModuleFileName( NULL, l_path, _countof( l_path ) );
if ( l_result )
{
l_return = l_path;
}
#elif defined( __linux__ )
char l_path[FILENAME_MAX];
std::stringstream l_stream;
l_stream << "/proc/" << getpid() << "/exe";
int l_bytes = std::min< std::size_t >( readlink( l_stream.str().c_str(), l_path, sizeof( l_path ) ), sizeof( l_path ) - 1 );
if ( l_bytes > 0 )
{
l_path[l_bytes] = '\0';
l_return = l_path;
}
#else
# error "Unsupported platform"
#endif
l_return = l_return.GetPath();
return l_return;
} |