aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/cpp/util/file_posix.cc
diff options
context:
space:
mode:
authorGravatar László Csomor <laszlocsomor@google.com>2017-01-30 08:41:26 +0000
committerGravatar Yun Peng <pcloudy@google.com>2017-01-30 09:03:29 +0000
commit855fbe9ee447b7b37fd8c73dbc047d69b7ceffcf (patch)
treeb7e29aaf5d9807fa020455322b7f99d42a9867ec /src/main/cpp/util/file_posix.cc
parent98cafe88f9b6eee6b56ba0b6cdbe7acc4e0adf04 (diff)
Bazel client: platform-specific JoinPath
This allows joining paths on "\" instead of "/" when building for Windows. See https://github.com/bazelbuild/bazel/issues/2107 -- Change-Id: I417ba40af6530650be2394db4bd445f0883d40e5 Reviewed-on: https://cr.bazel.build/8495 PiperOrigin-RevId: 145961689 MOS_MIGRATED_REVID=145961689
Diffstat (limited to 'src/main/cpp/util/file_posix.cc')
-rw-r--r--src/main/cpp/util/file_posix.cc29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/main/cpp/util/file_posix.cc b/src/main/cpp/util/file_posix.cc
index a1d806a9d9..57c994a3ff 100644
--- a/src/main/cpp/util/file_posix.cc
+++ b/src/main/cpp/util/file_posix.cc
@@ -168,6 +168,35 @@ IPipe* CreatePipe() {
return new PosixPipe(fd[0], fd[1]);
}
+string JoinPath(const string &path1, const string &path2) {
+ if (path1.empty()) {
+ // "" + "/bar"
+ return path2;
+ }
+ if (path2.empty()) {
+ // "foo/" + ""
+ return path1;
+ }
+
+ if (path1.back() == '/') {
+ if (path2.front() == '/') {
+ // foo/ + /bar
+ return path1 + path2.substr(1);
+ } else {
+ // foo/ + bar
+ return path1 + path2;
+ }
+ } else {
+ if (path2.front() == '/') {
+ // foo + /bar
+ return path1 + path2;
+ } else {
+ // foo + bar
+ return path1 + "/" + path2;
+ }
+ }
+}
+
pair<string, string> SplitPath(const string &path) {
size_t pos = path.rfind('/');