diff options
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/minizip/ints.h | 57 | ||||
-rw-r--r-- | contrib/minizip/ioapi.h | 31 | ||||
-rw-r--r-- | contrib/minizip/minizip.c | 3 | ||||
-rw-r--r-- | contrib/minizip/skipset.h | 33 | ||||
-rw-r--r-- | contrib/minizip/zip.c | 17 |
5 files changed, 90 insertions, 51 deletions
diff --git a/contrib/minizip/ints.h b/contrib/minizip/ints.h new file mode 100644 index 0000000..4c84375 --- /dev/null +++ b/contrib/minizip/ints.h | |||
@@ -0,0 +1,57 @@ | |||
1 | /* ints.h -- create integer types for 8, 16, 32, and 64 bits | ||
2 | * Copyright (C) 2024 Mark Adler | ||
3 | * For conditions of distribution and use, see the copyright notice in zlib.h | ||
4 | * | ||
5 | * There exist compilers with limits.h, but not stdint.h or inttypes.h. | ||
6 | */ | ||
7 | |||
8 | #ifndef INTS_H | ||
9 | #define INTS_H | ||
10 | #include <limits.h> | ||
11 | #if defined(UCHAR_MAX) && UCHAR_MAX == 0xff | ||
12 | typedef signed char i8_t; | ||
13 | typedef unsigned char ui8_t; | ||
14 | #else | ||
15 | # error "no 8-bit integer" | ||
16 | #endif | ||
17 | #if defined(USHRT_MAX) && USHRT_MAX == 0xffff | ||
18 | typedef short i16_t; | ||
19 | typedef unsigned short ui16_t; | ||
20 | #elif defined(UINT_MAX) && UINT_MAX == 0xffff | ||
21 | typedef int i16_t; | ||
22 | typedef unsigned ui16_t; | ||
23 | #else | ||
24 | # error "no 16-bit integer" | ||
25 | #endif | ||
26 | #if defined(UINT_MAX) && UINT_MAX == 0xffffffff | ||
27 | typedef int i32_t; | ||
28 | typedef unsigned ui32_t; | ||
29 | # define PI32 "d" | ||
30 | # define PUI32 "u" | ||
31 | #elif defined(ULONG_MAX) && ULONG_MAX == 0xffffffff | ||
32 | typedef long i32_t; | ||
33 | typedef unsigned long ui32_t; | ||
34 | # define PI32 "ld" | ||
35 | # define PUI32 "lu" | ||
36 | #else | ||
37 | # error "no 32-bit integer" | ||
38 | #endif | ||
39 | #if defined(ULONG_MAX) && ULONG_MAX == 0xffffffffffffffff | ||
40 | typedef long i64_t; | ||
41 | typedef unsigned long ui64_t; | ||
42 | # define PI64 "ld" | ||
43 | # define PUI64 "lu" | ||
44 | #elif defined(ULLONG_MAX) && ULLONG_MAX == 0xffffffffffffffff | ||
45 | typedef long long i64_t; | ||
46 | typedef unsigned long long ui64_t; | ||
47 | # define PI64 "lld" | ||
48 | # define PUI64 "llu" | ||
49 | #elif defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 0xffffffffffffffff | ||
50 | typedef long long i64_t; | ||
51 | typedef unsigned long long ui64_t; | ||
52 | # define PI64 "lld" | ||
53 | # define PUI64 "llu" | ||
54 | #else | ||
55 | # error "no 64-bit integer" | ||
56 | #endif | ||
57 | #endif | ||
diff --git a/contrib/minizip/ioapi.h b/contrib/minizip/ioapi.h index a2d2e6e..da1b72f 100644 --- a/contrib/minizip/ioapi.h +++ b/contrib/minizip/ioapi.h | |||
@@ -67,39 +67,12 @@ | |||
67 | #endif | 67 | #endif |
68 | #endif | 68 | #endif |
69 | 69 | ||
70 | /* | ||
71 | #ifndef ZPOS64_T | ||
72 | #ifdef _WIN32 | ||
73 | #define ZPOS64_T fpos_t | ||
74 | #else | ||
75 | #include <stdint.h> | ||
76 | #define ZPOS64_T uint64_t | ||
77 | #endif | ||
78 | #endif | ||
79 | */ | ||
80 | |||
81 | #ifdef HAVE_MINIZIP64_CONF_H | 70 | #ifdef HAVE_MINIZIP64_CONF_H |
82 | #include "mz64conf.h" | 71 | #include "mz64conf.h" |
83 | #endif | 72 | #endif |
84 | 73 | ||
85 | /* a type chosen by DEFINE */ | 74 | #include "ints.h" |
86 | #ifdef HAVE_64BIT_INT_CUSTOM | 75 | typedef ui64_t ZPOS64_T; |
87 | typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T; | ||
88 | #else | ||
89 | #ifdef HAS_STDINT_H | ||
90 | #include "stdint.h" | ||
91 | typedef uint64_t ZPOS64_T; | ||
92 | #else | ||
93 | |||
94 | |||
95 | |||
96 | #if defined(_MSC_VER) || defined(__BORLANDC__) | ||
97 | typedef unsigned __int64 ZPOS64_T; | ||
98 | #else | ||
99 | typedef unsigned long long int ZPOS64_T; | ||
100 | #endif | ||
101 | #endif | ||
102 | #endif | ||
103 | 76 | ||
104 | /* Maximum unsigned 32-bit value used as placeholder for zip64 */ | 77 | /* Maximum unsigned 32-bit value used as placeholder for zip64 */ |
105 | #ifndef MAXU32 | 78 | #ifndef MAXU32 |
diff --git a/contrib/minizip/minizip.c b/contrib/minizip/minizip.c index 66e88d0..a44e36a 100644 --- a/contrib/minizip/minizip.c +++ b/contrib/minizip/minizip.c | |||
@@ -62,6 +62,7 @@ | |||
62 | #endif | 62 | #endif |
63 | 63 | ||
64 | #include "zip.h" | 64 | #include "zip.h" |
65 | #include "ints.h" | ||
65 | 66 | ||
66 | #ifdef _WIN32 | 67 | #ifdef _WIN32 |
67 | #define USEWIN32IOAPI | 68 | #define USEWIN32IOAPI |
@@ -226,7 +227,7 @@ static int isLargeFile(const char* filename) { | |||
226 | FSEEKO_FUNC(pFile, 0, SEEK_END); | 227 | FSEEKO_FUNC(pFile, 0, SEEK_END); |
227 | pos = (ZPOS64_T)FTELLO_FUNC(pFile); | 228 | pos = (ZPOS64_T)FTELLO_FUNC(pFile); |
228 | 229 | ||
229 | printf("File : %s is %llu bytes\n", filename, pos); | 230 | printf("File : %s is %"PUI64" bytes\n", filename, pos); |
230 | 231 | ||
231 | if(pos >= 0xffffffff) | 232 | if(pos >= 0xffffffff) |
232 | largeFile = 1; | 233 | largeFile = 1; |
diff --git a/contrib/minizip/skipset.h b/contrib/minizip/skipset.h index 381aa13..5e648b9 100644 --- a/contrib/minizip/skipset.h +++ b/contrib/minizip/skipset.h | |||
@@ -56,11 +56,12 @@ | |||
56 | #define SKIPSET_H | 56 | #define SKIPSET_H |
57 | 57 | ||
58 | #include <stdlib.h> // realloc(), free(), NULL, size_t | 58 | #include <stdlib.h> // realloc(), free(), NULL, size_t |
59 | #include <stddef.h> // ptrdiff_t | ||
59 | #include <setjmp.h> // jmp_buf, longjmp() | 60 | #include <setjmp.h> // jmp_buf, longjmp() |
60 | #include <errno.h> // ENOMEM | 61 | #include <errno.h> // ENOMEM |
61 | #include <stdint.h> // int16_t, uint32_t, uint64_t | ||
62 | #include <time.h> // time(), clock() | 62 | #include <time.h> // time(), clock() |
63 | #include <assert.h> // assert.h | 63 | #include <assert.h> // assert.h |
64 | #include "ints.h" // i16_t, ui32_t, ui64_t | ||
64 | 65 | ||
65 | // Structures and functions below noted as "--private--" should not be used by | 66 | // Structures and functions below noted as "--private--" should not be used by |
66 | // the application. set_t is partially private and partially public -- see the | 67 | // the application. set_t is partially private and partially public -- see the |
@@ -74,20 +75,20 @@ | |||
74 | // Licensed under Apache License 2.0 (NO WARRANTY, etc. see website) | 75 | // Licensed under Apache License 2.0 (NO WARRANTY, etc. see website) |
75 | // --private-- Random number generator state. | 76 | // --private-- Random number generator state. |
76 | typedef struct { | 77 | typedef struct { |
77 | uint64_t state; // 64-bit generator state | 78 | ui64_t state; // 64-bit generator state |
78 | uint64_t inc; // 63-bit sequence id | 79 | ui64_t inc; // 63-bit sequence id |
79 | } set_rand_t; | 80 | } set_rand_t; |
80 | // --private-- Initialize the state *gen using seed and seq. seed seeds the | 81 | // --private-- Initialize the state *gen using seed and seq. seed seeds the |
81 | // advancing 64-bit state. seq is a sequence selection constant. | 82 | // advancing 64-bit state. seq is a sequence selection constant. |
82 | void set_seed(set_rand_t *gen, uint64_t seed, uint64_t seq) { | 83 | void set_seed(set_rand_t *gen, ui64_t seed, ui64_t seq) { |
83 | gen->inc = (seq << 1) | 1; | 84 | gen->inc = (seq << 1) | 1; |
84 | gen->state = (seed + gen->inc) * 6364136223846793005ULL + gen->inc; | 85 | gen->state = (seed + gen->inc) * 6364136223846793005ULL + gen->inc; |
85 | } | 86 | } |
86 | // Return 32 random bits, advancing the state *gen. | 87 | // Return 32 random bits, advancing the state *gen. |
87 | uint32_t set_rand(set_rand_t *gen) { | 88 | ui32_t set_rand(set_rand_t *gen) { |
88 | uint64_t state = gen->state; | 89 | ui64_t state = gen->state; |
89 | gen->state = state * 6364136223846793005ULL + gen->inc; | 90 | gen->state = state * 6364136223846793005ULL + gen->inc; |
90 | uint32_t mix = (uint32_t)(((state >> 18) ^ state) >> 27); | 91 | ui32_t mix = (ui32_t)(((state >> 18) ^ state) >> 27); |
91 | int rot = state >> 59; | 92 | int rot = state >> 59; |
92 | return (mix >> rot) | (mix << ((-rot) & 31)); | 93 | return (mix >> rot) | (mix << ((-rot) & 31)); |
93 | } | 94 | } |
@@ -97,8 +98,8 @@ uint32_t set_rand(set_rand_t *gen) { | |||
97 | typedef struct set_node_s set_node_t; | 98 | typedef struct set_node_s set_node_t; |
98 | struct set_node_s { | 99 | struct set_node_s { |
99 | set_key_t key; // the key (not used for head or path) | 100 | set_key_t key; // the key (not used for head or path) |
100 | int16_t size; // number of allocated pointers in right[] | 101 | i16_t size; // number of allocated pointers in right[] |
101 | int16_t fill; // number of pointers in right[] filled in | 102 | i16_t fill; // number of pointers in right[] filled in |
102 | set_node_t **right; // pointer for each level, each to the right | 103 | set_node_t **right; // pointer for each level, each to the right |
103 | }; | 104 | }; |
104 | 105 | ||
@@ -108,8 +109,8 @@ typedef struct set_s { | |||
108 | set_node_t *head; // skiplist head -- no key, just links | 109 | set_node_t *head; // skiplist head -- no key, just links |
109 | set_node_t *path; // right[] is path to key from set_found() | 110 | set_node_t *path; // right[] is path to key from set_found() |
110 | set_node_t *node; // node under construction, in case of longjmp() | 111 | set_node_t *node; // node under construction, in case of longjmp() |
111 | int16_t depth; // maximum depth of the skiplist | 112 | i16_t depth; // maximum depth of the skiplist |
112 | uint64_t ran; // a precious trove of random bits | 113 | ui64_t ran; // a precious trove of random bits |
113 | set_rand_t gen; // random number generator state | 114 | set_rand_t gen; // random number generator state |
114 | jmp_buf env; // setjmp() environment for allocation errors | 115 | jmp_buf env; // setjmp() environment for allocation errors |
115 | #ifdef SET_TRACK | 116 | #ifdef SET_TRACK |
@@ -184,13 +185,13 @@ void set_grow(set_t *set, set_node_t *node, int want, int fill) { | |||
184 | while (more < want) | 185 | while (more < want) |
185 | more <<= 1; | 186 | more <<= 1; |
186 | node->right = set_alloc(set, node->right, more * sizeof(set_node_t *)); | 187 | node->right = set_alloc(set, node->right, more * sizeof(set_node_t *)); |
187 | node->size = (int16_t)more; | 188 | node->size = (i16_t)more; |
188 | } | 189 | } |
189 | int i; | 190 | int i; |
190 | if (fill) | 191 | if (fill) |
191 | for (i = node->fill; i < want; i++) | 192 | for (i = node->fill; i < want; i++) |
192 | node->right[i] = set->head; | 193 | node->right[i] = set->head; |
193 | node->fill = (int16_t)want; | 194 | node->fill = (i16_t)want; |
194 | } | 195 | } |
195 | 196 | ||
196 | // --private-- Return a new node. key is left uninitialized. | 197 | // --private-- Return a new node. key is left uninitialized. |
@@ -231,8 +232,8 @@ void set_start(set_t *set) { | |||
231 | set_grow(set, set->head, 1, 1); // one link back to head for an empty set | 232 | set_grow(set, set->head, 1, 1); // one link back to head for an empty set |
232 | *(unsigned char *)&set->head->key = 137; // set id | 233 | *(unsigned char *)&set->head->key = 137; // set id |
233 | set->depth = 0; | 234 | set->depth = 0; |
234 | set_seed(&set->gen, ((uint64_t)(uintptr_t)set << 32) ^ | 235 | set_seed(&set->gen, ((ui64_t)(ptrdiff_t)set << 32) ^ |
235 | ((uint64_t)time(NULL) << 12) ^ clock(), 0); | 236 | ((ui64_t)time(NULL) << 12) ^ clock(), 0); |
236 | set->ran = 1; | 237 | set->ran = 1; |
237 | } | 238 | } |
238 | 239 | ||
@@ -337,7 +338,7 @@ int set_insert(set_t *set, set_key_t key) { | |||
337 | // The maximum depth is now deeper. Update the structures. | 338 | // The maximum depth is now deeper. Update the structures. |
338 | set_grow(set, set->path, level + 1, 1); | 339 | set_grow(set, set->path, level + 1, 1); |
339 | set_grow(set, set->head, level + 1, 1); | 340 | set_grow(set, set->head, level + 1, 1); |
340 | set->depth = (int16_t)level; | 341 | set->depth = (i16_t)level; |
341 | } | 342 | } |
342 | 343 | ||
343 | // Make a new node for the provided key, and insert it in the lists up to | 344 | // Make a new node for the provided key, and insert it in the lists up to |
diff --git a/contrib/minizip/zip.c b/contrib/minizip/zip.c index cbb2508..93d2612 100644 --- a/contrib/minizip/zip.c +++ b/contrib/minizip/zip.c | |||
@@ -25,8 +25,10 @@ | |||
25 | #include <stdio.h> | 25 | #include <stdio.h> |
26 | #include <stdlib.h> | 26 | #include <stdlib.h> |
27 | #include <string.h> | 27 | #include <string.h> |
28 | #include <stdint.h> | ||
29 | #include <time.h> | 28 | #include <time.h> |
29 | #ifndef ZLIB_CONST | ||
30 | # define ZLIB_CONST | ||
31 | #endif | ||
30 | #include "zlib.h" | 32 | #include "zlib.h" |
31 | #include "zip.h" | 33 | #include "zip.h" |
32 | 34 | ||
@@ -125,9 +127,9 @@ typedef struct linkedlist_data_s | |||
125 | 127 | ||
126 | // zipAlreadyThere() set functions for a set of zero-terminated strings, and | 128 | // zipAlreadyThere() set functions for a set of zero-terminated strings, and |
127 | // a block_t type for reading the central directory datablocks. | 129 | // a block_t type for reading the central directory datablocks. |
128 | typedef char const *set_key_t; | 130 | typedef char *set_key_t; |
129 | #define set_cmp(a, b) strcmp(a, b) | 131 | #define set_cmp(a, b) strcmp(a, b) |
130 | #define set_drop(s, k) set_free(s, (void *)(intptr_t)(k)) | 132 | #define set_drop(s, k) set_free(s, k) |
131 | #include "skipset.h" | 133 | #include "skipset.h" |
132 | typedef struct { | 134 | typedef struct { |
133 | unsigned char *next; // next byte in datablock data | 135 | unsigned char *next; // next byte in datablock data |
@@ -496,7 +498,12 @@ extern int ZEXPORT zipAlreadyThere(zipFile file, char const *name) { | |||
496 | } | 498 | } |
497 | 499 | ||
498 | // Return true if name is in the central directory. | 500 | // Return true if name is in the central directory. |
499 | return set_found(&zip->set, name); | 501 | size_t len = strlen(name); |
502 | char *copy = set_alloc(&zip->set, NULL, len + 1); | ||
503 | strcpy(copy, name); | ||
504 | int found = set_found(&zip->set, copy); | ||
505 | set_free(&zip->set, copy); | ||
506 | return found; | ||
500 | } | 507 | } |
501 | 508 | ||
502 | 509 | ||
@@ -1646,7 +1653,7 @@ extern int ZEXPORT zipWriteInFileInZip(zipFile file, const void* buf, unsigned i | |||
1646 | else | 1653 | else |
1647 | #endif | 1654 | #endif |
1648 | { | 1655 | { |
1649 | zi->ci.stream.next_in = (Bytef*)(uintptr_t)buf; | 1656 | zi->ci.stream.next_in = buf; |
1650 | zi->ci.stream.avail_in = len; | 1657 | zi->ci.stream.avail_in = len; |
1651 | 1658 | ||
1652 | while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0)) | 1659 | while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0)) |