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
@@ -0,0 +1,69 @@
|
|
1
|
+
/*
|
2
|
+
$NiH: zip_set_file_comment.c,v 1.3 2006/04/23 15:26:30 dillo Exp $
|
3
|
+
|
4
|
+
zip_set_file_comment.c -- set comment for file in archive
|
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 <stdlib.h>
|
39
|
+
|
40
|
+
#include "zip.h"
|
41
|
+
#include "zipint.h"
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
int
|
46
|
+
zip_set_file_comment(struct zip *za, int idx, const char *comment, int len)
|
47
|
+
{
|
48
|
+
char *tmpcom;
|
49
|
+
|
50
|
+
if (idx < 0 || idx >= za->nentry
|
51
|
+
|| len < 0 || len > MAXCOMLEN
|
52
|
+
|| (len > 0 && comment == NULL)) {
|
53
|
+
_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
|
54
|
+
return -1;
|
55
|
+
}
|
56
|
+
|
57
|
+
if (len > 0) {
|
58
|
+
if ((tmpcom=(char *)_zip_memdup(comment, len, &za->error)) == NULL)
|
59
|
+
return -1;
|
60
|
+
}
|
61
|
+
else
|
62
|
+
tmpcom = NULL;
|
63
|
+
|
64
|
+
free(za->entry[idx].ch_comment);
|
65
|
+
za->entry[idx].ch_comment = tmpcom;
|
66
|
+
za->entry[idx].ch_comment_len = len;
|
67
|
+
|
68
|
+
return 0;
|
69
|
+
}
|
data/ext/zip_set_name.c
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
/*
|
2
|
+
$NiH: zip_set_name.c,v 1.15 2004/11/30 22:19:38 wiz Exp $
|
3
|
+
|
4
|
+
zip_set_name.c -- rename helper function
|
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 <stdlib.h>
|
39
|
+
#include <string.h>
|
40
|
+
#include "zip.h"
|
41
|
+
#include "zipint.h"
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
int
|
46
|
+
_zip_set_name(struct zip *za, int idx, const char *name)
|
47
|
+
{
|
48
|
+
char *s;
|
49
|
+
int i;
|
50
|
+
|
51
|
+
if (idx < 0 || idx >= za->nentry || name == NULL) {
|
52
|
+
_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
|
53
|
+
return -1;
|
54
|
+
}
|
55
|
+
|
56
|
+
if ((i=_zip_name_locate(za, name, 0, NULL)) != -1 && i != idx) {
|
57
|
+
_zip_error_set(&za->error, ZIP_ER_EXISTS, 0);
|
58
|
+
return -1;
|
59
|
+
}
|
60
|
+
|
61
|
+
/* no effective name change */
|
62
|
+
if (i == idx)
|
63
|
+
return 0;
|
64
|
+
|
65
|
+
if ((s=strdup(name)) == NULL) {
|
66
|
+
_zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
|
67
|
+
return -1;
|
68
|
+
}
|
69
|
+
|
70
|
+
if (za->entry[idx].state == ZIP_ST_UNCHANGED)
|
71
|
+
za->entry[idx].state = ZIP_ST_RENAMED;
|
72
|
+
|
73
|
+
free(za->entry[idx].ch_filename);
|
74
|
+
za->entry[idx].ch_filename = s;
|
75
|
+
|
76
|
+
return 0;
|
77
|
+
}
|
@@ -0,0 +1,160 @@
|
|
1
|
+
/*
|
2
|
+
$NiH: zip_source_buffer.c,v 1.8 2006/04/23 14:50:49 wiz Exp $
|
3
|
+
|
4
|
+
zip_source_buffer.c -- create zip data source from buffer
|
5
|
+
Copyright (C) 1999-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
|
+
#include <string.h>
|
40
|
+
|
41
|
+
#include "zip.h"
|
42
|
+
#include "zipint.h"
|
43
|
+
|
44
|
+
struct read_data {
|
45
|
+
const char *buf, *data, *end;
|
46
|
+
time_t mtime;
|
47
|
+
int freep;
|
48
|
+
};
|
49
|
+
|
50
|
+
static ssize_t read_data(void *state, void *data, size_t len,
|
51
|
+
enum zip_source_cmd cmd);
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
struct zip_source *
|
56
|
+
zip_source_buffer(struct zip *za, const void *data, off_t len, int freep)
|
57
|
+
{
|
58
|
+
struct read_data *f;
|
59
|
+
struct zip_source *zs;
|
60
|
+
|
61
|
+
if (za == NULL)
|
62
|
+
return NULL;
|
63
|
+
|
64
|
+
if (len < 0 || (data == NULL && len > 0)) {
|
65
|
+
_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
|
66
|
+
return NULL;
|
67
|
+
}
|
68
|
+
|
69
|
+
if ((f=(struct read_data *)malloc(sizeof(*f))) == NULL) {
|
70
|
+
_zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
|
71
|
+
return NULL;
|
72
|
+
}
|
73
|
+
|
74
|
+
f->data = (const char *)data;
|
75
|
+
f->end = ((const char *)data)+len;
|
76
|
+
f->freep = freep;
|
77
|
+
f->mtime = time(NULL);
|
78
|
+
|
79
|
+
if ((zs=zip_source_function(za, read_data, f)) == NULL) {
|
80
|
+
free(f);
|
81
|
+
return NULL;
|
82
|
+
}
|
83
|
+
|
84
|
+
return zs;
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
static ssize_t
|
90
|
+
read_data(void *state, void *data, size_t len, enum zip_source_cmd cmd)
|
91
|
+
{
|
92
|
+
struct read_data *z;
|
93
|
+
char *buf;
|
94
|
+
size_t n;
|
95
|
+
|
96
|
+
z = (struct read_data *)state;
|
97
|
+
buf = (char *)data;
|
98
|
+
|
99
|
+
switch (cmd) {
|
100
|
+
case ZIP_SOURCE_OPEN:
|
101
|
+
z->buf = z->data;
|
102
|
+
return 0;
|
103
|
+
|
104
|
+
case ZIP_SOURCE_READ:
|
105
|
+
n = z->end - z->buf;
|
106
|
+
if (n > len)
|
107
|
+
n = len;
|
108
|
+
|
109
|
+
if (n) {
|
110
|
+
memcpy(buf, z->buf, n);
|
111
|
+
z->buf += n;
|
112
|
+
}
|
113
|
+
|
114
|
+
return n;
|
115
|
+
|
116
|
+
case ZIP_SOURCE_CLOSE:
|
117
|
+
return 0;
|
118
|
+
|
119
|
+
case ZIP_SOURCE_STAT:
|
120
|
+
{
|
121
|
+
struct zip_stat *st;
|
122
|
+
|
123
|
+
if (len < sizeof(*st))
|
124
|
+
return -1;
|
125
|
+
|
126
|
+
st = (struct zip_stat *)data;
|
127
|
+
|
128
|
+
zip_stat_init(st);
|
129
|
+
st->mtime = z->mtime;
|
130
|
+
st->size = z->end - z->data;
|
131
|
+
|
132
|
+
return sizeof(*st);
|
133
|
+
}
|
134
|
+
|
135
|
+
case ZIP_SOURCE_ERROR:
|
136
|
+
{
|
137
|
+
int *e;
|
138
|
+
|
139
|
+
if (len < sizeof(int)*2)
|
140
|
+
return -1;
|
141
|
+
|
142
|
+
e = (int *)data;
|
143
|
+
e[0] = e[1] = 0;
|
144
|
+
}
|
145
|
+
return sizeof(int)*2;
|
146
|
+
|
147
|
+
case ZIP_SOURCE_FREE:
|
148
|
+
if (z->freep) {
|
149
|
+
free((void *)z->data);
|
150
|
+
z->data = NULL;
|
151
|
+
}
|
152
|
+
free(z);
|
153
|
+
return 0;
|
154
|
+
|
155
|
+
default:
|
156
|
+
;
|
157
|
+
}
|
158
|
+
|
159
|
+
return -1;
|
160
|
+
}
|
@@ -0,0 +1,71 @@
|
|
1
|
+
/*
|
2
|
+
$NiH: zip_source_file.c,v 1.1 2004/11/18 15:06:23 wiz Exp $
|
3
|
+
|
4
|
+
zip_source_file.c -- create data source from file
|
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 <errno.h>
|
39
|
+
#include <stdio.h>
|
40
|
+
|
41
|
+
#include "zip.h"
|
42
|
+
#include "zipint.h"
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
struct zip_source *
|
47
|
+
zip_source_file(struct zip *za, const char *fname, off_t start, off_t len)
|
48
|
+
{
|
49
|
+
struct zip_source *zs;
|
50
|
+
FILE *fp;
|
51
|
+
|
52
|
+
if (za == NULL)
|
53
|
+
return NULL;
|
54
|
+
|
55
|
+
if (fname == NULL || start < 0 || len < -1) {
|
56
|
+
_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
|
57
|
+
return NULL;
|
58
|
+
}
|
59
|
+
|
60
|
+
if ((fp=fopen(fname, "rb")) == NULL) {
|
61
|
+
_zip_error_set(&za->error, ZIP_ER_OPEN, errno);
|
62
|
+
return NULL;
|
63
|
+
}
|
64
|
+
|
65
|
+
if ((zs=zip_source_filep(za, fp, start, len)) == NULL) {
|
66
|
+
fclose(fp);
|
67
|
+
return NULL;
|
68
|
+
}
|
69
|
+
|
70
|
+
return zs;
|
71
|
+
}
|
@@ -0,0 +1,176 @@
|
|
1
|
+
/*
|
2
|
+
$NiH: zip_source_filep.c,v 1.6 2005/06/09 19:57:10 dillo Exp $
|
3
|
+
|
4
|
+
zip_source_filep.c -- create data source from FILE *
|
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 <sys/stat.h>
|
39
|
+
#include <errno.h>
|
40
|
+
#include <stdio.h>
|
41
|
+
#include <stdlib.h>
|
42
|
+
#include <string.h>
|
43
|
+
|
44
|
+
#include "zip.h"
|
45
|
+
#include "zipint.h"
|
46
|
+
|
47
|
+
struct read_file {
|
48
|
+
FILE *f; /* file to copy from */
|
49
|
+
off_t off; /* start offset of */
|
50
|
+
off_t len; /* lengt of data to copy */
|
51
|
+
off_t remain; /* bytes remaining to be copied */
|
52
|
+
int e[2]; /* error codes */
|
53
|
+
};
|
54
|
+
|
55
|
+
static ssize_t read_file(void *state, void *data, size_t len,
|
56
|
+
enum zip_source_cmd cmd);
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
struct zip_source *
|
61
|
+
zip_source_filep(struct zip *za, FILE *file, off_t start, off_t len)
|
62
|
+
{
|
63
|
+
struct read_file *f;
|
64
|
+
struct zip_source *zs;
|
65
|
+
|
66
|
+
if (za == NULL)
|
67
|
+
return NULL;
|
68
|
+
|
69
|
+
if (file == NULL || start < 0 || len < -1) {
|
70
|
+
_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
|
71
|
+
return NULL;
|
72
|
+
}
|
73
|
+
|
74
|
+
if ((f=(struct read_file *)malloc(sizeof(struct read_file))) == NULL) {
|
75
|
+
_zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
|
76
|
+
return NULL;
|
77
|
+
}
|
78
|
+
|
79
|
+
f->f = file;
|
80
|
+
f->off = start;
|
81
|
+
f->len = (len ? len : -1);
|
82
|
+
|
83
|
+
if ((zs=zip_source_function(za, read_file, f)) == NULL) {
|
84
|
+
free(f);
|
85
|
+
return NULL;
|
86
|
+
}
|
87
|
+
|
88
|
+
return zs;
|
89
|
+
}
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
static ssize_t
|
94
|
+
read_file(void *state, void *data, size_t len, enum zip_source_cmd cmd)
|
95
|
+
{
|
96
|
+
struct read_file *z;
|
97
|
+
char *buf;
|
98
|
+
int i, n;
|
99
|
+
|
100
|
+
z = (struct read_file *)state;
|
101
|
+
buf = (char *)data;
|
102
|
+
|
103
|
+
switch (cmd) {
|
104
|
+
case ZIP_SOURCE_OPEN:
|
105
|
+
if (fseeko(z->f, z->off, SEEK_SET) < 0) {
|
106
|
+
z->e[0] = ZIP_ER_SEEK;
|
107
|
+
z->e[1] = errno;
|
108
|
+
return -1;
|
109
|
+
}
|
110
|
+
z->remain = z->len;
|
111
|
+
return 0;
|
112
|
+
|
113
|
+
case ZIP_SOURCE_READ:
|
114
|
+
if (z->remain != -1)
|
115
|
+
n = len > z->remain ? z->remain : len;
|
116
|
+
else
|
117
|
+
n = len;
|
118
|
+
|
119
|
+
if ((i=fread(buf, 1, n, z->f)) < 0) {
|
120
|
+
z->e[0] = ZIP_ER_READ;
|
121
|
+
z->e[1] = errno;
|
122
|
+
return -1;
|
123
|
+
}
|
124
|
+
|
125
|
+
if (z->remain != -1)
|
126
|
+
z->remain -= i;
|
127
|
+
|
128
|
+
return i;
|
129
|
+
|
130
|
+
case ZIP_SOURCE_CLOSE:
|
131
|
+
return 0;
|
132
|
+
|
133
|
+
case ZIP_SOURCE_STAT:
|
134
|
+
{
|
135
|
+
struct zip_stat *st;
|
136
|
+
struct stat fst;
|
137
|
+
|
138
|
+
if (len < sizeof(*st))
|
139
|
+
return -1;
|
140
|
+
|
141
|
+
if (fstat(fileno(z->f), &fst) != 0) {
|
142
|
+
z->e[0] = ZIP_ER_READ; /* best match */
|
143
|
+
z->e[1] = errno;
|
144
|
+
return -1;
|
145
|
+
}
|
146
|
+
|
147
|
+
st = (struct zip_stat *)data;
|
148
|
+
|
149
|
+
zip_stat_init(st);
|
150
|
+
st->mtime = fst.st_mtime;
|
151
|
+
if (z->len != -1)
|
152
|
+
st->size = z->len;
|
153
|
+
else if ((fst.st_mode&S_IFMT) == S_IFREG)
|
154
|
+
st->size = fst.st_size;
|
155
|
+
|
156
|
+
return sizeof(*st);
|
157
|
+
}
|
158
|
+
|
159
|
+
case ZIP_SOURCE_ERROR:
|
160
|
+
if (len < sizeof(int)*2)
|
161
|
+
return -1;
|
162
|
+
|
163
|
+
memcpy(data, z->e, sizeof(int)*2);
|
164
|
+
return sizeof(int)*2;
|
165
|
+
|
166
|
+
case ZIP_SOURCE_FREE:
|
167
|
+
fclose(z->f);
|
168
|
+
free(z);
|
169
|
+
return 0;
|
170
|
+
|
171
|
+
default:
|
172
|
+
;
|
173
|
+
}
|
174
|
+
|
175
|
+
return -1;
|
176
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
/*
|
2
|
+
$NiH: zip_source_free.c,v 1.1 2004/11/18 15:06:24 wiz Exp $
|
3
|
+
|
4
|
+
zip_source_free.c -- free zip data source
|
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 <stdlib.h>
|
39
|
+
|
40
|
+
#include "zip.h"
|
41
|
+
#include "zipint.h"
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
void
|
46
|
+
zip_source_free(struct zip_source *source)
|
47
|
+
{
|
48
|
+
if (source == NULL)
|
49
|
+
return;
|
50
|
+
|
51
|
+
(void)source->f(source->ud, NULL, 0, ZIP_SOURCE_FREE);
|
52
|
+
|
53
|
+
free(source);
|
54
|
+
}
|
@@ -0,0 +1,62 @@
|
|
1
|
+
/*
|
2
|
+
$NiH: zip_source_function.c,v 1.3 2004/12/22 16:32:00 dillo Exp $
|
3
|
+
|
4
|
+
zip_source_function.c -- create zip data source from callback function
|
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 <stdlib.h>
|
39
|
+
|
40
|
+
#include "zip.h"
|
41
|
+
#include "zipint.h"
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
struct zip_source *
|
46
|
+
zip_source_function(struct zip *za, zip_source_callback zcb, void *ud)
|
47
|
+
{
|
48
|
+
struct zip_source *zs;
|
49
|
+
|
50
|
+
if (za == NULL)
|
51
|
+
return NULL;
|
52
|
+
|
53
|
+
if ((zs=(struct zip_source *)malloc(sizeof(*zs))) == NULL) {
|
54
|
+
_zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
|
55
|
+
return NULL;
|
56
|
+
}
|
57
|
+
|
58
|
+
zs->f = zcb;
|
59
|
+
zs->ud = ud;
|
60
|
+
|
61
|
+
return zs;
|
62
|
+
}
|