Browse Source

Added symboles to check for in path_to_executable() because capital case UNIX is not defined under Linux (i.e. Ubuntu).
Lowercase unix is defined however. See: https://stackoverflow.com/questions/142508/how-do-i-check-os-with-a-preprocessor-directive
Also added missing include for readlink().
readlink() does not append a null byte, thus use information about the written byted when building the resulting string.

Nico Brügel 6 years ago
parent
commit
d7925be2e4
1 changed files with 5 additions and 3 deletions
  1. 5 3
      include/igl/path_to_executable.cpp

+ 5 - 3
include/igl/path_to_executable.cpp

@@ -13,6 +13,7 @@
 #  include <windows.h>
 #  include <windows.h>
 #endif
 #endif
 #include <stdint.h>
 #include <stdint.h>
+#include <unistd.h>
 IGL_INLINE std::string igl::path_to_executable()
 IGL_INLINE std::string igl::path_to_executable()
 {
 {
   // http://pastebin.com/ffzzxPzi
   // http://pastebin.com/ffzzxPzi
@@ -28,10 +29,11 @@ IGL_INLINE std::string igl::path_to_executable()
   {
   {
     path = buffer;
     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__)
 #elif defined(__FreeBSD__)
   int mib[4];
   int mib[4];