diff options
author | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2000-07-21 22:17:39 +0000 |
---|---|---|
committer | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2000-07-21 22:17:39 +0000 |
commit | 18850224eba1726999c4f194e173ded17cacb604 (patch) | |
tree | d310abbb240cf220b268843d033cee845f6f8486 /gzip.c | |
parent | 06f3ac5701f90981db22420811ccef501e8997c1 (diff) | |
download | busybox-w32-18850224eba1726999c4f194e173ded17cacb604.tar.gz busybox-w32-18850224eba1726999c4f194e173ded17cacb604.tar.bz2 busybox-w32-18850224eba1726999c4f194e173ded17cacb604.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
git-svn-id: svn://busybox.net/trunk/busybox@898 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'gzip.c')
-rw-r--r-- | gzip.c | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -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 | ||