libarchive-static 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,257 @@
1
+ /*-
2
+ * Copyright (c) 2003-2007 Tim Kientzle
3
+ * All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions
7
+ * are met:
8
+ * 1. Redistributions of source code must retain the above copyright
9
+ * notice, this list of conditions and the following disclaimer.
10
+ * 2. Redistributions in binary form must reproduce the above copyright
11
+ * notice, this list of conditions and the following disclaimer in the
12
+ * documentation and/or other materials provided with the distribution.
13
+ *
14
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
+ */
25
+
26
+ #include "archive_platform.h"
27
+ __FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_compression_none.c 201080 2009-12-28 02:03:54Z kientzle $");
28
+
29
+ #ifdef HAVE_ERRNO_H
30
+ #include <errno.h>
31
+ #endif
32
+ #ifdef HAVE_STDLIB_H
33
+ #include <stdlib.h>
34
+ #endif
35
+ #ifdef HAVE_STRING_H
36
+ #include <string.h>
37
+ #endif
38
+
39
+ #include "archive.h"
40
+ #include "archive_private.h"
41
+ #include "archive_write_private.h"
42
+
43
+ static int archive_compressor_none_finish(struct archive_write *a);
44
+ static int archive_compressor_none_init(struct archive_write *);
45
+ static int archive_compressor_none_write(struct archive_write *,
46
+ const void *, size_t);
47
+
48
+ struct archive_none {
49
+ char *buffer;
50
+ ssize_t buffer_size;
51
+ char *next; /* Current insert location */
52
+ ssize_t avail; /* Free space left in buffer */
53
+ };
54
+
55
+ int
56
+ archive_write_set_compression_none(struct archive *_a)
57
+ {
58
+ struct archive_write *a = (struct archive_write *)_a;
59
+ __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
60
+ ARCHIVE_STATE_NEW, "archive_write_set_compression_none");
61
+ a->compressor.init = &archive_compressor_none_init;
62
+ return (0);
63
+ }
64
+
65
+ /*
66
+ * Setup callback.
67
+ */
68
+ static int
69
+ archive_compressor_none_init(struct archive_write *a)
70
+ {
71
+ int ret;
72
+ struct archive_none *state;
73
+
74
+ a->archive.compression_code = ARCHIVE_COMPRESSION_NONE;
75
+ a->archive.compression_name = "none";
76
+
77
+ if (a->client_opener != NULL) {
78
+ ret = (a->client_opener)(&a->archive, a->client_data);
79
+ if (ret != 0)
80
+ return (ret);
81
+ }
82
+
83
+ state = (struct archive_none *)malloc(sizeof(*state));
84
+ if (state == NULL) {
85
+ archive_set_error(&a->archive, ENOMEM,
86
+ "Can't allocate data for output buffering");
87
+ return (ARCHIVE_FATAL);
88
+ }
89
+ memset(state, 0, sizeof(*state));
90
+
91
+ state->buffer_size = a->bytes_per_block;
92
+ if (state->buffer_size != 0) {
93
+ state->buffer = (char *)malloc(state->buffer_size);
94
+ if (state->buffer == NULL) {
95
+ archive_set_error(&a->archive, ENOMEM,
96
+ "Can't allocate output buffer");
97
+ free(state);
98
+ return (ARCHIVE_FATAL);
99
+ }
100
+ }
101
+
102
+ state->next = state->buffer;
103
+ state->avail = state->buffer_size;
104
+
105
+ a->compressor.data = state;
106
+ a->compressor.write = archive_compressor_none_write;
107
+ a->compressor.finish = archive_compressor_none_finish;
108
+ return (ARCHIVE_OK);
109
+ }
110
+
111
+ /*
112
+ * Write data to the stream.
113
+ */
114
+ static int
115
+ archive_compressor_none_write(struct archive_write *a, const void *vbuff,
116
+ size_t length)
117
+ {
118
+ const char *buff;
119
+ ssize_t remaining, to_copy;
120
+ ssize_t bytes_written;
121
+ struct archive_none *state;
122
+
123
+ state = (struct archive_none *)a->compressor.data;
124
+ buff = (const char *)vbuff;
125
+ if (a->client_writer == NULL) {
126
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER,
127
+ "No write callback is registered? "
128
+ "This is probably an internal programming error.");
129
+ return (ARCHIVE_FATAL);
130
+ }
131
+
132
+ remaining = length;
133
+
134
+ /*
135
+ * If there is no buffer for blocking, just pass the data
136
+ * straight through to the client write callback. In
137
+ * particular, this supports "no write delay" operation for
138
+ * special applications. Just set the block size to zero.
139
+ */
140
+ if (state->buffer_size == 0) {
141
+ while (remaining > 0) {
142
+ bytes_written = (a->client_writer)(&a->archive,
143
+ a->client_data, buff, remaining);
144
+ if (bytes_written <= 0)
145
+ return (ARCHIVE_FATAL);
146
+ a->archive.raw_position += bytes_written;
147
+ remaining -= bytes_written;
148
+ buff += bytes_written;
149
+ }
150
+ a->archive.file_position += length;
151
+ return (ARCHIVE_OK);
152
+ }
153
+
154
+ /* If the copy buffer isn't empty, try to fill it. */
155
+ if (state->avail < state->buffer_size) {
156
+ /* If buffer is not empty... */
157
+ /* ... copy data into buffer ... */
158
+ to_copy = (remaining > state->avail) ?
159
+ state->avail : remaining;
160
+ memcpy(state->next, buff, to_copy);
161
+ state->next += to_copy;
162
+ state->avail -= to_copy;
163
+ buff += to_copy;
164
+ remaining -= to_copy;
165
+ /* ... if it's full, write it out. */
166
+ if (state->avail == 0) {
167
+ bytes_written = (a->client_writer)(&a->archive,
168
+ a->client_data, state->buffer, state->buffer_size);
169
+ if (bytes_written <= 0)
170
+ return (ARCHIVE_FATAL);
171
+ /* XXX TODO: if bytes_written < state->buffer_size */
172
+ a->archive.raw_position += bytes_written;
173
+ state->next = state->buffer;
174
+ state->avail = state->buffer_size;
175
+ }
176
+ }
177
+
178
+ while (remaining > state->buffer_size) {
179
+ /* Write out full blocks directly to client. */
180
+ bytes_written = (a->client_writer)(&a->archive,
181
+ a->client_data, buff, state->buffer_size);
182
+ if (bytes_written <= 0)
183
+ return (ARCHIVE_FATAL);
184
+ a->archive.raw_position += bytes_written;
185
+ buff += bytes_written;
186
+ remaining -= bytes_written;
187
+ }
188
+
189
+ if (remaining > 0) {
190
+ /* Copy last bit into copy buffer. */
191
+ memcpy(state->next, buff, remaining);
192
+ state->next += remaining;
193
+ state->avail -= remaining;
194
+ }
195
+
196
+ a->archive.file_position += length;
197
+ return (ARCHIVE_OK);
198
+ }
199
+
200
+
201
+ /*
202
+ * Finish the compression.
203
+ */
204
+ static int
205
+ archive_compressor_none_finish(struct archive_write *a)
206
+ {
207
+ ssize_t block_length;
208
+ ssize_t target_block_length;
209
+ ssize_t bytes_written;
210
+ int ret;
211
+ struct archive_none *state;
212
+
213
+ state = (struct archive_none *)a->compressor.data;
214
+ ret = ARCHIVE_OK;
215
+ if (a->client_writer == NULL) {
216
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER,
217
+ "No write callback is registered? "
218
+ "This is probably an internal programming error.");
219
+ return (ARCHIVE_FATAL);
220
+ }
221
+
222
+ /* If there's pending data, pad and write the last block */
223
+ if (state->next != state->buffer) {
224
+ block_length = state->buffer_size - state->avail;
225
+
226
+ /* Tricky calculation to determine size of last block */
227
+ if (a->bytes_in_last_block <= 0)
228
+ /* Default or Zero: pad to full block */
229
+ target_block_length = a->bytes_per_block;
230
+ else
231
+ /* Round to next multiple of bytes_in_last_block. */
232
+ target_block_length = a->bytes_in_last_block *
233
+ ( (block_length + a->bytes_in_last_block - 1) /
234
+ a->bytes_in_last_block);
235
+ if (target_block_length > a->bytes_per_block)
236
+ target_block_length = a->bytes_per_block;
237
+ if (block_length < target_block_length) {
238
+ memset(state->next, 0,
239
+ target_block_length - block_length);
240
+ block_length = target_block_length;
241
+ }
242
+ bytes_written = (a->client_writer)(&a->archive,
243
+ a->client_data, state->buffer, block_length);
244
+ if (bytes_written <= 0)
245
+ ret = ARCHIVE_FATAL;
246
+ else {
247
+ a->archive.raw_position += bytes_written;
248
+ ret = ARCHIVE_OK;
249
+ }
250
+ }
251
+ if (state->buffer)
252
+ free(state->buffer);
253
+ free(state);
254
+ a->compressor.data = NULL;
255
+
256
+ return (ret);
257
+ }
@@ -0,0 +1,347 @@
1
+ /*-
2
+ * Copyright (c) 2007 Joerg Sonnenberger
3
+ * All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions
7
+ * are met:
8
+ * 1. Redistributions of source code must retain the above copyright
9
+ * notice, this list of conditions and the following disclaimer.
10
+ * 2. Redistributions in binary form must reproduce the above copyright
11
+ * notice, this list of conditions and the following disclaimer in the
12
+ * documentation and/or other materials provided with the distribution.
13
+ *
14
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
+ */
25
+
26
+ #include "archive_platform.h"
27
+
28
+ __FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_compression_program.c 201104 2009-12-28 03:14:30Z kientzle $");
29
+
30
+ /* This capability is only available on POSIX systems. */
31
+ #if (!defined(HAVE_PIPE) || !defined(HAVE_FCNTL) || \
32
+ !(defined(HAVE_FORK) || defined(HAVE_VFORK))) && (!defined(_WIN32) || defined(__CYGWIN__))
33
+ #include "archive.h"
34
+
35
+ /*
36
+ * On non-Posix systems, allow the program to build, but choke if
37
+ * this function is actually invoked.
38
+ */
39
+ int
40
+ archive_write_set_compression_program(struct archive *_a, const char *cmd)
41
+ {
42
+ archive_set_error(_a, -1,
43
+ "External compression programs not supported on this platform");
44
+ return (ARCHIVE_FATAL);
45
+ }
46
+
47
+ #else
48
+
49
+ #ifdef HAVE_SYS_WAIT_H
50
+ # include <sys/wait.h>
51
+ #endif
52
+ #ifdef HAVE_ERRNO_H
53
+ # include <errno.h>
54
+ #endif
55
+ #ifdef HAVE_FCNTL_H
56
+ # include <fcntl.h>
57
+ #endif
58
+ #ifdef HAVE_STDLIB_H
59
+ # include <stdlib.h>
60
+ #endif
61
+ #ifdef HAVE_STRING_H
62
+ # include <string.h>
63
+ #endif
64
+
65
+ #include "archive.h"
66
+ #include "archive_private.h"
67
+ #include "archive_write_private.h"
68
+
69
+ #include "filter_fork.h"
70
+
71
+ struct private_data {
72
+ char *description;
73
+ pid_t child;
74
+ int child_stdin, child_stdout;
75
+
76
+ char *child_buf;
77
+ size_t child_buf_len, child_buf_avail;
78
+ };
79
+
80
+ static int archive_compressor_program_finish(struct archive_write *);
81
+ static int archive_compressor_program_init(struct archive_write *);
82
+ static int archive_compressor_program_write(struct archive_write *,
83
+ const void *, size_t);
84
+
85
+ /*
86
+ * Allocate, initialize and return a archive object.
87
+ */
88
+ int
89
+ archive_write_set_compression_program(struct archive *_a, const char *cmd)
90
+ {
91
+ struct archive_write *a = (struct archive_write *)_a;
92
+ __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
93
+ ARCHIVE_STATE_NEW, "archive_write_set_compression_program");
94
+ a->compressor.init = &archive_compressor_program_init;
95
+ a->compressor.config = strdup(cmd);
96
+ return (ARCHIVE_OK);
97
+ }
98
+
99
+ /*
100
+ * Setup callback.
101
+ */
102
+ static int
103
+ archive_compressor_program_init(struct archive_write *a)
104
+ {
105
+ int ret;
106
+ struct private_data *state;
107
+ static const char *prefix = "Program: ";
108
+ char *cmd = a->compressor.config;
109
+
110
+ if (a->client_opener != NULL) {
111
+ ret = (a->client_opener)(&a->archive, a->client_data);
112
+ if (ret != ARCHIVE_OK)
113
+ return (ret);
114
+ }
115
+
116
+ state = (struct private_data *)malloc(sizeof(*state));
117
+ if (state == NULL) {
118
+ archive_set_error(&a->archive, ENOMEM,
119
+ "Can't allocate data for compression");
120
+ return (ARCHIVE_FATAL);
121
+ }
122
+ memset(state, 0, sizeof(*state));
123
+
124
+ a->archive.compression_code = ARCHIVE_COMPRESSION_PROGRAM;
125
+ state->description = (char *)malloc(strlen(prefix) + strlen(cmd) + 1);
126
+ strcpy(state->description, prefix);
127
+ strcat(state->description, cmd);
128
+ a->archive.compression_name = state->description;
129
+
130
+ state->child_buf_len = a->bytes_per_block;
131
+ state->child_buf_avail = 0;
132
+ state->child_buf = malloc(state->child_buf_len);
133
+
134
+ if (state->child_buf == NULL) {
135
+ archive_set_error(&a->archive, ENOMEM,
136
+ "Can't allocate data for compression buffer");
137
+ free(state);
138
+ return (ARCHIVE_FATAL);
139
+ }
140
+
141
+ if ((state->child = __archive_create_child(cmd,
142
+ &state->child_stdin, &state->child_stdout)) == -1) {
143
+ archive_set_error(&a->archive, EINVAL,
144
+ "Can't initialise filter");
145
+ free(state->child_buf);
146
+ free(state);
147
+ return (ARCHIVE_FATAL);
148
+ }
149
+
150
+ a->compressor.write = archive_compressor_program_write;
151
+ a->compressor.finish = archive_compressor_program_finish;
152
+
153
+ a->compressor.data = state;
154
+ return (0);
155
+ }
156
+
157
+ static ssize_t
158
+ child_write(struct archive_write *a, const char *buf, size_t buf_len)
159
+ {
160
+ struct private_data *state = a->compressor.data;
161
+ ssize_t ret;
162
+
163
+ if (state->child_stdin == -1)
164
+ return (-1);
165
+
166
+ if (buf_len == 0)
167
+ return (-1);
168
+
169
+ restart_write:
170
+ do {
171
+ ret = write(state->child_stdin, buf, buf_len);
172
+ } while (ret == -1 && errno == EINTR);
173
+
174
+ if (ret > 0)
175
+ return (ret);
176
+ if (ret == 0) {
177
+ close(state->child_stdin);
178
+ state->child_stdin = -1;
179
+ fcntl(state->child_stdout, F_SETFL, 0);
180
+ return (0);
181
+ }
182
+ if (ret == -1 && errno != EAGAIN)
183
+ return (-1);
184
+
185
+ if (state->child_stdout == -1) {
186
+ fcntl(state->child_stdin, F_SETFL, 0);
187
+ __archive_check_child(state->child_stdin, state->child_stdout);
188
+ goto restart_write;
189
+ }
190
+
191
+ do {
192
+ ret = read(state->child_stdout,
193
+ state->child_buf + state->child_buf_avail,
194
+ state->child_buf_len - state->child_buf_avail);
195
+ } while (ret == -1 && errno == EINTR);
196
+
197
+ if (ret == 0 || (ret == -1 && errno == EPIPE)) {
198
+ close(state->child_stdout);
199
+ state->child_stdout = -1;
200
+ fcntl(state->child_stdin, F_SETFL, 0);
201
+ goto restart_write;
202
+ }
203
+ if (ret == -1 && errno == EAGAIN) {
204
+ __archive_check_child(state->child_stdin, state->child_stdout);
205
+ goto restart_write;
206
+ }
207
+ if (ret == -1)
208
+ return (-1);
209
+
210
+ state->child_buf_avail += ret;
211
+
212
+ ret = (a->client_writer)(&a->archive, a->client_data,
213
+ state->child_buf, state->child_buf_avail);
214
+ if (ret <= 0)
215
+ return (-1);
216
+
217
+ if ((size_t)ret < state->child_buf_avail) {
218
+ memmove(state->child_buf, state->child_buf + ret,
219
+ state->child_buf_avail - ret);
220
+ }
221
+ state->child_buf_avail -= ret;
222
+ a->archive.raw_position += ret;
223
+ goto restart_write;
224
+ }
225
+
226
+ /*
227
+ * Write data to the compressed stream.
228
+ */
229
+ static int
230
+ archive_compressor_program_write(struct archive_write *a, const void *buff,
231
+ size_t length)
232
+ {
233
+ ssize_t ret;
234
+ const char *buf;
235
+
236
+ if (a->client_writer == NULL) {
237
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER,
238
+ "No write callback is registered? "
239
+ "This is probably an internal programming error.");
240
+ return (ARCHIVE_FATAL);
241
+ }
242
+
243
+ buf = buff;
244
+ while (length > 0) {
245
+ ret = child_write(a, buf, length);
246
+ if (ret == -1 || ret == 0) {
247
+ archive_set_error(&a->archive, EIO,
248
+ "Can't write to filter");
249
+ return (ARCHIVE_FATAL);
250
+ }
251
+ length -= ret;
252
+ buf += ret;
253
+ }
254
+
255
+ a->archive.file_position += length;
256
+ return (ARCHIVE_OK);
257
+ }
258
+
259
+
260
+ /*
261
+ * Finish the compression...
262
+ */
263
+ static int
264
+ archive_compressor_program_finish(struct archive_write *a)
265
+ {
266
+ int ret, status;
267
+ ssize_t bytes_read, bytes_written;
268
+ struct private_data *state;
269
+
270
+ state = (struct private_data *)a->compressor.data;
271
+ ret = 0;
272
+ if (a->client_writer == NULL) {
273
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER,
274
+ "No write callback is registered? "
275
+ "This is probably an internal programming error.");
276
+ ret = ARCHIVE_FATAL;
277
+ goto cleanup;
278
+ }
279
+
280
+ /* XXX pad compressed data. */
281
+
282
+ close(state->child_stdin);
283
+ state->child_stdin = -1;
284
+ fcntl(state->child_stdout, F_SETFL, 0);
285
+
286
+ for (;;) {
287
+ do {
288
+ bytes_read = read(state->child_stdout,
289
+ state->child_buf + state->child_buf_avail,
290
+ state->child_buf_len - state->child_buf_avail);
291
+ } while (bytes_read == -1 && errno == EINTR);
292
+
293
+ if (bytes_read == 0 || (bytes_read == -1 && errno == EPIPE))
294
+ break;
295
+
296
+ if (bytes_read == -1) {
297
+ archive_set_error(&a->archive, errno,
298
+ "Read from filter failed unexpectedly.");
299
+ ret = ARCHIVE_FATAL;
300
+ goto cleanup;
301
+ }
302
+ state->child_buf_avail += bytes_read;
303
+
304
+ bytes_written = (a->client_writer)(&a->archive, a->client_data,
305
+ state->child_buf, state->child_buf_avail);
306
+ if (bytes_written <= 0) {
307
+ ret = ARCHIVE_FATAL;
308
+ goto cleanup;
309
+ }
310
+ if ((size_t)bytes_written < state->child_buf_avail) {
311
+ memmove(state->child_buf,
312
+ state->child_buf + bytes_written,
313
+ state->child_buf_avail - bytes_written);
314
+ }
315
+ state->child_buf_avail -= bytes_written;
316
+ a->archive.raw_position += bytes_written;
317
+ }
318
+
319
+ /* XXX pad final compressed block. */
320
+
321
+ cleanup:
322
+ /* Shut down the child. */
323
+ if (state->child_stdin != -1)
324
+ close(state->child_stdin);
325
+ if (state->child_stdout != -1)
326
+ close(state->child_stdout);
327
+ while (waitpid(state->child, &status, 0) == -1 && errno == EINTR)
328
+ continue;
329
+
330
+ if (status != 0) {
331
+ archive_set_error(&a->archive, EIO,
332
+ "Filter exited with failure.");
333
+ ret = ARCHIVE_FATAL;
334
+ }
335
+
336
+ /* Release our configuration data. */
337
+ free(a->compressor.config);
338
+ a->compressor.config = NULL;
339
+
340
+ /* Release our private state data. */
341
+ free(state->child_buf);
342
+ free(state->description);
343
+ free(state);
344
+ return (ret);
345
+ }
346
+
347
+ #endif /* !defined(HAVE_PIPE) || !defined(HAVE_VFORK) || !defined(HAVE_FCNTL) */