summaryrefslogtreecommitdiffstats
path: root/minzip
diff options
context:
space:
mode:
authorTianjie Xu <xunchang@google.com>2016-08-06 03:00:04 +0200
committerTianjie Xu <xunchang@google.com>2016-09-01 23:32:55 +0200
commitc21edd46541a6e1c3b7de43aa6002ea45b90c64a (patch)
tree53763973ea3ef46540e4c1071c6f1f29378d8abd /minzip
parentMerge "Check an edge case when read(2) returns 0" am: 3202b8faf4 am: 852ae8d0fb (diff)
downloadandroid_bootable_recovery-c21edd46541a6e1c3b7de43aa6002ea45b90c64a.tar
android_bootable_recovery-c21edd46541a6e1c3b7de43aa6002ea45b90c64a.tar.gz
android_bootable_recovery-c21edd46541a6e1c3b7de43aa6002ea45b90c64a.tar.bz2
android_bootable_recovery-c21edd46541a6e1c3b7de43aa6002ea45b90c64a.tar.lz
android_bootable_recovery-c21edd46541a6e1c3b7de43aa6002ea45b90c64a.tar.xz
android_bootable_recovery-c21edd46541a6e1c3b7de43aa6002ea45b90c64a.tar.zst
android_bootable_recovery-c21edd46541a6e1c3b7de43aa6002ea45b90c64a.zip
Diffstat (limited to 'minzip')
-rw-r--r--minzip/Android.mk8
-rw-r--r--minzip/Hash.cpp (renamed from minzip/Hash.c)13
-rw-r--r--minzip/Log.h207
-rw-r--r--minzip/SysUtil.cpp (renamed from minzip/SysUtil.c)64
-rw-r--r--minzip/Zip.cpp (renamed from minzip/Zip.c)126
5 files changed, 107 insertions, 311 deletions
diff --git a/minzip/Android.mk b/minzip/Android.mk
index 3d36fd64e..6dbfee993 100644
--- a/minzip/Android.mk
+++ b/minzip/Android.mk
@@ -2,17 +2,17 @@ LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
- Hash.c \
- SysUtil.c \
+ Hash.cpp \
+ SysUtil.cpp \
DirUtil.cpp \
Inlines.c \
- Zip.c
+ Zip.cpp
LOCAL_C_INCLUDES := \
external/zlib \
external/safe-iop/include
-LOCAL_STATIC_LIBRARIES := libselinux
+LOCAL_STATIC_LIBRARIES := libselinux libbase
LOCAL_MODULE := libminzip
diff --git a/minzip/Hash.c b/minzip/Hash.cpp
index 49bcb3161..ac08935d4 100644
--- a/minzip/Hash.c
+++ b/minzip/Hash.cpp
@@ -8,8 +8,8 @@
#include <stdlib.h>
#include <assert.h>
-#define LOG_TAG "minzip"
-#include "Log.h"
+#include <android-base/logging.h>
+
#include "Hash.h"
/* table load factor, i.e. how full can it get before we resize */
@@ -220,8 +220,7 @@ void* mzHashTableLookup(HashTable* pHashTable, unsigned int itemHash, void* item
{
if (!resizeHash(pHashTable, pHashTable->tableSize * 2)) {
/* don't really have a way to indicate failure */
- LOGE("Dalvik hash resize failure\n");
- abort();
+ LOG(FATAL) << "Hash resize failure";
}
/* note "pEntry" is now invalid */
}
@@ -373,7 +372,7 @@ void mzHashTableProbeCount(HashTable* pHashTable, HashCalcFunc calcFunc,
totalProbe += count;
}
- LOGV("Probe: min=%d max=%d, total=%d in %d (%d), avg=%.3f\n",
- minProbe, maxProbe, totalProbe, numEntries, pHashTable->tableSize,
- (float) totalProbe / (float) numEntries);
+ LOG(VERBOSE) << "Probe: min=" << minProbe << ", max=" << maxProbe << ", total="
+ << totalProbe <<" in " << numEntries << " (" << pHashTable->tableSize
+ << "), avg=" << (float) totalProbe / (float) numEntries;
}
diff --git a/minzip/Log.h b/minzip/Log.h
deleted file mode 100644
index 36e62f594..000000000
--- a/minzip/Log.h
+++ /dev/null
@@ -1,207 +0,0 @@
-//
-// Copyright 2005 The Android Open Source Project
-//
-// C/C++ logging functions. See the logging documentation for API details.
-//
-// We'd like these to be available from C code (in case we import some from
-// somewhere), so this has a C interface.
-//
-// The output will be correct when the log file is shared between multiple
-// threads and/or multiple processes so long as the operating system
-// supports O_APPEND. These calls have mutex-protected data structures
-// and so are NOT reentrant. Do not use LOG in a signal handler.
-//
-#ifndef _MINZIP_LOG_H
-#define _MINZIP_LOG_H
-
-#include <stdio.h>
-
-// ---------------------------------------------------------------------
-
-/*
- * Normally we strip LOGV (VERBOSE messages) from release builds.
- * You can modify this (for example with "#define LOG_NDEBUG 0"
- * at the top of your source file) to change that behavior.
- */
-#ifndef LOG_NDEBUG
-#ifdef NDEBUG
-#define LOG_NDEBUG 1
-#else
-#define LOG_NDEBUG 0
-#endif
-#endif
-
-/*
- * This is the local tag used for the following simplified
- * logging macros. You can change this preprocessor definition
- * before using the other macros to change the tag.
- */
-#ifndef LOG_TAG
-#define LOG_TAG NULL
-#endif
-
-// ---------------------------------------------------------------------
-
-/*
- * Simplified macro to send a verbose log message using the current LOG_TAG.
- */
-#ifndef LOGV
-#if LOG_NDEBUG
-#define LOGV(...) ((void)0)
-#else
-#define LOGV(...) ((void)LOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
-#endif
-#endif
-
-#define CONDITION(cond) (__builtin_expect((cond)!=0, 0))
-
-#ifndef LOGV_IF
-#if LOG_NDEBUG
-#define LOGV_IF(cond, ...) ((void)0)
-#else
-#define LOGV_IF(cond, ...) \
- ( (CONDITION(cond)) \
- ? ((void)LOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
- : (void)0 )
-#endif
-#endif
-
-#define LOGVV LOGV
-#define LOGVV_IF LOGV_IF
-
-/*
- * Simplified macro to send a debug log message using the current LOG_TAG.
- */
-#ifndef LOGD
-#define LOGD(...) ((void)LOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
-#endif
-
-#ifndef LOGD_IF
-#define LOGD_IF(cond, ...) \
- ( (CONDITION(cond)) \
- ? ((void)LOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
- : (void)0 )
-#endif
-
-/*
- * Simplified macro to send an info log message using the current LOG_TAG.
- */
-#ifndef LOGI
-#define LOGI(...) ((void)LOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
-#endif
-
-#ifndef LOGI_IF
-#define LOGI_IF(cond, ...) \
- ( (CONDITION(cond)) \
- ? ((void)LOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
- : (void)0 )
-#endif
-
-/*
- * Simplified macro to send a warning log message using the current LOG_TAG.
- */
-#ifndef LOGW
-#define LOGW(...) ((void)LOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
-#endif
-
-#ifndef LOGW_IF
-#define LOGW_IF(cond, ...) \
- ( (CONDITION(cond)) \
- ? ((void)LOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
- : (void)0 )
-#endif
-
-/*
- * Simplified macro to send an error log message using the current LOG_TAG.
- */
-#ifndef LOGE
-#define LOGE(...) ((void)LOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
-#endif
-
-#ifndef LOGE_IF
-#define LOGE_IF(cond, ...) \
- ( (CONDITION(cond)) \
- ? ((void)LOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
- : (void)0 )
-#endif
-
-
-/*
- * Conditional based on whether the current LOG_TAG is enabled at
- * verbose priority.
- */
-#ifndef IF_LOGV
-#if LOG_NDEBUG
-#define IF_LOGV() if (false)
-#else
-#define IF_LOGV() IF_LOG(LOG_VERBOSE, LOG_TAG)
-#endif
-#endif
-
-/*
- * Conditional based on whether the current LOG_TAG is enabled at
- * debug priority.
- */
-#ifndef IF_LOGD
-#define IF_LOGD() IF_LOG(LOG_DEBUG, LOG_TAG)
-#endif
-
-/*
- * Conditional based on whether the current LOG_TAG is enabled at
- * info priority.
- */
-#ifndef IF_LOGI
-#define IF_LOGI() IF_LOG(LOG_INFO, LOG_TAG)
-#endif
-
-/*
- * Conditional based on whether the current LOG_TAG is enabled at
- * warn priority.
- */
-#ifndef IF_LOGW
-#define IF_LOGW() IF_LOG(LOG_WARN, LOG_TAG)
-#endif
-
-/*
- * Conditional based on whether the current LOG_TAG is enabled at
- * error priority.
- */
-#ifndef IF_LOGE
-#define IF_LOGE() IF_LOG(LOG_ERROR, LOG_TAG)
-#endif
-
-// ---------------------------------------------------------------------
-
-/*
- * Basic log message macro.
- *
- * Example:
- * LOG(LOG_WARN, NULL, "Failed with error %d", errno);
- *
- * The second argument may be NULL or "" to indicate the "global" tag.
- *
- * Non-gcc probably won't have __FUNCTION__. It's not vital. gcc also
- * offers __PRETTY_FUNCTION__, which is rather more than we need.
- */
-#ifndef LOG
-#define LOG(priority, tag, ...) \
- LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__)
-#endif
-
-/*
- * Log macro that allows you to specify a number for the priority.
- */
-#ifndef LOG_PRI
-#define LOG_PRI(priority, tag, ...) \
- printf(tag ": " __VA_ARGS__)
-#endif
-
-/*
- * Conditional given a desired logging priority and tag.
- */
-#ifndef IF_LOG
-#define IF_LOG(priority, tag) \
- if (1)
-#endif
-
-#endif // _MINZIP_LOG_H
diff --git a/minzip/SysUtil.c b/minzip/SysUtil.cpp
index e7dd17b51..4cdd60d9f 100644
--- a/minzip/SysUtil.c
+++ b/minzip/SysUtil.cpp
@@ -16,8 +16,8 @@
#include <sys/types.h>
#include <unistd.h>
-#define LOG_TAG "sysutil"
-#include "Log.h"
+#include <android-base/logging.h>
+
#include "SysUtil.h"
static bool sysMapFD(int fd, MemMapping* pMap) {
@@ -25,22 +25,22 @@ static bool sysMapFD(int fd, MemMapping* pMap) {
struct stat sb;
if (fstat(fd, &sb) == -1) {
- LOGE("fstat(%d) failed: %s\n", fd, strerror(errno));
+ PLOG(ERROR) << "fstat(" << fd << ") failed";
return false;
}
void* memPtr = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
if (memPtr == MAP_FAILED) {
- LOGE("mmap(%d, R, PRIVATE, %d, 0) failed: %s\n", (int) sb.st_size, fd, strerror(errno));
+ PLOG(ERROR) << "mmap(" << sb.st_size << ", R, PRIVATE, " << fd << ", 0) failed";
return false;
}
- pMap->addr = memPtr;
+ pMap->addr = reinterpret_cast<unsigned char*>(memPtr);
pMap->length = sb.st_size;
pMap->range_count = 1;
- pMap->ranges = malloc(sizeof(MappedRange));
+ pMap->ranges = reinterpret_cast<MappedRange*>(malloc(sizeof(MappedRange)));
if (pMap->ranges == NULL) {
- LOGE("malloc failed: %s\n", strerror(errno));
+ PLOG(ERROR) << "malloc failed";
munmap(memPtr, sb.st_size);
return false;
}
@@ -60,7 +60,7 @@ static int sysMapBlockFile(FILE* mapf, MemMapping* pMap)
unsigned int i;
if (fgets(block_dev, sizeof(block_dev), mapf) == NULL) {
- LOGE("failed to read block device from header\n");
+ PLOG(ERROR) << "failed to read block device from header";
return -1;
}
for (i = 0; i < sizeof(block_dev); ++i) {
@@ -71,37 +71,37 @@ static int sysMapBlockFile(FILE* mapf, MemMapping* pMap)
}
if (fscanf(mapf, "%zu %u\n%u\n", &size, &blksize, &range_count) != 3) {
- LOGE("failed to parse block map header\n");
+ LOG(ERROR) << "failed to parse block map header";
return -1;
}
if (blksize != 0) {
blocks = ((size-1) / blksize) + 1;
}
if (size == 0 || blksize == 0 || blocks > SIZE_MAX / blksize || range_count == 0) {
- LOGE("invalid data in block map file: size %zu, blksize %u, range_count %u\n",
- size, blksize, range_count);
+ LOG(ERROR) << "invalid data in block map file: size " << size << ", blksize " << blksize
+ << ", range_count " << range_count;
return -1;
}
pMap->range_count = range_count;
- pMap->ranges = calloc(range_count, sizeof(MappedRange));
+ pMap->ranges = reinterpret_cast<MappedRange*>(calloc(range_count, sizeof(MappedRange)));
if (pMap->ranges == NULL) {
- LOGE("calloc(%u, %zu) failed: %s\n", range_count, sizeof(MappedRange), strerror(errno));
+ PLOG(ERROR) << "calloc(" << range_count << ", " << sizeof(MappedRange) << ") failed";
return -1;
}
// Reserve enough contiguous address space for the whole file.
- unsigned char* reserve;
- reserve = mmap64(NULL, blocks * blksize, PROT_NONE, MAP_PRIVATE | MAP_ANON, -1, 0);
+ unsigned char* reserve = reinterpret_cast<unsigned char*>(mmap64(NULL, blocks * blksize,
+ PROT_NONE, MAP_PRIVATE | MAP_ANON, -1, 0));
if (reserve == MAP_FAILED) {
- LOGE("failed to reserve address space: %s\n", strerror(errno));
+ PLOG(ERROR) << "failed to reserve address space";
free(pMap->ranges);
return -1;
}
int fd = open(block_dev, O_RDONLY);
if (fd < 0) {
- LOGE("failed to open block device %s: %s\n", block_dev, strerror(errno));
+ PLOG(ERROR) << "failed to open block device " << block_dev;
munmap(reserve, blocks * blksize);
free(pMap->ranges);
return -1;
@@ -113,20 +113,20 @@ static int sysMapBlockFile(FILE* mapf, MemMapping* pMap)
for (i = 0; i < range_count; ++i) {
size_t start, end;
if (fscanf(mapf, "%zu %zu\n", &start, &end) != 2) {
- LOGE("failed to parse range %d in block map\n", i);
+ LOG(ERROR) << "failed to parse range " << i << " in block map";
success = false;
break;
}
size_t length = (end - start) * blksize;
- if (end <= start || (end - start) > SIZE_MAX / blksize || length > remaining_size) {
- LOGE("unexpected range in block map: %zu %zu\n", start, end);
- success = false;
- break;
+ if (end <= start || ((end - start) > SIZE_MAX / blksize) || length > remaining_size) {
+ LOG(ERROR) << "unexpected range in block map: " << start << " " << end;
+ success = false;
+ break;
}
void* addr = mmap64(next, length, PROT_READ, MAP_PRIVATE | MAP_FIXED, fd, ((off64_t)start)*blksize);
if (addr == MAP_FAILED) {
- LOGE("failed to map block %d: %s\n", i, strerror(errno));
+ PLOG(ERROR) << "failed to map block " << i;
success = false;
break;
}
@@ -137,8 +137,8 @@ static int sysMapBlockFile(FILE* mapf, MemMapping* pMap)
remaining_size -= length;
}
if (success && remaining_size != 0) {
- LOGE("ranges in block map are invalid: remaining_size = %zu\n", remaining_size);
- success = false;
+ LOG(ERROR) << "ranges in block map are invalid: remaining_size = " << remaining_size;
+ success = false;
}
if (!success) {
close(fd);
@@ -151,7 +151,7 @@ static int sysMapBlockFile(FILE* mapf, MemMapping* pMap)
pMap->addr = reserve;
pMap->length = size;
- LOGI("mmapped %d ranges\n", range_count);
+ LOG(INFO) << "mmapped " << range_count << " ranges";
return 0;
}
@@ -164,12 +164,12 @@ int sysMapFile(const char* fn, MemMapping* pMap)
// A map of blocks
FILE* mapf = fopen(fn+1, "r");
if (mapf == NULL) {
- LOGE("Unable to open '%s': %s\n", fn+1, strerror(errno));
+ PLOG(ERROR) << "Unable to open '" << (fn+1) << "'";
return -1;
}
if (sysMapBlockFile(mapf, pMap) != 0) {
- LOGE("Map of '%s' failed\n", fn);
+ LOG(ERROR) << "Map of '" << fn << "' failed";
fclose(mapf);
return -1;
}
@@ -179,12 +179,12 @@ int sysMapFile(const char* fn, MemMapping* pMap)
// This is a regular file.
int fd = open(fn, O_RDONLY);
if (fd == -1) {
- LOGE("Unable to open '%s': %s\n", fn, strerror(errno));
+ PLOG(ERROR) << "Unable to open '" << fn << "'";
return -1;
}
if (!sysMapFD(fd, pMap)) {
- LOGE("Map of '%s' failed\n", fn);
+ LOG(ERROR) << "Map of '" << fn << "' failed";
close(fd);
return -1;
}
@@ -202,8 +202,8 @@ void sysReleaseMap(MemMapping* pMap)
int i;
for (i = 0; i < pMap->range_count; ++i) {
if (munmap(pMap->ranges[i].addr, pMap->ranges[i].length) < 0) {
- LOGE("munmap(%p, %d) failed: %s\n",
- pMap->ranges[i].addr, (int)pMap->ranges[i].length, strerror(errno));
+ PLOG(ERROR) << "munmap(" << pMap->ranges[i].addr << ", " << pMap->ranges[i].length
+ << ") failed";
}
}
free(pMap->ranges);
diff --git a/minzip/Zip.c b/minzip/Zip.cpp
index d557daa7f..b887b8466 100644
--- a/minzip/Zip.c
+++ b/minzip/Zip.cpp
@@ -14,18 +14,18 @@
#include <sys/stat.h> // for S_ISLNK()
#include <unistd.h>
-#define LOG_TAG "minzip"
-#include "Zip.h"
-#include "Bits.h"
-#include "Log.h"
-#include "DirUtil.h"
+#include <string>
-#undef NDEBUG // do this after including Log.h
+#include <android-base/logging.h>
+#include <android-base/stringprintf.h>
#include <assert.h>
-
#include <selinux/label.h>
#include <selinux/selinux.h>
+#include "Zip.h"
+#include "Bits.h"
+#include "DirUtil.h"
+
#define SORT_ENTRIES 1
/*
@@ -154,8 +154,9 @@ static void addEntryToHashTable(HashTable* pHash, ZipEntry* pEntry)
found = (const ZipEntry*)mzHashTableLookup(pHash,
itemHash, pEntry, hashcmpZipEntry, true);
if (found != pEntry) {
- LOGW("WARNING: duplicate entry '%.*s' in Zip\n",
- found->fileNameLen, found->fileName);
+ LOG(WARNING) << "WARNING: duplicate entry '" << std::string(found->fileName,
+ found->fileNameLen) << "' in Zip";
+
/* keep going */
}
}
@@ -164,7 +165,7 @@ static int validFilename(const char *fileName, unsigned int fileNameLen)
{
// Forbid super long filenames.
if (fileNameLen >= PATH_MAX) {
- LOGW("Filename too long (%d chatacters)\n", fileNameLen);
+ LOG(WARNING) << "Filename too long (" << fileNameLen << " chatacters)";
return 0;
}
@@ -172,7 +173,8 @@ static int validFilename(const char *fileName, unsigned int fileNameLen)
unsigned int i;
for (i = 0; i < fileNameLen; ++i) {
if (fileName[i] < 32 || fileName[i] >= 127) {
- LOGW("Filename contains invalid character '\%03o'\n", fileName[i]);
+ LOG(WARNING) << android::base::StringPrintf(
+ "Filename contains invalid character '\%02x'\n", fileName[i]);
return 0;
}
}
@@ -201,10 +203,10 @@ static bool parseZipArchive(ZipArchive* pArchive)
*/
val = get4LE(pArchive->addr);
if (val == ENDSIG) {
- LOGW("Found Zip archive, but it looks empty\n");
+ LOG(WARNING) << "Found Zip archive, but it looks empty";
goto bail;
} else if (val != LOCSIG) {
- LOGW("Not a Zip archive (found 0x%08x)\n", val);
+ LOG(WARNING) << android::base::StringPrintf("Not a Zip archive (found 0x%08x)\n", val);
goto bail;
}
@@ -220,7 +222,7 @@ static bool parseZipArchive(ZipArchive* pArchive)
ptr--;
}
if (ptr < (const unsigned char*) pArchive->addr) {
- LOGW("Could not find end-of-central-directory in Zip\n");
+ LOG(WARNING) << "Could not find end-of-central-directory in Zip";
goto bail;
}
@@ -232,10 +234,10 @@ static bool parseZipArchive(ZipArchive* pArchive)
numEntries = get2LE(ptr + ENDSUB);
cdOffset = get4LE(ptr + ENDOFF);
- LOGVV("numEntries=%d cdOffset=%d\n", numEntries, cdOffset);
+ LOG(VERBOSE) << "numEntries=" << numEntries << " cdOffset=" << cdOffset;
if (numEntries == 0 || cdOffset >= pArchive->length) {
- LOGW("Invalid entries=%d offset=%d (len=%zd)\n",
- numEntries, cdOffset, pArchive->length);
+ LOG(WARNING) << "Invalid entries=" << numEntries << " offset=" << cdOffset
+ << " (len=" << pArchive->length << ")";
goto bail;
}
@@ -256,11 +258,11 @@ static bool parseZipArchive(ZipArchive* pArchive)
const char *fileName;
if (ptr + CENHDR > (const unsigned char*)pArchive->addr + pArchive->length) {
- LOGW("Ran off the end (at %d)\n", i);
+ LOG(WARNING) << "Ran off the end (at " << i << ")";
goto bail;
}
if (get4LE(ptr) != CENSIG) {
- LOGW("Missed a central dir sig (at %d)\n", i);
+ LOG(WARNING) << "Missed a central dir sig (at " << i << ")";
goto bail;
}
@@ -270,11 +272,11 @@ static bool parseZipArchive(ZipArchive* pArchive)
commentLen = get2LE(ptr + CENCOM);
fileName = (const char*)ptr + CENHDR;
if (fileName + fileNameLen > (const char*)pArchive->addr + pArchive->length) {
- LOGW("Filename ran off the end (at %d)\n", i);
+ LOG(WARNING) << "Filename ran off the end (at " << i << ")";
goto bail;
}
if (!validFilename(fileName, fileNameLen)) {
- LOGW("Invalid filename (at %d)\n", i);
+ LOG(WARNING) << "Invalid filename (at " << i << ")";
goto bail;
}
@@ -345,7 +347,8 @@ static bool parseZipArchive(ZipArchive* pArchive)
if ((pEntry->versionMadeBy & 0xff00) != 0 &&
(pEntry->versionMadeBy & 0xff00) != CENVEM_UNIX)
{
- LOGW("Incompatible \"version made by\": 0x%02x (at %d)\n",
+ LOG(WARNING) << android::base::StringPrintf(
+ "Incompatible \"version made by\": 0x%02x (at %d)\n",
pEntry->versionMadeBy >> 8, i);
goto bail;
}
@@ -355,26 +358,27 @@ static bool parseZipArchive(ZipArchive* pArchive)
// overflow. This is needed because localHdrOffset is untrusted.
if (!safe_add((uintptr_t *)&localHdr, (uintptr_t)pArchive->addr,
(uintptr_t)localHdrOffset)) {
- LOGW("Integer overflow adding in parseZipArchive\n");
+ LOG(WARNING) << "Integer overflow adding in parseZipArchive";
goto bail;
}
if ((uintptr_t)localHdr + LOCHDR >
(uintptr_t)pArchive->addr + pArchive->length) {
- LOGW("Bad offset to local header: %d (at %d)\n", localHdrOffset, i);
+ LOG(WARNING) << "Bad offset to local header: " << localHdrOffset
+ << " (at " << i << ")";
goto bail;
}
if (get4LE(localHdr) != LOCSIG) {
- LOGW("Missed a local header sig (at %d)\n", i);
+ LOG(WARNING) << "Missed a local header sig (at " << i << ")";
goto bail;
}
pEntry->offset = localHdrOffset + LOCHDR
+ get2LE(localHdr + LOCNAM) + get2LE(localHdr + LOCEXT);
if (!safe_add(NULL, pEntry->offset, pEntry->compLen)) {
- LOGW("Integer overflow adding in parseZipArchive\n");
+ LOG(WARNING) << "Integer overflow adding in parseZipArchive";
goto bail;
}
if ((size_t)pEntry->offset + pEntry->compLen > pArchive->length) {
- LOGW("Data ran off the end (at %d)\n", i);
+ LOG(WARNING) << "Data ran off the end (at " << i << ")";
goto bail;
}
@@ -432,7 +436,8 @@ int mzOpenZipArchive(unsigned char* addr, size_t length, ZipArchive* pArchive)
if (length < ENDHDR) {
err = -1;
- LOGW("Archive %p is too small to be zip (%zd)\n", pArchive, length);
+ LOG(WARNING) << "Archive " << pArchive << " is too small to be zip ("
+ << length << ")";
goto bail;
}
@@ -441,7 +446,7 @@ int mzOpenZipArchive(unsigned char* addr, size_t length, ZipArchive* pArchive)
if (!parseZipArchive(pArchive)) {
err = -1;
- LOGW("Parsing archive %p failed\n", pArchive);
+ LOG(WARNING) << "Parsing archive " << pArchive << " failed";
goto bail;
}
@@ -460,7 +465,7 @@ bail:
*/
void mzCloseZipArchive(ZipArchive* pArchive)
{
- LOGV("Closing archive %p\n", pArchive);
+ LOG(VERBOSE) << "Closing archive " << pArchive;
free(pArchive->pEntries);
@@ -534,10 +539,10 @@ static bool processDeflatedEntry(const ZipArchive *pArchive,
zerr = inflateInit2(&zstream, -MAX_WBITS);
if (zerr != Z_OK) {
if (zerr == Z_VERSION_ERROR) {
- LOGE("Installed zlib is not compatible with linked version (%s)\n",
- ZLIB_VERSION);
+ LOG(ERROR) << "Installed zlib is not compatible with linked version ("
+ << ZLIB_VERSION << ")";
} else {
- LOGE("Call to inflateInit2 failed (zerr=%d)\n", zerr);
+ LOG(ERROR) << "Call to inflateInit2 failed (zerr=" << zerr << ")";
}
goto bail;
}
@@ -549,7 +554,7 @@ static bool processDeflatedEntry(const ZipArchive *pArchive,
/* uncompress the data */
zerr = inflate(&zstream, Z_NO_FLUSH);
if (zerr != Z_OK && zerr != Z_STREAM_END) {
- LOGW("zlib inflate call failed (zerr=%d)\n", zerr);
+ LOG(WARNING) << "zlib inflate call failed (zerr=" << zerr << ")";
goto z_bail;
}
@@ -558,10 +563,10 @@ static bool processDeflatedEntry(const ZipArchive *pArchive,
(zerr == Z_STREAM_END && zstream.avail_out != sizeof(procBuf)))
{
long procSize = zstream.next_out - procBuf;
- LOGVV("+++ processing %d bytes\n", (int) procSize);
+ LOG(VERBOSE) << "+++ processing " << procSize << " bytes";
bool ret = processFunction(procBuf, procSize, cookie);
if (!ret) {
- LOGW("Process function elected to fail (in inflate)\n");
+ LOG(WARNING) << "Process function elected to fail (in inflate)";
goto z_bail;
}
@@ -582,7 +587,8 @@ z_bail:
bail:
if (totalOut != pEntry->uncompLen) {
if (success) { // error already shown?
- LOGW("Size mismatch on inflated file (%lu vs %u)\n", totalOut, pEntry->uncompLen);
+ LOG(WARNING) << "Size mismatch on inflated file (" << totalOut << " vs "
+ << pEntry->uncompLen << ")";
}
return false;
}
@@ -613,8 +619,8 @@ bool mzProcessZipEntryContents(const ZipArchive *pArchive,
ret = processDeflatedEntry(pArchive, pEntry, processFunction, cookie);
break;
default:
- LOGE("Unsupported compression type %d for entry '%s'\n",
- pEntry->compression, pEntry->fileName);
+ LOG(ERROR) << "Unsupported compression type " << pEntry->compression
+ << " for entry '" << pEntry->fileName << "'";
break;
}
@@ -653,7 +659,7 @@ bool mzReadZipEntry(const ZipArchive* pArchive, const ZipEntry* pEntry,
ret = mzProcessZipEntryContents(pArchive, pEntry, copyProcessFunction,
(void *)&args);
if (!ret) {
- LOGE("Can't extract entry to buffer.\n");
+ LOG(ERROR) << "Can't extract entry to buffer";
return false;
}
return true;
@@ -670,15 +676,15 @@ static bool writeProcessFunction(const unsigned char *data, int dataLen,
while (true) {
ssize_t n = TEMP_FAILURE_RETRY(write(fd, data+soFar, dataLen-soFar));
if (n <= 0) {
- LOGE("Error writing %zd bytes from zip file from %p: %s\n",
- dataLen-soFar, data+soFar, strerror(errno));
+ PLOG(ERROR) << "Error writing " << dataLen-soFar << " bytes from zip file from "
+ << data+soFar;
return false;
} else if (n > 0) {
soFar += n;
if (soFar == dataLen) return true;
if (soFar > dataLen) {
- LOGE("write overrun? (%zd bytes instead of %d)\n",
- soFar, dataLen);
+ LOG(ERROR) << "write overrun? (" << soFar << " bytes instead of "
+ << dataLen << ")";
return false;
}
}
@@ -694,7 +700,7 @@ bool mzExtractZipEntryToFile(const ZipArchive *pArchive,
bool ret = mzProcessZipEntryContents(pArchive, pEntry, writeProcessFunction,
(void*)(intptr_t)fd);
if (!ret) {
- LOGE("Can't extract entry to file.\n");
+ LOG(ERROR) << "Can't extract entry to file.";
return false;
}
return true;
@@ -730,7 +736,7 @@ bool mzExtractZipEntryToBuffer(const ZipArchive *pArchive,
bool ret = mzProcessZipEntryContents(pArchive, pEntry,
bufferProcessFunction, (void*)&bec);
if (!ret || bec.len != 0) {
- LOGE("Can't extract entry to memory buffer.\n");
+ LOG(ERROR) << "Can't extract entry to memory buffer.";
return false;
}
return true;
@@ -824,11 +830,11 @@ bool mzExtractRecursive(const ZipArchive *pArchive,
struct selabel_handle *sehnd)
{
if (zipDir[0] == '/') {
- LOGE("mzExtractRecursive(): zipDir must be a relative path.\n");
+ LOG(ERROR) << "mzExtractRecursive(): zipDir must be a relative path.";
return false;
}
if (targetDir[0] != '/') {
- LOGE("mzExtractRecursive(): targetDir must be an absolute path.\n");
+ LOG(ERROR) << "mzExtractRecursive(): targetDir must be an absolute path.\n";
return false;
}
@@ -838,7 +844,7 @@ bool mzExtractRecursive(const ZipArchive *pArchive,
zipDirLen = strlen(zipDir);
zpath = (char *)malloc(zipDirLen + 2);
if (zpath == NULL) {
- LOGE("Can't allocate %d bytes for zip path\n", zipDirLen + 2);
+ LOG(ERROR) << "Can't allocate " << (zipDirLen + 2) << " bytes for zip path";
return false;
}
/* If zipDir is empty, we'll extract the entire zip file.
@@ -917,8 +923,8 @@ bool mzExtractRecursive(const ZipArchive *pArchive,
*/
const char *targetFile = targetEntryPath(&helper, pEntry);
if (targetFile == NULL) {
- LOGE("Can't assemble target path for \"%.*s\"\n",
- pEntry->fileNameLen, pEntry->fileName);
+ LOG(ERROR) << "Can't assemble target path for \"" << std::string(pEntry->fileName,
+ pEntry->fileNameLen) << "\"";
ok = false;
break;
}
@@ -942,8 +948,7 @@ bool mzExtractRecursive(const ZipArchive *pArchive,
int ret = dirCreateHierarchy(
targetFile, UNZIP_DIRMODE, timestamp, true, sehnd);
if (ret != 0) {
- LOGE("Can't create containing directory for \"%s\": %s\n",
- targetFile, strerror(errno));
+ PLOG(ERROR) << "Can't create containing directory for \"" << targetFile << "\"";
ok = false;
break;
}
@@ -957,8 +962,8 @@ bool mzExtractRecursive(const ZipArchive *pArchive,
* warn about this for now and preserve older behavior.
*/
if (mzIsZipEntrySymlink(pEntry)) {
- LOGE("Symlink entry \"%.*s\" will be output as a regular file.",
- pEntry->fileNameLen, pEntry->fileName);
+ LOG(ERROR) << "Symlink entry \"" << std::string(pEntry->fileName,
+ pEntry->fileNameLen) << "\" will be output as a regular file.";
}
char *secontext = NULL;
@@ -977,8 +982,7 @@ bool mzExtractRecursive(const ZipArchive *pArchive,
}
if (fd < 0) {
- LOGE("Can't create target file \"%s\": %s\n",
- targetFile, strerror(errno));
+ PLOG(ERROR) << "Can't create target file \"" << targetFile << "\"";
ok = false;
break;
}
@@ -991,25 +995,25 @@ bool mzExtractRecursive(const ZipArchive *pArchive,
ok = false;
}
if (!ok) {
- LOGE("Error extracting \"%s\"\n", targetFile);
+ LOG(ERROR) << "Error extracting \"" << targetFile << "\"";
ok = false;
break;
}
if (timestamp != NULL && utime(targetFile, timestamp)) {
- LOGE("Error touching \"%s\"\n", targetFile);
+ LOG(ERROR) << "Error touching \"" << targetFile << "\"";
ok = false;
break;
}
- LOGV("Extracted file \"%s\"\n", targetFile);
+ LOG(VERBOSE) <<"Extracted file \"" << targetFile << "\"";
++extractCount;
}
if (callback != NULL) callback(targetFile, cookie);
}
- LOGV("Extracted %d file(s)\n", extractCount);
+ LOG(VERBOSE) << "Extracted " << extractCount << " file(s)";
free(helper.buf);
free(zpath);