Fix fileutils.cc for tests running under Win memory tools.

On Windows, when tests are run under memory tools like
DrMemory and TSan, slashes occur in the path as directory
separators. This makes the fileutils.cc fail to figure out
the project root, making paths to resource files invalid.

By replacing slashes in the path with backslashes for Windows
this can be fixed.

BUG=2318
TEST=running the same command as the bot locally, succeeding after this patch is applied.
R=phoglund@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/2137004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@4640 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
kjellander@webrtc.org 2013-08-29 11:26:41 +00:00
parent f8c16b8bf4
commit de499669ef

View File

@ -12,6 +12,7 @@
#ifdef WIN32 #ifdef WIN32
#include <direct.h> #include <direct.h>
#include <algorithm>
#define GET_CURRENT_DIR _getcwd #define GET_CURRENT_DIR _getcwd
#else #else
#include <unistd.h> #include <unistd.h>
@ -67,6 +68,13 @@ void SetExecutablePath(const std::string& path) {
if (path.find(working_dir) != std::string::npos) { if (path.find(working_dir) != std::string::npos) {
temp_path = path.substr(working_dir.length() + 1); temp_path = path.substr(working_dir.length() + 1);
} }
// On Windows, when tests are run under memory tools like DrMemory and TSan,
// slashes occur in the path as directory separators. Make sure we replace
// such cases with backslashes in order for the paths to be correct.
#ifdef WIN32
std::replace(temp_path.begin(), temp_path.end(), '/', '\\');
#endif
// Trim away the executable name; only store the relative dir path. // Trim away the executable name; only store the relative dir path.
temp_path = temp_path.substr(0, temp_path.find_last_of(kPathDelimiter)); temp_path = temp_path.substr(0, temp_path.find_last_of(kPathDelimiter));
strncpy(relative_dir_path, temp_path.c_str(), FILENAME_MAX); strncpy(relative_dir_path, temp_path.c_str(), FILENAME_MAX);