Merge pull request #1197 from BruegelN/fix-on-linux-path_to_executable

Fix on linux path_to_executable()
This commit is contained in:
Jérémie Dumas
2019-06-13 09:12:23 -04:00
committed by GitHub
2 changed files with 22 additions and 3 deletions
+7 -3
View File
@@ -11,8 +11,11 @@
#endif
#if defined(_WIN32)
# include <windows.h>
#else
#include <unistd.h>
#endif
#include <stdint.h>
IGL_INLINE std::string igl::path_to_executable()
{
// http://pastebin.com/ffzzxPzi
@@ -28,10 +31,11 @@ IGL_INLINE std::string igl::path_to_executable()
{
path = buffer;
}
#elif defined(UNIX)
if (readlink("/proc/self/exe", buffer, sizeof(buffer)) == -1)
#elif defined(UNIX) || defined(unix) || defined(__unix) || defined(__unix__)
int byte_count = readlink("/proc/self/exe", buffer, size);
if (byte_count != -1)
{
path = buffer;
path = std::string(buffer, byte_count);
}
#elif defined(__FreeBSD__)
int mib[4];
+15
View File
@@ -0,0 +1,15 @@
#include <test_common.h>
#include <igl/path_to_executable.h>
#include <iostream>
TEST_CASE("path_to_executable: example", "[igl]")
{
std::string path_to_executable = igl::path_to_executable();
REQUIRE(0 < path_to_executable.size());
// check if path_to_executable ends with correct file name, on windows .exe suffix is added.
std::string executable = "libigl_tests";
int pos = path_to_executable.length()-(executable.length() + 4/*".exe"*/);
REQUIRE( std::string::npos != path_to_executable.find(executable, pos));
}