diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2002-09-28 02:06:39 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2002-09-28 02:06:39 +0000 |
commit | 8132e933e6cf0e6bffccb1902f872b584a32c580 (patch) | |
tree | 630493464ea2911161899635bd97a40c713d2781 /archival/tar.c | |
parent | 92052e3945820f50e71737658997cc35ed287105 (diff) | |
download | busybox-w32-8132e933e6cf0e6bffccb1902f872b584a32c580.tar.gz busybox-w32-8132e933e6cf0e6bffccb1902f872b584a32c580.tar.bz2 busybox-w32-8132e933e6cf0e6bffccb1902f872b584a32c580.zip |
Fix for using '-' as the filename when reading from stdin
Diffstat (limited to 'archival/tar.c')
-rw-r--r-- | archival/tar.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/archival/tar.c b/archival/tar.c index 6ef698edf..0f0d4fd6f 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -626,14 +626,6 @@ int tar_main(int argc, char **argv) | |||
626 | tar_handle->src_fd = fileno(stdin); | 626 | tar_handle->src_fd = fileno(stdin); |
627 | tar_handle->flags = ARCHIVE_CREATE_LEADING_DIRS; | 627 | tar_handle->flags = ARCHIVE_CREATE_LEADING_DIRS; |
628 | 628 | ||
629 | /* Prepend '-' to the first argument if required */ | ||
630 | if (argv[1][0] != '-') { | ||
631 | char *tmp = xmalloc(strlen(argv[1]) + 2); | ||
632 | |||
633 | tmp[0] = '-'; | ||
634 | strcpy(tmp + 1, argv[1]); | ||
635 | argv[1] = tmp; | ||
636 | } | ||
637 | while ((opt = getopt(argc, argv, "ctxT:X:C:f:Opvz")) != -1) { | 629 | while ((opt = getopt(argc, argv, "ctxT:X:C:f:Opvz")) != -1) { |
638 | switch (opt) { | 630 | switch (opt) { |
639 | /* One and only one of these is required */ | 631 | /* One and only one of these is required */ |
@@ -704,6 +696,10 @@ int tar_main(int argc, char **argv) | |||
704 | } | 696 | } |
705 | } | 697 | } |
706 | 698 | ||
699 | if (*argv[optind] == '-') { | ||
700 | optind++; | ||
701 | } | ||
702 | |||
707 | /* Setup an array of filenames to work with */ | 703 | /* Setup an array of filenames to work with */ |
708 | /* TODO: This is the same as in ar, seperate function ? */ | 704 | /* TODO: This is the same as in ar, seperate function ? */ |
709 | while (optind < argc) { | 705 | while (optind < argc) { |
@@ -750,7 +746,9 @@ int tar_main(int argc, char **argv) | |||
750 | while (get_header_tar(tar_handle) == EXIT_SUCCESS); | 746 | while (get_header_tar(tar_handle) == EXIT_SUCCESS); |
751 | 747 | ||
752 | #ifdef CONFIG_FEATURE_CLEAN_UP | 748 | #ifdef CONFIG_FEATURE_CLEAN_UP |
753 | close(tar_handle->src_fd); | 749 | if (tar_handle->src_fd != fileno(stdin)) { |
750 | close(tar_handle->src_fd); | ||
751 | } | ||
754 | #endif | 752 | #endif |
755 | 753 | ||
756 | return(EXIT_SUCCESS); | 754 | return(EXIT_SUCCESS); |