Use the POSIX pathconf(2) to determine the maximum path length.

It fixes build on BSD platforms where PATH_MAX is defined in
<sys/syslimits.h> vs <linux/limits.h> on Linux.
pull/2443/head
fredzio 6 years ago
parent 240f76e822
commit ca7ac30f6d

@ -4,7 +4,6 @@
#include <pwd.h> #include <pwd.h>
#include <unistd.h> #include <unistd.h>
#include <linux/limits.h>
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
#include <components/debug/debuglog.hpp> #include <components/debug/debuglog.hpp>
@ -81,13 +80,12 @@ boost::filesystem::path LinuxPath::getGlobalConfigPath() const
boost::filesystem::path LinuxPath::getLocalPath() const boost::filesystem::path LinuxPath::getLocalPath() const
{ {
boost::filesystem::path localPath("./"); boost::filesystem::path localPath("./");
char binPath[PATH_MAX]; std::string binPath(pathconf(".", _PC_PATH_MAX), '\0');
memset(binPath, 0, sizeof(binPath));
const char *statusPaths[] = {"/proc/self/exe", "/proc/self/file", "/proc/curproc/exe", "/proc/curproc/file"}; const char *statusPaths[] = {"/proc/self/exe", "/proc/self/file", "/proc/curproc/exe", "/proc/curproc/file"};
for(const char *path : statusPaths) 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(); localPath = boost::filesystem::path(binPath).parent_path();
break; break;

Loading…
Cancel
Save