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,38 @@
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
+ * in this position and unchanged.
11
+ * 2. Redistributions in binary form must reproduce the above copyright
12
+ * notice, this list of conditions and the following disclaimer in the
13
+ * documentation and/or other materials provided with the distribution.
14
+ *
15
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+ *
26
+ * $FreeBSD: head/lib/libarchive/archive_write_disk_private.h 201086 2009-12-28 02:17:53Z kientzle $
27
+ */
28
+
29
+ #ifndef __LIBARCHIVE_BUILD
30
+ #error This header is only to be used internally to libarchive.
31
+ #endif
32
+
33
+ #ifndef ARCHIVE_WRITE_DISK_PRIVATE_H_INCLUDED
34
+ #define ARCHIVE_WRITE_DISK_PRIVATE_H_INCLUDED
35
+
36
+ struct archive_write_disk;
37
+
38
+ #endif
@@ -0,0 +1,262 @@
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_disk_set_standard_lookup.c 201083 2009-12-28 02:09:57Z 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
+ #include "archive_private.h"
50
+ #include "archive_read_private.h"
51
+ #include "archive_write_disk_private.h"
52
+
53
+ struct bucket {
54
+ char *name;
55
+ int hash;
56
+ id_t id;
57
+ };
58
+
59
+ static const size_t cache_size = 127;
60
+ static unsigned int hash(const char *);
61
+ static gid_t lookup_gid(void *, const char *uname, gid_t);
62
+ static uid_t lookup_uid(void *, const char *uname, uid_t);
63
+ static void cleanup(void *);
64
+
65
+ /*
66
+ * Installs functions that use getpwnam()/getgrnam()---along with
67
+ * a simple cache to accelerate such lookups---into the archive_write_disk
68
+ * object. This is in a separate file because getpwnam()/getgrnam()
69
+ * can pull in a LOT of library code (including NIS/LDAP functions, which
70
+ * pull in DNS resolveers, etc). This can easily top 500kB, which makes
71
+ * it inappropriate for some space-constrained applications.
72
+ *
73
+ * Applications that are size-sensitive may want to just use the
74
+ * real default functions (defined in archive_write_disk.c) that just
75
+ * use the uid/gid without the lookup. Or define your own custom functions
76
+ * if you prefer.
77
+ *
78
+ * TODO: Replace these hash tables with simpler move-to-front LRU
79
+ * lists with a bounded size (128 items?). The hash is a bit faster,
80
+ * but has a bad pathology in which it thrashes a single bucket. Even
81
+ * walking a list of 128 items is a lot faster than calling
82
+ * getpwnam()!
83
+ */
84
+ int
85
+ archive_write_disk_set_standard_lookup(struct archive *a)
86
+ {
87
+ struct bucket *ucache = malloc(cache_size * sizeof(struct bucket));
88
+ struct bucket *gcache = malloc(cache_size * sizeof(struct bucket));
89
+ memset(ucache, 0, cache_size * sizeof(struct bucket));
90
+ memset(gcache, 0, cache_size * sizeof(struct bucket));
91
+ archive_write_disk_set_group_lookup(a, gcache, lookup_gid, cleanup);
92
+ archive_write_disk_set_user_lookup(a, ucache, lookup_uid, cleanup);
93
+ return (ARCHIVE_OK);
94
+ }
95
+
96
+ static gid_t
97
+ lookup_gid(void *private_data, const char *gname, gid_t gid)
98
+ {
99
+ int h;
100
+ struct bucket *b;
101
+ struct bucket *gcache = (struct bucket *)private_data;
102
+
103
+ /* If no gname, just use the gid provided. */
104
+ if (gname == NULL || *gname == '\0')
105
+ return (gid);
106
+
107
+ /* Try to find gname in the cache. */
108
+ h = hash(gname);
109
+ b = &gcache[h % cache_size ];
110
+ if (b->name != NULL && b->hash == h && strcmp(gname, b->name) == 0)
111
+ return ((gid_t)b->id);
112
+
113
+ /* Free the cache slot for a new entry. */
114
+ if (b->name != NULL)
115
+ free(b->name);
116
+ b->name = strdup(gname);
117
+ /* Note: If strdup fails, that's okay; we just won't cache. */
118
+ b->hash = h;
119
+ #if HAVE_GRP_H
120
+ # if HAVE_GETGRNAM_R
121
+ {
122
+ char _buffer[128];
123
+ size_t bufsize = 128;
124
+ char *buffer = _buffer;
125
+ struct group grent, *result;
126
+ int r;
127
+
128
+ for (;;) {
129
+ result = &grent; /* Old getgrnam_r ignores last arg. */
130
+ r = getgrnam_r(gname, &grent, buffer, bufsize, &result);
131
+ if (r == 0)
132
+ break;
133
+ if (r != ERANGE)
134
+ break;
135
+ bufsize *= 2;
136
+ if (buffer != _buffer)
137
+ free(buffer);
138
+ buffer = malloc(bufsize);
139
+ if (buffer == NULL)
140
+ break;
141
+ }
142
+ if (result != NULL)
143
+ gid = result->gr_gid;
144
+ if (buffer != _buffer)
145
+ free(buffer);
146
+ }
147
+ # else /* HAVE_GETGRNAM_R */
148
+ {
149
+ struct group *result;
150
+
151
+ result = getgrnam(gname);
152
+ if (result != NULL)
153
+ gid = result->gr_gid;
154
+ }
155
+ # endif /* HAVE_GETGRNAM_R */
156
+ #elif defined(_WIN32) && !defined(__CYGWIN__)
157
+ /* TODO: do a gname->gid lookup for Windows. */
158
+ #else
159
+ #error No way to perform gid lookups on this platform
160
+ #endif
161
+ b->id = gid;
162
+
163
+ return (gid);
164
+ }
165
+
166
+ static uid_t
167
+ lookup_uid(void *private_data, const char *uname, uid_t uid)
168
+ {
169
+ int h;
170
+ struct bucket *b;
171
+ struct bucket *ucache = (struct bucket *)private_data;
172
+
173
+ /* If no uname, just use the uid provided. */
174
+ if (uname == NULL || *uname == '\0')
175
+ return (uid);
176
+
177
+ /* Try to find uname in the cache. */
178
+ h = hash(uname);
179
+ b = &ucache[h % cache_size ];
180
+ if (b->name != NULL && b->hash == h && strcmp(uname, b->name) == 0)
181
+ return ((uid_t)b->id);
182
+
183
+ /* Free the cache slot for a new entry. */
184
+ if (b->name != NULL)
185
+ free(b->name);
186
+ b->name = strdup(uname);
187
+ /* Note: If strdup fails, that's okay; we just won't cache. */
188
+ b->hash = h;
189
+ #if HAVE_PWD_H
190
+ # if HAVE_GETPWNAM_R
191
+ {
192
+ char _buffer[128];
193
+ size_t bufsize = 128;
194
+ char *buffer = _buffer;
195
+ struct passwd pwent, *result;
196
+ int r;
197
+
198
+ for (;;) {
199
+ result = &pwent; /* Old getpwnam_r ignores last arg. */
200
+ r = getpwnam_r(uname, &pwent, buffer, bufsize, &result);
201
+ if (r == 0)
202
+ break;
203
+ if (r != ERANGE)
204
+ break;
205
+ bufsize *= 2;
206
+ if (buffer != _buffer)
207
+ free(buffer);
208
+ buffer = malloc(bufsize);
209
+ if (buffer == NULL)
210
+ break;
211
+ }
212
+ if (result != NULL)
213
+ uid = result->pw_uid;
214
+ if (buffer != _buffer)
215
+ free(buffer);
216
+ }
217
+ # else /* HAVE_GETPWNAM_R */
218
+ {
219
+ struct passwd *result;
220
+
221
+ result = getpwnam(uname);
222
+ if (result != NULL)
223
+ uid = result->pw_uid;
224
+ }
225
+ #endif /* HAVE_GETPWNAM_R */
226
+ #elif defined(_WIN32) && !defined(__CYGWIN__)
227
+ /* TODO: do a uname->uid lookup for Windows. */
228
+ #else
229
+ #error No way to look up uids on this platform
230
+ #endif
231
+ b->id = uid;
232
+
233
+ return (uid);
234
+ }
235
+
236
+ static void
237
+ cleanup(void *private)
238
+ {
239
+ size_t i;
240
+ struct bucket *cache = (struct bucket *)private;
241
+
242
+ for (i = 0; i < cache_size; i++)
243
+ free(cache[i].name);
244
+ free(cache);
245
+ }
246
+
247
+
248
+ static unsigned int
249
+ hash(const char *p)
250
+ {
251
+ /* A 32-bit version of Peter Weinberger's (PJW) hash algorithm,
252
+ as used by ELF for hashing function names. */
253
+ unsigned g, h = 0;
254
+ while (*p != '\0') {
255
+ h = (h << 4) + *p++;
256
+ if ((g = h & 0xF0000000) != 0) {
257
+ h ^= g >> 24;
258
+ h &= 0x0FFFFFFF;
259
+ }
260
+ }
261
+ return h;
262
+ }
@@ -0,0 +1,141 @@
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_open_fd.c 201093 2009-12-28 02:28:44Z 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 write_fd_data {
54
+ off_t offset;
55
+ int fd;
56
+ };
57
+
58
+ static int file_close(struct archive *, void *);
59
+ static int file_open(struct archive *, void *);
60
+ static ssize_t file_write(struct archive *, void *, const void *buff, size_t);
61
+
62
+ int
63
+ archive_write_open_fd(struct archive *a, int fd)
64
+ {
65
+ struct write_fd_data *mine;
66
+
67
+ mine = (struct write_fd_data *)malloc(sizeof(*mine));
68
+ if (mine == NULL) {
69
+ archive_set_error(a, ENOMEM, "No memory");
70
+ return (ARCHIVE_FATAL);
71
+ }
72
+ mine->fd = fd;
73
+ #if defined(__CYGWIN__) || defined(_WIN32)
74
+ setmode(mine->fd, O_BINARY);
75
+ #endif
76
+ return (archive_write_open(a, mine,
77
+ file_open, file_write, file_close));
78
+ }
79
+
80
+ static int
81
+ file_open(struct archive *a, void *client_data)
82
+ {
83
+ struct write_fd_data *mine;
84
+ struct stat st;
85
+
86
+ mine = (struct write_fd_data *)client_data;
87
+
88
+ if (fstat(mine->fd, &st) != 0) {
89
+ archive_set_error(a, errno, "Couldn't stat fd %d", mine->fd);
90
+ return (ARCHIVE_FATAL);
91
+ }
92
+
93
+ /*
94
+ * If this is a regular file, don't add it to itself.
95
+ */
96
+ if (S_ISREG(st.st_mode))
97
+ archive_write_set_skip_file(a, st.st_dev, st.st_ino);
98
+
99
+ /*
100
+ * If client hasn't explicitly set the last block handling,
101
+ * then set it here.
102
+ */
103
+ if (archive_write_get_bytes_in_last_block(a) < 0) {
104
+ /* If the output is a block or character device, fifo,
105
+ * or stdout, pad the last block, otherwise leave it
106
+ * unpadded. */
107
+ if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode) ||
108
+ S_ISFIFO(st.st_mode) || (mine->fd == 1))
109
+ /* Last block will be fully padded. */
110
+ archive_write_set_bytes_in_last_block(a, 0);
111
+ else
112
+ archive_write_set_bytes_in_last_block(a, 1);
113
+ }
114
+
115
+ return (ARCHIVE_OK);
116
+ }
117
+
118
+ static ssize_t
119
+ file_write(struct archive *a, void *client_data, const void *buff, size_t length)
120
+ {
121
+ struct write_fd_data *mine;
122
+ ssize_t bytesWritten;
123
+
124
+ mine = (struct write_fd_data *)client_data;
125
+ bytesWritten = write(mine->fd, buff, length);
126
+ if (bytesWritten <= 0) {
127
+ archive_set_error(a, errno, "Write error");
128
+ return (-1);
129
+ }
130
+ return (bytesWritten);
131
+ }
132
+
133
+ static int
134
+ file_close(struct archive *a, void *client_data)
135
+ {
136
+ struct write_fd_data *mine = (struct write_fd_data *)client_data;
137
+
138
+ (void)a; /* UNUSED */
139
+ free(mine);
140
+ return (ARCHIVE_OK);
141
+ }
@@ -0,0 +1,105 @@
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_write_open_file.c,v 1.19 2007/01/09 08:05:56 kientzle Exp $");
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_STDLIB_H
39
+ #include <stdlib.h>
40
+ #endif
41
+ #ifdef HAVE_STRING_H
42
+ #include <string.h>
43
+ #endif
44
+ #ifdef HAVE_UNISTD_H
45
+ #include <unistd.h>
46
+ #endif
47
+
48
+ #include "archive.h"
49
+
50
+ struct write_FILE_data {
51
+ FILE *f;
52
+ };
53
+
54
+ static int file_close(struct archive *, void *);
55
+ static int file_open(struct archive *, void *);
56
+ static ssize_t file_write(struct archive *, void *, const void *buff, size_t);
57
+
58
+ int
59
+ archive_write_open_FILE(struct archive *a, FILE *f)
60
+ {
61
+ struct write_FILE_data *mine;
62
+
63
+ mine = (struct write_FILE_data *)malloc(sizeof(*mine));
64
+ if (mine == NULL) {
65
+ archive_set_error(a, ENOMEM, "No memory");
66
+ return (ARCHIVE_FATAL);
67
+ }
68
+ mine->f = f;
69
+ return (archive_write_open(a, mine,
70
+ file_open, file_write, file_close));
71
+ }
72
+
73
+ static int
74
+ file_open(struct archive *a, void *client_data)
75
+ {
76
+ (void)a; /* UNUSED */
77
+ (void)client_data; /* UNUSED */
78
+
79
+ return (ARCHIVE_OK);
80
+ }
81
+
82
+ static ssize_t
83
+ file_write(struct archive *a, void *client_data, const void *buff, size_t length)
84
+ {
85
+ struct write_FILE_data *mine;
86
+ size_t bytesWritten;
87
+
88
+ mine = client_data;
89
+ bytesWritten = fwrite(buff, 1, length, mine->f);
90
+ if (bytesWritten < length) {
91
+ archive_set_error(a, errno, "Write error");
92
+ return (-1);
93
+ }
94
+ return (bytesWritten);
95
+ }
96
+
97
+ static int
98
+ file_close(struct archive *a, void *client_data)
99
+ {
100
+ struct write_FILE_data *mine = client_data;
101
+
102
+ (void)a; /* UNUSED */
103
+ free(mine);
104
+ return (ARCHIVE_OK);
105
+ }
@@ -0,0 +1,162 @@
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_open_filename.c 191165 2009-04-17 00:39:35Z 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_STDLIB_H
39
+ #include <stdlib.h>
40
+ #endif
41
+ #ifdef HAVE_STRING_H
42
+ #include <string.h>
43
+ #endif
44
+ #ifdef HAVE_UNISTD_H
45
+ #include <unistd.h>
46
+ #endif
47
+
48
+ #include "archive.h"
49
+
50
+ #ifndef O_BINARY
51
+ #define O_BINARY 0
52
+ #endif
53
+
54
+ struct write_file_data {
55
+ int fd;
56
+ char filename[1];
57
+ };
58
+
59
+ static int file_close(struct archive *, void *);
60
+ static int file_open(struct archive *, void *);
61
+ static ssize_t file_write(struct archive *, void *, const void *buff, size_t);
62
+
63
+ int
64
+ archive_write_open_file(struct archive *a, const char *filename)
65
+ {
66
+ return (archive_write_open_filename(a, filename));
67
+ }
68
+
69
+ int
70
+ archive_write_open_filename(struct archive *a, const char *filename)
71
+ {
72
+ struct write_file_data *mine;
73
+
74
+ if (filename == NULL || filename[0] == '\0')
75
+ return (archive_write_open_fd(a, 1));
76
+
77
+ mine = (struct write_file_data *)malloc(sizeof(*mine) + strlen(filename));
78
+ if (mine == NULL) {
79
+ archive_set_error(a, ENOMEM, "No memory");
80
+ return (ARCHIVE_FATAL);
81
+ }
82
+ strcpy(mine->filename, filename);
83
+ mine->fd = -1;
84
+ return (archive_write_open(a, mine,
85
+ file_open, file_write, file_close));
86
+ }
87
+
88
+ static int
89
+ file_open(struct archive *a, void *client_data)
90
+ {
91
+ int flags;
92
+ struct write_file_data *mine;
93
+ struct stat st;
94
+
95
+ mine = (struct write_file_data *)client_data;
96
+ flags = O_WRONLY | O_CREAT | O_TRUNC | O_BINARY;
97
+
98
+ /*
99
+ * Open the file.
100
+ */
101
+ mine->fd = open(mine->filename, flags, 0666);
102
+ if (mine->fd < 0) {
103
+ archive_set_error(a, errno, "Failed to open '%s'",
104
+ mine->filename);
105
+ return (ARCHIVE_FATAL);
106
+ }
107
+
108
+ if (fstat(mine->fd, &st) != 0) {
109
+ archive_set_error(a, errno, "Couldn't stat '%s'",
110
+ mine->filename);
111
+ return (ARCHIVE_FATAL);
112
+ }
113
+
114
+ /*
115
+ * Set up default last block handling.
116
+ */
117
+ if (archive_write_get_bytes_in_last_block(a) < 0) {
118
+ if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode) ||
119
+ S_ISFIFO(st.st_mode))
120
+ /* Pad last block when writing to device or FIFO. */
121
+ archive_write_set_bytes_in_last_block(a, 0);
122
+ else
123
+ /* Don't pad last block otherwise. */
124
+ archive_write_set_bytes_in_last_block(a, 1);
125
+ }
126
+
127
+ /*
128
+ * If the output file is a regular file, don't add it to
129
+ * itself. If it's a device file, it's okay to add the device
130
+ * entry to the output archive.
131
+ */
132
+ if (S_ISREG(st.st_mode))
133
+ archive_write_set_skip_file(a, st.st_dev, st.st_ino);
134
+
135
+ return (ARCHIVE_OK);
136
+ }
137
+
138
+ static ssize_t
139
+ file_write(struct archive *a, void *client_data, const void *buff, size_t length)
140
+ {
141
+ struct write_file_data *mine;
142
+ ssize_t bytesWritten;
143
+
144
+ mine = (struct write_file_data *)client_data;
145
+ bytesWritten = write(mine->fd, buff, length);
146
+ if (bytesWritten <= 0) {
147
+ archive_set_error(a, errno, "Write error");
148
+ return (-1);
149
+ }
150
+ return (bytesWritten);
151
+ }
152
+
153
+ static int
154
+ file_close(struct archive *a, void *client_data)
155
+ {
156
+ struct write_file_data *mine = (struct write_file_data *)client_data;
157
+
158
+ (void)a; /* UNUSED */
159
+ close(mine->fd);
160
+ free(mine);
161
+ return (ARCHIVE_OK);
162
+ }