blob: ab5236889b6b35ddf7884ba4f1179d0502449908 [file] [log] [blame]
Christopher Ferrise6884ce2015-11-10 14:55:12 -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 */
16
17#ifndef LIBZIPARCHIVE_ZIPARCHIVE_PRIVATE_H_
18#define LIBZIPARCHIVE_ZIPARCHIVE_PRIVATE_H_
19
20#include <stdint.h>
21#include <stdlib.h>
22#include <unistd.h>
23
24#include <utils/FileMap.h>
25#include <ziparchive/zip_archive.h>
26
27struct ZipArchive {
28 // open Zip archive
29 const int fd;
30 const bool close_file;
31
32 // mapped central directory area
33 off64_t directory_offset;
34 android::FileMap directory_map;
35
36 // number of entries in the Zip archive
37 uint16_t num_entries;
38
39 // We know how many entries are in the Zip archive, so we can have a
40 // fixed-size hash table. We define a load factor of 0.75 and over
41 // allocate so the maximum number entries can never be higher than
42 // ((4 * UINT16_MAX) / 3 + 1) which can safely fit into a uint32_t.
43 uint32_t hash_table_size;
44 ZipString* hash_table;
45
46 ZipArchive(const int fd, bool assume_ownership) :
47 fd(fd),
48 close_file(assume_ownership),
49 directory_offset(0),
50 num_entries(0),
51 hash_table_size(0),
52 hash_table(NULL) {}
53
54 ~ZipArchive() {
55 if (close_file && fd >= 0) {
56 close(fd);
57 }
58
59 free(hash_table);
60 }
61};
62
63#endif // LIBZIPARCHIVE_ZIPARCHIVE_PRIVATE_H_