diff options
author | Narayan Kamath <narayan@google.com> | 2015-04-27 16:25:53 +0100 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2015-06-04 13:26:22 -0700 |
commit | 67ab5d95058d6fe1bab71b3f69e1934728902995 (patch) | |
tree | 7558fcaa5d56f472f58471a1157b2f0c0bda105c /libziparchive | |
parent | 4ba18cf3ffae39c86ef3c968871b331f1e7df914 (diff) | |
download | system_core-67ab5d95058d6fe1bab71b3f69e1934728902995.zip system_core-67ab5d95058d6fe1bab71b3f69e1934728902995.tar.gz system_core-67ab5d95058d6fe1bab71b3f69e1934728902995.tar.bz2 |
Use base::WriteFully in zip_archive.
We're already linking against libbase but we'll have to add
a libbase dependency to every target that includes libziparchive
as a STATIC_LIBRARY dependency, given that there's no way to
express that what we want (except by adding a LOCAL_WHOLE_STATIC_LIBRARY
dependency on libbase to libziparchive but that seems bad too)
Bug: http://b/21558406
Change-Id: I294ad389a9c61a1134a7bc323da25b0004a8f1e0
(cherry picked from commit e97e66ea7c624190afa4639d6ddc60e7d013f46c)
Diffstat (limited to 'libziparchive')
-rw-r--r-- | libziparchive/zip_archive.cc | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/libziparchive/zip_archive.cc b/libziparchive/zip_archive.cc index 34131f1..79c4c53 100644 --- a/libziparchive/zip_archive.cc +++ b/libziparchive/zip_archive.cc @@ -30,6 +30,7 @@ #include <memory> #include <vector> +#include "base/file.h" #include "base/macros.h" // TEMP_FAILURE_RETRY may or may not be in unistd #include "base/memory.h" #include "log/log.h" @@ -1033,24 +1034,14 @@ class FileWriter : public Writer { return false; } - // Keep track of the start position so we can calculate the - // total number of bytes written. - const uint8_t* const start = buf; - while (buf_size > 0) { - ssize_t bytes_written = TEMP_FAILURE_RETRY(write(fd_, buf, buf_size)); - if (bytes_written == -1) { - ALOGW("Zip: unable to write " ZD " bytes to file; %s", buf_size, strerror(errno)); - return false; - } - - buf_size -= bytes_written; - buf += bytes_written; + const bool result = android::base::WriteFully(fd_, buf, buf_size); + if (result) { + total_bytes_written_ += buf_size; + } else { + ALOGW("Zip: unable to write " ZD " bytes to file; %s", buf_size, strerror(errno)); } - total_bytes_written_ += static_cast<size_t>( - reinterpret_cast<uintptr_t>(buf) - reinterpret_cast<uintptr_t>(start)); - - return true; + return result; } private: FileWriter(const int fd, const size_t declared_length) : |