summaryrefslogtreecommitdiff
path: root/src/csplit.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2005-07-03 07:17:12 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2005-07-03 07:17:12 +0000
commitd54f92ab0d3ef489acae67a35e155470499cc0be (patch)
treec8195a6bd254a8335fa98bfd5019f6971e836118 /src/csplit.c
parent43ab391610c2db8bfbf972a11eb9f874ccc71864 (diff)
downloadcoreutils-d54f92ab0d3ef489acae67a35e155470499cc0be.tar.xz
Include fd-reopen.h.
Include stdio--.h, not stdio-safer.h. (input_desc): Remove. All uses changed to STDIN_FILENO. (set_input_file): Reopen stdin, to simplify code. (create_output_file): Use fopen, not fopen_safer.
Diffstat (limited to 'src/csplit.c')
-rw-r--r--src/csplit.c24
1 files changed, 8 insertions, 16 deletions
diff --git a/src/csplit.c b/src/csplit.c
index d7e2f208f..243d30775 100644
--- a/src/csplit.c
+++ b/src/csplit.c
@@ -30,10 +30,11 @@
#include <regex.h>
#include "error.h"
+#include "fd-reopen.h"
#include "inttostr.h"
#include "quote.h"
#include "safe-read.h"
-#include "stdio-safer.h"
+#include "stdio--.h"
#include "xstrtol.h"
/* Use SA_NOCLDSTOP as a proxy for whether the sigaction machinery is
@@ -130,9 +131,6 @@ void usage (int status);
/* The name this program was run with. */
char *program_name;
-/* Input file descriptor. */
-static int input_desc;
-
/* Start of buffer list. */
static struct buffer_record *head = NULL;
@@ -279,7 +277,7 @@ read_input (char *dest, size_t max_n_bytes)
if (max_n_bytes == 0)
return 0;
- bytes_read = safe_read (input_desc, dest, max_n_bytes);
+ bytes_read = safe_read (STDIN_FILENO, dest, max_n_bytes);
if (bytes_read == 0)
have_read_eof = true;
@@ -638,19 +636,13 @@ no_more_lines (void)
return find_line (current_line + 1) == NULL;
}
-/* Set the name of the input file to NAME and open it. */
+/* Open NAME as standard input. */
static void
set_input_file (const char *name)
{
- if (STREQ (name, "-"))
- input_desc = STDIN_FILENO;
- else
- {
- input_desc = open (name, O_RDONLY);
- if (input_desc < 0)
- error (EXIT_FAILURE, errno, "%s", name);
- }
+ if (! STREQ (name, "-") && fd_reopen (STDIN_FILENO, name, O_RDONLY, 0) < 0)
+ error (EXIT_FAILURE, errno, _("cannot open %s for reading"), quote (name));
}
/* Write all lines from the beginning of the buffer up to, but
@@ -940,7 +932,7 @@ create_output_file (void)
/* Create the output file in a critical section, to avoid races. */
sigprocmask (SIG_BLOCK, &caught_signals, &oldset);
- output_stream = fopen_safer (output_filename, "w");
+ output_stream = fopen (output_filename, "w");
fopen_ok = (output_stream != NULL);
fopen_errno = errno;
files_created += fopen_ok;
@@ -1438,7 +1430,7 @@ main (int argc, char **argv)
split_file ();
- if (close (input_desc) < 0)
+ if (close (STDIN_FILENO) != 0)
{
error (0, errno, _("read error"));
cleanup_fatal ();