diff options
author | 2017-03-02 09:09:09 +0000 | |
---|---|---|
committer | 2017-03-02 13:32:16 +0000 | |
commit | 508af301b3d7c1465189a0edfe4707a1c261a658 (patch) | |
tree | a426a81dd791f3053dd9cb86d5f0860992814a4f /src/main/cpp/util/file.cc | |
parent | 4f2b41d3f5fe936833380a0446adb671b8a50b1f (diff) |
Bazel client: do not use `errno`.
Do not use `errno` in platform-independent code,
because Windows API functions don't set it.
This change abstracts away error handling and the
functions whose `errno` result we care about, will
set an input error variable.
Fixes https://github.com/bazelbuild/bazel/issues/2506
--
PiperOrigin-RevId: 148977873
MOS_MIGRATED_REVID=148977873
Diffstat (limited to 'src/main/cpp/util/file.cc')
-rw-r--r-- | src/main/cpp/util/file.cc | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/main/cpp/util/file.cc b/src/main/cpp/util/file.cc index 44df52be12..cd9d9076d1 100644 --- a/src/main/cpp/util/file.cc +++ b/src/main/cpp/util/file.cc @@ -11,7 +11,6 @@ // 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. -#include <errno.h> #include <limits.h> // PATH_MAX #include <algorithm> @@ -34,12 +33,17 @@ bool ReadFrom(file_handle_type handle, string *content, int max_size) { content->clear(); char buf[kReadSize]; // OPT: This loop generates one spurious read on regular files. + int error; while (int r = ReadFromHandle( handle, buf, max_size > 0 ? std::min(static_cast<size_t>(max_size), kReadSize) - : kReadSize)) { + : kReadSize, + &error)) { if (r < 0) { - if (errno == EINTR || errno == EAGAIN) continue; + if (error == ReadFileResult::INTERRUPTED || + error == ReadFileResult::AGAIN) { + continue; + } return false; } content->append(buf, r); @@ -57,10 +61,14 @@ bool ReadFrom(file_handle_type handle, string *content, int max_size) { bool ReadFrom(file_handle_type handle, void *data, size_t size) { static const size_t kReadSize = 4096; // read 4K chunks size_t offset = 0; + int error; while (int r = ReadFromHandle(handle, reinterpret_cast<char *>(data) + offset, - std::min(kReadSize, size))) { + std::min(kReadSize, size), &error)) { if (r < 0) { - if (errno == EINTR || errno == EAGAIN) continue; + if (error == ReadFileResult::INTERRUPTED || + error == ReadFileResult::AGAIN) { + continue; + } return false; } offset += r; |