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.

Files changed (60) hide show
  1. data/README.txt +131 -0
  2. data/ext/extconf.rb +1 -1
  3. data/ext/libzip.mswin32.patch +113 -0
  4. data/ext/libzip.vcproj +308 -0
  5. data/ext/libzip.vcproj.IBM-94B792EFFD1.sugawara.user +37 -0
  6. data/ext/mkstemp.c +143 -0
  7. data/ext/zip.h +211 -0
  8. data/ext/zip_add.c +52 -0
  9. data/ext/zip_add_dir.c +83 -0
  10. data/ext/zip_close.c +566 -0
  11. data/ext/zip_delete.c +61 -0
  12. data/ext/zip_dirent.c +531 -0
  13. data/ext/zip_entry_free.c +55 -0
  14. data/ext/zip_entry_new.c +81 -0
  15. data/ext/zip_err_str.c +72 -0
  16. data/ext/zip_error.c +104 -0
  17. data/ext/zip_error_clear.c +47 -0
  18. data/ext/zip_error_get.c +47 -0
  19. data/ext/zip_error_get_sys_type.c +50 -0
  20. data/ext/zip_error_strerror.c +93 -0
  21. data/ext/zip_error_to_str.c +77 -0
  22. data/ext/zip_fclose.c +74 -0
  23. data/ext/zip_file_error_clear.c +47 -0
  24. data/ext/zip_file_error_get.c +47 -0
  25. data/ext/zip_file_get_offset.c +77 -0
  26. data/ext/zip_file_strerror.c +47 -0
  27. data/ext/zip_fopen.c +52 -0
  28. data/ext/zip_fopen_index.c +219 -0
  29. data/ext/zip_fread.c +125 -0
  30. data/ext/zip_free.c +83 -0
  31. data/ext/zip_get_archive_comment.c +63 -0
  32. data/ext/zip_get_file_comment.c +61 -0
  33. data/ext/zip_get_name.c +74 -0
  34. data/ext/zip_get_num_files.c +50 -0
  35. data/ext/zip_memdup.c +58 -0
  36. data/ext/zip_name_locate.c +95 -0
  37. data/ext/zip_new.c +71 -0
  38. data/ext/zip_open.c +520 -0
  39. data/ext/zip_rename.c +52 -0
  40. data/ext/zip_replace.c +81 -0
  41. data/ext/zip_set_archive_comment.c +68 -0
  42. data/ext/zip_set_file_comment.c +69 -0
  43. data/ext/zip_set_name.c +77 -0
  44. data/ext/zip_source_buffer.c +160 -0
  45. data/ext/zip_source_file.c +71 -0
  46. data/ext/zip_source_filep.c +176 -0
  47. data/ext/zip_source_free.c +54 -0
  48. data/ext/zip_source_function.c +62 -0
  49. data/ext/zip_source_zip.c +189 -0
  50. data/ext/zip_stat.c +52 -0
  51. data/ext/zip_stat_index.c +93 -0
  52. data/ext/zip_stat_init.c +53 -0
  53. data/ext/zip_strerror.c +47 -0
  54. data/ext/zip_unchange.c +84 -0
  55. data/ext/zip_unchange_all.c +56 -0
  56. data/ext/zip_unchange_archive.c +52 -0
  57. data/ext/zip_unchange_data.c +53 -0
  58. data/ext/zipint.h +240 -0
  59. data/ext/zipruby.h +1 -1
  60. metadata +63 -5
@@ -0,0 +1,77 @@
1
+ /*
2
+ $NiH: zip_file_get_offset.c,v 1.4 2006/04/23 14:51:45 wiz Exp $
3
+
4
+ zip_file_get_offset.c -- get offset of file data in archive.
5
+ Copyright (C) 1999, 2003, 2004 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
+
49
+
50
+ /* _zip_file_get_offset(za, ze):
51
+ Returns the offset of the file data for entry ze.
52
+
53
+ On error, fills in za->error and returns 0.
54
+ */
55
+
56
+ unsigned int
57
+ _zip_file_get_offset(struct zip *za, int idx)
58
+ {
59
+ struct zip_dirent de;
60
+ unsigned int offset;
61
+
62
+ offset = za->cdir->entry[idx].offset;
63
+
64
+ if (fseeko(za->zp, offset, SEEK_SET) != 0) {
65
+ _zip_error_set(&za->error, ZIP_ER_SEEK, errno);
66
+ return 0;
67
+ }
68
+
69
+ if (_zip_dirent_read(&de, za->zp, NULL, 0, 1, &za->error) != 0)
70
+ return 0;
71
+
72
+ offset += LENTRYSIZE + de.filename_len + de.extrafield_len;
73
+
74
+ _zip_dirent_finalize(&de);
75
+
76
+ return offset;
77
+ }
@@ -0,0 +1,47 @@
1
+ /*
2
+ $NiH$
3
+
4
+ zip_file_sterror.c -- get string representation of zip file error
5
+ Copyright (C) 1999, 2003 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 "zip.h"
39
+ #include "zipint.h"
40
+
41
+
42
+
43
+ const char *
44
+ zip_file_strerror(struct zip_file *zf)
45
+ {
46
+ return _zip_error_strerror(&zf->error);
47
+ }
data/ext/zip_fopen.c ADDED
@@ -0,0 +1,52 @@
1
+ /*
2
+ $NiH: zip_fopen.c,v 1.11 2005/01/11 18:38:16 wiz Exp $
3
+
4
+ zip_fopen.c -- open file in zip archive for reading
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 "zip.h"
39
+ #include "zipint.h"
40
+
41
+
42
+
43
+ struct zip_file *
44
+ zip_fopen(struct zip *za, const char *fname, int flags)
45
+ {
46
+ int idx;
47
+
48
+ if ((idx=zip_name_locate(za, fname, flags)) < 0)
49
+ return NULL;
50
+
51
+ return zip_fopen_index(za, idx, flags);
52
+ }
@@ -0,0 +1,219 @@
1
+ /*
2
+ $NiH: zip_fopen_index.c,v 1.24 2005/05/20 21:54:53 wiz Exp $
3
+
4
+ zip_fopen_index.c -- open file in zip archive for reading by index
5
+ Copyright (C) 1999, 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 <errno.h>
39
+ #include <stdio.h>
40
+ #include <stdlib.h>
41
+
42
+ #include "zip.h"
43
+ #include "zipint.h"
44
+
45
+ static struct zip_file *_zip_file_new(struct zip *za);
46
+
47
+
48
+
49
+ struct zip_file *
50
+ zip_fopen_index(struct zip *za, int fileno, int flags)
51
+ {
52
+ int len, ret;
53
+ int zfflags;
54
+ struct zip_file *zf;
55
+
56
+ if ((fileno < 0) || (fileno >= za->nentry)) {
57
+ _zip_error_set(&za->error, ZIP_ER_INVAL, 0);
58
+ return NULL;
59
+ }
60
+
61
+ if ((flags & ZIP_FL_UNCHANGED) == 0
62
+ && ZIP_ENTRY_DATA_CHANGED(za->entry+fileno)) {
63
+ _zip_error_set(&za->error, ZIP_ER_CHANGED, 0);
64
+ return NULL;
65
+ }
66
+
67
+ if (fileno >= za->cdir->nentry) {
68
+ _zip_error_set(&za->error, ZIP_ER_INVAL, 0);
69
+ return NULL;
70
+ }
71
+
72
+ zfflags = 0;
73
+ switch (za->cdir->entry[fileno].comp_method) {
74
+ case ZIP_CM_STORE:
75
+ zfflags |= ZIP_ZF_CRC;
76
+ break;
77
+
78
+ case ZIP_CM_DEFLATE:
79
+ if ((flags & ZIP_FL_COMPRESSED) == 0)
80
+ zfflags |= ZIP_ZF_CRC | ZIP_ZF_DECOMP;
81
+ break;
82
+ default:
83
+ if ((flags & ZIP_FL_COMPRESSED) == 0) {
84
+ _zip_error_set(&za->error, ZIP_ER_COMPNOTSUPP, 0);
85
+ return NULL;
86
+ }
87
+ break;
88
+ }
89
+
90
+ zf = _zip_file_new(za);
91
+
92
+ zf->flags = zfflags;
93
+ /* zf->name = za->cdir->entry[fileno].filename; */
94
+ zf->method = za->cdir->entry[fileno].comp_method;
95
+ zf->bytes_left = za->cdir->entry[fileno].uncomp_size;
96
+ zf->cbytes_left = za->cdir->entry[fileno].comp_size;
97
+ zf->crc_orig = za->cdir->entry[fileno].crc;
98
+
99
+ if ((zf->fpos=_zip_file_get_offset(za, fileno)) == 0) {
100
+ zip_fclose(zf);
101
+ return NULL;
102
+ }
103
+
104
+ if ((zf->flags & ZIP_ZF_DECOMP) == 0)
105
+ zf->bytes_left = zf->cbytes_left;
106
+ else {
107
+ if ((zf->buffer=(char *)malloc(BUFSIZE)) == NULL) {
108
+ _zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
109
+ zip_fclose(zf);
110
+ return NULL;
111
+ }
112
+
113
+ len = _zip_file_fillbuf(zf->buffer, BUFSIZE, zf);
114
+ if (len <= 0) {
115
+ _zip_error_copy(&za->error, &zf->error);
116
+ zip_fclose(zf);
117
+ return NULL;
118
+ }
119
+
120
+ if ((zf->zstr = (z_stream *)malloc(sizeof(z_stream))) == NULL) {
121
+ _zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
122
+ zip_fclose(zf);
123
+ return NULL;
124
+ }
125
+ zf->zstr->zalloc = Z_NULL;
126
+ zf->zstr->zfree = Z_NULL;
127
+ zf->zstr->opaque = NULL;
128
+ zf->zstr->next_in = (Bytef *)zf->buffer;
129
+ zf->zstr->avail_in = len;
130
+
131
+ /* negative value to tell zlib that there is no header */
132
+ if ((ret=inflateInit2(zf->zstr, -MAX_WBITS)) != Z_OK) {
133
+ _zip_error_set(&za->error, ZIP_ER_ZLIB, ret);
134
+ zip_fclose(zf);
135
+ return NULL;
136
+ }
137
+ }
138
+
139
+ return zf;
140
+ }
141
+
142
+
143
+
144
+ int
145
+ _zip_file_fillbuf(void *buf, size_t buflen, struct zip_file *zf)
146
+ {
147
+ int i, j;
148
+
149
+ if (zf->error.zip_err != ZIP_ER_OK)
150
+ return -1;
151
+
152
+ if ((zf->flags & ZIP_ZF_EOF) || zf->cbytes_left <= 0 || buflen <= 0)
153
+ return 0;
154
+
155
+ if (fseeko(zf->za->zp, zf->fpos, SEEK_SET) < 0) {
156
+ _zip_error_set(&zf->error, ZIP_ER_SEEK, errno);
157
+ return -1;
158
+ }
159
+ if (buflen < zf->cbytes_left)
160
+ i = buflen;
161
+ else
162
+ i = zf->cbytes_left;
163
+
164
+ j = fread(buf, 1, i, zf->za->zp);
165
+ if (j == 0) {
166
+ _zip_error_set(&zf->error, ZIP_ER_EOF, 0);
167
+ j = -1;
168
+ }
169
+ else if (j < 0)
170
+ _zip_error_set(&zf->error, ZIP_ER_READ, errno);
171
+ else {
172
+ zf->fpos += j;
173
+ zf->cbytes_left -= j;
174
+ }
175
+
176
+ return j;
177
+ }
178
+
179
+
180
+
181
+ static struct zip_file *
182
+ _zip_file_new(struct zip *za)
183
+ {
184
+ struct zip_file *zf, **file;
185
+ int n;
186
+
187
+ if ((zf=(struct zip_file *)malloc(sizeof(struct zip_file))) == NULL) {
188
+ _zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
189
+ return NULL;
190
+ }
191
+
192
+ if (za->nfile >= za->nfile_alloc-1) {
193
+ n = za->nfile_alloc + 10;
194
+ file = (struct zip_file **)realloc(za->file,
195
+ n*sizeof(struct zip_file *));
196
+ if (file == NULL) {
197
+ _zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
198
+ free(zf);
199
+ return NULL;
200
+ }
201
+ za->nfile_alloc = n;
202
+ za->file = file;
203
+ }
204
+
205
+ za->file[za->nfile++] = zf;
206
+
207
+ zf->za = za;
208
+ _zip_error_init(&zf->error);
209
+ zf->flags = 0;
210
+ zf->crc = crc32(0L, Z_NULL, 0);
211
+ zf->crc_orig = 0;
212
+ zf->method = -1;
213
+ zf->bytes_left = zf->cbytes_left = 0;
214
+ zf->fpos = 0;
215
+ zf->buffer = NULL;
216
+ zf->zstr = NULL;
217
+
218
+ return zf;
219
+ }
data/ext/zip_fread.c ADDED
@@ -0,0 +1,125 @@
1
+ /*
2
+ $NiH: zip_fread.c,v 1.20 2006/02/22 19:52:20 dillo Exp $
3
+
4
+ zip_fread.c -- read from file
5
+ Copyright (C) 1999, 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 "zip.h"
39
+ #include "zipint.h"
40
+
41
+
42
+
43
+ ssize_t
44
+ zip_fread(struct zip_file *zf, void *outbuf, size_t toread)
45
+ {
46
+ int ret;
47
+ size_t out_before, len;
48
+ int i;
49
+
50
+ if (!zf)
51
+ return -1;
52
+
53
+ if (zf->error.zip_err != 0)
54
+ return -1;
55
+
56
+ if ((zf->flags & ZIP_ZF_EOF) || (toread == 0))
57
+ return 0;
58
+
59
+ if (zf->bytes_left == 0) {
60
+ zf->flags |= ZIP_ZF_EOF;
61
+ if (zf->flags & ZIP_ZF_CRC) {
62
+ if (zf->crc != zf->crc_orig) {
63
+ _zip_error_set(&zf->error, ZIP_ER_CRC, 0);
64
+ return -1;
65
+ }
66
+ }
67
+ return 0;
68
+ }
69
+
70
+ if ((zf->flags & ZIP_ZF_DECOMP) == 0) {
71
+ ret = _zip_file_fillbuf(outbuf, toread, zf);
72
+ if (ret > 0) {
73
+ if (zf->flags & ZIP_ZF_CRC)
74
+ zf->crc = crc32(zf->crc, (Bytef *)outbuf, ret);
75
+ zf->bytes_left -= ret;
76
+ }
77
+ return ret;
78
+ }
79
+
80
+ zf->zstr->next_out = (Bytef *)outbuf;
81
+ zf->zstr->avail_out = toread;
82
+ out_before = zf->zstr->total_out;
83
+
84
+ /* endless loop until something has been accomplished */
85
+ for (;;) {
86
+ ret = inflate(zf->zstr, Z_SYNC_FLUSH);
87
+
88
+ switch (ret) {
89
+ case Z_OK:
90
+ case Z_STREAM_END:
91
+ /* all ok */
92
+ /* Z_STREAM_END probably won't happen, since we didn't
93
+ have a header */
94
+ len = zf->zstr->total_out - out_before;
95
+ if (len >= zf->bytes_left || len >= toread) {
96
+ if (zf->flags & ZIP_ZF_CRC)
97
+ zf->crc = crc32(zf->crc, (Bytef *)outbuf, len);
98
+ zf->bytes_left -= len;
99
+ return len;
100
+ }
101
+ break;
102
+
103
+ case Z_BUF_ERROR:
104
+ if (zf->zstr->avail_in == 0) {
105
+ i = _zip_file_fillbuf(zf->buffer, BUFSIZE, zf);
106
+ if (i == 0) {
107
+ _zip_error_set(&zf->error, ZIP_ER_INCONS, 0);
108
+ return -1;
109
+ }
110
+ else if (i < 0)
111
+ return -1;
112
+ zf->zstr->next_in = (Bytef *)zf->buffer;
113
+ zf->zstr->avail_in = i;
114
+ continue;
115
+ }
116
+ /* fallthrough */
117
+ case Z_NEED_DICT:
118
+ case Z_DATA_ERROR:
119
+ case Z_STREAM_ERROR:
120
+ case Z_MEM_ERROR:
121
+ _zip_error_set(&zf->error, ZIP_ER_ZLIB, ret);
122
+ return -1;
123
+ }
124
+ }
125
+ }
data/ext/zip_free.c ADDED
@@ -0,0 +1,83 @@
1
+ /*
2
+ $NiH: zip_free.c,v 1.16 2005/01/11 17:40:56 dillo Exp $
3
+
4
+ zip_free.c -- free struct zip
5
+ Copyright (C) 1999, 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 <stdlib.h>
39
+ #include "zip.h"
40
+ #include "zipint.h"
41
+
42
+
43
+
44
+ /* _zip_free:
45
+ frees the space allocated to a zipfile struct, and closes the
46
+ corresponding file. */
47
+
48
+ void
49
+ _zip_free(struct zip *za)
50
+ {
51
+ int i;
52
+
53
+ if (za == NULL)
54
+ return;
55
+
56
+ if (za->zn)
57
+ free(za->zn);
58
+
59
+ if (za->zp)
60
+ fclose(za->zp);
61
+
62
+ _zip_cdir_free(za->cdir);
63
+
64
+ if (za->entry) {
65
+ for (i=0; i<za->nentry; i++) {
66
+ _zip_entry_free(za->entry+i);
67
+ }
68
+ free(za->entry);
69
+ }
70
+
71
+ for (i=0; i<za->nfile; i++) {
72
+ if (za->file[i]->error.zip_err == ZIP_ER_OK) {
73
+ _zip_error_set(&za->file[i]->error, ZIP_ER_ZIPCLOSED, 0);
74
+ za->file[i]->za = NULL;
75
+ }
76
+ }
77
+
78
+ free(za->file);
79
+
80
+ free(za);
81
+
82
+ return;
83
+ }
@@ -0,0 +1,63 @@
1
+ /*
2
+ $NiH: zip_get_archive_comment.c,v 1.4 2006/04/23 16:11:33 wiz Exp $
3
+
4
+ zip_get_archive_comment.c -- get archive comment
5
+ Copyright (C) 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 "zip.h"
39
+ #include "zipint.h"
40
+
41
+
42
+
43
+ const char *
44
+ zip_get_archive_comment(struct zip *za, int *lenp, int flags)
45
+ {
46
+ if ((flags & ZIP_FL_UNCHANGED)
47
+ || (za->ch_comment_len == -1)) {
48
+ if (za->cdir) {
49
+ if (lenp != NULL)
50
+ *lenp = za->cdir->comment_len;
51
+ return za->cdir->comment;
52
+ }
53
+ else {
54
+ if (lenp != NULL)
55
+ *lenp = -1;
56
+ return NULL;
57
+ }
58
+ }
59
+
60
+ if (lenp != NULL)
61
+ *lenp = za->ch_comment_len;
62
+ return za->ch_comment;
63
+ }