1
0
mirror of https://git.FreeBSD.org/src.git synced 2025-01-20 15:43:16 +00:00

Support -t -O as in gtar. Perversely enough, -O means "send to stderr"

when used with -t, "send to stdout" when used with -x.

Thanks to: Ryan Hamilton for pointing out this odd beast
MFC after: 3 days
This commit is contained in:
Tim Kientzle 2004-08-27 04:13:15 +00:00
parent 20192d1959
commit 773d437982
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=134369
2 changed files with 16 additions and 11 deletions

View File

@ -481,7 +481,7 @@ main(int argc, char **argv)
if (bsdtar->option_no_subdirs)
only_mode(bsdtar, "-n", "cru");
if (bsdtar->option_stdout)
only_mode(bsdtar, "-O", "x");
only_mode(bsdtar, "-O", "xt");
if (bsdtar->option_warn_links)
only_mode(bsdtar, "--check-links", "cr");

View File

@ -46,7 +46,8 @@ __FBSDID("$FreeBSD$");
#include "bsdtar.h"
static void cleanup_security(struct bsdtar *);
static void list_item_verbose(struct bsdtar *, struct archive_entry *);
static void list_item_verbose(struct bsdtar *, FILE *,
struct archive_entry *);
static void read_archive(struct bsdtar *bsdtar, char mode);
static int security_problem(struct bsdtar *, struct archive_entry *);
@ -68,6 +69,7 @@ tar_mode_x(struct bsdtar *bsdtar)
static void
read_archive(struct bsdtar *bsdtar, char mode)
{
FILE *out;
struct archive *a;
struct archive_entry *entry;
int r;
@ -117,30 +119,34 @@ read_archive(struct bsdtar *bsdtar, char mode)
continue;
if (mode == 't') {
/* Perversely, gtar uses -O to mean "send to stderr"
* when used with -t. */
out = bsdtar->option_stdout ? stderr : stdout;
if (bsdtar->verbose < 2)
safe_fprintf(stdout, "%s",
safe_fprintf(out, "%s",
archive_entry_pathname(entry));
else
list_item_verbose(bsdtar, entry);
fflush(stdout);
list_item_verbose(bsdtar, out, entry);
fflush(out);
r = archive_read_data_skip(a);
if (r == ARCHIVE_WARN) {
fprintf(stdout, "\n");
fprintf(out, "\n");
bsdtar_warnc(bsdtar, 0, "%s",
archive_error_string(a));
}
if (r == ARCHIVE_RETRY) {
fprintf(stdout, "\n");
fprintf(out, "\n");
bsdtar_warnc(bsdtar, 0, "%s",
archive_error_string(a));
}
if (r == ARCHIVE_FATAL) {
fprintf(stdout, "\n");
fprintf(out, "\n");
bsdtar_warnc(bsdtar, 0, "%s",
archive_error_string(a));
break;
}
fprintf(stdout, "\n");
fprintf(out, "\n");
} else {
if (bsdtar->option_interactive &&
!yes("extract '%s'", archive_entry_pathname(entry)))
@ -199,9 +205,8 @@ read_archive(struct bsdtar *bsdtar, char mode)
* and 'pax -l' is documented as using the same format as 'ls -l'.
*/
static void
list_item_verbose(struct bsdtar *bsdtar, struct archive_entry *entry)
list_item_verbose(struct bsdtar *bsdtar, FILE *out, struct archive_entry *entry)
{
FILE *out = stdout;
const struct stat *st;
char tmp[100];
size_t w;