bug-diffutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-diffutils] [PATCH 15/19] use xfreopen rather than freopen


From: Jim Meyering
Subject: [bug-diffutils] [PATCH 15/19] use xfreopen rather than freopen
Date: Fri, 20 Nov 2009 10:12:24 +0100

From: Jim Meyering <address@hidden>

* src/cmp.c: Include "xfreopen.h".
Use xfreopen in place of freopen.
* src/diff.c Likewise, and...
(main): Set exit_failure to EXIT_TROUBLE, rather than to 2.
* src/diff3.c: Likewise.
* bootstrap.conf (gnulib_modules): Add xfreopen.
---
 bootstrap.conf |    1 +
 src/cmp.c      |    3 ++-
 src/diff.c     |    7 ++++---
 src/diff3.c    |    6 +++---
 4 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/bootstrap.conf b/bootstrap.conf
index d89bd4d..d474aca 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -66,6 +66,7 @@ version-etc
 version-etc-fsf
 wcwidth
 xalloc
+xfreopen
 xstrtoumax
 '

diff --git a/src/cmp.c b/src/cmp.c
index 0111e37..72b2690 100644
--- a/src/cmp.c
+++ b/src/cmp.c
@@ -33,6 +33,7 @@
 #include <unlocked-io.h>
 #include <version-etc.h>
 #include <xalloc.h>
+#include <xfreopen.h>
 #include <xstrtol.h>

 /* The official name of this program (e.g., no `g' prefix).  */
@@ -286,7 +287,7 @@ main (int argc, char **argv)
        {
          file_desc[f1] = STDIN_FILENO;
          if (O_BINARY && ! isatty (STDIN_FILENO))
-           freopen (NULL, "rb", stdin);
+           xfreopen (NULL, "rb", stdin);
        }
       else
        file_desc[f1] = open (file[f1], O_RDONLY | O_BINARY, 0);
diff --git a/src/diff.c b/src/diff.c
index 5e82381..f7b3991 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -38,6 +38,7 @@
 #include <timespec.h>
 #include <version-etc.h>
 #include <xalloc.h>
+#include <xfreopen.h>

 /* The official name of this program (e.g., no `g' prefix).  */
 #define PROGRAM_NAME "diff"
@@ -271,7 +272,7 @@ main (int argc, char **argv)
   char *numend;

   /* Do our initializations.  */
-  exit_failure = 2;
+  exit_failure = EXIT_TROUBLE;
   initialize_main (&argc, &argv);
   set_program_name (argv[0]);
   setlocale (LC_ALL, "");
@@ -517,7 +518,7 @@ main (int argc, char **argv)
 #if O_BINARY
          binary = true;
          if (! isatty (STDOUT_FILENO))
-           freopen (NULL, "wb", stdout);
+           xfreopen (NULL, "wb", stdout);
 #endif
          break;

@@ -1086,7 +1087,7 @@ compare_files (struct comparison const *parent,
            {
              cmp.file[f].desc = STDIN_FILENO;
              if (binary && ! isatty (STDIN_FILENO))
-               freopen (NULL, "rb", stdin);
+               xfreopen (NULL, "rb", stdin);
              if (fstat (STDIN_FILENO, &cmp.file[f].stat) != 0)
                cmp.file[f].desc = ERRNO_ENCODE (errno);
              else
diff --git a/src/diff3.c b/src/diff3.c
index bd6a96e..01abdca 100644
--- a/src/diff3.c
+++ b/src/diff3.c
@@ -33,6 +33,7 @@
 #include <sh-quote.h>
 #include <version-etc.h>
 #include <xalloc.h>
+#include <xfreopen.h>

 /* The official name of this program (e.g., no `g' prefix).  */
 #define PROGRAM_NAME "diff3"
@@ -229,7 +230,7 @@ main (int argc, char **argv)
   char **file;
   struct stat statb;

-  exit_failure = 2;
+  exit_failure = EXIT_TROUBLE;
   initialize_main (&argc, &argv);
   set_program_name (argv[0]);
   setlocale (LC_ALL, "");
@@ -387,8 +388,7 @@ main (int argc, char **argv)
                               tag_strings[0], tag_strings[1], tag_strings[2]);
   else if (merge)
     {
-      if (! freopen (file[rev_mapping[FILE0]], "r", stdin))
-       perror_with_exit (file[rev_mapping[FILE0]]);
+      xfreopen (file[rev_mapping[FILE0]], "r", stdin);
       conflicts_found
        = output_diff3_merge (stdin, stdout, diff3, mapping, rev_mapping,
                              tag_strings[0], tag_strings[1], tag_strings[2]);
-- 
1.6.5.3.433.g11067





reply via email to

[Prev in Thread] Current Thread [Next in Thread]