diff options
author | Jim Meyering <jim@meyering.net> | 2002-01-22 10:51:53 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2002-01-22 10:51:53 +0000 |
commit | 3da062869b0fabb0f02375a1ece02c6d410adc05 (patch) | |
tree | aff64001c32ea06c67ebbf96c539302f222d4387 /src | |
parent | f8053809f87560168dcc43647d98f7526071b691 (diff) | |
download | coreutils-3da062869b0fabb0f02375a1ece02c6d410adc05.tar.xz |
(swallow_file_in_memory): Work even if `open' returns 0.
Check for `close' error.
Diffstat (limited to 'src')
-rw-r--r-- | src/ptx.c | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -524,9 +524,9 @@ swallow_file_in_memory (const char *file_name, BLOCK *block) /* As special cases, a file name which is NULL or "-" indicates standard input, which is already opened. In all other cases, open the file from its name. */ - - if (!file_name || !*file_name || strcmp (file_name, "-") == 0) - file_handle = fileno (stdin); + bool using_stdin = !file_name || !*file_name || strcmp (file_name, "-") == 0; + if (using_stdin) + file_handle = STDIN_FILENO; else if ((file_handle = open (file_name, O_RDONLY)) < 0) error (EXIT_FAILURE, errno, "%s", file_name); @@ -593,8 +593,8 @@ swallow_file_in_memory (const char *file_name, BLOCK *block) /* Close the file, but only if it was not the standard input. */ - if (file_handle != fileno (stdin)) - close (file_handle); + if (! using_stdin && close (file_handle) != 0) + error (EXIT_FAILURE, errno, "%s", file_name); } /* Sort and search routines. */ |