1 #include "Path.h" 2 3 #include <string.h> 4 #include <unistd.h> 5 6 namespace gfxstream { 7 namespace guest { 8 getProgramDirectory()9std::string getProgramDirectory() { 10 std::string res; 11 #if defined(__linux__) 12 char path[1024]; 13 memset(path, 0, sizeof(path)); // happy valgrind! 14 int len = readlink("/proc/self/exe", path, sizeof(path)); 15 if (len > 0 && len < (int)sizeof(path)) { 16 char* x = ::strrchr(path, '/'); 17 if (x) { 18 *x = '\0'; 19 res.assign(path); 20 } 21 } 22 #else 23 #error "Unsupported platform!" 24 #endif 25 return res; 26 } 27 28 } // namespace guest 29 } // namespace gfxstream 30