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.
This commit is contained in:
Nico Brügel
2019-05-14 16:57:20 +02:00
parent 10e04cbef5
commit d7925be2e4
+5 -3
View File
@@ -13,6 +13,7 @@
# include <windows.h>
#endif
#include <stdint.h>
#include <unistd.h>
IGL_INLINE std::string igl::path_to_executable()
{
// http://pastebin.com/ffzzxPzi
@@ -28,10 +29,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];