diff options
Diffstat (limited to 'gzip.c')
-rw-r--r-- | gzip.c | 48 |
1 files changed, 20 insertions, 28 deletions
@@ -1900,42 +1900,36 @@ int gzip_main(int argc, char **argv) | |||
1900 | int tostdout = 0; | 1900 | int tostdout = 0; |
1901 | int fromstdin = 0; | 1901 | int fromstdin = 0; |
1902 | int force = 0; | 1902 | int force = 0; |
1903 | int opt; | ||
1903 | 1904 | ||
1904 | /* Parse any options */ | 1905 | while ((opt = getopt(argc, argv, "cf123456789d")) != -1) { |
1905 | while (--argc > 0 && **(++argv) == '-') { | 1906 | switch (opt) { |
1906 | if (*((*argv) + 1) == '\0') { | 1907 | case 'c': |
1907 | tostdout = 1; | 1908 | tostdout = 1; |
1908 | } | 1909 | break; |
1909 | while (*(++(*argv))) { | 1910 | case 'f': |
1910 | switch (**argv) { | 1911 | force = 1; |
1911 | case 'c': | 1912 | break; |
1912 | tostdout = 1; | 1913 | /* Ignore 1-9 (compression level) options */ |
1913 | break; | 1914 | case '1': case '2': case '3': case '4': case '5': |
1914 | case 'f': | 1915 | case '6': case '7': case '8': case '9': |
1915 | force = 1; | 1916 | break; |
1916 | break; | ||
1917 | /* Ignore 1-9 (compression level) options */ | ||
1918 | case '1': case '2': case '3': case '4': case '5': | ||
1919 | case '6': case '7': case '8': case '9': | ||
1920 | break; | ||
1921 | #ifdef BB_GUNZIP | 1917 | #ifdef BB_GUNZIP |
1922 | case 'd': | 1918 | case 'd': |
1923 | exit(gunzip_main(argc, argv)); | 1919 | optind = 1; |
1920 | return gunzip_main(argc, argv); | ||
1924 | #endif | 1921 | #endif |
1925 | default: | 1922 | default: |
1926 | show_usage(); | 1923 | show_usage(); |
1927 | } | ||
1928 | } | 1924 | } |
1929 | } | 1925 | } |
1930 | if (argc <= 0 ) { | 1926 | if (optind == argc) { |
1931 | fromstdin = 1; | 1927 | fromstdin = 1; |
1932 | tostdout = 1; | 1928 | tostdout = 1; |
1933 | } | 1929 | } |
1934 | 1930 | ||
1935 | if (isatty(fileno(stdin)) && fromstdin==1 && force==0) | ||
1936 | error_msg_and_die( "data not read from terminal. Use -f to force it."); | ||
1937 | if (isatty(fileno(stdout)) && tostdout==1 && force==0) | 1931 | if (isatty(fileno(stdout)) && tostdout==1 && force==0) |
1938 | error_msg_and_die( "data not written to terminal. Use -f to force it."); | 1932 | error_msg_and_die( "compressed data not written to terminal. Use -f to force it."); |
1939 | 1933 | ||
1940 | foreground = signal(SIGINT, SIG_IGN) != SIG_IGN; | 1934 | foreground = signal(SIGINT, SIG_IGN) != SIG_IGN; |
1941 | if (foreground) { | 1935 | if (foreground) { |
@@ -1975,9 +1969,7 @@ int gzip_main(int argc, char **argv) | |||
1975 | ifile_size = -1L; /* convention for unknown size */ | 1969 | ifile_size = -1L; /* convention for unknown size */ |
1976 | } else { | 1970 | } else { |
1977 | /* Open up the input file */ | 1971 | /* Open up the input file */ |
1978 | if (argc <= 0) | 1972 | strncpy(ifname, argv[optind], MAX_PATH_LEN); |
1979 | show_usage(); | ||
1980 | strncpy(ifname, *argv, MAX_PATH_LEN); | ||
1981 | 1973 | ||
1982 | /* Open input file */ | 1974 | /* Open input file */ |
1983 | inFileNum = open(ifname, O_RDONLY); | 1975 | inFileNum = open(ifname, O_RDONLY); |