aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2002-09-25 03:04:03 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2002-09-25 03:04:03 +0000
commit69eab26401db425cf27915a675953e2ac33ee0e5 (patch)
tree8eaa71110378ffc02ad71a2d78f045ca176c233b
parent7ca04f328e22fcbee4659d73f9a72dfdf1dd6a23 (diff)
downloadbusybox-w32-69eab26401db425cf27915a675953e2ac33ee0e5.tar.gz
busybox-w32-69eab26401db425cf27915a675953e2ac33ee0e5.tar.bz2
busybox-w32-69eab26401db425cf27915a675953e2ac33ee0e5.zip
Remove files made obsolete by new unarchiving code
-rw-r--r--archival/libunarchive/deb_extract.c84
-rw-r--r--archival/libunarchive/get_header_cpio.c137
-rw-r--r--archival/libunarchive/get_header_zip.c171
-rw-r--r--archival/libunarchive/unarchive.c263
4 files changed, 0 insertions, 655 deletions
diff --git a/archival/libunarchive/deb_extract.c b/archival/libunarchive/deb_extract.c
deleted file mode 100644
index b95ac4d1f..000000000
--- a/archival/libunarchive/deb_extract.c
+++ /dev/null
@@ -1,84 +0,0 @@
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU Library General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 */
16
17#include <stdio.h>
18#include <stdlib.h>
19#include <string.h>
20#include "unarchive.h"
21#include "libbb.h"
22
23char *deb_extract(const char *package_filename, FILE *out_stream,
24 const int extract_function, const char *prefix, const char *filename)
25{
26 FILE *deb_stream;
27 FILE *uncompressed_stream = NULL;
28 file_header_t *ar_header = NULL;
29 char **file_list = NULL;
30 char *output_buffer = NULL;
31 char *ared_file = NULL;
32 char ar_magic[8];
33 int gunzip_pid;
34
35 if (filename != NULL) {
36 file_list = xmalloc(sizeof(char *) * 2);
37 file_list[0] = xstrdup(filename);
38 file_list[1] = NULL;
39 }
40
41 if (extract_function & extract_control_tar_gz) {
42 ared_file = xstrdup("control.tar.gz");
43 }
44 else if (extract_function & extract_data_tar_gz) {
45 ared_file = xstrdup("data.tar.gz");
46 }
47
48 /* open the debian package to be worked on */
49 deb_stream = wfopen(package_filename, "r");
50 if (deb_stream == NULL) {
51 return(NULL);
52 }
53 /* set the buffer size */
54 setvbuf(deb_stream, NULL, _IOFBF, 0x8000);
55
56 /* check ar magic */
57 fread(ar_magic, 1, 8, deb_stream);
58 if (strncmp(ar_magic,"!<arch>",7) != 0) {
59 error_msg_and_die("invalid magic");
60 }
61 archive_offset = 8;
62
63 while ((ar_header = get_header_ar(deb_stream)) != NULL) {
64 if (strcmp(ared_file, ar_header->name) == 0) {
65 /* open a stream of decompressed data */
66 uncompressed_stream = gz_open(deb_stream, &gunzip_pid);
67 archive_offset = 0;
68 output_buffer = unarchive(uncompressed_stream, out_stream, get_header_tar, extract_function, prefix, file_list, NULL);
69 }
70 seek_sub_file(deb_stream, ar_header->size);
71 free(ar_header->name);
72 free(ar_header);
73 }
74 gz_close(gunzip_pid);
75 fclose(deb_stream);
76 fclose(uncompressed_stream);
77 free(ared_file);
78 if (filename != NULL) {
79 free(file_list[0]);
80 free(file_list);
81 }
82 return(output_buffer);
83}
84
diff --git a/archival/libunarchive/get_header_cpio.c b/archival/libunarchive/get_header_cpio.c
deleted file mode 100644
index cd48601b6..000000000
--- a/archival/libunarchive/get_header_cpio.c
+++ /dev/null
@@ -1,137 +0,0 @@
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU Library General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 */
16
17#include <stdio.h>
18#include <stdlib.h>
19#include <string.h>
20#include "unarchive.h"
21#include "libbb.h"
22
23struct hardlinks {
24 file_header_t *entry;
25 int inode;
26 struct hardlinks *next;
27};
28
29file_header_t *get_header_cpio(FILE *src_stream)
30{
31 file_header_t *cpio_entry = NULL;
32 char cpio_header[110];
33 int namesize;
34 char dummy[16];
35 int major, minor, nlink, inode;
36 static struct hardlinks *saved_hardlinks = NULL;
37 static int pending_hardlinks = 0;
38
39 if (pending_hardlinks) { /* Deal with any pending hardlinks */
40 struct hardlinks *tmp = saved_hardlinks, *oldtmp = NULL;
41 while (tmp) {
42 if (tmp->entry->link_name) { /* Found a hardlink ready to be extracted */
43 cpio_entry = tmp->entry;
44 if (oldtmp) oldtmp->next = tmp->next; /* Remove item from linked list */
45 else saved_hardlinks = tmp->next;
46 free(tmp);
47 return (cpio_entry);
48 }
49 oldtmp = tmp;
50 tmp = tmp->next;
51 }
52 pending_hardlinks = 0; /* No more pending hardlinks, read next file entry */
53 }
54
55 /* There can be padding before archive header */
56 seek_sub_file(src_stream, (4 - (archive_offset % 4)) % 4);
57 if (fread(cpio_header, 1, 110, src_stream) == 110) {
58 archive_offset += 110;
59 if (strncmp(cpio_header, "07070", 5) != 0) {
60 error_msg("Unsupported format or invalid magic");
61 return(NULL);
62 }
63 switch (cpio_header[5]) {
64 case '2': /* "crc" header format */
65 /* Doesnt do the crc check yet */
66 case '1': /* "newc" header format */
67 cpio_entry = (file_header_t *) xcalloc(1, sizeof(file_header_t));
68 sscanf(cpio_header, "%6c%8x%8x%8x%8x%8x%8lx%8lx%16c%8x%8x%8x%8c",
69 dummy, &inode, (unsigned int*)&cpio_entry->mode,
70 (unsigned int*)&cpio_entry->uid, (unsigned int*)&cpio_entry->gid,
71 &nlink, &cpio_entry->mtime, &cpio_entry->size,
72 dummy, &major, &minor, &namesize, dummy);
73
74 cpio_entry->name = (char *) xcalloc(1, namesize);
75 fread(cpio_entry->name, 1, namesize, src_stream); /* Read in filename */
76 archive_offset += namesize;
77 /* Skip padding before file contents */
78 seek_sub_file(src_stream, (4 - (archive_offset % 4)) % 4);
79 if (strcmp(cpio_entry->name, "TRAILER!!!") == 0) {
80 printf("%d blocks\n", (int) (archive_offset % 512 ? (archive_offset / 512) + 1 : archive_offset / 512)); /* Always round up */
81 if (saved_hardlinks) { /* Bummer - we still have unresolved hardlinks */
82 struct hardlinks *tmp = saved_hardlinks, *oldtmp = NULL;
83 while (tmp) {
84 error_msg("%s not created: cannot resolve hardlink", tmp->entry->name);
85 oldtmp = tmp;
86 tmp = tmp->next;
87 free (oldtmp->entry->name);
88 free (oldtmp->entry);
89 free (oldtmp);
90 }
91 saved_hardlinks = NULL;
92 pending_hardlinks = 0;
93 }
94 return(NULL);
95 }
96
97 if (S_ISLNK(cpio_entry->mode)) {
98 cpio_entry->link_name = (char *) xcalloc(1, cpio_entry->size + 1);
99 fread(cpio_entry->link_name, 1, cpio_entry->size, src_stream);
100 archive_offset += cpio_entry->size;
101 cpio_entry->size = 0; /* Stop possiable seeks in future */
102 }
103 if (nlink > 1 && !S_ISDIR(cpio_entry->mode)) {
104 if (cpio_entry->size == 0) { /* Put file on a linked list for later */
105 struct hardlinks *new = xmalloc(sizeof(struct hardlinks));
106 new->next = saved_hardlinks;
107 new->inode = inode;
108 new->entry = cpio_entry;
109 saved_hardlinks = new;
110 return(get_header_cpio(src_stream)); /* Recurse to next file */
111 } else { /* Found the file with data in */
112 struct hardlinks *tmp = saved_hardlinks;
113 pending_hardlinks = 1;
114 while (tmp) {
115 if (tmp->inode == inode) {
116 tmp->entry->link_name = xstrdup(cpio_entry->name);
117 nlink--;
118 }
119 tmp = tmp->next;
120 }
121 if (nlink > 1) error_msg("error resolving hardlink: did you create the archive with GNU cpio 2.0-2.2?");
122 }
123 }
124 cpio_entry->device = (major << 8) | minor;
125 break;
126 default:
127 error_msg("Unsupported format");
128 return(NULL);
129 }
130 if (ferror(src_stream) || feof(src_stream)) {
131 perror_msg("Stream error");
132 return(NULL);
133 }
134 }
135 return(cpio_entry);
136}
137
diff --git a/archival/libunarchive/get_header_zip.c b/archival/libunarchive/get_header_zip.c
deleted file mode 100644
index 5fa3a6c8c..000000000
--- a/archival/libunarchive/get_header_zip.c
+++ /dev/null
@@ -1,171 +0,0 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * get_header_zip for busybox
4 *
5 * Copyright (C) 2001 by Laurence Anderson
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#include <stddef.h>
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26#include "unarchive.h"
27#include "libbb.h"
28
29#define ZIP_FILEHEADER_MAGIC 0x04034b50
30#define ZIP_CDS_MAGIC 0x02014b50
31#define ZIP_CDS_END_MAGIC 0x06054b50
32#define ZIP_DD_MAGIC 0x08074b50
33
34
35enum {
36 zh_version,
37 zh_flags,
38 zh_method,
39 zh_modtime,
40 zh_moddate,
41 zh_crc32,
42 zh_cmpsize,
43 zh_ucmpsize,
44 zh_filename_len,
45 zh_extra_len
46};
47
48static const char fail_msg[] = "Invalid file or read error";
49
50static int le_read_int(FILE *fp, int n)
51{
52 int r = 0;
53 int s = 1;
54 int c;
55
56 archive_offset += n;
57
58 do {
59 if ((c = fgetc(fp)) == EOF) {
60 error_msg_and_die(fail_msg);
61 }
62 r += s * c;
63 s <<= 8;
64 } while (--n);
65
66 return r;
67}
68
69static void read_header(FILE *fp, int *zh)
70{
71 static const char s[] = { 2, 2, 2, 2, 2, 4, 4, 4, 2, 2, 0 };
72 int i = 0;
73
74 do {
75 zh[i] = le_read_int(fp, s[i]);
76 } while (s[++i]);
77}
78
79file_header_t *get_header_zip(FILE *zip_stream)
80{
81 int zip_header[10];
82 file_header_t *zip_entry = NULL;
83 int magic, tmpmagic;
84 /* If dd_ahead is true, we didn't know the last extracted file's length. */
85 static int dd_ahead = 0;
86
87 magic = le_read_int(zip_stream, 4);
88
89 checkmagic:
90 switch (magic) {
91 case ZIP_FILEHEADER_MAGIC:
92 zip_entry = xcalloc(1, sizeof(file_header_t));
93
94 read_header(zip_stream, zip_header);
95
96 if (zip_header[zh_method] == 8) {
97 zip_entry->extract_func = &inflate;
98 } else if (zip_header[zh_method] != 0) {
99 error_msg_and_die("Unsupported compression method %d\n",
100 zip_header[zh_method]);
101 }
102
103 zip_entry->name = xmalloc(zip_header[zh_filename_len] + 1);
104 if (!fread(zip_entry->name, zip_header[zh_filename_len], 1, zip_stream)) {
105 error_msg_and_die(fail_msg);
106 }
107 archive_offset += zip_header[zh_filename_len];
108
109 seek_sub_file(zip_stream, zip_header[zh_extra_len]);
110
111 zip_entry->size = zip_header[zh_cmpsize];
112
113 zip_entry->mode = S_IFREG | 0777;
114
115 /* Time/Date? */
116
117 zip_entry->name[zip_header[zh_filename_len]] = 0;
118 if (*(zip_entry->name + zip_header[zh_filename_len] - 1) == '/') {
119 /* Files that end in a / are directories */
120 /* Remove trailing / so unarchive doesn't get confused */
121 *(zip_entry->name + zip_header[zh_filename_len] - 1) = '\0';
122 zip_entry->mode ^= S_IFREG;
123 zip_entry->mode |= S_IFDIR;
124 }
125
126 if (zip_header[zh_flags] & 0x8) {
127 /* crc32, and sizes are in the data description _after_ the file */
128 if (zip_header[zh_cmpsize] == 0) {
129 /* As we don't know how long this file it is difficult to skip!
130 * but it is compressed, so normally its ok */
131 dd_ahead = 1;
132 }
133 if (zip_header[zh_ucmpsize] != 0) {
134 /* Humm... we would otherwise skip this twice - not good! */
135 dd_ahead = 2;
136 }
137 }
138 break;
139
140 case ZIP_CDS_MAGIC: /* FALLTHRU */
141 case ZIP_CDS_END_MAGIC:
142 return(NULL);
143 break;
144
145 case ZIP_DD_MAGIC: {
146 int cmpsize;
147 seek_sub_file(zip_stream, 4); // Skip crc32
148 cmpsize = le_read_int(zip_stream, 4);
149 if (dd_ahead == 1) archive_offset += cmpsize;
150 seek_sub_file(zip_stream, 4); // Skip uncompressed size
151 dd_ahead = 0;
152 return (get_header_zip(zip_stream));
153 break; }
154
155 default:
156 if (!dd_ahead) error_msg("Invalid magic (%#x): Trying to skip junk", magic);
157 dd_ahead = 0;
158 while ((tmpmagic = fgetc(zip_stream)) != EOF) {
159 archive_offset++;
160 magic = ((magic >> 8) & 0x00ffffff) | ((tmpmagic << 24) & 0xff000000);
161 if (magic == ZIP_FILEHEADER_MAGIC
162 || magic == ZIP_CDS_MAGIC
163 || magic == ZIP_CDS_END_MAGIC) {
164 goto checkmagic;
165 }
166 }
167 error_msg_and_die(fail_msg);
168 }
169
170 return(zip_entry);
171}
diff --git a/archival/libunarchive/unarchive.c b/archival/libunarchive/unarchive.c
deleted file mode 100644
index 03e3c3ec2..000000000
--- a/archival/libunarchive/unarchive.c
+++ /dev/null
@@ -1,263 +0,0 @@
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU Library General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 */
16
17#include <errno.h>
18#include <fnmatch.h>
19#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
22#include <unistd.h>
23#include <utime.h>
24#include <sys/wait.h>
25#include <signal.h>
26#include "unarchive.h"
27#include "busybox.h"
28
29/* Extract the data postioned at src_stream to either filesystem, stdout or
30 * buffer depending on the value of 'function' which is defined in libbb.h
31 *
32 * prefix doesnt have to be just a directory, it may prefix the filename as well.
33 *
34 * e.g. '/var/lib/dpkg/info/dpkg.' will extract all files to the base bath
35 * '/var/lib/dpkg/info/' and all files/dirs created in that dir will have
36 * 'dpkg.' as their prefix
37 *
38 * For this reason if prefix does point to a dir then it must end with a
39 * trailing '/' or else the last dir will be assumed to be the file prefix
40 */
41char *extract_archive(FILE *src_stream, FILE *out_stream, const file_header_t *file_entry,
42 const int function, const char *prefix)
43{
44 FILE *dst_stream = NULL;
45 char *full_name = NULL;
46 char *buffer = NULL;
47 struct utimbuf t;
48
49 /* prefix doesnt have to be a proper path it may prepend
50 * the filename as well */
51 if (prefix != NULL) {
52 /* strip leading '/' in filename to extract as prefix may not be dir */
53 /* Cant use concat_path_file here as prefix might not be a directory */
54 char *path = file_entry->name;
55 if (strncmp("./", path, 2) == 0) {
56 path += 2;
57 if (strlen(path) == 0) {
58 return(NULL);
59 }
60 }
61 bb_asprintf(&full_name, "%s%s", prefix, path);
62 } else {
63 full_name = file_entry->name;
64 }
65 if (function & extract_to_stdout) {
66 if (S_ISREG(file_entry->mode)) {
67 copy_file_chunk(src_stream, out_stream, file_entry->size);
68 archive_offset += file_entry->size;
69 }
70 }
71 else if (function & extract_one_to_buffer) {
72 if (S_ISREG(file_entry->mode)) {
73 buffer = (char *) xmalloc(file_entry->size + 1);
74 fread(buffer, 1, file_entry->size, src_stream);
75 buffer[file_entry->size] = '\0';
76 archive_offset += file_entry->size;
77 return(buffer);
78 }
79 }
80 else if (function & extract_all_to_fs) {
81 struct stat oldfile;
82 int stat_res;
83 stat_res = lstat (full_name, &oldfile);
84 if (stat_res == 0) { /* The file already exists */
85 if ((function & extract_unconditional) || (oldfile.st_mtime < file_entry->mtime)) {
86 if (!S_ISDIR(oldfile.st_mode)) {
87 unlink(full_name); /* Directories might not be empty etc */
88 }
89 } else {
90 if ((function & extract_quiet) != extract_quiet) {
91 error_msg("%s not created: newer or same age file exists", file_entry->name);
92 }
93 seek_sub_file(src_stream, file_entry->size);
94 return (NULL);
95 }
96 }
97 if (function & extract_create_leading_dirs) { /* Create leading directories with default umask */
98 char *buf, *parent;
99 buf = xstrdup(full_name);
100 parent = dirname(buf);
101 if (make_directory (parent, -1, FILEUTILS_RECUR) != 0) {
102 if ((function & extract_quiet) != extract_quiet) {
103 error_msg("couldn't create leading directories");
104 }
105 }
106 free (buf);
107 }
108 switch(file_entry->mode & S_IFMT) {
109 case S_IFREG:
110 if (file_entry->link_name) { /* Found a cpio hard link */
111 if (link(file_entry->link_name, full_name) != 0) {
112 if ((function & extract_quiet) != extract_quiet) {
113 perror_msg("Cannot link from %s to '%s'",
114 file_entry->name, file_entry->link_name);
115 }
116 }
117 } else {
118 if ((dst_stream = wfopen(full_name, "w")) == NULL) {
119 seek_sub_file(src_stream, file_entry->size);
120 return NULL;
121 }
122 archive_offset += file_entry->size;
123 if (file_entry->extract_func) file_entry->extract_func(src_stream, dst_stream);
124 else copy_file_chunk(src_stream, dst_stream, file_entry->size);
125 fclose(dst_stream);
126 }
127 break;
128 case S_IFDIR:
129 if (stat_res != 0) {
130 if (mkdir(full_name, file_entry->mode) < 0) {
131 if ((function & extract_quiet) != extract_quiet) {
132 perror_msg("extract_archive: %s", full_name);
133 }
134 }
135 }
136 break;
137 case S_IFLNK:
138 if (symlink(file_entry->link_name, full_name) < 0) {
139 if ((function & extract_quiet) != extract_quiet) {
140 perror_msg("Cannot create symlink from %s to '%s'", file_entry->name, file_entry->link_name);
141 }
142 return NULL;
143 }
144 break;
145 case S_IFSOCK:
146 case S_IFBLK:
147 case S_IFCHR:
148 case S_IFIFO:
149 if (mknod(full_name, file_entry->mode, file_entry->device) == -1) {
150 if ((function & extract_quiet) != extract_quiet) {
151 perror_msg("Cannot create node %s", file_entry->name);
152 }
153 return NULL;
154 }
155 break;
156 }
157
158 /* Changing a symlink's properties normally changes the properties of the
159 * file pointed to, so dont try and change the date or mode, lchown does
160 * does the right thing, but isnt available in older versions of libc */
161 if (S_ISLNK(file_entry->mode)) {
162#if (__GLIBC__ > 2) && (__GLIBC_MINOR__ > 1)
163 lchown(full_name, file_entry->uid, file_entry->gid);
164#endif
165 } else {
166 if (function & extract_preserve_date) {
167 t.actime = file_entry->mtime;
168 t.modtime = file_entry->mtime;
169 utime(full_name, &t);
170 }
171 chmod(full_name, file_entry->mode);
172 chown(full_name, file_entry->uid, file_entry->gid);
173 }
174 } else {
175 /* If we arent extracting data we have to skip it,
176 * if data size is 0 then then just do it anyway
177 * (saves testing for it) */
178 seek_sub_file(src_stream, file_entry->size);
179 }
180
181 /* extract_list and extract_verbose_list can be used in conjunction
182 * with one of the above four extraction functions, so do this seperately */
183 if (function & extract_verbose_list) {
184 fprintf(out_stream, "%s %d/%d %8d %s ", mode_string(file_entry->mode),
185 file_entry->uid, file_entry->gid,
186 (int) file_entry->size, time_string(file_entry->mtime));
187 }
188 if ((function & extract_list) || (function & extract_verbose_list)){
189 /* fputs doesnt add a trailing \n, so use fprintf */
190 fprintf(out_stream, "%s\n", full_name);
191 }
192
193 if (prefix != NULL) {
194 free(full_name);
195 }
196
197 return(NULL); /* Maybe we should say if failed */
198}
199
200char *unarchive(FILE *src_stream, FILE *out_stream, file_header_t *(*get_headers)(FILE *),
201 const int extract_function, const char *prefix, char **include_name, char **exclude_name)
202{
203 file_header_t *file_entry;
204 int extract_flag = TRUE;
205 int i;
206 char *buffer = NULL;
207#ifdef CONFIG_FEATURE_UNARCHIVE_TAPE
208 int pid, tape_pipe[2];
209
210 if (pipe(tape_pipe) != 0) error_msg_and_die("Can't create pipe\n");
211 if ((pid = fork()) == -1) error_msg_and_die("Fork failed\n");
212 if (pid==0) { /* child process */
213 close(tape_pipe[0]); /* We don't wan't to read from the pipe */
214 copyfd(fileno(src_stream), tape_pipe[1]);
215 close(tape_pipe[1]); /* Send EOF */
216 exit(0);
217 /* notreached */
218 }
219 close(tape_pipe[1]); /* Don't want to write down the pipe */
220 fclose(src_stream);
221 src_stream = fdopen(tape_pipe[0], "r");
222#endif
223 archive_offset = 0;
224 while ((file_entry = get_headers(src_stream)) != NULL) {
225
226 if (include_name != NULL) {
227 extract_flag = FALSE;
228 for(i = 0; include_name[i] != 0; i++) {
229 if (fnmatch(include_name[i], file_entry->name, FNM_LEADING_DIR) == 0) {
230 extract_flag = TRUE;
231 break;
232 }
233 }
234 } else {
235 extract_flag = TRUE;
236 }
237
238 /* If the file entry is in the exclude list dont extract it */
239 if (exclude_name != NULL) {
240 for(i = 0; exclude_name[i] != 0; i++) {
241 if (fnmatch(exclude_name[i], file_entry->name, FNM_LEADING_DIR) == 0) {
242 extract_flag = FALSE;
243 break;
244 }
245 }
246 }
247
248 if (extract_flag) {
249 buffer = extract_archive(src_stream, out_stream, file_entry, extract_function, prefix);
250 } else {
251 /* seek past the data entry */
252 seek_sub_file(src_stream, file_entry->size);
253 }
254 free(file_entry->name);
255 free(file_entry->link_name);
256 free(file_entry);
257 }
258#ifdef CONFIG_FEATURE_UNARCHIVE_TAPE
259 kill(pid, SIGTERM);
260 waitpid(pid, NULL, 0);
261#endif
262 return(buffer);
263}