Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3673f99d authored by Ryan Prichard's avatar Ryan Prichard
Browse files

Change ZipArchiveHandle from void* to ZipArchive*

A typedef to void* allows an implicit conversion from ZipArchiveHandle*
(or any other pointer type) to ZipArchiveHandle.

See I95d79809b6e118fb3c39c7b98b8055c8e324db1a in platform/bionic.

Bug: none
Test: m checkbuild
Change-Id: I3dd426cb64c46ef81e1dd81b4a2e4f40ac2701df
parent a605668e
Loading
Loading
Loading
Loading
+10 −9
Original line number Original line Diff line number Diff line
@@ -103,7 +103,8 @@ struct ZipEntry {
  off64_t offset;
  off64_t offset;
};
};


typedef void* ZipArchiveHandle;
struct ZipArchive;
typedef ZipArchive* ZipArchiveHandle;


/*
/*
 * Open a Zip archive, and sets handle to the value of the opaque
 * Open a Zip archive, and sets handle to the value of the opaque
@@ -144,7 +145,7 @@ int32_t OpenArchiveFromMemory(void* address, size_t length, const char* debugFil
 * this handle for any further operations without an intervening
 * this handle for any further operations without an intervening
 * call to one of the OpenArchive variants.
 * call to one of the OpenArchive variants.
 */
 */
void CloseArchive(ZipArchiveHandle handle);
void CloseArchive(ZipArchiveHandle archive);


/*
/*
 * Find an entry in the Zip archive, by name. |entryName| must be a null
 * Find an entry in the Zip archive, by name. |entryName| must be a null
@@ -162,7 +163,7 @@ void CloseArchive(ZipArchiveHandle handle);
 * On non-Windows platforms this method does not modify internal state and
 * On non-Windows platforms this method does not modify internal state and
 * can be called concurrently.
 * can be called concurrently.
 */
 */
int32_t FindEntry(const ZipArchiveHandle handle, const ZipString& entryName, ZipEntry* data);
int32_t FindEntry(const ZipArchiveHandle archive, const ZipString& entryName, ZipEntry* data);


/*
/*
 * Start iterating over all entries of a zip file. The order of iteration
 * Start iterating over all entries of a zip file. The order of iteration
@@ -177,8 +178,8 @@ int32_t FindEntry(const ZipArchiveHandle handle, const ZipString& entryName, Zip
 *
 *
 * Returns 0 on success and negative values on failure.
 * Returns 0 on success and negative values on failure.
 */
 */
int32_t StartIteration(ZipArchiveHandle handle, void** cookie_ptr, const ZipString* optional_prefix,
int32_t StartIteration(ZipArchiveHandle archive, void** cookie_ptr,
                       const ZipString* optional_suffix);
                       const ZipString* optional_prefix, const ZipString* optional_suffix);


/*
/*
 * Advance to the next element in the zipfile in iteration order.
 * Advance to the next element in the zipfile in iteration order.
@@ -203,7 +204,7 @@ void EndIteration(void* cookie);
 *
 *
 * Returns 0 on success and negative values on failure.
 * Returns 0 on success and negative values on failure.
 */
 */
int32_t ExtractEntryToFile(ZipArchiveHandle handle, ZipEntry* entry, int fd);
int32_t ExtractEntryToFile(ZipArchiveHandle archive, ZipEntry* entry, int fd);


/**
/**
 * Uncompress a given zip entry to the memory region at |begin| and of
 * Uncompress a given zip entry to the memory region at |begin| and of
@@ -213,9 +214,9 @@ int32_t ExtractEntryToFile(ZipArchiveHandle handle, ZipEntry* entry, int fd);
 *
 *
 * Returns 0 on success and negative values on failure.
 * Returns 0 on success and negative values on failure.
 */
 */
int32_t ExtractToMemory(ZipArchiveHandle handle, ZipEntry* entry, uint8_t* begin, uint32_t size);
int32_t ExtractToMemory(ZipArchiveHandle archive, ZipEntry* entry, uint8_t* begin, uint32_t size);


int GetFileDescriptor(const ZipArchiveHandle handle);
int GetFileDescriptor(const ZipArchiveHandle archive);


const char* ErrorCodeString(int32_t error_code);
const char* ErrorCodeString(int32_t error_code);


@@ -226,7 +227,7 @@ typedef bool (*ProcessZipEntryFunction)(const uint8_t* buf, size_t buf_size, voi
 * Stream the uncompressed data through the supplied function,
 * Stream the uncompressed data through the supplied function,
 * passing cookie to it each time it gets called.
 * passing cookie to it each time it gets called.
 */
 */
int32_t ProcessZipEntryContents(ZipArchiveHandle handle, ZipEntry* entry,
int32_t ProcessZipEntryContents(ZipArchiveHandle archive, ZipEntry* entry,
                                ProcessZipEntryFunction func, void* cookie);
                                ProcessZipEntryFunction func, void* cookie);
#endif
#endif


+13 −18
Original line number Original line Diff line number Diff line
@@ -517,8 +517,7 @@ int32_t OpenArchiveFromMemory(void* address, size_t length, const char* debug_fi
/*
/*
 * Close a ZipArchive, closing the file and freeing the contents.
 * Close a ZipArchive, closing the file and freeing the contents.
 */
 */
void CloseArchive(ZipArchiveHandle handle) {
void CloseArchive(ZipArchiveHandle archive) {
  ZipArchive* archive = reinterpret_cast<ZipArchive*>(handle);
  ALOGV("Closing archive %p", archive);
  ALOGV("Closing archive %p", archive);
  delete archive;
  delete archive;
}
}
@@ -745,10 +744,8 @@ struct IterationHandle {
  }
  }
};
};


int32_t StartIteration(ZipArchiveHandle handle, void** cookie_ptr, const ZipString* optional_prefix,
int32_t StartIteration(ZipArchiveHandle archive, void** cookie_ptr,
                       const ZipString* optional_suffix) {
                       const ZipString* optional_prefix, const ZipString* optional_suffix) {
  ZipArchive* archive = reinterpret_cast<ZipArchive*>(handle);

  if (archive == NULL || archive->hash_table == NULL) {
  if (archive == NULL || archive->hash_table == NULL) {
    ALOGW("Zip: Invalid ZipArchiveHandle");
    ALOGW("Zip: Invalid ZipArchiveHandle");
    return kInvalidHandle;
    return kInvalidHandle;
@@ -766,8 +763,7 @@ void EndIteration(void* cookie) {
  delete reinterpret_cast<IterationHandle*>(cookie);
  delete reinterpret_cast<IterationHandle*>(cookie);
}
}


int32_t FindEntry(const ZipArchiveHandle handle, const ZipString& entryName, ZipEntry* data) {
int32_t FindEntry(const ZipArchiveHandle archive, const ZipString& entryName, ZipEntry* data) {
  const ZipArchive* archive = reinterpret_cast<ZipArchive*>(handle);
  if (entryName.name_length == 0) {
  if (entryName.name_length == 0) {
    ALOGW("Zip: Invalid filename %.*s", entryName.name_length, entryName.name);
    ALOGW("Zip: Invalid filename %.*s", entryName.name_length, entryName.name);
    return kInvalidEntryName;
    return kInvalidEntryName;
@@ -1116,8 +1112,7 @@ static int32_t CopyEntryToWriter(MappedZipFile& mapped_zip, const ZipEntry* entr
  return 0;
  return 0;
}
}


int32_t ExtractToWriter(ZipArchiveHandle handle, ZipEntry* entry, zip_archive::Writer* writer) {
int32_t ExtractToWriter(ZipArchiveHandle archive, ZipEntry* entry, zip_archive::Writer* writer) {
  ZipArchive* archive = reinterpret_cast<ZipArchive*>(handle);
  const uint16_t method = entry->method;
  const uint16_t method = entry->method;


  // this should default to kUnknownCompressionMethod.
  // this should default to kUnknownCompressionMethod.
@@ -1145,18 +1140,18 @@ int32_t ExtractToWriter(ZipArchiveHandle handle, ZipEntry* entry, zip_archive::W
  return return_value;
  return return_value;
}
}


int32_t ExtractToMemory(ZipArchiveHandle handle, ZipEntry* entry, uint8_t* begin, uint32_t size) {
int32_t ExtractToMemory(ZipArchiveHandle archive, ZipEntry* entry, uint8_t* begin, uint32_t size) {
  MemoryWriter writer(begin, size);
  MemoryWriter writer(begin, size);
  return ExtractToWriter(handle, entry, &writer);
  return ExtractToWriter(archive, entry, &writer);
}
}


int32_t ExtractEntryToFile(ZipArchiveHandle handle, ZipEntry* entry, int fd) {
int32_t ExtractEntryToFile(ZipArchiveHandle archive, ZipEntry* entry, int fd) {
  auto writer = FileWriter::Create(fd, entry);
  auto writer = FileWriter::Create(fd, entry);
  if (!writer.IsValid()) {
  if (!writer.IsValid()) {
    return kIoError;
    return kIoError;
  }
  }


  return ExtractToWriter(handle, entry, &writer);
  return ExtractToWriter(archive, entry, &writer);
}
}


const char* ErrorCodeString(int32_t error_code) {
const char* ErrorCodeString(int32_t error_code) {
@@ -1173,8 +1168,8 @@ const char* ErrorCodeString(int32_t error_code) {
  return "Unknown return code";
  return "Unknown return code";
}
}


int GetFileDescriptor(const ZipArchiveHandle handle) {
int GetFileDescriptor(const ZipArchiveHandle archive) {
  return reinterpret_cast<ZipArchive*>(handle)->mapped_zip.GetFileDescriptor();
  return archive->mapped_zip.GetFileDescriptor();
}
}


ZipString::ZipString(const char* entry_name) : name(reinterpret_cast<const uint8_t*>(entry_name)) {
ZipString::ZipString(const char* entry_name) : name(reinterpret_cast<const uint8_t*>(entry_name)) {
@@ -1198,10 +1193,10 @@ class ProcessWriter : public zip_archive::Writer {
  void* cookie_;
  void* cookie_;
};
};


int32_t ProcessZipEntryContents(ZipArchiveHandle handle, ZipEntry* entry,
int32_t ProcessZipEntryContents(ZipArchiveHandle archive, ZipEntry* entry,
                                ProcessZipEntryFunction func, void* cookie) {
                                ProcessZipEntryFunction func, void* cookie) {
  ProcessWriter writer(func, cookie);
  ProcessWriter writer(func, cookie);
  return ExtractToWriter(handle, entry, &writer);
  return ExtractToWriter(archive, entry, &writer);
}
}


#endif  //! defined(_WIN32)
#endif  //! defined(_WIN32)