summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorScott Graham <scottmg@chromium.org>2014-04-02 21:11:26 (GMT)
committerScott Graham <scottmg@chromium.org>2014-04-03 02:38:44 (GMT)
commite6f9d04661f8bffa01bc306b6d191582ec62e23c (patch)
treeeea8813cc3580fa37155b3c0ea1328b6188fe0b1 /src
parent84986af6fdeae3f649f2bf884b20f644bc370e48 (diff)
downloadNinja-e6f9d04661f8bffa01bc306b6d191582ec62e23c.zip
Ninja-e6f9d04661f8bffa01bc306b6d191582ec62e23c.tar.gz
Ninja-e6f9d04661f8bffa01bc306b6d191582ec62e23c.tar.bz2
Support both slashes on Windows when making output dirs
Diffstat (limited to 'src')
-rw-r--r--src/disk_interface.cc13
-rw-r--r--src/disk_interface_test.cc13
2 files changed, 20 insertions, 6 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);
}
diff --git a/src/disk_interface_test.cc b/src/disk_interface_test.cc
index 55822a6..51a1d14 100644
--- a/src/disk_interface_test.cc
+++ b/src/disk_interface_test.cc
@@ -93,7 +93,18 @@ TEST_F(DiskInterfaceTest, ReadFile) {
}
TEST_F(DiskInterfaceTest, MakeDirs) {
- EXPECT_TRUE(disk_.MakeDirs("path/with/double//slash/"));
+ string path = "path/with/double//slash/";
+ EXPECT_TRUE(disk_.MakeDirs(path.c_str()));
+ FILE* f = fopen((path + "a_file").c_str(), "w");
+ EXPECT_TRUE(f);
+ EXPECT_EQ(0, fclose(f));
+#ifdef _WIN32
+ string path2 = "another\\with\\back\\\\slashes\\";
+ EXPECT_TRUE(disk_.MakeDirs(path2.c_str()));
+ FILE* f2 = fopen((path2 + "a_file").c_str(), "w");
+ EXPECT_TRUE(f2);
+ EXPECT_EQ(0, fclose(f2));
+#endif
}
TEST_F(DiskInterfaceTest, RemoveFile) {