Add support for gnutar's -O "extract to stdout" option.

This commit is contained in:
simonb 2003-07-08 06:00:48 +00:00
parent 04392e7f81
commit 1301238ab7
5 changed files with 38 additions and 23 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ar_subs.c,v 1.25 2003/06/23 13:06:53 grant Exp $ */
/* $NetBSD: ar_subs.c,v 1.26 2003/07/08 06:00:48 simonb Exp $ */
/*-
* Copyright (c) 1992 Keith Muller.
@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)ar_subs.c 8.2 (Berkeley) 4/18/94";
#else
__RCSID("$NetBSD: ar_subs.c,v 1.25 2003/06/23 13:06:53 grant Exp $");
__RCSID("$NetBSD: ar_subs.c,v 1.26 2003/07/08 06:00:48 simonb Exp $");
#endif
#endif /* not lint */
@ -308,7 +308,8 @@ extract(void)
/*
* if required, chdir around.
*/
if ((arcn->pat != NULL) && (arcn->pat->chdname != NULL))
if ((arcn->pat != NULL) && (arcn->pat->chdname != NULL) &&
!to_stdout)
if (chdir(arcn->pat->chdname) != 0)
syswarn(1, errno, "Cannot chdir to %s",
arcn->pat->chdname);
@ -336,22 +337,28 @@ extract(void)
}
continue;
}
/*
* we have a file with data here. If we cannot create it, skip
* over the data and purge the name from hard link table
*/
if ((fd = file_creat(arcn)) < 0) {
(void)fflush(listf);
(void)rd_skip(arcn->skip + arcn->pad);
purg_lnk(arcn);
continue;
if (to_stdout)
fd = STDOUT_FILENO;
else {
/*
* We have a file with data here. If we cannot create
* it, skip over the data and purge the name from hard
* link table.
*/
if ((fd = file_creat(arcn)) < 0) {
(void)fflush(listf);
(void)rd_skip(arcn->skip + arcn->pad);
purg_lnk(arcn);
continue;
}
}
/*
* extract the file from the archive and skip over padding and
* any unprocessed data
*/
res = (*frmt->rd_data)(arcn, fd, &cnt);
file_close(arcn, fd);
if (!to_stdout)
file_close(arcn, fd);
if (vflag && vfpart) {
(void)putc('\n', listf);
vfpart = 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: extern.h,v 1.37 2003/02/25 13:36:59 wiz Exp $ */
/* $NetBSD: extern.h,v 1.38 2003/07/08 06:00:48 simonb Exp $ */
/*-
* Copyright (c) 1992 Keith Muller.
@ -251,6 +251,7 @@ extern int pids;
extern int rmleadslash;
extern int exit_val;
extern int docrc;
extern int to_stdout;
extern char *dirptr;
extern char *ltmfrmt;
extern char *argv0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: options.c,v 1.64 2003/04/08 15:13:10 christos Exp $ */
/* $NetBSD: options.c,v 1.65 2003/07/08 06:00:48 simonb Exp $ */
/*-
* Copyright (c) 1992 Keith Muller.
@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)options.c 8.2 (Berkeley) 4/18/94";
#else
__RCSID("$NetBSD: options.c,v 1.64 2003/04/08 15:13:10 christos Exp $");
__RCSID("$NetBSD: options.c,v 1.65 2003/07/08 06:00:48 simonb Exp $");
#endif
#endif /* not lint */
@ -709,6 +709,7 @@ struct option tar_longopts[] = {
{ "gunzip", no_argument, 0, 'z' },
{ "read-full-blocks", no_argument, 0, 'B' },
{ "directory", required_argument, 0, 'C' },
{ "to-stdout", no_argument, 0, 'O' },
{ "absolute-paths", no_argument, 0, 'P' },
{ "files-from", required_argument, 0, 'T' },
{ "exclude-from", required_argument, 0, 'X' },
@ -749,7 +750,6 @@ struct option tar_longopts[] = {
{ "multi-volume", no_argument, 0, 'M' },
{ "after-date", required_argument, 0, 'N' },
{ "newer", required_argument, 0, 'N' },
{ "to-stdout", no_argument, 0, 'O' },
{ "record-number", no_argument, 0, 'R' },
{ "remove-files", no_argument, 0,
OPT_REMOVE_FILES },
@ -1076,8 +1076,13 @@ tar_options(int argc, char **argv)
if (act == ARCHIVE || act == APPND)
frmt = &(fsub[Oflag ? F_TAR : F_USTAR]);
else if (Oflag) {
tty_warn(1, "The -O/-o options are only valid when writing an archive");
tar_usage(); /* only valid when writing */
if (act == EXTRACT)
to_stdout = 1;
else {
tty_warn(1, "The -O/-o options are only valid when "
"writing or extracting an archive");
tar_usage();
}
}
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: pax.c,v 1.27 2003/06/23 13:06:53 grant Exp $ */
/* $NetBSD: pax.c,v 1.28 2003/07/08 06:00:49 simonb Exp $ */
/*-
* Copyright (c) 1992 Keith Muller.
@ -47,7 +47,7 @@ __COPYRIGHT("@(#) Copyright (c) 1992, 1993\n\
#if 0
static char sccsid[] = "@(#)pax.c 8.2 (Berkeley) 4/18/94";
#else
__RCSID("$NetBSD: pax.c,v 1.27 2003/06/23 13:06:53 grant Exp $");
__RCSID("$NetBSD: pax.c,v 1.28 2003/07/08 06:00:49 simonb Exp $");
#endif
#endif /* not lint */
@ -107,6 +107,7 @@ int pids; /* preserve file uid/gid */
int rmleadslash = 0; /* remove leading '/' from pathnames */
int exit_val; /* exit value */
int docrc; /* check/create file crc */
int to_stdout; /* extract to stdout */
char *dirptr; /* destination dir in a copy */
char *ltmfrmt; /* -v locale time format (if any) */
char *argv0; /* root of argv[0] */

View File

@ -1,4 +1,4 @@
.\" $NetBSD: tar.1,v 1.11 2003/04/10 06:07:40 grant Exp $
.\" $NetBSD: tar.1,v 1.12 2003/07/08 06:00:49 simonb Exp $
.\"
.\" Copyright (c) 1996 SigmaSoft, Th. Lockert
.\" All rights reserved.
@ -124,7 +124,8 @@ Do not cross filesystems.
.It Fl m , -modification-time
Do not preserve modification time.
.It Fl O
Write old-style (non-POSIX) archives.
When creating and appending to an archive, write old-style (non-POSIX) archives.
When extracting from an archive, extract to standard output.
.It Fl o , -portability , -old-archive
Don't write directory information that the older (V7) style
.Nm