Switch FileWriter::Write to boolean result code.
FileWriter::Write returned either the number of bytes written, or a negative
error code. No clients were doing anything with the result other than checking
for success or failure, and many clients were considering any non-zero result
success.
So, I changed the API to return less information, but just the information the
clients needed. Success or failure.
BUG=chromium-os:8521
TEST=Unittests
Change-Id: I51513d6aa7b704dc27fb90d5fae4dc7118a3f86c
Reviewed-on: https://gerrit.chromium.org/gerrit/11532
Reviewed-by: Andrew de los Reyes <[email protected]>
Tested-by: Don Garrett <[email protected]>
Commit-Ready: Don Garrett <[email protected]>
diff --git a/file_writer.cc b/file_writer.cc
index 1a95a75..ad29844 100644
--- a/file_writer.cc
+++ b/file_writer.cc
@@ -15,7 +15,7 @@
return 0;
}
-ssize_t DirectFileWriter::Write(const void* bytes, size_t count) {
+bool DirectFileWriter::Write(const void* bytes, size_t count) {
CHECK_GE(fd_, 0);
const char* char_bytes = reinterpret_cast<const char*>(bytes);
@@ -24,11 +24,11 @@
ssize_t rc = write(fd_, char_bytes + bytes_written,
count - bytes_written);
if (rc < 0)
- return -errno;
+ return false;
bytes_written += rc;
}
CHECK_EQ(bytes_written, count);
- return bytes_written;
+ return bytes_written == count;
}
int DirectFileWriter::Close() {