summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2005-04-11 20:11:45 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2005-04-11 20:11:45 +0000
commit9db4c897008075b9422f4a44ce93f7832ab08d4d (patch)
tree67de965cedf1f9e7f7acd52ee57373df4a0b3a93 /src
parentda5dc507512d75c38f41f16b51841c32cb6a04e6 (diff)
downloadcoreutils-9db4c897008075b9422f4a44ce93f7832ab08d4d.tar.xz
Include unistd-safer.h.
(copy_to_temp): Use fd_safer. (tac_file): Don't assume fopen cannot return stdin.
Diffstat (limited to 'src')
-rw-r--r--src/tac.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/tac.c b/src/tac.c
index 82274d715..157f0dfa6 100644
--- a/src/tac.c
+++ b/src/tac.c
@@ -48,6 +48,7 @@ tac -r -s '.\|
#include "quote.h"
#include "quotearg.h"
#include "safe-read.h"
+#include "unistd-safer.h"
/* The official name of this program (e.g., no `g' prefix). */
#define PROGRAM_NAME "tac"
@@ -448,14 +449,13 @@ copy_to_temp (FILE **g_tmp, char **g_tempfile, int input_fd, char const *file)
tempfile = template;
fd = mkstemp (template);
- if (fd == -1)
+ if (fd < 0)
{
error (0, errno, _("cannot create temporary file %s"), quote (tempfile));
return false;
}
- tmp = fdopen (fd, "w+");
- if (tmp == NULL)
+ if ((fd = fd_safer (fd)) < 0 || ! (tmp = fdopen (fd, "w+")))
{
error (0, errno, _("cannot open %s for writing"), quote (tempfile));
close (fd);
@@ -521,8 +521,9 @@ tac_file (const char *filename)
bool ok;
off_t file_size;
int fd;
+ bool is_stdin = STREQ (filename, "-");
- if (STREQ (filename, "-"))
+ if (is_stdin)
{
have_read_stdin = true;
fd = STDIN_FILENO;
@@ -554,7 +555,7 @@ tac_file (const char *filename)
? tac_seekable (fd, filename)
: tac_nonseekable (fd, filename));
- if (fd != STDIN_FILENO && close (fd) == -1)
+ if (!is_stdin && close (fd) != 0)
{
error (0, errno, _("%s: read error"), quotearg_colon (filename));
ok = false;