diff options
author | 2017-03-01 16:53:35 +0000 | |
---|---|---|
committer | 2017-03-01 17:20:57 +0000 | |
commit | 6e2ccb75d7c9e1e9102a0512449381e2fffc57a7 (patch) | |
tree | ed1d6e22971d4312f2370211638aeb2381374c2e /src/main/cpp/util/file.h | |
parent | 0dff43a2e3c566766f64fed597d143885d5d8368 (diff) |
Bazel client: simplify {Read,Write}File semantics
Introduce a platform-specific file handle type
(HANDLE on Windows, int on Linux/Darwin/FreeBSD)
so we can get rid of the read_func and write_func
functions, since they are always the same
everywhere.
Also include file_platform.h in file.h, since they
are logically the same file (file_platform.h is
just the platform-specific part of file.h).
--
PiperOrigin-RevId: 148892736
MOS_MIGRATED_REVID=148892736
Diffstat (limited to 'src/main/cpp/util/file.h')
-rw-r--r-- | src/main/cpp/util/file.h | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/src/main/cpp/util/file.h b/src/main/cpp/util/file.h index 2f29d15d9e..62ab0395c8 100644 --- a/src/main/cpp/util/file.h +++ b/src/main/cpp/util/file.h @@ -14,10 +14,11 @@ #ifndef BAZEL_SRC_MAIN_CPP_UTIL_FILE_H_ #define BAZEL_SRC_MAIN_CPP_UTIL_FILE_H_ -#include <functional> #include <string> #include <vector> +#include "src/main/cpp/util/file_platform.h" + namespace blaze_util { class IPipe { @@ -34,29 +35,22 @@ class IPipe { virtual int Receive(void *buffer, int size) = 0; }; -// Replaces 'content' with data read from a source using `read_func`. +// Replaces 'content' with data read from a source using `ReadFromHandle`. // If `max_size` is positive, the method reads at most that many bytes; // otherwise the method reads everything. // Returns false on error. Can be called from a signal handler. -bool ReadFrom(const std::function<int(void *, size_t)> &read_func, - std::string *content, int max_size = 0); +bool ReadFrom(file_handle_type handle, std::string *content, int max_size = 0); -// Reads up to `size` bytes using `read_func` into `data`. +// Reads up to `size` bytes using `ReadFromHandle` into `data`. // There must be enough memory allocated at `data`. // Returns true on success, false on error. -bool ReadFrom(const std::function<int(void *, size_t)> &read_func, void *data, - size_t size); +bool ReadFrom(file_handle_type handle, void *data, size_t size); // Writes `content` into file `filename`, and chmods it to `perm`. -// Returns false on failure, sets errno. +// Returns false on failure. bool WriteFile(const std::string &content, const std::string &filename, unsigned int perm = 0755); -// Writes `size` bytes from `data` into a destination using `write_func`. -// Returns false on failure, sets errno. -bool WriteTo(const std::function<int(const void *, size_t)> &write_func, - const void *data, size_t size); - // Returns the part of the path before the final "/". If there is a single // leading "/" in the path, the result will be the leading "/". If there is // no "/" in the path, the result is the empty prefix of the input (i.e., ""). |