diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2004-09-03 01:23:15 +0000 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2004-09-03 01:23:15 +0000 |
commit | d33243b5acb3a3a60e07886a3cf497e421a1427f (patch) | |
tree | 7d0c6979d89ce497de73e66fe3cdaa100b30c97a | |
parent | 5e2e64732818dcae8f327130add62d3b450a7020 (diff) | |
download | coreutils-d33243b5acb3a3a60e07886a3cf497e421a1427f.tar.xz |
(paste_parallel): Improve replacement for ENDLIST and CLOSED.
-rw-r--r-- | src/paste.c | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/src/paste.c b/src/paste.c index 7d0f615b5..ad3f4425d 100644 --- a/src/paste.c +++ b/src/paste.c @@ -148,12 +148,10 @@ paste_parallel (size_t nfiles, char **fnamptr) store the delimiters for closed files. */ char *delbuf = xmalloc (nfiles + 2); - /* Streams open to the files to process. */ + /* Streams open to the files to process; NULL if the corresponding + stream is closed. */ FILE **fileptr = xnmalloc (nfiles + 1, sizeof *fileptr); - /* Which of these streams are closed. */ - bool *closed = xcalloc (nfiles, sizeof *closed); - /* Number of files still open to process. */ size_t files_open; @@ -181,8 +179,6 @@ paste_parallel (size_t nfiles, char **fnamptr) } } - fileptr[files_open] = NULL; - if (opened_stdin && have_read_stdin) error (EXIT_FAILURE, 0, _("standard input is closed")); @@ -198,11 +194,12 @@ paste_parallel (size_t nfiles, char **fnamptr) size_t delims_saved = 0; /* Number of delims saved in `delbuf'. */ size_t i; - for (i = 0; fileptr[i] && files_open; i++) + for (i = 0; i < nfiles && files_open; i++) { int chr IF_LINT (= 0); /* Input character. */ size_t line_length = 0; /* Number of chars in line. */ - if (! closed[i]) + + if (fileptr[i]) { chr = getc (fileptr[i]); if (chr != EOF && delims_saved) @@ -224,8 +221,8 @@ paste_parallel (size_t nfiles, char **fnamptr) if (line_length == 0) { /* EOF, read error, or closed file. - If an EOF or error, close the file and mark it in the list. */ - if (! closed[i]) + If an EOF or error, close the file. */ + if (fileptr[i]) { if (ferror (fileptr[i])) { @@ -240,11 +237,11 @@ paste_parallel (size_t nfiles, char **fnamptr) ok = false; } - closed[i] = true; + fileptr[i] = NULL; files_open--; } - if (! fileptr[i + 1]) + if (i + 1 == nfiles) { /* End of this output line. Is this the end of the whole thing? */ @@ -275,7 +272,7 @@ paste_parallel (size_t nfiles, char **fnamptr) somedone = true; /* Except for last file, replace last newline with delim. */ - if (fileptr[i + 1]) + if (i + 1 != nfiles) { if (chr != '\n' && chr != EOF) putc (chr, stdout); @@ -295,7 +292,6 @@ paste_parallel (size_t nfiles, char **fnamptr) } } free (fileptr); - free (closed); free (delbuf); return ok; } |