summaryrefslogtreecommitdiff
path: root/bin/pax
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1996-04-19 02:24:59 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1996-04-19 02:24:59 +0000
commit63b4d3b7796d956b66d8abeae61895b9c18137cf (patch)
treed68a2d8ed0cdf6f63628451be47fe9c1cc3ce712 /bin/pax
parent30887e358421523b225907c50935e4d5df878342 (diff)
from mrg; impliment -z (gzip) in pax and tar, and -Z (compress) in tar
Diffstat (limited to 'bin/pax')
-rw-r--r--bin/pax/ar_io.c74
-rw-r--r--bin/pax/extern.h4
-rw-r--r--bin/pax/options.c32
-rw-r--r--bin/pax/pax.c5
4 files changed, 106 insertions, 9 deletions
diff --git a/bin/pax/ar_io.c b/bin/pax/ar_io.c
index 46a8cc98346..7cef8d2e67a 100644
--- a/bin/pax/ar_io.c
+++ b/bin/pax/ar_io.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ar_io.c,v 1.4 1995/03/21 09:07:04 cgd Exp $ */
+/* $NetBSD: ar_io.c,v 1.5 1996/03/26 23:54:13 mrg Exp $ */
/*-
* Copyright (c) 1992 Keith Muller.
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)ar_io.c 8.2 (Berkeley) 4/18/94";
#else
-static char rcsid[] = "$NetBSD: ar_io.c,v 1.4 1995/03/21 09:07:04 cgd Exp $";
+static char rcsid[] = "$NetBSD: ar_io.c,v 1.5 1996/03/26 23:54:13 mrg Exp $";
#endif
#endif /* not lint */
@@ -84,9 +84,11 @@ static int invld_rec; /* tape has out of spec record size */
static int wr_trail = 1; /* trailer was rewritten in append */
static int can_unlnk = 0; /* do we unlink null archives? */
char *arcname; /* printable name of archive */
+char *gzip_program; /* name of gzip program */
static int get_phys __P((void));
extern sigset_t s_mask;
+static void ar_start_gzip __P((int));
/*
* ar_open()
@@ -126,6 +128,8 @@ ar_open(name)
arcname = STDN;
} else if ((arfd = open(name, EXT_MODE, DMOD)) < 0)
syswarn(0, errno, "Failed open to read on %s", name);
+ if (zflag)
+ ar_start_gzip(arfd);
break;
case ARCHIVE:
if (name == NULL) {
@@ -135,8 +139,12 @@ ar_open(name)
syswarn(0, errno, "Failed open to write on %s", name);
else
can_unlnk = 1;
+ if (zflag)
+ ar_start_gzip(arfd);
break;
case APPND:
+ if (zflag)
+ err(1, "can not gzip while appending");
if (name == NULL) {
arfd = STDOUT_FILENO;
arcname = STDO;
@@ -1292,3 +1300,65 @@ ar_next()
}
return(0);
}
+
+/*
+ * ar_start_gzip()
+ * starts the gzip compression/decompression process as a child, using magic
+ * to keep the fd the same in the calling function (parent).
+ */
+void
+#ifdef __STDC__
+ar_start_gzip(int fd)
+#else
+ar_start_gzip(fd)
+ int fd;
+#endif
+{
+ pid_t pid;
+ int fds[2];
+ char *gzip_flags;
+
+ if (pipe(fds) < 0)
+ err(1, "could not pipe");
+ pid = fork();
+ if (pid < 0)
+ err(1, "could not fork");
+
+ /* parent */
+ if (pid) {
+ switch (act) {
+ case ARCHIVE:
+ dup2(fds[1], fd);
+ break;
+ case LIST:
+ case EXTRACT:
+ dup2(fds[0], fd);
+ break;
+ default:
+ errx(1, "ar_start_gzip: impossible");
+ }
+ close(fds[0]);
+ close(fds[1]);
+ } else {
+ switch (act) {
+ case ARCHIVE:
+ dup2(fds[0], STDIN_FILENO);
+ dup2(fd, STDOUT_FILENO);
+ gzip_flags = "-c";
+ break;
+ case LIST:
+ case EXTRACT:
+ dup2(fds[1], STDOUT_FILENO);
+ dup2(fd, STDIN_FILENO);
+ gzip_flags = "-dc";
+ break;
+ default:
+ errx(1, "ar_start_gzip: impossible");
+ }
+ close(fds[0]);
+ close(fds[1]);
+ if (execlp(gzip_program, gzip_program, gzip_flags, NULL) < 0)
+ err(1, "could not exec");
+ /* NOTREACHED */
+ }
+}
diff --git a/bin/pax/extern.h b/bin/pax/extern.h
index 34a04d6ca43..fe198b0508f 100644
--- a/bin/pax/extern.h
+++ b/bin/pax/extern.h
@@ -1,4 +1,4 @@
-/* $NetBSD: extern.h,v 1.4 1995/03/21 09:07:16 cgd Exp $ */
+/* $NetBSD: extern.h,v 1.5 1996/03/26 23:54:16 mrg Exp $ */
/*-
* Copyright (c) 1992 Keith Muller.
@@ -49,6 +49,7 @@
* ar_io.c
*/
extern char *arcname;
+extern char *gzip_program;
int ar_open __P((char *));
void ar_close __P((void));
void ar_drain __P((void));
@@ -215,6 +216,7 @@ extern int nflag;
extern int tflag;
extern int uflag;
extern int vflag;
+extern int zflag;
extern int Dflag;
extern int Hflag;
extern int Lflag;
diff --git a/bin/pax/options.c b/bin/pax/options.c
index fb773b08823..5c916ee8126 100644
--- a/bin/pax/options.c
+++ b/bin/pax/options.c
@@ -1,4 +1,4 @@
-/* $NetBSD: options.c,v 1.5 1995/03/21 09:07:30 cgd Exp $ */
+/* $NetBSD: options.c,v 1.6 1996/03/26 23:54:18 mrg Exp $ */
/*-
* Copyright (c) 1992 Keith Muller.
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)options.c 8.2 (Berkeley) 4/18/94";
#else
-static char rcsid[] = "$NetBSD: options.c,v 1.5 1995/03/21 09:07:30 cgd Exp $";
+static char rcsid[] = "$NetBSD: options.c,v 1.6 1996/03/26 23:54:18 mrg Exp $";
#endif
#endif /* not lint */
@@ -83,6 +83,9 @@ static void cpio_options __P((register int, register char **));
static void cpio_usage __P((void));
#endif
+#define GZIP_CMD "gzip" /* command to run as gzip */
+#define COMPRESS_CMD "compress" /* command to run as compress */
+
/*
* Format specific routine table - MUST BE IN SORTED ORDER BY NAME
* (see pax.h for description of each function)
@@ -199,7 +202,7 @@ pax_options(argc, argv)
/*
* process option flags
*/
- while ((c=getopt(argc,argv,"ab:cdf:iklno:p:rs:tuvwx:B:DE:G:HLPT:U:XYZ"))
+ while ((c=getopt(argc,argv,"ab:cdf:iklno:p:rs:tuvwx:zB:DE:G:HLPT:U:XYZ"))
!= EOF) {
switch (c) {
case 'a':
@@ -383,6 +386,13 @@ pax_options(argc, argv)
(void)fputs("\n\n", stderr);
pax_usage();
break;
+ case 'z':
+ /*
+ * use gzip. Non standard option.
+ */
+ zflag = 1;
+ gzip_program = GZIP_CMD;
+ break;
case 'B':
/*
* non-standard option on number of bytes written on a
@@ -594,7 +604,7 @@ tar_options(argc, argv)
/*
* process option flags
*/
- while ((c = getoldopt(argc, argv, "b:cef:moprutvwxBHLPX014578"))
+ while ((c = getoldopt(argc, argv, "b:cef:moprutvwxzBHLPXZ014578"))
!= EOF) {
switch(c) {
case 'b':
@@ -684,6 +694,13 @@ tar_options(argc, argv)
*/
act = EXTRACT;
break;
+ case 'z':
+ /*
+ * use gzip. Non standard option.
+ */
+ zflag = 1;
+ gzip_program = GZIP_CMD;
+ break;
case 'B':
/*
* Nothing to do here, this is pax default
@@ -713,6 +730,13 @@ tar_options(argc, argv)
*/
Xflag = 1;
break;
+ case 'Z':
+ /*
+ * use compress.
+ */
+ zflag = 1;
+ gzip_program = COMPRESS_CMD;
+ break;
case '0':
arcname = DEV_0;
break;
diff --git a/bin/pax/pax.c b/bin/pax/pax.c
index 3fe7ca2df7e..94857a240e7 100644
--- a/bin/pax/pax.c
+++ b/bin/pax/pax.c
@@ -1,4 +1,4 @@
-/* $NetBSD: pax.c,v 1.4 1995/03/21 09:07:39 cgd Exp $ */
+/* $NetBSD: pax.c,v 1.5 1996/03/26 23:54:20 mrg Exp $ */
/*-
* Copyright (c) 1992 Keith Muller.
@@ -47,7 +47,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)pax.c 8.2 (Berkeley) 4/18/94";
#else
-static char rcsid[] = "$NetBSD: pax.c,v 1.4 1995/03/21 09:07:39 cgd Exp $";
+static char rcsid[] = "$NetBSD: pax.c,v 1.5 1996/03/26 23:54:20 mrg Exp $";
#endif
#endif /* not lint */
@@ -83,6 +83,7 @@ int nflag; /* select first archive member match */
int tflag; /* restore access time after read */
int uflag; /* ignore older modification time files */
int vflag; /* produce verbose output */
+int zflag; /* use gzip */
int Dflag; /* same as uflag except inode change time */
int Hflag; /* follow command line symlinks (write only) */
int Lflag; /* follow symlinks when writing */