Simplified version checking.
[oweals/busybox.git] / gunzip.c
index db5f6ee556dbb79a5cf8666c94ea68e700d34c88..430bc630efc80daef9949eac46ab431d4fa9ab18 100644 (file)
--- a/gunzip.c
+++ b/gunzip.c
@@ -68,7 +68,8 @@ static char *license_msg[] = {
 
 extern int gunzip_main(int argc, char **argv)
 {
-       FILE *in_file, *out_file;
+       FILE *in_file = stdin;
+       FILE *out_file = NULL;
        struct stat stat_buf;
 
        char *if_name = NULL;
@@ -87,7 +88,7 @@ extern int gunzip_main(int argc, char **argv)
        if (strcmp(applet_name, "zcat") == 0)
                flags |= gunzip_to_stdout;
 
-       while ((opt = getopt(argc, argv, "ctfhd")) != -1) {
+       while ((opt = getopt(argc, argv, "ctfhdq")) != -1) {
                switch (opt) {
                case 'c':
                        flags |= gunzip_to_stdout;
@@ -100,6 +101,9 @@ extern int gunzip_main(int argc, char **argv)
                        break;
                case 'd': /* Used to convert gzip to gunzip. */
                        break;
+               case 'q':
+                       error_msg("-q option not supported, ignored");
+                       break;
                case 'h':
                default:
                        show_usage(); /* exit's inside usage */
@@ -107,14 +111,16 @@ extern int gunzip_main(int argc, char **argv)
        }
 
        /* Set input filename and number */
-       if (argv[optind] == NULL) {
+       if (argv[optind] == NULL || strcmp(argv[optind], "-") == 0) {
                flags |= gunzip_to_stdout;
-               in_file = stdin;
        } else {
                if_name = strdup(argv[optind]);
                /* Open input file */
                in_file = xfopen(if_name, "r");
 
+               /* set the buffer size */
+               setvbuf(in_file, NULL, _IOFBF, 0x8000);
+
                /* Get the time stamp on the input file. */
                if (stat(if_name, &stat_buf) < 0) {
                        error_msg_and_die("Couldn't stat file %s", if_name);