summaryrefslogtreecommitdiff
path: root/src/ptx.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2002-01-22 10:51:53 +0000
committerJim Meyering <jim@meyering.net>2002-01-22 10:51:53 +0000
commit3da062869b0fabb0f02375a1ece02c6d410adc05 (patch)
treeaff64001c32ea06c67ebbf96c539302f222d4387 /src/ptx.c
parentf8053809f87560168dcc43647d98f7526071b691 (diff)
downloadcoreutils-3da062869b0fabb0f02375a1ece02c6d410adc05.tar.xz
(swallow_file_in_memory): Work even if `open' returns 0.
Check for `close' error.
Diffstat (limited to 'src/ptx.c')
-rw-r--r--src/ptx.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/ptx.c b/src/ptx.c
index 1955cd0f7..9b101d215 100644
--- a/src/ptx.c
+++ b/src/ptx.c
@@ -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. */