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,303 @@
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_read_disk_set_standard_lookup.c 201109 2009-12-28 03:30:31Z kientzle $");
28
+
29
+ #ifdef HAVE_SYS_TYPES_H
30
+ #include <sys/types.h>
31
+ #endif
32
+ #ifdef HAVE_ERRNO_H
33
+ #include <errno.h>
34
+ #endif
35
+ #ifdef HAVE_GRP_H
36
+ #include <grp.h>
37
+ #endif
38
+ #ifdef HAVE_PWD_H
39
+ #include <pwd.h>
40
+ #endif
41
+ #ifdef HAVE_STDLIB_H
42
+ #include <stdlib.h>
43
+ #endif
44
+ #ifdef HAVE_STRING_H
45
+ #include <string.h>
46
+ #endif
47
+
48
+ #include "archive.h"
49
+
50
+ #if defined(_WIN32) && !defined(__CYGWIN__)
51
+ int
52
+ archive_read_disk_set_standard_lookup(struct archive *a)
53
+ {
54
+ archive_set_error(a, -1, "Standard lookups not available on Windows");
55
+ return (ARCHIVE_FATAL);
56
+ }
57
+ #else /* ! (_WIN32 && !__CYGWIN__) */
58
+ #define name_cache_size 127
59
+
60
+ static const char * const NO_NAME = "(noname)";
61
+
62
+ struct name_cache {
63
+ struct archive *archive;
64
+ char *buff;
65
+ size_t buff_size;
66
+ int probes;
67
+ int hits;
68
+ size_t size;
69
+ struct {
70
+ id_t id;
71
+ const char *name;
72
+ } cache[name_cache_size];
73
+ };
74
+
75
+ static const char * lookup_gname(void *, gid_t);
76
+ static const char * lookup_uname(void *, uid_t);
77
+ static void cleanup(void *);
78
+ static const char * lookup_gname_helper(struct name_cache *, id_t gid);
79
+ static const char * lookup_uname_helper(struct name_cache *, id_t uid);
80
+
81
+ /*
82
+ * Installs functions that use getpwuid()/getgrgid()---along with
83
+ * a simple cache to accelerate such lookups---into the archive_read_disk
84
+ * object. This is in a separate file because getpwuid()/getgrgid()
85
+ * can pull in a LOT of library code (including NIS/LDAP functions, which
86
+ * pull in DNS resolveers, etc). This can easily top 500kB, which makes
87
+ * it inappropriate for some space-constrained applications.
88
+ *
89
+ * Applications that are size-sensitive may want to just use the
90
+ * real default functions (defined in archive_read_disk.c) that just
91
+ * use the uid/gid without the lookup. Or define your own custom functions
92
+ * if you prefer.
93
+ */
94
+ int
95
+ archive_read_disk_set_standard_lookup(struct archive *a)
96
+ {
97
+ struct name_cache *ucache = malloc(sizeof(struct name_cache));
98
+ struct name_cache *gcache = malloc(sizeof(struct name_cache));
99
+
100
+ if (ucache == NULL || gcache == NULL) {
101
+ archive_set_error(a, ENOMEM,
102
+ "Can't allocate uname/gname lookup cache");
103
+ free(ucache);
104
+ free(gcache);
105
+ return (ARCHIVE_FATAL);
106
+ }
107
+
108
+ memset(ucache, 0, sizeof(*ucache));
109
+ ucache->archive = a;
110
+ ucache->size = name_cache_size;
111
+ memset(gcache, 0, sizeof(*gcache));
112
+ gcache->archive = a;
113
+ gcache->size = name_cache_size;
114
+
115
+ archive_read_disk_set_gname_lookup(a, gcache, lookup_gname, cleanup);
116
+ archive_read_disk_set_uname_lookup(a, ucache, lookup_uname, cleanup);
117
+
118
+ return (ARCHIVE_OK);
119
+ }
120
+
121
+ static void
122
+ cleanup(void *data)
123
+ {
124
+ struct name_cache *cache = (struct name_cache *)data;
125
+ size_t i;
126
+
127
+ if (cache != NULL) {
128
+ for (i = 0; i < cache->size; i++) {
129
+ if (cache->cache[i].name != NULL &&
130
+ cache->cache[i].name != NO_NAME)
131
+ free((void *)(uintptr_t)cache->cache[i].name);
132
+ }
133
+ free(cache->buff);
134
+ free(cache);
135
+ }
136
+ }
137
+
138
+ /*
139
+ * Lookup uid/gid from uname/gname, return NULL if no match.
140
+ */
141
+ static const char *
142
+ lookup_name(struct name_cache *cache,
143
+ const char * (*lookup_fn)(struct name_cache *, id_t), id_t id)
144
+ {
145
+ const char *name;
146
+ int slot;
147
+
148
+
149
+ cache->probes++;
150
+
151
+ slot = id % cache->size;
152
+ if (cache->cache[slot].name != NULL) {
153
+ if (cache->cache[slot].id == id) {
154
+ cache->hits++;
155
+ if (cache->cache[slot].name == NO_NAME)
156
+ return (NULL);
157
+ return (cache->cache[slot].name);
158
+ }
159
+ if (cache->cache[slot].name != NO_NAME)
160
+ free((void *)(uintptr_t)cache->cache[slot].name);
161
+ cache->cache[slot].name = NULL;
162
+ }
163
+
164
+ name = (lookup_fn)(cache, id);
165
+ if (name == NULL) {
166
+ /* Cache and return the negative response. */
167
+ cache->cache[slot].name = NO_NAME;
168
+ cache->cache[slot].id = id;
169
+ return (NULL);
170
+ }
171
+
172
+ cache->cache[slot].name = name;
173
+ cache->cache[slot].id = id;
174
+ return (cache->cache[slot].name);
175
+ }
176
+
177
+ static const char *
178
+ lookup_uname(void *data, uid_t uid)
179
+ {
180
+ struct name_cache *uname_cache = (struct name_cache *)data;
181
+ return (lookup_name(uname_cache,
182
+ &lookup_uname_helper, (id_t)uid));
183
+ }
184
+
185
+ #if HAVE_GETPWUID_R
186
+ static const char *
187
+ lookup_uname_helper(struct name_cache *cache, id_t id)
188
+ {
189
+ struct passwd pwent, *result;
190
+ int r;
191
+
192
+ if (cache->buff_size == 0) {
193
+ cache->buff_size = 256;
194
+ cache->buff = malloc(cache->buff_size);
195
+ }
196
+ if (cache->buff == NULL)
197
+ return (NULL);
198
+ for (;;) {
199
+ result = &pwent; /* Old getpwuid_r ignores last arg. */
200
+ r = getpwuid_r((uid_t)id, &pwent,
201
+ cache->buff, cache->buff_size, &result);
202
+ if (r == 0)
203
+ break;
204
+ if (r != ERANGE)
205
+ break;
206
+ /* ERANGE means our buffer was too small, but POSIX
207
+ * doesn't tell us how big the buffer should be, so
208
+ * we just double it and try again. Because the buffer
209
+ * is kept around in the cache object, we shouldn't
210
+ * have to do this very often. */
211
+ cache->buff_size *= 2;
212
+ cache->buff = realloc(cache->buff, cache->buff_size);
213
+ if (cache->buff == NULL)
214
+ break;
215
+ }
216
+ if (r != 0) {
217
+ archive_set_error(cache->archive, errno,
218
+ "Can't lookup user for id %d", (int)id);
219
+ return (NULL);
220
+ }
221
+ if (result == NULL)
222
+ return (NULL);
223
+
224
+ return strdup(result->pw_name);
225
+ }
226
+ #else
227
+ static const char *
228
+ lookup_uname_helper(struct name_cache *cache, id_t id)
229
+ {
230
+ struct passwd *result;
231
+
232
+ result = getpwuid((uid_t)id);
233
+
234
+ if (result == NULL)
235
+ return (NULL);
236
+
237
+ return strdup(result->pw_name);
238
+ }
239
+ #endif
240
+
241
+ static const char *
242
+ lookup_gname(void *data, gid_t gid)
243
+ {
244
+ struct name_cache *gname_cache = (struct name_cache *)data;
245
+ return (lookup_name(gname_cache,
246
+ &lookup_gname_helper, (id_t)gid));
247
+ }
248
+
249
+ #if HAVE_GETGRGID_R
250
+ static const char *
251
+ lookup_gname_helper(struct name_cache *cache, id_t id)
252
+ {
253
+ struct group grent, *result;
254
+ int r;
255
+
256
+ if (cache->buff_size == 0) {
257
+ cache->buff_size = 256;
258
+ cache->buff = malloc(cache->buff_size);
259
+ }
260
+ if (cache->buff == NULL)
261
+ return (NULL);
262
+ for (;;) {
263
+ result = &grent; /* Old getgrgid_r ignores last arg. */
264
+ r = getgrgid_r((gid_t)id, &grent,
265
+ cache->buff, cache->buff_size, &result);
266
+ if (r == 0)
267
+ break;
268
+ if (r != ERANGE)
269
+ break;
270
+ /* ERANGE means our buffer was too small, but POSIX
271
+ * doesn't tell us how big the buffer should be, so
272
+ * we just double it and try again. */
273
+ cache->buff_size *= 2;
274
+ cache->buff = realloc(cache->buff, cache->buff_size);
275
+ if (cache->buff == NULL)
276
+ break;
277
+ }
278
+ if (r != 0) {
279
+ archive_set_error(cache->archive, errno,
280
+ "Can't lookup group for id %d", (int)id);
281
+ return (NULL);
282
+ }
283
+ if (result == NULL)
284
+ return (NULL);
285
+
286
+ return strdup(result->gr_name);
287
+ }
288
+ #else
289
+ static const char *
290
+ lookup_gname_helper(struct name_cache *cache, id_t id)
291
+ {
292
+ struct group *result;
293
+
294
+ result = getgrgid((gid_t)id);
295
+
296
+ if (result == NULL)
297
+ return (NULL);
298
+
299
+ return strdup(result->gr_name);
300
+ }
301
+ #endif
302
+
303
+ #endif /* ! (_WIN32 && !__CYGWIN__) */
@@ -0,0 +1,182 @@
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: src/lib/libarchive/archive_read_extract.c,v 1.61 2008/05/26 17:00:22 kientzle Exp $");
28
+
29
+ #ifdef HAVE_SYS_TYPES_H
30
+ #include <sys/types.h>
31
+ #endif
32
+ #ifdef HAVE_ERRNO_H
33
+ #include <errno.h>
34
+ #endif
35
+ #ifdef HAVE_STDLIB_H
36
+ #include <stdlib.h>
37
+ #endif
38
+ #ifdef HAVE_STRING_H
39
+ #include <string.h>
40
+ #endif
41
+
42
+ #include "archive.h"
43
+ #include "archive_private.h"
44
+ #include "archive_read_private.h"
45
+ #include "archive_write_disk_private.h"
46
+
47
+ struct extract {
48
+ struct archive *ad; /* archive_write_disk object */
49
+
50
+ /* Progress function invoked during extract. */
51
+ void (*extract_progress)(void *);
52
+ void *extract_progress_user_data;
53
+ };
54
+
55
+ static int archive_read_extract_cleanup(struct archive_read *);
56
+ static int copy_data(struct archive *ar, struct archive *aw);
57
+ static struct extract *get_extract(struct archive_read *);
58
+
59
+ static struct extract *
60
+ get_extract(struct archive_read *a)
61
+ {
62
+ /* If we haven't initialized, do it now. */
63
+ /* This also sets up a lot of global state. */
64
+ if (a->extract == NULL) {
65
+ a->extract = (struct extract *)malloc(sizeof(*a->extract));
66
+ if (a->extract == NULL) {
67
+ archive_set_error(&a->archive, ENOMEM, "Can't extract");
68
+ return (NULL);
69
+ }
70
+ memset(a->extract, 0, sizeof(*a->extract));
71
+ a->extract->ad = archive_write_disk_new();
72
+ if (a->extract->ad == NULL) {
73
+ archive_set_error(&a->archive, ENOMEM, "Can't extract");
74
+ return (NULL);
75
+ }
76
+ archive_write_disk_set_standard_lookup(a->extract->ad);
77
+ a->cleanup_archive_extract = archive_read_extract_cleanup;
78
+ }
79
+ return (a->extract);
80
+ }
81
+
82
+ int
83
+ archive_read_extract(struct archive *_a, struct archive_entry *entry, int flags)
84
+ {
85
+ struct extract *extract;
86
+
87
+ extract = get_extract((struct archive_read *)_a);
88
+ if (extract == NULL)
89
+ return (ARCHIVE_FATAL);
90
+ archive_write_disk_set_options(extract->ad, flags);
91
+ return (archive_read_extract2(_a, entry, extract->ad));
92
+ }
93
+
94
+ int
95
+ archive_read_extract2(struct archive *_a, struct archive_entry *entry,
96
+ struct archive *ad)
97
+ {
98
+ struct archive_read *a = (struct archive_read *)_a;
99
+ int r, r2;
100
+
101
+ /* Set up for this particular entry. */
102
+ archive_write_disk_set_skip_file(ad,
103
+ a->skip_file_dev, a->skip_file_ino);
104
+ r = archive_write_header(ad, entry);
105
+ if (r < ARCHIVE_WARN)
106
+ r = ARCHIVE_WARN;
107
+ if (r != ARCHIVE_OK)
108
+ /* If _write_header failed, copy the error. */
109
+ archive_copy_error(&a->archive, ad);
110
+ else
111
+ /* Otherwise, pour data into the entry. */
112
+ r = copy_data(_a, ad);
113
+ r2 = archive_write_finish_entry(ad);
114
+ if (r2 < ARCHIVE_WARN)
115
+ r2 = ARCHIVE_WARN;
116
+ /* Use the first message. */
117
+ if (r2 != ARCHIVE_OK && r == ARCHIVE_OK)
118
+ archive_copy_error(&a->archive, ad);
119
+ /* Use the worst error return. */
120
+ if (r2 < r)
121
+ r = r2;
122
+ return (r);
123
+ }
124
+
125
+ void
126
+ archive_read_extract_set_progress_callback(struct archive *_a,
127
+ void (*progress_func)(void *), void *user_data)
128
+ {
129
+ struct archive_read *a = (struct archive_read *)_a;
130
+ struct extract *extract = get_extract(a);
131
+ if (extract != NULL) {
132
+ extract->extract_progress = progress_func;
133
+ extract->extract_progress_user_data = user_data;
134
+ }
135
+ }
136
+
137
+ static int
138
+ copy_data(struct archive *ar, struct archive *aw)
139
+ {
140
+ off_t offset;
141
+ const void *buff;
142
+ struct extract *extract;
143
+ size_t size;
144
+ int r;
145
+
146
+ extract = get_extract((struct archive_read *)ar);
147
+ for (;;) {
148
+ r = archive_read_data_block(ar, &buff, &size, &offset);
149
+ if (r == ARCHIVE_EOF)
150
+ return (ARCHIVE_OK);
151
+ if (r != ARCHIVE_OK)
152
+ return (r);
153
+ r = archive_write_data_block(aw, buff, size, offset);
154
+ if (r < ARCHIVE_WARN)
155
+ r = ARCHIVE_WARN;
156
+ if (r != ARCHIVE_OK) {
157
+ archive_set_error(ar, archive_errno(aw),
158
+ "%s", archive_error_string(aw));
159
+ return (r);
160
+ }
161
+ if (extract->extract_progress)
162
+ (extract->extract_progress)
163
+ (extract->extract_progress_user_data);
164
+ }
165
+ }
166
+
167
+ /*
168
+ * Cleanup function for archive_extract.
169
+ */
170
+ static int
171
+ archive_read_extract_cleanup(struct archive_read *a)
172
+ {
173
+ int ret = ARCHIVE_OK;
174
+
175
+ #if ARCHIVE_API_VERSION > 1
176
+ ret =
177
+ #endif
178
+ archive_write_finish(a->extract->ad);
179
+ free(a->extract);
180
+ a->extract = NULL;
181
+ return (ret);
182
+ }
@@ -0,0 +1,190 @@
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_read_open_fd.c 201103 2009-12-28 03:13:49Z kientzle $");
28
+
29
+ #ifdef HAVE_SYS_STAT_H
30
+ #include <sys/stat.h>
31
+ #endif
32
+ #ifdef HAVE_ERRNO_H
33
+ #include <errno.h>
34
+ #endif
35
+ #ifdef HAVE_FCNTL_H
36
+ #include <fcntl.h>
37
+ #endif
38
+ #ifdef HAVE_IO_H
39
+ #include <io.h>
40
+ #endif
41
+ #ifdef HAVE_STDLIB_H
42
+ #include <stdlib.h>
43
+ #endif
44
+ #ifdef HAVE_STRING_H
45
+ #include <string.h>
46
+ #endif
47
+ #ifdef HAVE_UNISTD_H
48
+ #include <unistd.h>
49
+ #endif
50
+
51
+ #include "archive.h"
52
+
53
+ struct read_fd_data {
54
+ int fd;
55
+ size_t block_size;
56
+ char can_skip;
57
+ void *buffer;
58
+ };
59
+
60
+ static int file_close(struct archive *, void *);
61
+ static ssize_t file_read(struct archive *, void *, const void **buff);
62
+ #if ARCHIVE_API_VERSION < 2
63
+ static ssize_t file_skip(struct archive *, void *, size_t request);
64
+ #else
65
+ static off_t file_skip(struct archive *, void *, off_t request);
66
+ #endif
67
+
68
+ int
69
+ archive_read_open_fd(struct archive *a, int fd, size_t block_size)
70
+ {
71
+ struct stat st;
72
+ struct read_fd_data *mine;
73
+ void *b;
74
+
75
+ archive_clear_error(a);
76
+ if (fstat(fd, &st) != 0) {
77
+ archive_set_error(a, errno, "Can't stat fd %d", fd);
78
+ return (ARCHIVE_FATAL);
79
+ }
80
+
81
+ mine = (struct read_fd_data *)malloc(sizeof(*mine));
82
+ b = malloc(block_size);
83
+ if (mine == NULL || b == NULL) {
84
+ archive_set_error(a, ENOMEM, "No memory");
85
+ free(mine);
86
+ free(b);
87
+ return (ARCHIVE_FATAL);
88
+ }
89
+ mine->block_size = block_size;
90
+ mine->buffer = b;
91
+ mine->fd = fd;
92
+ /*
93
+ * Skip support is a performance optimization for anything
94
+ * that supports lseek(). On FreeBSD, only regular files and
95
+ * raw disk devices support lseek() and there's no portable
96
+ * way to determine if a device is a raw disk device, so we
97
+ * only enable this optimization for regular files.
98
+ */
99
+ if (S_ISREG(st.st_mode)) {
100
+ archive_read_extract_set_skip_file(a, st.st_dev, st.st_ino);
101
+ mine->can_skip = 1;
102
+ } else
103
+ mine->can_skip = 0;
104
+ #if defined(__CYGWIN__) || defined(_WIN32)
105
+ setmode(mine->fd, O_BINARY);
106
+ #endif
107
+
108
+ return (archive_read_open2(a, mine,
109
+ NULL, file_read, file_skip, file_close));
110
+ }
111
+
112
+ static ssize_t
113
+ file_read(struct archive *a, void *client_data, const void **buff)
114
+ {
115
+ struct read_fd_data *mine = (struct read_fd_data *)client_data;
116
+ ssize_t bytes_read;
117
+
118
+ *buff = mine->buffer;
119
+ for (;;) {
120
+ bytes_read = read(mine->fd, mine->buffer, mine->block_size);
121
+ if (bytes_read < 0) {
122
+ if (errno == EINTR)
123
+ continue;
124
+ archive_set_error(a, errno, "Error reading fd %d", mine->fd);
125
+ }
126
+ return (bytes_read);
127
+ }
128
+ }
129
+
130
+ #if ARCHIVE_API_VERSION < 2
131
+ static ssize_t
132
+ file_skip(struct archive *a, void *client_data, size_t request)
133
+ #else
134
+ static off_t
135
+ file_skip(struct archive *a, void *client_data, off_t request)
136
+ #endif
137
+ {
138
+ struct read_fd_data *mine = (struct read_fd_data *)client_data;
139
+ off_t old_offset, new_offset;
140
+
141
+ if (!mine->can_skip)
142
+ return (0);
143
+
144
+ /* Reduce request to the next smallest multiple of block_size */
145
+ request = (request / mine->block_size) * mine->block_size;
146
+ if (request == 0)
147
+ return (0);
148
+
149
+ /*
150
+ * Hurray for lazy evaluation: if the first lseek fails, the second
151
+ * one will not be executed.
152
+ */
153
+ if (((old_offset = lseek(mine->fd, 0, SEEK_CUR)) < 0) ||
154
+ ((new_offset = lseek(mine->fd, request, SEEK_CUR)) < 0))
155
+ {
156
+ /* If seek failed once, it will probably fail again. */
157
+ mine->can_skip = 0;
158
+
159
+ if (errno == ESPIPE)
160
+ {
161
+ /*
162
+ * Failure to lseek() can be caused by the file
163
+ * descriptor pointing to a pipe, socket or FIFO.
164
+ * Return 0 here, so the compression layer will use
165
+ * read()s instead to advance the file descriptor.
166
+ * It's slower of course, but works as well.
167
+ */
168
+ return (0);
169
+ }
170
+ /*
171
+ * There's been an error other than ESPIPE. This is most
172
+ * likely caused by a programmer error (too large request)
173
+ * or a corrupted archive file.
174
+ */
175
+ archive_set_error(a, errno, "Error seeking");
176
+ return (-1);
177
+ }
178
+ return (new_offset - old_offset);
179
+ }
180
+
181
+ static int
182
+ file_close(struct archive *a, void *client_data)
183
+ {
184
+ struct read_fd_data *mine = (struct read_fd_data *)client_data;
185
+
186
+ (void)a; /* UNUSED */
187
+ free(mine->buffer);
188
+ free(mine);
189
+ return (ARCHIVE_OK);
190
+ }