diff options
author | Scott Graham <scottmg@chromium.org> | 2014-04-02 21:11:26 (GMT) |
---|---|---|
committer | Scott Graham <scottmg@chromium.org> | 2014-04-03 02:38:44 (GMT) |
commit | e6f9d04661f8bffa01bc306b6d191582ec62e23c (patch) | |
tree | eea8813cc3580fa37155b3c0ea1328b6188fe0b1 /src/disk_interface.cc | |
parent | 84986af6fdeae3f649f2bf884b20f644bc370e48 (diff) | |
download | Ninja-e6f9d04661f8bffa01bc306b6d191582ec62e23c.zip Ninja-e6f9d04661f8bffa01bc306b6d191582ec62e23c.tar.gz Ninja-e6f9d04661f8bffa01bc306b6d191582ec62e23c.tar.bz2 |
Support both slashes on Windows when making output dirs
Diffstat (limited to 'src/disk_interface.cc')
-rw-r--r-- | src/disk_interface.cc | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/disk_interface.cc b/src/disk_interface.cc index 3233144..bfacb81 100644 --- a/src/disk_interface.cc +++ b/src/disk_interface.cc @@ -14,6 +14,8 @@ #include "disk_interface.h" +#include <algorithm> + #include <errno.h> #include <stdio.h> #include <string.h> @@ -31,15 +33,16 @@ namespace { string DirName(const string& path) { #ifdef _WIN32 - const char kPathSeparator = '\\'; + const char kPathSeparators[] = "\\/"; #else - const char kPathSeparator = '/'; + const char kPathSeparators[] = "/"; #endif - - string::size_type slash_pos = path.rfind(kPathSeparator); + string::size_type slash_pos = path.find_last_of(kPathSeparators); if (slash_pos == string::npos) return string(); // Nothing to do. - while (slash_pos > 0 && path[slash_pos - 1] == kPathSeparator) + const char* const kEnd = kPathSeparators + strlen(kPathSeparators); + while (slash_pos > 0 && + std::find(kPathSeparators, kEnd, path[slash_pos - 1]) != kEnd) --slash_pos; return path.substr(0, slash_pos); } |