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 @@
#include <assert.h>
#include <limits.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _MSC_VER
#ifdef _WIN32
#include <Windows.h>
#else
#elif defined(__APPLE__)
#include <mach-o/dyld.h>
#else // Linux
#include <unistd.h>
#endif
#endif // _WIN32
#include <memory>
#include <sstream>
#include <string>
#include <utility>
#include "base/memory/free_deleter.h"
#include "third_party/pdfium/public/cpp/fpdf_deleters.h"
#include "third_party/pdfium/public/fpdf_dataavail.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) {
void Add_Segment(FX_DOWNLOADHINTS* pThis, size_t offset, size_t size) {}
std::string ProgramPath() {
#ifdef _MSC_VER
std::string result;
#ifdef _WIN32
wchar_t wpath[MAX_PATH];
char path[MAX_PATH];
DWORD res = GetModuleFileName(NULL, wpath, MAX_PATH);
assert(res != 0);
wcstombs(path, wpath, MAX_PATH);
return std::string(path, res);
#else
char* path = new char[PATH_MAX + 1];
assert(path);
ssize_t sz = readlink("/proc/self/exe", path, PATH_MAX);
assert(sz > 0);
std::string result(path, sz);
delete[] path;
return result;
DWORD len = GetModuleFileNameA(NULL, path, MAX_PATH);
if (len != 0)
result = std::string(path, len);
#elif defined(__APPLE__)
char path[PATH_MAX];
unsigned int len = PATH_MAX;
if (!_NSGetExecutablePath(path, &len)) {
std::unique_ptr<char, base::FreeDeleter> resolved_path(
realpath(path, nullptr));
if (resolved_path.get())
result = std::string(resolved_path.get());
}
#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
return result;
}
} // 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