-/* $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.
#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 */
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()
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) {
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;
}
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 */
+ }
+}
-/* $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.
* 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));
extern int tflag;
extern int uflag;
extern int vflag;
+extern int zflag;
extern int Dflag;
extern int Hflag;
extern int Lflag;
-/* $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.
#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 */
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)
/*
* 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':
(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
/*
* process option flags
*/
- while ((c = getoldopt(argc, argv, "b:cef:moprutvwxBHLPX014578"))
+ while ((c = getoldopt(argc, argv, "b:cef:moprutvwxzBHLPXZ014578"))
!= EOF) {
switch(c) {
case 'b':
*/
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
*/
Xflag = 1;
break;
+ case 'Z':
+ /*
+ * use compress.
+ */
+ zflag = 1;
+ gzip_program = COMPRESS_CMD;
+ break;
case '0':
arcname = DEV_0;
break;
-/* $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.
#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 */
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 */