aboutsummaryrefslogtreecommitdiff
path: root/coreutils/sort.c
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils/sort.c')
-rw-r--r--coreutils/sort.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/coreutils/sort.c b/coreutils/sort.c
index 510f7a235..15566ce2b 100644
--- a/coreutils/sort.c
+++ b/coreutils/sort.c
@@ -351,10 +351,13 @@ int sort_main(int argc ATTRIBUTE_UNUSED, char **argv)
351 if (option_mask32 & FLAG_b) option_mask32 |= FLAG_bb; 351 if (option_mask32 & FLAG_b) option_mask32 |= FLAG_bb;
352 352
353 /* Open input files and read data */ 353 /* Open input files and read data */
354 for (i = argv[optind] ? optind : optind-1; argv[i]; i++) { 354 argv += optind;
355 fp = stdin; 355 if (!*argv)
356 if (i >= optind && NOT_LONE_DASH(argv[i])) 356 *--argv = (char*)"-";
357 fp = xfopen(argv[i], "r"); 357 do {
358 /* coreutils 6.9 compat: abort on first open error,
359 * do not continue to next file: */
360 fp = xfopen_stdin(*argv);
358 for (;;) { 361 for (;;) {
359 line = GET_LINE(fp); 362 line = GET_LINE(fp);
360 if (!line) break; 363 if (!line) break;
@@ -362,8 +365,9 @@ int sort_main(int argc ATTRIBUTE_UNUSED, char **argv)
362 lines = xrealloc(lines, sizeof(char *) * (linecount + 64)); 365 lines = xrealloc(lines, sizeof(char *) * (linecount + 64));
363 lines[linecount++] = line; 366 lines[linecount++] = line;
364 } 367 }
365 fclose(fp); 368 fclose_if_not_stdin(fp);
366 } 369 } while (*++argv);
370
367#if ENABLE_FEATURE_SORT_BIG 371#if ENABLE_FEATURE_SORT_BIG
368 /* if no key, perform alphabetic sort */ 372 /* if no key, perform alphabetic sort */
369 if (!key_list) 373 if (!key_list)