aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2016-11-22 14:02:07 +0000
committerGravatar Dmitry Lomov <dslomov@google.com>2016-11-22 14:15:35 +0000
commitbc3f2649adee9ace37960370626b0273bfb15e11 (patch)
tree44f31f061808453261be83e12c84e3ffc601e3ce
parenta23068a19a00515555526e2e377f1ec540ed7a40 (diff)
Bazel client: fix compiler warnings
-- MOS_MIGRATED_REVID=139899429
-rw-r--r--src/main/cpp/blaze_util.cc20
-rw-r--r--src/main/cpp/blaze_util.h10
-rw-r--r--src/main/cpp/util/file.h6
-rw-r--r--src/main/cpp/util/file_posix.cc11
4 files changed, 20 insertions, 27 deletions
diff --git a/src/main/cpp/blaze_util.cc b/src/main/cpp/blaze_util.cc
index 9e1bd2df38..cfa2b92511 100644
--- a/src/main/cpp/blaze_util.cc
+++ b/src/main/cpp/blaze_util.cc
@@ -77,23 +77,21 @@ string MakeAbsolute(const string &path) {
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 @@ bool ReadFileDescriptor(int fd, string *content, size_t max_size) {
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 7241682cba..0f7b71a596 100644
--- a/src/main/cpp/blaze_util.h
+++ b/src/main/cpp/blaze_util.h
@@ -42,17 +42,17 @@ std::string GetUserName();
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 6118eefb0b..13a2b4828c 100644
--- a/src/main/cpp/util/file.h
+++ b/src/main/cpp/util/file.h
@@ -24,11 +24,13 @@ class IPipe {
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 5bb8772d70..08a38cc102 100644
--- a/src/main/cpp/util/file_posix.cc
+++ b/src/main/cpp/util/file_posix.cc
@@ -45,15 +45,12 @@ class PosixPipe : public IPipe {
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: