aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/cpp/util/file_platform.h
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2016-11-09 10:08:19 +0000
committerGravatar Klaus Aehlig <aehlig@google.com>2016-11-09 10:54:13 +0000
commitb9d7767cc957d1cc6af0722c85858a5944df3d63 (patch)
tree4422d30e16d423c1fa75c5f331c28e16668de497 /src/main/cpp/util/file_platform.h
parentf926f3e1f43b008e034b4e8ecd16f5935ad35434 (diff)
blaze_utils: fork file handling for platforms
This commit repurposes file_posix.cc to be the POSIX API file handling implementation, and adds file_windows.cc for the Win32 API implementations. Furthermore it introduces file_platform.h that declares the interface. Subsequent changes will replace POSIX API calls in the rest of the C++ code with these abstract methods. Motivation: our code is so littered with POSIX-isms that we need an abstraction layer if we hope to compile it with MSVC. -- MOS_MIGRATED_REVID=138615822
Diffstat (limited to 'src/main/cpp/util/file_platform.h')
-rw-r--r--src/main/cpp/util/file_platform.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/main/cpp/util/file_platform.h b/src/main/cpp/util/file_platform.h
new file mode 100644
index 0000000000..6d00daffff
--- /dev/null
+++ b/src/main/cpp/util/file_platform.h
@@ -0,0 +1,39 @@
+// Copyright 2016 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef BAZEL_SRC_MAIN_CPP_UTIL_FILE_PLATFORM_H_
+#define BAZEL_SRC_MAIN_CPP_UTIL_FILE_PLATFORM_H_
+
+#include <string>
+
+namespace blaze_util {
+
+// Checks each element of the PATH variable for executable. If none is found, ""
+// is returned. Otherwise, the full path to executable is returned. Can die if
+// looking up PATH fails.
+std::string Which(const std::string &executable);
+
+// Returns true if this path exists.
+bool PathExists(const std::string& path);
+
+// Returns true if the path exists and can be accessed to read/write as desired.
+//
+// If `exec` is true and the path refers to a file, it means the file must be
+// executable; if the path is a directory, it means the directory must be
+// openable.
+bool CanAccess(const std::string& path, bool read, bool write, bool exec);
+
+} // namespace blaze_util
+
+#endif // BAZEL_SRC_MAIN_CPP_UTIL_FILE_PLATFORM_H_