@appzung/react-native-code-push 8.3.2 → 9.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/CodePush.podspec +3 -3
  2. package/README.md +3 -1
  3. package/android/app/build.gradle +2 -0
  4. package/android/app/src/main/AndroidManifest.xml +1 -2
  5. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateUtils.java +15 -8
  6. package/android/build.gradle +3 -0
  7. package/ios/CodePush/CodePush.m +2 -1
  8. package/ios/CodePush/SSZipArchive/Info.plist +26 -0
  9. package/ios/CodePush/SSZipArchive/README.md +1 -1
  10. package/ios/CodePush/SSZipArchive/SSZipArchive.h +129 -27
  11. package/ios/CodePush/SSZipArchive/SSZipArchive.m +1119 -314
  12. package/ios/CodePush/SSZipArchive/SSZipCommon.h +71 -0
  13. package/ios/CodePush/SSZipArchive/Supporting Files/PrivacyInfo.xcprivacy +23 -0
  14. package/ios/CodePush/SSZipArchive/include/ZipArchive.h +25 -0
  15. package/ios/CodePush/SSZipArchive/minizip/LICENSE +17 -0
  16. package/ios/CodePush/SSZipArchive/minizip/mz.h +273 -0
  17. package/ios/CodePush/SSZipArchive/minizip/mz_compat.c +1306 -0
  18. package/ios/CodePush/SSZipArchive/minizip/mz_compat.h +346 -0
  19. package/ios/CodePush/SSZipArchive/minizip/mz_crypt.c +187 -0
  20. package/ios/CodePush/SSZipArchive/minizip/mz_crypt.h +65 -0
  21. package/ios/CodePush/SSZipArchive/minizip/mz_crypt_apple.c +526 -0
  22. package/ios/CodePush/SSZipArchive/minizip/mz_os.c +348 -0
  23. package/ios/CodePush/SSZipArchive/minizip/mz_os.h +176 -0
  24. package/ios/CodePush/SSZipArchive/minizip/mz_os_posix.c +350 -0
  25. package/ios/CodePush/SSZipArchive/minizip/mz_strm.c +556 -0
  26. package/ios/CodePush/SSZipArchive/minizip/mz_strm.h +132 -0
  27. package/ios/CodePush/SSZipArchive/minizip/mz_strm_buf.c +383 -0
  28. package/ios/CodePush/SSZipArchive/minizip/mz_strm_buf.h +42 -0
  29. package/ios/CodePush/SSZipArchive/minizip/mz_strm_mem.c +269 -0
  30. package/ios/CodePush/SSZipArchive/minizip/mz_strm_mem.h +48 -0
  31. package/ios/CodePush/SSZipArchive/minizip/mz_strm_os.h +40 -0
  32. package/ios/CodePush/SSZipArchive/minizip/mz_strm_os_posix.c +203 -0
  33. package/ios/CodePush/SSZipArchive/minizip/mz_strm_pkcrypt.c +334 -0
  34. package/ios/CodePush/SSZipArchive/minizip/mz_strm_pkcrypt.h +46 -0
  35. package/ios/CodePush/SSZipArchive/minizip/mz_strm_split.c +429 -0
  36. package/ios/CodePush/SSZipArchive/minizip/mz_strm_split.h +43 -0
  37. package/ios/CodePush/SSZipArchive/minizip/mz_strm_wzaes.c +360 -0
  38. package/ios/CodePush/SSZipArchive/minizip/mz_strm_wzaes.h +46 -0
  39. package/ios/CodePush/SSZipArchive/minizip/mz_strm_zlib.c +389 -0
  40. package/ios/CodePush/SSZipArchive/minizip/mz_strm_zlib.h +43 -0
  41. package/ios/CodePush/SSZipArchive/minizip/mz_zip.c +2782 -0
  42. package/ios/CodePush/SSZipArchive/minizip/mz_zip.h +262 -0
  43. package/ios/CodePush/SSZipArchive/minizip/mz_zip_rw.c +1942 -0
  44. package/ios/CodePush/SSZipArchive/minizip/mz_zip_rw.h +285 -0
  45. package/ios/CodePush.xcodeproj/project.pbxproj +245 -130
  46. package/ios/PrivacyInfo.xcprivacy +31 -0
  47. package/package.json +2 -2
  48. package/ios/CodePush/SSZipArchive/Common.h +0 -81
  49. package/ios/CodePush/SSZipArchive/aes/aes.h +0 -198
  50. package/ios/CodePush/SSZipArchive/aes/aes_via_ace.h +0 -541
  51. package/ios/CodePush/SSZipArchive/aes/aescrypt.c +0 -294
  52. package/ios/CodePush/SSZipArchive/aes/aeskey.c +0 -548
  53. package/ios/CodePush/SSZipArchive/aes/aesopt.h +0 -739
  54. package/ios/CodePush/SSZipArchive/aes/aestab.c +0 -391
  55. package/ios/CodePush/SSZipArchive/aes/aestab.h +0 -173
  56. package/ios/CodePush/SSZipArchive/aes/brg_endian.h +0 -126
  57. package/ios/CodePush/SSZipArchive/aes/brg_types.h +0 -219
  58. package/ios/CodePush/SSZipArchive/aes/entropy.c +0 -54
  59. package/ios/CodePush/SSZipArchive/aes/entropy.h +0 -16
  60. package/ios/CodePush/SSZipArchive/aes/fileenc.c +0 -144
  61. package/ios/CodePush/SSZipArchive/aes/fileenc.h +0 -121
  62. package/ios/CodePush/SSZipArchive/aes/hmac.c +0 -145
  63. package/ios/CodePush/SSZipArchive/aes/hmac.h +0 -103
  64. package/ios/CodePush/SSZipArchive/aes/prng.c +0 -155
  65. package/ios/CodePush/SSZipArchive/aes/prng.h +0 -82
  66. package/ios/CodePush/SSZipArchive/aes/pwd2key.c +0 -103
  67. package/ios/CodePush/SSZipArchive/aes/pwd2key.h +0 -57
  68. package/ios/CodePush/SSZipArchive/aes/sha1.c +0 -258
  69. package/ios/CodePush/SSZipArchive/aes/sha1.h +0 -73
  70. package/ios/CodePush/SSZipArchive/minizip/crypt.h +0 -130
  71. package/ios/CodePush/SSZipArchive/minizip/ioapi.c +0 -369
  72. package/ios/CodePush/SSZipArchive/minizip/ioapi.h +0 -175
  73. package/ios/CodePush/SSZipArchive/minizip/mztools.c +0 -284
  74. package/ios/CodePush/SSZipArchive/minizip/mztools.h +0 -31
  75. package/ios/CodePush/SSZipArchive/minizip/unzip.c +0 -1839
  76. package/ios/CodePush/SSZipArchive/minizip/unzip.h +0 -248
  77. package/ios/CodePush/SSZipArchive/minizip/zip.c +0 -1910
  78. package/ios/CodePush/SSZipArchive/minizip/zip.h +0 -202
@@ -1,1910 +0,0 @@
1
- /* zip.c -- IO on .zip files using zlib
2
- Version 1.1, February 14h, 2010
3
- part of the MiniZip project
4
-
5
- Copyright (C) 1998-2010 Gilles Vollant
6
- http://www.winimage.com/zLibDll/minizip.html
7
- Modifications for Zip64 support
8
- Copyright (C) 2009-2010 Mathias Svensson
9
- http://result42.com
10
- Modifications for AES, PKWARE disk spanning
11
- Copyright (C) 2010-2014 Nathan Moinvaziri
12
-
13
- This program is distributed under the terms of the same license as zlib.
14
- See the accompanying LICENSE file for the full text of the license.
15
- */
16
-
17
- #include <stdio.h>
18
- #include <stdlib.h>
19
- #include <string.h>
20
- #include <time.h>
21
- #include "zlib.h"
22
- #include "zip.h"
23
-
24
- #ifdef STDC
25
- # include <stddef.h>
26
- # include <string.h>
27
- # include <stdlib.h>
28
- #endif
29
- #ifdef NO_ERRNO_H
30
- extern int errno;
31
- #else
32
- # include <errno.h>
33
- #endif
34
-
35
- #ifdef HAVE_AES
36
- # define AES_METHOD (99)
37
- # define AES_PWVERIFYSIZE (2)
38
- # define AES_AUTHCODESIZE (10)
39
- # define AES_MAXSALTLENGTH (16)
40
- # define AES_VERSION (0x0001)
41
- # define AES_ENCRYPTIONMODE (0x03)
42
-
43
- # include "aes.h"
44
- # include "fileenc.h"
45
- # include "prng.h"
46
- # include "entropy.h"
47
- #endif
48
-
49
- #ifndef NOCRYPT
50
- # define INCLUDECRYPTINGCODE_IFCRYPTALLOWED
51
- # include "crypt.h"
52
- #endif
53
-
54
- #ifndef local
55
- # define local static
56
- #endif
57
- /* compile with -Dlocal if your debugger can't find static symbols */
58
-
59
- #define SIZEDATA_INDATABLOCK (4096 - (4 * 4))
60
-
61
- #define DISKHEADERMAGIC (0x08074b50)
62
- #define LOCALHEADERMAGIC (0x04034b50)
63
- #define CENTRALHEADERMAGIC (0x02014b50)
64
- #define ENDHEADERMAGIC (0x06054b50)
65
- #define ZIP64ENDHEADERMAGIC (0x06064b50)
66
- #define ZIP64ENDLOCHEADERMAGIC (0x07064b50)
67
-
68
- #define FLAG_LOCALHEADER_OFFSET (0x06)
69
- #define CRC_LOCALHEADER_OFFSET (0x0e)
70
-
71
- #define SIZECENTRALHEADER (0x2e) /* 46 */
72
- #define SIZECENTRALHEADERLOCATOR (0x14) /* 20 */
73
- #define SIZECENTRALDIRITEM (0x2e)
74
- #define SIZEZIPLOCALHEADER (0x1e)
75
-
76
- #ifndef BUFREADCOMMENT
77
- # define BUFREADCOMMENT (0x400)
78
- #endif
79
- #ifndef VERSIONMADEBY
80
- # define VERSIONMADEBY (0x0) /* platform dependent */
81
- #endif
82
-
83
- #ifndef Z_BUFSIZE
84
- # define Z_BUFSIZE (64 * 1024)
85
- #endif
86
- #ifndef Z_MAXFILENAMEINZIP
87
- # define Z_MAXFILENAMEINZIP (256)
88
- #endif
89
-
90
- #ifndef ALLOC
91
- # define ALLOC(size) (malloc(size))
92
- #endif
93
- #ifndef TRYFREE
94
- # define TRYFREE(p) {if (p) free(p); }
95
- #endif
96
-
97
- /* NOT sure that this work on ALL platform */
98
- #define MAKEULONG64(a, b) ((ZPOS64_T)(((unsigned long)(a)) | ((ZPOS64_T)((unsigned long)(b))) << 32))
99
-
100
- #ifndef DEF_MEM_LEVEL
101
- # if MAX_MEM_LEVEL >= 8
102
- # define DEF_MEM_LEVEL 8
103
- # else
104
- # define DEF_MEM_LEVEL MAX_MEM_LEVEL
105
- # endif
106
- #endif
107
-
108
- const char zip_copyright[] = " zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
109
-
110
- typedef struct linkedlist_datablock_internal_s {
111
- struct linkedlist_datablock_internal_s *next_datablock;
112
- uLong avail_in_this_block;
113
- uLong filled_in_this_block;
114
- uLong unused; /* for future use and alignment */
115
- unsigned char data[SIZEDATA_INDATABLOCK];
116
- } linkedlist_datablock_internal;
117
-
118
- typedef struct linkedlist_data_s {
119
- linkedlist_datablock_internal *first_block;
120
- linkedlist_datablock_internal *last_block;
121
- } linkedlist_data;
122
-
123
- typedef struct {
124
- z_stream stream; /* zLib stream structure for inflate */
125
- #ifdef HAVE_BZIP2
126
- bz_stream bstream; /* bzLib stream structure for bziped */
127
- #endif
128
- #ifdef HAVE_AES
129
- fcrypt_ctx aes_ctx;
130
- prng_ctx aes_rng[1];
131
- #endif
132
- int stream_initialised; /* 1 is stream is initialized */
133
- uInt pos_in_buffered_data; /* last written byte in buffered_data */
134
-
135
- ZPOS64_T pos_local_header; /* offset of the local header of the file currently writing */
136
- char *central_header; /* central header data for the current file */
137
- uLong size_centralextra;
138
- uLong size_centralheader; /* size of the central header for cur file */
139
- uLong size_centralextrafree; /* Extra bytes allocated to the central header but that are not used */
140
- uLong size_comment;
141
- uLong flag; /* flag of the file currently writing */
142
-
143
- int method; /* compression method written to file.*/
144
- int compression_method; /* compression method to use */
145
- int raw; /* 1 for directly writing raw data */
146
- Byte buffered_data[Z_BUFSIZE]; /* buffer contain compressed data to be writ*/
147
- uLong dosDate;
148
- uLong crc32;
149
- int zip64; /* Add ZIP64 extended information in the extra field */
150
- uLong number_disk; /* number of current disk used for spanning ZIP */
151
- ZPOS64_T pos_zip64extrainfo;
152
- ZPOS64_T total_compressed;
153
- ZPOS64_T total_uncompressed;
154
- #ifndef NOCRYPT
155
- unsigned long keys[3]; /* keys defining the pseudo-random sequence */
156
- const unsigned long *pcrc_32_tab;
157
- int crypt_header_size;
158
- #endif
159
- } curfile64_info;
160
-
161
- typedef struct {
162
- zlib_filefunc64_32_def z_filefunc;
163
- voidpf filestream; /* io structure of the zipfile */
164
- voidpf filestream_with_CD; /* io structure of the zipfile with the central dir */
165
- linkedlist_data central_dir; /* datablock with central dir in construction*/
166
- int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/
167
- int append; /* append mode */
168
- curfile64_info ci; /* info on the file currently writing */
169
-
170
- ZPOS64_T begin_pos; /* position of the beginning of the zipfile */
171
- ZPOS64_T add_position_when_writting_offset;
172
- ZPOS64_T number_entry;
173
- ZPOS64_T disk_size; /* size of each disk */
174
- uLong number_disk; /* number of the current disk, used for spanning ZIP */
175
- uLong number_disk_with_CD; /* number the the disk with central dir, used for spanning ZIP */
176
- #ifndef NO_ADDFILEINEXISTINGZIP
177
- char *globalcomment;
178
- #endif
179
- } zip64_internal;
180
-
181
- /* Allocate a new data block */
182
- local linkedlist_datablock_internal *allocate_new_datablock OF(());
183
- local linkedlist_datablock_internal *allocate_new_datablock()
184
- {
185
- linkedlist_datablock_internal *ldi;
186
-
187
- ldi = (linkedlist_datablock_internal *)ALLOC(sizeof(linkedlist_datablock_internal));
188
-
189
- if (ldi != NULL) {
190
- ldi->next_datablock = NULL;
191
- ldi->filled_in_this_block = 0;
192
- ldi->avail_in_this_block = SIZEDATA_INDATABLOCK;
193
- }
194
- return ldi;
195
- }
196
-
197
- /* Free data block in linked list */
198
- local void free_datablock OF((linkedlist_datablock_internal * ldi));
199
- local void free_datablock(linkedlist_datablock_internal *ldi)
200
- {
201
- while (ldi != NULL) {
202
- linkedlist_datablock_internal *ldinext = ldi->next_datablock;
203
- TRYFREE(ldi);
204
- ldi = ldinext;
205
- }
206
- }
207
-
208
- /* Initialize linked list */
209
- local void init_linkedlist OF((linkedlist_data * ll));
210
- local void init_linkedlist(linkedlist_data *ll)
211
- {
212
- ll->first_block = ll->last_block = NULL;
213
- }
214
-
215
- /* Free entire linked list and all data blocks */
216
- local void free_linkedlist OF((linkedlist_data * ll));
217
- local void free_linkedlist(linkedlist_data *ll)
218
- {
219
- free_datablock(ll->first_block);
220
- ll->first_block = ll->last_block = NULL;
221
- }
222
-
223
- /* Add data to linked list data block */
224
- local int add_data_in_datablock OF((linkedlist_data * ll, const void *buf, uLong len));
225
- local int add_data_in_datablock(linkedlist_data *ll, const void *buf, uLong len)
226
- {
227
- linkedlist_datablock_internal *ldi;
228
- const unsigned char *from_copy;
229
-
230
- if (ll == NULL)
231
- return ZIP_INTERNALERROR;
232
-
233
- if (ll->last_block == NULL) {
234
- ll->first_block = ll->last_block = allocate_new_datablock();
235
- if (ll->first_block == NULL)
236
- return ZIP_INTERNALERROR;
237
- }
238
-
239
- ldi = ll->last_block;
240
- from_copy = (unsigned char *)buf;
241
-
242
- while (len > 0) {
243
- uInt copy_this;
244
- uInt i;
245
- unsigned char *to_copy;
246
-
247
- if (ldi->avail_in_this_block == 0) {
248
- ldi->next_datablock = allocate_new_datablock();
249
- if (ldi->next_datablock == NULL)
250
- return ZIP_INTERNALERROR;
251
- ldi = ldi->next_datablock;
252
- ll->last_block = ldi;
253
- }
254
-
255
- if (ldi->avail_in_this_block < len)
256
- copy_this = (uInt)ldi->avail_in_this_block;
257
- else
258
- copy_this = (uInt)len;
259
-
260
- to_copy = &(ldi->data[ldi->filled_in_this_block]);
261
-
262
- for (i = 0; i < copy_this; i++)
263
- *(to_copy + i) = *(from_copy + i);
264
-
265
- ldi->filled_in_this_block += copy_this;
266
- ldi->avail_in_this_block -= copy_this;
267
- from_copy += copy_this;
268
- len -= copy_this;
269
- }
270
- return ZIP_OK;
271
- }
272
-
273
- local uLong zip64local_TmzDateToDosDate OF((const tm_zip * ptm));
274
- local uLong zip64local_TmzDateToDosDate(const tm_zip *ptm)
275
- {
276
- uLong year;
277
- #define zip64local_in_range(min, max, value) ((min) <= (value) && (value) <= (max))
278
- /* Years supported:
279
- * [00, 79] (assumed to be between 2000 and 2079)
280
- * [80, 207] (assumed to be between 1980 and 2107, typical output of old
281
- software that does 'year-1900' to get a double digit year)
282
- * [1980, 2107]
283
- Due to the date format limitations, only years between 1980 and 2107 can be stored.
284
- */
285
- if (!(zip64local_in_range(1980, 2107, ptm->tm_year) || zip64local_in_range(0, 207, ptm->tm_year)) ||
286
- !zip64local_in_range(0, 11, ptm->tm_mon) ||
287
- !zip64local_in_range(1, 31, ptm->tm_mday) ||
288
- !zip64local_in_range(0, 23, ptm->tm_hour) ||
289
- !zip64local_in_range(0, 59, ptm->tm_min) ||
290
- !zip64local_in_range(0, 59, ptm->tm_sec))
291
- return 0;
292
- #undef zip64local_in_range
293
-
294
- year = (uLong)ptm->tm_year;
295
- if (year >= 1980) /* range [1980, 2107] */
296
- year -= 1980;
297
- else if (year >= 80) /* range [80, 99] */
298
- year -= 80;
299
- else /* range [00, 79] */
300
- year += 20;
301
-
302
- return
303
- (uLong)(((ptm->tm_mday) + (32 * (ptm->tm_mon + 1)) + (512 * year)) << 16) |
304
- ((ptm->tm_sec / 2) + (32 * ptm->tm_min) + (2048 * (uLong)ptm->tm_hour));
305
- }
306
-
307
- /* Inputs a long in LSB order to the given file: nbByte == 1, 2 ,4 or 8 (byte, short or long, ZPOS64_T) */
308
- local int zip64local_putValue OF((const zlib_filefunc64_32_def * pzlib_filefunc_def, voidpf filestream,
309
- ZPOS64_T x, int nbByte));
310
- local int zip64local_putValue(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream,
311
- ZPOS64_T x, int nbByte)
312
- {
313
- unsigned char buf[8];
314
- int n;
315
- for (n = 0; n < nbByte; n++) {
316
- buf[n] = (unsigned char)(x & 0xff);
317
- x >>= 8;
318
- }
319
- if (x != 0) {
320
- /* data overflow - hack for ZIP64 (X Roche) */
321
- for (n = 0; n < nbByte; n++) {
322
- buf[n] = 0xff;
323
- }
324
- }
325
-
326
- if (ZWRITE64(*pzlib_filefunc_def, filestream, buf, nbByte) != (uLong)nbByte)
327
- return ZIP_ERRNO;
328
-
329
- return ZIP_OK;
330
- }
331
-
332
- local void zip64local_putValue_inmemory OF((void *dest, ZPOS64_T x, int nbByte));
333
- local void zip64local_putValue_inmemory(void *dest, ZPOS64_T x, int nbByte)
334
- {
335
- unsigned char *buf = (unsigned char *)dest;
336
- int n;
337
- for (n = 0; n < nbByte; n++) {
338
- buf[n] = (unsigned char)(x & 0xff);
339
- x >>= 8;
340
- }
341
-
342
- if (x != 0) {
343
- /* data overflow - hack for ZIP64 */
344
- for (n = 0; n < nbByte; n++) {
345
- buf[n] = 0xff;
346
- }
347
- }
348
- }
349
-
350
- local int zip64local_getByte OF((const zlib_filefunc64_32_def * pzlib_filefunc_def, voidpf filestream, int *pi));
351
- local int zip64local_getByte(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, int *pi)
352
- {
353
- unsigned char c;
354
- int err = (int)ZREAD64(*pzlib_filefunc_def, filestream, &c, 1);
355
- if (err == 1) {
356
- *pi = (int)c;
357
- return ZIP_OK;
358
- }
359
- if (ZERROR64(*pzlib_filefunc_def, filestream))
360
- return ZIP_ERRNO;
361
- return ZIP_EOF;
362
- }
363
-
364
- local int zip64local_getShort OF((const zlib_filefunc64_32_def * pzlib_filefunc_def, voidpf filestream, uLong * pX));
365
- local int zip64local_getShort(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)
366
- {
367
- uLong x;
368
- int i = 0;
369
- int err;
370
-
371
- err = zip64local_getByte(pzlib_filefunc_def, filestream, &i);
372
- x = (uLong)i;
373
- if (err == ZIP_OK)
374
- err = zip64local_getByte(pzlib_filefunc_def, filestream, &i);
375
- x += ((uLong)i) << 8;
376
-
377
- if (err == ZIP_OK)
378
- *pX = x;
379
- else
380
- *pX = 0;
381
- return err;
382
- }
383
-
384
- local int zip64local_getLong OF((const zlib_filefunc64_32_def * pzlib_filefunc_def, voidpf filestream, uLong * pX));
385
- local int zip64local_getLong(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)
386
- {
387
- uLong x;
388
- int i = 0;
389
- int err;
390
-
391
- err = zip64local_getByte(pzlib_filefunc_def, filestream, &i);
392
- x = (uLong)i;
393
- if (err == ZIP_OK)
394
- err = zip64local_getByte(pzlib_filefunc_def, filestream, &i);
395
- x += ((uLong)i) << 8;
396
- if (err == ZIP_OK)
397
- err = zip64local_getByte(pzlib_filefunc_def, filestream, &i);
398
- x += ((uLong)i) << 16;
399
- if (err == ZIP_OK)
400
- err = zip64local_getByte(pzlib_filefunc_def, filestream, &i);
401
- x += ((uLong)i) << 24;
402
-
403
- if (err == ZIP_OK)
404
- *pX = x;
405
- else
406
- *pX = 0;
407
- return err;
408
- }
409
-
410
- local int zip64local_getLong64 OF((const zlib_filefunc64_32_def * pzlib_filefunc_def, voidpf filestream, ZPOS64_T * pX));
411
- local int zip64local_getLong64(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)
412
- {
413
- ZPOS64_T x;
414
- int i = 0;
415
- int err;
416
-
417
- err = zip64local_getByte(pzlib_filefunc_def, filestream, &i);
418
- x = (ZPOS64_T)i;
419
- if (err == ZIP_OK)
420
- err = zip64local_getByte(pzlib_filefunc_def, filestream, &i);
421
- x += ((ZPOS64_T)i) << 8;
422
- if (err == ZIP_OK)
423
- err = zip64local_getByte(pzlib_filefunc_def, filestream, &i);
424
- x += ((ZPOS64_T)i) << 16;
425
- if (err == ZIP_OK)
426
- err = zip64local_getByte(pzlib_filefunc_def, filestream, &i);
427
- x += ((ZPOS64_T)i) << 24;
428
- if (err == ZIP_OK)
429
- err = zip64local_getByte(pzlib_filefunc_def, filestream, &i);
430
- x += ((ZPOS64_T)i) << 32;
431
- if (err == ZIP_OK)
432
- err = zip64local_getByte(pzlib_filefunc_def, filestream, &i);
433
- x += ((ZPOS64_T)i) << 40;
434
- if (err == ZIP_OK)
435
- err = zip64local_getByte(pzlib_filefunc_def, filestream, &i);
436
- x += ((ZPOS64_T)i) << 48;
437
- if (err == ZIP_OK)
438
- err = zip64local_getByte(pzlib_filefunc_def, filestream, &i);
439
- x += ((ZPOS64_T)i) << 56;
440
-
441
- if (err == ZIP_OK)
442
- *pX = x;
443
- else
444
- *pX = 0;
445
-
446
- return err;
447
- }
448
-
449
- /* Gets the amount of bytes left to write to the current disk for spanning archives */
450
- local int zipGetDiskSizeAvailable OF((zipFile file, ZPOS64_T * size_available));
451
- local int zipGetDiskSizeAvailable(zipFile file, ZPOS64_T *size_available)
452
- {
453
- zip64_internal *zi;
454
- ZPOS64_T current_disk_size;
455
-
456
- zi = (zip64_internal *)file;
457
- ZSEEK64(zi->z_filefunc, zi->filestream, 0, ZLIB_FILEFUNC_SEEK_END);
458
- current_disk_size = ZTELL64(zi->z_filefunc, zi->filestream);
459
- *size_available = zi->disk_size - current_disk_size;
460
- return ZIP_OK;
461
- }
462
-
463
- /* Goes to a specific disk number for spanning archives */
464
- local int zipGoToSpecificDisk OF((zipFile file, int number_disk, int open_existing));
465
- local int zipGoToSpecificDisk(zipFile file, int number_disk, int open_existing)
466
- {
467
- zip64_internal *zi;
468
- int err = ZIP_OK;
469
-
470
- zi = (zip64_internal *)file;
471
- if (zi->disk_size == 0)
472
- return err;
473
-
474
- if ((zi->filestream != NULL) && (zi->filestream != zi->filestream_with_CD))
475
- ZCLOSE64(zi->z_filefunc, zi->filestream);
476
-
477
- zi->filestream = ZOPENDISK64(zi->z_filefunc, zi->filestream_with_CD, number_disk, (open_existing == 1) ?
478
- (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING) :
479
- (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE));
480
-
481
- if (zi->filestream == NULL)
482
- err = ZIP_ERRNO;
483
-
484
- return err;
485
- }
486
-
487
- /* Goes to the first disk in a spanned archive */
488
- local int zipGoToFirstDisk OF((zipFile file));
489
- local int zipGoToFirstDisk(zipFile file)
490
- {
491
- zip64_internal *zi;
492
- int number_disk_next;
493
- int err = ZIP_OK;
494
-
495
- zi = (zip64_internal *)file;
496
-
497
- if (zi->disk_size == 0)
498
- return err;
499
- number_disk_next = 0;
500
- if (zi->number_disk_with_CD > 0)
501
- number_disk_next = (int)zi->number_disk_with_CD - 1;
502
- err = zipGoToSpecificDisk(file, number_disk_next, (zi->append == APPEND_STATUS_ADDINZIP));
503
- if ((err == ZIP_ERRNO) && (zi->append == APPEND_STATUS_ADDINZIP))
504
- err = zipGoToSpecificDisk(file, number_disk_next, 0);
505
- if (err == ZIP_OK)
506
- zi->number_disk = number_disk_next;
507
- ZSEEK64(zi->z_filefunc, zi->filestream, 0, ZLIB_FILEFUNC_SEEK_END);
508
- return err;
509
- }
510
-
511
- /* Goes to the next disk in a spanned archive */
512
- local int zipGoToNextDisk OF((zipFile file));
513
- local int zipGoToNextDisk(zipFile file)
514
- {
515
- zip64_internal *zi;
516
- ZPOS64_T size_available_in_disk;
517
- int err = ZIP_OK;
518
- int number_disk_next;
519
-
520
- zi = (zip64_internal *)file;
521
-
522
- if (zi->disk_size == 0)
523
- return err;
524
-
525
- number_disk_next = (int)zi->number_disk + 1;
526
-
527
- do {
528
- err = zipGoToSpecificDisk(file, number_disk_next, (zi->append == APPEND_STATUS_ADDINZIP));
529
- if ((err == ZIP_ERRNO) && (zi->append == APPEND_STATUS_ADDINZIP))
530
- err = zipGoToSpecificDisk(file, number_disk_next, 0);
531
- if (err != ZIP_OK)
532
- break;
533
- err = zipGetDiskSizeAvailable(file, &size_available_in_disk);
534
- if (err != ZIP_OK)
535
- break;
536
- zi->number_disk = number_disk_next;
537
- zi->number_disk_with_CD = zi->number_disk + 1;
538
-
539
- number_disk_next += 1;
540
- } while (size_available_in_disk <= 0);
541
-
542
- return err;
543
- }
544
-
545
- /* Locate the Central directory of a zipfile (at the end, just before the global comment) */
546
- local ZPOS64_T zip64local_SearchCentralDir OF((const zlib_filefunc64_32_def * pzlib_filefunc_def, voidpf filestream));
547
- local ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream)
548
- {
549
- unsigned char *buf;
550
- ZPOS64_T file_size;
551
- ZPOS64_T back_read = 4;
552
- ZPOS64_T max_back = 0xffff; /* maximum size of global comment */
553
- ZPOS64_T pos_found = 0;
554
- uLong read_size;
555
- ZPOS64_T read_pos;
556
- int i;
557
-
558
- buf = (unsigned char *)ALLOC(BUFREADCOMMENT + 4);
559
- if (buf == NULL)
560
- return 0;
561
-
562
- if (ZSEEK64(*pzlib_filefunc_def, filestream, 0, ZLIB_FILEFUNC_SEEK_END) != 0) {
563
- TRYFREE(buf);
564
- return 0;
565
- }
566
-
567
- file_size = ZTELL64(*pzlib_filefunc_def, filestream);
568
-
569
- if (max_back > file_size)
570
- max_back = file_size;
571
-
572
- while (back_read < max_back) {
573
- if (back_read + BUFREADCOMMENT > max_back)
574
- back_read = max_back;
575
- else
576
- back_read += BUFREADCOMMENT;
577
-
578
- read_pos = file_size - back_read;
579
- read_size = ((BUFREADCOMMENT + 4) < (file_size - read_pos)) ?
580
- (BUFREADCOMMENT + 4) : (uLong)(file_size - read_pos);
581
-
582
- if (ZSEEK64(*pzlib_filefunc_def, filestream, read_pos, ZLIB_FILEFUNC_SEEK_SET) != 0)
583
- break;
584
- if (ZREAD64(*pzlib_filefunc_def, filestream, buf, read_size) != read_size)
585
- break;
586
-
587
- for (i = (int)read_size - 3; (i--) > 0; )
588
- if ((*(buf + i)) == (ENDHEADERMAGIC & 0xff) &&
589
- (*(buf + i + 1)) == (ENDHEADERMAGIC >> 8 & 0xff) &&
590
- (*(buf + i + 2)) == (ENDHEADERMAGIC >> 16 & 0xff) &&
591
- (*(buf + i + 3)) == (ENDHEADERMAGIC >> 24 & 0xff)) {
592
- pos_found = read_pos + i;
593
- break;
594
- }
595
-
596
- if (pos_found != 0)
597
- break;
598
- }
599
- TRYFREE(buf);
600
- return pos_found;
601
- }
602
-
603
- /* Locate the Central directory 64 of a zipfile (at the end, just before the global comment) */
604
- local ZPOS64_T zip64local_SearchCentralDir64 OF((const zlib_filefunc64_32_def * pzlib_filefunc_def, voidpf filestream,
605
- const ZPOS64_T endcentraloffset));
606
- local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream,
607
- const ZPOS64_T endcentraloffset)
608
- {
609
- ZPOS64_T offset;
610
- uLong uL;
611
-
612
- /* Zip64 end of central directory locator */
613
- if (ZSEEK64(*pzlib_filefunc_def, filestream, endcentraloffset - SIZECENTRALHEADERLOCATOR, ZLIB_FILEFUNC_SEEK_SET) != 0)
614
- return 0;
615
-
616
- /* read locator signature */
617
- if (zip64local_getLong(pzlib_filefunc_def, filestream, &uL) != ZIP_OK)
618
- return 0;
619
- if (uL != ZIP64ENDLOCHEADERMAGIC)
620
- return 0;
621
- /* number of the disk with the start of the zip64 end of central directory */
622
- if (zip64local_getLong(pzlib_filefunc_def, filestream, &uL) != ZIP_OK)
623
- return 0;
624
- /* relative offset of the zip64 end of central directory record */
625
- if (zip64local_getLong64(pzlib_filefunc_def, filestream, &offset) != ZIP_OK)
626
- return 0;
627
- /* total number of disks */
628
- if (zip64local_getLong(pzlib_filefunc_def, filestream, &uL) != ZIP_OK)
629
- return 0;
630
- /* Goto end of central directory record */
631
- if (ZSEEK64(*pzlib_filefunc_def, filestream, offset, ZLIB_FILEFUNC_SEEK_SET) != 0)
632
- return 0;
633
- /* the signature */
634
- if (zip64local_getLong(pzlib_filefunc_def, filestream, &uL) != ZIP_OK)
635
- return 0;
636
- if (uL != ZIP64ENDHEADERMAGIC)
637
- return 0;
638
-
639
- return offset;
640
- }
641
-
642
- extern zipFile ZEXPORT zipOpen4(const void *pathname, int append, ZPOS64_T disk_size, zipcharpc *globalcomment,
643
- zlib_filefunc64_32_def *pzlib_filefunc64_32_def)
644
- {
645
- zip64_internal ziinit;
646
- zip64_internal *zi;
647
- #ifndef NO_ADDFILEINEXISTINGZIP
648
- ZPOS64_T byte_before_the_zipfile; /* byte before the zipfile, (>0 for sfx)*/
649
- ZPOS64_T size_central_dir = 0; /* size of the central directory */
650
- ZPOS64_T offset_central_dir = 0; /* offset of start of central directory */
651
- ZPOS64_T number_entry_CD = 0; /* total number of entries in the central dir */
652
- ZPOS64_T number_entry;
653
- ZPOS64_T central_pos;
654
- ZPOS64_T size_central_dir_to_read;
655
- uLong uL;
656
- uLong size_comment = 0;
657
- size_t buf_size = SIZEDATA_INDATABLOCK;
658
- void *buf_read;
659
- #endif
660
- int err = ZIP_OK;
661
- int mode;
662
-
663
- ziinit.z_filefunc.zseek32_file = NULL;
664
- ziinit.z_filefunc.ztell32_file = NULL;
665
- if (pzlib_filefunc64_32_def == NULL)
666
- fill_fopen64_filefunc(&ziinit.z_filefunc.zfile_func64);
667
- else
668
- ziinit.z_filefunc = *pzlib_filefunc64_32_def;
669
-
670
- if (append == APPEND_STATUS_CREATE)
671
- mode = (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE);
672
- else
673
- mode = (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING);
674
-
675
- ziinit.filestream = ZOPEN64(ziinit.z_filefunc, pathname, mode);
676
- if (ziinit.filestream == NULL)
677
- return NULL;
678
-
679
- if (append == APPEND_STATUS_CREATEAFTER) {
680
- /* Don't support spanning ZIP with APPEND_STATUS_CREATEAFTER */
681
- if (disk_size > 0)
682
- return NULL;
683
-
684
- ZSEEK64(ziinit.z_filefunc, ziinit.filestream, 0, SEEK_END);
685
- }
686
-
687
- ziinit.filestream_with_CD = ziinit.filestream;
688
- ziinit.append = append;
689
- ziinit.number_disk = 0;
690
- ziinit.number_disk_with_CD = 0;
691
- ziinit.disk_size = disk_size;
692
- ziinit.begin_pos = ZTELL64(ziinit.z_filefunc, ziinit.filestream);
693
- ziinit.in_opened_file_inzip = 0;
694
- ziinit.ci.stream_initialised = 0;
695
- ziinit.number_entry = 0;
696
- ziinit.add_position_when_writting_offset = 0;
697
- init_linkedlist(&(ziinit.central_dir));
698
-
699
- zi = (zip64_internal *)ALLOC(sizeof(zip64_internal));
700
- if (zi == NULL) {
701
- ZCLOSE64(ziinit.z_filefunc, ziinit.filestream);
702
- return NULL;
703
- }
704
-
705
- #ifndef NO_ADDFILEINEXISTINGZIP
706
- /* Add file in a zipfile */
707
- ziinit.globalcomment = NULL;
708
- if (append == APPEND_STATUS_ADDINZIP) {
709
- /* Read and Cache Central Directory Records */
710
- central_pos = zip64local_SearchCentralDir(&ziinit.z_filefunc, ziinit.filestream);
711
- /* disable to allow appending to empty ZIP archive (must be standard zip, not zip64)
712
- if (central_pos == 0)
713
- err = ZIP_ERRNO;
714
- */
715
-
716
- if (err == ZIP_OK) {
717
- /* read end of central directory info */
718
- if (ZSEEK64(ziinit.z_filefunc, ziinit.filestream, central_pos, ZLIB_FILEFUNC_SEEK_SET) != 0)
719
- err = ZIP_ERRNO;
720
-
721
- /* the signature, already checked */
722
- if (zip64local_getLong(&ziinit.z_filefunc, ziinit.filestream, &uL) != ZIP_OK)
723
- err = ZIP_ERRNO;
724
- /* number of this disk */
725
- if (zip64local_getShort(&ziinit.z_filefunc, ziinit.filestream, &ziinit.number_disk) != ZIP_OK)
726
- err = ZIP_ERRNO;
727
- /* number of the disk with the start of the central directory */
728
- if (zip64local_getShort(&ziinit.z_filefunc, ziinit.filestream, &ziinit.number_disk_with_CD) != ZIP_OK)
729
- err = ZIP_ERRNO;
730
- /* total number of entries in the central dir on this disk */
731
- number_entry = 0;
732
- if (zip64local_getShort(&ziinit.z_filefunc, ziinit.filestream, &uL) != ZIP_OK)
733
- err = ZIP_ERRNO;
734
- else
735
- number_entry = uL;
736
- /* total number of entries in the central dir */
737
- number_entry_CD = 0;
738
- if (zip64local_getShort(&ziinit.z_filefunc, ziinit.filestream, &uL) != ZIP_OK)
739
- err = ZIP_ERRNO;
740
- else
741
- number_entry_CD = uL;
742
- if (number_entry_CD != number_entry)
743
- err = ZIP_BADZIPFILE;
744
- /* size of the central directory */
745
- size_central_dir = 0;
746
- if (zip64local_getLong(&ziinit.z_filefunc, ziinit.filestream, &uL) != ZIP_OK)
747
- err = ZIP_ERRNO;
748
- else
749
- size_central_dir = uL;
750
- /* offset of start of central directory with respect to the starting disk number */
751
- offset_central_dir = 0;
752
- if (zip64local_getLong(&ziinit.z_filefunc, ziinit.filestream, &uL) != ZIP_OK)
753
- err = ZIP_ERRNO;
754
- else
755
- offset_central_dir = uL;
756
- /* zipfile global comment length */
757
- if (zip64local_getShort(&ziinit.z_filefunc, ziinit.filestream, &size_comment) != ZIP_OK)
758
- err = ZIP_ERRNO;
759
-
760
- if ((err == ZIP_OK) && ((number_entry_CD == 0xffff) || (offset_central_dir == 0xffffffff))) {
761
- /* Format should be Zip64, as the central directory or file size is too large */
762
- central_pos = zip64local_SearchCentralDir64(&ziinit.z_filefunc, ziinit.filestream, central_pos);
763
-
764
- if (central_pos) {
765
- ZPOS64_T sizeEndOfCentralDirectory;
766
-
767
- if (ZSEEK64(ziinit.z_filefunc, ziinit.filestream, central_pos, ZLIB_FILEFUNC_SEEK_SET) != 0)
768
- err = ZIP_ERRNO;
769
-
770
- /* the signature, already checked */
771
- if (zip64local_getLong(&ziinit.z_filefunc, ziinit.filestream, &uL) != ZIP_OK)
772
- err = ZIP_ERRNO;
773
- /* size of zip64 end of central directory record */
774
- if (zip64local_getLong64(&ziinit.z_filefunc, ziinit.filestream, &sizeEndOfCentralDirectory) != ZIP_OK)
775
- err = ZIP_ERRNO;
776
- /* version made by */
777
- if (zip64local_getShort(&ziinit.z_filefunc, ziinit.filestream, &uL) != ZIP_OK)
778
- err = ZIP_ERRNO;
779
- /* version needed to extract */
780
- if (zip64local_getShort(&ziinit.z_filefunc, ziinit.filestream, &uL) != ZIP_OK)
781
- err = ZIP_ERRNO;
782
- /* number of this disk */
783
- if (zip64local_getLong(&ziinit.z_filefunc, ziinit.filestream, &ziinit.number_disk) != ZIP_OK)
784
- err = ZIP_ERRNO;
785
- /* number of the disk with the start of the central directory */
786
- if (zip64local_getLong(&ziinit.z_filefunc, ziinit.filestream, &ziinit.number_disk_with_CD) != ZIP_OK)
787
- err = ZIP_ERRNO;
788
- /* total number of entries in the central directory on this disk */
789
- if (zip64local_getLong64(&ziinit.z_filefunc, ziinit.filestream, &number_entry) != ZIP_OK)
790
- err = ZIP_ERRNO;
791
- /* total number of entries in the central directory */
792
- if (zip64local_getLong64(&ziinit.z_filefunc, ziinit.filestream, &number_entry_CD) != ZIP_OK)
793
- err = ZIP_ERRNO;
794
- if (number_entry_CD != number_entry)
795
- err = ZIP_BADZIPFILE;
796
- /* size of the central directory */
797
- if (zip64local_getLong64(&ziinit.z_filefunc, ziinit.filestream, &size_central_dir) != ZIP_OK)
798
- err = ZIP_ERRNO;
799
- /* offset of start of central directory with respect to the starting disk number */
800
- if (zip64local_getLong64(&ziinit.z_filefunc, ziinit.filestream, &offset_central_dir) != ZIP_OK)
801
- err = ZIP_ERRNO;
802
- } else
803
- err = ZIP_BADZIPFILE;
804
- }
805
- }
806
-
807
- if ((err == ZIP_OK) && (central_pos < offset_central_dir + size_central_dir))
808
- err = ZIP_BADZIPFILE;
809
-
810
- if (err != ZIP_OK) {
811
- ZCLOSE64(ziinit.z_filefunc, ziinit.filestream);
812
- TRYFREE(zi);
813
- return NULL;
814
- }
815
-
816
- if (size_comment > 0) {
817
- ziinit.globalcomment = (char *)ALLOC(size_comment + 1);
818
- if (ziinit.globalcomment) {
819
- size_comment = ZREAD64(ziinit.z_filefunc, ziinit.filestream, ziinit.globalcomment, size_comment);
820
- ziinit.globalcomment[size_comment] = 0;
821
- }
822
- }
823
-
824
- byte_before_the_zipfile = central_pos - (offset_central_dir + size_central_dir);
825
- ziinit.add_position_when_writting_offset = byte_before_the_zipfile;
826
-
827
- /* Store central directory in memory */
828
- size_central_dir_to_read = size_central_dir;
829
- buf_size = SIZEDATA_INDATABLOCK;
830
- buf_read = (void *)ALLOC(buf_size);
831
-
832
- if (ZSEEK64(ziinit.z_filefunc, ziinit.filestream,
833
- offset_central_dir + byte_before_the_zipfile, ZLIB_FILEFUNC_SEEK_SET) != 0)
834
- err = ZIP_ERRNO;
835
-
836
- while ((size_central_dir_to_read > 0) && (err == ZIP_OK)) {
837
- ZPOS64_T read_this = SIZEDATA_INDATABLOCK;
838
- if (read_this > size_central_dir_to_read)
839
- read_this = size_central_dir_to_read;
840
-
841
- if (ZREAD64(ziinit.z_filefunc, ziinit.filestream, buf_read, (uLong)read_this) != read_this)
842
- err = ZIP_ERRNO;
843
-
844
- if (err == ZIP_OK)
845
- err = add_data_in_datablock(&ziinit.central_dir, buf_read, (uLong)read_this);
846
-
847
- size_central_dir_to_read -= read_this;
848
- }
849
- TRYFREE(buf_read);
850
-
851
- ziinit.begin_pos = byte_before_the_zipfile;
852
- ziinit.number_entry = number_entry_CD;
853
-
854
- if (ZSEEK64(ziinit.z_filefunc, ziinit.filestream,
855
- offset_central_dir + byte_before_the_zipfile, ZLIB_FILEFUNC_SEEK_SET) != 0)
856
- err = ZIP_ERRNO;
857
- }
858
-
859
- if (globalcomment)
860
- *globalcomment = ziinit.globalcomment;
861
- #endif
862
-
863
- if (err != ZIP_OK) {
864
- #ifndef NO_ADDFILEINEXISTINGZIP
865
- TRYFREE(ziinit.globalcomment);
866
- #endif
867
- TRYFREE(zi);
868
- return NULL;
869
- }
870
-
871
- *zi = ziinit;
872
- zipGoToFirstDisk((zipFile)zi);
873
- return (zipFile)zi;
874
- }
875
-
876
- extern zipFile ZEXPORT zipOpen2(const char *pathname, int append, zipcharpc *globalcomment,
877
- zlib_filefunc_def *pzlib_filefunc32_def)
878
- {
879
- if (pzlib_filefunc32_def != NULL) {
880
- zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
881
- fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill, pzlib_filefunc32_def);
882
- return zipOpen4(pathname, append, 0, globalcomment, &zlib_filefunc64_32_def_fill);
883
- }
884
- return zipOpen4(pathname, append, 0, globalcomment, NULL);
885
- }
886
-
887
- extern zipFile ZEXPORT zipOpen2_64(const void *pathname, int append, zipcharpc *globalcomment,
888
- zlib_filefunc64_def *pzlib_filefunc_def)
889
- {
890
- if (pzlib_filefunc_def != NULL) {
891
- zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
892
- zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
893
- zlib_filefunc64_32_def_fill.ztell32_file = NULL;
894
- zlib_filefunc64_32_def_fill.zseek32_file = NULL;
895
- return zipOpen4(pathname, append, 0, globalcomment, &zlib_filefunc64_32_def_fill);
896
- }
897
- return zipOpen4(pathname, append, 0, globalcomment, NULL);
898
- }
899
-
900
- extern zipFile ZEXPORT zipOpen3(const char *pathname, int append, ZPOS64_T disk_size, zipcharpc *globalcomment,
901
- zlib_filefunc_def *pzlib_filefunc32_def)
902
- {
903
- if (pzlib_filefunc32_def != NULL) {
904
- zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
905
- fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill, pzlib_filefunc32_def);
906
- return zipOpen4(pathname, append, disk_size, globalcomment, &zlib_filefunc64_32_def_fill);
907
- }
908
- return zipOpen4(pathname, append, disk_size, globalcomment, NULL);
909
- }
910
-
911
- extern zipFile ZEXPORT zipOpen3_64(const void *pathname, int append, ZPOS64_T disk_size, zipcharpc *globalcomment,
912
- zlib_filefunc64_def *pzlib_filefunc_def)
913
- {
914
- if (pzlib_filefunc_def != NULL) {
915
- zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
916
- zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
917
- zlib_filefunc64_32_def_fill.ztell32_file = NULL;
918
- zlib_filefunc64_32_def_fill.zseek32_file = NULL;
919
- return zipOpen4(pathname, append, disk_size, globalcomment, &zlib_filefunc64_32_def_fill);
920
- }
921
- return zipOpen4(pathname, append, disk_size, globalcomment, NULL);
922
- }
923
-
924
- extern zipFile ZEXPORT zipOpen(const char *pathname, int append)
925
- {
926
- return zipOpen3((const void *)pathname, append, 0, NULL, NULL);
927
- }
928
-
929
- extern zipFile ZEXPORT zipOpen64(const void *pathname, int append)
930
- {
931
- return zipOpen3(pathname, append, 0, NULL, NULL);
932
- }
933
-
934
- extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
935
- const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global,
936
- uInt size_extrafield_global, const char *comment, int method, int level, int raw, int windowBits, int memLevel,
937
- int strategy, const char *password, uLong crcForCrypting, uLong versionMadeBy, uLong flagBase, int zip64)
938
- {
939
- zip64_internal *zi;
940
- uInt size_filename;
941
- uInt size_comment = 0;
942
- uInt i;
943
- int err = ZIP_OK;
944
- ZPOS64_T size_available;
945
- ZPOS64_T size_needed;
946
-
947
- #ifdef NOCRYPT
948
- (crcForCrypting);
949
- if (password != NULL)
950
- return ZIP_PARAMERROR;
951
- #endif
952
-
953
- if (file == NULL)
954
- return ZIP_PARAMERROR;
955
-
956
- if ((method != 0) &&
957
- #ifdef HAVE_BZIP2
958
- (method != Z_BZIP2ED) &&
959
- #endif
960
- (method != Z_DEFLATED))
961
- return ZIP_PARAMERROR;
962
-
963
- zi = (zip64_internal *)file;
964
-
965
- if (zi->in_opened_file_inzip == 1) {
966
- err = zipCloseFileInZip(file);
967
- if (err != ZIP_OK)
968
- return err;
969
- }
970
-
971
- if (filename == NULL)
972
- filename = "-";
973
- if (comment != NULL)
974
- size_comment = (uInt)strlen(comment);
975
-
976
- size_filename = (uInt)strlen(filename);
977
-
978
- if (zipfi == NULL)
979
- zi->ci.dosDate = 0;
980
- else {
981
- if (zipfi->dosDate != 0)
982
- zi->ci.dosDate = zipfi->dosDate;
983
- else
984
- zi->ci.dosDate = zip64local_TmzDateToDosDate(&zipfi->tmz_date);
985
- }
986
-
987
- zi->ci.method = method;
988
- zi->ci.compression_method = method;
989
- zi->ci.crc32 = 0;
990
- zi->ci.stream_initialised = 0;
991
- zi->ci.pos_in_buffered_data = 0;
992
- zi->ci.raw = raw;
993
- zi->ci.flag = flagBase;
994
- if ((level == 8) || (level == 9))
995
- zi->ci.flag |= 2;
996
- if (level == 2)
997
- zi->ci.flag |= 4;
998
- if (level == 1)
999
- zi->ci.flag |= 6;
1000
- if (password != NULL) {
1001
- zi->ci.flag |= 1;
1002
- #ifdef HAVE_AES
1003
- zi->ci.method = AES_METHOD;
1004
- #endif
1005
- }
1006
-
1007
- if (zi->disk_size > 0) {
1008
- if ((zi->number_disk == 0) && (zi->number_entry == 0))
1009
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)DISKHEADERMAGIC, 4);
1010
-
1011
- /* Make sure enough space available on current disk for local header */
1012
- zipGetDiskSizeAvailable((zipFile)zi, &size_available);
1013
- size_needed = 30 + size_filename + size_extrafield_local;
1014
- if (zi->ci.zip64)
1015
- size_needed += 20;
1016
- #ifdef HAVE_AES
1017
- if (zi->ci.method == AES_METHOD)
1018
- size_needed += 11;
1019
- #endif
1020
- if (size_available < size_needed)
1021
- zipGoToNextDisk((zipFile)zi);
1022
- }
1023
-
1024
- zi->ci.pos_local_header = ZTELL64(zi->z_filefunc, zi->filestream);
1025
- zi->ci.size_comment = size_comment;
1026
- zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + size_extrafield_global;
1027
- zi->ci.size_centralextra = size_extrafield_global;
1028
- zi->ci.size_centralextrafree = 32; /* Extra space reserved for ZIP64 extra info */
1029
- #ifdef HAVE_AES
1030
- if (zi->ci.method == AES_METHOD)
1031
- zi->ci.size_centralextrafree += 11; /* Extra space reserved for AES extra info */
1032
- #endif
1033
- zi->ci.central_header = (char *)ALLOC((uInt)zi->ci.size_centralheader + zi->ci.size_centralextrafree + size_comment);
1034
- zi->ci.number_disk = zi->number_disk;
1035
-
1036
- /* Write central directory header */
1037
- zip64local_putValue_inmemory(zi->ci.central_header, (uLong)CENTRALHEADERMAGIC, 4);
1038
- zip64local_putValue_inmemory(zi->ci.central_header + 4, (uLong)versionMadeBy, 2);
1039
- zip64local_putValue_inmemory(zi->ci.central_header + 6, (uLong)20, 2);
1040
- zip64local_putValue_inmemory(zi->ci.central_header + 8, (uLong)zi->ci.flag, 2);
1041
- zip64local_putValue_inmemory(zi->ci.central_header + 10, (uLong)zi->ci.method, 2);
1042
- zip64local_putValue_inmemory(zi->ci.central_header + 12, (uLong)zi->ci.dosDate, 4);
1043
- zip64local_putValue_inmemory(zi->ci.central_header + 16, (uLong)0, 4); /*crc*/
1044
- zip64local_putValue_inmemory(zi->ci.central_header + 20, (uLong)0, 4); /*compr size*/
1045
- zip64local_putValue_inmemory(zi->ci.central_header + 24, (uLong)0, 4); /*uncompr size*/
1046
- zip64local_putValue_inmemory(zi->ci.central_header + 28, (uLong)size_filename, 2);
1047
- zip64local_putValue_inmemory(zi->ci.central_header + 30, (uLong)size_extrafield_global, 2);
1048
- zip64local_putValue_inmemory(zi->ci.central_header + 32, (uLong)size_comment, 2);
1049
- zip64local_putValue_inmemory(zi->ci.central_header + 34, (uLong)zi->ci.number_disk, 2); /*disk nm start*/
1050
-
1051
- if (zipfi == NULL)
1052
- zip64local_putValue_inmemory(zi->ci.central_header + 36, (uLong)0, 2);
1053
- else
1054
- zip64local_putValue_inmemory(zi->ci.central_header + 36, (uLong)zipfi->internal_fa, 2);
1055
- if (zipfi == NULL)
1056
- zip64local_putValue_inmemory(zi->ci.central_header + 38, (uLong)0, 4);
1057
- else
1058
- zip64local_putValue_inmemory(zi->ci.central_header + 38, (uLong)zipfi->external_fa, 4);
1059
- if (zi->ci.pos_local_header >= 0xffffffff)
1060
- zip64local_putValue_inmemory(zi->ci.central_header + 42, (uLong)0xffffffff, 4);
1061
- else
1062
- zip64local_putValue_inmemory(zi->ci.central_header + 42,
1063
- (uLong)zi->ci.pos_local_header - zi->add_position_when_writting_offset, 4);
1064
-
1065
- for (i = 0; i < size_filename; i++)
1066
- zi->ci.central_header[SIZECENTRALHEADER + i] = filename[i];
1067
- for (i = 0; i < size_extrafield_global; i++)
1068
- zi->ci.central_header[SIZECENTRALHEADER + size_filename + i] =
1069
- ((const char *)extrafield_global)[i];
1070
- /* Store comment at the end for later repositioning */
1071
- for (i = 0; i < size_comment; i++)
1072
- zi->ci.central_header[zi->ci.size_centralheader +
1073
- zi->ci.size_centralextrafree + i] = comment[i];
1074
-
1075
- if (zi->ci.central_header == NULL)
1076
- return ZIP_INTERNALERROR;
1077
-
1078
- zi->ci.zip64 = zip64;
1079
- zi->ci.total_compressed = 0;
1080
- zi->ci.total_uncompressed = 0;
1081
- zi->ci.pos_zip64extrainfo = 0;
1082
-
1083
- /* Write the local header */
1084
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)LOCALHEADERMAGIC, 4);
1085
-
1086
- if (err == ZIP_OK) {
1087
- if (zi->ci.zip64)
1088
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)45, 2); /* version needed to extract */
1089
- else
1090
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)20, 2); /* version needed to extract */
1091
- }
1092
- if (err == ZIP_OK)
1093
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)zi->ci.flag, 2);
1094
- if (err == ZIP_OK)
1095
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)zi->ci.method, 2);
1096
- if (err == ZIP_OK)
1097
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)zi->ci.dosDate, 4);
1098
-
1099
- /* CRC & compressed size & uncompressed size will be filled in later and rewritten later */
1100
-
1101
- if (err == ZIP_OK)
1102
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)0, 4); /* crc 32, unknown */
1103
- if (err == ZIP_OK) {
1104
- if (zi->ci.zip64)
1105
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)0xFFFFFFFF, 4); /* compressed size, unknown */
1106
- else
1107
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)0, 4); /* compressed size, unknown */
1108
- }
1109
- if (err == ZIP_OK) {
1110
- if (zi->ci.zip64) /* uncompressed size, unknown */
1111
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)0xFFFFFFFF, 4);
1112
- else /* uncompressed size, unknown */
1113
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)0, 4);
1114
- }
1115
- if (err == ZIP_OK)
1116
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)size_filename, 2);
1117
- if (err == ZIP_OK) {
1118
- ZPOS64_T size_extrafield = size_extrafield_local;
1119
- if (zi->ci.zip64)
1120
- size_extrafield += 20;
1121
- #ifdef HAVE_AES
1122
- if (zi->ci.method == AES_METHOD)
1123
- size_extrafield += 11;
1124
- #endif
1125
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)size_extrafield, 2);
1126
- }
1127
- if ((err == ZIP_OK) && (size_filename > 0)) {
1128
- if (ZWRITE64(zi->z_filefunc, zi->filestream, filename, size_filename) != size_filename)
1129
- err = ZIP_ERRNO;
1130
- }
1131
- if ((err == ZIP_OK) && (size_extrafield_local > 0)) {
1132
- if (ZWRITE64(zi->z_filefunc, zi->filestream, extrafield_local, size_extrafield_local) != size_extrafield_local)
1133
- err = ZIP_ERRNO;
1134
- }
1135
-
1136
- /* Write the Zip64 extended info */
1137
- if ((err == ZIP_OK) && (zi->ci.zip64)) {
1138
- short headerid = 1;
1139
- short datasize = 16;
1140
- ZPOS64_T compressed_size = 0;
1141
- ZPOS64_T uncompressed_size = 0;
1142
-
1143
- /* Remember position of Zip64 extended info for the local file header.
1144
- (needed when we update size after done with file) */
1145
- zi->ci.pos_zip64extrainfo = ZTELL64(zi->z_filefunc, zi->filestream);
1146
-
1147
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (short)headerid, 2);
1148
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (short)datasize, 2);
1149
-
1150
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)uncompressed_size, 8);
1151
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)compressed_size, 8);
1152
- }
1153
- #ifdef HAVE_AES
1154
- /* Write the AES extended info */
1155
- if ((err == ZIP_OK) && (zi->ci.method == AES_METHOD)) {
1156
- int headerid = 0x9901;
1157
- short datasize = 7;
1158
-
1159
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, headerid, 2);
1160
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, datasize, 2);
1161
-
1162
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, AES_VERSION, 2);
1163
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, 'A', 1);
1164
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, 'E', 1);
1165
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, AES_ENCRYPTIONMODE, 1);
1166
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->ci.compression_method, 2);
1167
- }
1168
- #endif
1169
-
1170
- #ifdef HAVE_BZIP2
1171
- zi->ci.bstream.avail_in = (uInt)0;
1172
- zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
1173
- zi->ci.bstream.next_out = (char *)zi->ci.buffered_data;
1174
- zi->ci.bstream.total_in_hi32 = 0;
1175
- zi->ci.bstream.total_in_lo32 = 0;
1176
- zi->ci.bstream.total_out_hi32 = 0;
1177
- zi->ci.bstream.total_out_lo32 = 0;
1178
- #endif
1179
-
1180
- zi->ci.stream.avail_in = (uInt)0;
1181
- zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
1182
- zi->ci.stream.next_out = zi->ci.buffered_data;
1183
- zi->ci.stream.total_in = 0;
1184
- zi->ci.stream.total_out = 0;
1185
- zi->ci.stream.data_type = Z_BINARY;
1186
-
1187
- if ((err == ZIP_OK) && (!zi->ci.raw)) {
1188
- if (method == Z_DEFLATED) {
1189
- zi->ci.stream.zalloc = (alloc_func)0;
1190
- zi->ci.stream.zfree = (free_func)0;
1191
- zi->ci.stream.opaque = (voidpf)zi;
1192
-
1193
- if (windowBits > 0)
1194
- windowBits = -windowBits;
1195
-
1196
- err = deflateInit2(&zi->ci.stream, level, Z_DEFLATED, windowBits, memLevel, strategy);
1197
-
1198
- if (err == Z_OK)
1199
- zi->ci.stream_initialised = Z_DEFLATED;
1200
- } else if (method == Z_BZIP2ED) {
1201
- #ifdef HAVE_BZIP2
1202
- zi->ci.bstream.bzalloc = 0;
1203
- zi->ci.bstream.bzfree = 0;
1204
- zi->ci.bstream.opaque = (voidpf)0;
1205
-
1206
- err = BZ2_bzCompressInit(&zi->ci.bstream, level, 0, 35);
1207
- if (err == BZ_OK)
1208
- zi->ci.stream_initialised = Z_BZIP2ED;
1209
- #endif
1210
- }
1211
- }
1212
-
1213
- #ifndef NOCRYPT
1214
- zi->ci.crypt_header_size = 0;
1215
- if ((err == Z_OK) && ((zi->ci.flag & 1) != 0)) {
1216
- #ifdef HAVE_AES
1217
- if (zi->ci.method == AES_METHOD) {
1218
- unsigned char passverify[AES_PWVERIFYSIZE];
1219
- unsigned char saltvalue[AES_MAXSALTLENGTH];
1220
- uInt saltlength;
1221
-
1222
- if ((AES_ENCRYPTIONMODE < 1) || (AES_ENCRYPTIONMODE > 3))
1223
- return Z_ERRNO;
1224
-
1225
- saltlength = SALT_LENGTH(AES_ENCRYPTIONMODE);
1226
-
1227
- prng_init(entropy_fun, zi->ci.aes_rng);
1228
- prng_rand(saltvalue, saltlength, zi->ci.aes_rng);
1229
- prng_end(zi->ci.aes_rng);
1230
-
1231
- fcrypt_init(AES_ENCRYPTIONMODE, (unsigned char *)password, (unsigned int)strlen(password), saltvalue, passverify, &zi->ci.aes_ctx);
1232
-
1233
- if (ZWRITE64(zi->z_filefunc, zi->filestream, saltvalue, saltlength) != saltlength)
1234
- err = ZIP_ERRNO;
1235
- if (ZWRITE64(zi->z_filefunc, zi->filestream, passverify, AES_PWVERIFYSIZE) != AES_PWVERIFYSIZE)
1236
- err = ZIP_ERRNO;
1237
-
1238
- zi->ci.crypt_header_size = saltlength + AES_PWVERIFYSIZE + AES_AUTHCODESIZE;
1239
- } else
1240
- #endif
1241
- {
1242
- unsigned char bufHead[RAND_HEAD_LEN];
1243
- unsigned int sizeHead;
1244
-
1245
- zi->ci.pcrc_32_tab = (const unsigned long *)get_crc_table();
1246
- /*init_keys(password, zi->ci.keys, zi->ci.pcrc_32_tab);*/
1247
-
1248
- sizeHead = crypthead(password, bufHead, RAND_HEAD_LEN, zi->ci.keys, zi->ci.pcrc_32_tab, crcForCrypting);
1249
- zi->ci.crypt_header_size = sizeHead;
1250
-
1251
- if (ZWRITE64(zi->z_filefunc, zi->filestream, bufHead, sizeHead) != sizeHead)
1252
- err = ZIP_ERRNO;
1253
- }
1254
- }
1255
- #endif
1256
-
1257
- if (err == Z_OK)
1258
- zi->in_opened_file_inzip = 1;
1259
- return err;
1260
- }
1261
-
1262
- extern int ZEXPORT zipOpenNewFileInZip4(zipFile file, const char *filename, const zip_fileinfo *zipfi,
1263
- const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global,
1264
- uInt size_extrafield_global, const char *comment, int method, int level, int raw, int windowBits,
1265
- int memLevel, int strategy, const char *password, uLong crcForCrypting, uLong versionMadeBy, uLong flagBase)
1266
- {
1267
- return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local,
1268
- extrafield_global, size_extrafield_global, comment, method, level, raw, windowBits, memLevel,
1269
- strategy, password, crcForCrypting, versionMadeBy, flagBase, 0);
1270
- }
1271
-
1272
- extern int ZEXPORT zipOpenNewFileInZip3(zipFile file, const char *filename, const zip_fileinfo *zipfi,
1273
- const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global,
1274
- uInt size_extrafield_global, const char *comment, int method, int level, int raw, int windowBits,
1275
- int memLevel, int strategy, const char *password, uLong crcForCrypting)
1276
- {
1277
- return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local,
1278
- extrafield_global, size_extrafield_global, comment, method, level, raw, windowBits, memLevel,
1279
- strategy, password, crcForCrypting, VERSIONMADEBY, 0, 0);
1280
- }
1281
-
1282
- extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
1283
- const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global,
1284
- uInt size_extrafield_global, const char *comment, int method, int level, int raw, int windowBits,
1285
- int memLevel, int strategy, const char *password, uLong crcForCrypting, int zip64)
1286
- {
1287
- return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local,
1288
- extrafield_global, size_extrafield_global, comment, method, level, raw, windowBits, memLevel, strategy,
1289
- password, crcForCrypting, VERSIONMADEBY, 0, zip64);
1290
- }
1291
-
1292
- extern int ZEXPORT zipOpenNewFileInZip2(zipFile file, const char *filename, const zip_fileinfo *zipfi,
1293
- const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global,
1294
- uInt size_extrafield_global, const char *comment, int method, int level, int raw)
1295
- {
1296
- return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local,
1297
- extrafield_global, size_extrafield_global, comment, method, level, raw, -MAX_WBITS, DEF_MEM_LEVEL,
1298
- Z_DEFAULT_STRATEGY, NULL, 0, VERSIONMADEBY, 0, 0);
1299
- }
1300
-
1301
- extern int ZEXPORT zipOpenNewFileInZip2_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
1302
- const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global,
1303
- uInt size_extrafield_global, const char *comment, int method, int level, int raw, int zip64)
1304
- {
1305
- return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local,
1306
- extrafield_global, size_extrafield_global, comment, method, level, raw, -MAX_WBITS, DEF_MEM_LEVEL,
1307
- Z_DEFAULT_STRATEGY, NULL, 0, VERSIONMADEBY, 0, zip64);
1308
- }
1309
-
1310
- extern int ZEXPORT zipOpenNewFileInZip64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
1311
- const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global,
1312
- uInt size_extrafield_global, const char *comment, int method, int level, int zip64)
1313
- {
1314
- return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local,
1315
- extrafield_global, size_extrafield_global, comment, method, level, 0, -MAX_WBITS, DEF_MEM_LEVEL,
1316
- Z_DEFAULT_STRATEGY, NULL, 0, VERSIONMADEBY, 0, zip64);
1317
- }
1318
-
1319
- extern int ZEXPORT zipOpenNewFileInZip(zipFile file, const char *filename, const zip_fileinfo *zipfi,
1320
- const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global,
1321
- uInt size_extrafield_global, const char *comment, int method, int level)
1322
- {
1323
- return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local,
1324
- extrafield_global, size_extrafield_global, comment, method, level, 0, -MAX_WBITS, DEF_MEM_LEVEL,
1325
- Z_DEFAULT_STRATEGY, NULL, 0, VERSIONMADEBY, 0, 0);
1326
- }
1327
-
1328
- /* Flushes the write buffer to disk */
1329
- local int zip64FlushWriteBuffer OF((zip64_internal * zi));
1330
- local int zip64FlushWriteBuffer(zip64_internal *zi)
1331
- {
1332
- int err = ZIP_OK;
1333
- uInt written = 0;
1334
- uInt total_written = 0;
1335
- uInt write = 0;
1336
- uInt max_write = 0;
1337
- ZPOS64_T size_available = 0;
1338
-
1339
- if ((zi->ci.flag & 1) != 0) {
1340
- #ifndef NOCRYPT
1341
- #ifdef HAVE_AES
1342
- if (zi->ci.method == AES_METHOD) {
1343
- fcrypt_encrypt(zi->ci.buffered_data, zi->ci.pos_in_buffered_data, &zi->ci.aes_ctx);
1344
- } else
1345
- #endif
1346
- {
1347
- uInt i;
1348
- int t;
1349
- for (i = 0; i < zi->ci.pos_in_buffered_data; i++)
1350
- zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab, zi->ci.buffered_data[i], t);
1351
- }
1352
- #endif
1353
- }
1354
-
1355
- write = zi->ci.pos_in_buffered_data;
1356
-
1357
- do {
1358
- max_write = write;
1359
-
1360
- if (zi->disk_size > 0) {
1361
- err = zipGetDiskSizeAvailable((zipFile)zi, &size_available);
1362
- if (err != ZIP_OK)
1363
- return err;
1364
-
1365
- if (size_available == 0) {
1366
- err = zipGoToNextDisk((zipFile)zi);
1367
- if (err != ZIP_OK)
1368
- return err;
1369
- }
1370
-
1371
- if (size_available < (ZPOS64_T)max_write)
1372
- max_write = (uInt)size_available;
1373
- }
1374
-
1375
- written = (unsigned int)ZWRITE64(zi->z_filefunc, zi->filestream, zi->ci.buffered_data + total_written, max_write);
1376
-
1377
- if (ZERROR64(zi->z_filefunc, zi->filestream)) {
1378
- err = ZIP_ERRNO;
1379
- break;
1380
- }
1381
-
1382
- total_written += written;
1383
- write -= written;
1384
- } while (write > 0);
1385
-
1386
- zi->ci.total_compressed += zi->ci.pos_in_buffered_data;
1387
-
1388
- #ifdef HAVE_BZIP2
1389
- if (zi->ci.compression_method == Z_BZIP2ED) {
1390
- zi->ci.total_uncompressed += zi->ci.bstream.total_in_lo32;
1391
- zi->ci.bstream.total_in_lo32 = 0;
1392
- zi->ci.bstream.total_in_hi32 = 0;
1393
- } else
1394
- #endif
1395
- {
1396
- zi->ci.total_uncompressed += zi->ci.stream.total_in;
1397
- zi->ci.stream.total_in = 0;
1398
- }
1399
-
1400
- zi->ci.pos_in_buffered_data = 0;
1401
-
1402
- return err;
1403
- }
1404
-
1405
- extern int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, unsigned int len)
1406
- {
1407
- zip64_internal *zi;
1408
- int err = ZIP_OK;
1409
-
1410
- if (file == NULL)
1411
- return ZIP_PARAMERROR;
1412
- zi = (zip64_internal *)file;
1413
-
1414
- if (zi->in_opened_file_inzip == 0)
1415
- return ZIP_PARAMERROR;
1416
-
1417
- zi->ci.crc32 = crc32(zi->ci.crc32, buf, (uInt)len);
1418
-
1419
- #ifdef HAVE_BZIP2
1420
- if ((zi->ci.compression_method == Z_BZIP2ED) && (!zi->ci.raw)) {
1421
- zi->ci.bstream.next_in = (void *)buf;
1422
- zi->ci.bstream.avail_in = len;
1423
- err = BZ_RUN_OK;
1424
-
1425
- while ((err == BZ_RUN_OK) && (zi->ci.bstream.avail_in > 0)) {
1426
- if (zi->ci.bstream.avail_out == 0) {
1427
- if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
1428
- err = ZIP_ERRNO;
1429
- zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
1430
- zi->ci.bstream.next_out = (char *)zi->ci.buffered_data;
1431
- } else {
1432
- uLong uTotalOutBefore_lo = zi->ci.bstream.total_out_lo32;
1433
- uLong uTotalOutBefore_hi = zi->ci.bstream.total_out_hi32;
1434
-
1435
- err = BZ2_bzCompress(&zi->ci.bstream, BZ_RUN);
1436
-
1437
- zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore_lo);
1438
- }
1439
- }
1440
-
1441
- if (err == BZ_RUN_OK)
1442
- err = ZIP_OK;
1443
- } else
1444
- #endif
1445
- {
1446
- zi->ci.stream.next_in = (Bytef *)buf;
1447
- zi->ci.stream.avail_in = len;
1448
-
1449
- while ((err == ZIP_OK) && (zi->ci.stream.avail_in > 0)) {
1450
- if (zi->ci.stream.avail_out == 0) {
1451
- if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
1452
- err = ZIP_ERRNO;
1453
- zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
1454
- zi->ci.stream.next_out = zi->ci.buffered_data;
1455
- }
1456
-
1457
- if (err != ZIP_OK)
1458
- break;
1459
-
1460
- if ((zi->ci.compression_method == Z_DEFLATED) && (!zi->ci.raw)) {
1461
- uLong total_out_before = zi->ci.stream.total_out;
1462
- err = deflate(&zi->ci.stream, Z_NO_FLUSH);
1463
- zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - total_out_before);
1464
- } else {
1465
- uInt copy_this, i;
1466
- if (zi->ci.stream.avail_in < zi->ci.stream.avail_out)
1467
- copy_this = zi->ci.stream.avail_in;
1468
- else
1469
- copy_this = zi->ci.stream.avail_out;
1470
-
1471
- for (i = 0; i < copy_this; i++)
1472
- *(((char *)zi->ci.stream.next_out) + i) =
1473
- *(((const char *)zi->ci.stream.next_in) + i);
1474
-
1475
- zi->ci.stream.avail_in -= copy_this;
1476
- zi->ci.stream.avail_out -= copy_this;
1477
- zi->ci.stream.next_in += copy_this;
1478
- zi->ci.stream.next_out += copy_this;
1479
- zi->ci.stream.total_in += copy_this;
1480
- zi->ci.stream.total_out += copy_this;
1481
- zi->ci.pos_in_buffered_data += copy_this;
1482
- }
1483
- }
1484
- }
1485
-
1486
- return err;
1487
- }
1488
-
1489
- extern int ZEXPORT zipCloseFileInZipRaw(zipFile file, uLong uncompressed_size, uLong crc32)
1490
- {
1491
- return zipCloseFileInZipRaw64(file, uncompressed_size, crc32);
1492
- }
1493
-
1494
- extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_size, uLong crc32)
1495
- {
1496
- zip64_internal *zi;
1497
- ZPOS64_T compressed_size;
1498
- uLong invalidValue = 0xffffffff;
1499
- uLong i = 0;
1500
- short datasize = 0;
1501
- int err = ZIP_OK;
1502
-
1503
- if (file == NULL)
1504
- return ZIP_PARAMERROR;
1505
- zi = (zip64_internal *)file;
1506
-
1507
- if (zi->in_opened_file_inzip == 0)
1508
- return ZIP_PARAMERROR;
1509
- zi->ci.stream.avail_in = 0;
1510
-
1511
- if (!zi->ci.raw) {
1512
- if (zi->ci.compression_method == Z_DEFLATED) {
1513
- while (err == ZIP_OK) {
1514
- uLong total_out_before;
1515
- if (zi->ci.stream.avail_out == 0) {
1516
- if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
1517
- err = ZIP_ERRNO;
1518
- zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
1519
- zi->ci.stream.next_out = zi->ci.buffered_data;
1520
- }
1521
- total_out_before = zi->ci.stream.total_out;
1522
- err = deflate(&zi->ci.stream, Z_FINISH);
1523
- zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - total_out_before);
1524
- }
1525
- } else if (zi->ci.compression_method == Z_BZIP2ED) {
1526
- #ifdef HAVE_BZIP2
1527
- err = BZ_FINISH_OK;
1528
- while (err == BZ_FINISH_OK) {
1529
- uLong total_out_before;
1530
- if (zi->ci.bstream.avail_out == 0) {
1531
- if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
1532
- err = ZIP_ERRNO;
1533
- zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
1534
- zi->ci.bstream.next_out = (char *)zi->ci.buffered_data;
1535
- }
1536
- total_out_before = zi->ci.bstream.total_out_lo32;
1537
- err = BZ2_bzCompress(&zi->ci.bstream, BZ_FINISH);
1538
- if (err == BZ_STREAM_END)
1539
- err = Z_STREAM_END;
1540
- zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - total_out_before);
1541
- }
1542
-
1543
- if (err == BZ_FINISH_OK)
1544
- err = ZIP_OK;
1545
- #endif
1546
- }
1547
- }
1548
-
1549
- if (err == Z_STREAM_END)
1550
- err = ZIP_OK; /* this is normal */
1551
-
1552
- if ((zi->ci.pos_in_buffered_data > 0) && (err == ZIP_OK)) {
1553
- if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
1554
- err = ZIP_ERRNO;
1555
- }
1556
-
1557
- #ifdef HAVE_AES
1558
- if (zi->ci.method == AES_METHOD) {
1559
- unsigned char authcode[AES_AUTHCODESIZE];
1560
-
1561
- fcrypt_end(authcode, &zi->ci.aes_ctx);
1562
-
1563
- if (ZWRITE64(zi->z_filefunc, zi->filestream, authcode, AES_AUTHCODESIZE) != AES_AUTHCODESIZE)
1564
- err = ZIP_ERRNO;
1565
- }
1566
- #endif
1567
-
1568
- if (!zi->ci.raw) {
1569
- if (zi->ci.compression_method == Z_DEFLATED) {
1570
- int tmp_err = deflateEnd(&zi->ci.stream);
1571
- if (err == ZIP_OK)
1572
- err = tmp_err;
1573
- zi->ci.stream_initialised = 0;
1574
- }
1575
- #ifdef HAVE_BZIP2
1576
- else if (zi->ci.compression_method == Z_BZIP2ED) {
1577
- int tmperr = BZ2_bzCompressEnd(&zi->ci.bstream);
1578
- if (err == ZIP_OK)
1579
- err = tmperr;
1580
- zi->ci.stream_initialised = 0;
1581
- }
1582
- #endif
1583
-
1584
- crc32 = (uLong)zi->ci.crc32;
1585
- uncompressed_size = zi->ci.total_uncompressed;
1586
- }
1587
-
1588
- compressed_size = zi->ci.total_compressed;
1589
- #ifndef NOCRYPT
1590
- compressed_size += zi->ci.crypt_header_size;
1591
- #endif
1592
-
1593
- /* Update current item crc and sizes */
1594
- if (compressed_size >= 0xffffffff || uncompressed_size >= 0xffffffff || zi->ci.pos_local_header >= 0xffffffff) {
1595
- zip64local_putValue_inmemory(zi->ci.central_header + 4, (uLong)45, 2); /* version made by */
1596
- zip64local_putValue_inmemory(zi->ci.central_header + 6, (uLong)45, 2); /* version needed */
1597
- }
1598
- zip64local_putValue_inmemory(zi->ci.central_header + 16, crc32, 4); /* crc */
1599
- if (compressed_size >= 0xffffffff)
1600
- zip64local_putValue_inmemory(zi->ci.central_header + 20, invalidValue, 4); /* compr size */
1601
- else
1602
- zip64local_putValue_inmemory(zi->ci.central_header + 20, compressed_size, 4); /* compr size */
1603
- if (zi->ci.stream.data_type == Z_ASCII)
1604
- zip64local_putValue_inmemory(zi->ci.central_header + 36, (uLong)Z_ASCII, 2); /* internal file attrib */
1605
- if (uncompressed_size >= 0xffffffff)
1606
- zip64local_putValue_inmemory(zi->ci.central_header + 24, invalidValue, 4); /* uncompr size */
1607
- else
1608
- zip64local_putValue_inmemory(zi->ci.central_header + 24, uncompressed_size, 4); /* uncompr size */
1609
-
1610
- /* Add ZIP64 extra info field for uncompressed size */
1611
- if (uncompressed_size >= 0xffffffff)
1612
- datasize += 8;
1613
- /* Add ZIP64 extra info field for compressed size */
1614
- if (compressed_size >= 0xffffffff)
1615
- datasize += 8;
1616
- /* Add ZIP64 extra info field for relative offset to local file header of current file */
1617
- if (zi->ci.pos_local_header >= 0xffffffff)
1618
- datasize += 8;
1619
-
1620
- /* Add Extra Information Header for 'ZIP64 information' */
1621
- if (datasize > 0) {
1622
- char *p = zi->ci.central_header + zi->ci.size_centralheader;
1623
-
1624
- if ((uLong)(datasize + 4) > zi->ci.size_centralextrafree)
1625
- return ZIP_BADZIPFILE;
1626
-
1627
- zip64local_putValue_inmemory(p, 0x0001, 2);
1628
- p += 2;
1629
- zip64local_putValue_inmemory(p, datasize, 2);
1630
- p += 2;
1631
-
1632
- if (uncompressed_size >= 0xffffffff) {
1633
- zip64local_putValue_inmemory(p, uncompressed_size, 8);
1634
- p += 8;
1635
- }
1636
- if (compressed_size >= 0xffffffff) {
1637
- zip64local_putValue_inmemory(p, compressed_size, 8);
1638
- p += 8;
1639
- }
1640
- if (zi->ci.pos_local_header >= 0xffffffff) {
1641
- zip64local_putValue_inmemory(p, zi->ci.pos_local_header, 8);
1642
- p += 8;
1643
- }
1644
-
1645
- zi->ci.size_centralextrafree -= datasize + 4;
1646
- zi->ci.size_centralheader += datasize + 4;
1647
- zi->ci.size_centralextra += datasize + 4;
1648
-
1649
- zip64local_putValue_inmemory(zi->ci.central_header + 30, (uLong)zi->ci.size_centralextra, 2);
1650
- }
1651
-
1652
- #ifdef HAVE_AES
1653
- /* Write the AES extended info */
1654
- if (zi->ci.method == AES_METHOD) {
1655
- char *p = zi->ci.central_header + zi->ci.size_centralheader;
1656
-
1657
- datasize = 7;
1658
-
1659
- if ((uLong)(datasize + 4) > zi->ci.size_centralextrafree)
1660
- return ZIP_BADZIPFILE;
1661
-
1662
- zip64local_putValue_inmemory(p, 0x9901, 2);
1663
- p += 2;
1664
- zip64local_putValue_inmemory(p, datasize, 2);
1665
- p += 2;
1666
- zip64local_putValue_inmemory(p, AES_VERSION, 2);
1667
- p += 2;
1668
- zip64local_putValue_inmemory(p, 'A', 1);
1669
- p += 1;
1670
- zip64local_putValue_inmemory(p, 'E', 1);
1671
- p += 1;
1672
- zip64local_putValue_inmemory(p, AES_ENCRYPTIONMODE, 1);
1673
- p += 1;
1674
- zip64local_putValue_inmemory(p, zi->ci.compression_method, 2);
1675
- p += 2;
1676
-
1677
- zi->ci.size_centralextrafree -= datasize + 4;
1678
- zi->ci.size_centralheader += datasize + 4;
1679
- zi->ci.size_centralextra += datasize + 4;
1680
-
1681
- zip64local_putValue_inmemory(zi->ci.central_header + 30, (uLong)zi->ci.size_centralextra, 2);
1682
- }
1683
- #endif
1684
- /* Restore comment to correct position */
1685
- for (i = 0; i < zi->ci.size_comment; i++)
1686
- zi->ci.central_header[zi->ci.size_centralheader + i] =
1687
- zi->ci.central_header[zi->ci.size_centralheader + zi->ci.size_centralextrafree + i];
1688
- zi->ci.size_centralheader += zi->ci.size_comment;
1689
-
1690
- if (err == ZIP_OK)
1691
- err = add_data_in_datablock(&zi->central_dir, zi->ci.central_header, (uLong)zi->ci.size_centralheader);
1692
-
1693
- free(zi->ci.central_header);
1694
-
1695
- if (err == ZIP_OK) {
1696
- /* Update the LocalFileHeader with the new values. */
1697
- ZPOS64_T cur_pos_inzip = ZTELL64(zi->z_filefunc, zi->filestream);
1698
- uLong cur_number_disk = zi->number_disk;
1699
-
1700
- /* Local file header is stored on previous disk, switch to make edits */
1701
- if (zi->ci.number_disk != cur_number_disk)
1702
- err = zipGoToSpecificDisk(file, (int)zi->ci.number_disk, 1);
1703
-
1704
- if (ZSEEK64(zi->z_filefunc, zi->filestream, zi->ci.pos_local_header + 14, ZLIB_FILEFUNC_SEEK_SET) != 0)
1705
- err = ZIP_ERRNO;
1706
- if (err == ZIP_OK)
1707
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, crc32, 4); /* crc 32, unknown */
1708
-
1709
- if (uncompressed_size >= 0xffffffff || compressed_size >= 0xffffffff) {
1710
- if (zi->ci.pos_zip64extrainfo > 0) {
1711
- /* Update the size in the ZIP64 extended field. */
1712
- if (ZSEEK64(zi->z_filefunc, zi->filestream, zi->ci.pos_zip64extrainfo + 4, ZLIB_FILEFUNC_SEEK_SET) != 0)
1713
- err = ZIP_ERRNO;
1714
-
1715
- if (err == ZIP_OK) /* compressed size, unknown */
1716
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, uncompressed_size, 8);
1717
- if (err == ZIP_OK) /* uncompressed size, unknown */
1718
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, compressed_size, 8);
1719
- } else
1720
- err = ZIP_BADZIPFILE; /* Caller passed zip64 = 0, so no room for zip64 info -> fatal */
1721
- } else {
1722
- if (err == ZIP_OK) /* compressed size, unknown */
1723
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, compressed_size, 4);
1724
- if (err == ZIP_OK) /* uncompressed size, unknown */
1725
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, uncompressed_size, 4);
1726
- }
1727
-
1728
- /* Now switch back again to the disk we were on before */
1729
- if (zi->ci.number_disk != cur_number_disk)
1730
- err = zipGoToSpecificDisk(file, (int)cur_number_disk, 1);
1731
-
1732
- if (ZSEEK64(zi->z_filefunc, zi->filestream, cur_pos_inzip, ZLIB_FILEFUNC_SEEK_SET) != 0)
1733
- err = ZIP_ERRNO;
1734
- }
1735
-
1736
- zi->number_entry++;
1737
- zi->in_opened_file_inzip = 0;
1738
-
1739
- return err;
1740
- }
1741
-
1742
- extern int ZEXPORT zipCloseFileInZip(zipFile file)
1743
- {
1744
- return zipCloseFileInZipRaw(file, 0, 0);
1745
- }
1746
-
1747
- extern int ZEXPORT zipClose(zipFile file, const char *global_comment)
1748
- {
1749
- zip64_internal *zi;
1750
- int err = 0;
1751
- uLong size_centraldir = 0;
1752
- uInt size_global_comment = 0;
1753
- ZPOS64_T centraldir_pos_inzip;
1754
- ZPOS64_T pos = 0;
1755
- uLong write = 0;
1756
-
1757
- if (file == NULL)
1758
- return ZIP_PARAMERROR;
1759
-
1760
- zi = (zip64_internal *)file;
1761
-
1762
- if (zi->in_opened_file_inzip == 1)
1763
- err = zipCloseFileInZip(file);
1764
-
1765
- #ifndef NO_ADDFILEINEXISTINGZIP
1766
- if (global_comment == NULL)
1767
- global_comment = zi->globalcomment;
1768
- #endif
1769
-
1770
- if (zi->filestream != zi->filestream_with_CD) {
1771
- if (ZCLOSE64(zi->z_filefunc, zi->filestream) != 0)
1772
- if (err == ZIP_OK)
1773
- err = ZIP_ERRNO;
1774
- if (zi->disk_size > 0)
1775
- zi->number_disk_with_CD = zi->number_disk + 1;
1776
- zi->filestream = zi->filestream_with_CD;
1777
- }
1778
-
1779
- centraldir_pos_inzip = ZTELL64(zi->z_filefunc, zi->filestream);
1780
-
1781
- if (err == ZIP_OK) {
1782
- linkedlist_datablock_internal *ldi = zi->central_dir.first_block;
1783
- while (ldi != NULL) {
1784
- if ((err == ZIP_OK) && (ldi->filled_in_this_block > 0)) {
1785
- write = ZWRITE64(zi->z_filefunc, zi->filestream, ldi->data, ldi->filled_in_this_block);
1786
- if (write != ldi->filled_in_this_block)
1787
- err = ZIP_ERRNO;
1788
- }
1789
-
1790
- size_centraldir += ldi->filled_in_this_block;
1791
- ldi = ldi->next_datablock;
1792
- }
1793
- }
1794
-
1795
- free_linkedlist(&(zi->central_dir));
1796
-
1797
- pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
1798
-
1799
- /* Write the ZIP64 central directory header */
1800
- if (pos >= 0xffffffff || zi->number_entry > 0xffff) {
1801
- ZPOS64_T zip64eocd_pos_inzip = ZTELL64(zi->z_filefunc, zi->filestream);
1802
- uLong zip64datasize = 44;
1803
-
1804
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)ZIP64ENDHEADERMAGIC, 4);
1805
-
1806
- /* size of this 'zip64 end of central directory' */
1807
- if (err == ZIP_OK)
1808
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)zip64datasize, 8);
1809
- /* version made by */
1810
- if (err == ZIP_OK)
1811
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)45, 2);
1812
- /* version needed */
1813
- if (err == ZIP_OK)
1814
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)45, 2);
1815
- /* number of this disk */
1816
- if (err == ZIP_OK)
1817
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)zi->number_disk_with_CD, 4);
1818
- /* number of the disk with the start of the central directory */
1819
- if (err == ZIP_OK)
1820
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)zi->number_disk_with_CD, 4);
1821
- /* total number of entries in the central dir on this disk */
1822
- if (err == ZIP_OK)
1823
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8);
1824
- /* total number of entries in the central dir */
1825
- if (err == ZIP_OK)
1826
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8);
1827
- /* size of the central directory */
1828
- if (err == ZIP_OK)
1829
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)size_centraldir, 8);
1830
-
1831
- if (err == ZIP_OK) {
1832
- /* offset of start of central directory with respect to the starting disk number */
1833
- ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
1834
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)pos, 8);
1835
- }
1836
- if (err == ZIP_OK)
1837
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)ZIP64ENDLOCHEADERMAGIC, 4);
1838
-
1839
- /* number of the disk with the start of the central directory */
1840
- if (err == ZIP_OK)
1841
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)zi->number_disk_with_CD, 4);
1842
- /*relative offset to the Zip64EndOfCentralDirectory */
1843
- if (err == ZIP_OK) {
1844
- ZPOS64_T pos = zip64eocd_pos_inzip - zi->add_position_when_writting_offset;
1845
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, pos, 8);
1846
- }
1847
- /* number of the disk with the start of the central directory */
1848
- if (err == ZIP_OK)
1849
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)zi->number_disk_with_CD + 1, 4);
1850
- }
1851
-
1852
- /* Write the central directory header */
1853
-
1854
- /* signature */
1855
- if (err == ZIP_OK)
1856
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)ENDHEADERMAGIC, 4);
1857
- /* number of this disk */
1858
- if (err == ZIP_OK)
1859
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)zi->number_disk_with_CD, 2);
1860
- /* number of the disk with the start of the central directory */
1861
- if (err == ZIP_OK)
1862
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)zi->number_disk_with_CD, 2);
1863
- /* total number of entries in the central dir on this disk */
1864
- if (err == ZIP_OK) {
1865
- if (zi->number_entry >= 0xffff)
1866
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)0xffff, 2); /* use value in ZIP64 record */
1867
- else
1868
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)zi->number_entry, 2);
1869
- }
1870
- /* total number of entries in the central dir */
1871
- if (err == ZIP_OK) {
1872
- if (zi->number_entry >= 0xffff)
1873
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)0xffff, 2); /* use value in ZIP64 record */
1874
- else
1875
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)zi->number_entry, 2);
1876
- }
1877
- /* size of the central directory */
1878
- if (err == ZIP_OK)
1879
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)size_centraldir, 4);
1880
- /* offset of start of central directory with respect to the starting disk number */
1881
- if (err == ZIP_OK) {
1882
- ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
1883
- if (pos >= 0xffffffff)
1884
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)0xffffffff, 4);
1885
- else
1886
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)pos, 4);
1887
- }
1888
-
1889
- /* Write global comment */
1890
-
1891
- if (global_comment != NULL)
1892
- size_global_comment = (uInt)strlen(global_comment);
1893
- if (err == ZIP_OK)
1894
- err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)size_global_comment, 2);
1895
- if (err == ZIP_OK && size_global_comment > 0) {
1896
- if (ZWRITE64(zi->z_filefunc, zi->filestream, global_comment, size_global_comment) != size_global_comment)
1897
- err = ZIP_ERRNO;
1898
- }
1899
-
1900
- if ((ZCLOSE64(zi->z_filefunc, zi->filestream) != 0) && (err == ZIP_OK))
1901
- err = ZIP_ERRNO;
1902
-
1903
- #ifndef NO_ADDFILEINEXISTINGZIP
1904
- TRYFREE(zi->globalcomment);
1905
- #endif
1906
- TRYFREE(zi);
1907
-
1908
- return err;
1909
- }
1910
-