diff options
Diffstat (limited to 'libs/utils/ZipFileRO.cpp')
-rw-r--r-- | libs/utils/ZipFileRO.cpp | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/libs/utils/ZipFileRO.cpp b/libs/utils/ZipFileRO.cpp index cad7720..a1bfedb 100644 --- a/libs/utils/ZipFileRO.cpp +++ b/libs/utils/ZipFileRO.cpp @@ -20,6 +20,7 @@ #define LOG_TAG "zipro" //#define LOG_NDEBUG 0 #include <utils/Log.h> +#include <utils/Compat.h> #include <utils/ZipFileRO.h> #include <utils/misc.h> #include <utils/threads.h> @@ -32,14 +33,6 @@ #include <assert.h> #include <unistd.h> -#if HAVE_PRINTF_ZD -# define ZD "%zd" -# define ZD_TYPE ssize_t -#else -# define ZD "%ld" -# define ZD_TYPE long -#endif - /* * We must open binary files using open(path, ... | O_BINARY) under Windows. * Otherwise strange read errors will happen. @@ -48,21 +41,6 @@ # define O_BINARY 0 #endif -/* - * TEMP_FAILURE_RETRY is defined by some, but not all, versions of - * <unistd.h>. (Alas, it is not as standard as we'd hoped!) So, if it's - * not already defined, then define it here. - */ -#ifndef TEMP_FAILURE_RETRY -/* Used to retry syscalls that can return EINTR. */ -#define TEMP_FAILURE_RETRY(exp) ({ \ - typeof (exp) _rc; \ - do { \ - _rc = (exp); \ - } while (_rc == -1 && errno == EINTR); \ - _rc; }) -#endif - using namespace android; /* @@ -118,7 +96,7 @@ ZipFileRO::~ZipFileRO() { */ int ZipFileRO::entryToIndex(const ZipEntryRO entry) const { - long ent = ((long) entry) - kZipEntryAdj; + long ent = ((intptr_t) entry) - kZipEntryAdj; if (ent < 0 || ent >= mHashTableSize || mHashTable[ent].name == NULL) { ALOGW("Invalid ZipEntryRO %p (%ld)\n", entry, ent); return -1; @@ -140,7 +118,7 @@ status_t ZipFileRO::open(const char* zipFileName) /* * Open and map the specified file. */ - fd = ::open(zipFileName, O_RDONLY | O_BINARY); + fd = TEMP_FAILURE_RETRY(::open(zipFileName, O_RDONLY | O_BINARY)); if (fd < 0) { ALOGW("Unable to open zip '%s': %s\n", zipFileName, strerror(errno)); return NAME_NOT_FOUND; @@ -320,6 +298,25 @@ bool ZipFileRO::mapCentralDirectory(void) return true; } + +/* + * Round up to the next highest power of 2. + * + * Found on http://graphics.stanford.edu/~seander/bithacks.html. + */ +static unsigned int roundUpPower2(unsigned int val) +{ + val--; + val |= val >> 1; + val |= val >> 2; + val |= val >> 4; + val |= val >> 8; + val |= val >> 16; + val++; + + return val; +} + bool ZipFileRO::parseZipArchive(void) { bool result = false; @@ -459,7 +456,7 @@ ZipEntryRO ZipFileRO::findEntryByIndex(int idx) const for (int ent = 0; ent < mHashTableSize; ent++) { if (mHashTable[ent].name != NULL) { if (idx-- == 0) - return (ZipEntryRO) (ent + kZipEntryAdj); + return (ZipEntryRO) (intptr_t)(ent + kZipEntryAdj); } } @@ -752,7 +749,7 @@ bool ZipFileRO::uncompressEntry(ZipEntryRO entry, int fd) const ptr = (const unsigned char*) file->getDataPtr(); if (method == kCompressStored) { - ssize_t actual = write(fd, ptr, uncompLen); + ssize_t actual = TEMP_FAILURE_RETRY(write(fd, ptr, uncompLen)); if (actual < 0) { ALOGE("Write failed: %s\n", strerror(errno)); goto unmap; @@ -901,9 +898,12 @@ bail: (zerr == Z_STREAM_END && zstream.avail_out != sizeof(writeBuf))) { long writeSize = zstream.next_out - writeBuf; - int cc = write(fd, writeBuf, writeSize); - if (cc != (int) writeSize) { - ALOGW("write failed in inflate (%d vs %ld)\n", cc, writeSize); + int cc = TEMP_FAILURE_RETRY(write(fd, writeBuf, writeSize)); + if (cc < 0) { + ALOGW("write failed in inflate: %s", strerror(errno)); + goto z_bail; + } else if (cc != (int) writeSize) { + ALOGW("write failed in inflate (%d vs %ld)", cc, writeSize); goto z_bail; } |