blob: e293bf0f9bab7c02e8912a0c6f368f02fcd99641 [file] [log] [blame]
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Andy McFadden80a4e242010-04-23 16:34:52 -070016
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080017/*
18 * Read-only access to Zip archives, with minimal heap allocation.
19 */
Carl Shapiro375fb112011-06-14 20:31:24 -070020#ifndef LIBDEX_ZIPARCHIVE_H_
21#define LIBDEX_ZIPARCHIVE_H_
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080022
Narayan Kamath39e8b7e2013-12-17 10:03:19 +000023#include <ziparchive/zip_archive.h>
24
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080025#include "SysUtil.h"
26#include "DexFile.h" // need DEX_INLINE
27
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080028/*
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080029 * Open a Zip archive.
30 *
31 * On success, returns 0 and populates "pArchive". Returns nonzero errno
32 * value on failure.
33 */
Narayan Kamath39e8b7e2013-12-17 10:03:19 +000034DEX_INLINE int dexZipOpenArchive(const char* fileName, ZipArchiveHandle* pArchive) {
35 return OpenArchive(fileName, pArchive);
36}
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080037
38/*
39 * Like dexZipOpenArchive, but takes a file descriptor open for reading
40 * at the start of the file. The descriptor must be mappable (this does
41 * not allow access to a stream).
42 *
43 * "debugFileName" will appear in error messages, but is not otherwise used.
44 */
Narayan Kamath39e8b7e2013-12-17 10:03:19 +000045DEX_INLINE int dexZipOpenArchiveFd(int fd, const char* debugFileName,
46 ZipArchiveHandle* pArchive) {
47 return OpenArchiveFd(fd, debugFileName, pArchive);
48}
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080049
50/*
51 * Close archive, releasing resources associated with it.
52 *
53 * Depending on the implementation this could unmap pages used by classes
54 * stored in a Jar. This should only be done after unloading classes.
55 */
Narayan Kamath39e8b7e2013-12-17 10:03:19 +000056DEX_INLINE void dexZipCloseArchive(ZipArchiveHandle archive) {
57 CloseArchive(archive);
58}
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080059
60/*
61 * Return the archive's file descriptor.
62 */
Narayan Kamath39e8b7e2013-12-17 10:03:19 +000063DEX_INLINE int dexZipGetArchiveFd(const ZipArchiveHandle pArchive) {
64 return GetFileDescriptor(pArchive);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080065}
66
67/*
68 * Find an entry in the Zip archive, by name. Returns NULL if the entry
69 * was not found.
70 */
Narayan Kamath39e8b7e2013-12-17 10:03:19 +000071DEX_INLINE int dexZipFindEntry(const ZipArchiveHandle pArchive,
72 const char* entryName, ZipEntry* data) {
Piotr Jastrzebski2e2f03c2014-08-13 10:00:59 +010073 return FindEntry(pArchive, ZipEntryName(entryName), data);
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080074}
75
76/*
77 * Uncompress and write an entry to a file descriptor.
Andy McFadden80a4e242010-04-23 16:34:52 -070078 *
79 * Returns 0 on success.
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080080 */
Narayan Kamath39e8b7e2013-12-17 10:03:19 +000081DEX_INLINE int dexZipExtractEntryToFile(ZipArchiveHandle handle,
82 ZipEntry* entry, int fd) {
83 return ExtractEntryToFile(handle, entry, fd);
84}
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080085
Carl Shapiro375fb112011-06-14 20:31:24 -070086#endif // LIBDEX_ZIPARCHIVE_H_