#include "dpkg.h"
#include "dpkg-db.h"
+static void
+fd_fd_filter(int fd_in, int fd_out,
+ const char *file, const char *cmd, const char *args,
+ const char *desc)
+{
+ if (fd_in != 0) {
+ m_dup2(fd_in, 0);
+ close(fd_in);
+ }
+ if (fd_out != 1) {
+ m_dup2(fd_out, 1);
+ close(fd_out);
+ }
+ execlp(file, cmd, args, NULL);
+ ohshite(_("%s: failed to exec '%s %s'"), desc, cmd, args);
+}
+
void decompress_cat(enum compression_type type, int fd_in, int fd_out, char *desc, ...) {
va_list al;
struct varbuf v;
}
exit(0);
#else
- if (fd_in != 0) {
- m_dup2(fd_in, 0);
- close(fd_in);
- }
- if (fd_out != 1) {
- m_dup2(fd_out, 1);
- close(fd_out);
- }
- execlp(GZIP,"gzip","-dc",(char*)0); ohshite(_("%s: failed to exec gzip -dc"), v.buf);
+ fd_fd_filter(fd_in, fd_out, GZIP, "gzip", "-dc", v.buf);
#endif
case BZ2:
#ifdef WITH_BZ2
}
exit(0);
#else
- if (fd_in != 0) {
- m_dup2(fd_in, 0);
- close(fd_in);
- }
- if (fd_out != 1) {
- m_dup2(fd_out, 1);
- close(fd_out);
- }
- execlp(BZIP2,"bzip2","-dc",(char*)0); ohshite(_("%s: failed to exec bzip2 -dc"), v.buf);
+ fd_fd_filter(fd_in, fd_out, BZIP2, "bzip2", "-dc", v.buf);
#endif
case compress_type_lzma:
- if (fd_in != 0) {
- m_dup2(fd_in, 0);
- close(fd_in);
- }
- if (fd_out != 1) {
- m_dup2(fd_out, 1);
- close(fd_out);
- }
- execlp(LZMA, "lzma", "-dc", (char *)0);
- ohshite(_("%s: failed to exec %s"), v.buf, "lzma -dc");
+ fd_fd_filter(fd_in, fd_out, LZMA, "lzma", "-dc", v.buf);
case CAT:
fd_fd_copy(fd_in, fd_out, -1, _("%s: decompression"), v.buf);
exit(0);
exit(0);
}
#else
- if (fd_in != 0) {
- m_dup2(fd_in, 0);
- close(fd_in);
- }
- if (fd_out != 1) {
- m_dup2(fd_out, 1);
- close(fd_out);
- }
strncpy(combuf, "-9c", sizeof(combuf));
combuf[1]= *compression;
- execlp(GZIP,"gzip",combuf,(char*)0); ohshit(_("%s: failed to exec gzip %s"), v.buf, combuf);
+ fd_fd_filter(fd_in, fd_out, GZIP, "gzip", combuf, v.buf);
#endif
case BZ2:
#ifdef WITH_BZ2
exit(0);
}
#else
- if (fd_in != 0) {
- m_dup2(fd_in, 0);
- close(fd_in);
- }
- if (fd_out != 1) {
- m_dup2(fd_out, 1);
- close(fd_out);
- }
strncpy(combuf, "-9c", sizeof(combuf));
combuf[1]= *compression;
- execlp(BZIP2,"bzip2",combuf,(char*)0); ohshit(_("%s: failed to exec bzip2 %s"), v.buf, combuf);
+ fd_fd_filter(fd_in, fd_out, BZIP2, "bzip2", combuf, v.buf);
#endif
case CAT:
fd_fd_copy(fd_in, fd_out, -1, _("%s: compression"), v.buf);