Commit 2cf30bd0 by Corentin Wallez

Fix GetExecutablePath on Linux

It was using lstat to get the size of /proc/self/exe but it always returns 0, so we just use a big buffer on the stack instead. BUG=angleproject:892 Change-Id: I6d88efeb4ec5de7a78cb3668e3d78520203ad1d5 Reviewed-on: https://chromium-review.googlesource.com/269990Reviewed-by: 's avatarKenneth Russell <kbr@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 0e201cb7
......@@ -7,36 +7,25 @@
// Linux_path_utils.cpp: Implementation of OS-specific path functions for Linux
#include "path_utils.h"
#include <array>
#include <sys/stat.h>
#include <unistd.h>
#include <array>
std::string GetExecutablePath()
{
struct stat sb;
if (lstat("/proc/self/exe", &sb) == -1)
{
return "";
}
// We cannot use lstat to get the size of /proc/self/exe as it always returns 0
// so we just use a big buffer and hope the path fits in it.
char path[4096];
char *path = static_cast<char*>(malloc(sb.st_size + 1));
if (!path)
ssize_t result = readlink("/proc/self/exe", path, sizeof(path) - 1);
if (result < 0 || result >= sizeof(path) - 1)
{
return "";
}
ssize_t result = readlink("/proc/self/exe", path, sb.st_size);
if (result != sb.st_size)
{
free(path);
return "";
}
path[sb.st_size] = '\0';
std::string strPath(path);
free(path);
return strPath;
path[result] = '\0';
return path;
}
std::string GetExecutableDirectory()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment