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
data/ext/mkstemp.c ADDED
@@ -0,0 +1,143 @@
1
+ /* $NiH: mkstemp.c,v 1.3 2006/04/23 14:51:45 wiz Exp $ */
2
+
3
+ /* Adapted from NetBSB libc by Dieter Baron */
4
+
5
+ /* NetBSD: gettemp.c,v 1.13 2003/12/05 00:57:36 uebayasi Exp */
6
+
7
+ /*
8
+ * Copyright (c) 1987, 1993
9
+ * The Regents of the University of California. All rights reserved.
10
+ *
11
+ * Redistribution and use in source and binary forms, with or without
12
+ * modification, are permitted provided that the following conditions
13
+ * are met:
14
+ * 1. Redistributions of source code must retain the above copyright
15
+ * notice, this list of conditions and the following disclaimer.
16
+ * 2. Redistributions in binary form must reproduce the above copyright
17
+ * notice, this list of conditions and the following disclaimer in the
18
+ * documentation and/or other materials provided with the distribution.
19
+ * 3. Neither the name of the University nor the names of its contributors
20
+ * may be used to endorse or promote products derived from this software
21
+ * without specific prior written permission.
22
+ *
23
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33
+ * SUCH DAMAGE.
34
+ */
35
+
36
+ #include <sys/types.h>
37
+ #include <sys/stat.h>
38
+
39
+ #include <assert.h>
40
+ #include <ctype.h>
41
+ #include <errno.h>
42
+ #include <fcntl.h>
43
+ #include <stdio.h>
44
+ #include <stdlib.h>
45
+
46
+ #ifdef _WIN32
47
+ #include <io.h>
48
+ #include <process.h>
49
+ #define getpid() _getpid()
50
+ typedef int pid_t;
51
+ #define S_ISDIR(m) (((m) & (_S_IFMT)) == (_S_IFDIR))
52
+ #define open(p, f, m) _open((p), ((f) | _O_BINARY), _S_IREAD | _S_IWRITE)
53
+ #endif
54
+
55
+ int
56
+ _zip_mkstemp(char *path)
57
+ {
58
+ int fd;
59
+ char *start, *trv;
60
+ struct stat sbuf;
61
+ pid_t pid;
62
+
63
+ /* To guarantee multiple calls generate unique names even if
64
+ the file is not created. 676 different possibilities with 7
65
+ or more X's, 26 with 6 or less. */
66
+ static char xtra[2] = "aa";
67
+ int xcnt = 0;
68
+
69
+ pid = getpid();
70
+
71
+ /* Move to end of path and count trailing X's. */
72
+ for (trv = path; *trv; ++trv)
73
+ if (*trv == 'X')
74
+ xcnt++;
75
+ else
76
+ xcnt = 0;
77
+
78
+ /* Use at least one from xtra. Use 2 if more than 6 X's. */
79
+ if (*(trv - 1) == 'X')
80
+ *--trv = xtra[0];
81
+ if (xcnt > 6 && *(trv - 1) == 'X')
82
+ *--trv = xtra[1];
83
+
84
+ /* Set remaining X's to pid digits with 0's to the left. */
85
+ while (*--trv == 'X') {
86
+ *trv = (pid % 10) + '0';
87
+ pid /= 10;
88
+ }
89
+
90
+ /* update xtra for next call. */
91
+ if (xtra[0] != 'z')
92
+ xtra[0]++;
93
+ else {
94
+ xtra[0] = 'a';
95
+ if (xtra[1] != 'z')
96
+ xtra[1]++;
97
+ else
98
+ xtra[1] = 'a';
99
+ }
100
+
101
+ /*
102
+ * check the target directory; if you have six X's and it
103
+ * doesn't exist this runs for a *very* long time.
104
+ */
105
+ for (start = trv + 1;; --trv) {
106
+ if (trv <= path)
107
+ break;
108
+ if (*trv == '/') {
109
+ *trv = '\0';
110
+ if (stat(path, &sbuf))
111
+ return (0);
112
+ if (!S_ISDIR(sbuf.st_mode)) {
113
+ errno = ENOTDIR;
114
+ return (0);
115
+ }
116
+ *trv = '/';
117
+ break;
118
+ }
119
+ }
120
+
121
+ for (;;) {
122
+ if ((fd = open(path, O_CREAT | O_EXCL | O_RDWR, 0600)) >= 0)
123
+ return (fd);
124
+ if (errno != EEXIST)
125
+ return (0);
126
+
127
+ /* tricky little algorithm for backward compatibility */
128
+ for (trv = start;;) {
129
+ if (!*trv)
130
+ return (0);
131
+ if (*trv == 'z')
132
+ *trv++ = 'a';
133
+ else {
134
+ if (isdigit((unsigned char)*trv))
135
+ *trv = 'a';
136
+ else
137
+ ++*trv;
138
+ break;
139
+ }
140
+ }
141
+ }
142
+ /*NOTREACHED*/
143
+ }
data/ext/zip.h ADDED
@@ -0,0 +1,211 @@
1
+ #ifndef _HAD_ZIP_H
2
+ #define _HAD_ZIP_H
3
+
4
+ /*
5
+ $NiH: zip.h,v 1.59 2006/10/04 15:21:09 dillo Exp $
6
+
7
+ zip.h -- exported declarations.
8
+ Copyright (C) 1999-2006 Dieter Baron and Thomas Klausner
9
+
10
+ This file is part of libzip, a library to manipulate ZIP archives.
11
+ The authors can be contacted at <nih@giga.or.at>
12
+
13
+ Redistribution and use in source and binary forms, with or without
14
+ modification, are permitted provided that the following conditions
15
+ are met:
16
+ 1. Redistributions of source code must retain the above copyright
17
+ notice, this list of conditions and the following disclaimer.
18
+ 2. Redistributions in binary form must reproduce the above copyright
19
+ notice, this list of conditions and the following disclaimer in
20
+ the documentation and/or other materials provided with the
21
+ distribution.
22
+ 3. The names of the authors may not be used to endorse or promote
23
+ products derived from this software without specific prior
24
+ written permission.
25
+
26
+ THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
27
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
30
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
32
+ GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
34
+ IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
35
+ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
36
+ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
+ */
38
+
39
+
40
+
41
+ #ifdef __cplusplus
42
+ extern "C" {
43
+ #endif
44
+
45
+ #include <sys/types.h>
46
+ #include <stdio.h>
47
+ #include <time.h>
48
+
49
+ #ifdef _WIN32
50
+ typedef int ssize_t;
51
+ #endif
52
+
53
+ /* flags for zip_open */
54
+
55
+ #define ZIP_CREATE 1
56
+ #define ZIP_EXCL 2
57
+ #define ZIP_CHECKCONS 4
58
+
59
+
60
+ /* flags for zip_name_locate, zip_fopen, zip_stat, ... */
61
+
62
+ #define ZIP_FL_NOCASE 1 /* ignore case on name lookup */
63
+ #define ZIP_FL_NODIR 2 /* ignore directory component */
64
+ #define ZIP_FL_COMPRESSED 4 /* read compressed data */
65
+ #define ZIP_FL_UNCHANGED 8 /* use original data, ignoring changes */
66
+
67
+ /* libzip error codes */
68
+
69
+ #define ZIP_ER_OK 0 /* N No error */
70
+ #define ZIP_ER_MULTIDISK 1 /* N Multi-disk zip archives not supported */
71
+ #define ZIP_ER_RENAME 2 /* S Renaming temporary file failed */
72
+ #define ZIP_ER_CLOSE 3 /* S Closing zip archive failed */
73
+ #define ZIP_ER_SEEK 4 /* S Seek error */
74
+ #define ZIP_ER_READ 5 /* S Read error */
75
+ #define ZIP_ER_WRITE 6 /* S Write error */
76
+ #define ZIP_ER_CRC 7 /* N CRC error */
77
+ #define ZIP_ER_ZIPCLOSED 8 /* N Containing zip archive was closed */
78
+ #define ZIP_ER_NOENT 9 /* N No such file */
79
+ #define ZIP_ER_EXISTS 10 /* N File already exists */
80
+ #define ZIP_ER_OPEN 11 /* S Can't open file */
81
+ #define ZIP_ER_TMPOPEN 12 /* S Failure to create temporary file */
82
+ #define ZIP_ER_ZLIB 13 /* Z Zlib error */
83
+ #define ZIP_ER_MEMORY 14 /* N Malloc failure */
84
+ #define ZIP_ER_CHANGED 15 /* N Entry has been changed */
85
+ #define ZIP_ER_COMPNOTSUPP 16 /* N Compression method not supported */
86
+ #define ZIP_ER_EOF 17 /* N Premature EOF */
87
+ #define ZIP_ER_INVAL 18 /* N Invalid argument */
88
+ #define ZIP_ER_NOZIP 19 /* N Not a zip archive */
89
+ #define ZIP_ER_INTERNAL 20 /* N Internal error */
90
+ #define ZIP_ER_INCONS 21 /* N Zip archive inconsistent */
91
+ #define ZIP_ER_REMOVE 22 /* S Can't remove file */
92
+ #define ZIP_ER_DELETED 23 /* N Entry has been deleted */
93
+
94
+
95
+ /* type of system error value */
96
+
97
+ #define ZIP_ET_NONE 0 /* sys_err unused */
98
+ #define ZIP_ET_SYS 1 /* sys_err is errno */
99
+ #define ZIP_ET_ZLIB 2 /* sys_err is zlib error code */
100
+
101
+ /* compression methods */
102
+
103
+ #define ZIP_CM_DEFAULT -1 /* better of deflate or store */
104
+ #define ZIP_CM_STORE 0 /* stored (uncompressed) */
105
+ #define ZIP_CM_SHRINK 1 /* shrunk */
106
+ #define ZIP_CM_REDUCE_1 2 /* reduced with factor 1 */
107
+ #define ZIP_CM_REDUCE_2 3 /* reduced with factor 2 */
108
+ #define ZIP_CM_REDUCE_3 4 /* reduced with factor 3 */
109
+ #define ZIP_CM_REDUCE_4 5 /* reduced with factor 4 */
110
+ #define ZIP_CM_IMPLODE 6 /* imploded */
111
+ /* 7 - Reserved for Tokenizing compression algorithm */
112
+ #define ZIP_CM_DEFLATE 8 /* deflated */
113
+ #define ZIP_CM_DEFLATE64 9 /* deflate64 */
114
+ #define ZIP_CM_PKWARE_IMPLODE 10 /* PKWARE imploding */
115
+ /* 11 - Reserved by PKWARE */
116
+ #define ZIP_CM_BZIP2 12 /* compressed using BZIP2 algorithm */
117
+
118
+ /* encryption methods */
119
+
120
+ #define ZIP_EM_NONE 0 /* not encrypted */
121
+ #define ZIP_EM_TRAD_PKWARE 1 /* traditional PKWARE encryption */
122
+ #if 0 /* Strong Encryption Header not parsed yet */
123
+ #define ZIP_EM_DES 0x6601 /* strong encryption: DES */
124
+ #define ZIP_EM_RC2_OLD 0x6602 /* strong encryption: RC2, version < 5.2 */
125
+ #define ZIP_EM_3DES_168 0x6603
126
+ #define ZIP_EM_3DES_112 0x6609
127
+ #define ZIP_EM_AES_128 0x660e
128
+ #define ZIP_EM_AES_192 0x660f
129
+ #define ZIP_EM_AES_256 0x6610
130
+ #define ZIP_EM_RC2 0x6702 /* strong encryption: RC2, version >= 5.2 */
131
+ #define ZIP_EM_RC4 0x6801
132
+ #endif
133
+ #define ZIP_EM_UNKNOWN 0xffff /* unknown algorithm */
134
+
135
+
136
+
137
+ enum zip_source_cmd {
138
+ ZIP_SOURCE_OPEN, /* prepare for reading */
139
+ ZIP_SOURCE_READ, /* read data */
140
+ ZIP_SOURCE_CLOSE, /* reading is done */
141
+ ZIP_SOURCE_STAT, /* get meta information */
142
+ ZIP_SOURCE_ERROR, /* get error information */
143
+ ZIP_SOURCE_FREE /* cleanup and free resources */
144
+ };
145
+
146
+ typedef ssize_t (*zip_source_callback)(void *state, void *data,
147
+ size_t len, enum zip_source_cmd cmd);
148
+
149
+ struct zip_stat {
150
+ const char *name; /* name of the file */
151
+ int index; /* index within archive */
152
+ unsigned int crc; /* crc of file data */
153
+ time_t mtime; /* modification time */
154
+ off_t size; /* size of file (uncompressed) */
155
+ off_t comp_size; /* size of file (compressed) */
156
+ unsigned short comp_method; /* compression method used */
157
+ unsigned short encryption_method; /* encryption method used */
158
+ };
159
+
160
+ struct zip;
161
+ struct zip_file;
162
+ struct zip_source;
163
+
164
+
165
+
166
+ int zip_add(struct zip *, const char *, struct zip_source *);
167
+ int zip_add_dir(struct zip *, const char *);
168
+ int zip_close(struct zip *);
169
+ int zip_delete(struct zip *, int);
170
+ void zip_error_clear(struct zip *);
171
+ void zip_error_get(struct zip *, int *, int *);
172
+ int zip_error_get_sys_type(int);
173
+ int zip_error_to_str(char *, size_t, int, int);
174
+ int zip_fclose(struct zip_file *);
175
+ void zip_file_error_clear(struct zip_file *);
176
+ void zip_file_error_get(struct zip_file *, int *, int *);
177
+ const char *zip_file_strerror(struct zip_file *);
178
+ struct zip_file *zip_fopen(struct zip *, const char *, int);
179
+ struct zip_file *zip_fopen_index(struct zip *, int, int);
180
+ ssize_t zip_fread(struct zip_file *, void *, size_t);
181
+ const char *zip_get_archive_comment(struct zip *, int *, int);
182
+ const char *zip_get_file_comment(struct zip *, int, int *, int);
183
+ const char *zip_get_name(struct zip *, int, int);
184
+ int zip_get_num_files(struct zip *);
185
+ int zip_name_locate(struct zip *, const char *, int);
186
+ struct zip *zip_open(const char *, int, int *);
187
+ int zip_rename(struct zip *, int, const char *);
188
+ int zip_replace(struct zip *, int, struct zip_source *);
189
+ int zip_set_archive_comment(struct zip *, const char *, int);
190
+ int zip_set_file_comment(struct zip *, int, const char *, int);
191
+ struct zip_source *zip_source_buffer(struct zip *, const void *, off_t, int);
192
+ struct zip_source *zip_source_file(struct zip *, const char *, off_t, off_t);
193
+ struct zip_source *zip_source_filep(struct zip *, FILE *, off_t, off_t);
194
+ void zip_source_free(struct zip_source *);
195
+ struct zip_source *zip_source_function(struct zip *,
196
+ zip_source_callback, void *);
197
+ struct zip_source *zip_source_zip(struct zip *, struct zip *, int, int,
198
+ off_t, off_t);
199
+ int zip_stat(struct zip *, const char *, int, struct zip_stat *);
200
+ int zip_stat_index(struct zip *, int, int, struct zip_stat *);
201
+ void zip_stat_init(struct zip_stat *);
202
+ const char *zip_strerror(struct zip *);
203
+ int zip_unchange(struct zip *, int);
204
+ int zip_unchange_all(struct zip *);
205
+ int zip_unchange_archive(struct zip *);
206
+
207
+ #ifdef __cplusplus
208
+ }
209
+ #endif
210
+
211
+ #endif /* _HAD_ZIP_H */
data/ext/zip_add.c ADDED
@@ -0,0 +1,52 @@
1
+ /*
2
+ $NiH: zip_add.c,v 1.13 2004/11/17 21:55:09 wiz Exp $
3
+
4
+ zip_add.c -- add file via 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 "zip.h"
39
+ #include "zipint.h"
40
+
41
+
42
+
43
+ int
44
+ zip_add(struct zip *za, const char *name, struct zip_source *source)
45
+ {
46
+ if (name == NULL || source == NULL) {
47
+ _zip_error_set(&za->error, ZIP_ER_INVAL, 0);
48
+ return -1;
49
+ }
50
+
51
+ return _zip_replace(za, -1, name, source);
52
+ }
data/ext/zip_add_dir.c ADDED
@@ -0,0 +1,83 @@
1
+ /*
2
+ $NiH: zip_add.c,v 1.14 2004/11/18 15:04:04 wiz Exp $
3
+
4
+ zip_add_dir.c -- add directory
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
+
45
+
46
+ int
47
+ zip_add_dir(struct zip *za, const char *name)
48
+ {
49
+ int len, ret;
50
+ char *s;
51
+ struct zip_source *source;
52
+
53
+ if (name == NULL) {
54
+ _zip_error_set(&za->error, ZIP_ER_INVAL, 0);
55
+ return -1;
56
+ }
57
+
58
+ s = NULL;
59
+ len = strlen(name);
60
+
61
+ if (name[len-1] != '/') {
62
+ if ((s=(char *)malloc(len+2)) == NULL) {
63
+ _zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
64
+ return -1;
65
+ }
66
+ strcpy(s, name);
67
+ s[len] = '/';
68
+ s[len+1] = '\0';
69
+ }
70
+
71
+ if ((source=zip_source_buffer(za, NULL, 0, 0)) == NULL) {
72
+ free(s);
73
+ return -1;
74
+ }
75
+
76
+ ret = _zip_replace(za, -1, s ? s : name, source);
77
+
78
+ free(s);
79
+ if (ret < 0)
80
+ zip_source_free(source);
81
+
82
+ return ret;
83
+ }