From bfe4b5edb3097df66ddbf9639c3b3cd290734ed8 Mon Sep 17 00:00:00 2001 From: Narayan Kamath Date: Wed, 20 Sep 2017 16:04:26 +0100 Subject: [PATCH] DO NOT MERGE : Partially revert change 141d1d836465e8a5a56a5cc1e. There are no functional changes here. This is in place to make merge conflicts less likely if any further changes are made to this code in the future. Test: make Test: zip_archive_test Bug: 64211847 Change-Id: I80ff9712c85d602d27f132ac54f62b3524ac9106 --- libziparchive/zip_archive.cc | 46 +++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/libziparchive/zip_archive.cc b/libziparchive/zip_archive.cc index 4fe563865..7cc9ac39d 100644 --- a/libziparchive/zip_archive.cc +++ b/libziparchive/zip_archive.cc @@ -594,28 +594,7 @@ static int32_t MapCentralDirectory(int fd, const char* debug_file_name, return result; } -// Attempts to read |len| bytes into |buf| at offset |off|. -// -// This method uses pread64 on platforms that support it and -// lseek64 + read on platforms that don't. This implies that -// callers should not rely on the |fd| offset being incremented -// as a side effect of this call. -static inline ssize_t ReadAtOffset(int fd, uint8_t* buf, size_t len, - off64_t off) { -#ifdef HAVE_PREAD - return TEMP_FAILURE_RETRY(pread64(fd, buf, len, off)); -#else - // The only supported platform that doesn't support pread at the moment - // is Windows. Only recent versions of windows support unix like forks, - // and even there the semantics are quite different. - if (lseek64(fd, off, SEEK_SET) != off) { - ALOGW("Zip: failed seek to offset %" PRId64, off); - return kIoError; - } - - return TEMP_FAILURE_RETRY(read(fd, buf, len)); -#endif // HAVE_PREAD -} +static inline ssize_t ReadAtOffset(int fd, uint8_t* buf, size_t len, off64_t off); /* * Parses the Zip archive's Central Directory. Allocates and populates the @@ -778,6 +757,29 @@ static int32_t UpdateEntryFromDataDescriptor(int fd, return 0; } +// Attempts to read |len| bytes into |buf| at offset |off|. +// +// This method uses pread64 on platforms that support it and +// lseek64 + read on platforms that don't. This implies that +// callers should not rely on the |fd| offset being incremented +// as a side effect of this call. +static inline ssize_t ReadAtOffset(int fd, uint8_t* buf, size_t len, + off64_t off) { +#ifdef HAVE_PREAD + return TEMP_FAILURE_RETRY(pread64(fd, buf, len, off)); +#else + // The only supported platform that doesn't support pread at the moment + // is Windows. Only recent versions of windows support unix like forks, + // and even there the semantics are quite different. + if (lseek64(fd, off, SEEK_SET) != off) { + ALOGW("Zip: failed seek to offset %" PRId64, off); + return kIoError; + } + + return TEMP_FAILURE_RETRY(read(fd, buf, len)); +#endif // HAVE_PREAD +} + static int32_t FindEntry(const ZipArchive* archive, const int ent, ZipEntry* data) { const uint16_t nameLen = archive->hash_table[ent].name_length;