diff options
author | Eric Andersen <andersen@codepoet.org> | 2000-07-21 22:17:39 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2000-07-21 22:17:39 +0000 |
commit | ea824fb9370c41756a75b70698b6222b3386f6c5 (patch) | |
tree | d310abbb240cf220b268843d033cee845f6f8486 /archival | |
parent | bf960f58e2fc56402cc5c3c090d90b706a4de5f2 (diff) | |
download | busybox-w32-ea824fb9370c41756a75b70698b6222b3386f6c5.tar.gz busybox-w32-ea824fb9370c41756a75b70698b6222b3386f6c5.tar.bz2 busybox-w32-ea824fb9370c41756a75b70698b6222b3386f6c5.zip |
Fixed stdin/stdout paths so things like
tar cvf - /etc/* | gzip -c9 >test.tgz
will now work. Fix thanks to Dave Cinege <dcinege@psychosis.com>
with some adjustments by me to be mroe GNU-like.
-Erik
Diffstat (limited to 'archival')
-rw-r--r-- | archival/gunzip.c | 28 | ||||
-rw-r--r-- | archival/gzip.c | 18 |
2 files changed, 35 insertions, 11 deletions
diff --git a/archival/gunzip.c b/archival/gunzip.c index b29bdf7c1..330dee335 100644 --- a/archival/gunzip.c +++ b/archival/gunzip.c | |||
@@ -569,19 +569,20 @@ local int get_method (int in); | |||
569 | int gunzip_main(int argc, char **argv) | 569 | int gunzip_main(int argc, char **argv) |
570 | { | 570 | { |
571 | int file_count; /* number of files to precess */ | 571 | int file_count; /* number of files to precess */ |
572 | int to_stdout = 0; | 572 | int tostdout = 0; |
573 | int fromstdin = 0; | 573 | int fromstdin = 0; |
574 | int result; | 574 | int result; |
575 | int inFileNum; | 575 | int inFileNum; |
576 | int outFileNum; | 576 | int outFileNum; |
577 | int delInputFile = 0; | 577 | int delInputFile = 0; |
578 | int force = 0; | ||
578 | struct stat statBuf; | 579 | struct stat statBuf; |
579 | char *delFileName; | 580 | char *delFileName; |
580 | char ifname[MAX_PATH_LEN + 1]; /* input file name */ | 581 | char ifname[MAX_PATH_LEN + 1]; /* input file name */ |
581 | char ofname[MAX_PATH_LEN + 1]; /* output file name */ | 582 | char ofname[MAX_PATH_LEN + 1]; /* output file name */ |
582 | 583 | ||
583 | if (strcmp(applet_name, "zcat") == 0) { | 584 | if (strcmp(applet_name, "zcat") == 0) { |
584 | to_stdout = 1; | 585 | tostdout = 1; |
585 | if (argc == 1) { | 586 | if (argc == 1) { |
586 | fromstdin = 1; | 587 | fromstdin = 1; |
587 | } | 588 | } |
@@ -590,23 +591,32 @@ int gunzip_main(int argc, char **argv) | |||
590 | /* Parse any options */ | 591 | /* Parse any options */ |
591 | while (--argc > 0 && **(++argv) == '-') { | 592 | while (--argc > 0 && **(++argv) == '-') { |
592 | if (*((*argv) + 1) == '\0') { | 593 | if (*((*argv) + 1) == '\0') { |
593 | fromstdin = 1; | 594 | tostdout = 1; |
594 | to_stdout = 1; | ||
595 | } | 595 | } |
596 | while (*(++(*argv))) { | 596 | while (*(++(*argv))) { |
597 | switch (**argv) { | 597 | switch (**argv) { |
598 | case 'c': | 598 | case 'c': |
599 | to_stdout = 1; | 599 | tostdout = 1; |
600 | break; | 600 | break; |
601 | case 't': | 601 | case 't': |
602 | test_mode = 1; | 602 | test_mode = 1; |
603 | break; | 603 | break; |
604 | 604 | case 'f': | |
605 | force = 1; | ||
606 | break; | ||
605 | default: | 607 | default: |
606 | usage(gunzip_usage); | 608 | usage(gunzip_usage); |
607 | } | 609 | } |
608 | } | 610 | } |
609 | } | 611 | } |
612 | if (argc <= 0) | ||
613 | fromstdin = 1; | ||
614 | |||
615 | if (isatty(fileno(stdin)) && fromstdin==1 && force==0) | ||
616 | fatalError( "data not read from terminal. Use -f to force it.\n"); | ||
617 | if (isatty(fileno(stdout)) && tostdout==1 && force==0) | ||
618 | fatalError( "data not written to terminal. Use -f to force it.\n"); | ||
619 | |||
610 | 620 | ||
611 | foreground = signal(SIGINT, SIG_IGN) != SIG_IGN; | 621 | foreground = signal(SIGINT, SIG_IGN) != SIG_IGN; |
612 | if (foreground) { | 622 | if (foreground) { |
@@ -644,7 +654,7 @@ int gunzip_main(int argc, char **argv) | |||
644 | ifile_size = -1L; /* convention for unknown size */ | 654 | ifile_size = -1L; /* convention for unknown size */ |
645 | } else { | 655 | } else { |
646 | /* Open up the input file */ | 656 | /* Open up the input file */ |
647 | if (*argv == '\0') | 657 | if (argc <= 0) |
648 | usage(gunzip_usage); | 658 | usage(gunzip_usage); |
649 | if (strlen(*argv) > MAX_PATH_LEN) { | 659 | if (strlen(*argv) > MAX_PATH_LEN) { |
650 | errorMsg(name_too_long); | 660 | errorMsg(name_too_long); |
@@ -667,7 +677,7 @@ int gunzip_main(int argc, char **argv) | |||
667 | ifile_size = statBuf.st_size; | 677 | ifile_size = statBuf.st_size; |
668 | } | 678 | } |
669 | 679 | ||
670 | if (to_stdout == 1) { | 680 | if (tostdout == 1) { |
671 | /* And get to work */ | 681 | /* And get to work */ |
672 | strcpy(ofname, "stdout"); | 682 | strcpy(ofname, "stdout"); |
673 | outFileNum = fileno(stdout); | 683 | outFileNum = fileno(stdout); |
@@ -741,7 +751,7 @@ int gunzip_main(int argc, char **argv) | |||
741 | 751 | ||
742 | /* ======================================================================== | 752 | /* ======================================================================== |
743 | * Check the magic number of the input file and update ofname if an | 753 | * Check the magic number of the input file and update ofname if an |
744 | * original name was given and to_stdout is not set. | 754 | * original name was given and tostdout is not set. |
745 | * Return the compression method, -1 for error, -2 for warning. | 755 | * Return the compression method, -1 for error, -2 for warning. |
746 | * Set inptr to the offset of the next byte to be processed. | 756 | * Set inptr to the offset of the next byte to be processed. |
747 | * Updates time_stamp if there is one and --no-time is not used. | 757 | * Updates time_stamp if there is one and --no-time is not used. |
diff --git a/archival/gzip.c b/archival/gzip.c index 98ce259ca..19ad1a729 100644 --- a/archival/gzip.c +++ b/archival/gzip.c | |||
@@ -1801,6 +1801,7 @@ int gzip_main(int argc, char **argv) | |||
1801 | char *delFileName; | 1801 | char *delFileName; |
1802 | int tostdout = 0; | 1802 | int tostdout = 0; |
1803 | int fromstdin = 0; | 1803 | int fromstdin = 0; |
1804 | int force = 0; | ||
1804 | 1805 | ||
1805 | if (argc == 1) | 1806 | if (argc == 1) |
1806 | usage(gzip_usage); | 1807 | usage(gzip_usage); |
@@ -1808,7 +1809,6 @@ int gzip_main(int argc, char **argv) | |||
1808 | /* Parse any options */ | 1809 | /* Parse any options */ |
1809 | while (--argc > 0 && **(++argv) == '-') { | 1810 | while (--argc > 0 && **(++argv) == '-') { |
1810 | if (*((*argv) + 1) == '\0') { | 1811 | if (*((*argv) + 1) == '\0') { |
1811 | fromstdin = 1; | ||
1812 | tostdout = 1; | 1812 | tostdout = 1; |
1813 | } | 1813 | } |
1814 | while (*(++(*argv))) { | 1814 | while (*(++(*argv))) { |
@@ -1816,11 +1816,25 @@ int gzip_main(int argc, char **argv) | |||
1816 | case 'c': | 1816 | case 'c': |
1817 | tostdout = 1; | 1817 | tostdout = 1; |
1818 | break; | 1818 | break; |
1819 | case 'f': | ||
1820 | force = 1; | ||
1821 | break; | ||
1822 | /* Ignore 1-9 (compression level) options */ | ||
1823 | case '1': case '2': case '3': case '4': case '5': | ||
1824 | case '6': case '7': case '8': case '9': | ||
1825 | break; | ||
1819 | default: | 1826 | default: |
1820 | usage(gzip_usage); | 1827 | usage(gzip_usage); |
1821 | } | 1828 | } |
1822 | } | 1829 | } |
1823 | } | 1830 | } |
1831 | if (argc <= 0) | ||
1832 | fromstdin = 1; | ||
1833 | |||
1834 | if (isatty(fileno(stdin)) && fromstdin==1 && force==0) | ||
1835 | fatalError( "data not read from terminal. Use -f to force it.\n"); | ||
1836 | if (isatty(fileno(stdout)) && tostdout==1 && force==0) | ||
1837 | fatalError( "data not written to terminal. Use -f to force it.\n"); | ||
1824 | 1838 | ||
1825 | foreground = signal(SIGINT, SIG_IGN) != SIG_IGN; | 1839 | foreground = signal(SIGINT, SIG_IGN) != SIG_IGN; |
1826 | if (foreground) { | 1840 | if (foreground) { |
@@ -1860,7 +1874,7 @@ int gzip_main(int argc, char **argv) | |||
1860 | ifile_size = -1L; /* convention for unknown size */ | 1874 | ifile_size = -1L; /* convention for unknown size */ |
1861 | } else { | 1875 | } else { |
1862 | /* Open up the input file */ | 1876 | /* Open up the input file */ |
1863 | if (*argv == '\0') | 1877 | if (argc <= 0) |
1864 | usage(gzip_usage); | 1878 | usage(gzip_usage); |
1865 | strncpy(ifname, *argv, MAX_PATH_LEN); | 1879 | strncpy(ifname, *argv, MAX_PATH_LEN); |
1866 | 1880 | ||