Dieter Baron | 2d6db59 | 1999-07-25 18:26:20 +0000 | [diff] [blame] | 1 | #ifndef _HAD_ZIP_H |
| 2 | #define _HAD_ZIP_H |
| 3 | |
Dieter Baron | bbb6369 | 1999-07-26 22:04:20 +0000 | [diff] [blame] | 4 | /* |
| 5 | zip.h -- exported declarations. |
Thomas Klausner | 3b0ea21 | 2014-06-15 23:52:14 +0200 | [diff] [blame] | 6 | Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner |
Dieter Baron | bbb6369 | 1999-07-26 22:04:20 +0000 | [diff] [blame] | 7 | |
Dieter Baron | dd9afca | 2003-10-02 14:13:37 +0000 | [diff] [blame] | 8 | This file is part of libzip, a library to manipulate ZIP archives. |
Dieter Baron | b86c433 | 2007-11-07 14:35:13 +0100 | [diff] [blame] | 9 | The authors can be contacted at <libzip@nih.at> |
Dieter Baron | bbb6369 | 1999-07-26 22:04:20 +0000 | [diff] [blame] | 10 | |
Dieter Baron | dd9afca | 2003-10-02 14:13:37 +0000 | [diff] [blame] | 11 | Redistribution and use in source and binary forms, with or without |
| 12 | modification, are permitted provided that the following conditions |
| 13 | are met: |
| 14 | 1. Redistributions of source code must retain the above copyright |
| 15 | notice, this list of conditions and the following disclaimer. |
| 16 | 2. Redistributions in binary form must reproduce the above copyright |
| 17 | notice, this list of conditions and the following disclaimer in |
| 18 | the documentation and/or other materials provided with the |
| 19 | distribution. |
| 20 | 3. The names of the authors may not be used to endorse or promote |
| 21 | products derived from this software without specific prior |
| 22 | written permission. |
| 23 | |
| 24 | THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS |
| 25 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 26 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 27 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY |
| 28 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 30 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 31 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER |
| 32 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 33 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 34 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Dieter Baron | bbb6369 | 1999-07-26 22:04:20 +0000 | [diff] [blame] | 35 | */ |
| 36 | |
Dieter Baron | bbb6369 | 1999-07-26 22:04:20 +0000 | [diff] [blame] | 37 | |
Dieter Baron | 8bc1276 | 2007-08-22 13:39:13 +0200 | [diff] [blame] | 38 | #ifndef ZIP_EXTERN |
Thomas Klausner | 3b0ea21 | 2014-06-15 23:52:14 +0200 | [diff] [blame] | 39 | # ifndef ZIP_STATIC |
| 40 | # ifdef _WIN32 |
| 41 | # define ZIP_EXTERN __declspec(dllimport) |
| 42 | # elif defined(__GNUC__) && __GNUC__ >= 4 |
| 43 | # define ZIP_EXTERN __attribute__ ((visibility ("default"))) |
| 44 | # else |
| 45 | # define ZIP_EXTERN |
| 46 | # endif |
| 47 | # else |
| 48 | # define ZIP_EXTERN |
| 49 | # endif |
Dieter Baron | 8bc1276 | 2007-08-22 13:39:13 +0200 | [diff] [blame] | 50 | #endif |
| 51 | |
Dieter Baron | 08f2851 | 2005-07-14 14:08:11 +0000 | [diff] [blame] | 52 | #ifdef __cplusplus |
| 53 | extern "C" { |
Thomas Klausner | ea8ba49 | 2014-09-23 16:54:47 +0200 | [diff] [blame] | 54 | #if 0 |
| 55 | } /* fix autoindent */ |
| 56 | #endif |
Dieter Baron | 08f2851 | 2005-07-14 14:08:11 +0000 | [diff] [blame] | 57 | #endif |
| 58 | |
Dieter Baron | c65abed | 2008-08-01 17:04:17 +0200 | [diff] [blame] | 59 | #include <zipconf.h> |
| 60 | |
Dieter Baron | 2d6db59 | 1999-07-25 18:26:20 +0000 | [diff] [blame] | 61 | #include <sys/types.h> |
| 62 | #include <stdio.h> |
Thomas Klausner | 01b2a3c | 1999-07-27 20:35:58 +0000 | [diff] [blame] | 63 | #include <time.h> |
Dieter Baron | 2d6db59 | 1999-07-25 18:26:20 +0000 | [diff] [blame] | 64 | |
Dieter Baron | 2d6db59 | 1999-07-25 18:26:20 +0000 | [diff] [blame] | 65 | /* flags for zip_open */ |
Dieter Baron | b2ed74d | 2004-04-14 14:01:31 +0000 | [diff] [blame] | 66 | |
Dieter Baron | 2d6db59 | 1999-07-25 18:26:20 +0000 | [diff] [blame] | 67 | #define ZIP_CREATE 1 |
| 68 | #define ZIP_EXCL 2 |
| 69 | #define ZIP_CHECKCONS 4 |
Dieter Baron | 6c0681b | 2012-02-13 22:51:05 +0100 | [diff] [blame] | 70 | #define ZIP_TRUNCATE 8 |
Thomas Klausner | ea8ba49 | 2014-09-23 16:54:47 +0200 | [diff] [blame] | 71 | #define ZIP_RDONLY 16 |
Dieter Baron | 2d6db59 | 1999-07-25 18:26:20 +0000 | [diff] [blame] | 72 | |
Dieter Baron | e3f91ef | 2003-10-06 02:50:14 +0000 | [diff] [blame] | 73 | |
Dieter Baron | b2ed74d | 2004-04-14 14:01:31 +0000 | [diff] [blame] | 74 | /* flags for zip_name_locate, zip_fopen, zip_stat, ... */ |
| 75 | |
Dieter Baron | abc6fd7 | 2012-07-22 15:49:45 +0200 | [diff] [blame] | 76 | #define ZIP_FL_NOCASE 1u /* ignore case on name lookup */ |
| 77 | #define ZIP_FL_NODIR 2u /* ignore directory component */ |
| 78 | #define ZIP_FL_COMPRESSED 4u /* read compressed data */ |
| 79 | #define ZIP_FL_UNCHANGED 8u /* use original data, ignoring changes */ |
| 80 | #define ZIP_FL_RECOMPRESS 16u /* force recompression of data */ |
| 81 | #define ZIP_FL_ENCRYPTED 32u /* read encrypted data (implies ZIP_FL_COMPRESSED) */ |
| 82 | #define ZIP_FL_ENC_GUESS 0u /* guess string encoding (is default) */ |
| 83 | #define ZIP_FL_ENC_RAW 64u /* get unmodified string */ |
| 84 | #define ZIP_FL_ENC_STRICT 128u /* follow specification strictly */ |
| 85 | #define ZIP_FL_LOCAL 256u /* in local header */ |
| 86 | #define ZIP_FL_CENTRAL 512u /* in central directory */ |
| 87 | /* 1024u reserved for internal use */ |
| 88 | #define ZIP_FL_ENC_UTF_8 2048u /* string is UTF-8 encoded */ |
| 89 | #define ZIP_FL_ENC_CP437 4096u /* string is CP437 encoded */ |
| 90 | #define ZIP_FL_OVERWRITE 8192u /* zip_file_add: if file with name exists, overwrite (replace) it */ |
Dieter Baron | b2ed74d | 2004-04-14 14:01:31 +0000 | [diff] [blame] | 91 | |
Dieter Baron | 416df86 | 2008-05-14 14:56:13 +0200 | [diff] [blame] | 92 | /* archive global flags flags */ |
| 93 | |
Dieter Baron | abc6fd7 | 2012-07-22 15:49:45 +0200 | [diff] [blame] | 94 | #define ZIP_AFL_TORRENT 1u /* torrent zipped */ |
| 95 | #define ZIP_AFL_RDONLY 2u /* read only -- cannot be cleared */ |
Dieter Baron | 416df86 | 2008-05-14 14:56:13 +0200 | [diff] [blame] | 96 | |
Dieter Baron | 2f3f11c | 2009-02-14 18:58:01 +0100 | [diff] [blame] | 97 | |
Dieter Baron | 0e5eeab | 2012-04-24 18:47:12 +0200 | [diff] [blame] | 98 | /* create a new extra field */ |
| 99 | |
Dieter Baron | 3efab99 | 2012-05-04 09:29:29 +0200 | [diff] [blame] | 100 | #define ZIP_EXTRA_FIELD_ALL ZIP_UINT16_MAX |
Dieter Baron | 0e5eeab | 2012-04-24 18:47:12 +0200 | [diff] [blame] | 101 | #define ZIP_EXTRA_FIELD_NEW ZIP_UINT16_MAX |
| 102 | |
Dieter Baron | 2f3f11c | 2009-02-14 18:58:01 +0100 | [diff] [blame] | 103 | |
Dieter Baron | b2ed74d | 2004-04-14 14:01:31 +0000 | [diff] [blame] | 104 | /* libzip error codes */ |
Dieter Baron | 2d6db59 | 1999-07-25 18:26:20 +0000 | [diff] [blame] | 105 | |
Thomas Klausner | d0147e9 | 2004-11-17 21:55:17 +0000 | [diff] [blame] | 106 | #define ZIP_ER_OK 0 /* N No error */ |
| 107 | #define ZIP_ER_MULTIDISK 1 /* N Multi-disk zip archives not supported */ |
| 108 | #define ZIP_ER_RENAME 2 /* S Renaming temporary file failed */ |
| 109 | #define ZIP_ER_CLOSE 3 /* S Closing zip archive failed */ |
| 110 | #define ZIP_ER_SEEK 4 /* S Seek error */ |
| 111 | #define ZIP_ER_READ 5 /* S Read error */ |
| 112 | #define ZIP_ER_WRITE 6 /* S Write error */ |
| 113 | #define ZIP_ER_CRC 7 /* N CRC error */ |
| 114 | #define ZIP_ER_ZIPCLOSED 8 /* N Containing zip archive was closed */ |
| 115 | #define ZIP_ER_NOENT 9 /* N No such file */ |
| 116 | #define ZIP_ER_EXISTS 10 /* N File already exists */ |
| 117 | #define ZIP_ER_OPEN 11 /* S Can't open file */ |
| 118 | #define ZIP_ER_TMPOPEN 12 /* S Failure to create temporary file */ |
| 119 | #define ZIP_ER_ZLIB 13 /* Z Zlib error */ |
| 120 | #define ZIP_ER_MEMORY 14 /* N Malloc failure */ |
| 121 | #define ZIP_ER_CHANGED 15 /* N Entry has been changed */ |
| 122 | #define ZIP_ER_COMPNOTSUPP 16 /* N Compression method not supported */ |
Thomas Klausner | ea8ba49 | 2014-09-23 16:54:47 +0200 | [diff] [blame] | 123 | #define ZIP_ER_EOF 17 /* N Premature end of file */ |
Thomas Klausner | d0147e9 | 2004-11-17 21:55:17 +0000 | [diff] [blame] | 124 | #define ZIP_ER_INVAL 18 /* N Invalid argument */ |
| 125 | #define ZIP_ER_NOZIP 19 /* N Not a zip archive */ |
| 126 | #define ZIP_ER_INTERNAL 20 /* N Internal error */ |
| 127 | #define ZIP_ER_INCONS 21 /* N Zip archive inconsistent */ |
| 128 | #define ZIP_ER_REMOVE 22 /* S Can't remove file */ |
Dieter Baron | ca7d39a | 2005-01-20 21:00:29 +0000 | [diff] [blame] | 129 | #define ZIP_ER_DELETED 23 /* N Entry has been deleted */ |
Dieter Baron | 63e12d1 | 2009-01-25 23:26:36 +0100 | [diff] [blame] | 130 | #define ZIP_ER_ENCRNOTSUPP 24 /* N Encryption method not supported */ |
Dieter Baron | ae53a57 | 2009-01-26 23:03:31 +0100 | [diff] [blame] | 131 | #define ZIP_ER_RDONLY 25 /* N Read-only archive */ |
| 132 | #define ZIP_ER_NOPASSWD 26 /* N No password provided */ |
Dieter Baron | 2f3f11c | 2009-02-14 18:58:01 +0100 | [diff] [blame] | 133 | #define ZIP_ER_WRONGPASSWD 27 /* N Wrong password provided */ |
Thomas Klausner | ea8ba49 | 2014-09-23 16:54:47 +0200 | [diff] [blame] | 134 | #define ZIP_ER_OPNOTSUPP 28 /* N Operation not supported */ |
| 135 | #define ZIP_ER_INUSE 29 /* N Resource still in use */ |
| 136 | #define ZIP_ER_TELL 30 /* S Tell error */ |
Dieter Baron | b2ed74d | 2004-04-14 14:01:31 +0000 | [diff] [blame] | 137 | |
| 138 | /* type of system error value */ |
| 139 | |
Dieter Baron | e3f91ef | 2003-10-06 02:50:14 +0000 | [diff] [blame] | 140 | #define ZIP_ET_NONE 0 /* sys_err unused */ |
| 141 | #define ZIP_ET_SYS 1 /* sys_err is errno */ |
Thomas Klausner | d0147e9 | 2004-11-17 21:55:17 +0000 | [diff] [blame] | 142 | #define ZIP_ET_ZLIB 2 /* sys_err is zlib error code */ |
Dieter Baron | 2d6db59 | 1999-07-25 18:26:20 +0000 | [diff] [blame] | 143 | |
Dieter Baron | b2ed74d | 2004-04-14 14:01:31 +0000 | [diff] [blame] | 144 | /* compression methods */ |
Dieter Baron | 2d6db59 | 1999-07-25 18:26:20 +0000 | [diff] [blame] | 145 | |
Thomas Klausner | 5d56de9 | 2014-10-08 14:39:52 +0200 | [diff] [blame] | 146 | #define ZIP_CM_DEFAULT -1 /* better of deflate or store */ |
Dieter Baron | b2ed74d | 2004-04-14 14:01:31 +0000 | [diff] [blame] | 147 | #define ZIP_CM_STORE 0 /* stored (uncompressed) */ |
| 148 | #define ZIP_CM_SHRINK 1 /* shrunk */ |
| 149 | #define ZIP_CM_REDUCE_1 2 /* reduced with factor 1 */ |
| 150 | #define ZIP_CM_REDUCE_2 3 /* reduced with factor 2 */ |
| 151 | #define ZIP_CM_REDUCE_3 4 /* reduced with factor 3 */ |
| 152 | #define ZIP_CM_REDUCE_4 5 /* reduced with factor 4 */ |
| 153 | #define ZIP_CM_IMPLODE 6 /* imploded */ |
Thomas Klausner | e21b065 | 2004-11-17 21:59:00 +0000 | [diff] [blame] | 154 | /* 7 - Reserved for Tokenizing compression algorithm */ |
Dieter Baron | b2ed74d | 2004-04-14 14:01:31 +0000 | [diff] [blame] | 155 | #define ZIP_CM_DEFLATE 8 /* deflated */ |
| 156 | #define ZIP_CM_DEFLATE64 9 /* deflate64 */ |
| 157 | #define ZIP_CM_PKWARE_IMPLODE 10 /* PKWARE imploding */ |
Thomas Klausner | c3ed804 | 2005-09-06 23:44:25 +0000 | [diff] [blame] | 158 | /* 11 - Reserved by PKWARE */ |
| 159 | #define ZIP_CM_BZIP2 12 /* compressed using BZIP2 algorithm */ |
Dieter Baron | 62e54ee | 2007-11-08 16:00:25 +0100 | [diff] [blame] | 160 | /* 13 - Reserved by PKWARE */ |
| 161 | #define ZIP_CM_LZMA 14 /* LZMA (EFS) */ |
| 162 | /* 15-17 - Reserved by PKWARE */ |
| 163 | #define ZIP_CM_TERSE 18 /* compressed using IBM TERSE (new) */ |
| 164 | #define ZIP_CM_LZ77 19 /* IBM LZ77 z Architecture (PFS) */ |
| 165 | #define ZIP_CM_WAVPACK 97 /* WavPack compressed data */ |
| 166 | #define ZIP_CM_PPMD 98 /* PPMd version I, Rev 1 */ |
Thomas Klausner | 42dd7b7 | 1999-07-25 20:32:18 +0000 | [diff] [blame] | 167 | |
Dieter Baron | 45b1075 | 2006-04-24 14:04:19 +0000 | [diff] [blame] | 168 | /* encryption methods */ |
| 169 | |
| 170 | #define ZIP_EM_NONE 0 /* not encrypted */ |
| 171 | #define ZIP_EM_TRAD_PKWARE 1 /* traditional PKWARE encryption */ |
| 172 | #if 0 /* Strong Encryption Header not parsed yet */ |
| 173 | #define ZIP_EM_DES 0x6601 /* strong encryption: DES */ |
| 174 | #define ZIP_EM_RC2_OLD 0x6602 /* strong encryption: RC2, version < 5.2 */ |
| 175 | #define ZIP_EM_3DES_168 0x6603 |
| 176 | #define ZIP_EM_3DES_112 0x6609 |
| 177 | #define ZIP_EM_AES_128 0x660e |
| 178 | #define ZIP_EM_AES_192 0x660f |
| 179 | #define ZIP_EM_AES_256 0x6610 |
| 180 | #define ZIP_EM_RC2 0x6702 /* strong encryption: RC2, version >= 5.2 */ |
| 181 | #define ZIP_EM_RC4 0x6801 |
| 182 | #endif |
| 183 | #define ZIP_EM_UNKNOWN 0xffff /* unknown algorithm */ |
| 184 | |
Dieter Baron | 504965c | 2013-09-18 19:37:22 +0200 | [diff] [blame] | 185 | #define ZIP_OPSYS_DOS 0x00u |
| 186 | #define ZIP_OPSYS_AMIGA 0x01u |
| 187 | #define ZIP_OPSYS_OPENVMS 0x02u |
| 188 | #define ZIP_OPSYS_UNIX 0x03u |
| 189 | #define ZIP_OPSYS_VM_CMS 0x04u |
| 190 | #define ZIP_OPSYS_ATARI_ST 0x05u |
| 191 | #define ZIP_OPSYS_OS_2 0x06u |
| 192 | #define ZIP_OPSYS_MACINTOSH 0x07u |
| 193 | #define ZIP_OPSYS_Z_SYSTEM 0x08u |
| 194 | #define ZIP_OPSYS_CPM 0x09u |
| 195 | #define ZIP_OPSYS_WINDOWS_NTFS 0x0au |
| 196 | #define ZIP_OPSYS_MVS 0x0bu |
| 197 | #define ZIP_OPSYS_VSE 0x0cu |
| 198 | #define ZIP_OPSYS_ACORN_RISC 0x0du |
| 199 | #define ZIP_OPSYS_VFAT 0x0eu |
| 200 | #define ZIP_OPSYS_ALTERNATE_MVS 0x0fu |
| 201 | #define ZIP_OPSYS_BEOS 0x10u |
| 202 | #define ZIP_OPSYS_TANDEM 0x11u |
| 203 | #define ZIP_OPSYS_OS_400 0x12u |
| 204 | #define ZIP_OPSYS_OS_X 0x13u |
| 205 | |
| 206 | #define ZIP_OPSYS_DEFAULT ZIP_OPSYS_UNIX |
| 207 | |
Dieter Baron | b2ed74d | 2004-04-14 14:01:31 +0000 | [diff] [blame] | 208 | |
Dieter Baron | 35bf0fd | 2004-12-22 16:32:01 +0000 | [diff] [blame] | 209 | enum zip_source_cmd { |
Thomas Klausner | ea8ba49 | 2014-09-23 16:54:47 +0200 | [diff] [blame] | 210 | ZIP_SOURCE_OPEN, /* prepare for reading */ |
| 211 | ZIP_SOURCE_READ, /* read data */ |
| 212 | ZIP_SOURCE_CLOSE, /* reading is done */ |
| 213 | ZIP_SOURCE_STAT, /* get meta information */ |
| 214 | ZIP_SOURCE_ERROR, /* get error information */ |
| 215 | ZIP_SOURCE_FREE, /* cleanup and free resources */ |
| 216 | ZIP_SOURCE_SEEK, /* set position for reading */ |
| 217 | ZIP_SOURCE_TELL, /* get read position */ |
| 218 | ZIP_SOURCE_BEGIN_WRITE, /* prepare for writing */ |
| 219 | ZIP_SOURCE_COMMIT_WRITE, /* writing is done */ |
| 220 | ZIP_SOURCE_ROLLBACK_WRITE, /* discard written changes */ |
| 221 | ZIP_SOURCE_WRITE, /* write data */ |
| 222 | ZIP_SOURCE_SEEK_WRITE, /* set position for writing */ |
| 223 | ZIP_SOURCE_TELL_WRITE, /* get write position */ |
| 224 | ZIP_SOURCE_SUPPORTS, /* check whether source supports command */ |
| 225 | ZIP_SOURCE_REMOVE /* remove file */ |
Dieter Baron | 2d6db59 | 1999-07-25 18:26:20 +0000 | [diff] [blame] | 226 | }; |
Thomas Klausner | ea8ba49 | 2014-09-23 16:54:47 +0200 | [diff] [blame] | 227 | typedef enum zip_source_cmd zip_source_cmd_t; |
Dieter Baron | 2d6db59 | 1999-07-25 18:26:20 +0000 | [diff] [blame] | 228 | |
Dieter Baron | 8631d4b | 2014-10-10 16:28:54 +0200 | [diff] [blame] | 229 | #define ZIP_SOURCE_MAKE_COMMAND_BITMASK(cmd) (1<<(cmd)) |
| 230 | |
| 231 | #define ZIP_SOURCE_SUPPORTS_READABLE (ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_OPEN) \ |
| 232 | | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_READ) \ |
| 233 | | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_CLOSE) \ |
| 234 | | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_STAT) \ |
| 235 | | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ERROR) \ |
| 236 | | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_FREE)) |
| 237 | |
| 238 | #define ZIP_SOURCE_SUPPORTS_SEEKABLE (ZIP_SOURCE_SUPPORTS_READABLE \ |
| 239 | | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK) \ |
| 240 | | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL) \ |
| 241 | | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SUPPORTS)) |
| 242 | |
| 243 | #define ZIP_SOURCE_SUPPORTS_WRITABLE (ZIP_SOURCE_SUPPORTS_SEEKABLE \ |
| 244 | | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_BEGIN_WRITE) \ |
| 245 | | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_COMMIT_WRITE) \ |
| 246 | | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_ROLLBACK_WRITE) \ |
| 247 | | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_WRITE) \ |
| 248 | | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_SEEK_WRITE) \ |
| 249 | | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_TELL_WRITE) \ |
| 250 | | ZIP_SOURCE_MAKE_COMMAND_BITMASK(ZIP_SOURCE_REMOVE)) |
| 251 | |
Thomas Klausner | ea8ba49 | 2014-09-23 16:54:47 +0200 | [diff] [blame] | 252 | /* for use by sources */ |
| 253 | struct zip_source_args_seek { |
| 254 | zip_int64_t offset; |
| 255 | int whence; |
| 256 | }; |
Thomas Klausner | 03ca1c1 | 2014-09-24 01:02:15 +0200 | [diff] [blame] | 257 | |
Thomas Klausner | ea8ba49 | 2014-09-23 16:54:47 +0200 | [diff] [blame] | 258 | typedef struct zip_source_args_seek zip_source_args_seek_t; |
Thomas Klausner | 1c9348a | 2014-12-02 10:47:28 +0100 | [diff] [blame] | 259 | #define ZIP_SOURCE_GET_ARGS(type, data, len, error) ((len) < sizeof(type) ? zip_error_set((error), ZIP_ER_INVAL, 0), (type *)NULL : (type *)(data)) |
Thomas Klausner | ea8ba49 | 2014-09-23 16:54:47 +0200 | [diff] [blame] | 260 | |
| 261 | |
| 262 | /* error information */ |
| 263 | /* use zip_error_*() to access */ |
| 264 | struct zip_error { |
| 265 | int zip_err; /* libzip error code (ZIP_ER_*) */ |
| 266 | int sys_err; /* copy of errno (E*) or zlib error code */ |
| 267 | char *str; /* string representation or NULL */ |
| 268 | }; |
Dieter Baron | ba98df0 | 2009-03-30 00:03:53 +0200 | [diff] [blame] | 269 | |
Dieter Baron | abc6fd7 | 2012-07-22 15:49:45 +0200 | [diff] [blame] | 270 | #define ZIP_STAT_NAME 0x0001u |
| 271 | #define ZIP_STAT_INDEX 0x0002u |
| 272 | #define ZIP_STAT_SIZE 0x0004u |
| 273 | #define ZIP_STAT_COMP_SIZE 0x0008u |
| 274 | #define ZIP_STAT_MTIME 0x0010u |
| 275 | #define ZIP_STAT_CRC 0x0020u |
| 276 | #define ZIP_STAT_COMP_METHOD 0x0040u |
| 277 | #define ZIP_STAT_ENCRYPTION_METHOD 0x0080u |
| 278 | #define ZIP_STAT_FLAGS 0x0100u |
Dieter Baron | dc094e2 | 2009-03-12 11:49:05 +0100 | [diff] [blame] | 279 | |
Dieter Baron | e3f91ef | 2003-10-06 02:50:14 +0000 | [diff] [blame] | 280 | struct zip_stat { |
Dieter Baron | dc094e2 | 2009-03-12 11:49:05 +0100 | [diff] [blame] | 281 | zip_uint64_t valid; /* which fields have valid values */ |
Dieter Baron | e3f91ef | 2003-10-06 02:50:14 +0000 | [diff] [blame] | 282 | const char *name; /* name of the file */ |
Dieter Baron | cb1379d | 2009-03-10 14:46:51 +0100 | [diff] [blame] | 283 | zip_uint64_t index; /* index within archive */ |
Dieter Baron | c65abed | 2008-08-01 17:04:17 +0200 | [diff] [blame] | 284 | zip_uint64_t size; /* size of file (uncompressed) */ |
| 285 | zip_uint64_t comp_size; /* size of file (compressed) */ |
Dieter Baron | dc094e2 | 2009-03-12 11:49:05 +0100 | [diff] [blame] | 286 | time_t mtime; /* modification time */ |
| 287 | zip_uint32_t crc; /* crc of file data */ |
Dieter Baron | c65abed | 2008-08-01 17:04:17 +0200 | [diff] [blame] | 288 | zip_uint16_t comp_method; /* compression method used */ |
| 289 | zip_uint16_t encryption_method; /* encryption method used */ |
Dieter Baron | e00b1b8 | 2009-10-28 15:39:02 +0100 | [diff] [blame] | 290 | zip_uint32_t flags; /* reserved for future use */ |
Dieter Baron | e3f91ef | 2003-10-06 02:50:14 +0000 | [diff] [blame] | 291 | }; |
| 292 | |
| 293 | struct zip; |
| 294 | struct zip_file; |
Thomas Klausner | ef9a02f | 2004-11-18 15:06:20 +0000 | [diff] [blame] | 295 | struct zip_source; |
Dieter Baron | e3f91ef | 2003-10-06 02:50:14 +0000 | [diff] [blame] | 296 | |
Thomas Klausner | ea8ba49 | 2014-09-23 16:54:47 +0200 | [diff] [blame] | 297 | typedef struct zip zip_t; |
| 298 | typedef struct zip_error zip_error_t; |
| 299 | typedef struct zip_file zip_file_t; |
| 300 | typedef struct zip_source zip_source_t; |
| 301 | typedef struct zip_stat zip_stat_t; |
| 302 | |
Dieter Baron | 3efab99 | 2012-05-04 09:29:29 +0200 | [diff] [blame] | 303 | typedef zip_uint32_t zip_flags_t; |
| 304 | |
Dieter Baron | 1d9dfeb | 2014-09-28 23:02:54 +0200 | [diff] [blame] | 305 | typedef zip_int64_t (*zip_source_callback)(void *, void *, zip_uint64_t, zip_source_cmd_t); |
Dieter Baron | 2f3f11c | 2009-02-14 18:58:01 +0100 | [diff] [blame] | 306 | |
Dieter Baron | 2d6db59 | 1999-07-25 18:26:20 +0000 | [diff] [blame] | 307 | |
Thomas Klausner | 0830a77 | 2012-05-18 19:52:08 +0200 | [diff] [blame] | 308 | #ifndef ZIP_DISABLE_DEPRECATED |
Dieter Baron | 1d9dfeb | 2014-09-28 23:02:54 +0200 | [diff] [blame] | 309 | ZIP_EXTERN zip_int64_t zip_add(zip_t *, const char *, zip_source_t *); /* use zip_file_add */ |
| 310 | ZIP_EXTERN zip_int64_t zip_add_dir(zip_t *, const char *); /* use zip_dir_add */ |
| 311 | ZIP_EXTERN const char *zip_get_file_comment(zip_t *, zip_uint64_t, int *, int); /* use zip_file_get_comment */ |
| 312 | ZIP_EXTERN int zip_get_num_files(zip_t *); /* use zip_get_num_entries instead */ |
| 313 | ZIP_EXTERN int zip_rename(zip_t *, zip_uint64_t, const char *); /* use zip_file_rename */ |
| 314 | ZIP_EXTERN int zip_replace(zip_t *, zip_uint64_t, zip_source_t *); /* use zip_file_replace */ |
| 315 | ZIP_EXTERN int zip_set_file_comment(zip_t *, zip_uint64_t, const char *, int); /* use zip_file_set_comment */ |
Thomas Klausner | ea8ba49 | 2014-09-23 16:54:47 +0200 | [diff] [blame] | 316 | ZIP_EXTERN int zip_error_get_sys_type(int); /* use zip_error_system_type */ |
Dieter Baron | 1d9dfeb | 2014-09-28 23:02:54 +0200 | [diff] [blame] | 317 | ZIP_EXTERN void zip_error_get(zip_t *, int *, int *); /* use zip_get_error, zip_error_code_zip / zip_error_code_system */ |
Thomas Klausner | da1c245 | 2014-12-02 16:01:26 +0100 | [diff] [blame] | 318 | ZIP_EXTERN int zip_error_to_str(char *, zip_uint64_t, int, int); |
Dieter Baron | 1d9dfeb | 2014-09-28 23:02:54 +0200 | [diff] [blame] | 319 | ZIP_EXTERN void zip_file_error_get(zip_file_t *, int *, int *); /* use zip_file_get_error, zip_error_code_zip / zip_error_code_system */ |
Thomas Klausner | 0830a77 | 2012-05-18 19:52:08 +0200 | [diff] [blame] | 320 | #endif |
| 321 | |
Dieter Baron | 1d9dfeb | 2014-09-28 23:02:54 +0200 | [diff] [blame] | 322 | ZIP_EXTERN int zip_archive_set_tempdir(zip_t *, const char *); |
| 323 | ZIP_EXTERN int zip_close(zip_t *); |
| 324 | ZIP_EXTERN int zip_delete(zip_t *, zip_uint64_t); |
| 325 | ZIP_EXTERN zip_int64_t zip_dir_add(zip_t *, const char *, zip_flags_t); |
| 326 | ZIP_EXTERN void zip_discard(zip_t *); |
Thomas Klausner | ea8ba49 | 2014-09-23 16:54:47 +0200 | [diff] [blame] | 327 | |
Dieter Baron | 1d9dfeb | 2014-09-28 23:02:54 +0200 | [diff] [blame] | 328 | ZIP_EXTERN zip_error_t *zip_get_error(zip_t *); |
| 329 | ZIP_EXTERN void zip_error_clear(zip_t *); |
| 330 | ZIP_EXTERN int zip_error_code_zip(const zip_error_t *); |
| 331 | ZIP_EXTERN int zip_error_code_system(const zip_error_t *); |
| 332 | ZIP_EXTERN void zip_error_fini(zip_error_t *); |
| 333 | ZIP_EXTERN void zip_error_init(zip_error_t *); |
Thomas Klausner | da1c245 | 2014-12-02 16:01:26 +0100 | [diff] [blame] | 334 | ZIP_EXTERN void zip_error_init_with_code(zip_error_t *, int); |
Thomas Klausner | ea8ba49 | 2014-09-23 16:54:47 +0200 | [diff] [blame] | 335 | ZIP_EXTERN void zip_error_set(zip_error_t *, int, int); |
Dieter Baron | 1d9dfeb | 2014-09-28 23:02:54 +0200 | [diff] [blame] | 336 | ZIP_EXTERN const char *zip_error_strerror(zip_error_t *); |
| 337 | ZIP_EXTERN int zip_error_system_type(const zip_error_t *); |
Thomas Klausner | ea8ba49 | 2014-09-23 16:54:47 +0200 | [diff] [blame] | 338 | ZIP_EXTERN zip_int64_t zip_error_to_data(const zip_error_t *, void *, zip_uint64_t); |
Thomas Klausner | ea8ba49 | 2014-09-23 16:54:47 +0200 | [diff] [blame] | 339 | |
Dieter Baron | 1d9dfeb | 2014-09-28 23:02:54 +0200 | [diff] [blame] | 340 | ZIP_EXTERN int zip_fclose(zip_file_t *); |
| 341 | ZIP_EXTERN zip_t *zip_fdopen(int, int, int *); |
| 342 | ZIP_EXTERN zip_int64_t zip_file_add(zip_t *, const char *, zip_source_t *, zip_flags_t); |
| 343 | ZIP_EXTERN void zip_file_error_clear(zip_file_t *); |
| 344 | ZIP_EXTERN int zip_file_extra_field_delete(zip_t *, zip_uint64_t, zip_uint16_t, zip_flags_t); |
| 345 | ZIP_EXTERN int zip_file_extra_field_delete_by_id(zip_t *, zip_uint64_t, zip_uint16_t, zip_uint16_t, zip_flags_t); |
| 346 | ZIP_EXTERN int zip_file_extra_field_set(zip_t *, zip_uint64_t, zip_uint16_t, zip_uint16_t, const zip_uint8_t *, zip_uint16_t, zip_flags_t); |
| 347 | ZIP_EXTERN zip_int16_t zip_file_extra_fields_count(zip_t *, zip_uint64_t, zip_flags_t); |
| 348 | ZIP_EXTERN zip_int16_t zip_file_extra_fields_count_by_id(zip_t *, zip_uint64_t, zip_uint16_t, zip_flags_t); |
| 349 | ZIP_EXTERN const zip_uint8_t *zip_file_extra_field_get(zip_t *, zip_uint64_t, zip_uint16_t, zip_uint16_t *, zip_uint16_t *, zip_flags_t); |
| 350 | ZIP_EXTERN const zip_uint8_t *zip_file_extra_field_get_by_id(zip_t *, zip_uint64_t, zip_uint16_t, zip_uint16_t, zip_uint16_t *, zip_flags_t); |
| 351 | ZIP_EXTERN const char *zip_file_get_comment(zip_t *, zip_uint64_t, zip_uint32_t *, zip_flags_t); |
| 352 | ZIP_EXTERN zip_error_t *zip_file_get_error(zip_file_t *); |
| 353 | ZIP_EXTERN int zip_file_get_external_attributes(zip_t *, zip_uint64_t, zip_flags_t, zip_uint8_t *, zip_uint32_t *); |
| 354 | ZIP_EXTERN int zip_file_rename(zip_t *, zip_uint64_t, const char *, zip_flags_t); |
| 355 | ZIP_EXTERN int zip_file_replace(zip_t *, zip_uint64_t, zip_source_t *, zip_flags_t); |
| 356 | ZIP_EXTERN int zip_file_set_comment(zip_t *, zip_uint64_t, const char *, zip_uint16_t, zip_flags_t); |
| 357 | ZIP_EXTERN int zip_file_set_external_attributes(zip_t *, zip_uint64_t, zip_flags_t, zip_uint8_t, zip_uint32_t); |
| 358 | ZIP_EXTERN int zip_file_set_mtime(zip_t *, zip_uint64_t, time_t, zip_flags_t); |
| 359 | ZIP_EXTERN const char *zip_file_strerror(zip_file_t *); |
| 360 | ZIP_EXTERN zip_file_t *zip_fopen(zip_t *, const char *, zip_flags_t); |
| 361 | ZIP_EXTERN zip_file_t *zip_fopen_encrypted(zip_t *, const char *, zip_flags_t, const char *); |
| 362 | ZIP_EXTERN zip_file_t *zip_fopen_index(zip_t *, zip_uint64_t, zip_flags_t); |
| 363 | ZIP_EXTERN zip_file_t *zip_fopen_index_encrypted(zip_t *, zip_uint64_t, zip_flags_t, const char *); |
| 364 | ZIP_EXTERN zip_int64_t zip_fread(zip_file_t *, void *, zip_uint64_t); |
| 365 | ZIP_EXTERN const char *zip_get_archive_comment(zip_t *, int *, zip_flags_t); |
| 366 | ZIP_EXTERN int zip_get_archive_flag(zip_t *, zip_flags_t, zip_flags_t); |
| 367 | ZIP_EXTERN const char *zip_get_name(zip_t *, zip_uint64_t, zip_flags_t); |
| 368 | ZIP_EXTERN zip_int64_t zip_get_num_entries(zip_t *, zip_flags_t); |
| 369 | ZIP_EXTERN zip_int64_t zip_name_locate(zip_t *, const char *, zip_flags_t); |
| 370 | ZIP_EXTERN zip_t *zip_open(const char *, int, int *); |
| 371 | ZIP_EXTERN zip_t *zip_open_from_source(zip_source_t *, int, zip_error_t *); |
| 372 | ZIP_EXTERN int zip_set_archive_comment(zip_t *, const char *, zip_uint16_t); |
| 373 | ZIP_EXTERN int zip_set_archive_flag(zip_t *, zip_flags_t, int); |
| 374 | ZIP_EXTERN int zip_set_default_password(zip_t *, const char *); |
| 375 | ZIP_EXTERN int zip_set_file_compression(zip_t *, zip_uint64_t, zip_int32_t, zip_uint32_t); |
Dieter Baron | ac9bb7a | 2014-10-10 10:34:33 +0200 | [diff] [blame] | 376 | ZIP_EXTERN int zip_source_begin_write(zip_source_t *); |
Dieter Baron | 1d9dfeb | 2014-09-28 23:02:54 +0200 | [diff] [blame] | 377 | ZIP_EXTERN zip_source_t *zip_source_buffer(zip_t *, const void *, zip_uint64_t, int); |
Thomas Klausner | ea8ba49 | 2014-09-23 16:54:47 +0200 | [diff] [blame] | 378 | ZIP_EXTERN zip_source_t *zip_source_buffer_create(const void *, zip_uint64_t, int, zip_error_t *); |
| 379 | ZIP_EXTERN int zip_source_close(zip_source_t *); |
Dieter Baron | ac9bb7a | 2014-10-10 10:34:33 +0200 | [diff] [blame] | 380 | ZIP_EXTERN int zip_source_commit_write(zip_source_t *); |
Thomas Klausner | ea8ba49 | 2014-09-23 16:54:47 +0200 | [diff] [blame] | 381 | ZIP_EXTERN zip_error_t *zip_source_error(zip_source_t *src); |
Dieter Baron | 1d9dfeb | 2014-09-28 23:02:54 +0200 | [diff] [blame] | 382 | ZIP_EXTERN zip_source_t *zip_source_file(zip_t *, const char *, zip_uint64_t, zip_int64_t); |
| 383 | ZIP_EXTERN zip_source_t *zip_source_file_create(const char *, zip_uint64_t, zip_int64_t, zip_error_t *); |
| 384 | ZIP_EXTERN zip_source_t *zip_source_filep(zip_t *, FILE *, zip_uint64_t, zip_int64_t); |
| 385 | ZIP_EXTERN zip_source_t *zip_source_filep_create(FILE *, zip_uint64_t, zip_int64_t, zip_error_t *); |
Thomas Klausner | ea8ba49 | 2014-09-23 16:54:47 +0200 | [diff] [blame] | 386 | ZIP_EXTERN void zip_source_free(zip_source_t *); |
Dieter Baron | 1d9dfeb | 2014-09-28 23:02:54 +0200 | [diff] [blame] | 387 | ZIP_EXTERN zip_source_t *zip_source_function(zip_t *, zip_source_callback, void *); |
Thomas Klausner | ea8ba49 | 2014-09-23 16:54:47 +0200 | [diff] [blame] | 388 | ZIP_EXTERN zip_source_t *zip_source_function_create(zip_source_callback, void *, zip_error_t *); |
| 389 | ZIP_EXTERN int zip_source_is_deleted(zip_source_t *); |
| 390 | ZIP_EXTERN void zip_source_keep(zip_source_t *); |
Dieter Baron | 1d9dfeb | 2014-09-28 23:02:54 +0200 | [diff] [blame] | 391 | ZIP_EXTERN zip_int64_t zip_source_make_command_bitmap(zip_source_cmd_t, ...); |
Thomas Klausner | ea8ba49 | 2014-09-23 16:54:47 +0200 | [diff] [blame] | 392 | ZIP_EXTERN int zip_source_open(zip_source_t *); |
| 393 | ZIP_EXTERN zip_int64_t zip_source_read(zip_source_t *, void *, zip_uint64_t); |
Dieter Baron | ac9bb7a | 2014-10-10 10:34:33 +0200 | [diff] [blame] | 394 | ZIP_EXTERN void zip_source_rollback_write(zip_source_t *); |
Thomas Klausner | 07ffcac | 2014-11-18 14:37:01 +0100 | [diff] [blame] | 395 | ZIP_EXTERN int zip_source_seek(zip_source_t *, zip_int64_t, int); |
Dieter Baron | c548a18 | 2014-10-10 18:27:50 +0200 | [diff] [blame] | 396 | ZIP_EXTERN zip_int64_t zip_source_seek_compute_offset(zip_uint64_t, zip_uint64_t, void *, zip_uint64_t, zip_error_t *); |
Thomas Klausner | 07ffcac | 2014-11-18 14:37:01 +0100 | [diff] [blame] | 397 | ZIP_EXTERN int zip_source_seek_write(zip_source_t *, zip_int64_t, int); |
Dieter Baron | 1d9dfeb | 2014-09-28 23:02:54 +0200 | [diff] [blame] | 398 | ZIP_EXTERN int zip_source_stat(zip_source_t *, zip_stat_t *); |
Thomas Klausner | 07ffcac | 2014-11-18 14:37:01 +0100 | [diff] [blame] | 399 | ZIP_EXTERN zip_int64_t zip_source_tell(zip_source_t *); |
| 400 | ZIP_EXTERN zip_int64_t zip_source_tell_write(zip_source_t *); |
Andrew Molyneux | 516cab0 | 2014-12-24 20:07:05 +0000 | [diff] [blame^] | 401 | #ifdef _WIN32 |
| 402 | ZIP_EXTERN zip_source_t *zip_source_win32a(zip_t *, const char *, zip_uint64_t, zip_int64_t); |
| 403 | ZIP_EXTERN zip_source_t *zip_source_win32a_create(const char *, zip_uint64_t, zip_int64_t, zip_error_t *); |
| 404 | ZIP_EXTERN zip_source_t *zip_source_win32file(zip_t *, void *, zip_uint64_t, zip_int64_t); |
| 405 | ZIP_EXTERN zip_source_t *zip_source_win32file_create(void *, zip_uint64_t, zip_int64_t, zip_error_t *); |
| 406 | ZIP_EXTERN zip_source_t *zip_source_win32utf8(zip_t *, const char *, zip_uint64_t, zip_int64_t); |
| 407 | ZIP_EXTERN zip_source_t *zip_source_win32utf8_create(const char *, zip_uint64_t, zip_int64_t, zip_error_t *); |
| 408 | ZIP_EXTERN zip_source_t *zip_source_win32w(zip_t *, const wchar_t *, zip_uint64_t, zip_int64_t); |
| 409 | ZIP_EXTERN zip_source_t *zip_source_win32w_create(const wchar_t *, zip_uint64_t, zip_int64_t, zip_error_t *); |
| 410 | #endif |
Dieter Baron | ac9bb7a | 2014-10-10 10:34:33 +0200 | [diff] [blame] | 411 | ZIP_EXTERN zip_int64_t zip_source_write(zip_source_t *, const void *, zip_uint64_t); |
Dieter Baron | 1d9dfeb | 2014-09-28 23:02:54 +0200 | [diff] [blame] | 412 | ZIP_EXTERN zip_source_t *zip_source_zip(zip_t *, zip_t *, zip_uint64_t, zip_flags_t, zip_uint64_t, zip_int64_t); |
| 413 | ZIP_EXTERN int zip_stat(zip_t *, const char *, zip_flags_t, zip_stat_t *); |
| 414 | ZIP_EXTERN int zip_stat_index(zip_t *, zip_uint64_t, zip_flags_t, zip_stat_t *); |
| 415 | ZIP_EXTERN void zip_stat_init(zip_stat_t *); |
| 416 | ZIP_EXTERN const char *zip_strerror(zip_t *); |
| 417 | ZIP_EXTERN int zip_unchange(zip_t *, zip_uint64_t); |
| 418 | ZIP_EXTERN int zip_unchange_all(zip_t *); |
| 419 | ZIP_EXTERN int zip_unchange_archive(zip_t *); |
Dieter Baron | 2d6db59 | 1999-07-25 18:26:20 +0000 | [diff] [blame] | 420 | |
Dieter Baron | 08f2851 | 2005-07-14 14:08:11 +0000 | [diff] [blame] | 421 | #ifdef __cplusplus |
| 422 | } |
| 423 | #endif |
| 424 | |
Dieter Baron | 2d6db59 | 1999-07-25 18:26:20 +0000 | [diff] [blame] | 425 | #endif /* _HAD_ZIP_H */ |