]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
use xfreopen in place of unchecked freopen
authorJim Meyering <meyering@redhat.com>
Sun, 12 Oct 2008 12:50:02 +0000 (14:50 +0200)
committerJim Meyering <meyering@redhat.com>
Mon, 10 Nov 2008 07:11:59 +0000 (08:11 +0100)
* bootstrap.conf (modules): Add xfreopen.
* src/cat.c (main): Include "xfreopen.h".  Use xfreopen.
* src/cksum.c (cksum): Likewise.
* src/head.c (head_file, main): Likewise.
* src/md5sum.c (digest_file): Likewise.
* src/od.c (open_next_file): Likewise.
* src/split.c (type_undef): Likewise.
* src/sum.c (bsd_sum_file, sysv_sum_file): Likewise.
* src/tac.c (tac_file, main): Likewise.
* src/tail.c (tail_file, main): Likewise.
* src/tee.c (tee_files): Likewise.
* src/tr.c (main): Likewise.
* src/wc.c (wc_file): Likewise.
* po/POTFILES.in: Add lib/xfreopen.c

14 files changed:
bootstrap.conf
po/POTFILES.in
src/cat.c
src/cksum.c
src/head.c
src/md5sum.c
src/od.c
src/split.c
src/sum.c
src/tac.c
src/tail.c
src/tee.c
src/tr.c
src/wc.c

index 338dada3ad0ace580ac9e679b26db8e7dfbd9559..aae307cbc727730a468c67afbc08c9dd863c313e 100644 (file)
@@ -99,7 +99,9 @@ gnulib_modules="
        vc-list-files
        verify version-etc-fsf
        wcwidth winsz-ioctl winsz-termios write-any-file
-       xalloc xgetcwd xgethostname
+       xalloc
+       xfreopen
+       xgetcwd xgethostname
        xmemcoll xnanosleep
        xprintf
        xprintf-posix
index c8e97d6df1b3bc6111ab103f6d704cc5835f9168..8a6e541f4ecabc4a6ce1f57a46604d0220a8d917 100644 (file)
@@ -24,6 +24,7 @@ lib/unicodeio.c
 lib/userspec.c
 lib/version-etc.c
 lib/xalloc-die.c
+lib/xfreopen.c
 lib/xfts.c
 lib/xmemcoll.c
 lib/xmemxfrm.c
index 9c1996a67fc7eaa01d2a2b35527e8f6bd298ee97..543e5cf138423f3212bb8dbe50094717b69dd6f2 100644 (file)
--- a/src/cat.c
+++ b/src/cat.c
@@ -39,6 +39,7 @@
 #include "full-write.h"
 #include "quote.h"
 #include "safe-read.h"
+#include "xfreopen.h"
 
 /* The official name of this program (e.g., no `g' prefix).  */
 #define PROGRAM_NAME "cat"
@@ -664,7 +665,7 @@ main (int argc, char **argv)
     {
       file_open_mode |= O_BINARY;
       if (O_BINARY && ! isatty (STDOUT_FILENO))
-       freopen (NULL, "wb", stdout);
+       xfreopen (NULL, "wb", stdout);
     }
 
   /* Check if any of the input files are the same as the output file.  */
@@ -684,7 +685,7 @@ main (int argc, char **argv)
          have_read_stdin = true;
          input_desc = STDIN_FILENO;
          if ((file_open_mode & O_BINARY) && ! isatty (STDIN_FILENO))
-           freopen (NULL, "rb", stdin);
+           xfreopen (NULL, "rb", stdin);
        }
       else
        {
index 8bbed37f9fd5a12e59bae2c5d924d03f26ad76e4..2893d303b62212690e527cf433edd44fc60e9da3 100644 (file)
@@ -43,6 +43,7 @@
 #include <sys/types.h>
 #include <stdint.h>
 #include "system.h"
+#include "xfreopen.h"
 
 #ifdef CRCTAB
 
@@ -192,7 +193,7 @@ cksum (const char *file, bool print_name)
       fp = stdin;
       have_read_stdin = true;
       if (O_BINARY && ! isatty (STDIN_FILENO))
-       freopen (NULL, "rb", stdin);
+       xfreopen (NULL, "rb", stdin);
     }
   else
     {
index 0ef912a58c7f0c545fe3bd0516f91c8f55a11974..7f90d4b29e801b83c00ce4067a3f1c5759dbbf65 100644 (file)
@@ -36,6 +36,7 @@
 #include "full-read.h"
 #include "quote.h"
 #include "safe-read.h"
+#include "xfreopen.h"
 #include "xstrtol.h"
 
 /* The official name of this program (e.g., no `g' prefix).  */
@@ -838,7 +839,7 @@ head_file (const char *filename, uintmax_t n_units, bool count_lines,
       fd = STDIN_FILENO;
       filename = _("standard input");
       if (O_BINARY && ! isatty (STDIN_FILENO))
-       freopen (NULL, "rb", stdin);
+       xfreopen (NULL, "rb", stdin);
     }
   else
     {
@@ -1051,7 +1052,7 @@ main (int argc, char **argv)
               : default_file_list);
 
   if (O_BINARY && ! isatty (STDOUT_FILENO))
-    freopen (NULL, "wb", stdout);
+    xfreopen (NULL, "wb", stdout);
 
   for (i = 0; file_list[i]; ++i)
     ok &= head_file (file_list[i], n_units, count_lines, elide_from_end);
index 238c02ee662915a7552cdceb963c6fc3bc62e8b2..d31a780bfd93f9fde14e1e8c816f57820e7ae3f7 100644 (file)
@@ -37,6 +37,7 @@
 #endif
 #include "error.h"
 #include "stdio--.h"
+#include "xfreopen.h"
 
 /* The official name of this program (e.g., no `g' prefix).  */
 #if HASH_ALGO_MD5
@@ -391,7 +392,7 @@ digest_file (const char *filename, int *binary, unsigned char *bin_result)
          if (*binary < 0)
            *binary = ! isatty (STDIN_FILENO);
          if (*binary)
-           freopen (NULL, "rb", stdin);
+           xfreopen (NULL, "rb", stdin);
        }
     }
   else
index ed3b50a8c9adbf15369b6840b110eb15d0bd3706..2dcb39837764d23a1dff129a28fe44eb1a19c10a 100644 (file)
--- a/src/od.c
+++ b/src/od.c
@@ -25,6 +25,7 @@
 #include "system.h"
 #include "error.h"
 #include "quote.h"
+#include "xfreopen.h"
 #include "xprintf.h"
 #include "xstrtol.h"
 
@@ -864,7 +865,7 @@ open_next_file (void)
          in_stream = stdin;
          have_read_stdin = true;
          if (O_BINARY && ! isatty (STDIN_FILENO))
-           freopen (NULL, "rb", stdin);
+           xfreopen (NULL, "rb", stdin);
        }
       else
        {
index 85687c407bb614d339dfe9e1fbd77e00d22072e8..be182eff653e2c57cedb66d6e098fc14d0a8c269 100644 (file)
@@ -34,6 +34,7 @@
 #include "full-write.h"
 #include "quote.h"
 #include "safe-read.h"
+#include "xfreopen.h"
 #include "xstrtol.h"
 
 /* The official name of this program (e.g., no `g' prefix).  */
@@ -544,7 +545,7 @@ main (int argc, char **argv)
 
   /* Binary I/O is safer when bytecounts are used.  */
   if (O_BINARY && ! isatty (STDIN_FILENO))
-    freopen (NULL, "rb", stdin);
+    xfreopen (NULL, "rb", stdin);
 
   /* No output file is open now.  */
   output_desc = -1;
index 314656f53547970d3803381a6093f9ebc1de6c5d..4cb8f31aa2c82e876f5bd031f62109058cb18b6f 100644 (file)
--- a/src/sum.c
+++ b/src/sum.c
@@ -28,6 +28,7 @@
 #include "error.h"
 #include "human.h"
 #include "safe-read.h"
+#include "xfreopen.h"
 
 /* The official name of this program (e.g., no `g' prefix).  */
 #define PROGRAM_NAME "sum"
@@ -97,7 +98,7 @@ bsd_sum_file (const char *file, int print_name)
       fp = stdin;
       have_read_stdin = true;
       if (O_BINARY && ! isatty (STDIN_FILENO))
-       freopen (NULL, "rb", stdin);
+       xfreopen (NULL, "rb", stdin);
     }
   else
     {
@@ -165,7 +166,7 @@ sysv_sum_file (const char *file, int print_name)
       fd = STDIN_FILENO;
       have_read_stdin = true;
       if (O_BINARY && ! isatty (STDIN_FILENO))
-       freopen (NULL, "rb", stdin);
+       xfreopen (NULL, "rb", stdin);
     }
   else
     {
index c83986f592acc40308016c337ffbf84ee4b99961..be8f3abccbfad7664691d869ba50ea470d6d45f0 100644 (file)
--- a/src/tac.c
+++ b/src/tac.c
@@ -48,6 +48,7 @@ tac -r -s '.\|
 #include "quotearg.h"
 #include "safe-read.h"
 #include "stdlib--.h"
+#include "xfreopen.h"
 
 /* The official name of this program (e.g., no `g' prefix).  */
 #define PROGRAM_NAME "tac"
@@ -533,7 +534,7 @@ tac_file (const char *filename)
       fd = STDIN_FILENO;
       filename = _("standard input");
       if (O_BINARY && ! isatty (STDIN_FILENO))
-       freopen (NULL, "rb", stdin);
+       xfreopen (NULL, "rb", stdin);
     }
   else
     {
@@ -647,7 +648,7 @@ main (int argc, char **argv)
          : default_file_list);
 
   if (O_BINARY && ! isatty (STDOUT_FILENO))
-    freopen (NULL, "wb", stdout);
+    xfreopen (NULL, "wb", stdout);
 
   {
     size_t i;
index 43fd6d4128f17f008d9ac327cb9072297714f33b..6ad6d4330d7f1d264ac47d4aa6bacb9189f96fa0 100644 (file)
@@ -40,6 +40,7 @@
 #include "quote.h"
 #include "safe-read.h"
 #include "stat-time.h"
+#include "xfreopen.h"
 #include "xnanosleep.h"
 #include "xstrtol.h"
 #include "xstrtod.h"
@@ -1273,7 +1274,7 @@ tail_file (struct File_spec *f, uintmax_t n_units)
       have_read_stdin = true;
       fd = STDIN_FILENO;
       if (O_BINARY && ! isatty (STDIN_FILENO))
-       freopen (NULL, "rb", stdin);
+       xfreopen (NULL, "rb", stdin);
     }
   else
     fd = open (f->name, O_RDONLY | O_BINARY);
@@ -1683,7 +1684,7 @@ main (int argc, char **argv)
     print_headers = true;
 
   if (O_BINARY && ! isatty (STDOUT_FILENO))
-    freopen (NULL, "wb", stdout);
+    xfreopen (NULL, "wb", stdout);
 
   for (i = 0; i < n_files; i++)
     ok &= tail_file (&F[i], n_units);
index 4e46aabb598e64612ed91e6b3de45df926d53be8..2d13f6d54a2d0ed7f1156984eb8dea1a4b133df7 100644 (file)
--- a/src/tee.c
+++ b/src/tee.c
@@ -24,6 +24,7 @@
 #include "system.h"
 #include "error.h"
 #include "stdio--.h"
+#include "xfreopen.h"
 
 /* The official name of this program (e.g., no `g' prefix).  */
 #define PROGRAM_NAME "tee"
@@ -152,9 +153,9 @@ tee_files (int nfiles, const char **files)
     files[i] = files[i - 1];
 
   if (O_BINARY && ! isatty (STDIN_FILENO))
-    freopen (NULL, "rb", stdin);
+    xfreopen (NULL, "rb", stdin);
   if (O_BINARY && ! isatty (STDOUT_FILENO))
-    freopen (NULL, "wb", stdout);
+    xfreopen (NULL, "wb", stdout);
 
   /* In the array of NFILES + 1 descriptors, make
      the first one correspond to standard output.   */
index 0f94eef845f2abcc4afcfb1001007a5c58fe8248..f4b5317315787d7145224dadd0a0367af12c59f0 100644 (file)
--- a/src/tr.c
+++ b/src/tr.c
@@ -27,6 +27,7 @@
 #include "error.h"
 #include "quote.h"
 #include "safe-read.h"
+#include "xfreopen.h"
 #include "xstrtol.h"
 
 /* The official name of this program (e.g., no `g' prefix).  */
@@ -1750,9 +1751,9 @@ main (int argc, char **argv)
      non-printable characters, or characters which are stripped away
      by text-mode reads (like CR and ^Z).  */
   if (O_BINARY && ! isatty (STDIN_FILENO))
-    freopen (NULL, "rb", stdin);
+    xfreopen (NULL, "rb", stdin);
   if (O_BINARY && ! isatty (STDOUT_FILENO))
-    freopen (NULL, "wb", stdout);
+    xfreopen (NULL, "wb", stdout);
 
   if (squeeze_repeats && non_option_args == 1)
     {
index 0bb1929f488b6ba18e957d7201648c39197dad92..280d7ac885f2708bde33e47297acd7ed18f7ff8b 100644 (file)
--- a/src/wc.c
+++ b/src/wc.c
@@ -32,6 +32,7 @@
 #include "quotearg.h"
 #include "readtokens0.h"
 #include "safe-read.h"
+#include "xfreopen.h"
 
 #if !defined iswspace && !HAVE_ISWSPACE
 # define iswspace(wc) \
@@ -486,7 +487,7 @@ wc_file (char const *file, struct fstatus *fstatus)
     {
       have_read_stdin = true;
       if (O_BINARY && ! isatty (STDIN_FILENO))
-       freopen (NULL, "rb", stdin);
+       xfreopen (NULL, "rb", stdin);
       return wc (STDIN_FILENO, file, fstatus);
     }
   else