libarchive 0.1.0-mswin32

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,138 @@
1
+ = Libarchive/Ruby
2
+
3
+ Copyright (c) 2009 SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
4
+
5
+ == Description
6
+
7
+ Ruby bindings for Libarchive.
8
+
9
+ Libarchive is a programming library that can create and read several different streaming archive formats, including most popular tar variants, several cpio formats, and both BSD and GNU ar variants.
10
+
11
+ == Support archive (from Libarchive 2.6.0)
12
+ === reading
13
+ * gzip compression
14
+ * bzip2 compression
15
+ * compress/LZW compression
16
+ * GNU tar format (including GNU long filenames, long link names, and
17
+ sparse files)
18
+ * Solaris 9 extended tar format (including ACLs)
19
+ * Old V7 tar archives
20
+ * POSIX ustar
21
+ * POSIX pax interchange format
22
+ * POSIX octet-oriented cpio
23
+ * SVR4 ASCII cpio
24
+ * Binary cpio (big-endian or little-endian)
25
+ * ISO9660 CD-ROM images (with optional Rockridge extensions)
26
+ * ZIP archives (with uncompressed or "deflate" compressed entries)
27
+ * GNU and BSD 'ar' archives
28
+ * 'mtree' format
29
+ * lzma compression not supported
30
+
31
+ === writing
32
+ * gzip compression
33
+ * bzip2 compression
34
+ * compress/LZW compression
35
+ * POSIX ustar
36
+ * POSIX pax interchange format
37
+ * "restricted" pax format, which will create ustar archives except for entries that require pax extensions (for long filenames, etc).
38
+ * ACLs not supported
39
+ * POSIX octet-oriented cpio
40
+ * SVR4 "newc" cpio
41
+ * shar archives
42
+ * GNU and BSD 'ar' archives
43
+
44
+ == Project Page
45
+
46
+ http://rubyforge.org/projects/libarchive
47
+
48
+ == Source Code
49
+
50
+ http://coderepos.org/share/browser/lang/ruby/libarchive/trunk/
51
+
52
+ == Dependency
53
+
54
+ Libarchive/Ruby depend on Libarchive.
55
+
56
+ Please install Libarchive. (version 2.6.0 or more is recommended)
57
+
58
+ == Install
59
+
60
+ gem install libarchive
61
+
62
+ == Example
63
+ === reading archive
64
+ require 'libarchive_ruby'
65
+
66
+ Archive::Reader.open_filename('foo.tar.gz') do |ar|
67
+ while entry = ar.next_header
68
+ name = entry.pathname
69
+ data = ar.read_data
70
+
71
+ #data = ""
72
+ #ar.read_data(1024) do |x|
73
+ # data << x
74
+ #end
75
+
76
+ puts "#{name} (size=#{data.size})"
77
+ end
78
+ end
79
+
80
+ === creating archive
81
+ require 'libarchive_ruby'
82
+ include Archive
83
+
84
+ Writer.open_filename('foo.tar.bz2', COMPRESSION_BZIP2, FORMAT_TAR_USTAR) do |ar|
85
+ Dir.glob('*.c').each do |fn|
86
+ ar.new_entry do |entry|
87
+ entry.copy_stat(fn)
88
+ entry.pathname = fn
89
+ ar.write_header(entry)
90
+ ar.write_data(open(fn) {|f| f.read })
91
+
92
+ #open(fn) do |f|
93
+ # ar.write_data do
94
+ # f.read(1024)
95
+ # end
96
+ #end
97
+ end
98
+ end
99
+ end
100
+
101
+ Reader.open_filename('foo.zip') do |ar|
102
+ while entry = ar.next_header
103
+ p entry.pathname
104
+ p ar.read_data.size
105
+ end
106
+ end
107
+
108
+ == License
109
+ Copyright (c) 2009 SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
110
+ All rights reserved.
111
+
112
+ Redistribution and use in source and binary forms, with or without modification,
113
+ are permitted provided that the following conditions are met:
114
+
115
+ * Redistributions of source code must retain the above copyright notice,
116
+ this list of conditions and the following disclaimer.
117
+ * Redistributions in binary form must reproduce the above copyright notice,
118
+ this list of conditions and the following disclaimer in the documentation
119
+ and/or other materials provided with the distribution.
120
+ * The names of its contributors may be used to endorse or promote products
121
+ derived from this software without specific prior written permission.
122
+
123
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
124
+ ANY EXPRESS OR IMPLIED WARRANTIES,
125
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
126
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
127
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
128
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
129
+ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
130
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
131
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
132
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
133
+ DAMAGE.
134
+
135
+ === Libarchive
136
+ Libarchive/Ruby(mswin32) contains Libarchive 2.6.0.
137
+ * http://people.freebsd.org/~kientzle/libarchive/
138
+ * see {COPYING.libarchive}[link:files/COPYING_libarchive.html]
@@ -0,0 +1,1724 @@
1
+ #include "libarchive_internal.h"
2
+
3
+ VALUE rb_mArchive;
4
+ VALUE rb_eArchiveError;
5
+
6
+ /* */
7
+ VALUE rb_libarchive_s_version_number(VALUE self) {
8
+ #if ARCHIVE_VERSION >= 2005000
9
+ return INT2NUM(archive_version_number());
10
+ #else
11
+ return INT2NUM(archive_version_stamp());
12
+ #endif
13
+ }
14
+
15
+ /* */
16
+ VALUE rb_libarchive_s_version_string(VALUE self) {
17
+ #if ARCHIVE_VERSION_NUMBER >= 2005000
18
+ return rb_str_new2(archive_version_string());
19
+ #else
20
+ return rb_str_new2(archive_version());
21
+ #endif
22
+ }
23
+
24
+ void DLLEXPORT Init_libarchive_ruby() {
25
+ rb_mArchive = rb_define_module("Archive");
26
+ rb_define_const(rb_mArchive, "VERSION", rb_str_new2(VERSION));
27
+
28
+ rb_define_const(rb_mArchive, "COMPRESSION_NONE", INT2NUM(ARCHIVE_COMPRESSION_NONE));
29
+ rb_define_const(rb_mArchive, "COMPRESSION_GZIP", INT2NUM(ARCHIVE_COMPRESSION_GZIP));
30
+ rb_define_const(rb_mArchive, "COMPRESSION_BZIP2", INT2NUM(ARCHIVE_COMPRESSION_BZIP2));
31
+ rb_define_const(rb_mArchive, "COMPRESSION_COMPRESS", INT2NUM(ARCHIVE_COMPRESSION_COMPRESS));
32
+ // XXX:
33
+ /*
34
+ rb_define_const(rb_mArchive, "COMPRESSION_PROGRAM", INT2NUM(ARCHIVE_COMPRESSION_PROGRAM));
35
+ rb_define_const(rb_mArchive, "COMPRESSION_LZMA", INT2NUM(ARCHIVE_COMPRESSION_LZMA));
36
+ */
37
+
38
+ rb_define_const(rb_mArchive, "FORMAT_BASE_MASK", INT2NUM(ARCHIVE_FORMAT_BASE_MASK));
39
+ rb_define_const(rb_mArchive, "FORMAT_CPIO", INT2NUM(ARCHIVE_FORMAT_CPIO));
40
+ rb_define_const(rb_mArchive, "FORMAT_CPIO_POSIX", INT2NUM(ARCHIVE_FORMAT_CPIO_POSIX));
41
+ rb_define_const(rb_mArchive, "FORMAT_CPIO_BIN_LE", INT2NUM(ARCHIVE_FORMAT_CPIO_BIN_LE));
42
+ rb_define_const(rb_mArchive, "FORMAT_CPIO_BIN_BE", INT2NUM(ARCHIVE_FORMAT_CPIO_BIN_BE));
43
+ rb_define_const(rb_mArchive, "FORMAT_CPIO_SVR4_NOCRC", INT2NUM(ARCHIVE_FORMAT_CPIO_SVR4_NOCRC));
44
+ rb_define_const(rb_mArchive, "FORMAT_CPIO_SVR4_CRC", INT2NUM(ARCHIVE_FORMAT_CPIO_SVR4_CRC));
45
+ rb_define_const(rb_mArchive, "FORMAT_SHAR", INT2NUM(ARCHIVE_FORMAT_SHAR));
46
+ rb_define_const(rb_mArchive, "FORMAT_SHAR_BASE", INT2NUM(ARCHIVE_FORMAT_SHAR_BASE));
47
+ rb_define_const(rb_mArchive, "FORMAT_SHAR_DUMP", INT2NUM(ARCHIVE_FORMAT_SHAR_DUMP));
48
+ rb_define_const(rb_mArchive, "FORMAT_TAR", INT2NUM(ARCHIVE_FORMAT_TAR));
49
+ rb_define_const(rb_mArchive, "FORMAT_TAR_USTAR", INT2NUM(ARCHIVE_FORMAT_TAR_USTAR));
50
+ rb_define_const(rb_mArchive, "FORMAT_TAR_PAX_INTERCHANGE", INT2NUM(ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE));
51
+ rb_define_const(rb_mArchive, "FORMAT_TAR_PAX_RESTRICTED", INT2NUM(ARCHIVE_FORMAT_TAR_PAX_RESTRICTED));
52
+ rb_define_const(rb_mArchive, "FORMAT_TAR_GNUTAR", INT2NUM(ARCHIVE_FORMAT_TAR_GNUTAR));
53
+ rb_define_const(rb_mArchive, "FORMAT_ISO9660", INT2NUM(ARCHIVE_FORMAT_ISO9660));
54
+ rb_define_const(rb_mArchive, "FORMAT_ISO9660_ROCKRIDGE", INT2NUM(ARCHIVE_FORMAT_ISO9660_ROCKRIDGE));
55
+ rb_define_const(rb_mArchive, "FORMAT_ZIP", INT2NUM(ARCHIVE_FORMAT_ZIP));
56
+ rb_define_const(rb_mArchive, "FORMAT_EMPTY", INT2NUM(ARCHIVE_FORMAT_EMPTY));
57
+ rb_define_const(rb_mArchive, "FORMAT_AR", INT2NUM(ARCHIVE_FORMAT_AR));
58
+ rb_define_const(rb_mArchive, "FORMAT_AR_GNU", INT2NUM(ARCHIVE_FORMAT_AR_GNU));
59
+ rb_define_const(rb_mArchive, "FORMAT_AR_BSD", INT2NUM(ARCHIVE_FORMAT_AR_BSD));
60
+ #ifdef ARCHIVE_FORMAT_MTREE
61
+ rb_define_const(rb_mArchive, "FORMAT_MTREE", INT2NUM(ARCHIVE_FORMAT_MTREE));
62
+ #endif
63
+
64
+ rb_define_const(rb_mArchive, "EXTRACT_OWNER", INT2NUM(ARCHIVE_EXTRACT_OWNER));
65
+ rb_define_const(rb_mArchive, "EXTRACT_PERM", INT2NUM(ARCHIVE_EXTRACT_PERM));
66
+ rb_define_const(rb_mArchive, "EXTRACT_TIME", INT2NUM(ARCHIVE_EXTRACT_TIME));
67
+ rb_define_const(rb_mArchive, "EXTRACT_NO_OVERWRITE", INT2NUM(ARCHIVE_EXTRACT_NO_OVERWRITE));
68
+ rb_define_const(rb_mArchive, "EXTRACT_UNLINK", INT2NUM(ARCHIVE_EXTRACT_UNLINK));
69
+ rb_define_const(rb_mArchive, "EXTRACT_ACL", INT2NUM(ARCHIVE_EXTRACT_ACL));
70
+ rb_define_const(rb_mArchive, "EXTRACT_FFLAGS", INT2NUM(ARCHIVE_EXTRACT_FFLAGS));
71
+ rb_define_const(rb_mArchive, "EXTRACT_XATTR", INT2NUM(ARCHIVE_EXTRACT_XATTR));
72
+ rb_define_const(rb_mArchive, "EXTRACT_SECURE_SYMLINKS", INT2NUM(ARCHIVE_EXTRACT_SECURE_SYMLINKS));
73
+ rb_define_const(rb_mArchive, "EXTRACT_SECURE_NODOTDOT", INT2NUM(ARCHIVE_EXTRACT_SECURE_NODOTDOT));
74
+ rb_define_const(rb_mArchive, "EXTRACT_NO_AUTODIR", INT2NUM(ARCHIVE_EXTRACT_NO_AUTODIR));
75
+ rb_define_const(rb_mArchive, "EXTRACT_NO_OVERWRITE_NEWER", INT2NUM(ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER));
76
+ #ifdef ARCHIVE_EXTRACT_SPARSE
77
+ rb_define_const(rb_mArchive, "EXTRACT_SPARSE", INT2NUM(ARCHIVE_EXTRACT_SPARSE));
78
+ #endif
79
+
80
+ rb_define_module_function(rb_mArchive, "version_number", rb_libarchive_s_version_number, 0);
81
+ rb_define_module_function(rb_mArchive, "version_string", rb_libarchive_s_version_string, 0);
82
+
83
+ rb_eArchiveError = rb_define_class_under(rb_mArchive, "Error", rb_eStandardError);
84
+
85
+ Init_libarchive_reader();
86
+ Init_libarchive_writer();
87
+ Init_libarchive_archive();
88
+ Init_libarchive_entry();
89
+ }
90
+ #include "libarchive_internal.h"
91
+
92
+ extern VALUE rb_cArchiveReader;
93
+ extern VALUE rb_cArchiveWriter;
94
+ extern VALUE rb_eArchiveError;
95
+
96
+ static void rb_libarchive_archive_free(struct rb_libarchive_archive_container *p) {
97
+ xfree(p);
98
+ }
99
+
100
+ static void rb_libarchive_archive_mark(struct rb_libarchive_archive_container *p) {
101
+ rb_gc_mark(p->memory);
102
+ }
103
+
104
+ VALUE rb_libarchive_archive_alloc(VALUE klass) {
105
+ struct rb_libarchive_archive_container *p = ALLOC(struct rb_libarchive_archive_container);
106
+ p->ar = NULL;
107
+ p->eof = 0;
108
+ p->memory = Qnil;
109
+ return Data_Wrap_Struct(klass, rb_libarchive_archive_mark, rb_libarchive_archive_free, p);
110
+ }
111
+
112
+ /* */
113
+ static VALUE rb_libarchive_archive_position_compressed(VALUE self) {
114
+ struct rb_libarchive_archive_container *p;
115
+ Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
116
+ Check_Archive(p);
117
+ return LL2NUM(archive_position_compressed(p->ar));
118
+ }
119
+
120
+ /* */
121
+ static VALUE rb_libarchive_archive_position_uncompressed(VALUE self) {
122
+ struct rb_libarchive_archive_container *p;
123
+ Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
124
+ Check_Archive(p);
125
+ return LL2NUM(archive_position_uncompressed(p->ar));
126
+ }
127
+
128
+ /* */
129
+ static VALUE rb_libarchive_archive_compression_name(VALUE self) {
130
+ struct rb_libarchive_archive_container *p;
131
+ Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
132
+ Check_Archive(p);
133
+ return rb_str_new2(archive_compression_name(p->ar));
134
+ }
135
+
136
+ /* */
137
+ static VALUE rb_libarchive_archive_compression(VALUE self) {
138
+ struct rb_libarchive_archive_container *p;
139
+ Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
140
+ Check_Archive(p);
141
+ return INT2NUM(archive_compression(p->ar));
142
+ }
143
+
144
+ /* */
145
+ static VALUE rb_libarchive_archive_format_name(VALUE self) {
146
+ struct rb_libarchive_archive_container *p;
147
+ Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
148
+ Check_Archive(p);
149
+ return rb_str_new2(archive_format_name(p->ar));
150
+ }
151
+
152
+ /* */
153
+ static VALUE rb_libarchive_archive_format(VALUE self) {
154
+ struct rb_libarchive_archive_container *p;
155
+ Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
156
+ Check_Archive(p);
157
+ return NUM2INT(archive_format(p->ar));
158
+ }
159
+
160
+ void Init_libarchive_archive() {
161
+ rb_define_method(rb_cArchiveReader, "position_compressed", rb_libarchive_archive_position_compressed, 0);
162
+ rb_define_method(rb_cArchiveWriter, "position_compressed", rb_libarchive_archive_position_compressed, 0);
163
+ rb_define_method(rb_cArchiveReader, "position_uncompressed", rb_libarchive_archive_position_uncompressed, 0);
164
+ rb_define_method(rb_cArchiveWriter, "position_uncompressed", rb_libarchive_archive_position_uncompressed, 0);
165
+ rb_define_method(rb_cArchiveReader, "compression_name", rb_libarchive_archive_compression_name, 0);
166
+ rb_define_method(rb_cArchiveWriter, "compression_name", rb_libarchive_archive_compression_name, 0);
167
+ rb_define_method(rb_cArchiveReader, "compression", rb_libarchive_archive_compression, 0);
168
+ rb_define_method(rb_cArchiveWriter, "compression", rb_libarchive_archive_compression, 0);
169
+ rb_define_method(rb_cArchiveReader, "format_name", rb_libarchive_archive_format_name, 0);
170
+ rb_define_method(rb_cArchiveWriter, "format_name", rb_libarchive_archive_format_name, 0);
171
+ rb_define_method(rb_cArchiveReader, "format", rb_libarchive_archive_format, 0);
172
+ rb_define_method(rb_cArchiveWriter, "format", rb_libarchive_archive_format, 0);
173
+ }
174
+ #include "libarchive_internal.h"
175
+
176
+ extern VALUE rb_mArchive;
177
+ VALUE rb_cArchiveEntry;
178
+ extern VALUE rb_eArchiveError;
179
+
180
+ static void rb_libarchive_entry_free(struct rb_libarchive_entry_container *p) {
181
+ xfree(p);
182
+ }
183
+
184
+ static VALUE rb_libarchive_entry_alloc(VALUE klass) {
185
+ struct rb_libarchive_entry_container *p = ALLOC(struct rb_libarchive_entry_container);
186
+ p->ae = NULL;
187
+ p->must_close = 1;
188
+ return Data_Wrap_Struct(klass, 0, rb_libarchive_entry_free, p);
189
+ }
190
+
191
+ /* */
192
+ VALUE rb_libarchive_entry_close(VALUE self) {
193
+ struct rb_libarchive_entry_container *p;
194
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
195
+ Check_Entry(p);
196
+
197
+ if (!p->must_close) {
198
+ rb_raise(rb_eArchiveError, "Close entry failed: It is not necessary to close");
199
+ }
200
+
201
+ archive_entry_free(p->ae);
202
+ p->ae = NULL;
203
+ return Qnil;
204
+ }
205
+
206
+ VALUE rb_libarchive_entry_new(struct archive_entry *ae, int must_close) {
207
+ VALUE entry;
208
+ struct rb_libarchive_entry_container *p;
209
+ entry = rb_funcall(rb_cArchiveEntry, rb_intern("new"), 0);
210
+ Data_Get_Struct(entry, struct rb_libarchive_entry_container, p);
211
+ p->ae = ae;
212
+ p->must_close = must_close;
213
+ return entry;
214
+ }
215
+
216
+ /* */
217
+ static VALUE rb_libarchive_entry_atime(VALUE self) {
218
+ struct rb_libarchive_entry_container *p;
219
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
220
+ Check_Entry(p);
221
+ return LONG2TIME((long) archive_entry_atime(p->ae));
222
+ }
223
+
224
+ /* */
225
+ static VALUE rb_libarchive_entry_atime_nsec(VALUE self) {
226
+ struct rb_libarchive_entry_container *p;
227
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
228
+ Check_Entry(p);
229
+ return LONG2NUM(archive_entry_atime_nsec(p->ae));
230
+ }
231
+
232
+ /* */
233
+ static VALUE rb_libarchive_entry_atime_is_set(VALUE self) {
234
+ struct rb_libarchive_entry_container *p;
235
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
236
+ Check_Entry(p);
237
+ return archive_entry_atime_is_set(p->ae) ? Qtrue : Qfalse;
238
+ }
239
+
240
+ /* */
241
+ static VALUE rb_libarchive_entry_birthtime(VALUE self) {
242
+ struct rb_libarchive_entry_container *p;
243
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
244
+ Check_Entry(p);
245
+ return LONG2TIME((long) archive_entry_birthtime(p->ae));
246
+ }
247
+
248
+ /* */
249
+ static VALUE rb_libarchive_entry_birthtime_nsec(VALUE self) {
250
+ struct rb_libarchive_entry_container *p;
251
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
252
+ Check_Entry(p);
253
+ return LONG2NUM(archive_entry_birthtime_nsec(p->ae));
254
+ }
255
+
256
+ /* */
257
+ static VALUE rb_libarchive_entry_birthtime_is_set(VALUE self) {
258
+ struct rb_libarchive_entry_container *p;
259
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
260
+ Check_Entry(p);
261
+ return archive_entry_birthtime_is_set(p->ae) ? Qtrue : Qfalse;
262
+ }
263
+
264
+ /* */
265
+ static VALUE rb_libarchive_entry_ctime(VALUE self) {
266
+ struct rb_libarchive_entry_container *p;
267
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
268
+ Check_Entry(p);
269
+ return LONG2TIME((long) archive_entry_ctime(p->ae));
270
+ }
271
+
272
+ /* */
273
+ static VALUE rb_libarchive_entry_ctime_nsec(VALUE self) {
274
+ struct rb_libarchive_entry_container *p;
275
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
276
+ Check_Entry(p);
277
+ return LONG2NUM(archive_entry_ctime_nsec(p->ae));
278
+ }
279
+
280
+ /* */
281
+ static VALUE rb_libarchive_entry_ctime_is_set(VALUE self) {
282
+ struct rb_libarchive_entry_container *p;
283
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
284
+ Check_Entry(p);
285
+ return archive_entry_ctime_is_set(p->ae) ? Qtrue : Qfalse;
286
+ }
287
+
288
+ /* */
289
+ static VALUE rb_libarchive_entry_dev(VALUE self) {
290
+ struct rb_libarchive_entry_container *p;
291
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
292
+ Check_Entry(p);
293
+ return LONG2NUM(archive_entry_dev(p->ae));
294
+ }
295
+
296
+ /* */
297
+ static VALUE rb_libarchive_entry_devmajor(VALUE self) {
298
+ struct rb_libarchive_entry_container *p;
299
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
300
+ Check_Entry(p);
301
+ return LONG2NUM(archive_entry_devmajor(p->ae));
302
+ }
303
+
304
+ /* */
305
+ static VALUE rb_libarchive_entry_devminor(VALUE self) {
306
+ struct rb_libarchive_entry_container *p;
307
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
308
+ Check_Entry(p);
309
+ return LONG2NUM(archive_entry_devminor(p->ae));
310
+ }
311
+
312
+ /* */
313
+ static VALUE rb_libarchive_entry_filetype(VALUE self) {
314
+ struct rb_libarchive_entry_container *p;
315
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
316
+ Check_Entry(p);
317
+ return INT2NUM(archive_entry_filetype(p->ae));
318
+ }
319
+
320
+ /* */
321
+ static VALUE rb_libarchive_entry_is_directory(VALUE self) {
322
+ struct rb_libarchive_entry_container *p;
323
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
324
+ Check_Entry(p);
325
+ return S_ISDIR(archive_entry_filetype(p->ae)) ? Qtrue : Qfalse;
326
+ }
327
+
328
+ /* */
329
+ static VALUE rb_libarchive_entry_is_character_special(VALUE self) {
330
+ struct rb_libarchive_entry_container *p;
331
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
332
+ Check_Entry(p);
333
+ return S_ISCHR(archive_entry_filetype(p->ae)) ? Qtrue : Qfalse;
334
+ }
335
+
336
+ /* */
337
+ static VALUE rb_libarchive_entry_is_block_special(VALUE self) {
338
+ struct rb_libarchive_entry_container *p;
339
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
340
+ Check_Entry(p);
341
+ return S_ISBLK(archive_entry_filetype(p->ae)) ? Qtrue : Qfalse;
342
+ }
343
+
344
+ /* */
345
+ static VALUE rb_libarchive_entry_is_regular(VALUE self) {
346
+ struct rb_libarchive_entry_container *p;
347
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
348
+ Check_Entry(p);
349
+ return S_ISREG(archive_entry_filetype(p->ae)) ? Qtrue : Qfalse;
350
+ }
351
+
352
+ /* */
353
+ static VALUE rb_libarchive_entry_is_symbolic_link(VALUE self) {
354
+ struct rb_libarchive_entry_container *p;
355
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
356
+ Check_Entry(p);
357
+ return S_ISLNK(archive_entry_filetype(p->ae)) ? Qtrue : Qfalse;
358
+ }
359
+
360
+ /* */
361
+ static VALUE rb_libarchive_entry_is_socket(VALUE self) {
362
+ struct rb_libarchive_entry_container *p;
363
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
364
+ Check_Entry(p);
365
+ return S_ISSOCK(archive_entry_filetype(p->ae)) ? Qtrue : Qfalse;
366
+ }
367
+
368
+ /* */
369
+ static VALUE rb_libarchive_entry_is_fifo(VALUE self) {
370
+ struct rb_libarchive_entry_container *p;
371
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
372
+ Check_Entry(p);
373
+ return S_ISFIFO(archive_entry_filetype(p->ae)) ? Qtrue : Qfalse;
374
+ }
375
+
376
+ /* */
377
+ static VALUE rb_libarchive_entry_fflags(VALUE self) {
378
+ struct rb_libarchive_entry_container *p;
379
+ long set, clear;
380
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
381
+ Check_Entry(p);
382
+ archive_entry_fflags(p->ae, &set, &clear);
383
+ return rb_ary_new3(2, LONG2NUM(set), LONG2NUM(clear));
384
+ }
385
+
386
+ /* */
387
+ static VALUE rb_libarchive_entry_fflags_text(VALUE self) {
388
+ struct rb_libarchive_entry_container *p;
389
+ const char *fflags_text;
390
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
391
+ Check_Entry(p);
392
+ fflags_text = archive_entry_fflags_text(p->ae);
393
+ return (fflags_text != NULL) ? rb_str_new2(fflags_text) : Qnil;
394
+ }
395
+
396
+ /* */
397
+ static VALUE rb_libarchive_entry_gid(VALUE self) {
398
+ struct rb_libarchive_entry_container *p;
399
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
400
+ Check_Entry(p);
401
+ return LONG2NUM(archive_entry_gid(p->ae));
402
+ }
403
+
404
+ /* */
405
+ static VALUE rb_libarchive_entry_gname(VALUE self) {
406
+ struct rb_libarchive_entry_container *p;
407
+ const char *gname;
408
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
409
+ Check_Entry(p);
410
+ gname = archive_entry_gname(p->ae);
411
+ return (gname != NULL) ? rb_str_new2(gname) : Qnil;
412
+ }
413
+
414
+ /* */
415
+ static VALUE rb_libarchive_entry_hardlink(VALUE self) {
416
+ struct rb_libarchive_entry_container *p;
417
+ const char *hardlink;
418
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
419
+ Check_Entry(p);
420
+ hardlink = archive_entry_hardlink(p->ae);
421
+ return (hardlink != NULL) ? rb_str_new2(hardlink) : Qnil;
422
+ }
423
+
424
+ /* */
425
+ static VALUE rb_libarchive_entry_ino(VALUE self) {
426
+ struct rb_libarchive_entry_container *p;
427
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
428
+ return LONG2NUM(archive_entry_ino(p->ae));
429
+ }
430
+
431
+ /* */
432
+ static VALUE rb_libarchive_entry_mode(VALUE self) {
433
+ struct rb_libarchive_entry_container *p;
434
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
435
+ return LONG2NUM(archive_entry_mode(p->ae));
436
+ }
437
+
438
+ /* */
439
+ static VALUE rb_libarchive_entry_mtime(VALUE self) {
440
+ struct rb_libarchive_entry_container *p;
441
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
442
+ Check_Entry(p);
443
+ return LONG2TIME((long) archive_entry_mtime(p->ae));
444
+ }
445
+
446
+ /* */
447
+ static VALUE rb_libarchive_entry_mtime_nsec(VALUE self) {
448
+ struct rb_libarchive_entry_container *p;
449
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
450
+ Check_Entry(p);
451
+ return LONG2NUM(archive_entry_mtime_nsec(p->ae));
452
+ }
453
+
454
+ /* */
455
+ static VALUE rb_libarchive_entry_mtime_is_set(VALUE self) {
456
+ struct rb_libarchive_entry_container *p;
457
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
458
+ Check_Entry(p);
459
+ return archive_entry_mtime_is_set(p->ae) ? Qtrue : Qfalse;
460
+ }
461
+
462
+ /* */
463
+ static VALUE rb_libarchive_entry_nlink(VALUE self) {
464
+ struct rb_libarchive_entry_container *p;
465
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
466
+ Check_Entry(p);
467
+ return LONG2NUM(archive_entry_nlink(p->ae));
468
+ }
469
+
470
+ /* */
471
+ static VALUE rb_libarchive_entry_pathname(VALUE self) {
472
+ struct rb_libarchive_entry_container *p;
473
+ const char *pathname;
474
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
475
+ Check_Entry(p);
476
+ pathname = archive_entry_pathname(p->ae);
477
+ return (pathname != NULL) ? rb_str_new2(pathname) : Qnil;
478
+ }
479
+
480
+ /* */
481
+ static VALUE rb_libarchive_entry_rdev(VALUE self) {
482
+ struct rb_libarchive_entry_container *p;
483
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
484
+ Check_Entry(p);
485
+ return LONG2NUM(archive_entry_rdev(p->ae));
486
+ }
487
+
488
+ /* */
489
+ static VALUE rb_libarchive_entry_rdevmajor(VALUE self) {
490
+ struct rb_libarchive_entry_container *p;
491
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
492
+ Check_Entry(p);
493
+ return LONG2NUM(archive_entry_rdevmajor(p->ae));
494
+ }
495
+
496
+ /* */
497
+ static VALUE rb_libarchive_entry_rdevminor(VALUE self) {
498
+ struct rb_libarchive_entry_container *p;
499
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
500
+ Check_Entry(p);
501
+ return LONG2NUM(archive_entry_rdevminor(p->ae));
502
+ }
503
+
504
+ #if ARCHIVE_VERSION_NUMBER >= 2005003
505
+ /* */
506
+ static VALUE rb_libarchive_entry_sourcepath(VALUE self) {
507
+ struct rb_libarchive_entry_container *p;
508
+ const char *sourcepath;
509
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
510
+ Check_Entry(p);
511
+ sourcepath = archive_entry_sourcepath(p->ae);
512
+ return (sourcepath != NULL) ? rb_str_new2(sourcepath) : Qnil;
513
+ }
514
+ #endif
515
+
516
+ /* */
517
+ static VALUE rb_libarchive_entry_size(VALUE self) {
518
+ struct rb_libarchive_entry_container *p;
519
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
520
+ Check_Entry(p);
521
+ return LL2NUM(archive_entry_size(p->ae));
522
+ }
523
+
524
+ /* */
525
+ static VALUE rb_libarchive_entry_size_is_set(VALUE self) {
526
+ struct rb_libarchive_entry_container *p;
527
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
528
+ Check_Entry(p);
529
+ return archive_entry_size_is_set(p->ae) ? Qtrue : Qfalse;
530
+ }
531
+
532
+ #if ARCHIVE_VERSION_NUMBER >= 2003002
533
+ /* */
534
+ static VALUE rb_libarchive_entry_strmode(VALUE self) {
535
+ struct rb_libarchive_entry_container *p;
536
+ const char *strmode;
537
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
538
+ Check_Entry(p);
539
+ strmode = archive_entry_strmode(p->ae);
540
+ return (strmode != NULL) ? rb_str_new2(strmode) : Qnil;
541
+ }
542
+ #endif
543
+
544
+ /* */
545
+ static VALUE rb_libarchive_entry_symlink(VALUE self) {
546
+ struct rb_libarchive_entry_container *p;
547
+ const char *symlink;
548
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
549
+ Check_Entry(p);
550
+ symlink = archive_entry_symlink(p->ae);
551
+ return (symlink != NULL) ? rb_str_new2(symlink) : Qnil;
552
+ }
553
+
554
+ /* */
555
+ static VALUE rb_libarchive_entry_uid(VALUE self) {
556
+ struct rb_libarchive_entry_container *p;
557
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
558
+ Check_Entry(p);
559
+ return LONG2NUM(archive_entry_uid(p->ae));
560
+ }
561
+
562
+ /* */
563
+ static VALUE rb_libarchive_entry_uname(VALUE self) {
564
+ struct rb_libarchive_entry_container *p;
565
+ const char *uname;
566
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
567
+ Check_Entry(p);
568
+ uname = archive_entry_uname(p->ae);
569
+ return (uname != NULL) ? rb_str_new2(uname) : Qnil;
570
+ }
571
+
572
+ /* */
573
+ static VALUE rb_libarchive_entry_set_atime(VALUE self, VALUE v_time) {
574
+ struct rb_libarchive_entry_container *p;
575
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
576
+ Check_Entry(p);
577
+ Check_Class(v_time, rb_cTime);
578
+ archive_entry_set_atime(p->ae, TIME2LONG(v_time), 0);
579
+ return Qnil;
580
+ }
581
+
582
+ /* */
583
+ static VALUE rb_libarchive_entry_set_atime2(VALUE self, VALUE v_time, VALUE v_ns) {
584
+ struct rb_libarchive_entry_container *p;
585
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
586
+ Check_Entry(p);
587
+ Check_Class(v_time, rb_cTime);
588
+ Check_Type(v_ns, T_FIXNUM);
589
+ archive_entry_set_atime(p->ae, TIME2LONG(v_time), NUM2LONG(v_ns));
590
+ return Qnil;
591
+ }
592
+
593
+ /* */
594
+ static VALUE rb_libarchive_entry_unset_atime(VALUE self) {
595
+ struct rb_libarchive_entry_container *p;
596
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
597
+ Check_Entry(p);
598
+ archive_entry_unset_atime(p->ae);
599
+ return Qnil;
600
+ }
601
+
602
+ /* */
603
+ static VALUE rb_libarchive_entry_set_birthtime(VALUE self, VALUE v_time) {
604
+ struct rb_libarchive_entry_container *p;
605
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
606
+ Check_Entry(p);
607
+ Check_Class(v_time, rb_cTime);
608
+ archive_entry_set_birthtime(p->ae, TIME2LONG(v_time), 0);
609
+ return Qnil;
610
+ }
611
+
612
+ /* */
613
+ static VALUE rb_libarchive_entry_set_birthtime2(VALUE self, VALUE v_time, VALUE v_ns) {
614
+ struct rb_libarchive_entry_container *p;
615
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
616
+ Check_Entry(p);
617
+ Check_Class(v_time, rb_cTime);
618
+ Check_Type(v_ns, T_FIXNUM);
619
+ archive_entry_set_birthtime(p->ae, TIME2LONG(v_time), NUM2LONG(v_ns));
620
+ return Qnil;
621
+ }
622
+
623
+ /* */
624
+ static VALUE rb_libarchive_entry_unset_birthtime(VALUE self) {
625
+ struct rb_libarchive_entry_container *p;
626
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
627
+ Check_Entry(p);
628
+ archive_entry_unset_birthtime(p->ae);
629
+ return Qnil;
630
+ }
631
+
632
+ /* */
633
+ static VALUE rb_libarchive_entry_set_ctime(VALUE self, VALUE v_time) {
634
+ struct rb_libarchive_entry_container *p;
635
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
636
+ Check_Entry(p);
637
+ Check_Class(v_time, rb_cTime);
638
+ archive_entry_set_ctime(p->ae, TIME2LONG(v_time), 0);
639
+ return Qnil;
640
+ }
641
+
642
+ /* */
643
+ static VALUE rb_libarchive_entry_set_ctime2(VALUE self, VALUE v_time, VALUE v_ns) {
644
+ struct rb_libarchive_entry_container *p;
645
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
646
+ Check_Entry(p);
647
+ Check_Class(v_time, rb_cTime);
648
+ Check_Type(v_ns, T_FIXNUM);
649
+ archive_entry_set_ctime(p->ae, TIME2LONG(v_time), NUM2LONG(v_ns));
650
+ return Qnil;
651
+ }
652
+
653
+ /* */
654
+ static VALUE rb_libarchive_entry_unset_ctime(VALUE self) {
655
+ struct rb_libarchive_entry_container *p;
656
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
657
+ Check_Entry(p);
658
+ archive_entry_unset_ctime(p->ae);
659
+ return Qnil;
660
+ }
661
+
662
+ /* */
663
+ static VALUE rb_libarchive_entry_set_dev(VALUE self, VALUE v_dev) {
664
+ struct rb_libarchive_entry_container *p;
665
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
666
+ Check_Entry(p);
667
+ Check_Type(v_dev, T_FIXNUM);
668
+ archive_entry_set_dev(p->ae, NUM2LONG(v_dev));
669
+ return Qnil;
670
+ }
671
+
672
+ /* */
673
+ static VALUE rb_libarchive_entry_set_devmajor(VALUE self, VALUE v_dev) {
674
+ struct rb_libarchive_entry_container *p;
675
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
676
+ Check_Entry(p);
677
+ Check_Type(v_dev, T_FIXNUM);
678
+ archive_entry_set_devmajor(p->ae, NUM2LONG(v_dev));
679
+ return Qnil;
680
+ }
681
+
682
+ /* */
683
+ static VALUE rb_libarchive_entry_set_devminor(VALUE self, VALUE v_dev) {
684
+ struct rb_libarchive_entry_container *p;
685
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
686
+ Check_Entry(p);
687
+ Check_Type(v_dev, T_FIXNUM);
688
+ archive_entry_set_devminor(p->ae, NUM2LONG(v_dev));
689
+ return Qnil;
690
+ }
691
+
692
+ /* */
693
+ static VALUE rb_libarchive_entry_set_filetype(VALUE self, VALUE v_type) {
694
+ struct rb_libarchive_entry_container *p;
695
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
696
+ Check_Entry(p);
697
+ Check_Type(v_type, T_FIXNUM);
698
+ archive_entry_set_filetype(p->ae, NUM2LONG(v_type));
699
+ return Qnil;
700
+ }
701
+
702
+ /* */
703
+ static VALUE rb_libarchive_entry_set_fflags(VALUE self, VALUE v_set, VALUE v_clear) {
704
+ struct rb_libarchive_entry_container *p;
705
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
706
+ Check_Entry(p);
707
+ Check_Type(v_set, T_FIXNUM);
708
+ Check_Type(v_clear, T_FIXNUM);
709
+ archive_entry_set_fflags(p->ae, (unsigned long) NUM2LONG(v_set), (unsigned long) NUM2LONG(v_clear));
710
+ return Qnil;
711
+ }
712
+
713
+ /* */
714
+ static VALUE rb_libarchive_entry_copy_fflags_text(VALUE self, VALUE v_fflags_text) {
715
+ struct rb_libarchive_entry_container *p;
716
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
717
+ Check_Entry(p);
718
+ Check_Type(v_fflags_text, T_STRING);
719
+ archive_entry_copy_fflags_text(p->ae, RSTRING_PTR(v_fflags_text));
720
+ return Qnil;
721
+ }
722
+
723
+ /* */
724
+ static VALUE rb_libarchive_entry_set_gid(VALUE self, VALUE v_gid) {
725
+ struct rb_libarchive_entry_container *p;
726
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
727
+ Check_Entry(p);
728
+ Check_Type(v_gid, T_FIXNUM);
729
+ archive_entry_set_gid(p->ae, NUM2LONG(v_gid));
730
+ return Qnil;
731
+ }
732
+
733
+ /* */
734
+ static VALUE rb_libarchive_entry_set_gname(VALUE self, VALUE v_gname) {
735
+ struct rb_libarchive_entry_container *p;
736
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
737
+ Check_Entry(p);
738
+ Check_Type(v_gname, T_STRING);
739
+ archive_entry_set_gname(p->ae, RSTRING_PTR(v_gname));
740
+ return Qnil;
741
+ }
742
+
743
+ /* */
744
+ static VALUE rb_libarchive_entry_copy_gname(VALUE self, VALUE v_gname) {
745
+ struct rb_libarchive_entry_container *p;
746
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
747
+ Check_Entry(p);
748
+ Check_Type(v_gname, T_STRING);
749
+ archive_entry_copy_gname(p->ae, RSTRING_PTR(v_gname));
750
+ return Qnil;
751
+ }
752
+
753
+ /* */
754
+ static VALUE rb_libarchive_entry_set_hardlink(VALUE self, VALUE v_hardlink) {
755
+ struct rb_libarchive_entry_container *p;
756
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
757
+ Check_Entry(p);
758
+ Check_Type(v_hardlink, T_STRING);
759
+ archive_entry_set_hardlink(p->ae, RSTRING_PTR(v_hardlink));
760
+ return Qnil;
761
+ }
762
+
763
+ /* */
764
+ static VALUE rb_libarchive_entry_copy_hardlink(VALUE self, VALUE v_hardlink) {
765
+ struct rb_libarchive_entry_container *p;
766
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
767
+ Check_Entry(p);
768
+ Check_Type(v_hardlink, T_STRING);
769
+ archive_entry_copy_hardlink(p->ae, RSTRING_PTR(v_hardlink));
770
+ return Qnil;
771
+ }
772
+
773
+ /* */
774
+ static VALUE rb_libarchive_entry_set_ino(VALUE self, VALUE v_ino) {
775
+ struct rb_libarchive_entry_container *p;
776
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
777
+ Check_Entry(p);
778
+ Check_Type(v_ino, T_FIXNUM);
779
+ archive_entry_set_ino(p->ae, (unsigned long) NUM2LONG(v_ino));
780
+ return Qnil;
781
+ }
782
+
783
+ /* */
784
+ static VALUE rb_libarchive_entry_set_link(VALUE self, VALUE v_link) {
785
+ struct rb_libarchive_entry_container *p;
786
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
787
+ Check_Entry(p);
788
+ Check_Type(v_link, T_STRING);
789
+ archive_entry_set_link(p->ae, RSTRING_PTR(v_link));
790
+ return Qnil;
791
+ }
792
+
793
+ /* */
794
+ static VALUE rb_libarchive_entry_copy_link(VALUE self, VALUE v_link) {
795
+ struct rb_libarchive_entry_container *p;
796
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
797
+ Check_Entry(p);
798
+ Check_Type(v_link, T_STRING);
799
+ archive_entry_copy_link(p->ae, RSTRING_PTR(v_link));
800
+ return Qnil;
801
+ }
802
+
803
+ /* */
804
+ static VALUE rb_libarchive_entry_set_mode(VALUE self, VALUE v_mode) {
805
+ struct rb_libarchive_entry_container *p;
806
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
807
+ Check_Entry(p);
808
+ Check_Type(v_mode, T_STRING);
809
+ archive_entry_set_mode(p->ae, NUM2INT(v_mode));
810
+ return Qnil;
811
+ }
812
+
813
+ /* */
814
+ static VALUE rb_libarchive_entry_set_mtime(VALUE self, VALUE v_time) {
815
+ struct rb_libarchive_entry_container *p;
816
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
817
+ Check_Entry(p);
818
+ Check_Class(v_time, rb_cTime);
819
+ archive_entry_set_mtime(p->ae, TIME2LONG(v_time), 0);
820
+ return Qnil;
821
+ }
822
+
823
+ /* */
824
+ static VALUE rb_libarchive_entry_set_mtime2(VALUE self, VALUE v_time, VALUE v_ns) {
825
+ struct rb_libarchive_entry_container *p;
826
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
827
+ Check_Entry(p);
828
+ Check_Class(v_time, rb_cTime);
829
+ Check_Type(v_ns, T_FIXNUM);
830
+ archive_entry_set_mtime(p->ae, TIME2LONG(v_time), NUM2LONG(v_ns));
831
+ return Qnil;
832
+ }
833
+
834
+ /* */
835
+ static VALUE rb_libarchive_entry_unset_mtime(VALUE self) {
836
+ struct rb_libarchive_entry_container *p;
837
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
838
+ Check_Entry(p);
839
+ archive_entry_unset_mtime(p->ae);
840
+ return Qnil;
841
+ }
842
+
843
+ /* */
844
+ static VALUE rb_libarchive_entry_set_nlink(VALUE self, VALUE v_nlink) {
845
+ struct rb_libarchive_entry_container *p;
846
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
847
+ Check_Entry(p);
848
+ Check_Type(v_nlink, T_FIXNUM);
849
+ archive_entry_set_nlink(p->ae, NUM2LONG(v_nlink));
850
+ return Qnil;
851
+ }
852
+
853
+ /* */
854
+ static VALUE rb_libarchive_entry_set_pathname(VALUE self, VALUE v_filename) {
855
+ struct rb_libarchive_entry_container *p;
856
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
857
+ Check_Entry(p);
858
+ Check_Type(v_filename, T_STRING);
859
+ archive_entry_set_pathname(p->ae, RSTRING_PTR(v_filename));
860
+ return Qnil;
861
+ }
862
+
863
+ /* */
864
+ static VALUE rb_libarchive_entry_copy_pathname(VALUE self, VALUE v_filename) {
865
+ struct rb_libarchive_entry_container *p;
866
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
867
+ Check_Entry(p);
868
+ Check_Type(v_filename, T_STRING);
869
+ archive_entry_copy_pathname(p->ae, RSTRING_PTR(v_filename));
870
+ return Qnil;
871
+ }
872
+
873
+ /* */
874
+ static VALUE rb_libarchive_entry_set_perm(VALUE self, VALUE v_perm) {
875
+ struct rb_libarchive_entry_container *p;
876
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
877
+ Check_Entry(p);
878
+ Check_Type(v_perm, T_STRING);
879
+ archive_entry_set_perm(p->ae, NUM2INT(v_perm));
880
+ return Qnil;
881
+ }
882
+
883
+ /* */
884
+ static VALUE rb_libarchive_entry_set_rdev(VALUE self, VALUE v_rdev) {
885
+ struct rb_libarchive_entry_container *p;
886
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
887
+ Check_Entry(p);
888
+ Check_Type(v_rdev, T_FIXNUM);
889
+ archive_entry_set_rdev(p->ae, NUM2LONG(v_rdev));
890
+ return Qnil;
891
+ }
892
+
893
+ /* */
894
+ static VALUE rb_libarchive_entry_set_rdevmajor(VALUE self, VALUE v_rdev) {
895
+ struct rb_libarchive_entry_container *p;
896
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
897
+ Check_Entry(p);
898
+ Check_Type(v_rdev, T_FIXNUM);
899
+ archive_entry_set_rdevmajor(p->ae, NUM2LONG(v_rdev));
900
+ return Qnil;
901
+ }
902
+
903
+ /* */
904
+ static VALUE rb_libarchive_entry_set_rdevminor(VALUE self, VALUE v_rdev) {
905
+ struct rb_libarchive_entry_container *p;
906
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
907
+ Check_Entry(p);
908
+ Check_Type(v_rdev, T_FIXNUM);
909
+ archive_entry_set_rdevminor(p->ae, NUM2LONG(v_rdev));
910
+ return Qnil;
911
+ }
912
+
913
+ /* */
914
+ static VALUE rb_libarchive_entry_set_size(VALUE self, VALUE v_size) {
915
+ struct rb_libarchive_entry_container *p;
916
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
917
+ Check_Entry(p);
918
+ Check_Type(v_size, T_FIXNUM);
919
+ archive_entry_set_size(p->ae, NUM2LL(v_size));
920
+ return Qnil;
921
+ }
922
+
923
+ /* */
924
+ static VALUE rb_libarchive_entry_unset_size(VALUE self) {
925
+ struct rb_libarchive_entry_container *p;
926
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
927
+ Check_Entry(p);
928
+ archive_entry_unset_size(p->ae);
929
+ return Qnil;
930
+ }
931
+
932
+ #if ARCHIVE_VERSION_NUMBER >= 2005003
933
+ /* */
934
+ static VALUE rb_libarchive_entry_copy_sourcepath(VALUE self, VALUE v_sourcepath) {
935
+ struct rb_libarchive_entry_container *p;
936
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
937
+ Check_Entry(p);
938
+ Check_Type(v_sourcepath, T_STRING);
939
+ archive_entry_copy_sourcepath(p->ae, RSTRING_PTR(v_sourcepath));
940
+ return Qnil;
941
+ }
942
+ #endif
943
+
944
+ /* */
945
+ static VALUE rb_libarchive_entry_set_symlink(VALUE self, VALUE v_symlink) {
946
+ struct rb_libarchive_entry_container *p;
947
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
948
+ Check_Entry(p);
949
+ Check_Type(v_symlink, T_STRING);
950
+ archive_entry_set_symlink(p->ae, RSTRING_PTR(v_symlink));
951
+ return Qnil;
952
+ }
953
+
954
+ /* */
955
+ static VALUE rb_libarchive_entry_copy_symlink(VALUE self, VALUE v_symlink) {
956
+ struct rb_libarchive_entry_container *p;
957
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
958
+ Check_Entry(p);
959
+ Check_Type(v_symlink, T_STRING);
960
+ archive_entry_copy_symlink(p->ae, RSTRING_PTR(v_symlink));
961
+ return Qnil;
962
+ }
963
+
964
+ /* */
965
+ static VALUE rb_libarchive_entry_set_uid(VALUE self, VALUE v_uid) {
966
+ struct rb_libarchive_entry_container *p;
967
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
968
+ Check_Entry(p);
969
+ Check_Type(v_uid, T_FIXNUM);
970
+ archive_entry_set_uid(p->ae, NUM2LONG(v_uid));
971
+ return Qnil;
972
+ }
973
+
974
+ /* */
975
+ static VALUE rb_libarchive_entry_set_uname(VALUE self, VALUE v_uname) {
976
+ struct rb_libarchive_entry_container *p;
977
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
978
+ Check_Entry(p);
979
+ Check_Type(v_uname, T_STRING);
980
+ archive_entry_set_uname(p->ae, RSTRING_PTR(v_uname));
981
+ return Qnil;
982
+ }
983
+
984
+ /* */
985
+ static VALUE rb_libarchive_entry_copy_uname(VALUE self, VALUE v_uname) {
986
+ struct rb_libarchive_entry_container *p;
987
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
988
+ Check_Entry(p);
989
+ Check_Type(v_uname, T_STRING);
990
+ archive_entry_copy_uname(p->ae, RSTRING_PTR(v_uname));
991
+ return Qnil;
992
+ }
993
+
994
+ /* */
995
+ static VALUE rb_libarchive_entry_copy_stat(VALUE self, VALUE v_filename) {
996
+ struct rb_libarchive_entry_container *p;
997
+ const char *filename;
998
+ struct stat s;
999
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
1000
+ Check_Entry(p);
1001
+ Check_Type(v_filename, T_STRING);
1002
+ filename = RSTRING_PTR(v_filename);
1003
+
1004
+ if (stat(filename, &s) != 0) {
1005
+ rb_raise(rb_eArchiveError, "Copy stat failed: %", strerror(errno));
1006
+ }
1007
+
1008
+ archive_entry_copy_stat(p->ae, &s);
1009
+ return Qnil;
1010
+ }
1011
+
1012
+ /* */
1013
+ static VALUE rb_libarchive_entry_copy_lstat(VALUE self, VALUE v_filename) {
1014
+ struct rb_libarchive_entry_container *p;
1015
+ const char *filename;
1016
+ struct stat s;
1017
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
1018
+ Check_Entry(p);
1019
+ Check_Type(v_filename, T_STRING);
1020
+ filename = RSTRING_PTR(v_filename);
1021
+
1022
+ if (lstat(filename, &s) != 0) {
1023
+ rb_raise(rb_eArchiveError, "Copy stat failed: %", strerror(errno));
1024
+ }
1025
+
1026
+ archive_entry_copy_stat(p->ae, &s);
1027
+ return Qnil;
1028
+ }
1029
+
1030
+ /* */
1031
+ static VALUE rb_libarchive_entry_xattr_clear(VALUE self) {
1032
+ struct rb_libarchive_entry_container *p;
1033
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
1034
+ Check_Entry(p);
1035
+ archive_entry_xattr_clear(p->ae);
1036
+ return Qnil;
1037
+ }
1038
+
1039
+ /* */
1040
+ static VALUE rb_libarchive_entry_xattr_add_entry(VALUE self, VALUE v_name, VALUE v_value) {
1041
+ struct rb_libarchive_entry_container *p;
1042
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
1043
+ Check_Entry(p);
1044
+ Check_Type(v_name, T_STRING);
1045
+ Check_Type(v_value, T_STRING);
1046
+ archive_entry_xattr_add_entry(p->ae, RSTRING_PTR(v_name), RSTRING_PTR(v_value), RSTRING_LEN(v_value));
1047
+ return Qnil;
1048
+ }
1049
+
1050
+ /* */
1051
+ static VALUE rb_libarchive_entry_xattr_count(VALUE self) {
1052
+ struct rb_libarchive_entry_container *p;
1053
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
1054
+ Check_Entry(p);
1055
+ return INT2NUM(archive_entry_xattr_count(p->ae));
1056
+ }
1057
+
1058
+ /* */
1059
+ static VALUE rb_libarchive_entry_xattr_reset(VALUE self) {
1060
+ struct rb_libarchive_entry_container *p;
1061
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
1062
+ Check_Entry(p);
1063
+ return INT2NUM(archive_entry_xattr_reset(p->ae));
1064
+ }
1065
+
1066
+ /* */
1067
+ static VALUE rb_libarchive_entry_xattr_next(VALUE self) {
1068
+ struct rb_libarchive_entry_container *p;
1069
+ const char *name;
1070
+ const void *value;
1071
+ size_t size;
1072
+ Data_Get_Struct(self, struct rb_libarchive_entry_container, p);
1073
+ Check_Entry(p);
1074
+
1075
+ if (archive_entry_xattr_next(p->ae, &name, &value, &size) != ARCHIVE_OK) {
1076
+ return Qnil;
1077
+ } else {
1078
+ return rb_ary_new3(3, rb_str_new2(name), rb_str_new(value, size));
1079
+ }
1080
+ }
1081
+
1082
+ void Init_libarchive_entry() {
1083
+ rb_cArchiveEntry = rb_define_class_under(rb_mArchive, "Entry", rb_cObject);
1084
+ rb_define_alloc_func(rb_cArchiveEntry, rb_libarchive_entry_alloc);
1085
+ rb_funcall(rb_cArchiveEntry, rb_intern("private_class_method"), 1, ID2SYM(rb_intern("new")));
1086
+ rb_define_method(rb_cArchiveEntry, "close", rb_libarchive_entry_close, 0);
1087
+
1088
+ rb_define_method(rb_cArchiveEntry, "atime", rb_libarchive_entry_atime, 0);
1089
+ rb_define_method(rb_cArchiveEntry, "atime_nsec", rb_libarchive_entry_atime_nsec, 0);
1090
+ rb_define_method(rb_cArchiveEntry, "atime_is_set?", rb_libarchive_entry_atime_is_set, 0);
1091
+ rb_define_method(rb_cArchiveEntry, "birthtime", rb_libarchive_entry_birthtime, 0);
1092
+ rb_define_method(rb_cArchiveEntry, "birthtime_nsec", rb_libarchive_entry_birthtime_nsec, 0);
1093
+ rb_define_method(rb_cArchiveEntry, "birthtime_is_set?", rb_libarchive_entry_birthtime_is_set, 0);
1094
+ rb_define_method(rb_cArchiveEntry, "ctime", rb_libarchive_entry_ctime, 0);
1095
+ rb_define_method(rb_cArchiveEntry, "ctime_nsec", rb_libarchive_entry_ctime_nsec, 0);
1096
+ rb_define_method(rb_cArchiveEntry, "ctime_is_set?", rb_libarchive_entry_ctime_is_set, 0);
1097
+ rb_define_method(rb_cArchiveEntry, "dev", rb_libarchive_entry_dev, 0);
1098
+ rb_define_method(rb_cArchiveEntry, "devmajor", rb_libarchive_entry_devmajor, 0);
1099
+ rb_define_method(rb_cArchiveEntry, "devminor", rb_libarchive_entry_devminor, 0);
1100
+ rb_define_method(rb_cArchiveEntry, "filetype", rb_libarchive_entry_filetype, 0);
1101
+ rb_define_method(rb_cArchiveEntry, "directory?", rb_libarchive_entry_is_directory, 0);
1102
+ rb_define_method(rb_cArchiveEntry, "character_special?", rb_libarchive_entry_is_character_special, 0);
1103
+ rb_define_method(rb_cArchiveEntry, "block_special?", rb_libarchive_entry_is_block_special, 0);
1104
+ rb_define_method(rb_cArchiveEntry, "regular?", rb_libarchive_entry_is_regular, 0);
1105
+ rb_define_method(rb_cArchiveEntry, "symbolic_link?", rb_libarchive_entry_is_symbolic_link, 0);
1106
+ rb_define_method(rb_cArchiveEntry, "socket?", rb_libarchive_entry_is_socket, 0);
1107
+ rb_define_method(rb_cArchiveEntry, "fifo?", rb_libarchive_entry_is_fifo, 0);
1108
+ rb_define_method(rb_cArchiveEntry, "fflags", rb_libarchive_entry_fflags, 0);
1109
+ rb_define_method(rb_cArchiveEntry, "fflags_text", rb_libarchive_entry_fflags_text, 0);
1110
+ rb_define_method(rb_cArchiveEntry, "gid", rb_libarchive_entry_gid, 0);
1111
+ rb_define_method(rb_cArchiveEntry, "gname", rb_libarchive_entry_gname, 0);
1112
+ rb_define_method(rb_cArchiveEntry, "hardlink", rb_libarchive_entry_hardlink, 0);
1113
+ rb_define_method(rb_cArchiveEntry, "ino", rb_libarchive_entry_ino, 0);
1114
+ rb_define_method(rb_cArchiveEntry, "mode", rb_libarchive_entry_mode, 0);
1115
+ rb_define_method(rb_cArchiveEntry, "mtime", rb_libarchive_entry_mtime, 0);
1116
+ rb_define_method(rb_cArchiveEntry, "mtime_nsec", rb_libarchive_entry_mtime_nsec, 0);
1117
+ rb_define_method(rb_cArchiveEntry, "mtime_is_set?", rb_libarchive_entry_mtime_is_set, 0);
1118
+ rb_define_method(rb_cArchiveEntry, "nlink", rb_libarchive_entry_nlink, 0);
1119
+ rb_define_method(rb_cArchiveEntry, "pathname", rb_libarchive_entry_pathname, 0);
1120
+ rb_define_method(rb_cArchiveEntry, "rdev", rb_libarchive_entry_rdev, 0);
1121
+ rb_define_method(rb_cArchiveEntry, "rdevmajor", rb_libarchive_entry_rdevmajor, 0);
1122
+ rb_define_method(rb_cArchiveEntry, "rdevminor", rb_libarchive_entry_rdevminor, 0);
1123
+ #if ARCHIVE_VERSION_NUMBER >= 2005003
1124
+ rb_define_method(rb_cArchiveEntry, "sourcepath", rb_libarchive_entry_sourcepath, 0);
1125
+ #endif
1126
+ rb_define_method(rb_cArchiveEntry, "size", rb_libarchive_entry_size, 0);
1127
+ rb_define_method(rb_cArchiveEntry, "size_is_set?", rb_libarchive_entry_size_is_set, 0);
1128
+ #if ARCHIVE_VERSION_NUMBER >= 2003002
1129
+ rb_define_method(rb_cArchiveEntry, "strmode", rb_libarchive_entry_strmode, 0);
1130
+ #endif
1131
+ rb_define_method(rb_cArchiveEntry, "symlink", rb_libarchive_entry_symlink, 0);
1132
+ rb_define_method(rb_cArchiveEntry, "uid", rb_libarchive_entry_uid, 0);
1133
+ rb_define_method(rb_cArchiveEntry, "uname", rb_libarchive_entry_uname, 0);
1134
+
1135
+ rb_define_method(rb_cArchiveEntry, "atime=", rb_libarchive_entry_set_atime, 1);
1136
+ rb_define_method(rb_cArchiveEntry, "set_atime", rb_libarchive_entry_set_atime2, 2);
1137
+ rb_define_method(rb_cArchiveEntry, "unset_atime", rb_libarchive_entry_unset_atime, 0);
1138
+ rb_define_method(rb_cArchiveEntry, "birthtimee=", rb_libarchive_entry_set_birthtime, 1);
1139
+ rb_define_method(rb_cArchiveEntry, "set_birthtime", rb_libarchive_entry_set_birthtime2, 2);
1140
+ rb_define_method(rb_cArchiveEntry, "unset_birthtime", rb_libarchive_entry_unset_birthtime, 0);
1141
+ rb_define_method(rb_cArchiveEntry, "ctime=", rb_libarchive_entry_set_ctime, 1);
1142
+ rb_define_method(rb_cArchiveEntry, "set_ctime", rb_libarchive_entry_set_ctime2, 2);
1143
+ rb_define_method(rb_cArchiveEntry, "unset_ctime", rb_libarchive_entry_unset_ctime, 0);
1144
+ rb_define_method(rb_cArchiveEntry, "dev=", rb_libarchive_entry_set_dev, 1);
1145
+ rb_define_method(rb_cArchiveEntry, "devmajor=", rb_libarchive_entry_set_devmajor, 1);
1146
+ rb_define_method(rb_cArchiveEntry, "devminor=", rb_libarchive_entry_set_devminor, 1);
1147
+ rb_define_method(rb_cArchiveEntry, "filetype=", rb_libarchive_entry_set_filetype, 1);
1148
+ rb_define_method(rb_cArchiveEntry, "set_fflags", rb_libarchive_entry_set_fflags, 2);
1149
+ rb_define_method(rb_cArchiveEntry, "copy_fflags_text", rb_libarchive_entry_copy_fflags_text, 1);
1150
+ rb_define_method(rb_cArchiveEntry, "gid=", rb_libarchive_entry_set_gid, 1);
1151
+ rb_define_method(rb_cArchiveEntry, "gname=", rb_libarchive_entry_set_gname, 1);
1152
+ rb_define_method(rb_cArchiveEntry, "copy_gname", rb_libarchive_entry_copy_gname, 1);
1153
+ rb_define_method(rb_cArchiveEntry, "hardlink=", rb_libarchive_entry_set_hardlink, 1);
1154
+ rb_define_method(rb_cArchiveEntry, "copy_hardlink", rb_libarchive_entry_copy_hardlink, 1);
1155
+ rb_define_method(rb_cArchiveEntry, "ino=", rb_libarchive_entry_set_ino, 1);
1156
+ rb_define_method(rb_cArchiveEntry, "link=", rb_libarchive_entry_set_link, 1);
1157
+ rb_define_method(rb_cArchiveEntry, "copy_link", rb_libarchive_entry_copy_link, 1);
1158
+ rb_define_method(rb_cArchiveEntry, "mode=", rb_libarchive_entry_set_mode, 1);
1159
+ rb_define_method(rb_cArchiveEntry, "mtime=", rb_libarchive_entry_set_mtime, 1);
1160
+ rb_define_method(rb_cArchiveEntry, "set_mtime", rb_libarchive_entry_set_mtime2, 2);
1161
+ rb_define_method(rb_cArchiveEntry, "unset_mtime", rb_libarchive_entry_unset_mtime, 0);
1162
+ rb_define_method(rb_cArchiveEntry, "nlink=", rb_libarchive_entry_set_nlink, 1);
1163
+ rb_define_method(rb_cArchiveEntry, "pathname=", rb_libarchive_entry_set_pathname, 1);
1164
+ rb_define_method(rb_cArchiveEntry, "copy_pathname", rb_libarchive_entry_copy_pathname, 1);
1165
+ rb_define_method(rb_cArchiveEntry, "perm=", rb_libarchive_entry_set_perm, 1);
1166
+ rb_define_method(rb_cArchiveEntry, "rdev=", rb_libarchive_entry_set_rdev, 1);
1167
+ rb_define_method(rb_cArchiveEntry, "rdevmajor=", rb_libarchive_entry_set_rdevmajor, 1);
1168
+ rb_define_method(rb_cArchiveEntry, "rdevminor=", rb_libarchive_entry_set_rdevminor, 1);
1169
+ rb_define_method(rb_cArchiveEntry, "size=", rb_libarchive_entry_set_size, 1);
1170
+ rb_define_method(rb_cArchiveEntry, "unset_size", rb_libarchive_entry_unset_size, 0);
1171
+ #if ARCHIVE_VERSION_NUMBER >= 2005003
1172
+ rb_define_method(rb_cArchiveEntry, "copy_sourcepath", rb_libarchive_entry_copy_sourcepath, 1);
1173
+ #endif
1174
+ rb_define_method(rb_cArchiveEntry, "symlink=", rb_libarchive_entry_set_symlink, 1);
1175
+ rb_define_method(rb_cArchiveEntry, "copy_symlink", rb_libarchive_entry_copy_symlink, 1);
1176
+ rb_define_method(rb_cArchiveEntry, "uid=", rb_libarchive_entry_set_uid, 1);
1177
+ rb_define_method(rb_cArchiveEntry, "uname=", rb_libarchive_entry_set_uname, 1);
1178
+ rb_define_method(rb_cArchiveEntry, "copy_uname", rb_libarchive_entry_copy_uname, 1);
1179
+
1180
+ rb_define_method(rb_cArchiveEntry, "copy_stat", rb_libarchive_entry_copy_stat, 1);
1181
+ rb_define_method(rb_cArchiveEntry, "copy_lstat", rb_libarchive_entry_copy_lstat, 1);
1182
+
1183
+ rb_define_method(rb_cArchiveEntry, "xattr_clear", rb_libarchive_entry_xattr_clear, 0);
1184
+ rb_define_method(rb_cArchiveEntry, "xattr_add_entry", rb_libarchive_entry_xattr_add_entry, 2);
1185
+ rb_define_method(rb_cArchiveEntry, "xattr_count", rb_libarchive_entry_xattr_count, 0);
1186
+ rb_define_method(rb_cArchiveEntry, "xattr_reset", rb_libarchive_entry_xattr_reset, 0);
1187
+ rb_define_method(rb_cArchiveEntry, "xattr_next", rb_libarchive_entry_xattr_next, 0);
1188
+ }
1189
+ #include "libarchive_internal.h"
1190
+
1191
+ extern VALUE rb_mArchive;
1192
+ VALUE rb_cArchiveReader;
1193
+ extern VALUE rb_eArchiveError;
1194
+ extern VALUE rb_cArchiveEntry;
1195
+
1196
+ static void rb_libarchive_reader_close0(struct rb_libarchive_archive_container *p) {
1197
+ archive_read_close(p->ar);
1198
+ archive_read_finish(p->ar);
1199
+ p->ar = NULL;
1200
+ }
1201
+
1202
+ /* */
1203
+ static VALUE rb_libarchive_reader_close(VALUE self) {
1204
+ struct rb_libarchive_archive_container *p;
1205
+ Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
1206
+ Check_Archive(p);
1207
+ rb_libarchive_reader_close0(p);
1208
+ return Qnil;
1209
+ }
1210
+
1211
+ static VALUE rb_libarchive_reader_s_open0(int (*archive_open)(struct rb_libarchive_archive_container *, void *), void *arg, int compression, int format) {
1212
+ VALUE reader;
1213
+ struct rb_libarchive_archive_container *p;
1214
+ int r;
1215
+ reader = rb_funcall(rb_cArchiveReader, rb_intern("new"), 0);
1216
+ Data_Get_Struct(reader, struct rb_libarchive_archive_container, p);
1217
+
1218
+ if ((p->ar = archive_read_new()) == NULL) {
1219
+ rb_raise(rb_eArchiveError, "Open reader failed: %s", strerror(errno));
1220
+ }
1221
+
1222
+ if (compression != -1) {
1223
+ r = archive_read_support_compression(p->ar, compression);
1224
+ } else {
1225
+ r = archive_read_support_compression_all(p->ar);
1226
+ }
1227
+
1228
+ if (r != ARCHIVE_OK) {
1229
+ char error_string[BUFSIZ];
1230
+ archive_copy_error_string(p->ar, error_string, BUFSIZ);
1231
+ rb_libarchive_reader_close0(p);
1232
+ rb_raise(rb_eArchiveError, "Support compression failed: %s", error_string);
1233
+ }
1234
+
1235
+ if (format != -1) {
1236
+ r = archive_read_support_format(p->ar, format);
1237
+ } else {
1238
+ r = archive_read_support_format_all(p->ar);
1239
+ }
1240
+
1241
+ if (r != ARCHIVE_OK) {
1242
+ char error_string[BUFSIZ];
1243
+ archive_copy_error_string(p->ar, error_string, BUFSIZ);
1244
+ rb_libarchive_reader_close0(p);
1245
+ rb_raise(rb_eArchiveError, "Support format failed: %s", error_string);
1246
+ }
1247
+
1248
+ if (archive_open(p, arg) != ARCHIVE_OK) {
1249
+ char error_string[BUFSIZ];
1250
+ archive_copy_error_string(p->ar, error_string, BUFSIZ);
1251
+ rb_libarchive_reader_close0(p);
1252
+ rb_raise(rb_eArchiveError, "Open reader failed: %s", error_string);
1253
+ }
1254
+
1255
+ if (rb_block_given_p()) {
1256
+ VALUE retval;
1257
+ int status;
1258
+ retval = rb_protect(rb_yield, reader, &status);
1259
+ rb_libarchive_reader_close0(p);
1260
+
1261
+ if (status != 0) {
1262
+ rb_jump_tag(status);
1263
+ }
1264
+
1265
+ return retval;
1266
+ } else {
1267
+ return reader;
1268
+ }
1269
+ }
1270
+
1271
+ static int rb_libarchive_reader_s_open_filename0(struct rb_libarchive_archive_container *p, void *arg) {
1272
+ const char *filename = (const char *) arg;
1273
+
1274
+ if (filename != NULL) {
1275
+ struct stat s;
1276
+
1277
+ if (stat(filename, &s) != 0) {
1278
+ archive_set_error(p->ar, -1, strerror(errno));
1279
+ return (ARCHIVE_FATAL);
1280
+ }
1281
+ }
1282
+
1283
+ return archive_read_open_filename(p->ar, filename, BLOCK_SIZE);
1284
+ }
1285
+
1286
+ /* */
1287
+ static VALUE rb_libarchive_reader_s_open_filename(int argc, VALUE *argv, VALUE self) {
1288
+ VALUE v_filename, v_compression, v_format;
1289
+ const char *filename = NULL;
1290
+ int compression = -1, format = -1;
1291
+ rb_scan_args(argc, argv, "12", &v_filename, &v_compression, &v_format);
1292
+ Check_Type(v_filename, T_STRING);
1293
+ filename = RSTRING_PTR(v_filename);
1294
+
1295
+ if (!NIL_P(v_compression)) {
1296
+ compression = NUM2INT(v_compression);
1297
+ }
1298
+
1299
+ if (!NIL_P(v_format)) {
1300
+ format = NUM2INT(v_format);
1301
+ }
1302
+
1303
+ return rb_libarchive_reader_s_open0(rb_libarchive_reader_s_open_filename0, (void *) filename, compression, format);
1304
+ }
1305
+
1306
+ static int rb_libarchive_reader_s_open_memory0(struct rb_libarchive_archive_container *p, void *arg) {
1307
+ VALUE v_buff = (VALUE) arg;
1308
+ return archive_read_open_memory(p->ar, RSTRING_PTR(v_buff), RSTRING_LEN(v_buff));
1309
+ }
1310
+
1311
+ /* */
1312
+ static VALUE rb_libarchive_reader_s_open_memory(int argc, VALUE *argv, VALUE self) {
1313
+ VALUE v_memory, v_compression, v_format;
1314
+ int compression = -1, format = -1;
1315
+ rb_scan_args(argc, argv, "12", &v_memory, &v_compression, &v_format);
1316
+ Check_Type(v_memory, T_STRING);
1317
+
1318
+ if (!NIL_P(v_compression)) {
1319
+ compression = NUM2INT(v_compression);
1320
+ }
1321
+
1322
+ if (!NIL_P(v_format)) {
1323
+ format = NUM2INT(v_format);
1324
+ }
1325
+
1326
+ return rb_libarchive_reader_s_open0(rb_libarchive_reader_s_open_memory0, (void *) v_memory, compression, format);
1327
+ }
1328
+
1329
+ /* */
1330
+ static VALUE rb_libarchive_reader_next_header(VALUE self) {
1331
+ struct rb_libarchive_archive_container *p;
1332
+ struct archive_entry *ae;
1333
+ int r;
1334
+ Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
1335
+ Check_Archive(p);
1336
+
1337
+ if (p->eof) {
1338
+ return Qnil;
1339
+ }
1340
+
1341
+ r = archive_read_next_header(p->ar, &ae);
1342
+
1343
+ if (r == ARCHIVE_EOF) {
1344
+ p->eof = 1;
1345
+ return Qnil;
1346
+ } else if (r != ARCHIVE_OK) {
1347
+ rb_raise(rb_eArchiveError, "Fetch entry failed: %s", archive_error_string(p->ar));
1348
+ }
1349
+
1350
+ return rb_libarchive_entry_new(ae, 0);
1351
+ }
1352
+
1353
+ /* */
1354
+ static VALUE rb_libarchive_reader_header_position(VALUE self) {
1355
+ struct rb_libarchive_archive_container *p;
1356
+ Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
1357
+ Check_Archive(p);
1358
+ return LONG2NUM((long) archive_read_header_position(p->ar));
1359
+ }
1360
+
1361
+ /* */
1362
+ static VALUE rb_libarchive_reader_read_data(int argc, VALUE *argv, VALUE self) {
1363
+ VALUE v_size;
1364
+ struct rb_libarchive_archive_container *p;
1365
+ char *buff;
1366
+ size_t size = DATA_BUFFER_SIZE;
1367
+ ssize_t n;
1368
+ rb_scan_args(argc, argv, "01", &v_size);
1369
+
1370
+ if (!NIL_P(v_size)) {
1371
+ size = NUM2INT(v_size);
1372
+ }
1373
+
1374
+ Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
1375
+ Check_Archive(p);
1376
+
1377
+ if (p->eof) {
1378
+ return Qnil;
1379
+ }
1380
+
1381
+ if (rb_block_given_p()) {
1382
+ ssize_t len = 0;
1383
+ int status = 0;
1384
+ buff = xmalloc(size);
1385
+
1386
+ while ((n = archive_read_data(p->ar, buff, size)) > 0) {
1387
+ rb_protect(rb_yield, rb_str_new(buff, n), &status);
1388
+
1389
+ if (status != 0) {
1390
+ break;
1391
+ }
1392
+
1393
+ len += n;
1394
+ }
1395
+
1396
+ xfree(buff);
1397
+
1398
+ if (status != 0) {
1399
+ rb_jump_tag(status);
1400
+ }
1401
+
1402
+ if (n < 0) {
1403
+ rb_raise(rb_eArchiveError, "Read data failed: %s", archive_error_string(p->ar));
1404
+ }
1405
+
1406
+ return LONG2NUM(len);
1407
+ } else {
1408
+ VALUE retval = rb_str_new("", 0);
1409
+ buff = xmalloc(size);
1410
+
1411
+ while ((n = archive_read_data(p->ar, buff, size)) > 0) {
1412
+ rb_str_cat(retval, buff, n);
1413
+ }
1414
+
1415
+ xfree(buff);
1416
+
1417
+ if (n < 0) {
1418
+ rb_raise(rb_eArchiveError, "Read data failed: %s", archive_error_string(p->ar));
1419
+ }
1420
+
1421
+ return retval;
1422
+ }
1423
+ }
1424
+
1425
+ /* */
1426
+ static VALUE rb_libarchive_reader_save_data(int argc, VALUE *argv, VALUE self) {
1427
+ VALUE v_filename, v_flags;
1428
+ struct rb_libarchive_archive_container *p;
1429
+ const char *filename;
1430
+ int flags, fd, r;
1431
+ rb_scan_args(argc, argv, "11", &v_filename, &v_flags);
1432
+ Check_Type(v_filename, T_STRING);
1433
+ filename = RSTRING_PTR(v_filename);
1434
+
1435
+ if (!NIL_P(v_flags)) {
1436
+ flags = ((O_WRONLY | NUM2INT(v_flags)) & O_FLAGS);
1437
+ } else {
1438
+ flags = (O_WRONLY | O_CREAT | O_EXCL
1439
+ #ifdef O_BINARY
1440
+ | O_BINARY
1441
+ #endif
1442
+ );
1443
+ }
1444
+
1445
+ Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
1446
+ Check_Archive(p);
1447
+
1448
+ if ((fd = open(filename, flags)) == -1) {
1449
+ rb_raise(rb_eArchiveError, "Save data failed: %s", strerror(errno));
1450
+ }
1451
+
1452
+ r = archive_read_data_into_fd(p->ar, fd);
1453
+ _close(fd);
1454
+
1455
+ if (r != ARCHIVE_OK) {
1456
+ rb_raise(rb_eArchiveError, "Save data failed: %s", archive_error_string(p->ar));
1457
+ }
1458
+
1459
+ return Qnil;
1460
+ }
1461
+
1462
+ /* */
1463
+ static VALUE rb_libarchive_reader_extract(int argc, VALUE *argv, VALUE self) {
1464
+ VALUE v_entry, v_flags;
1465
+ struct rb_libarchive_archive_container *pa;
1466
+ struct rb_libarchive_entry_container *pae;
1467
+ int flags = 0;
1468
+ rb_scan_args(argc, argv, "11", &v_entry, &v_flags);
1469
+ Check_Class(v_entry, rb_cArchiveEntry);
1470
+
1471
+ if (!NIL_P(v_flags)) {
1472
+ flags = (NUM2INT(v_flags) & EXTRACT_FLAGS);
1473
+ }
1474
+
1475
+ Data_Get_Struct(self, struct rb_libarchive_archive_container, pa);
1476
+ Check_Archive(pa);
1477
+
1478
+ if (pa->eof) {
1479
+ rb_raise(rb_eArchiveError, "Extract archive failed: It has already reached EOF");
1480
+ }
1481
+
1482
+ Data_Get_Struct(v_entry, struct rb_libarchive_entry_container, pae);
1483
+ Check_Entry(pae);
1484
+
1485
+ if (archive_read_extract(pa->ar, pae->ae, flags) != ARCHIVE_OK) {
1486
+ rb_raise(rb_eArchiveError, "Extract archive failed: %s", archive_error_string(pa->ar));
1487
+ }
1488
+
1489
+ return Qnil;
1490
+ }
1491
+
1492
+ void Init_libarchive_reader() {
1493
+ rb_cArchiveReader = rb_define_class_under(rb_mArchive, "Reader", rb_cObject);
1494
+ rb_define_alloc_func(rb_cArchiveReader, rb_libarchive_archive_alloc);
1495
+ rb_funcall(rb_cArchiveReader, rb_intern("private_class_method"), 1, ID2SYM(rb_intern("new")));
1496
+ rb_define_singleton_method(rb_cArchiveReader, "open_filename", rb_libarchive_reader_s_open_filename, -1);
1497
+ rb_define_singleton_method(rb_cArchiveReader, "open_memory", rb_libarchive_reader_s_open_memory, -1);
1498
+ rb_define_method(rb_cArchiveReader, "close", rb_libarchive_reader_close, 0);
1499
+ rb_define_method(rb_cArchiveReader, "next_header", rb_libarchive_reader_next_header, 0);
1500
+ rb_define_method(rb_cArchiveReader, "header_position", rb_libarchive_reader_header_position, 0);
1501
+ rb_define_method(rb_cArchiveReader, "read_data", rb_libarchive_reader_read_data, -1);
1502
+ rb_define_method(rb_cArchiveReader, "save_data", rb_libarchive_reader_save_data, -1);
1503
+ rb_define_method(rb_cArchiveReader, "extract", rb_libarchive_reader_extract, -1);
1504
+ }
1505
+ #include "libarchive_internal.h"
1506
+
1507
+ extern VALUE rb_mArchive;
1508
+ VALUE rb_cArchiveWriter;
1509
+ extern VALUE rb_eArchiveError;
1510
+ extern VALUE rb_cArchiveEntry;
1511
+
1512
+ static void rb_libarchive_writer_close0(struct rb_libarchive_archive_container *p) {
1513
+ archive_write_close(p->ar);
1514
+ archive_write_finish(p->ar);
1515
+ p->ar = NULL;
1516
+ }
1517
+
1518
+ /* */
1519
+ static VALUE rb_libarchive_writer_close(VALUE self) {
1520
+ struct rb_libarchive_archive_container *p;
1521
+ Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
1522
+ Check_Archive(p);
1523
+ rb_libarchive_writer_close0(p);
1524
+ return Qnil;
1525
+ }
1526
+
1527
+ static VALUE rb_libarchive_writer_s_open0(int (*archive_open)(struct rb_libarchive_archive_container *, void *), void *arg, int compression, int format) {
1528
+ VALUE writer;
1529
+ struct rb_libarchive_archive_container *p;
1530
+ writer = rb_funcall(rb_cArchiveWriter, rb_intern("new"), 0);
1531
+ Data_Get_Struct(writer, struct rb_libarchive_archive_container, p);
1532
+
1533
+ if ((p->ar = archive_write_new()) == NULL) {
1534
+ rb_raise(rb_eArchiveError, "Open writer failed: %s", strerror(errno));
1535
+ }
1536
+
1537
+ if (archive_write_set_compression(p->ar, compression) != ARCHIVE_OK) {
1538
+ char error_string[BUFSIZ];
1539
+ archive_copy_error_string(p->ar, error_string, BUFSIZ);
1540
+ rb_libarchive_writer_close0(p);
1541
+ rb_raise(rb_eArchiveError, "Set compression failed: %s", error_string);
1542
+ }
1543
+
1544
+ if (archive_write_set_format(p->ar, format) != ARCHIVE_OK) {
1545
+ char error_string[BUFSIZ];
1546
+ archive_copy_error_string(p->ar, error_string, BUFSIZ);
1547
+ rb_libarchive_writer_close0(p);
1548
+ rb_raise(rb_eArchiveError, "Set format failed: %s", error_string);
1549
+ }
1550
+
1551
+ if (archive_open(p, arg) != ARCHIVE_OK) {
1552
+ char error_string[BUFSIZ];
1553
+ archive_copy_error_string(p->ar, error_string, BUFSIZ);
1554
+ rb_libarchive_writer_close0(p);
1555
+ rb_raise(rb_eArchiveError, "Open writer failed: %s", error_string);
1556
+ }
1557
+
1558
+ if (rb_block_given_p()) {
1559
+ VALUE retval;
1560
+ int status;
1561
+ retval = rb_protect(rb_yield, writer, &status);
1562
+ rb_libarchive_writer_close0(p);
1563
+
1564
+ if (status != 0) {
1565
+ rb_jump_tag(status);
1566
+ }
1567
+
1568
+ return retval;
1569
+ } else {
1570
+ return writer;
1571
+ }
1572
+ }
1573
+
1574
+ static int rb_libarchive_writer_s_open_filename0(struct rb_libarchive_archive_container *p, void *arg) {
1575
+ const char *filename = (const char *) arg;
1576
+ return archive_write_open_filename(p->ar, filename);
1577
+ }
1578
+
1579
+ /* */
1580
+ static VALUE rb_libarchive_writer_s_open_filename(VALUE self, VALUE v_filename, VALUE v_compression, VALUE v_format) {
1581
+ const char *filename = NULL;
1582
+ int compression, format;
1583
+ Check_Type(v_filename, T_STRING);
1584
+
1585
+ if (RSTRING_LEN(v_filename) < 1) {
1586
+ rb_raise(rb_eArchiveError, "Open writer failed: No such file or directory");
1587
+ }
1588
+
1589
+ filename = RSTRING_PTR(v_filename);
1590
+ compression = NUM2INT(v_compression);
1591
+ format = NUM2INT(v_format);
1592
+ return rb_libarchive_writer_s_open0(rb_libarchive_writer_s_open_filename0, (void *) filename, compression, format);
1593
+ }
1594
+
1595
+ static int rb_libarchive_writer_s_open_memory0(struct rb_libarchive_archive_container *p, void *arg) {
1596
+ VALUE str = (VALUE) arg;
1597
+ p->memory = str;
1598
+ return archive_write_open_rb_str(p->ar, str);
1599
+ }
1600
+
1601
+ /* */
1602
+ static VALUE rb_libarchive_writer_s_open_memory(VALUE self, VALUE v_memory, VALUE v_compression, VALUE v_format) {
1603
+ int compression, format;
1604
+ Check_Type(v_memory, T_STRING);
1605
+ compression = NUM2INT(v_compression);
1606
+ format = NUM2INT(v_format);
1607
+ return rb_libarchive_writer_s_open0(rb_libarchive_writer_s_open_memory0, (void *) v_memory, compression, format);
1608
+ }
1609
+
1610
+ /* */
1611
+ static VALUE rb_libarchive_writer_new_entry(VALUE self) {
1612
+ VALUE entry;
1613
+ struct rb_libarchive_archive_container *p;
1614
+ struct archive_entry *ae;
1615
+ Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
1616
+ Check_Archive(p);
1617
+
1618
+ if ((ae = archive_entry_new()) == NULL) {
1619
+ rb_raise(rb_eArchiveError, "New entry failed: %s", strerror(errno));
1620
+ }
1621
+
1622
+ entry = rb_libarchive_entry_new(ae, 1);
1623
+
1624
+ if (rb_block_given_p()) {
1625
+ VALUE retval;
1626
+ int status;
1627
+ retval = rb_protect(rb_yield, entry, &status);
1628
+ rb_libarchive_entry_close(entry);
1629
+
1630
+ if (status != 0) {
1631
+ rb_jump_tag(status);
1632
+ }
1633
+
1634
+ return retval;
1635
+ } else {
1636
+ return entry;
1637
+ }
1638
+ }
1639
+
1640
+ /* */
1641
+ static VALUE rb_libarchive_writer_write_header(VALUE self, VALUE v_entry) {
1642
+ struct rb_libarchive_archive_container *pa;
1643
+ struct rb_libarchive_entry_container *pae;
1644
+ Check_Class(v_entry, rb_cArchiveEntry);
1645
+ Data_Get_Struct(self, struct rb_libarchive_archive_container, pa);
1646
+ Check_Archive(pa);
1647
+ Data_Get_Struct(v_entry, struct rb_libarchive_entry_container, pae);
1648
+ Check_Entry(pae);
1649
+
1650
+ if (archive_write_header(pa->ar, pae->ae) != ARCHIVE_OK) {
1651
+ rb_raise(rb_eArchiveError, "Write header failed: %s", archive_error_string(pa->ar));
1652
+ }
1653
+
1654
+ return Qnil;
1655
+ }
1656
+
1657
+ static ssize_t rb_libarchive_writer_write_data0(struct archive *ar, VALUE v_buff) {
1658
+ const char *buff;
1659
+ size_t size;
1660
+ ssize_t n;
1661
+
1662
+ if (NIL_P(v_buff)) {
1663
+ return 0;
1664
+ }
1665
+
1666
+ Check_Type(v_buff, T_STRING);
1667
+ buff = RSTRING_PTR(v_buff);
1668
+ size = RSTRING_LEN(v_buff);
1669
+
1670
+ if (size < 1) {
1671
+ return 0;
1672
+ }
1673
+
1674
+ if ((n = archive_write_data(ar, buff, size)) < 0) {
1675
+ rb_raise(rb_eArchiveError, "Write data failed: %s", archive_error_string(ar));
1676
+ }
1677
+
1678
+ return n;
1679
+ }
1680
+
1681
+ /* */
1682
+ static VALUE rb_libarchive_writer_write_data(int argc, VALUE *argv, VALUE self) {
1683
+ struct rb_libarchive_archive_container *p;
1684
+ Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
1685
+ Check_Archive(p);
1686
+
1687
+ if (rb_block_given_p()) {
1688
+ ssize_t len = 0;
1689
+
1690
+ if (argc > 0) {
1691
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
1692
+ }
1693
+
1694
+ while(1) {
1695
+ VALUE retval;
1696
+ ssize_t n;
1697
+ retval = rb_yield(Qnil);
1698
+
1699
+ if ((n = rb_libarchive_writer_write_data0(p->ar, retval)) < 1) {
1700
+ return LONG2NUM(len);
1701
+ }
1702
+
1703
+ len += n;
1704
+ }
1705
+ } else {
1706
+ VALUE v_buff;
1707
+ ssize_t n;
1708
+ rb_scan_args(argc, argv, "10", &v_buff);
1709
+ n = rb_libarchive_writer_write_data0(p->ar, v_buff);
1710
+ return LONG2NUM(n);
1711
+ }
1712
+ }
1713
+
1714
+ void Init_libarchive_writer() {
1715
+ rb_cArchiveWriter = rb_define_class_under(rb_mArchive, "Writer", rb_cObject);
1716
+ rb_define_alloc_func(rb_cArchiveWriter, rb_libarchive_archive_alloc);
1717
+ rb_funcall(rb_cArchiveWriter, rb_intern("private_class_method"), 1, ID2SYM(rb_intern("new")));
1718
+ rb_define_singleton_method(rb_cArchiveWriter, "open_filename", rb_libarchive_writer_s_open_filename, 3);
1719
+ rb_define_singleton_method(rb_cArchiveWriter, "open_memory", rb_libarchive_writer_s_open_memory, 3);
1720
+ rb_define_method(rb_cArchiveWriter, "close", rb_libarchive_writer_close, 0);
1721
+ rb_define_method(rb_cArchiveWriter, "new_entry", rb_libarchive_writer_new_entry, 0);
1722
+ rb_define_method(rb_cArchiveWriter, "write_header", rb_libarchive_writer_write_header, 1);
1723
+ rb_define_method(rb_cArchiveWriter, "write_data", rb_libarchive_writer_write_data, -1);
1724
+ }