libarchive 0.1.1-mswin32 → 0.1.2-mswin32

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