From ca7ac30f6d348adfb0e7e9fdfbaced00717b11c0 Mon Sep 17 00:00:00 2001 From: fredzio Date: Sun, 7 Jul 2019 01:02:38 +0200 Subject: [PATCH] Use the POSIX pathconf(2) to determine the maximum path length. It fixes build on BSD platforms where PATH_MAX is defined in vs on Linux. --- components/files/linuxpath.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/components/files/linuxpath.cpp b/components/files/linuxpath.cpp index 3acfd825f..5f34539d5 100644 --- a/components/files/linuxpath.cpp +++ b/components/files/linuxpath.cpp @@ -4,7 +4,6 @@ #include #include -#include #include #include @@ -81,13 +80,12 @@ boost::filesystem::path LinuxPath::getGlobalConfigPath() const boost::filesystem::path LinuxPath::getLocalPath() const { boost::filesystem::path localPath("./"); - char binPath[PATH_MAX]; - memset(binPath, 0, sizeof(binPath)); + std::string binPath(pathconf(".", _PC_PATH_MAX), '\0'); const char *statusPaths[] = {"/proc/self/exe", "/proc/self/file", "/proc/curproc/exe", "/proc/curproc/file"}; for(const char *path : statusPaths) { - if (readlink(path, binPath, sizeof(binPath)) != -1) + if (readlink(path, &binPath[0], binPath.size()) != -1) { localPath = boost::filesystem::path(binPath).parent_path(); break;