From d9b9e5e22753180a18a74c482a690ffccde5d2c8 Mon Sep 17 00:00:00 2001 From: Chao Shen Date: Wed, 3 Jan 2018 20:38:01 +0800 Subject: [PATCH] fix appveyor --- src/platform_posix.cc | 5 +++-- src/utils.cc | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/platform_posix.cc b/src/platform_posix.cc index 21d6ba20..da3b22a5 100644 --- a/src/platform_posix.cc +++ b/src/platform_posix.cc @@ -139,8 +139,9 @@ std::string GetExecutablePath() { return std::string(path); #else char buffer[PATH_MAX] = {0}; - readlink("/proc/self/exe", buffer, PATH_MAX); - return std::string(buffer); + if(-1 == readlink("/proc/self/exe", buffer, PATH_MAX)) + return ""; + return buffer; #endif } diff --git a/src/utils.cc b/src/utils.cc index 66c19ca3..1381c82c 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -14,6 +14,7 @@ #include #include #include +#include #include #if !defined(__APPLE__) @@ -490,6 +491,13 @@ std::string GetDefaultResourceDirectory() { std::string resource_directory = std::string(ENSURE_STRING_MACRO_ARGUMENT(DEFAULT_RESOURCE_DIRECTORY)); + // Remove double quoted resource dir if it was passed with quotes + // by the build system. + if (resource_directory.size() >= 2 && resource_directory[0] == '"' && + resource_directory[resource_directory.size() - 1] == '"') { + resource_directory = + resource_directory.substr(1, resource_directory.size() - 2); + } if (resource_directory.find("..") != std::string::npos) { std::string executable_path = GetExecutablePath(); size_t pos = executable_path.find_last_of('/'); @@ -499,7 +507,11 @@ std::string GetDefaultResourceDirectory() { result = resource_directory; } - return NormalizePath(result); + result = NormalizePath(result); +#if defined(_WIN32) + std::replace(result.begin(), result.end(), '/', '\\'); +#endif + return result; } std::string UpdateToRnNewlines(std::string output) { @@ -585,4 +597,4 @@ TEST_SUITE("Update \\n to \\r\\n") { REQUIRE(UpdateToRnNewlines("f1\nfo2\nfoo3") == "f1\r\nfo2\r\nfoo3"); REQUIRE(UpdateToRnNewlines("f1\r\nfo2\r\nfoo3") == "f1\r\nfo2\r\nfoo3"); } -} \ No newline at end of file +}