| 1 | /* unzip.h -- Backwards compatible unzip interface |
| 2 | part of the minizip-ng project |
| 3 | |
| 4 | Copyright (C) Nathan Moinvaziri |
| 5 | https://github.com/zlib-ng/minizip-ng |
| 6 | Copyright (C) 1998-2010 Gilles Vollant |
| 7 | https://www.winimage.com/zLibDll/minizip.html |
| 8 | |
| 9 | This program is distributed under the terms of the same license as zlib. |
| 10 | See the accompanying LICENSE file for the full text of the license. |
| 11 | */ |
| 12 | |
| 13 | #ifndef _unz64_H |
| 14 | #define _unz64_H |
| 15 | |
| 16 | #ifdef __cplusplus |
| 17 | extern "C" { |
| 18 | #endif |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | |
| 22 | #if !defined(_ZLIB_H) && !defined(ZLIB_H) && !defined(ZLIB_H_) |
| 23 | # if __has_include(<zlib-ng.h>) |
| 24 | # include <zlib-ng.h> |
| 25 | # elif __has_include(<zlib.h>) |
| 26 | # include <zlib.h> |
| 27 | # endif |
| 28 | #endif |
| 29 | |
| 30 | #ifndef _ZLIBIOAPI_H |
| 31 | # include "ioapi.h" |
| 32 | #endif |
| 33 | |
| 34 | /***************************************************************************/ |
| 35 | |
| 36 | #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) |
| 37 | /* like the STRICT of WIN32, we define a pointer that cannot be converted |
| 38 | from (void*) without cast */ |
| 39 | typedef struct TagunzFile__ { |
| 40 | int unused; |
| 41 | } unzFile__; |
| 42 | typedef unzFile__ *unzFile; |
| 43 | #else |
| 44 | typedef void *unzFile; |
| 45 | #endif |
| 46 | |
| 47 | /***************************************************************************/ |
| 48 | |
| 49 | #define UNZ_OK (0) |
| 50 | #define UNZ_END_OF_LIST_OF_FILE (-100) |
| 51 | #define UNZ_ERRNO (-1) /* Z_ERRNO */ |
| 52 | #define UNZ_EOF (0) |
| 53 | #define UNZ_PARAMERROR (-102) |
| 54 | #define UNZ_BADZIPFILE (-103) |
| 55 | #define UNZ_INTERNALERROR (-104) |
| 56 | #define UNZ_CRCERROR (-105) |
| 57 | #define UNZ_BADPASSWORD (-106) /* minizip-ng */ |
| 58 | |
| 59 | /***************************************************************************/ |
| 60 | /* tm_unz contain date/time info */ |
| 61 | typedef struct tm_unz_s { |
| 62 | int tm_sec; /* seconds after the minute - [0,59] */ |
| 63 | int tm_min; /* minutes after the hour - [0,59] */ |
| 64 | int tm_hour; /* hours since midnight - [0,23] */ |
| 65 | int tm_mday; /* day of the month - [1,31] */ |
| 66 | int tm_mon; /* months since January - [0,11] */ |
| 67 | int tm_year; /* years - [1980..2044] */ |
| 68 | } tm_unz; |
| 69 | |
| 70 | /***************************************************************************/ |
| 71 | |
| 72 | #if !defined(MZ_COMPAT_VERSION) || MZ_COMPAT_VERSION <= 110 |
| 73 | # define mz_dos_date dosDate |
| 74 | #else |
| 75 | # define mz_dos_date dos_date |
| 76 | #endif |
| 77 | |
| 78 | /* Global data about the zip from end of central dir */ |
| 79 | typedef struct unz_global_info64_s { |
| 80 | uint64_t number_entry; /* total number of entries in the central dir on this disk */ |
| 81 | unsigned long size_comment; /* size of the global comment of the zipfile */ |
| 82 | /* minizip-ng fields */ |
| 83 | uint32_t number_disk_with_CD; /* number the the disk with central dir, used for spanning ZIP */ |
| 84 | } unz_global_info64; |
| 85 | |
| 86 | typedef struct unz_global_info_s { |
| 87 | unsigned long number_entry; /* total number of entries in the central dir on this disk */ |
| 88 | unsigned long size_comment; /* size of the global comment of the zipfile */ |
| 89 | /* minizip-ng fields */ |
| 90 | uint32_t number_disk_with_CD; /* number the the disk with central dir, used for spanning ZIP */ |
| 91 | } unz_global_info; |
| 92 | |
| 93 | /* Information about a file in the zip */ |
| 94 | typedef struct unz_file_info64_s { |
| 95 | unsigned long version; /* version made by 2 bytes */ |
| 96 | unsigned long version_needed; /* version needed to extract 2 bytes */ |
| 97 | unsigned long flag; /* general purpose bit flag 2 bytes */ |
| 98 | unsigned long compression_method; /* compression method 2 bytes */ |
| 99 | unsigned long mz_dos_date; /* last mod file date in Dos fmt 4 bytes */ |
| 100 | unsigned long crc; /* crc-32 4 bytes */ |
| 101 | ZPOS64_T compressed_size; /* compressed size 8 bytes */ |
| 102 | ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */ |
| 103 | unsigned long size_filename; /* filename length 2 bytes */ |
| 104 | unsigned long size_file_extra; /* extra field length 2 bytes */ |
| 105 | unsigned long size_file_comment; /* file comment length 2 bytes */ |
| 106 | |
| 107 | unsigned long disk_num_start; /* disk number start 4 bytes */ |
| 108 | unsigned long internal_fa; /* internal file attributes 2 bytes */ |
| 109 | unsigned long external_fa; /* external file attributes 4 bytes */ |
| 110 | |
| 111 | tm_unz tmu_date; |
| 112 | |
| 113 | /* minizip-ng fields */ |
| 114 | ZPOS64_T disk_offset; |
| 115 | uint16_t size_file_extra_internal; |
| 116 | } unz_file_info64; |
| 117 | |
| 118 | typedef struct unz_file_info_s { |
| 119 | unsigned long version; /* version made by 2 bytes */ |
| 120 | unsigned long version_needed; /* version needed to extract 2 bytes */ |
| 121 | unsigned long flag; /* general purpose bit flag 2 bytes */ |
| 122 | unsigned long compression_method; /* compression method 2 bytes */ |
| 123 | unsigned long mz_dos_date; /* last mod file date in Dos fmt 4 bytes */ |
| 124 | unsigned long crc; /* crc-32 4 bytes */ |
| 125 | ZPOS64_T compressed_size; /* compressed size 4 bytes */ |
| 126 | ZPOS64_T uncompressed_size; /* uncompressed size 4 bytes */ |
| 127 | unsigned long size_filename; /* filename length 2 bytes */ |
| 128 | unsigned long size_file_extra; /* extra field length 2 bytes */ |
| 129 | unsigned long size_file_comment; /* file comment length 2 bytes */ |
| 130 | |
| 131 | unsigned long disk_num_start; /* disk number start 2 bytes */ |
| 132 | unsigned long internal_fa; /* internal file attributes 2 bytes */ |
| 133 | unsigned long external_fa; /* external file attributes 4 bytes */ |
| 134 | |
| 135 | tm_unz tmu_date; |
| 136 | |
| 137 | /* minizip-ng fields */ |
| 138 | ZPOS64_T disk_offset; |
| 139 | } unz_file_info; |
| 140 | |
| 141 | /***************************************************************************/ |
| 142 | |
| 143 | #if !defined(MZ_COMPAT_VERSION) || MZ_COMPAT_VERSION < 110 |
| 144 | /* Possible values: |
| 145 | 0 - Uses OS default, e.g. Windows ignores case. |
| 146 | 1 - Is case sensitive. |
| 147 | >= 2 - Ignore case. |
| 148 | */ |
| 149 | typedef int unzFileNameCase; |
| 150 | #else |
| 151 | typedef int (*unzFileNameComparer)(unzFile file, const char *filename1, const char *filename2); |
| 152 | #endif |
| 153 | typedef int (*unzIteratorFunction)(unzFile file); |
| 154 | typedef int (*unzIteratorFunction2)(unzFile file, unz_file_info64 *pfile_info, char *filename, uint16_t filename_size, |
| 155 | void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size); |
| 156 | |
| 157 | /***************************************************************************/ |
| 158 | /* Reading a zip file */ |
| 159 | |
| 160 | /* Compatibility layer with the original minizip library (unzip.h). */ |
| 161 | ZEXPORT unzFile unzOpen(const char *path); |
| 162 | ZEXPORT unzFile unzOpen64(const void *path); |
| 163 | ZEXPORT unzFile unzOpen2(const char *path, zlib_filefunc_def *pzlib_filefunc_def); |
| 164 | ZEXPORT unzFile unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_filefunc_def); |
| 165 | ZEXPORT int unzClose(unzFile file); |
| 166 | |
| 167 | ZEXPORT int unzGetGlobalInfo(unzFile file, unz_global_info *pglobal_info32); |
| 168 | ZEXPORT int unzGetGlobalInfo64(unzFile file, unz_global_info64 *pglobal_info); |
| 169 | ZEXPORT int unzGetGlobalComment(unzFile file, char *comment, unsigned long comment_size); |
| 170 | ZEXPORT int unzOpenCurrentFile(unzFile file); |
| 171 | ZEXPORT int unzOpenCurrentFilePassword(unzFile file, const char *password); |
| 172 | ZEXPORT int unzOpenCurrentFile2(unzFile file, int *method, int *level, int raw); |
| 173 | ZEXPORT int unzOpenCurrentFile3(unzFile file, int *method, int *level, int raw, const char *password); |
| 174 | ZEXPORT int unzReadCurrentFile(unzFile file, void *buf, uint32_t len); |
| 175 | ZEXPORT int unzCloseCurrentFile(unzFile file); |
| 176 | ZEXPORT int unzGetCurrentFileInfo(unzFile file, unz_file_info *pfile_info, char *filename, unsigned long filename_size, |
| 177 | void *extrafield, unsigned long extrafield_size, char *comment, |
| 178 | unsigned long comment_size); |
| 179 | ZEXPORT int unzGetCurrentFileInfo64(unzFile file, unz_file_info64 *pfile_info, char *filename, |
| 180 | unsigned long filename_size, void *extrafield, unsigned long extrafield_size, |
| 181 | char *comment, unsigned long comment_size); |
| 182 | ZEXPORT int unzGoToFirstFile(unzFile file); |
| 183 | ZEXPORT int unzGoToNextFile(unzFile file); |
| 184 | #if !defined(MZ_COMPAT_VERSION) || MZ_COMPAT_VERSION < 110 |
| 185 | ZEXPORT int unzLocateFile(unzFile file, const char *filename, unzFileNameCase filename_case); |
| 186 | #else |
| 187 | ZEXPORT int unzLocateFile(unzFile file, const char *filename, unzFileNameComparer filename_compare_func); |
| 188 | #endif |
| 189 | /* unzStringFileNameCompare is too new */ |
| 190 | ZEXPORT int unzGetLocalExtrafield(unzFile file, void *buf, unsigned int len); |
| 191 | |
| 192 | /* Compatibility layer with older minizip-ng (mz_unzip.h). */ |
| 193 | unzFile unzOpen_MZ(void *stream); |
| 194 | ZEXPORT int unzClose_MZ(unzFile file); |
| 195 | ZEXPORT void *unzGetHandle_MZ(unzFile file); |
| 196 | ZEXPORT void *unzGetStream_MZ(unzFile file); |
| 197 | |
| 198 | /***************************************************************************/ |
| 199 | /* Raw access to zip file */ |
| 200 | |
| 201 | typedef struct unz_file_pos_s { |
| 202 | uint32_t pos_in_zip_directory; /* offset in zip file directory */ |
| 203 | uint32_t num_of_file; /* # of file */ |
| 204 | } unz_file_pos; |
| 205 | |
| 206 | typedef struct unz64_file_pos_s { |
| 207 | int64_t pos_in_zip_directory; /* offset in zip file directory */ |
| 208 | uint64_t num_of_file; /* # of file */ |
| 209 | } unz64_file_pos; |
| 210 | |
| 211 | /* Compatibility layer with the original minizip library (unzip.h). */ |
| 212 | ZEXPORT int unzGetFilePos(unzFile file, unz_file_pos *file_pos); |
| 213 | ZEXPORT int unzGoToFilePos(unzFile file, unz_file_pos *file_pos); |
| 214 | ZEXPORT int unzGetFilePos64(unzFile file, unz64_file_pos *file_pos); |
| 215 | ZEXPORT int unzGoToFilePos64(unzFile file, const unz64_file_pos *file_pos); |
| 216 | ZEXPORT int64_t unzGetOffset64(unzFile file); |
| 217 | ZEXPORT unsigned long unzGetOffset(unzFile file); |
| 218 | ZEXPORT int unzSetOffset64(unzFile file, int64_t pos); |
| 219 | ZEXPORT int unzSetOffset(unzFile file, unsigned long pos); |
| 220 | ZEXPORT int32_t unztell(unzFile file); |
| 221 | ZEXPORT uint64_t unztell64(unzFile file); |
| 222 | ZEXPORT int unzeof(unzFile file); |
| 223 | |
| 224 | /* Compatibility layer with older minizip-ng (mz_unzip.h). */ |
| 225 | ZEXPORT int32_t unzTell(unzFile file); |
| 226 | ZEXPORT uint64_t unzTell64(unzFile file); |
| 227 | ZEXPORT int unzSeek(unzFile file, int32_t offset, int origin); |
| 228 | ZEXPORT int unzSeek64(unzFile file, int64_t offset, int origin); |
| 229 | ZEXPORT int unzEndOfFile(unzFile file); |
| 230 | ZEXPORT void *unzGetStream(unzFile file); |
| 231 | |
| 232 | /***************************************************************************/ |
| 233 | |
| 234 | #ifdef __cplusplus |
| 235 | } |
| 236 | #endif |
| 237 | |
| 238 | #endif /* _unz64_H */ |