libarchive-static 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. data/ext/Makefile +6 -0
  2. data/ext/extconf.rb +61 -0
  3. data/ext/libarchive-0.1.1/COPYING.libarchive +60 -0
  4. data/ext/libarchive-0.1.1/LICENSE.libbzip2 +42 -0
  5. data/ext/libarchive-0.1.1/README.txt +143 -0
  6. data/ext/libarchive-0.1.1/ext/Makefile.in +0 -0
  7. data/ext/libarchive-0.1.1/ext/archive_read_support_compression.c +31 -0
  8. data/ext/libarchive-0.1.1/ext/archive_read_support_compression.h +6 -0
  9. data/ext/libarchive-0.1.1/ext/archive_read_support_format.c +32 -0
  10. data/ext/libarchive-0.1.1/ext/archive_read_support_format.h +6 -0
  11. data/ext/libarchive-0.1.1/ext/archive_write_open_rb_str.c +29 -0
  12. data/ext/libarchive-0.1.1/ext/archive_write_open_rb_str.h +6 -0
  13. data/ext/libarchive-0.1.1/ext/archive_write_set_compression.c +32 -0
  14. data/ext/libarchive-0.1.1/ext/archive_write_set_compression.h +6 -0
  15. data/ext/libarchive-0.1.1/ext/config.h.in +22 -0
  16. data/ext/libarchive-0.1.1/ext/configure +3904 -0
  17. data/ext/libarchive-0.1.1/ext/configure.in +11 -0
  18. data/ext/libarchive-0.1.1/ext/depend +19 -0
  19. data/ext/libarchive-0.1.1/ext/extconf.rb +6 -0
  20. data/ext/libarchive-0.1.1/ext/install-sh +250 -0
  21. data/ext/libarchive-0.1.1/ext/libarchive.c +89 -0
  22. data/ext/libarchive-0.1.1/ext/libarchive_archive.c +84 -0
  23. data/ext/libarchive-0.1.1/ext/libarchive_entry.c +1015 -0
  24. data/ext/libarchive-0.1.1/ext/libarchive_internal.h +155 -0
  25. data/ext/libarchive-0.1.1/ext/libarchive_reader.c +328 -0
  26. data/ext/libarchive-0.1.1/ext/libarchive_win32.h +52 -0
  27. data/ext/libarchive-0.1.1/ext/libarchive_writer.c +246 -0
  28. data/ext/libarchive-0.1.1/libarchive.c +1762 -0
  29. data/ext/libarchive-2.8.4/Makefile.in +7076 -0
  30. data/ext/libarchive-2.8.4/build/autoconf/check_stdcall_func.m4 +51 -0
  31. data/ext/libarchive-2.8.4/build/autoconf/compile +143 -0
  32. data/ext/libarchive-2.8.4/build/autoconf/config.guess +1502 -0
  33. data/ext/libarchive-2.8.4/build/autoconf/config.sub +1708 -0
  34. data/ext/libarchive-2.8.4/build/autoconf/depcomp +630 -0
  35. data/ext/libarchive-2.8.4/build/autoconf/install-sh +291 -0
  36. data/ext/libarchive-2.8.4/build/autoconf/la_uid_t.m4 +20 -0
  37. data/ext/libarchive-2.8.4/build/autoconf/ltmain.sh +8406 -0
  38. data/ext/libarchive-2.8.4/build/autoconf/missing +376 -0
  39. data/ext/libarchive-2.8.4/build/pkgconfig/libarchive.pc.in +10 -0
  40. data/ext/libarchive-2.8.4/config.h.in +772 -0
  41. data/ext/libarchive-2.8.4/configure +17916 -0
  42. data/ext/libarchive-2.8.4/libarchive/archive.h +741 -0
  43. data/ext/libarchive-2.8.4/libarchive/archive_check_magic.c +134 -0
  44. data/ext/libarchive-2.8.4/libarchive/archive_crc32.h +66 -0
  45. data/ext/libarchive-2.8.4/libarchive/archive_endian.h +162 -0
  46. data/ext/libarchive-2.8.4/libarchive/archive_entry.c +2202 -0
  47. data/ext/libarchive-2.8.4/libarchive/archive_entry.h +524 -0
  48. data/ext/libarchive-2.8.4/libarchive/archive_entry_copy_bhfi.c +74 -0
  49. data/ext/libarchive-2.8.4/libarchive/archive_entry_copy_stat.c +77 -0
  50. data/ext/libarchive-2.8.4/libarchive/archive_entry_link_resolver.c +405 -0
  51. data/ext/libarchive-2.8.4/libarchive/archive_entry_private.h +184 -0
  52. data/ext/libarchive-2.8.4/libarchive/archive_entry_stat.c +118 -0
  53. data/ext/libarchive-2.8.4/libarchive/archive_entry_strmode.c +87 -0
  54. data/ext/libarchive-2.8.4/libarchive/archive_entry_xattr.c +158 -0
  55. data/ext/libarchive-2.8.4/libarchive/archive_hash.h +281 -0
  56. data/ext/libarchive-2.8.4/libarchive/archive_platform.h +165 -0
  57. data/ext/libarchive-2.8.4/libarchive/archive_private.h +124 -0
  58. data/ext/libarchive-2.8.4/libarchive/archive_read.c +1249 -0
  59. data/ext/libarchive-2.8.4/libarchive/archive_read_data_into_fd.c +93 -0
  60. data/ext/libarchive-2.8.4/libarchive/archive_read_disk.c +198 -0
  61. data/ext/libarchive-2.8.4/libarchive/archive_read_disk_entry_from_file.c +570 -0
  62. data/ext/libarchive-2.8.4/libarchive/archive_read_disk_private.h +62 -0
  63. data/ext/libarchive-2.8.4/libarchive/archive_read_disk_set_standard_lookup.c +303 -0
  64. data/ext/libarchive-2.8.4/libarchive/archive_read_extract.c +182 -0
  65. data/ext/libarchive-2.8.4/libarchive/archive_read_open_fd.c +190 -0
  66. data/ext/libarchive-2.8.4/libarchive/archive_read_open_file.c +165 -0
  67. data/ext/libarchive-2.8.4/libarchive/archive_read_open_filename.c +272 -0
  68. data/ext/libarchive-2.8.4/libarchive/archive_read_open_memory.c +156 -0
  69. data/ext/libarchive-2.8.4/libarchive/archive_read_private.h +199 -0
  70. data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_all.c +60 -0
  71. data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_bzip2.c +353 -0
  72. data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_compress.c +444 -0
  73. data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_gzip.c +465 -0
  74. data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_none.c +40 -0
  75. data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_program.c +459 -0
  76. data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_rpm.c +287 -0
  77. data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_uu.c +627 -0
  78. data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_xz.c +708 -0
  79. data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_all.c +43 -0
  80. data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_ar.c +584 -0
  81. data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_cpio.c +777 -0
  82. data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_empty.c +93 -0
  83. data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_iso9660.c +2830 -0
  84. data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_mtree.c +1304 -0
  85. data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_raw.c +185 -0
  86. data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_tar.c +2418 -0
  87. data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_xar.c +3151 -0
  88. data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_zip.c +903 -0
  89. data/ext/libarchive-2.8.4/libarchive/archive_string.c +453 -0
  90. data/ext/libarchive-2.8.4/libarchive/archive_string.h +148 -0
  91. data/ext/libarchive-2.8.4/libarchive/archive_string_sprintf.c +164 -0
  92. data/ext/libarchive-2.8.4/libarchive/archive_util.c +391 -0
  93. data/ext/libarchive-2.8.4/libarchive/archive_virtual.c +94 -0
  94. data/ext/libarchive-2.8.4/libarchive/archive_windows.c +1236 -0
  95. data/ext/libarchive-2.8.4/libarchive/archive_windows.h +347 -0
  96. data/ext/libarchive-2.8.4/libarchive/archive_write.c +466 -0
  97. data/ext/libarchive-2.8.4/libarchive/archive_write_disk.c +2628 -0
  98. data/ext/libarchive-2.8.4/libarchive/archive_write_disk_private.h +38 -0
  99. data/ext/libarchive-2.8.4/libarchive/archive_write_disk_set_standard_lookup.c +262 -0
  100. data/ext/libarchive-2.8.4/libarchive/archive_write_open_fd.c +141 -0
  101. data/ext/libarchive-2.8.4/libarchive/archive_write_open_file.c +105 -0
  102. data/ext/libarchive-2.8.4/libarchive/archive_write_open_filename.c +162 -0
  103. data/ext/libarchive-2.8.4/libarchive/archive_write_open_memory.c +126 -0
  104. data/ext/libarchive-2.8.4/libarchive/archive_write_private.h +122 -0
  105. data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_bzip2.c +408 -0
  106. data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_compress.c +492 -0
  107. data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_gzip.c +477 -0
  108. data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_none.c +257 -0
  109. data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_program.c +347 -0
  110. data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_xz.c +438 -0
  111. data/ext/libarchive-2.8.4/libarchive/archive_write_set_format.c +72 -0
  112. data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_ar.c +550 -0
  113. data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_by_name.c +76 -0
  114. data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_cpio.c +344 -0
  115. data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_cpio_newc.c +295 -0
  116. data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_mtree.c +1050 -0
  117. data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_pax.c +1386 -0
  118. data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_shar.c +626 -0
  119. data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_ustar.c +587 -0
  120. data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_zip.c +667 -0
  121. data/ext/libarchive-2.8.4/libarchive/config_freebsd.h +154 -0
  122. data/ext/libarchive-2.8.4/libarchive/filter_fork.c +161 -0
  123. data/ext/libarchive-2.8.4/libarchive/filter_fork.h +41 -0
  124. data/ext/libarchive-2.8.4/libarchive/filter_fork_windows.c +113 -0
  125. data/ext/libarchive-static-makefile +80 -0
  126. data/ext/libarchive-static-wrapper-makefile +22 -0
  127. data/ext/zlib-1.2.5/Makefile.in +257 -0
  128. data/ext/zlib-1.2.5/adler32.c +169 -0
  129. data/ext/zlib-1.2.5/compress.c +80 -0
  130. data/ext/zlib-1.2.5/configure +596 -0
  131. data/ext/zlib-1.2.5/crc32.c +442 -0
  132. data/ext/zlib-1.2.5/crc32.h +441 -0
  133. data/ext/zlib-1.2.5/deflate.c +1834 -0
  134. data/ext/zlib-1.2.5/deflate.h +342 -0
  135. data/ext/zlib-1.2.5/example.c +565 -0
  136. data/ext/zlib-1.2.5/gzclose.c +25 -0
  137. data/ext/zlib-1.2.5/gzguts.h +132 -0
  138. data/ext/zlib-1.2.5/gzlib.c +537 -0
  139. data/ext/zlib-1.2.5/gzread.c +653 -0
  140. data/ext/zlib-1.2.5/gzwrite.c +531 -0
  141. data/ext/zlib-1.2.5/infback.c +632 -0
  142. data/ext/zlib-1.2.5/inffast.c +340 -0
  143. data/ext/zlib-1.2.5/inffast.h +11 -0
  144. data/ext/zlib-1.2.5/inffixed.h +94 -0
  145. data/ext/zlib-1.2.5/inflate.c +1480 -0
  146. data/ext/zlib-1.2.5/inflate.h +122 -0
  147. data/ext/zlib-1.2.5/inftrees.c +330 -0
  148. data/ext/zlib-1.2.5/inftrees.h +62 -0
  149. data/ext/zlib-1.2.5/minigzip.c +440 -0
  150. data/ext/zlib-1.2.5/trees.c +1244 -0
  151. data/ext/zlib-1.2.5/trees.h +128 -0
  152. data/ext/zlib-1.2.5/uncompr.c +59 -0
  153. data/ext/zlib-1.2.5/zconf.h +428 -0
  154. data/ext/zlib-1.2.5/zlib.h +1613 -0
  155. data/ext/zlib-1.2.5/zutil.c +318 -0
  156. data/ext/zlib-1.2.5/zutil.h +274 -0
  157. metadata +211 -0
@@ -0,0 +1,155 @@
1
+ #ifndef _LIBARCHIVE_INTERNAL_H_
2
+ #define _LIBARCHIVE_INTERNAL_H_
3
+
4
+ #ifdef HAVE_CONFIG_H
5
+ #include "config.h"
6
+ #endif
7
+
8
+ #include <fcntl.h>
9
+ #include <stdio.h>
10
+ #include <stdlib.h>
11
+ #include <string.h>
12
+ #include <sys/types.h>
13
+ #include <sys/stat.h>
14
+ #include <errno.h>
15
+
16
+ #ifndef _WIN32
17
+ #include <unistd.h>
18
+ #endif
19
+
20
+ #ifdef _WIN32
21
+ #ifdef stat
22
+ #undef stat
23
+ #endif
24
+ #define stat _stat
25
+ #endif // _WIN32
26
+
27
+ #include <archive.h>
28
+ #include <archive_entry.h>
29
+
30
+ #include <ruby.h>
31
+ #include <rubysig.h>
32
+
33
+ #ifdef _WIN32
34
+ #include "libarchive_win32.h"
35
+ #endif
36
+
37
+ #include "archive_write_open_rb_str.h"
38
+ #include "archive_read_support_compression.h"
39
+ #include "archive_read_support_format.h"
40
+ #include "archive_write_set_compression.h"
41
+
42
+ #ifdef LIBARCHIVE_EXPORTS
43
+ #define DLLEXPORT __declspec(dllexport)
44
+ #else
45
+ #define DLLEXPORT
46
+ #endif
47
+
48
+ #define VERSION "0.1.1"
49
+ #define BLOCK_SIZE 10240
50
+ #define DATA_BUFFER_SIZE 65536
51
+
52
+ #ifndef RSTRING_PTR
53
+ #define RSTRING_PTR(s) (RSTRING(s)->ptr)
54
+ #endif
55
+ #ifndef RSTRING_LEN
56
+ #define RSTRING_LEN(s) (RSTRING(s)->len)
57
+ #endif
58
+
59
+ #ifdef O_NONBLOCK
60
+ #define LIBARCHIVE_O_NONBLOCK O_NONBLOCK
61
+ #elif O_NDELAY
62
+ #define LIBARCHIVE_O_NONBLOCK O_NDELAY
63
+ #else
64
+ #define LIBARCHIVE_O_NONBLOCK 0
65
+ #endif
66
+
67
+ #ifdef O_NOCTTY
68
+ #define LIBARCHIVE_O_NOCTTY O_NOCTTY
69
+ #else
70
+ #define LIBARCHIVE_O_NOCTTY 0
71
+ #endif
72
+
73
+ #ifdef O_BINARY
74
+ #define LIBARCHIVE_O_BINARY O_BINARY
75
+ #else
76
+ #define LIBARCHIVE_O_BINARY 0
77
+ #endif
78
+
79
+ #ifdef O_SYNC
80
+ #define LIBARCHIVE_O_SYNC O_SYNC
81
+ #else
82
+ #define LIBARCHIVE_O_SYNC 0
83
+ #endif
84
+
85
+ #define O_FLAGS (O_RDONLY | O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_EXCL | O_TRUNC | \
86
+ LIBARCHIVE_O_NONBLOCK | LIBARCHIVE_O_NOCTTY | LIBARCHIVE_O_BINARY | LIBARCHIVE_O_SYNC)
87
+
88
+ #define EXTRACT_FLAGS_WITHOUT_ARCHIVE_EXTRACT_SPARSE \
89
+ (ARCHIVE_EXTRACT_OWNER | ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_TIME | \
90
+ ARCHIVE_EXTRACT_NO_OVERWRITE | ARCHIVE_EXTRACT_UNLINK | ARCHIVE_EXTRACT_ACL | \
91
+ ARCHIVE_EXTRACT_FFLAGS | ARCHIVE_EXTRACT_XATTR | ARCHIVE_EXTRACT_SECURE_SYMLINKS | \
92
+ ARCHIVE_EXTRACT_SECURE_NODOTDOT | ARCHIVE_EXTRACT_NO_AUTODIR | \
93
+ ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER)
94
+
95
+ #ifdef ARCHIVE_EXTRACT_SPARSE
96
+ #define EXTRACT_FLAGS (EXTRACT_FLAGS_WITHOUT_ARCHIVE_EXTRACT_SPARSE | ARCHIVE_EXTRACT_SPARSE)
97
+ #else
98
+ #define EXTRACT_FLAGS EXTRACT_FLAGS_WITHOUT_ARCHIVE_EXTRACT_SPARSE
99
+ #endif
100
+
101
+ struct rb_libarchive_archive_container {
102
+ struct archive *ar;
103
+ int eof;
104
+ VALUE memory;
105
+ };
106
+
107
+ struct rb_libarchive_entry_container {
108
+ struct archive_entry *ae;
109
+ int must_close;
110
+ };
111
+
112
+ #define Check_Archive(p) do { \
113
+ if ((p)->ar == NULL) { \
114
+ rb_raise(rb_eArchiveError, "Invalid archive"); \
115
+ } \
116
+ } while(0)
117
+
118
+ #define Check_Entry(p) do { \
119
+ if ((p)->ae == NULL) { \
120
+ rb_raise(rb_eArchiveError, "Invalid entry"); \
121
+ } \
122
+ } while(0)
123
+
124
+ #define Check_Class(v, c) do { \
125
+ if (!rb_obj_is_instance_of((v), (c))) { \
126
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)", \
127
+ rb_class2name(CLASS_OF(v)), rb_class2name(c)); \
128
+ } \
129
+ } while(0)
130
+
131
+ #define Check_Class(v, c) do { \
132
+ if (!rb_obj_is_instance_of((v), (c))) { \
133
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)", \
134
+ rb_class2name(CLASS_OF(v)), rb_class2name(c)); \
135
+ } \
136
+ } while(0)
137
+
138
+ #define LONG2TIME(i) rb_funcall(rb_cTime, rb_intern("at"), 1, LONG2NUM(i))
139
+ #define TIME2LONG(v) NUM2LONG(rb_funcall((v), rb_intern("tv_sec"), 0))
140
+
141
+ #define archive_copy_error_string(a, b, n) do { \
142
+ strncpy((b), archive_error_string(a), (n)); \
143
+ (b)[((n) - 1)] = '\0'; \
144
+ } while(0)
145
+
146
+ VALUE rb_libarchive_archive_alloc(VALUE klass);
147
+ VALUE rb_libarchive_entry_new(struct archive_entry *ae, int must_close);
148
+ VALUE rb_libarchive_entry_close(VALUE self);
149
+
150
+ void Init_libarchive_reader();
151
+ void Init_libarchive_writer();
152
+ void Init_libarchive_archive();
153
+ void Init_libarchive_entry();
154
+
155
+ #endif // _LIBARCHIVE_INTERNAL_H_
@@ -0,0 +1,328 @@
1
+ #include "libarchive_internal.h"
2
+
3
+ extern VALUE rb_mArchive;
4
+ VALUE rb_cArchiveReader;
5
+ extern VALUE rb_eArchiveError;
6
+ extern VALUE rb_cArchiveEntry;
7
+
8
+ static void rb_libarchive_reader_close0(struct rb_libarchive_archive_container *p) {
9
+ archive_read_close(p->ar);
10
+ archive_read_finish(p->ar);
11
+ p->ar = NULL;
12
+ }
13
+
14
+ /* */
15
+ static VALUE rb_libarchive_reader_close(VALUE self) {
16
+ struct rb_libarchive_archive_container *p;
17
+ Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
18
+ Check_Archive(p);
19
+ rb_libarchive_reader_close0(p);
20
+ return Qnil;
21
+ }
22
+
23
+ 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) {
24
+ VALUE reader;
25
+ struct rb_libarchive_archive_container *p;
26
+ int r;
27
+ reader = rb_funcall(rb_cArchiveReader, rb_intern("new"), 0);
28
+ Data_Get_Struct(reader, struct rb_libarchive_archive_container, p);
29
+
30
+ if ((p->ar = archive_read_new()) == NULL) {
31
+ rb_raise(rb_eArchiveError, "Open reader failed: %s", strerror(errno));
32
+ }
33
+
34
+ if (cmd != NULL) {
35
+ r = archive_read_support_compression_program(p->ar, cmd);
36
+ } else if (compression != -1) {
37
+ r = archive_read_support_compression(p->ar, compression);
38
+ } else {
39
+ r = archive_read_support_compression_all(p->ar);
40
+ }
41
+
42
+ if (r != ARCHIVE_OK) {
43
+ char error_string[BUFSIZ];
44
+ archive_copy_error_string(p->ar, error_string, BUFSIZ);
45
+ rb_libarchive_reader_close0(p);
46
+ rb_raise(rb_eArchiveError, "Support compression failed: %s", error_string);
47
+ }
48
+
49
+ if (format != -1) {
50
+ r = archive_read_support_format(p->ar, format);
51
+ } else {
52
+ r = archive_read_support_format_all(p->ar);
53
+ }
54
+
55
+ if (r != ARCHIVE_OK) {
56
+ char error_string[BUFSIZ];
57
+ archive_copy_error_string(p->ar, error_string, BUFSIZ);
58
+ rb_libarchive_reader_close0(p);
59
+ rb_raise(rb_eArchiveError, "Support format failed: %s", error_string);
60
+ }
61
+
62
+ if (archive_open(p, arg) != ARCHIVE_OK) {
63
+ char error_string[BUFSIZ];
64
+ archive_copy_error_string(p->ar, error_string, BUFSIZ);
65
+ rb_libarchive_reader_close0(p);
66
+ rb_raise(rb_eArchiveError, "Open reader failed: %s", error_string);
67
+ }
68
+
69
+ if (rb_block_given_p()) {
70
+ VALUE retval;
71
+ int status;
72
+ retval = rb_protect(rb_yield, reader, &status);
73
+ rb_libarchive_reader_close0(p);
74
+
75
+ if (status != 0) {
76
+ rb_jump_tag(status);
77
+ }
78
+
79
+ return retval;
80
+ } else {
81
+ return reader;
82
+ }
83
+ }
84
+
85
+ static int rb_libarchive_reader_s_open_filename0(struct rb_libarchive_archive_container *p, void *arg) {
86
+ const char *filename = (const char *) arg;
87
+
88
+ if (filename != NULL) {
89
+ struct stat s;
90
+
91
+ if (stat(filename, &s) != 0) {
92
+ archive_set_error(p->ar, -1, strerror(errno));
93
+ return (ARCHIVE_FATAL);
94
+ }
95
+ }
96
+
97
+ return archive_read_open_filename(p->ar, filename, BLOCK_SIZE);
98
+ }
99
+
100
+ /* */
101
+ static VALUE rb_libarchive_reader_s_open_filename(int argc, VALUE *argv, VALUE self) {
102
+ VALUE v_filename, v_compression, v_format;
103
+ const char *filename = NULL;
104
+ int compression = -1, format = -1;
105
+ const char *cmd = NULL;
106
+ rb_scan_args(argc, argv, "12", &v_filename, &v_compression, &v_format);
107
+ Check_Type(v_filename, T_STRING);
108
+ filename = RSTRING_PTR(v_filename);
109
+
110
+ if (T_STRING == TYPE(v_compression)) {
111
+ compression = -1;
112
+ cmd = RSTRING_PTR(v_compression);
113
+ } else if (!NIL_P(v_compression)) {
114
+ compression = NUM2INT(v_compression);
115
+ }
116
+
117
+ if (!NIL_P(v_format)) {
118
+ format = NUM2INT(v_format);
119
+ }
120
+
121
+ return rb_libarchive_reader_s_open0(rb_libarchive_reader_s_open_filename0, (void *) filename, compression, format, cmd);
122
+ }
123
+
124
+ static int rb_libarchive_reader_s_open_memory0(struct rb_libarchive_archive_container *p, void *arg) {
125
+ VALUE v_buff = (VALUE) arg;
126
+ return archive_read_open_memory(p->ar, RSTRING_PTR(v_buff), RSTRING_LEN(v_buff));
127
+ }
128
+
129
+ /* */
130
+ static VALUE rb_libarchive_reader_s_open_memory(int argc, VALUE *argv, VALUE self) {
131
+ VALUE v_memory, v_compression, v_format;
132
+ int compression = -1, format = -1;
133
+ const char *cmd = NULL;
134
+ rb_scan_args(argc, argv, "12", &v_memory, &v_compression, &v_format);
135
+ Check_Type(v_memory, T_STRING);
136
+
137
+ if (T_STRING == TYPE(v_compression)) {
138
+ compression = -1;
139
+ cmd = RSTRING_PTR(v_compression);
140
+ } else if (!NIL_P(v_compression)) {
141
+ compression = NUM2INT(v_compression);
142
+ }
143
+
144
+ if (!NIL_P(v_format)) {
145
+ format = NUM2INT(v_format);
146
+ }
147
+
148
+ return rb_libarchive_reader_s_open0(rb_libarchive_reader_s_open_memory0, (void *) v_memory, compression, format, cmd);
149
+ }
150
+
151
+ /* */
152
+ static VALUE rb_libarchive_reader_next_header(VALUE self) {
153
+ struct rb_libarchive_archive_container *p;
154
+ struct archive_entry *ae;
155
+ int r;
156
+ Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
157
+ Check_Archive(p);
158
+
159
+ if (p->eof) {
160
+ return Qnil;
161
+ }
162
+
163
+ r = archive_read_next_header(p->ar, &ae);
164
+
165
+ if (r == ARCHIVE_EOF) {
166
+ p->eof = 1;
167
+ return Qnil;
168
+ } else if (r != ARCHIVE_OK) {
169
+ rb_raise(rb_eArchiveError, "Fetch entry failed: %s", archive_error_string(p->ar));
170
+ }
171
+
172
+ return rb_libarchive_entry_new(ae, 0);
173
+ }
174
+
175
+ /* */
176
+ static VALUE rb_libarchive_reader_header_position(VALUE self) {
177
+ struct rb_libarchive_archive_container *p;
178
+ Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
179
+ Check_Archive(p);
180
+ return LONG2NUM((long) archive_read_header_position(p->ar));
181
+ }
182
+
183
+ /* */
184
+ static VALUE rb_libarchive_reader_read_data(int argc, VALUE *argv, VALUE self) {
185
+ VALUE v_size;
186
+ struct rb_libarchive_archive_container *p;
187
+ char *buff;
188
+ size_t size = DATA_BUFFER_SIZE;
189
+ ssize_t n;
190
+ rb_scan_args(argc, argv, "01", &v_size);
191
+
192
+ if (!NIL_P(v_size)) {
193
+ size = NUM2INT(v_size);
194
+ }
195
+
196
+ Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
197
+ Check_Archive(p);
198
+
199
+ if (p->eof) {
200
+ return Qnil;
201
+ }
202
+
203
+ if (rb_block_given_p()) {
204
+ ssize_t len = 0;
205
+ int status = 0;
206
+ buff = xmalloc(size);
207
+
208
+ while ((n = archive_read_data(p->ar, buff, size)) > 0) {
209
+ rb_protect(rb_yield, rb_str_new(buff, n), &status);
210
+
211
+ if (status != 0) {
212
+ break;
213
+ }
214
+
215
+ len += n;
216
+ }
217
+
218
+ xfree(buff);
219
+
220
+ if (status != 0) {
221
+ rb_jump_tag(status);
222
+ }
223
+
224
+ if (n < 0) {
225
+ rb_raise(rb_eArchiveError, "Read data failed: %s", archive_error_string(p->ar));
226
+ }
227
+
228
+ return LONG2NUM(len);
229
+ } else {
230
+ VALUE retval = rb_str_new("", 0);
231
+ buff = xmalloc(size);
232
+
233
+ while ((n = archive_read_data(p->ar, buff, size)) > 0) {
234
+ rb_str_cat(retval, buff, n);
235
+ }
236
+
237
+ xfree(buff);
238
+
239
+ if (n < 0) {
240
+ rb_raise(rb_eArchiveError, "Read data failed: %s", archive_error_string(p->ar));
241
+ }
242
+
243
+ return retval;
244
+ }
245
+ }
246
+
247
+ /* */
248
+ static VALUE rb_libarchive_reader_save_data(int argc, VALUE *argv, VALUE self) {
249
+ VALUE v_filename, v_flags;
250
+ struct rb_libarchive_archive_container *p;
251
+ const char *filename;
252
+ int flags, fd, r;
253
+ rb_scan_args(argc, argv, "11", &v_filename, &v_flags);
254
+ Check_Type(v_filename, T_STRING);
255
+ filename = RSTRING_PTR(v_filename);
256
+
257
+ if (!NIL_P(v_flags)) {
258
+ flags = ((O_WRONLY | NUM2INT(v_flags)) & O_FLAGS);
259
+ } else {
260
+ flags = (O_WRONLY | O_CREAT | O_EXCL
261
+ #ifdef O_BINARY
262
+ | O_BINARY
263
+ #endif
264
+ );
265
+ }
266
+
267
+ Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
268
+ Check_Archive(p);
269
+
270
+ if ((fd = open(filename, flags)) == -1) {
271
+ rb_raise(rb_eArchiveError, "Save data failed: %s", strerror(errno));
272
+ }
273
+
274
+ r = archive_read_data_into_fd(p->ar, fd);
275
+ _close(fd);
276
+
277
+ if (r != ARCHIVE_OK) {
278
+ rb_raise(rb_eArchiveError, "Save data failed: %s", archive_error_string(p->ar));
279
+ }
280
+
281
+ return Qnil;
282
+ }
283
+
284
+ /* */
285
+ static VALUE rb_libarchive_reader_extract(int argc, VALUE *argv, VALUE self) {
286
+ VALUE v_entry, v_flags;
287
+ struct rb_libarchive_archive_container *pa;
288
+ struct rb_libarchive_entry_container *pae;
289
+ int flags = 0;
290
+ rb_scan_args(argc, argv, "11", &v_entry, &v_flags);
291
+ Check_Class(v_entry, rb_cArchiveEntry);
292
+
293
+ if (!NIL_P(v_flags)) {
294
+ flags = (NUM2INT(v_flags) & EXTRACT_FLAGS);
295
+ }
296
+
297
+ Data_Get_Struct(self, struct rb_libarchive_archive_container, pa);
298
+ Check_Archive(pa);
299
+
300
+ if (pa->eof) {
301
+ rb_raise(rb_eArchiveError, "Extract archive failed: It has already reached EOF");
302
+ }
303
+
304
+ Data_Get_Struct(v_entry, struct rb_libarchive_entry_container, pae);
305
+ Check_Entry(pae);
306
+
307
+ if (archive_read_extract(pa->ar, pae->ae, flags) != ARCHIVE_OK) {
308
+ rb_raise(rb_eArchiveError, "Extract archive failed: %s", archive_error_string(pa->ar));
309
+ }
310
+
311
+ return Qnil;
312
+ }
313
+
314
+ void Init_libarchive_reader() {
315
+ rb_cArchiveReader = rb_define_class_under(rb_mArchive, "Reader", rb_cObject);
316
+ rb_define_alloc_func(rb_cArchiveReader, rb_libarchive_archive_alloc);
317
+ rb_funcall(rb_cArchiveReader, rb_intern("private_class_method"), 1, ID2SYM(rb_intern("new")));
318
+ rb_define_singleton_method(rb_cArchiveReader, "open_filename", rb_libarchive_reader_s_open_filename, -1);
319
+ rb_define_module_function(rb_mArchive, "read_open_filename", rb_libarchive_reader_s_open_filename, -1);
320
+ rb_define_singleton_method(rb_cArchiveReader, "open_memory", rb_libarchive_reader_s_open_memory, -1);
321
+ rb_define_module_function(rb_mArchive, "read_open_memory", rb_libarchive_reader_s_open_memory, -1);
322
+ rb_define_method(rb_cArchiveReader, "close", rb_libarchive_reader_close, 0);
323
+ rb_define_method(rb_cArchiveReader, "next_header", rb_libarchive_reader_next_header, 0);
324
+ rb_define_method(rb_cArchiveReader, "header_position", rb_libarchive_reader_header_position, 0);
325
+ rb_define_method(rb_cArchiveReader, "read_data", rb_libarchive_reader_read_data, -1);
326
+ rb_define_method(rb_cArchiveReader, "save_data", rb_libarchive_reader_save_data, -1);
327
+ rb_define_method(rb_cArchiveReader, "extract", rb_libarchive_reader_extract, -1);
328
+ }
@@ -0,0 +1,52 @@
1
+ #ifndef _LIBARCHIVE_WIN32_H_
2
+ #define _LIBARCHIVE_WIN32_H_
3
+
4
+ #ifdef _WIN32
5
+
6
+ typedef long ssize_t;
7
+
8
+ #ifdef open
9
+ #undef open
10
+ #endif
11
+ #define open(p, f) _open((p), (f), _S_IREAD | _S_IWRITE)
12
+
13
+ #ifdef close
14
+ #undef close
15
+ #endif
16
+ #define close(f) _close(f)
17
+
18
+ #ifdef stat
19
+ #undef stat
20
+ #endif
21
+ #define stat _stat
22
+ #define lstat(p, s) _stat((p), (s))
23
+
24
+ #ifdef strerror
25
+ #undef strerror
26
+ #endif
27
+
28
+ #ifndef S_ISBLK
29
+ #define S_ISBLK(m) (0)
30
+ #endif
31
+ #ifndef S_ISCHR
32
+ #define S_ISCHR(m) (((m) & (_S_IFMT)) == (_S_IFCHR))
33
+ #endif
34
+ #ifndef S_ISDIR
35
+ #define S_ISDIR(m) (((m) & (_S_IFMT)) == (_S_IFDIR))
36
+ #endif
37
+ #ifndef S_ISFIFO
38
+ #define S_ISFIFO(m) (((m) & (_S_IFMT)) == (_S_IFIFO))
39
+ #endif
40
+ #ifndef S_ISLNK
41
+ #define S_ISLNK(m) (0)
42
+ #endif
43
+ #ifndef S_ISREG
44
+ #define S_ISREG(m) (((m) & (_S_IFMT)) == (_S_IFREG))
45
+ #endif
46
+ #ifndef S_ISSOCK
47
+ #define S_ISSOCK(m) (0)
48
+ #endif
49
+
50
+ #endif // _WIN32
51
+
52
+ #endif // _LIBARCHIVE_WIN32_H_