aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--contrib/minizip/skipset.h34
-rw-r--r--contrib/minizip/zip.c1
2 files changed, 19 insertions, 16 deletions
diff --git a/contrib/minizip/skipset.h b/contrib/minizip/skipset.h
index 3878bcfe..34e24438 100644
--- a/contrib/minizip/skipset.h
+++ b/contrib/minizip/skipset.h
@@ -80,17 +80,17 @@ typedef struct {
80} set_rand_t; 80} set_rand_t;
81/* --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
82// advancing 64-bit state. seq is a sequence selection constant. */ 82// advancing 64-bit state. seq is a sequence selection constant. */
83void set_seed(set_rand_t *gen, ui64_t seed, ui64_t seq) { 83static void set_seed(set_rand_t *gen, ui64_t seed, ui64_t seq) {
84 gen->inc = (seq << 1) | 1; 84 gen->inc = (seq << 1) | 1;
85 gen->state = (seed + gen->inc) * 6364136223846793005ULL + gen->inc; 85 gen->state = (seed + gen->inc) * 6364136223846793005ULL + gen->inc;
86} 86}
87/* Start a unique random number sequence using bits from noise sources. */ 87/* Start a unique random number sequence using bits from noise sources. */
88void set_uniq(set_rand_t *gen, const void *ptr) { 88static void set_uniq(set_rand_t *gen, const void *ptr) {
89 set_seed(gen, ((ui64_t)(ptrdiff_t)ptr << 32) ^ 89 set_seed(gen, ((ui64_t)(ptrdiff_t)ptr << 32) ^
90 ((ui64_t)time(NULL) << 12) ^ clock(), 0); 90 ((ui64_t)time(NULL) << 12) ^ clock(), 0);
91} 91}
92/* Return 32 random bits, advancing the state *gen. */ 92/* Return 32 random bits, advancing the state *gen. */
93ui32_t set_rand(set_rand_t *gen) { 93static ui32_t set_rand(set_rand_t *gen) {
94 ui32_t mix; 94 ui32_t mix;
95 int rot; 95 int rot;
96 ui64_t state = gen->state; 96 ui64_t state = gen->state;
@@ -152,7 +152,7 @@ typedef struct set_s {
152# define SET_ALLOC_SIZE(ptr) 0 152# define SET_ALLOC_SIZE(ptr) 0
153# endif 153# endif
154// With tracking. 154// With tracking.
155void *set_alloc(set_t *set, void *ptr, size_t size) { 155static void *set_alloc(set_t *set, void *ptr, size_t size) {
156 size_t had = ptr == NULL ? 0 : SET_ALLOC_SIZE(ptr); 156 size_t had = ptr == NULL ? 0 : SET_ALLOC_SIZE(ptr);
157 void *mem = realloc(ptr, size); 157 void *mem = realloc(ptr, size);
158 if (mem == NULL) 158 if (mem == NULL)
@@ -161,7 +161,7 @@ void *set_alloc(set_t *set, void *ptr, size_t size) {
161 set->memory += SET_ALLOC_SIZE(mem) - had; 161 set->memory += SET_ALLOC_SIZE(mem) - had;
162 return mem; 162 return mem;
163} 163}
164void set_free(set_t *set, void *ptr) { 164static void set_free(set_t *set, void *ptr) {
165 if (ptr != NULL) { 165 if (ptr != NULL) {
166 set->allocs--; 166 set->allocs--;
167 set->memory -= SET_ALLOC_SIZE(ptr); 167 set->memory -= SET_ALLOC_SIZE(ptr);
@@ -170,13 +170,13 @@ void set_free(set_t *set, void *ptr) {
170} 170}
171#else 171#else
172/* Without tracking. */ 172/* Without tracking. */
173void *set_alloc(set_t *set, void *ptr, size_t size) { 173static void *set_alloc(set_t *set, void *ptr, size_t size) {
174 void *mem = realloc(ptr, size); 174 void *mem = realloc(ptr, size);
175 if (mem == NULL) 175 if (mem == NULL)
176 longjmp(set->env, ENOMEM); 176 longjmp(set->env, ENOMEM);
177 return mem; 177 return mem;
178} 178}
179void set_free(set_t *set, void *ptr) { 179static void set_free(set_t *set, void *ptr) {
180 (void)set; 180 (void)set;
181 free(ptr); 181 free(ptr);
182} 182}
@@ -186,7 +186,7 @@ void set_free(set_t *set, void *ptr) {
186// want links. If fill is true, assure that the first want links are filled in, 186// want links. If fill is true, assure that the first want links are filled in,
187// setting them to set->head if not previously filled in. Otherwise it is 187// setting them to set->head if not previously filled in. Otherwise it is
188// assumed that the first want links are about to be filled in. */ 188// assumed that the first want links are about to be filled in. */
189void set_grow(set_t *set, set_node_t *node, int want, int fill) { 189static void set_grow(set_t *set, set_node_t *node, int want, int fill) {
190 int i; 190 int i;
191 if (node->size < want) { 191 if (node->size < want) {
192 int more = node->size ? node->size : 1; 192 int more = node->size ? node->size : 1;
@@ -203,7 +203,7 @@ void set_grow(set_t *set, set_node_t *node, int want, int fill) {
203} 203}
204 204
205/* --private-- Return a new node. key is left uninitialized. */ 205/* --private-- Return a new node. key is left uninitialized. */
206set_node_t *set_node(set_t *set) { 206static set_node_t *set_node(set_t *set) {
207 set_node_t *node = set_alloc(set, NULL, sizeof(set_node_t)); 207 set_node_t *node = set_alloc(set, NULL, sizeof(set_node_t));
208 node->size = 0; 208 node->size = 0;
209 node->fill = 0; 209 node->fill = 0;
@@ -212,7 +212,7 @@ set_node_t *set_node(set_t *set) {
212} 212}
213 213
214/* --private-- Free the list linked from head, along with the keys. */ 214/* --private-- Free the list linked from head, along with the keys. */
215void set_sweep(set_t *set) { 215static void set_sweep(set_t *set) {
216 set_node_t *step = set->head->right[0]; 216 set_node_t *step = set->head->right[0];
217 while (step != set->head) { 217 while (step != set->head) {
218 set_node_t *next = step->right[0]; /* save link to next node */ 218 set_node_t *next = step->right[0]; /* save link to next node */
@@ -229,7 +229,7 @@ void set_sweep(set_t *set) {
229// errno.h.) The set can still be used if this happens, assuming that it didn't 229// errno.h.) The set can still be used if this happens, assuming that it didn't
230// happen during set_start(). Whether set_start() completed or not, set_end() 230// happen during set_start(). Whether set_start() completed or not, set_end()
231// can be used to free the set's memory after a longjmp(). */ 231// can be used to free the set's memory after a longjmp(). */
232void set_start(set_t *set) { 232SKIPSET_EXPORT void set_start(set_t *set) {
233#ifdef SET_TRACK 233#ifdef SET_TRACK
234 set->allocs = 0; 234 set->allocs = 0;
235 set->memory = 0; 235 set->memory = 0;
@@ -246,15 +246,16 @@ void set_start(set_t *set) {
246 246
247/* Return true if *set appears to be in a usable state. If *set has been zeroed 247/* Return true if *set appears to be in a usable state. If *set has been zeroed
248// out, then set_ok(set) will be false and set_end(set) will be safe. */ 248// out, then set_ok(set) will be false and set_end(set) will be safe. */
249int set_ok(set_t *set) { 249SKIPSET_EXPORT int set_ok(set_t *set) {
250 return set->head != NULL && 250 return set->head != NULL &&
251 set->head->right != NULL && 251 set->head->right != NULL &&
252 *(unsigned char *)&set->head->key == 137; 252 *(unsigned char *)&set->head->key == 137;
253} 253}
254 254
255#if 0 /* not used in minizip */
255/* Empty the set. This frees the memory used for the previous set contents. 256/* Empty the set. This frees the memory used for the previous set contents.
256// After set_clear(), *set is ready for use, as if after a set_start(). */ 257// After set_clear(), *set is ready for use, as if after a set_start(). */
257void set_clear(set_t *set) { 258SKIPSET_EXPORT void set_clear(set_t *set) {
258 assert(set_ok(set) && "improper use"); 259 assert(set_ok(set) && "improper use");
259 260
260 /* Free all the keys and their nodes. */ 261 /* Free all the keys and their nodes. */
@@ -267,12 +268,13 @@ void set_clear(set_t *set) {
267 set->path->fill = 0; 268 set->path->fill = 0;
268 set->depth = 0; 269 set->depth = 0;
269} 270}
271#endif
270 272
271/* Done using the set -- free all allocations. The only operation on *set 273/* Done using the set -- free all allocations. The only operation on *set
272// permitted after this is set_start(). Though another set_end() would do no 274// permitted after this is set_start(). Though another set_end() would do no
273// harm. This can be done at any time after a set_start(), or after a longjmp() 275// harm. This can be done at any time after a set_start(), or after a longjmp()
274// on any allocation failure, including during a set_start(). */ 276// on any allocation failure, including during a set_start(). */
275void set_end(set_t *set) { 277SKIPSET_EXPORT void set_end(set_t *set) {
276 if (set->head != NULL) { 278 if (set->head != NULL) {
277 /* Empty the set and free the head node. */ 279 /* Empty the set and free the head node. */
278 if (set->head->right != NULL) { 280 if (set->head->right != NULL) {
@@ -299,7 +301,7 @@ void set_end(set_t *set) {
299 301
300/* Look for key. Return 1 if found or 0 if not. This also puts the path to get 302/* Look for key. Return 1 if found or 0 if not. This also puts the path to get
301// there in set->path, for use by set_insert(). */ 303// there in set->path, for use by set_insert(). */
302int set_found(set_t *set, set_key_t key) { 304SKIPSET_EXPORT int set_found(set_t *set, set_key_t key) {
303 set_node_t *head, *here; 305 set_node_t *head, *here;
304 int i; 306 int i;
305 assert(set_ok(set) && "improper use"); 307 assert(set_ok(set) && "improper use");
@@ -322,7 +324,7 @@ int set_found(set_t *set, set_key_t key) {
322} 324}
323 325
324/* Insert the key key. Return 0 on success, or 1 if key is already in the set. */ 326/* Insert the key key. Return 0 on success, or 1 if key is already in the set. */
325int set_insert(set_t *set, set_key_t key) { 327SKIPSET_EXPORT int set_insert(set_t *set, set_key_t key) {
326 int level = 0; 328 int level = 0;
327 int bit; 329 int bit;
328 int i; 330 int i;
diff --git a/contrib/minizip/zip.c b/contrib/minizip/zip.c
index 136c0486..03424ab0 100644
--- a/contrib/minizip/zip.c
+++ b/contrib/minizip/zip.c
@@ -129,6 +129,7 @@ typedef struct linkedlist_data_s
129 129
130/* zipAlreadyThere() set functions for a set of zero-terminated strings, and 130/* zipAlreadyThere() set functions for a set of zero-terminated strings, and
131// a block_t type for reading the central directory datablocks. */ 131// a block_t type for reading the central directory datablocks. */
132#define SKIPSET_EXPORT static
132typedef char *set_key_t; 133typedef char *set_key_t;
133#define set_cmp(a, b) strcmp(a, b) 134#define set_cmp(a, b) strcmp(a, b)
134#define set_drop(s, k) set_free(s, k) 135#define set_drop(s, k) set_free(s, k)