aboutsummaryrefslogtreecommitdiff
path: root/coreutils/expand.c
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils/expand.c')
-rw-r--r--coreutils/expand.c23
1 files changed, 7 insertions, 16 deletions
diff --git a/coreutils/expand.c b/coreutils/expand.c
index c0133956f..a7ac8ea84 100644
--- a/coreutils/expand.c
+++ b/coreutils/expand.c
@@ -154,7 +154,7 @@ int expand_main(int argc ATTRIBUTE_UNUSED, char **argv)
154 if (ENABLE_EXPAND && (!ENABLE_UNEXPAND || applet_name[0] == 'e')) { 154 if (ENABLE_EXPAND && (!ENABLE_UNEXPAND || applet_name[0] == 'e')) {
155 USE_FEATURE_EXPAND_LONG_OPTIONS(applet_long_options = expand_longopts); 155 USE_FEATURE_EXPAND_LONG_OPTIONS(applet_long_options = expand_longopts);
156 opt = getopt32(argv, "it:", &opt_t); 156 opt = getopt32(argv, "it:", &opt_t);
157 } else if (ENABLE_UNEXPAND) { 157 } else {
158 USE_FEATURE_UNEXPAND_LONG_OPTIONS(applet_long_options = unexpand_longopts); 158 USE_FEATURE_UNEXPAND_LONG_OPTIONS(applet_long_options = unexpand_longopts);
159 /* -t NUM sets also -a */ 159 /* -t NUM sets also -a */
160 opt_complementary = "ta"; 160 opt_complementary = "ta";
@@ -166,32 +166,23 @@ int expand_main(int argc ATTRIBUTE_UNUSED, char **argv)
166 166
167 argv += optind; 167 argv += optind;
168 168
169 /* If no args are given, read from stdin */
170 if (!*argv) { 169 if (!*argv) {
171 *--argv = (char*)bb_msg_standard_input; 170 *--argv = (char*)bb_msg_standard_input;
172 goto use_stdin;
173 } 171 }
174
175 do { 172 do {
176 if (NOT_LONE_CHAR(*argv, '-')) { 173 file = fopen_or_warn_stdin(*argv);
177 file = fopen_or_warn(*argv, "r"); 174 if (!file) {
178 if (!file) { 175 exit_status = EXIT_FAILURE;
179 exit_status = EXIT_FAILURE; 176 continue;
180 continue;
181 }
182 } else {
183 use_stdin:
184 file = stdin;
185 } 177 }
186 178
187 if (ENABLE_EXPAND && (!ENABLE_UNEXPAND || applet_name[0] == 'e')) 179 if (ENABLE_EXPAND && (!ENABLE_UNEXPAND || applet_name[0] == 'e'))
188 USE_EXPAND(expand(file, tab_size, opt)); 180 USE_EXPAND(expand(file, tab_size, opt));
189 else if (ENABLE_UNEXPAND) 181 else
190 USE_UNEXPAND(unexpand(file, tab_size, opt)); 182 USE_UNEXPAND(unexpand(file, tab_size, opt));
191 183
192 /* Check and close the file */ 184 /* Check and close the file */
193 /* We do want all of them to execute, thus | instead of || */ 185 if (fclose_if_not_stdin(file)) {
194 if (ferror(file) | fclose_if_not_stdin(file)) {
195 bb_simple_perror_msg(*argv); 186 bb_simple_perror_msg(*argv);
196 exit_status = EXIT_FAILURE; 187 exit_status = EXIT_FAILURE;
197 } 188 }