aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archival/gunzip.c78
-rw-r--r--gunzip.c78
2 files changed, 58 insertions, 98 deletions
diff --git a/archival/gunzip.c b/archival/gunzip.c
index 65f435651..e6f6bdfc1 100644
--- a/archival/gunzip.c
+++ b/archival/gunzip.c
@@ -80,58 +80,38 @@ extern int gunzip_main(int argc, char **argv)
80 char *delete_file_name = NULL; 80 char *delete_file_name = NULL;
81 81
82 const int gunzip_to_stdout = 1; 82 const int gunzip_to_stdout = 1;
83 const int gunzip_from_stdin = 2; 83 const int gunzip_force = 2;
84 const int gunzip_force = 4; 84 const int gunzip_test = 4;
85 const int gunzip_test = 8;
86 85
87 int flags = 0; 86 int flags = 0;
88 int opt = 0; 87 int opt = 0;
89 int delete_old_file = FALSE; 88 int delete_old_file = FALSE;
90 89
91 /* if called as zcat */ 90 /* if called as zcat */
92 if (strcmp(applet_name, "zcat") == 0) { 91 if (strcmp(applet_name, "zcat") == 0)
93 if (argc > 2) { 92 flags |= gunzip_to_stdout;
94 show_usage(); 93
94 while ((opt = getopt(argc, argv, "ctfh")) != -1) {
95 switch (opt) {
96 case 'c':
97 flags |= gunzip_to_stdout;
98 break;
99 case 'f':
100 flags |= gunzip_force;
101 break;
102 case 't':
103 flags |= gunzip_test;
104 break;
105 case 'h':
106 default:
107 show_usage(); /* exit's inside usage */
95 } 108 }
96 else if (argc == 2) {
97 /* a filename was specified */
98 flags |= (gunzip_to_stdout | gunzip_force);
99 optind = 1;
100 } else {
101 /* read from stdin, this gets caught below as argv[optind] will be NULL */
102 optind = argc;
103 }
104 } else {
105 /* workout flags as regular gunzip */
106 while ((opt = getopt(argc, argv, "ctfh")) != -1) {
107 switch (opt) {
108 case 'c':
109 flags |= gunzip_to_stdout;
110 break;
111 case 'f':
112 flags |= gunzip_force;
113 break;
114 case 't':
115 flags |= gunzip_test;
116 break;
117 case 'h':
118 default:
119 show_usage(); /* exit's inside usage */
120 }
121 }
122 }
123
124 /* no filename specified so it must be reading from stdin to stdout */
125 if (argv[optind] == NULL) {
126 flags |= (gunzip_from_stdin |gunzip_to_stdout |gunzip_force);
127 } 109 }
128 110
129 /* Set input filename and number */ 111 /* Set input filename and number */
130 if (flags & gunzip_from_stdin) { 112 if (argv[optind] == NULL) {
113 flags |= gunzip_to_stdout;
131 in_file = stdin; 114 in_file = stdin;
132 if ((flags & gunzip_force) == 0) {
133 error_msg_and_die("data not written to terminal. Use -f to force it.");
134 }
135 } else { 115 } else {
136 if_name = strdup(argv[optind]); 116 if_name = strdup(argv[optind]);
137 /* Open input file */ 117 /* Open input file */
@@ -139,19 +119,19 @@ extern int gunzip_main(int argc, char **argv)
139 119
140 /* Get the time stamp on the input file. */ 120 /* Get the time stamp on the input file. */
141 if (stat(if_name, &stat_buf) < 0) { 121 if (stat(if_name, &stat_buf) < 0) {
142 error_msg_and_die("Couldnt stat file %s",if_name); 122 error_msg_and_die("Couldn't stat file %s", if_name);
143 } 123 }
144 } 124 }
145 125
126 /* Check that the input is sane. */
127 if (isatty(fileno(in_file)) && (flags & gunzip_force) == 0)
128 error_msg_and_die("compressed data not read from terminal. Use -f to force it.");
129
146 /* Set output filename and number */ 130 /* Set output filename and number */
147 if (flags & gunzip_to_stdout) { 131 if (flags & gunzip_test) {
148 out_file = stdout;
149 /* whats the best way to do this with streams ? */
150 if (isatty(fileno(out_file)) && ((flags & gunzip_force) == 0)) {
151 error_msg_and_die("data not written to terminal. Use -f to force it.");
152 }
153 } else if (flags & gunzip_test) {
154 out_file = xfopen("/dev/null", "w"); /* why does test use filenum 2 ? */ 132 out_file = xfopen("/dev/null", "w"); /* why does test use filenum 2 ? */
133 } else if (flags & gunzip_to_stdout) {
134 out_file = stdout;
155 } else { 135 } else {
156 char *extension; 136 char *extension;
157 int length = strlen(if_name); 137 int length = strlen(if_name);
diff --git a/gunzip.c b/gunzip.c
index 65f435651..e6f6bdfc1 100644
--- a/gunzip.c
+++ b/gunzip.c
@@ -80,58 +80,38 @@ extern int gunzip_main(int argc, char **argv)
80 char *delete_file_name = NULL; 80 char *delete_file_name = NULL;
81 81
82 const int gunzip_to_stdout = 1; 82 const int gunzip_to_stdout = 1;
83 const int gunzip_from_stdin = 2; 83 const int gunzip_force = 2;
84 const int gunzip_force = 4; 84 const int gunzip_test = 4;
85 const int gunzip_test = 8;
86 85
87 int flags = 0; 86 int flags = 0;
88 int opt = 0; 87 int opt = 0;
89 int delete_old_file = FALSE; 88 int delete_old_file = FALSE;
90 89
91 /* if called as zcat */ 90 /* if called as zcat */
92 if (strcmp(applet_name, "zcat") == 0) { 91 if (strcmp(applet_name, "zcat") == 0)
93 if (argc > 2) { 92 flags |= gunzip_to_stdout;
94 show_usage(); 93
94 while ((opt = getopt(argc, argv, "ctfh")) != -1) {
95 switch (opt) {
96 case 'c':
97 flags |= gunzip_to_stdout;
98 break;
99 case 'f':
100 flags |= gunzip_force;
101 break;
102 case 't':
103 flags |= gunzip_test;
104 break;
105 case 'h':
106 default:
107 show_usage(); /* exit's inside usage */
95 } 108 }
96 else if (argc == 2) {
97 /* a filename was specified */
98 flags |= (gunzip_to_stdout | gunzip_force);
99 optind = 1;
100 } else {
101 /* read from stdin, this gets caught below as argv[optind] will be NULL */
102 optind = argc;
103 }
104 } else {
105 /* workout flags as regular gunzip */
106 while ((opt = getopt(argc, argv, "ctfh")) != -1) {
107 switch (opt) {
108 case 'c':
109 flags |= gunzip_to_stdout;
110 break;
111 case 'f':
112 flags |= gunzip_force;
113 break;
114 case 't':
115 flags |= gunzip_test;
116 break;
117 case 'h':
118 default:
119 show_usage(); /* exit's inside usage */
120 }
121 }
122 }
123
124 /* no filename specified so it must be reading from stdin to stdout */
125 if (argv[optind] == NULL) {
126 flags |= (gunzip_from_stdin |gunzip_to_stdout |gunzip_force);
127 } 109 }
128 110
129 /* Set input filename and number */ 111 /* Set input filename and number */
130 if (flags & gunzip_from_stdin) { 112 if (argv[optind] == NULL) {
113 flags |= gunzip_to_stdout;
131 in_file = stdin; 114 in_file = stdin;
132 if ((flags & gunzip_force) == 0) {
133 error_msg_and_die("data not written to terminal. Use -f to force it.");
134 }
135 } else { 115 } else {
136 if_name = strdup(argv[optind]); 116 if_name = strdup(argv[optind]);
137 /* Open input file */ 117 /* Open input file */
@@ -139,19 +119,19 @@ extern int gunzip_main(int argc, char **argv)
139 119
140 /* Get the time stamp on the input file. */ 120 /* Get the time stamp on the input file. */
141 if (stat(if_name, &stat_buf) < 0) { 121 if (stat(if_name, &stat_buf) < 0) {
142 error_msg_and_die("Couldnt stat file %s",if_name); 122 error_msg_and_die("Couldn't stat file %s", if_name);
143 } 123 }
144 } 124 }
145 125
126 /* Check that the input is sane. */
127 if (isatty(fileno(in_file)) && (flags & gunzip_force) == 0)
128 error_msg_and_die("compressed data not read from terminal. Use -f to force it.");
129
146 /* Set output filename and number */ 130 /* Set output filename and number */
147 if (flags & gunzip_to_stdout) { 131 if (flags & gunzip_test) {
148 out_file = stdout;
149 /* whats the best way to do this with streams ? */
150 if (isatty(fileno(out_file)) && ((flags & gunzip_force) == 0)) {
151 error_msg_and_die("data not written to terminal. Use -f to force it.");
152 }
153 } else if (flags & gunzip_test) {
154 out_file = xfopen("/dev/null", "w"); /* why does test use filenum 2 ? */ 132 out_file = xfopen("/dev/null", "w"); /* why does test use filenum 2 ? */
133 } else if (flags & gunzip_to_stdout) {
134 out_file = stdout;
155 } else { 135 } else {
156 char *extension; 136 char *extension;
157 int length = strlen(if_name); 137 int length = strlen(if_name);