tarruby 0.1.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 (85) hide show
  1. data/README.txt +99 -0
  2. data/ext/extconf.rb +19 -0
  3. data/ext/libtar/COPYRIGHT +35 -0
  4. data/ext/libtar/ChangeLog +243 -0
  5. data/ext/libtar/ChangeLog-1.0.x +141 -0
  6. data/ext/libtar/INSTALL +183 -0
  7. data/ext/libtar/Makefile.in +51 -0
  8. data/ext/libtar/README +121 -0
  9. data/ext/libtar/TODO +10 -0
  10. data/ext/libtar/autoconf/ac_path_generic.m4 +136 -0
  11. data/ext/libtar/autoconf/aclocal.m4 +199 -0
  12. data/ext/libtar/autoconf/encap.m4 +133 -0
  13. data/ext/libtar/autoconf/install-sh +251 -0
  14. data/ext/libtar/autom4te.cache/output.0 +8102 -0
  15. data/ext/libtar/autom4te.cache/requests +112 -0
  16. data/ext/libtar/autom4te.cache/traces.0 +382 -0
  17. data/ext/libtar/compat/ChangeLog +31 -0
  18. data/ext/libtar/compat/README +12 -0
  19. data/ext/libtar/compat/TODO +4 -0
  20. data/ext/libtar/compat/basename.c +91 -0
  21. data/ext/libtar/compat/compat.h +260 -0
  22. data/ext/libtar/compat/dirname.c +96 -0
  23. data/ext/libtar/compat/fnmatch.c +237 -0
  24. data/ext/libtar/compat/gethostbyname_r.c +41 -0
  25. data/ext/libtar/compat/gethostname.c +36 -0
  26. data/ext/libtar/compat/getservbyname_r.c +41 -0
  27. data/ext/libtar/compat/glob.c +898 -0
  28. data/ext/libtar/compat/inet_aton.c +27 -0
  29. data/ext/libtar/compat/module.ac +591 -0
  30. data/ext/libtar/compat/snprintf.c +788 -0
  31. data/ext/libtar/compat/strdup.c +62 -0
  32. data/ext/libtar/compat/strlcat.c +72 -0
  33. data/ext/libtar/compat/strlcpy.c +68 -0
  34. data/ext/libtar/compat/strmode.c +199 -0
  35. data/ext/libtar/compat/strrstr.c +40 -0
  36. data/ext/libtar/compat/strsep.c +87 -0
  37. data/ext/libtar/config.h.in +187 -0
  38. data/ext/libtar/configure +8102 -0
  39. data/ext/libtar/configure.ac +114 -0
  40. data/ext/libtar/doc/Makefile.in +152 -0
  41. data/ext/libtar/doc/tar_append_file.3 +50 -0
  42. data/ext/libtar/doc/tar_block_read.3 +24 -0
  43. data/ext/libtar/doc/tar_extract_all.3 +43 -0
  44. data/ext/libtar/doc/tar_extract_file.3 +84 -0
  45. data/ext/libtar/doc/tar_open.3 +97 -0
  46. data/ext/libtar/doc/th_get_pathname.3 +63 -0
  47. data/ext/libtar/doc/th_print_long_ls.3 +22 -0
  48. data/ext/libtar/doc/th_read.3 +34 -0
  49. data/ext/libtar/doc/th_set_from_stat.3 +45 -0
  50. data/ext/libtar/lib/Makefile.in +92 -0
  51. data/ext/libtar/lib/append.c +272 -0
  52. data/ext/libtar/lib/block.c +384 -0
  53. data/ext/libtar/lib/decode.c +130 -0
  54. data/ext/libtar/lib/encode.c +237 -0
  55. data/ext/libtar/lib/extract.c +656 -0
  56. data/ext/libtar/lib/handle.c +150 -0
  57. data/ext/libtar/lib/internal.h +46 -0
  58. data/ext/libtar/lib/libtar.h +311 -0
  59. data/ext/libtar/lib/output.c +146 -0
  60. data/ext/libtar/lib/util.c +153 -0
  61. data/ext/libtar/lib/wrapper.c +175 -0
  62. data/ext/libtar/libtar/Makefile.in +73 -0
  63. data/ext/libtar/libtar/libtar.c +363 -0
  64. data/ext/libtar/listhash/ChangeLog +15 -0
  65. data/ext/libtar/listhash/TODO +21 -0
  66. data/ext/libtar/listhash/hash.c.in +344 -0
  67. data/ext/libtar/listhash/hash_new.3.in +74 -0
  68. data/ext/libtar/listhash/list.c.in +458 -0
  69. data/ext/libtar/listhash/list_new.3.in +86 -0
  70. data/ext/libtar/listhash/listhash.h.in +196 -0
  71. data/ext/libtar/listhash/module.ac +21 -0
  72. data/ext/libtar/win32/config.h +190 -0
  73. data/ext/libtar/win32/dirent.c +115 -0
  74. data/ext/libtar/win32/dirent.h +24 -0
  75. data/ext/libtar/win32/grp.h +4 -0
  76. data/ext/libtar/win32/listhash/libtar_hash.c +344 -0
  77. data/ext/libtar/win32/listhash/libtar_list.c +458 -0
  78. data/ext/libtar/win32/listhash/libtar_listhash.h +196 -0
  79. data/ext/libtar/win32/pwd.h +4 -0
  80. data/ext/libtar/win32/sys/param.h +8 -0
  81. data/ext/libtar/win32/tar.h +35 -0
  82. data/ext/libtar/win32/utime.h +6 -0
  83. data/ext/libtar/win32/win32/types.h +10 -0
  84. data/ext/tarruby.c +648 -0
  85. metadata +150 -0
@@ -0,0 +1,363 @@
1
+ /*
2
+ ** Copyright 1998-2003 University of Illinois Board of Trustees
3
+ ** Copyright 1998-2003 Mark D. Roth
4
+ ** All rights reserved.
5
+ **
6
+ ** libtar.c - demo driver program for libtar
7
+ **
8
+ ** Mark D. Roth <roth@uiuc.edu>
9
+ ** Campus Information Technologies and Educational Services
10
+ ** University of Illinois at Urbana-Champaign
11
+ */
12
+
13
+ #include <config.h>
14
+ #include <libtar.h>
15
+
16
+ #include <stdio.h>
17
+ #include <fcntl.h>
18
+ #include <errno.h>
19
+ #include <sys/param.h>
20
+
21
+ #ifdef STDC_HEADERS
22
+ # include <string.h>
23
+ #endif
24
+
25
+ #ifdef HAVE_UNISTD_H
26
+ # include <unistd.h>
27
+ #endif
28
+
29
+ #ifdef DEBUG
30
+ # include <signal.h>
31
+ #endif
32
+
33
+ #ifdef HAVE_LIBZ
34
+ # include <zlib.h>
35
+ #endif
36
+
37
+ #include <compat.h>
38
+
39
+
40
+ char *progname;
41
+ int verbose = 0;
42
+ int use_gnu = 0;
43
+
44
+ #ifdef DEBUG
45
+ void
46
+ segv_handler(int sig)
47
+ {
48
+ puts("OOPS! Caught SIGSEGV, bailing out...");
49
+ fflush(stdout);
50
+ fflush(stderr);
51
+ }
52
+ #endif
53
+
54
+
55
+ #ifdef HAVE_LIBZ
56
+
57
+ int use_zlib = 0;
58
+
59
+ int
60
+ gzopen_frontend(char *pathname, int oflags, int mode)
61
+ {
62
+ char *gzoflags;
63
+ gzFile gzf;
64
+ int fd;
65
+
66
+ switch (oflags & O_ACCMODE)
67
+ {
68
+ case O_WRONLY:
69
+ gzoflags = "wb";
70
+ break;
71
+ case O_RDONLY:
72
+ gzoflags = "rb";
73
+ break;
74
+ default:
75
+ case O_RDWR:
76
+ errno = EINVAL;
77
+ return -1;
78
+ }
79
+
80
+ fd = open(pathname, oflags, mode);
81
+ if (fd == -1)
82
+ return -1;
83
+
84
+ if ((oflags & O_CREAT) && fchmod(fd, mode))
85
+ return -1;
86
+
87
+ gzf = gzdopen(fd, gzoflags);
88
+ if (!gzf)
89
+ {
90
+ errno = ENOMEM;
91
+ return -1;
92
+ }
93
+
94
+ return (int)gzf;
95
+ }
96
+
97
+ tartype_t gztype = { (openfunc_t) gzopen_frontend, (closefunc_t) gzclose,
98
+ (readfunc_t) gzread, (writefunc_t) gzwrite
99
+ };
100
+
101
+ #endif /* HAVE_LIBZ */
102
+
103
+
104
+ int
105
+ create(char *tarfile, char *rootdir, libtar_list_t *l)
106
+ {
107
+ TAR *t;
108
+ char *pathname;
109
+ char buf[MAXPATHLEN];
110
+ libtar_listptr_t lp;
111
+
112
+ if (tar_open(&t, tarfile,
113
+ #ifdef HAVE_LIBZ
114
+ (use_zlib ? &gztype : NULL),
115
+ #else
116
+ NULL,
117
+ #endif
118
+ O_WRONLY | O_CREAT, 0644,
119
+ (verbose ? TAR_VERBOSE : 0)
120
+ | (use_gnu ? TAR_GNU : 0)) == -1)
121
+ {
122
+ fprintf(stderr, "tar_open(): %s\n", strerror(errno));
123
+ return -1;
124
+ }
125
+
126
+ libtar_listptr_reset(&lp);
127
+ while (libtar_list_next(l, &lp) != 0)
128
+ {
129
+ pathname = (char *)libtar_listptr_data(&lp);
130
+ if (pathname[0] != '/' && rootdir != NULL)
131
+ snprintf(buf, sizeof(buf), "%s/%s", rootdir, pathname);
132
+ else
133
+ strlcpy(buf, pathname, sizeof(buf));
134
+ if (tar_append_tree(t, buf, pathname) != 0)
135
+ {
136
+ fprintf(stderr,
137
+ "tar_append_tree(\"%s\", \"%s\"): %s\n", buf,
138
+ pathname, strerror(errno));
139
+ tar_close(t);
140
+ return -1;
141
+ }
142
+ }
143
+
144
+ if (tar_append_eof(t) != 0)
145
+ {
146
+ fprintf(stderr, "tar_append_eof(): %s\n", strerror(errno));
147
+ tar_close(t);
148
+ return -1;
149
+ }
150
+
151
+ if (tar_close(t) != 0)
152
+ {
153
+ fprintf(stderr, "tar_close(): %s\n", strerror(errno));
154
+ return -1;
155
+ }
156
+
157
+ return 0;
158
+ }
159
+
160
+
161
+ int
162
+ list(char *tarfile)
163
+ {
164
+ TAR *t;
165
+ int i;
166
+
167
+ if (tar_open(&t, tarfile,
168
+ #ifdef HAVE_LIBZ
169
+ (use_zlib ? &gztype : NULL),
170
+ #else
171
+ NULL,
172
+ #endif
173
+ O_RDONLY, 0,
174
+ (verbose ? TAR_VERBOSE : 0)
175
+ | (use_gnu ? TAR_GNU : 0)) == -1)
176
+ {
177
+ fprintf(stderr, "tar_open(): %s\n", strerror(errno));
178
+ return -1;
179
+ }
180
+
181
+ while ((i = th_read(t)) == 0)
182
+ {
183
+ th_print_long_ls(t);
184
+ #ifdef DEBUG
185
+ th_print(t);
186
+ #endif
187
+ if (TH_ISREG(t) && tar_skip_regfile(t) != 0)
188
+ {
189
+ fprintf(stderr, "tar_skip_regfile(): %s\n",
190
+ strerror(errno));
191
+ return -1;
192
+ }
193
+ }
194
+
195
+ #ifdef DEBUG
196
+ printf("th_read() returned %d\n", i);
197
+ printf("EOF mark encountered after %ld bytes\n",
198
+ # ifdef HAVE_LIBZ
199
+ (use_zlib
200
+ ? gzseek((gzFile) t->fd, 0, SEEK_CUR)
201
+ :
202
+ # endif
203
+ lseek(t->fd, 0, SEEK_CUR)
204
+ # ifdef HAVE_LIBZ
205
+ )
206
+ # endif
207
+ );
208
+ #endif
209
+
210
+ if (tar_close(t) != 0)
211
+ {
212
+ fprintf(stderr, "tar_close(): %s\n", strerror(errno));
213
+ return -1;
214
+ }
215
+
216
+ return 0;
217
+ }
218
+
219
+
220
+ int
221
+ extract(char *tarfile, char *rootdir)
222
+ {
223
+ TAR *t;
224
+
225
+ #ifdef DEBUG
226
+ puts("opening tarfile...");
227
+ #endif
228
+ if (tar_open(&t, tarfile,
229
+ #ifdef HAVE_LIBZ
230
+ (use_zlib ? &gztype : NULL),
231
+ #else
232
+ NULL,
233
+ #endif
234
+ O_RDONLY, 0,
235
+ (verbose ? TAR_VERBOSE : 0)
236
+ | (use_gnu ? TAR_GNU : 0)) == -1)
237
+ {
238
+ fprintf(stderr, "tar_open(): %s\n", strerror(errno));
239
+ return -1;
240
+ }
241
+
242
+ #ifdef DEBUG
243
+ puts("extracting tarfile...");
244
+ #endif
245
+ if (tar_extract_all(t, rootdir) != 0)
246
+ {
247
+ fprintf(stderr, "tar_extract_all(): %s\n", strerror(errno));
248
+ return -1;
249
+ }
250
+
251
+ #ifdef DEBUG
252
+ puts("closing tarfile...");
253
+ #endif
254
+ if (tar_close(t) != 0)
255
+ {
256
+ fprintf(stderr, "tar_close(): %s\n", strerror(errno));
257
+ return -1;
258
+ }
259
+
260
+ return 0;
261
+ }
262
+
263
+
264
+ void
265
+ usage()
266
+ {
267
+ printf("Usage: %s [-C rootdir] [-g] [-z] -x|-t filename.tar\n",
268
+ progname);
269
+ printf(" %s [-C rootdir] [-g] [-z] -c filename.tar ...\n",
270
+ progname);
271
+ exit(-1);
272
+ }
273
+
274
+
275
+ #define MODE_LIST 1
276
+ #define MODE_CREATE 2
277
+ #define MODE_EXTRACT 3
278
+
279
+ int
280
+ main(int argc, char *argv[])
281
+ {
282
+ char *tarfile = NULL;
283
+ char *rootdir = NULL;
284
+ int c;
285
+ int mode = 0;
286
+ libtar_list_t *l;
287
+
288
+ progname = basename(argv[0]);
289
+
290
+ while ((c = getopt(argc, argv, "cC:gtvVxz")) != -1)
291
+ switch (c)
292
+ {
293
+ case 'V':
294
+ printf("libtar %s by Mark D. Roth <roth@uiuc.edu>\n",
295
+ libtar_version);
296
+ break;
297
+ case 'C':
298
+ rootdir = strdup(optarg);
299
+ break;
300
+ case 'v':
301
+ verbose = 1;
302
+ break;
303
+ case 'g':
304
+ use_gnu = 1;
305
+ break;
306
+ case 'c':
307
+ if (mode)
308
+ usage();
309
+ mode = MODE_CREATE;
310
+ break;
311
+ case 'x':
312
+ if (mode)
313
+ usage();
314
+ mode = MODE_EXTRACT;
315
+ break;
316
+ case 't':
317
+ if (mode)
318
+ usage();
319
+ mode = MODE_LIST;
320
+ break;
321
+ #ifdef HAVE_LIBZ
322
+ case 'z':
323
+ use_zlib = 1;
324
+ break;
325
+ #endif /* HAVE_LIBZ */
326
+ default:
327
+ usage();
328
+ }
329
+
330
+ if (!mode || ((argc - optind) < (mode == MODE_CREATE ? 2 : 1)))
331
+ {
332
+ #ifdef DEBUG
333
+ printf("argc - optind == %d\tmode == %d\n", argc - optind,
334
+ mode);
335
+ #endif
336
+ usage();
337
+ }
338
+
339
+ #ifdef DEBUG
340
+ signal(SIGSEGV, segv_handler);
341
+ #endif
342
+
343
+ switch (mode)
344
+ {
345
+ case MODE_EXTRACT:
346
+ return extract(argv[optind], rootdir);
347
+ case MODE_CREATE:
348
+ tarfile = argv[optind];
349
+ l = libtar_list_new(LIST_QUEUE, NULL);
350
+ for (c = optind + 1; c < argc; c++)
351
+ libtar_list_add(l, argv[c]);
352
+ return create(tarfile, rootdir, l);
353
+ case MODE_LIST:
354
+ return list(argv[optind]);
355
+ default:
356
+ break;
357
+ }
358
+
359
+ /* NOTREACHED */
360
+ return -2;
361
+ }
362
+
363
+
@@ -0,0 +1,15 @@
1
+ 2002-12-09 added list_empty() and hash_empty() functions
2
+
3
+ 2002-09-12 fixed list_iterate function to return -1 if it gets
4
+ an invalid argument
5
+
6
+ include <config.h> and <compat.h> from source files, not
7
+ from header file, since header file is sometimes
8
+ installed as part of a user-visible API
9
+ (those APIs should eventually be redesigned without the
10
+ listhash code being publicly visible, but for now we
11
+ need to accomodate this)
12
+
13
+ 2002-07-07 modified list iterate function to return int
14
+ (returns -1 if plugin function returns -1)
15
+
@@ -0,0 +1,21 @@
1
+ Functionality:
2
+ --------------
3
+
4
+ * add list mode to allow nodes to be inserted in any arbitrary location
5
+ * add "*_hash_iterate()" function
6
+ * add flags argument to *_list_del() that allows the listptr to be set
7
+ to the previous or next element
8
+ * add a generic pointer type to replace *_listptr_t and *_hashptr_t ???
9
+
10
+
11
+ Code Cleanup:
12
+ -------------
13
+
14
+ * rename functions:
15
+ *_list_next => *_listptr_next()
16
+ *_list_prev => *_listptr_prev()
17
+ *_hash_next => *_hashptr_next()
18
+ * start using "*_list_t" and "*_hash_t" instead of "*_list_t *" and
19
+ "*_hash_t *" ?
20
+ * add prefixes to structure member field names
21
+