From 8e08536108d2b5a7f4f9a4b008987b54602fda18 Mon Sep 17 00:00:00 2001 From: Piotr Jastrzebski Date: Mon, 18 Aug 2014 11:37:45 +0100 Subject: [PATCH] Fix win_sdk build by not using vector Change-Id: I4e9ee4286ea29e1f5f2ee477525e79bfa16ad9a0 --- libziparchive/Android.mk | 2 -- libziparchive/zip_archive.cc | 30 ++++++++++++++++++++---------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/libziparchive/Android.mk b/libziparchive/Android.mk index 684c635b3..d96bc63ed 100644 --- a/libziparchive/Android.mk +++ b/libziparchive/Android.mk @@ -31,7 +31,6 @@ LOCAL_MODULE:= libziparchive LOCAL_C_INCLUDES += ${includes} LOCAL_CFLAGS := -Werror -include external/libcxx/libcxx.mk include $(BUILD_STATIC_LIBRARY) include $(CLEAR_VARS) @@ -44,7 +43,6 @@ LOCAL_STATIC_LIBRARIES := libz libutils LOCAL_MODULE:= libziparchive-host LOCAL_CFLAGS := -Werror LOCAL_MULTILIB := both -include external/libcxx/libcxx.mk include $(BUILD_HOST_STATIC_LIBRARY) include $(CLEAR_VARS) diff --git a/libziparchive/zip_archive.cc b/libziparchive/zip_archive.cc index cbe1b14ae..24088bb93 100644 --- a/libziparchive/zip_archive.cc +++ b/libziparchive/zip_archive.cc @@ -29,7 +29,6 @@ #include #include #include -#include #include #include // TEMP_FAILURE_RETRY may or may not be in unistd @@ -889,8 +888,23 @@ static int32_t FindEntry(const ZipArchive* archive, const int ent, struct IterationHandle { uint32_t position; - std::vector prefix; + const uint8_t* prefix; + uint16_t prefix_len; ZipArchive* archive; + + IterationHandle() : prefix(NULL), prefix_len(0) {} + + IterationHandle(const ZipEntryName& prefix_name) + : prefix_len(prefix_name.name_length) { + uint8_t* prefix_copy = new uint8_t[prefix_len]; + memcpy(reinterpret_cast(prefix_copy), prefix_name.name, + prefix_len * sizeof(uint8_t)); + prefix = prefix_copy; + } + + ~IterationHandle() { + delete [] prefix; + } }; int32_t StartIteration(ZipArchiveHandle handle, void** cookie_ptr, @@ -902,14 +916,10 @@ int32_t StartIteration(ZipArchiveHandle handle, void** cookie_ptr, return kInvalidHandle; } - IterationHandle* cookie = new IterationHandle(); + IterationHandle* cookie = + optional_prefix != NULL ? new IterationHandle(*optional_prefix) : new IterationHandle(); cookie->position = 0; cookie->archive = archive; - if (optional_prefix != NULL) { - cookie->prefix.insert(cookie->prefix.begin(), - optional_prefix->name, - optional_prefix->name + optional_prefix->name_length); - } *cookie_ptr = cookie ; return 0; @@ -956,8 +966,8 @@ int32_t Next(void* cookie, ZipEntry* data, ZipEntryName* name) { for (uint32_t i = currentOffset; i < hash_table_length; ++i) { if (hash_table[i].name != NULL && - (handle->prefix.empty() || - (memcmp(&(handle->prefix[0]), hash_table[i].name, handle->prefix.size()) == 0))) { + (handle->prefix_len == 0 || + (memcmp(handle->prefix, hash_table[i].name, handle->prefix_len) == 0))) { handle->position = (i + 1); const int error = FindEntry(archive, i, data); if (!error) {