Commit 98b579c1 authored by Ryan Harrison's avatar Ryan Harrison Committed by Commit Bot

Fetch executable path for Mac in helper

The current implementation for Mac crashes, since /proc/ doesn't exist and thus
the path being searched for. This leads to attempting to create a string of
length 0.

This adds in Mac specific logic for fetching this information.

BUG=chromium:773183

Change-Id: I57bc2530ee79a51c0caad42ec31f640f73c7a7d4
Reviewed-on: https://chromium-review.googlesource.com/740344Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Cr-Commit-Position: refs/heads/master@{#513288}
parent d34d4b4c
...@@ -8,23 +8,27 @@ ...@@ -8,23 +8,27 @@
#include <assert.h> #include <assert.h>
#include <limits.h> #include <limits.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef _MSC_VER #ifdef _WIN32
#include <Windows.h> #include <Windows.h>
#else #elif defined(__APPLE__)
#include <mach-o/dyld.h>
#else // Linux
#include <unistd.h> #include <unistd.h>
#endif #endif // _WIN32
#include <memory> #include <memory>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <utility> #include <utility>
#include "base/memory/free_deleter.h"
#include "third_party/pdfium/public/cpp/fpdf_deleters.h" #include "third_party/pdfium/public/cpp/fpdf_deleters.h"
#include "third_party/pdfium/public/fpdf_dataavail.h" #include "third_party/pdfium/public/fpdf_dataavail.h"
#include "third_party/pdfium/public/fpdf_text.h" #include "third_party/pdfium/public/fpdf_text.h"
...@@ -78,22 +82,30 @@ FPDF_BOOL Is_Data_Avail(FX_FILEAVAIL* pThis, size_t offset, size_t size) { ...@@ -78,22 +82,30 @@ FPDF_BOOL Is_Data_Avail(FX_FILEAVAIL* pThis, size_t offset, size_t size) {
void Add_Segment(FX_DOWNLOADHINTS* pThis, size_t offset, size_t size) {} void Add_Segment(FX_DOWNLOADHINTS* pThis, size_t offset, size_t size) {}
std::string ProgramPath() { std::string ProgramPath() {
#ifdef _MSC_VER std::string result;
#ifdef _WIN32
wchar_t wpath[MAX_PATH]; wchar_t wpath[MAX_PATH];
char path[MAX_PATH]; char path[MAX_PATH];
DWORD res = GetModuleFileName(NULL, wpath, MAX_PATH); DWORD len = GetModuleFileNameA(NULL, path, MAX_PATH);
assert(res != 0); if (len != 0)
wcstombs(path, wpath, MAX_PATH); result = std::string(path, len);
return std::string(path, res); #elif defined(__APPLE__)
#else char path[PATH_MAX];
char* path = new char[PATH_MAX + 1]; unsigned int len = PATH_MAX;
assert(path); if (!_NSGetExecutablePath(path, &len)) {
ssize_t sz = readlink("/proc/self/exe", path, PATH_MAX); std::unique_ptr<char, base::FreeDeleter> resolved_path(
assert(sz > 0); realpath(path, nullptr));
std::string result(path, sz); if (resolved_path.get())
delete[] path; result = std::string(resolved_path.get());
return result; }
#else // Linux
char path[PATH_MAX];
ssize_t len = readlink("/proc/self/exe", path, PATH_MAX);
if (len > 0)
result = std::string(path, len);
#endif #endif
return result;
} }
} // namespace } // namespace
......
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