diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2000-06-09 16:37:55 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2000-06-09 16:37:55 +0000 |
commit | f6f08f73cb61ccff13d5d26d55298321c9725744 (patch) | |
tree | d6e6845f46812736a4e68cef4cafa678a9626d3b /bin/pax | |
parent | dd13259d5d5223a51db5eb4ec68f5dc885f6184b (diff) |
Some minor cleanup, ok'd millert@
- remove zflag variable, since gzip_program is enough to know what's
going on.
- fix ar_gzip call to not depend on global variables. Avoid bogus act
checks, avoid calling if fd == -1.
- do gzip check for append as early as possible.
- remove old K&R prototype when updating.
Diffstat (limited to 'bin/pax')
-rw-r--r-- | bin/pax/ar_io.c | 46 | ||||
-rw-r--r-- | bin/pax/extern.h | 5 | ||||
-rw-r--r-- | bin/pax/options.c | 9 | ||||
-rw-r--r-- | bin/pax/pax.c | 8 |
4 files changed, 22 insertions, 46 deletions
diff --git a/bin/pax/ar_io.c b/bin/pax/ar_io.c index c95c41de9c9..02acf481888 100644 --- a/bin/pax/ar_io.c +++ b/bin/pax/ar_io.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ar_io.c,v 1.19 1999/08/04 17:13:24 espie Exp $ */ +/* $OpenBSD: ar_io.c,v 1.20 2000/06/09 16:37:54 espie Exp $ */ /* $NetBSD: ar_io.c,v 1.5 1996/03/26 23:54:13 mrg Exp $ */ /*- @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)ar_io.c 8.2 (Berkeley) 4/18/94"; #else -static char rcsid[] = "$OpenBSD: ar_io.c,v 1.19 1999/08/04 17:13:24 espie Exp $"; +static char rcsid[] = "$OpenBSD: ar_io.c,v 1.20 2000/06/09 16:37:54 espie Exp $"; #endif #endif /* not lint */ @@ -87,12 +87,12 @@ 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 */ +const char *gzip_program; /* name of gzip program */ static pid_t zpid = -1; /* pid of child process */ static int get_phys __P((void)); extern sigset_t s_mask; -static void ar_start_gzip __P((int)); +static void ar_start_gzip __P((int, const char *, int)); /* * ar_open() @@ -132,8 +132,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); + if (arfd != -1 && gzip_program != NULL) + ar_start_gzip(arfd, gzip_program, 0); break; case ARCHIVE: if (name == NULL) { @@ -143,12 +143,10 @@ ar_open(name) syswarn(0, errno, "Failed open to write on %s", name); else can_unlnk = 1; - if (zflag) - ar_start_gzip(arfd); + if (arfd != -1 && gzip_program != NULL) + ar_start_gzip(arfd, gzip_program, 1); break; case APPND: - if (zflag) - err(1, "can not gzip while appending"); if (name == NULL) { arfd = STDOUT_FILENO; arcname = STDO; @@ -1321,12 +1319,7 @@ ar_next() * 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 +ar_start_gzip(int fd, const char *gzip_program, int wr) { int fds[2]; char *gzip_flags; @@ -1339,34 +1332,21 @@ ar_start_gzip(fd) /* parent */ if (zpid) { - switch (act) { - case ARCHIVE: + if (wr) dup2(fds[1], fd); - break; - case LIST: - case EXTRACT: + else dup2(fds[0], fd); - break; - default: - errx(1, "ar_start_gzip: impossible"); - } close(fds[0]); close(fds[1]); } else { - switch (act) { - case ARCHIVE: + if (wr) { dup2(fds[0], STDIN_FILENO); dup2(fd, STDOUT_FILENO); gzip_flags = "-c"; - break; - case LIST: - case EXTRACT: + } else { 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]); diff --git a/bin/pax/extern.h b/bin/pax/extern.h index df441731d48..fba5f842d0a 100644 --- a/bin/pax/extern.h +++ b/bin/pax/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.15 1998/09/20 02:22:21 millert Exp $ */ +/* $OpenBSD: extern.h,v 1.16 2000/06/09 16:37:54 espie Exp $ */ /* $NetBSD: extern.h,v 1.5 1996/03/26 23:54:16 mrg Exp $ */ /*- @@ -50,7 +50,7 @@ * ar_io.c */ extern char *arcname; -extern char *gzip_program; +extern const char *gzip_program; int ar_open __P((char *)); void ar_close __P((void)); void ar_drain __P((void)); @@ -219,7 +219,6 @@ 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 f1ecc81ce5b..d1af16a99a0 100644 --- a/bin/pax/options.c +++ b/bin/pax/options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options.c,v 1.41 2000/01/22 20:24:52 deraadt Exp $ */ +/* $OpenBSD: options.c,v 1.42 2000/06/09 16:37:54 espie Exp $ */ /* $NetBSD: options.c,v 1.6 1996/03/26 23:54:18 mrg Exp $ */ /*- @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)options.c 8.2 (Berkeley) 4/18/94"; #else -static char rcsid[] = "$OpenBSD: options.c,v 1.41 2000/01/22 20:24:52 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: options.c,v 1.42 2000/06/09 16:37:54 espie Exp $"; #endif #endif /* not lint */ @@ -397,7 +397,6 @@ pax_options(argc, argv) /* * use gzip. Non standard option. */ - zflag = 1; gzip_program = GZIP_CMD; break; case 'B': @@ -735,7 +734,6 @@ tar_options(argc, argv) /* * use gzip. Non standard option. */ - zflag = 1; gzip_program = GZIP_CMD; break; case 'B': @@ -774,7 +772,6 @@ tar_options(argc, argv) /* * use compress. */ - zflag = 1; gzip_program = COMPRESS_CMD; break; case '0': @@ -1096,7 +1093,6 @@ cpio_options(argc, argv) /* * use gzip. Non standard option. */ - zflag = 1; gzip_program = GZIP_CMD; break; case 'A': @@ -1179,7 +1175,6 @@ cpio_options(argc, argv) /* * use compress. Non standard option. */ - zflag = 1; gzip_program = COMPRESS_CMD; break; case '6': diff --git a/bin/pax/pax.c b/bin/pax/pax.c index 637e2f3ecbb..f8e614711fe 100644 --- a/bin/pax/pax.c +++ b/bin/pax/pax.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pax.c,v 1.14 1998/09/20 02:22:22 millert Exp $ */ +/* $OpenBSD: pax.c,v 1.15 2000/06/09 16:37:54 espie Exp $ */ /* $NetBSD: pax.c,v 1.5 1996/03/26 23:54:20 mrg Exp $ */ /*- @@ -48,7 +48,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)pax.c 8.2 (Berkeley) 4/18/94"; #else -static char rcsid[] = "$OpenBSD: pax.c,v 1.14 1998/09/20 02:22:22 millert Exp $"; +static char rcsid[] = "$OpenBSD: pax.c,v 1.15 2000/06/09 16:37:54 espie Exp $"; #endif #endif /* not lint */ @@ -63,6 +63,7 @@ static char rcsid[] = "$OpenBSD: pax.c,v 1.14 1998/09/20 02:22:22 millert Exp $" #include <stdlib.h> #include <string.h> #include <errno.h> +#include <err.h> #include <fcntl.h> #include "pax.h" #include "extern.h" @@ -87,7 +88,6 @@ 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 */ @@ -266,6 +266,8 @@ main(argc, argv) archive(); break; case APPND: + if (gzip_program != NULL) + err(1, "can not gzip while appending"); append(); break; case COPY: |