| 1 | /* zip.h -- Backwards compatible zip 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 _zip64_H |
| 14 | #define _zip64_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(STRICTZIP) || defined(STRICTZIPUNZIP) |
| 37 | /* like the STRICT of WIN32, we define a pointer that cannot be converted |
| 38 | from (void*) without cast */ |
| 39 | typedef struct TagzipFile__ { |
| 40 | int unused; |
| 41 | } zipFile__; |
| 42 | typedef zipFile__ *zipFile; |
| 43 | #else |
| 44 | typedef void *zipFile; |
| 45 | #endif |
| 46 | |
| 47 | /***************************************************************************/ |
| 48 | |
| 49 | #define ZIP_OK (0) |
| 50 | #define ZIP_EOF (0) |
| 51 | #define ZIP_ERRNO (-1) /* Z_ERRNO */ |
| 52 | #define ZIP_PARAMERROR (-102) |
| 53 | #define ZIP_BADZIPFILE (-103) |
| 54 | #define ZIP_INTERNALERROR (-104) |
| 55 | |
| 56 | /***************************************************************************/ |
| 57 | /* default memLevel */ |
| 58 | #ifndef DEF_MEM_LEVEL |
| 59 | # if MAX_MEM_LEVEL >= 8 |
| 60 | # define DEF_MEM_LEVEL 8 |
| 61 | # else |
| 62 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL |
| 63 | # endif |
| 64 | #endif |
| 65 | |
| 66 | /***************************************************************************/ |
| 67 | /* tm_zip contain date/time info */ |
| 68 | typedef struct tm_zip_s { |
| 69 | int tm_sec; /* seconds after the minute - [0,59] */ |
| 70 | int tm_min; /* minutes after the hour - [0,59] */ |
| 71 | int tm_hour; /* hours since midnight - [0,23] */ |
| 72 | int tm_mday; /* day of the month - [1,31] */ |
| 73 | int tm_mon; /* months since January - [0,11] */ |
| 74 | int tm_year; /* years - [1980..2044] */ |
| 75 | } tm_zip; |
| 76 | |
| 77 | /***************************************************************************/ |
| 78 | |
| 79 | #if !defined(MZ_COMPAT_VERSION) || MZ_COMPAT_VERSION <= 110 |
| 80 | # define mz_dos_date dosDate |
| 81 | #else |
| 82 | # define mz_dos_date dos_date |
| 83 | #endif |
| 84 | |
| 85 | typedef struct { |
| 86 | tm_zip tmz_date; /* date in understandable format */ |
| 87 | unsigned long mz_dos_date; /* if dos_date == 0, tmz_date is used */ |
| 88 | unsigned long internal_fa; /* internal file attributes 2 bytes */ |
| 89 | unsigned long external_fa; /* external file attributes 4 bytes */ |
| 90 | } zip_fileinfo; |
| 91 | |
| 92 | typedef const char *zipcharpc; |
| 93 | |
| 94 | #define APPEND_STATUS_CREATE (0) |
| 95 | #define APPEND_STATUS_CREATEAFTER (1) |
| 96 | #define APPEND_STATUS_ADDINZIP (2) |
| 97 | |
| 98 | /***************************************************************************/ |
| 99 | /* Writing a zip file */ |
| 100 | |
| 101 | /* Compatibility layer with the original minizip library (zip.h). */ |
| 102 | ZEXPORT zipFile zipOpen(const char *path, int append); |
| 103 | ZEXPORT zipFile zipOpen64(const void *path, int append); |
| 104 | |
| 105 | ZEXPORT zipFile zipOpen2(const char *path, int append, zipcharpc *globalcomment, zlib_filefunc_def *pzlib_filefunc_def); |
| 106 | ZEXPORT zipFile zipOpen2_64(const void *path, int append, zipcharpc *globalcomment, |
| 107 | zlib_filefunc64_def *pzlib_filefunc_def); |
| 108 | /* zipOpen3 is not supported */ |
| 109 | |
| 110 | ZEXPORT int zipOpenNewFileInZip(zipFile file, const char *filename, const zip_fileinfo *zipfi, |
| 111 | const void *extrafield_local, uint16_t size_extrafield_local, |
| 112 | const void *extrafield_global, uint16_t size_extrafield_global, const char *comment, |
| 113 | int compression_method, int level); |
| 114 | ZEXPORT int zipOpenNewFileInZip64(zipFile file, const char *filename, const zip_fileinfo *zipfi, |
| 115 | const void *extrafield_local, uint16_t size_extrafield_local, |
| 116 | const void *extrafield_global, uint16_t size_extrafield_global, const char *comment, |
| 117 | int compression_method, int level, int zip64); |
| 118 | ZEXPORT int zipOpenNewFileInZip2(zipFile file, const char *filename, const zip_fileinfo *zipfi, |
| 119 | const void *extrafield_local, uint16_t size_extrafield_local, |
| 120 | const void *extrafield_global, uint16_t size_extrafield_global, const char *comment, |
| 121 | int compression_method, int level, int raw); |
| 122 | ZEXPORT int zipOpenNewFileInZip2_64(zipFile file, const char *filename, const zip_fileinfo *zipfi, |
| 123 | const void *extrafield_local, uint16_t size_extrafield_local, |
| 124 | const void *extrafield_global, uint16_t size_extrafield_global, const char *comment, |
| 125 | int compression_method, int level, int raw, int zip64); |
| 126 | ZEXPORT int zipOpenNewFileInZip3(zipFile file, const char *filename, const zip_fileinfo *zipfi, |
| 127 | const void *extrafield_local, uint16_t size_extrafield_local, |
| 128 | const void *extrafield_global, uint16_t size_extrafield_global, const char *comment, |
| 129 | int compression_method, int level, int raw, int windowBits, int memLevel, int strategy, |
| 130 | const char *password, unsigned long crc_for_crypting); |
| 131 | ZEXPORT int zipOpenNewFileInZip3_64(zipFile file, const char *filename, const zip_fileinfo *zipfi, |
| 132 | const void *extrafield_local, uint16_t size_extrafield_local, |
| 133 | const void *extrafield_global, uint16_t size_extrafield_global, const char *comment, |
| 134 | int compression_method, int level, int raw, int windowBits, int memLevel, |
| 135 | int strategy, const char *password, unsigned long crc_for_crypting, int zip64); |
| 136 | ZEXPORT int zipOpenNewFileInZip4(zipFile file, const char *filename, const zip_fileinfo *zipfi, |
| 137 | const void *extrafield_local, uint16_t size_extrafield_local, |
| 138 | const void *extrafield_global, uint16_t size_extrafield_global, const char *comment, |
| 139 | int compression_method, int level, int raw, int windowBits, int memLevel, int strategy, |
| 140 | const char *password, unsigned long crc_for_crypting, unsigned long version_madeby, |
| 141 | unsigned long flag_base); |
| 142 | ZEXPORT int zipOpenNewFileInZip4_64(zipFile file, const char *filename, const zip_fileinfo *zipfi, |
| 143 | const void *extrafield_local, uint16_t size_extrafield_local, |
| 144 | const void *extrafield_global, uint16_t size_extrafield_global, const char *comment, |
| 145 | int compression_method, int level, int raw, int windowBits, int memLevel, |
| 146 | int strategy, const char *password, unsigned long crc_for_crypting, |
| 147 | unsigned long version_madeby, unsigned long flag_base, int zip64); |
| 148 | ZEXPORT int zipWriteInFileInZip(zipFile file, const void *buf, uint32_t len); |
| 149 | ZEXPORT int zipCloseFileInZipRaw(zipFile file, unsigned long uncompressed_size, unsigned long crc32); |
| 150 | ZEXPORT int zipCloseFileInZipRaw64(zipFile file, uint64_t uncompressed_size, unsigned long crc32); |
| 151 | ZEXPORT int zipCloseFileInZip(zipFile file); |
| 152 | /* zipAlreadyThere is too new */ |
| 153 | ZEXPORT int zipClose(zipFile file, const char *global_comment); |
| 154 | /* zipRemoveExtraInfoBlock is not supported */ |
| 155 | |
| 156 | /* Compatibility layer with older minizip-ng (mz_zip.h). */ |
| 157 | ZEXPORT zipFile zipOpen_MZ(void *stream, int append, zipcharpc *globalcomment); |
| 158 | ZEXPORT void *zipGetHandle_MZ(zipFile); |
| 159 | ZEXPORT void *zipGetStream_MZ(zipFile file); |
| 160 | ZEXPORT int zipOpenNewFileInZip_64(zipFile file, const char *filename, const zip_fileinfo *zipfi, |
| 161 | const void *extrafield_local, uint16_t size_extrafield_local, |
| 162 | const void *extrafield_global, uint16_t size_extrafield_global, const char *comment, |
| 163 | int compression_method, int level, int zip64); |
| 164 | ZEXPORT int zipOpenNewFileInZip5(zipFile file, const char *filename, const zip_fileinfo *zipfi, |
| 165 | const void *extrafield_local, uint16_t size_extrafield_local, |
| 166 | const void *extrafield_global, uint16_t size_extrafield_global, const char *comment, |
| 167 | int compression_method, int level, int raw, int windowBits, int memLevel, int strategy, |
| 168 | const char *password, unsigned long crc_for_crypting, unsigned long version_madeby, |
| 169 | unsigned long flag_base, int zip64); |
| 170 | ZEXPORT int zipCloseFileInZip64(zipFile file); |
| 171 | ZEXPORT int zipClose_64(zipFile file, const char *global_comment); |
| 172 | ZEXPORT int zipClose2_64(zipFile file, const char *global_comment, uint16_t version_madeby); |
| 173 | int zipClose_MZ(zipFile file, const char *global_comment); |
| 174 | int zipClose2_MZ(zipFile file, const char *global_comment, uint16_t version_madeby); |
| 175 | |
| 176 | #ifdef __cplusplus |
| 177 | } |
| 178 | #endif |
| 179 | |
| 180 | #endif /* _zip64_H */ |