diff options
Diffstat (limited to 'coreutils/cut.c')
-rw-r--r-- | coreutils/cut.c | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/coreutils/cut.c b/coreutils/cut.c index ed6f8f608..e617ef28f 100644 --- a/coreutils/cut.c +++ b/coreutils/cut.c | |||
@@ -205,7 +205,7 @@ int cut_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
205 | char *ntok; | 205 | char *ntok; |
206 | int s = 0, e = 0; | 206 | int s = 0, e = 0; |
207 | 207 | ||
208 | /* take apart the lists, one by one (they are separated with commas */ | 208 | /* take apart the lists, one by one (they are separated with commas) */ |
209 | while ((ltok = strsep(&sopt, ",")) != NULL) { | 209 | while ((ltok = strsep(&sopt, ",")) != NULL) { |
210 | 210 | ||
211 | /* it's actually legal to pass an empty list */ | 211 | /* it's actually legal to pass an empty list */ |
@@ -258,25 +258,18 @@ int cut_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
258 | 258 | ||
259 | { | 259 | { |
260 | int retval = EXIT_SUCCESS; | 260 | int retval = EXIT_SUCCESS; |
261 | FILE *file = stdin; | ||
262 | 261 | ||
263 | if (!*argv) { | 262 | if (!*argv) |
264 | argv--; | 263 | *--argv = (char *)"-"; |
265 | goto jump_in; | ||
266 | } | ||
267 | 264 | ||
268 | do { | 265 | do { |
269 | file = stdin; | 266 | FILE *file = fopen_or_warn_stdin(*argv); |
270 | if (NOT_LONE_DASH(*argv)) | ||
271 | file = fopen_or_warn(*argv, "r"); | ||
272 | if (!file) { | 267 | if (!file) { |
273 | retval = EXIT_FAILURE; | 268 | retval = EXIT_FAILURE; |
274 | continue; | 269 | continue; |
275 | } | 270 | } |
276 | jump_in: | ||
277 | cut_file(file, delim); | 271 | cut_file(file, delim); |
278 | if (NOT_LONE_DASH(*argv)) | 272 | fclose_if_not_stdin(file); |
279 | fclose(file); | ||
280 | } while (*++argv); | 273 | } while (*++argv); |
281 | 274 | ||
282 | if (ENABLE_FEATURE_CLEAN_UP) | 275 | if (ENABLE_FEATURE_CLEAN_UP) |