Bazel client: fix compiler warnings
--
MOS_MIGRATED_REVID=139899429
diff --git a/src/main/cpp/blaze_util.cc b/src/main/cpp/blaze_util.cc
index 9e1bd2d..cfa2b92 100644
--- a/src/main/cpp/blaze_util.cc
+++ b/src/main/cpp/blaze_util.cc
@@ -77,23 +77,21 @@
return cwd + separator + path;
}
-// Replaces 'contents' with contents of 'fd' file descriptor.
-// If `max_size` is positive, the method reads at most that many bytes; if it
-// is 0, the method reads the whole file.
-// Returns false on error.
-bool ReadFileDescriptor(int fd, string *content, size_t max_size) {
+bool ReadFileDescriptor(int fd, string *content, int max_size) {
content->clear();
char buf[4096];
// OPT: This loop generates one spurious read on regular files.
- while (int r = read(fd, buf, max_size > 0 ? std::min(max_size, sizeof buf)
- : sizeof buf)) {
+ while (int r = read(fd, buf,
+ max_size > 0
+ ? std::min(max_size, static_cast<int>(sizeof buf))
+ : sizeof buf)) {
if (r == -1) {
if (errno == EINTR || errno == EAGAIN) continue;
return false;
}
content->append(buf, r);
if (max_size > 0) {
- if (max_size > static_cast<size_t>(r)) {
+ if (max_size > r) {
max_size -= r;
} else {
break;
@@ -104,11 +102,7 @@
return true;
}
-// Replaces 'content' with contents of file 'filename'.
-// If `max_size` is positive, the method reads at most that many bytes; if it
-// is 0, the method reads the whole file.
-// Returns false on error.
-bool ReadFile(const string &filename, string *content, size_t max_size) {
+bool ReadFile(const string &filename, string *content, int max_size) {
int fd = open(filename.c_str(), O_RDONLY);
if (fd == -1) return false;
return ReadFileDescriptor(fd, content, max_size);
diff --git a/src/main/cpp/blaze_util.h b/src/main/cpp/blaze_util.h
index 7241682..0f7b71a 100644
--- a/src/main/cpp/blaze_util.h
+++ b/src/main/cpp/blaze_util.h
@@ -42,17 +42,17 @@
std::string MakeAbsolute(const std::string &path);
// Replaces 'content' with contents of file 'filename'.
-// If `max_size` is positive, the method reads at most that many bytes; if it
-// is 0, the method reads the whole file.
+// If `max_size` is positive, the method reads at most that many bytes;
+// otherwise the method reads the whole file.
// Returns false on error. Can be called from a signal handler.
bool ReadFile(const std::string &filename, std::string *content,
- size_t max_size = 0);
+ int max_size = 0);
// Replaces 'content' with contents of file descriptor 'fd'.
// If `max_size` is positive, the method reads at most that many bytes; if it
-// is 0, the method reads the whole file.
+// otherwise the method reads the whole file.
// Returns false on error. Can be called from a signal handler.
-bool ReadFileDescriptor(int fd, std::string *content, size_t max_size = 0);
+bool ReadFileDescriptor(int fd, std::string *content, int max_size = 0);
// Writes 'content' into file 'filename', and makes it executable.
// Returns false on failure, sets errno.
diff --git a/src/main/cpp/util/file.h b/src/main/cpp/util/file.h
index 6118eef..13a2b48 100644
--- a/src/main/cpp/util/file.h
+++ b/src/main/cpp/util/file.h
@@ -24,11 +24,13 @@
virtual ~IPipe() {}
// Sends `size` bytes from `buffer` through the pipe.
- virtual bool Send(void *buffer, size_t size) = 0;
+ // Returns true if `size` is not negative and could send all the data.
+ virtual bool Send(void *buffer, int size) = 0;
// Receives at most `size` bytes into `buffer` from the pipe.
// Returns the number of bytes received; sets `errno` upon error.
- virtual int Receive(void *buffer, size_t size) = 0;
+ // If `size` is negative, returns -1.
+ virtual int Receive(void *buffer, int size) = 0;
};
// Returns the part of the path before the final "/". If there is a single
diff --git a/src/main/cpp/util/file_posix.cc b/src/main/cpp/util/file_posix.cc
index 5bb8772..08a38cc 100644
--- a/src/main/cpp/util/file_posix.cc
+++ b/src/main/cpp/util/file_posix.cc
@@ -45,15 +45,12 @@
close(_send_socket);
}
- // Sends `size` bytes from `buffer` through the pipe.
- bool Send(void* buffer, size_t size) override {
- return write(_send_socket, buffer, size) == size;
+ bool Send(void* buffer, int size) override {
+ return size >= 0 && write(_send_socket, buffer, size) == size;
}
- // Receives at most `size` bytes into `buffer` from the pipe.
- // Returns the number of bytes received; sets `errno` upon error.
- int Receive(void* buffer, size_t size) override {
- return read(_recv_socket, buffer, size);
+ int Receive(void* buffer, int size) override {
+ return size < 0 ? -1 : read(_recv_socket, buffer, size);
}
private: