zipruby 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of zipruby might be problematic. Click here for more details.
- data/README.txt +131 -0
- data/ext/extconf.rb +1 -1
- data/ext/libzip.mswin32.patch +113 -0
- data/ext/libzip.vcproj +308 -0
- data/ext/libzip.vcproj.IBM-94B792EFFD1.sugawara.user +37 -0
- data/ext/mkstemp.c +143 -0
- data/ext/zip.h +211 -0
- data/ext/zip_add.c +52 -0
- data/ext/zip_add_dir.c +83 -0
- data/ext/zip_close.c +566 -0
- data/ext/zip_delete.c +61 -0
- data/ext/zip_dirent.c +531 -0
- data/ext/zip_entry_free.c +55 -0
- data/ext/zip_entry_new.c +81 -0
- data/ext/zip_err_str.c +72 -0
- data/ext/zip_error.c +104 -0
- data/ext/zip_error_clear.c +47 -0
- data/ext/zip_error_get.c +47 -0
- data/ext/zip_error_get_sys_type.c +50 -0
- data/ext/zip_error_strerror.c +93 -0
- data/ext/zip_error_to_str.c +77 -0
- data/ext/zip_fclose.c +74 -0
- data/ext/zip_file_error_clear.c +47 -0
- data/ext/zip_file_error_get.c +47 -0
- data/ext/zip_file_get_offset.c +77 -0
- data/ext/zip_file_strerror.c +47 -0
- data/ext/zip_fopen.c +52 -0
- data/ext/zip_fopen_index.c +219 -0
- data/ext/zip_fread.c +125 -0
- data/ext/zip_free.c +83 -0
- data/ext/zip_get_archive_comment.c +63 -0
- data/ext/zip_get_file_comment.c +61 -0
- data/ext/zip_get_name.c +74 -0
- data/ext/zip_get_num_files.c +50 -0
- data/ext/zip_memdup.c +58 -0
- data/ext/zip_name_locate.c +95 -0
- data/ext/zip_new.c +71 -0
- data/ext/zip_open.c +520 -0
- data/ext/zip_rename.c +52 -0
- data/ext/zip_replace.c +81 -0
- data/ext/zip_set_archive_comment.c +68 -0
- data/ext/zip_set_file_comment.c +69 -0
- data/ext/zip_set_name.c +77 -0
- data/ext/zip_source_buffer.c +160 -0
- data/ext/zip_source_file.c +71 -0
- data/ext/zip_source_filep.c +176 -0
- data/ext/zip_source_free.c +54 -0
- data/ext/zip_source_function.c +62 -0
- data/ext/zip_source_zip.c +189 -0
- data/ext/zip_stat.c +52 -0
- data/ext/zip_stat_index.c +93 -0
- data/ext/zip_stat_init.c +53 -0
- data/ext/zip_strerror.c +47 -0
- data/ext/zip_unchange.c +84 -0
- data/ext/zip_unchange_all.c +56 -0
- data/ext/zip_unchange_archive.c +52 -0
- data/ext/zip_unchange_data.c +53 -0
- data/ext/zipint.h +240 -0
- data/ext/zipruby.h +1 -1
- metadata +63 -5
data/ext/zip_dirent.c
ADDED
@@ -0,0 +1,531 @@
|
|
1
|
+
/*
|
2
|
+
$NiH: zip_dirent.c,v 1.10 2007/03/03 13:48:08 wiz Exp $
|
3
|
+
|
4
|
+
zip_dirent.c -- read directory entry (local or central), clean dirent
|
5
|
+
Copyright (C) 1999, 2003, 2004, 2005 Dieter Baron and Thomas Klausner
|
6
|
+
|
7
|
+
This file is part of libzip, a library to manipulate ZIP archives.
|
8
|
+
The authors can be contacted at <nih@giga.or.at>
|
9
|
+
|
10
|
+
Redistribution and use in source and binary forms, with or without
|
11
|
+
modification, are permitted provided that the following conditions
|
12
|
+
are met:
|
13
|
+
1. Redistributions of source code must retain the above copyright
|
14
|
+
notice, this list of conditions and the following disclaimer.
|
15
|
+
2. Redistributions in binary form must reproduce the above copyright
|
16
|
+
notice, this list of conditions and the following disclaimer in
|
17
|
+
the documentation and/or other materials provided with the
|
18
|
+
distribution.
|
19
|
+
3. The names of the authors may not be used to endorse or promote
|
20
|
+
products derived from this software without specific prior
|
21
|
+
written permission.
|
22
|
+
|
23
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
|
24
|
+
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
25
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
26
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
27
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
28
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
29
|
+
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
30
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
31
|
+
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
32
|
+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
33
|
+
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
*/
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
#include <stdio.h>
|
39
|
+
#include <stdlib.h>
|
40
|
+
#include <string.h>
|
41
|
+
#include <errno.h>
|
42
|
+
#include <sys/types.h>
|
43
|
+
#include <sys/stat.h>
|
44
|
+
|
45
|
+
#include "zip.h"
|
46
|
+
#include "zipint.h"
|
47
|
+
|
48
|
+
static time_t _zip_d2u_time(int, int);
|
49
|
+
static char *_zip_readfpstr(FILE *, unsigned int, int, struct zip_error *);
|
50
|
+
static char *_zip_readstr(unsigned char **, int, int, struct zip_error *);
|
51
|
+
static void _zip_u2d_time(time_t, unsigned short *, unsigned short *);
|
52
|
+
static void _zip_write2(unsigned short, FILE *);
|
53
|
+
static void _zip_write4(unsigned int, FILE *);
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
void
|
58
|
+
_zip_cdir_free(struct zip_cdir *cd)
|
59
|
+
{
|
60
|
+
int i;
|
61
|
+
|
62
|
+
if (!cd)
|
63
|
+
return;
|
64
|
+
|
65
|
+
for (i=0; i<cd->nentry; i++)
|
66
|
+
_zip_dirent_finalize(cd->entry+i);
|
67
|
+
free(cd->comment);
|
68
|
+
free(cd->entry);
|
69
|
+
free(cd);
|
70
|
+
}
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
struct zip_cdir *
|
75
|
+
_zip_cdir_new(int nentry, struct zip_error *error)
|
76
|
+
{
|
77
|
+
struct zip_cdir *cd;
|
78
|
+
|
79
|
+
if ((cd=(struct zip_cdir *)malloc(sizeof(*cd))) == NULL) {
|
80
|
+
_zip_error_set(error, ZIP_ER_MEMORY, 0);
|
81
|
+
return NULL;
|
82
|
+
}
|
83
|
+
|
84
|
+
if ((cd->entry=(struct zip_dirent *)malloc(sizeof(*(cd->entry))*nentry))
|
85
|
+
== NULL) {
|
86
|
+
_zip_error_set(error, ZIP_ER_MEMORY, 0);
|
87
|
+
free(cd);
|
88
|
+
return NULL;
|
89
|
+
}
|
90
|
+
|
91
|
+
/* entries must be initialized by caller */
|
92
|
+
|
93
|
+
cd->nentry = nentry;
|
94
|
+
cd->size = cd->offset = 0;
|
95
|
+
cd->comment = NULL;
|
96
|
+
cd->comment_len = 0;
|
97
|
+
|
98
|
+
return cd;
|
99
|
+
}
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
int
|
104
|
+
_zip_cdir_write(struct zip_cdir *cd, FILE *fp, struct zip_error *error)
|
105
|
+
{
|
106
|
+
int i;
|
107
|
+
|
108
|
+
cd->offset = ftello(fp);
|
109
|
+
|
110
|
+
for (i=0; i<cd->nentry; i++) {
|
111
|
+
if (_zip_dirent_write(cd->entry+i, fp, 0, error) != 0)
|
112
|
+
return -1;
|
113
|
+
}
|
114
|
+
|
115
|
+
cd->size = ftello(fp) - cd->offset;
|
116
|
+
|
117
|
+
/* clearerr(fp); */
|
118
|
+
fwrite(EOCD_MAGIC, 1, 4, fp);
|
119
|
+
_zip_write4(0, fp);
|
120
|
+
_zip_write2((unsigned short)cd->nentry, fp);
|
121
|
+
_zip_write2((unsigned short)cd->nentry, fp);
|
122
|
+
_zip_write4(cd->size, fp);
|
123
|
+
_zip_write4(cd->offset, fp);
|
124
|
+
_zip_write2(cd->comment_len, fp);
|
125
|
+
fwrite(cd->comment, 1, cd->comment_len, fp);
|
126
|
+
|
127
|
+
if (ferror(fp)) {
|
128
|
+
_zip_error_set(error, ZIP_ER_WRITE, errno);
|
129
|
+
return -1;
|
130
|
+
}
|
131
|
+
|
132
|
+
return 0;
|
133
|
+
}
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
void
|
138
|
+
_zip_dirent_finalize(struct zip_dirent *zde)
|
139
|
+
{
|
140
|
+
free(zde->filename);
|
141
|
+
zde->filename = NULL;
|
142
|
+
free(zde->extrafield);
|
143
|
+
zde->extrafield = NULL;
|
144
|
+
free(zde->comment);
|
145
|
+
zde->comment = NULL;
|
146
|
+
}
|
147
|
+
|
148
|
+
|
149
|
+
|
150
|
+
void
|
151
|
+
_zip_dirent_init(struct zip_dirent *de)
|
152
|
+
{
|
153
|
+
de->version_madeby = 0;
|
154
|
+
de->version_needed = 20; /* 2.0 */
|
155
|
+
de->bitflags = 0;
|
156
|
+
de->comp_method = 0;
|
157
|
+
de->last_mod = 0;
|
158
|
+
de->crc = 0;
|
159
|
+
de->comp_size = 0;
|
160
|
+
de->uncomp_size = 0;
|
161
|
+
de->filename = NULL;
|
162
|
+
de->filename_len = 0;
|
163
|
+
de->extrafield = NULL;
|
164
|
+
de->extrafield_len = 0;
|
165
|
+
de->comment = NULL;
|
166
|
+
de->comment_len = 0;
|
167
|
+
de->disk_number = 0;
|
168
|
+
de->int_attrib = 0;
|
169
|
+
de->ext_attrib = 0;
|
170
|
+
de->offset = 0;
|
171
|
+
}
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
/* _zip_dirent_read(zde, fp, bufp, left, localp, error):
|
176
|
+
Fills the zip directory entry zde.
|
177
|
+
|
178
|
+
If bufp is non-NULL, data is taken from there and bufp is advanced
|
179
|
+
by the amount of data used; no more than left bytes are used.
|
180
|
+
Otherwise data is read from fp as needed.
|
181
|
+
|
182
|
+
If localp != 0, it reads a local header instead of a central
|
183
|
+
directory entry.
|
184
|
+
|
185
|
+
Returns 0 if successful. On error, error is filled in and -1 is
|
186
|
+
returned.
|
187
|
+
*/
|
188
|
+
|
189
|
+
int
|
190
|
+
_zip_dirent_read(struct zip_dirent *zde, FILE *fp,
|
191
|
+
unsigned char **bufp, unsigned int left, int localp,
|
192
|
+
struct zip_error *error)
|
193
|
+
{
|
194
|
+
unsigned char buf[CDENTRYSIZE];
|
195
|
+
unsigned char *cur;
|
196
|
+
unsigned short dostime, dosdate;
|
197
|
+
unsigned int size;
|
198
|
+
|
199
|
+
if (localp)
|
200
|
+
size = LENTRYSIZE;
|
201
|
+
else
|
202
|
+
size = CDENTRYSIZE;
|
203
|
+
|
204
|
+
if (bufp) {
|
205
|
+
/* use data from buffer */
|
206
|
+
cur = *bufp;
|
207
|
+
if (left < size) {
|
208
|
+
_zip_error_set(error, ZIP_ER_NOZIP, 0);
|
209
|
+
return -1;
|
210
|
+
}
|
211
|
+
}
|
212
|
+
else {
|
213
|
+
/* read entry from disk */
|
214
|
+
if ((fread(buf, 1, size, fp)<size)) {
|
215
|
+
_zip_error_set(error, ZIP_ER_READ, errno);
|
216
|
+
return -1;
|
217
|
+
}
|
218
|
+
left = size;
|
219
|
+
cur = buf;
|
220
|
+
}
|
221
|
+
|
222
|
+
if (memcmp(cur, (localp ? LOCAL_MAGIC : CENTRAL_MAGIC), 4) != 0) {
|
223
|
+
_zip_error_set(error, ZIP_ER_NOZIP, 0);
|
224
|
+
return -1;
|
225
|
+
}
|
226
|
+
cur += 4;
|
227
|
+
|
228
|
+
|
229
|
+
/* convert buffercontents to zip_dirent */
|
230
|
+
|
231
|
+
if (!localp)
|
232
|
+
zde->version_madeby = _zip_read2(&cur);
|
233
|
+
else
|
234
|
+
zde->version_madeby = 0;
|
235
|
+
zde->version_needed = _zip_read2(&cur);
|
236
|
+
zde->bitflags = _zip_read2(&cur);
|
237
|
+
zde->comp_method = _zip_read2(&cur);
|
238
|
+
|
239
|
+
/* convert to time_t */
|
240
|
+
dostime = _zip_read2(&cur);
|
241
|
+
dosdate = _zip_read2(&cur);
|
242
|
+
zde->last_mod = _zip_d2u_time(dostime, dosdate);
|
243
|
+
|
244
|
+
zde->crc = _zip_read4(&cur);
|
245
|
+
zde->comp_size = _zip_read4(&cur);
|
246
|
+
zde->uncomp_size = _zip_read4(&cur);
|
247
|
+
|
248
|
+
zde->filename_len = _zip_read2(&cur);
|
249
|
+
zde->extrafield_len = _zip_read2(&cur);
|
250
|
+
|
251
|
+
if (localp) {
|
252
|
+
zde->comment_len = 0;
|
253
|
+
zde->disk_number = 0;
|
254
|
+
zde->int_attrib = 0;
|
255
|
+
zde->ext_attrib = 0;
|
256
|
+
zde->offset = 0;
|
257
|
+
} else {
|
258
|
+
zde->comment_len = _zip_read2(&cur);
|
259
|
+
zde->disk_number = _zip_read2(&cur);
|
260
|
+
zde->int_attrib = _zip_read2(&cur);
|
261
|
+
zde->ext_attrib = _zip_read4(&cur);
|
262
|
+
zde->offset = _zip_read4(&cur);
|
263
|
+
}
|
264
|
+
|
265
|
+
zde->filename = NULL;
|
266
|
+
zde->extrafield = NULL;
|
267
|
+
zde->comment = NULL;
|
268
|
+
|
269
|
+
if (bufp) {
|
270
|
+
if (left < CDENTRYSIZE + (zde->filename_len+zde->extrafield_len
|
271
|
+
+zde->comment_len)) {
|
272
|
+
_zip_error_set(error, ZIP_ER_NOZIP, 0);
|
273
|
+
return -1;
|
274
|
+
}
|
275
|
+
|
276
|
+
if (zde->filename_len) {
|
277
|
+
zde->filename = _zip_readstr(&cur, zde->filename_len, 1, error);
|
278
|
+
if (!zde->filename)
|
279
|
+
return -1;
|
280
|
+
}
|
281
|
+
|
282
|
+
if (zde->extrafield_len) {
|
283
|
+
zde->extrafield = _zip_readstr(&cur, zde->extrafield_len, 0,
|
284
|
+
error);
|
285
|
+
if (!zde->extrafield)
|
286
|
+
return -1;
|
287
|
+
}
|
288
|
+
|
289
|
+
if (zde->comment_len) {
|
290
|
+
zde->comment = _zip_readstr(&cur, zde->comment_len, 0, error);
|
291
|
+
if (!zde->comment)
|
292
|
+
return -1;
|
293
|
+
}
|
294
|
+
}
|
295
|
+
else {
|
296
|
+
if (zde->filename_len) {
|
297
|
+
zde->filename = _zip_readfpstr(fp, zde->filename_len, 1, error);
|
298
|
+
if (!zde->filename)
|
299
|
+
return -1;
|
300
|
+
}
|
301
|
+
|
302
|
+
if (zde->extrafield_len) {
|
303
|
+
zde->extrafield = _zip_readfpstr(fp, zde->extrafield_len, 0,
|
304
|
+
error);
|
305
|
+
if (!zde->extrafield)
|
306
|
+
return -1;
|
307
|
+
}
|
308
|
+
|
309
|
+
if (zde->comment_len) {
|
310
|
+
zde->comment = _zip_readfpstr(fp, zde->comment_len, 0, error);
|
311
|
+
if (!zde->comment)
|
312
|
+
return -1;
|
313
|
+
}
|
314
|
+
}
|
315
|
+
|
316
|
+
if (bufp)
|
317
|
+
*bufp = cur;
|
318
|
+
|
319
|
+
return 0;
|
320
|
+
}
|
321
|
+
|
322
|
+
|
323
|
+
|
324
|
+
/* _zip_dirent_write(zde, fp, localp, error):
|
325
|
+
Writes zip directory entry zde to file fp.
|
326
|
+
|
327
|
+
If localp != 0, it writes a local header instead of a central
|
328
|
+
directory entry.
|
329
|
+
|
330
|
+
Returns 0 if successful. On error, error is filled in and -1 is
|
331
|
+
returned.
|
332
|
+
*/
|
333
|
+
|
334
|
+
int
|
335
|
+
_zip_dirent_write(struct zip_dirent *zde, FILE *fp, int localp,
|
336
|
+
struct zip_error *error)
|
337
|
+
{
|
338
|
+
unsigned short dostime, dosdate;
|
339
|
+
|
340
|
+
fwrite(localp ? LOCAL_MAGIC : CENTRAL_MAGIC, 1, 4, fp);
|
341
|
+
|
342
|
+
if (!localp)
|
343
|
+
_zip_write2(zde->version_madeby, fp);
|
344
|
+
_zip_write2(zde->version_needed, fp);
|
345
|
+
_zip_write2(zde->bitflags, fp);
|
346
|
+
_zip_write2(zde->comp_method, fp);
|
347
|
+
|
348
|
+
_zip_u2d_time(zde->last_mod, &dostime, &dosdate);
|
349
|
+
_zip_write2(dostime, fp);
|
350
|
+
_zip_write2(dosdate, fp);
|
351
|
+
|
352
|
+
_zip_write4(zde->crc, fp);
|
353
|
+
_zip_write4(zde->comp_size, fp);
|
354
|
+
_zip_write4(zde->uncomp_size, fp);
|
355
|
+
|
356
|
+
_zip_write2(zde->filename_len, fp);
|
357
|
+
_zip_write2(zde->extrafield_len, fp);
|
358
|
+
|
359
|
+
if (!localp) {
|
360
|
+
_zip_write2(zde->comment_len, fp);
|
361
|
+
_zip_write2(zde->disk_number, fp);
|
362
|
+
_zip_write2(zde->int_attrib, fp);
|
363
|
+
_zip_write4(zde->ext_attrib, fp);
|
364
|
+
_zip_write4(zde->offset, fp);
|
365
|
+
}
|
366
|
+
|
367
|
+
if (zde->filename_len)
|
368
|
+
fwrite(zde->filename, 1, zde->filename_len, fp);
|
369
|
+
|
370
|
+
if (zde->extrafield_len)
|
371
|
+
fwrite(zde->extrafield, 1, zde->extrafield_len, fp);
|
372
|
+
|
373
|
+
if (!localp) {
|
374
|
+
if (zde->comment_len)
|
375
|
+
fwrite(zde->comment, 1, zde->comment_len, fp);
|
376
|
+
}
|
377
|
+
|
378
|
+
if (ferror(fp)) {
|
379
|
+
_zip_error_set(error, ZIP_ER_WRITE, errno);
|
380
|
+
return -1;
|
381
|
+
}
|
382
|
+
|
383
|
+
return 0;
|
384
|
+
}
|
385
|
+
|
386
|
+
|
387
|
+
|
388
|
+
static time_t
|
389
|
+
_zip_d2u_time(int dtime, int ddate)
|
390
|
+
{
|
391
|
+
struct tm *tm;
|
392
|
+
time_t now;
|
393
|
+
|
394
|
+
now = time(NULL);
|
395
|
+
tm = localtime(&now);
|
396
|
+
/* let mktime decide if DST is in effect */
|
397
|
+
tm->tm_isdst = -1;
|
398
|
+
|
399
|
+
tm->tm_year = ((ddate>>9)&127) + 1980 - 1900;
|
400
|
+
tm->tm_mon = ((ddate>>5)&15) - 1;
|
401
|
+
tm->tm_mday = ddate&31;
|
402
|
+
|
403
|
+
tm->tm_hour = (dtime>>11)&31;
|
404
|
+
tm->tm_min = (dtime>>5)&63;
|
405
|
+
tm->tm_sec = (dtime<<1)&62;
|
406
|
+
|
407
|
+
return mktime(tm);
|
408
|
+
}
|
409
|
+
|
410
|
+
|
411
|
+
|
412
|
+
unsigned short
|
413
|
+
_zip_read2(unsigned char **a)
|
414
|
+
{
|
415
|
+
unsigned short ret;
|
416
|
+
|
417
|
+
ret = (*a)[0]+((*a)[1]<<8);
|
418
|
+
*a += 2;
|
419
|
+
|
420
|
+
return ret;
|
421
|
+
}
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
unsigned int
|
426
|
+
_zip_read4(unsigned char **a)
|
427
|
+
{
|
428
|
+
unsigned int ret;
|
429
|
+
|
430
|
+
ret = ((((((*a)[3]<<8)+(*a)[2])<<8)+(*a)[1])<<8)+(*a)[0];
|
431
|
+
*a += 4;
|
432
|
+
|
433
|
+
return ret;
|
434
|
+
}
|
435
|
+
|
436
|
+
|
437
|
+
|
438
|
+
static char *
|
439
|
+
_zip_readfpstr(FILE *fp, unsigned int len, int nulp, struct zip_error *error)
|
440
|
+
{
|
441
|
+
char *r, *o;
|
442
|
+
|
443
|
+
r = (char *)malloc(nulp ? len+1 : len);
|
444
|
+
if (!r) {
|
445
|
+
_zip_error_set(error, ZIP_ER_MEMORY, 0);
|
446
|
+
return NULL;
|
447
|
+
}
|
448
|
+
|
449
|
+
if (fread(r, 1, len, fp)<len) {
|
450
|
+
free(r);
|
451
|
+
_zip_error_set(error, ZIP_ER_READ, errno);
|
452
|
+
return NULL;
|
453
|
+
}
|
454
|
+
|
455
|
+
if (nulp) {
|
456
|
+
/* replace any in-string NUL characters with spaces */
|
457
|
+
r[len] = 0;
|
458
|
+
for (o=r; o<r+len; o++)
|
459
|
+
if (*o == '\0')
|
460
|
+
*o = ' ';
|
461
|
+
}
|
462
|
+
|
463
|
+
return r;
|
464
|
+
}
|
465
|
+
|
466
|
+
|
467
|
+
|
468
|
+
static char *
|
469
|
+
_zip_readstr(unsigned char **buf, int len, int nulp, struct zip_error *error)
|
470
|
+
{
|
471
|
+
char *r, *o;
|
472
|
+
|
473
|
+
r = (char *)malloc(nulp ? len+1 : len);
|
474
|
+
if (!r) {
|
475
|
+
_zip_error_set(error, ZIP_ER_MEMORY, 0);
|
476
|
+
return NULL;
|
477
|
+
}
|
478
|
+
|
479
|
+
memcpy(r, *buf, len);
|
480
|
+
*buf += len;
|
481
|
+
|
482
|
+
if (nulp) {
|
483
|
+
/* replace any in-string NUL characters with spaces */
|
484
|
+
r[len] = 0;
|
485
|
+
for (o=r; o<r+len; o++)
|
486
|
+
if (*o == '\0')
|
487
|
+
*o = ' ';
|
488
|
+
}
|
489
|
+
|
490
|
+
return r;
|
491
|
+
}
|
492
|
+
|
493
|
+
|
494
|
+
|
495
|
+
static void
|
496
|
+
_zip_write2(unsigned short i, FILE *fp)
|
497
|
+
{
|
498
|
+
putc(i&0xff, fp);
|
499
|
+
putc((i>>8)&0xff, fp);
|
500
|
+
|
501
|
+
return;
|
502
|
+
}
|
503
|
+
|
504
|
+
|
505
|
+
|
506
|
+
static void
|
507
|
+
_zip_write4(unsigned int i, FILE *fp)
|
508
|
+
{
|
509
|
+
putc(i&0xff, fp);
|
510
|
+
putc((i>>8)&0xff, fp);
|
511
|
+
putc((i>>16)&0xff, fp);
|
512
|
+
putc((i>>24)&0xff, fp);
|
513
|
+
|
514
|
+
return;
|
515
|
+
}
|
516
|
+
|
517
|
+
|
518
|
+
|
519
|
+
static void
|
520
|
+
_zip_u2d_time(time_t time, unsigned short *dtime, unsigned short *ddate)
|
521
|
+
{
|
522
|
+
struct tm *tm;
|
523
|
+
|
524
|
+
tm = localtime(&time);
|
525
|
+
*ddate = ((tm->tm_year+1900-1980)<<9) + ((tm->tm_mon+1)<<5)
|
526
|
+
+ tm->tm_mday;
|
527
|
+
*dtime = ((tm->tm_hour)<<11) + ((tm->tm_min)<<5)
|
528
|
+
+ ((tm->tm_sec)>>1);
|
529
|
+
|
530
|
+
return;
|
531
|
+
}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
/*
|
2
|
+
$NiH: zip_entry_free.c,v 1.1 2004/11/30 21:37:01 wiz Exp $
|
3
|
+
|
4
|
+
zip_entry_free.c -- free struct zip_entry
|
5
|
+
Copyright (C) 1999, 2003, 2004, 2006 Dieter Baron and Thomas Klausner
|
6
|
+
|
7
|
+
This file is part of libzip, a library to manipulate ZIP archives.
|
8
|
+
The authors can be contacted at <nih@giga.or.at>
|
9
|
+
|
10
|
+
Redistribution and use in source and binary forms, with or without
|
11
|
+
modification, are permitted provided that the following conditions
|
12
|
+
are met:
|
13
|
+
1. Redistributions of source code must retain the above copyright
|
14
|
+
notice, this list of conditions and the following disclaimer.
|
15
|
+
2. Redistributions in binary form must reproduce the above copyright
|
16
|
+
notice, this list of conditions and the following disclaimer in
|
17
|
+
the documentation and/or other materials provided with the
|
18
|
+
distribution.
|
19
|
+
3. The names of the authors may not be used to endorse or promote
|
20
|
+
products derived from this software without specific prior
|
21
|
+
written permission.
|
22
|
+
|
23
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
|
24
|
+
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
25
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
26
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
27
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
28
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
29
|
+
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
30
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
31
|
+
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
32
|
+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
33
|
+
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
*/
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
#include <stdlib.h>
|
39
|
+
|
40
|
+
#include "zip.h"
|
41
|
+
#include "zipint.h"
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
void
|
46
|
+
_zip_entry_free(struct zip_entry *ze)
|
47
|
+
{
|
48
|
+
free(ze->ch_filename);
|
49
|
+
ze->ch_filename = NULL;
|
50
|
+
free(ze->ch_comment);
|
51
|
+
ze->ch_comment = NULL;
|
52
|
+
ze->ch_comment_len = -1;
|
53
|
+
|
54
|
+
_zip_unchange_data(ze);
|
55
|
+
}
|
data/ext/zip_entry_new.c
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
/*
|
2
|
+
$NiH: zip_entry_new.c,v 1.1 2004/11/30 21:42:22 wiz Exp $
|
3
|
+
|
4
|
+
zip_entry_new.c -- create and init struct zip_entry
|
5
|
+
Copyright (C) 1999, 2003, 2004, 2006 Dieter Baron and Thomas Klausner
|
6
|
+
|
7
|
+
This file is part of libzip, a library to manipulate ZIP archives.
|
8
|
+
The authors can be contacted at <nih@giga.or.at>
|
9
|
+
|
10
|
+
Redistribution and use in source and binary forms, with or without
|
11
|
+
modification, are permitted provided that the following conditions
|
12
|
+
are met:
|
13
|
+
1. Redistributions of source code must retain the above copyright
|
14
|
+
notice, this list of conditions and the following disclaimer.
|
15
|
+
2. Redistributions in binary form must reproduce the above copyright
|
16
|
+
notice, this list of conditions and the following disclaimer in
|
17
|
+
the documentation and/or other materials provided with the
|
18
|
+
distribution.
|
19
|
+
3. The names of the authors may not be used to endorse or promote
|
20
|
+
products derived from this software without specific prior
|
21
|
+
written permission.
|
22
|
+
|
23
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
|
24
|
+
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
25
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
26
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
27
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
28
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
29
|
+
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
30
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
31
|
+
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
32
|
+
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
33
|
+
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
*/
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
#include <stdlib.h>
|
39
|
+
|
40
|
+
#include "zip.h"
|
41
|
+
#include "zipint.h"
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
struct zip_entry *
|
46
|
+
_zip_entry_new(struct zip *za)
|
47
|
+
{
|
48
|
+
struct zip_entry *ze;
|
49
|
+
if (!za) {
|
50
|
+
ze = (struct zip_entry *)malloc(sizeof(struct zip_entry));
|
51
|
+
if (!ze) {
|
52
|
+
_zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
|
53
|
+
return NULL;
|
54
|
+
}
|
55
|
+
}
|
56
|
+
else {
|
57
|
+
if (za->nentry >= za->nentry_alloc-1) {
|
58
|
+
za->nentry_alloc += 16;
|
59
|
+
za->entry = (struct zip_entry *)realloc(za->entry,
|
60
|
+
sizeof(struct zip_entry)
|
61
|
+
* za->nentry_alloc);
|
62
|
+
if (!za->entry) {
|
63
|
+
_zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
|
64
|
+
return NULL;
|
65
|
+
}
|
66
|
+
}
|
67
|
+
ze = za->entry+za->nentry;
|
68
|
+
}
|
69
|
+
|
70
|
+
ze->state = ZIP_ST_UNCHANGED;
|
71
|
+
|
72
|
+
ze->ch_filename = NULL;
|
73
|
+
ze->ch_comment = NULL;
|
74
|
+
ze->ch_comment_len = -1;
|
75
|
+
ze->source = NULL;
|
76
|
+
|
77
|
+
if (za)
|
78
|
+
za->nentry++;
|
79
|
+
|
80
|
+
return ze;
|
81
|
+
}
|