diff options
Diffstat (limited to 'gunzip.c')
-rw-r--r-- | gunzip.c | 28 |
1 files changed, 19 insertions, 9 deletions
@@ -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. |