22
fd_fd_filter(int fd_in, int fd_out,
23
const char *file, const char *cmd, const char *args,
34
execlp(file, cmd, args, NULL);
35
ohshite(_("%s: failed to exec '%s %s'"), desc, cmd, args);
38
void decompress_cat(enum compress_type type, int fd_in, int fd_out, char *desc, ...) {
40
struct varbuf v = VARBUF_INIT;
43
varbufvprintf(&v, desc, al);
47
case compress_type_gzip:
52
gzFile gzfile = gzdopen(fd_in, "r");
53
while ((actualread= gzread(gzfile,buffer,sizeof(buffer))) > 0) {
54
if (actualread < 0 ) {
56
const char *errmsg = gzerror(gzfile, &err);
58
if (errno == EINTR) continue;
59
errmsg= strerror(errno);
61
ohshite(_("%s: internal gzip error: `%s'"), v.buf, errmsg);
63
write(fd_out,buffer,actualread);
68
fd_fd_filter(fd_in, fd_out, GZIP, "gzip", "-dc", v.buf);
70
case compress_type_bzip2:
75
BZFILE *bzfile = BZ2_bzdopen(fd_in, "r");
76
while ((actualread= BZ2_bzread(bzfile,buffer,sizeof(buffer))) > 0) {
77
if (actualread < 0 ) {
79
const char *errmsg = BZ2_bzerror(bzfile, &err);
80
if (err == BZ_IO_ERROR) {
81
if (errno == EINTR) continue;
82
errmsg= strerror(errno);
84
ohshite(_("%s: internal bzip2 error: `%s'"), v.buf, errmsg);
86
write(fd_out,buffer,actualread);
91
fd_fd_filter(fd_in, fd_out, BZIP2, "bzip2", "-dc", v.buf);
93
case compress_type_lzma:
94
fd_fd_filter(fd_in, fd_out, LZMA, "lzma", "-dc", v.buf);
95
case compress_type_cat:
96
fd_fd_copy(fd_in, fd_out, -1, _("%s: decompression"), v.buf);
103
void compress_cat(enum compress_type type, int fd_in, int fd_out, const char *compression, char *desc, ...) {
105
struct varbuf v = VARBUF_INIT;
109
varbufvprintf(&v, desc, al);
112
if(compression == NULL) compression= "9";
113
else if (*compression == '0')
114
type = compress_type_cat;
117
case compress_type_gzip:
120
int actualread, actualwrite;
123
strncpy(combuf, "w9", sizeof(combuf));
124
combuf[1]= *compression;
125
gzfile = gzdopen(1, combuf);
126
while((actualread = read(0,buffer,sizeof(buffer))) > 0) {
127
if (actualread < 0 ) {
128
if (errno == EINTR) continue;
129
ohshite(_("%s: internal gzip error: read: `%s'"), v.buf, strerror(errno));
131
actualwrite= gzwrite(gzfile,buffer,actualread);
132
if (actualwrite < 0 ) {
134
const char *errmsg = gzerror(gzfile, &err);
135
if (err == Z_ERRNO) {
136
if (errno == EINTR) continue;
137
errmsg= strerror(errno);
139
ohshite(_("%s: internal gzip error: write: `%s'"), v.buf, errmsg);
141
if (actualwrite != actualread)
142
ohshite(_("%s: internal gzip error: read(%i) != write(%i)"), v.buf, actualread, actualwrite);
148
strncpy(combuf, "-9c", sizeof(combuf));
149
combuf[1]= *compression;
150
fd_fd_filter(fd_in, fd_out, GZIP, "gzip", combuf, v.buf);
152
case compress_type_bzip2:
155
int actualread, actualwrite;
158
strncpy(combuf, "w9", sizeof(combuf));
159
combuf[1]= *compression;
160
bzfile = BZ2_bzdopen(1, combuf);
161
while((actualread = read(0,buffer,sizeof(buffer))) > 0) {
162
if (actualread < 0 ) {
163
if (errno == EINTR) continue;
164
ohshite(_("%s: internal bzip2 error: read: `%s'"), v.buf, strerror(errno));
166
actualwrite= BZ2_bzwrite(bzfile,buffer,actualread);
167
if (actualwrite < 0 ) {
169
const char *errmsg = BZ2_bzerror(bzfile, &err);
170
if (err == BZ_IO_ERROR) {
171
if (errno == EINTR) continue;
172
errmsg= strerror(errno);
174
ohshite(_("%s: internal bzip2 error: write: `%s'"), v.buf, errmsg);
176
if (actualwrite != actualread)
177
ohshite(_("%s: internal bzip2 error: read(%i) != write(%i)"), v.buf, actualread, actualwrite);
183
strncpy(combuf, "-9c", sizeof(combuf));
184
combuf[1]= *compression;
185
fd_fd_filter(fd_in, fd_out, BZIP2, "bzip2", combuf, v.buf);
187
case compress_type_lzma:
188
strncpy(combuf, "-9c", sizeof(combuf));
189
combuf[1] = *compression;
190
fd_fd_filter(fd_in, fd_out, LZMA, "lzma", combuf, v.buf);
191
case compress_type_cat:
192
fd_fd_copy(fd_in, fd_out, -1, _("%s: compression"), v.buf);