am 848a2bc4: Merge "MinGW/Cygwin requires open() in O_BINARY mode." into gingerbread
Merge commit '848a2bc4cc6eab0f1d0bc030616b9305df3aa7da' into gingerbread-plus-aosp * commit '848a2bc4cc6eab0f1d0bc030616b9305df3aa7da': MinGW/Cygwin requires open() in O_BINARY mode.
This commit is contained in:
commit
9f986a25fc
@ -32,6 +32,22 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <unistd.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.
|
||||||
|
*/
|
||||||
|
#ifndef O_BINARY
|
||||||
|
# define O_BINARY 0
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TEMP_FAILURE_RETRY is defined by some, but not all, versions of
|
* 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
|
* <unistd.h>. (Alas, it is not as standard as we'd hoped!) So, if it's
|
||||||
@ -124,7 +140,7 @@ status_t ZipFileRO::open(const char* zipFileName)
|
|||||||
/*
|
/*
|
||||||
* Open and map the specified file.
|
* Open and map the specified file.
|
||||||
*/
|
*/
|
||||||
fd = ::open(zipFileName, O_RDONLY);
|
fd = ::open(zipFileName, O_RDONLY | O_BINARY);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
LOGW("Unable to open zip '%s': %s\n", zipFileName, strerror(errno));
|
LOGW("Unable to open zip '%s': %s\n", zipFileName, strerror(errno));
|
||||||
return NAME_NOT_FOUND;
|
return NAME_NOT_FOUND;
|
||||||
@ -172,8 +188,8 @@ bail:
|
|||||||
*/
|
*/
|
||||||
bool ZipFileRO::mapCentralDirectory(void)
|
bool ZipFileRO::mapCentralDirectory(void)
|
||||||
{
|
{
|
||||||
size_t readAmount = kMaxEOCDSearch;
|
ssize_t readAmount = kMaxEOCDSearch;
|
||||||
if (readAmount > (size_t) mFileLength)
|
if (readAmount > (ssize_t) mFileLength)
|
||||||
readAmount = mFileLength;
|
readAmount = mFileLength;
|
||||||
|
|
||||||
unsigned char* scanBuf = (unsigned char*) malloc(readAmount);
|
unsigned char* scanBuf = (unsigned char*) malloc(readAmount);
|
||||||
@ -233,7 +249,8 @@ bool ZipFileRO::mapCentralDirectory(void)
|
|||||||
}
|
}
|
||||||
actual = TEMP_FAILURE_RETRY(read(mFd, scanBuf, readAmount));
|
actual = TEMP_FAILURE_RETRY(read(mFd, scanBuf, readAmount));
|
||||||
if (actual != (ssize_t) readAmount) {
|
if (actual != (ssize_t) readAmount) {
|
||||||
LOGW("Zip: read %zd failed: %s\n", readAmount, strerror(errno));
|
LOGW("Zip: read " ZD ", expected " ZD ". Failed: %s\n",
|
||||||
|
(ZD_TYPE) actual, (ZD_TYPE) readAmount, strerror(errno));
|
||||||
free(scanBuf);
|
free(scanBuf);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -292,8 +309,8 @@ bool ZipFileRO::mapCentralDirectory(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!mDirectoryMap->create(mFileName, mFd, dirOffset, dirSize, true)) {
|
if (!mDirectoryMap->create(mFileName, mFd, dirOffset, dirSize, true)) {
|
||||||
LOGW("Unable to map '%s' (%zd to %zd): %s\n", mFileName,
|
LOGW("Unable to map '%s' (" ZD " to " ZD "): %s\n", mFileName,
|
||||||
dirOffset, dirOffset + dirSize, strerror(errno));
|
(ZD_TYPE) dirOffset, (ZD_TYPE) (dirOffset + dirSize), strerror(errno));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -350,8 +367,8 @@ bool ZipFileRO::parseZipArchive(void)
|
|||||||
|
|
||||||
ptr += kCDELen + fileNameLen + extraLen + commentLen;
|
ptr += kCDELen + fileNameLen + extraLen + commentLen;
|
||||||
if ((size_t)(ptr - cdPtr) > cdLength) {
|
if ((size_t)(ptr - cdPtr) > cdLength) {
|
||||||
LOGW("bad CD advance (%d vs %zd) at entry %d\n",
|
LOGW("bad CD advance (%d vs " ZD ") at entry %d\n",
|
||||||
(int) (ptr - cdPtr), cdLength, i);
|
(int) (ptr - cdPtr), (ZD_TYPE) cdLength, i);
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -556,8 +573,8 @@ bool ZipFileRO::getEntryInfo(ZipEntryRO entry, int* pMethod, size_t* pUncompLen,
|
|||||||
if (get4LE(lfhBuf) != kLFHSignature) {
|
if (get4LE(lfhBuf) != kLFHSignature) {
|
||||||
off_t actualOffset = lseek(mFd, 0, SEEK_CUR);
|
off_t actualOffset = lseek(mFd, 0, SEEK_CUR);
|
||||||
LOGW("didn't find signature at start of lfh; wanted: offset=%ld data=0x%08x; "
|
LOGW("didn't find signature at start of lfh; wanted: offset=%ld data=0x%08x; "
|
||||||
"got: offset=%zd data=0x%08lx\n",
|
"got: offset=" ZD " data=0x%08lx\n",
|
||||||
localHdrOffset, kLFHSignature, (size_t)actualOffset, get4LE(lfhBuf));
|
localHdrOffset, kLFHSignature, (ZD_TYPE) actualOffset, get4LE(lfhBuf));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -572,16 +589,16 @@ bool ZipFileRO::getEntryInfo(ZipEntryRO entry, int* pMethod, size_t* pUncompLen,
|
|||||||
|
|
||||||
/* check lengths */
|
/* check lengths */
|
||||||
if ((off_t)(dataOffset + compLen) > cdOffset) {
|
if ((off_t)(dataOffset + compLen) > cdOffset) {
|
||||||
LOGW("bad compressed length in zip (%ld + %zd > %ld)\n",
|
LOGW("bad compressed length in zip (%ld + " ZD " > %ld)\n",
|
||||||
(long) dataOffset, compLen, (long) cdOffset);
|
(long) dataOffset, (ZD_TYPE) compLen, (long) cdOffset);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (method == kCompressStored &&
|
if (method == kCompressStored &&
|
||||||
(off_t)(dataOffset + uncompLen) > cdOffset)
|
(off_t)(dataOffset + uncompLen) > cdOffset)
|
||||||
{
|
{
|
||||||
LOGE("ERROR: bad uncompressed length in zip (%ld + %zd > %ld)\n",
|
LOGE("ERROR: bad uncompressed length in zip (%ld + " ZD " > %ld)\n",
|
||||||
(long) dataOffset, uncompLen, (long) cdOffset);
|
(long) dataOffset, (ZD_TYPE) uncompLen, (long) cdOffset);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -732,8 +749,8 @@ bool ZipFileRO::uncompressEntry(ZipEntryRO entry, int fd) const
|
|||||||
LOGE("Write failed: %s\n", strerror(errno));
|
LOGE("Write failed: %s\n", strerror(errno));
|
||||||
goto unmap;
|
goto unmap;
|
||||||
} else if ((size_t) actual != uncompLen) {
|
} else if ((size_t) actual != uncompLen) {
|
||||||
LOGE("Partial write during uncompress (%zd of %zd)\n",
|
LOGE("Partial write during uncompress (" ZD " of " ZD ")\n",
|
||||||
(size_t)actual, (size_t)uncompLen);
|
(ZD_TYPE) actual, (ZD_TYPE) uncompLen);
|
||||||
goto unmap;
|
goto unmap;
|
||||||
} else {
|
} else {
|
||||||
LOGI("+++ successful write\n");
|
LOGI("+++ successful write\n");
|
||||||
@ -802,8 +819,8 @@ bail:
|
|||||||
|
|
||||||
/* paranoia */
|
/* paranoia */
|
||||||
if (zstream.total_out != uncompLen) {
|
if (zstream.total_out != uncompLen) {
|
||||||
LOGW("Size mismatch on inflated file (%ld vs %zd)\n",
|
LOGW("Size mismatch on inflated file (%ld vs " ZD ")\n",
|
||||||
zstream.total_out, uncompLen);
|
zstream.total_out, (ZD_TYPE) uncompLen);
|
||||||
goto z_bail;
|
goto z_bail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -891,8 +908,8 @@ bail:
|
|||||||
|
|
||||||
/* paranoia */
|
/* paranoia */
|
||||||
if (zstream.total_out != uncompLen) {
|
if (zstream.total_out != uncompLen) {
|
||||||
LOGW("Size mismatch on inflated file (%ld vs %zd)\n",
|
LOGW("Size mismatch on inflated file (%ld vs " ZD ")\n",
|
||||||
zstream.total_out, uncompLen);
|
zstream.total_out, (ZD_TYPE) uncompLen);
|
||||||
goto z_bail;
|
goto z_bail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user