grep-commit
[Top][All Lists]
Advanced

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

grep branch, master, updated. v3.0-7-gc4485ac


From: Paul Eggert
Subject: grep branch, master, updated. v3.0-7-gc4485ac
Date: Thu, 16 Feb 2017 11:54:45 -0500 (EST)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "grep".

The branch, master has been updated
       via  c4485ac49a977d666187db4c5c25045215976577 (commit)
       via  cde60563801884ae65546090b24cb92620b1f828 (commit)
       via  5ac3d87a69122d45a837840914c2f9e66b5bb8d4 (commit)
       via  5398777784b4455aa8466c1aef48b5738b8cd626 (commit)
      from  e1ca01be48cb64e5eaa6b5b29910e7eea1719f91 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/grep.git/commit/?id=c4485ac49a977d666187db4c5c25045215976577


commit c4485ac49a977d666187db4c5c25045215976577
Author: Paul Eggert <address@hidden>
Date:   Thu Feb 16 08:51:34 2017 -0800

    Fix up recent -U patches
    
    Inspired by a suggestion by Eric Blake (Bug#25707#17).
    * bootstrap.conf (gnulib_modules): Add xbinary-io,
    and remove binary-io and xfreopen.
    * doc/grep.texi (Other Options):
    Fix typo and reword to be a bit more general.
    * src/grep.c: Include xbinary-io.h instead of xfreopen.h.
    (grepfile): Open with O_BINARY if binary.
    (grepdesc): No need for set_binary_mode now.
    (grep_command_line_arg, main): Set stdin to binary mode if binary.
    (main): Avoid unnecessary test of stdin == NULL.
    Use xsetmode instead of xfreopen.
    * src/system.h: Do not include binary-io.h.

diff --git a/bootstrap.conf b/bootstrap.conf
index 4115f35..1c50974 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -26,7 +26,6 @@ gnulib_modules='
 alloca
 announce-gen
 argmatch
-binary-io
 c-ctype
 closeout
 dfa
@@ -53,10 +52,10 @@ isatty
 isblank
 iswctype
 largefile
-lseek
 locale
-malloc-gnu
+lseek
 maintainer-makefile
+malloc-gnu
 manywarnings
 mbrlen
 mbrtowc
@@ -95,7 +94,7 @@ wcrtomb
 wctob
 wctype-h
 xalloc
-xfreopen
+xbinary-io
 xstrtoimax
 '
 gnulib_name=libgreputils
diff --git a/doc/grep.texi b/doc/grep.texi
index 94a0621..077c05f 100644
--- a/doc/grep.texi
+++ b/doc/grep.texi
@@ -741,25 +741,26 @@ This can cause a performance penalty.
 @opindex -U
 @opindex --binary
 @cindex MS-Windows binary I/O
address@hidden binary I/O, /MS-Windows
-Under MS-Windows, use binary I/O when reading and writing files other
address@hidden binary I/O
+On platforms that distinguish between text and binary I/O,
+use the latter when reading and writing files other
 than the user's terminal, so that all input bytes are read and written
 as-is.  This overrides the default behavior where @command{grep}
-follows the operating system's advice whether to use binary or text
-I/O.  When @command{grep} uses text I/O it reads a carriage
-return--newline pair as a newline and a Control-Z as end-of-file, and
-it writes a newline as a carriage return--newline pair.  When this
-option is combined with @option{--byte-offset} (@option{-b}), byte
-counts treat each text I/O carriage return--newline as a single byte.
-
-When using text I/O, @option{--binary-files} heuristics are applied to
-input data after text-I/O processing.  These heuristics need not agree
+follows the operating system's advice whether to use text or binary
+I/address@hidden  On MS-Windows when @command{grep} uses text I/O it reads a
+carriage return--newline pair as a newline and a Control-Z as
+end-of-file, and it writes a newline as a carriage return--newline
+pair.
+
+When using text I/O @option{--byte-offset} (@option{-b}) counts and
address@hidden heuristics apply to input data after text-I/O
+processing.  Also, the @option{--binary-files} heuristics need not agree
 with the @option{--binary} option; that is, they may treat the data as
 text even if @option{--binary} is given, or vice versa.
 @xref{File and Directory Selection}.
 
-This option has no effect on platforms other than MS-Windows.
-
+This option has no effect on GNU and other POSIX-compatible platforms,
+which do not distinguish text from binary I/O.
 
 @item -z
 @itemx --null-data
diff --git a/src/grep.c b/src/grep.c
index 32cb642..775f227 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -48,7 +48,7 @@
 #include "search.h"
 #include "version-etc.h"
 #include "xalloc.h"
-#include "xfreopen.h"
+#include "xbinary-io.h"
 #include "xstrtol.h"
 
 enum { SEP_CHAR_SELECTED = ':' };
@@ -1700,6 +1700,7 @@ static bool
 grepfile (int dirdesc, char const *name, bool follow, bool command_line)
 {
   int oflag = (O_RDONLY | O_NOCTTY
+               | (binary ? O_BINARY : 0)
                | (follow ? 0 : O_NOFOLLOW)
                | (skip_devices (command_line) ? O_NONBLOCK : 0));
   int desc = openat_safer (dirdesc, name, oflag);
@@ -1854,11 +1855,6 @@ grepdesc (int desc, bool command_line)
       goto closeout;
     }
 
-  /* Set input to binary mode.  Pipes are simulated with files
-     on DOS, so this includes the case of "foo | grep bar".  */
-  if (binary && !isatty (desc))
-    set_binary_mode (desc, O_BINARY);
-
   count = grep (desc, &st, &ineof);
   if (count_matches)
     {
@@ -1899,6 +1895,8 @@ grep_command_line_arg (char const *arg)
   if (STREQ (arg, "-"))
     {
       filename = label;
+      if (binary)
+        xset_binary_mode (STDIN_FILENO, O_BINARY);
       return grepdesc (STDIN_FILENO, true);
     }
   else
@@ -2579,14 +2577,15 @@ main (int argc, char **argv)
         if (STREQ (optarg, "-"))
           {
             if (binary)
-              xfreopen (NULL, "rb", stdin);
+              xset_binary_mode (STDIN_FILENO, O_BINARY);
             fp = stdin;
           }
         else
-          fp = fopen (optarg, binary ? "rb" : "r");
-
-        if (!fp)
-          die (EXIT_TROUBLE, errno, "%s", optarg);
+          {
+            fp = fopen (optarg, binary ? "rb" : "r");
+            if (!fp)
+              die (EXIT_TROUBLE, errno, "%s", optarg);
+          }
         oldcc = keycc;
         for (;; keycc += cc)
           {
@@ -2897,10 +2896,8 @@ main (int argc, char **argv)
   if ((argc - optind > 1 && !no_filenames) || with_filenames)
     out_file = 1;
 
-  /* Output is set to binary mode because we shouldn't convert
-     NL to CR-LF pairs, especially when grepping binary files.  */
-  if (binary && !isatty (STDOUT_FILENO))
-    xfreopen (NULL, "wb", stdout);
+  if (binary)
+    xset_binary_mode (STDOUT_FILENO, O_BINARY);
 
   /* Prefer sysconf for page size, as getpagesize typically returns int.  */
 #ifdef _SC_PAGESIZE
diff --git a/src/system.h b/src/system.h
index 05d8f1a..6292a28 100644
--- a/src/system.h
+++ b/src/system.h
@@ -23,7 +23,6 @@
 #include <unistd.h>
 #include <errno.h>
 
-#include "binary-io.h"
 #include "configmake.h"
 #include "dirname.h"
 #include "ignore-value.h"

http://git.savannah.gnu.org/cgit/grep.git/commit/?id=cde60563801884ae65546090b24cb92620b1f828


commit c4485ac49a977d666187db4c5c25045215976577
Author: Paul Eggert <address@hidden>
Date:   Thu Feb 16 08:51:34 2017 -0800

    Fix up recent -U patches
    
    Inspired by a suggestion by Eric Blake (Bug#25707#17).
    * bootstrap.conf (gnulib_modules): Add xbinary-io,
    and remove binary-io and xfreopen.
    * doc/grep.texi (Other Options):
    Fix typo and reword to be a bit more general.
    * src/grep.c: Include xbinary-io.h instead of xfreopen.h.
    (grepfile): Open with O_BINARY if binary.
    (grepdesc): No need for set_binary_mode now.
    (grep_command_line_arg, main): Set stdin to binary mode if binary.
    (main): Avoid unnecessary test of stdin == NULL.
    Use xsetmode instead of xfreopen.
    * src/system.h: Do not include binary-io.h.

diff --git a/bootstrap.conf b/bootstrap.conf
index 4115f35..1c50974 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -26,7 +26,6 @@ gnulib_modules='
 alloca
 announce-gen
 argmatch
-binary-io
 c-ctype
 closeout
 dfa
@@ -53,10 +52,10 @@ isatty
 isblank
 iswctype
 largefile
-lseek
 locale
-malloc-gnu
+lseek
 maintainer-makefile
+malloc-gnu
 manywarnings
 mbrlen
 mbrtowc
@@ -95,7 +94,7 @@ wcrtomb
 wctob
 wctype-h
 xalloc
-xfreopen
+xbinary-io
 xstrtoimax
 '
 gnulib_name=libgreputils
diff --git a/doc/grep.texi b/doc/grep.texi
index 94a0621..077c05f 100644
--- a/doc/grep.texi
+++ b/doc/grep.texi
@@ -741,25 +741,26 @@ This can cause a performance penalty.
 @opindex -U
 @opindex --binary
 @cindex MS-Windows binary I/O
address@hidden binary I/O, /MS-Windows
-Under MS-Windows, use binary I/O when reading and writing files other
address@hidden binary I/O
+On platforms that distinguish between text and binary I/O,
+use the latter when reading and writing files other
 than the user's terminal, so that all input bytes are read and written
 as-is.  This overrides the default behavior where @command{grep}
-follows the operating system's advice whether to use binary or text
-I/O.  When @command{grep} uses text I/O it reads a carriage
-return--newline pair as a newline and a Control-Z as end-of-file, and
-it writes a newline as a carriage return--newline pair.  When this
-option is combined with @option{--byte-offset} (@option{-b}), byte
-counts treat each text I/O carriage return--newline as a single byte.
-
-When using text I/O, @option{--binary-files} heuristics are applied to
-input data after text-I/O processing.  These heuristics need not agree
+follows the operating system's advice whether to use text or binary
+I/address@hidden  On MS-Windows when @command{grep} uses text I/O it reads a
+carriage return--newline pair as a newline and a Control-Z as
+end-of-file, and it writes a newline as a carriage return--newline
+pair.
+
+When using text I/O @option{--byte-offset} (@option{-b}) counts and
address@hidden heuristics apply to input data after text-I/O
+processing.  Also, the @option{--binary-files} heuristics need not agree
 with the @option{--binary} option; that is, they may treat the data as
 text even if @option{--binary} is given, or vice versa.
 @xref{File and Directory Selection}.
 
-This option has no effect on platforms other than MS-Windows.
-
+This option has no effect on GNU and other POSIX-compatible platforms,
+which do not distinguish text from binary I/O.
 
 @item -z
 @itemx --null-data
diff --git a/src/grep.c b/src/grep.c
index 32cb642..775f227 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -48,7 +48,7 @@
 #include "search.h"
 #include "version-etc.h"
 #include "xalloc.h"
-#include "xfreopen.h"
+#include "xbinary-io.h"
 #include "xstrtol.h"
 
 enum { SEP_CHAR_SELECTED = ':' };
@@ -1700,6 +1700,7 @@ static bool
 grepfile (int dirdesc, char const *name, bool follow, bool command_line)
 {
   int oflag = (O_RDONLY | O_NOCTTY
+               | (binary ? O_BINARY : 0)
                | (follow ? 0 : O_NOFOLLOW)
                | (skip_devices (command_line) ? O_NONBLOCK : 0));
   int desc = openat_safer (dirdesc, name, oflag);
@@ -1854,11 +1855,6 @@ grepdesc (int desc, bool command_line)
       goto closeout;
     }
 
-  /* Set input to binary mode.  Pipes are simulated with files
-     on DOS, so this includes the case of "foo | grep bar".  */
-  if (binary && !isatty (desc))
-    set_binary_mode (desc, O_BINARY);
-
   count = grep (desc, &st, &ineof);
   if (count_matches)
     {
@@ -1899,6 +1895,8 @@ grep_command_line_arg (char const *arg)
   if (STREQ (arg, "-"))
     {
       filename = label;
+      if (binary)
+        xset_binary_mode (STDIN_FILENO, O_BINARY);
       return grepdesc (STDIN_FILENO, true);
     }
   else
@@ -2579,14 +2577,15 @@ main (int argc, char **argv)
         if (STREQ (optarg, "-"))
           {
             if (binary)
-              xfreopen (NULL, "rb", stdin);
+              xset_binary_mode (STDIN_FILENO, O_BINARY);
             fp = stdin;
           }
         else
-          fp = fopen (optarg, binary ? "rb" : "r");
-
-        if (!fp)
-          die (EXIT_TROUBLE, errno, "%s", optarg);
+          {
+            fp = fopen (optarg, binary ? "rb" : "r");
+            if (!fp)
+              die (EXIT_TROUBLE, errno, "%s", optarg);
+          }
         oldcc = keycc;
         for (;; keycc += cc)
           {
@@ -2897,10 +2896,8 @@ main (int argc, char **argv)
   if ((argc - optind > 1 && !no_filenames) || with_filenames)
     out_file = 1;
 
-  /* Output is set to binary mode because we shouldn't convert
-     NL to CR-LF pairs, especially when grepping binary files.  */
-  if (binary && !isatty (STDOUT_FILENO))
-    xfreopen (NULL, "wb", stdout);
+  if (binary)
+    xset_binary_mode (STDOUT_FILENO, O_BINARY);
 
   /* Prefer sysconf for page size, as getpagesize typically returns int.  */
 #ifdef _SC_PAGESIZE
diff --git a/src/system.h b/src/system.h
index 05d8f1a..6292a28 100644
--- a/src/system.h
+++ b/src/system.h
@@ -23,7 +23,6 @@
 #include <unistd.h>
 #include <errno.h>
 
-#include "binary-io.h"
 #include "configmake.h"
 #include "dirname.h"
 #include "ignore-value.h"

http://git.savannah.gnu.org/cgit/grep.git/commit/?id=5ac3d87a69122d45a837840914c2f9e66b5bb8d4


commit c4485ac49a977d666187db4c5c25045215976577
Author: Paul Eggert <address@hidden>
Date:   Thu Feb 16 08:51:34 2017 -0800

    Fix up recent -U patches
    
    Inspired by a suggestion by Eric Blake (Bug#25707#17).
    * bootstrap.conf (gnulib_modules): Add xbinary-io,
    and remove binary-io and xfreopen.
    * doc/grep.texi (Other Options):
    Fix typo and reword to be a bit more general.
    * src/grep.c: Include xbinary-io.h instead of xfreopen.h.
    (grepfile): Open with O_BINARY if binary.
    (grepdesc): No need for set_binary_mode now.
    (grep_command_line_arg, main): Set stdin to binary mode if binary.
    (main): Avoid unnecessary test of stdin == NULL.
    Use xsetmode instead of xfreopen.
    * src/system.h: Do not include binary-io.h.

diff --git a/bootstrap.conf b/bootstrap.conf
index 4115f35..1c50974 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -26,7 +26,6 @@ gnulib_modules='
 alloca
 announce-gen
 argmatch
-binary-io
 c-ctype
 closeout
 dfa
@@ -53,10 +52,10 @@ isatty
 isblank
 iswctype
 largefile
-lseek
 locale
-malloc-gnu
+lseek
 maintainer-makefile
+malloc-gnu
 manywarnings
 mbrlen
 mbrtowc
@@ -95,7 +94,7 @@ wcrtomb
 wctob
 wctype-h
 xalloc
-xfreopen
+xbinary-io
 xstrtoimax
 '
 gnulib_name=libgreputils
diff --git a/doc/grep.texi b/doc/grep.texi
index 94a0621..077c05f 100644
--- a/doc/grep.texi
+++ b/doc/grep.texi
@@ -741,25 +741,26 @@ This can cause a performance penalty.
 @opindex -U
 @opindex --binary
 @cindex MS-Windows binary I/O
address@hidden binary I/O, /MS-Windows
-Under MS-Windows, use binary I/O when reading and writing files other
address@hidden binary I/O
+On platforms that distinguish between text and binary I/O,
+use the latter when reading and writing files other
 than the user's terminal, so that all input bytes are read and written
 as-is.  This overrides the default behavior where @command{grep}
-follows the operating system's advice whether to use binary or text
-I/O.  When @command{grep} uses text I/O it reads a carriage
-return--newline pair as a newline and a Control-Z as end-of-file, and
-it writes a newline as a carriage return--newline pair.  When this
-option is combined with @option{--byte-offset} (@option{-b}), byte
-counts treat each text I/O carriage return--newline as a single byte.
-
-When using text I/O, @option{--binary-files} heuristics are applied to
-input data after text-I/O processing.  These heuristics need not agree
+follows the operating system's advice whether to use text or binary
+I/address@hidden  On MS-Windows when @command{grep} uses text I/O it reads a
+carriage return--newline pair as a newline and a Control-Z as
+end-of-file, and it writes a newline as a carriage return--newline
+pair.
+
+When using text I/O @option{--byte-offset} (@option{-b}) counts and
address@hidden heuristics apply to input data after text-I/O
+processing.  Also, the @option{--binary-files} heuristics need not agree
 with the @option{--binary} option; that is, they may treat the data as
 text even if @option{--binary} is given, or vice versa.
 @xref{File and Directory Selection}.
 
-This option has no effect on platforms other than MS-Windows.
-
+This option has no effect on GNU and other POSIX-compatible platforms,
+which do not distinguish text from binary I/O.
 
 @item -z
 @itemx --null-data
diff --git a/src/grep.c b/src/grep.c
index 32cb642..775f227 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -48,7 +48,7 @@
 #include "search.h"
 #include "version-etc.h"
 #include "xalloc.h"
-#include "xfreopen.h"
+#include "xbinary-io.h"
 #include "xstrtol.h"
 
 enum { SEP_CHAR_SELECTED = ':' };
@@ -1700,6 +1700,7 @@ static bool
 grepfile (int dirdesc, char const *name, bool follow, bool command_line)
 {
   int oflag = (O_RDONLY | O_NOCTTY
+               | (binary ? O_BINARY : 0)
                | (follow ? 0 : O_NOFOLLOW)
                | (skip_devices (command_line) ? O_NONBLOCK : 0));
   int desc = openat_safer (dirdesc, name, oflag);
@@ -1854,11 +1855,6 @@ grepdesc (int desc, bool command_line)
       goto closeout;
     }
 
-  /* Set input to binary mode.  Pipes are simulated with files
-     on DOS, so this includes the case of "foo | grep bar".  */
-  if (binary && !isatty (desc))
-    set_binary_mode (desc, O_BINARY);
-
   count = grep (desc, &st, &ineof);
   if (count_matches)
     {
@@ -1899,6 +1895,8 @@ grep_command_line_arg (char const *arg)
   if (STREQ (arg, "-"))
     {
       filename = label;
+      if (binary)
+        xset_binary_mode (STDIN_FILENO, O_BINARY);
       return grepdesc (STDIN_FILENO, true);
     }
   else
@@ -2579,14 +2577,15 @@ main (int argc, char **argv)
         if (STREQ (optarg, "-"))
           {
             if (binary)
-              xfreopen (NULL, "rb", stdin);
+              xset_binary_mode (STDIN_FILENO, O_BINARY);
             fp = stdin;
           }
         else
-          fp = fopen (optarg, binary ? "rb" : "r");
-
-        if (!fp)
-          die (EXIT_TROUBLE, errno, "%s", optarg);
+          {
+            fp = fopen (optarg, binary ? "rb" : "r");
+            if (!fp)
+              die (EXIT_TROUBLE, errno, "%s", optarg);
+          }
         oldcc = keycc;
         for (;; keycc += cc)
           {
@@ -2897,10 +2896,8 @@ main (int argc, char **argv)
   if ((argc - optind > 1 && !no_filenames) || with_filenames)
     out_file = 1;
 
-  /* Output is set to binary mode because we shouldn't convert
-     NL to CR-LF pairs, especially when grepping binary files.  */
-  if (binary && !isatty (STDOUT_FILENO))
-    xfreopen (NULL, "wb", stdout);
+  if (binary)
+    xset_binary_mode (STDOUT_FILENO, O_BINARY);
 
   /* Prefer sysconf for page size, as getpagesize typically returns int.  */
 #ifdef _SC_PAGESIZE
diff --git a/src/system.h b/src/system.h
index 05d8f1a..6292a28 100644
--- a/src/system.h
+++ b/src/system.h
@@ -23,7 +23,6 @@
 #include <unistd.h>
 #include <errno.h>
 
-#include "binary-io.h"
 #include "configmake.h"
 #include "dirname.h"
 #include "ignore-value.h"

http://git.savannah.gnu.org/cgit/grep.git/commit/?id=5398777784b4455aa8466c1aef48b5738b8cd626


commit c4485ac49a977d666187db4c5c25045215976577
Author: Paul Eggert <address@hidden>
Date:   Thu Feb 16 08:51:34 2017 -0800

    Fix up recent -U patches
    
    Inspired by a suggestion by Eric Blake (Bug#25707#17).
    * bootstrap.conf (gnulib_modules): Add xbinary-io,
    and remove binary-io and xfreopen.
    * doc/grep.texi (Other Options):
    Fix typo and reword to be a bit more general.
    * src/grep.c: Include xbinary-io.h instead of xfreopen.h.
    (grepfile): Open with O_BINARY if binary.
    (grepdesc): No need for set_binary_mode now.
    (grep_command_line_arg, main): Set stdin to binary mode if binary.
    (main): Avoid unnecessary test of stdin == NULL.
    Use xsetmode instead of xfreopen.
    * src/system.h: Do not include binary-io.h.

diff --git a/bootstrap.conf b/bootstrap.conf
index 4115f35..1c50974 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -26,7 +26,6 @@ gnulib_modules='
 alloca
 announce-gen
 argmatch
-binary-io
 c-ctype
 closeout
 dfa
@@ -53,10 +52,10 @@ isatty
 isblank
 iswctype
 largefile
-lseek
 locale
-malloc-gnu
+lseek
 maintainer-makefile
+malloc-gnu
 manywarnings
 mbrlen
 mbrtowc
@@ -95,7 +94,7 @@ wcrtomb
 wctob
 wctype-h
 xalloc
-xfreopen
+xbinary-io
 xstrtoimax
 '
 gnulib_name=libgreputils
diff --git a/doc/grep.texi b/doc/grep.texi
index 94a0621..077c05f 100644
--- a/doc/grep.texi
+++ b/doc/grep.texi
@@ -741,25 +741,26 @@ This can cause a performance penalty.
 @opindex -U
 @opindex --binary
 @cindex MS-Windows binary I/O
address@hidden binary I/O, /MS-Windows
-Under MS-Windows, use binary I/O when reading and writing files other
address@hidden binary I/O
+On platforms that distinguish between text and binary I/O,
+use the latter when reading and writing files other
 than the user's terminal, so that all input bytes are read and written
 as-is.  This overrides the default behavior where @command{grep}
-follows the operating system's advice whether to use binary or text
-I/O.  When @command{grep} uses text I/O it reads a carriage
-return--newline pair as a newline and a Control-Z as end-of-file, and
-it writes a newline as a carriage return--newline pair.  When this
-option is combined with @option{--byte-offset} (@option{-b}), byte
-counts treat each text I/O carriage return--newline as a single byte.
-
-When using text I/O, @option{--binary-files} heuristics are applied to
-input data after text-I/O processing.  These heuristics need not agree
+follows the operating system's advice whether to use text or binary
+I/address@hidden  On MS-Windows when @command{grep} uses text I/O it reads a
+carriage return--newline pair as a newline and a Control-Z as
+end-of-file, and it writes a newline as a carriage return--newline
+pair.
+
+When using text I/O @option{--byte-offset} (@option{-b}) counts and
address@hidden heuristics apply to input data after text-I/O
+processing.  Also, the @option{--binary-files} heuristics need not agree
 with the @option{--binary} option; that is, they may treat the data as
 text even if @option{--binary} is given, or vice versa.
 @xref{File and Directory Selection}.
 
-This option has no effect on platforms other than MS-Windows.
-
+This option has no effect on GNU and other POSIX-compatible platforms,
+which do not distinguish text from binary I/O.
 
 @item -z
 @itemx --null-data
diff --git a/src/grep.c b/src/grep.c
index 32cb642..775f227 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -48,7 +48,7 @@
 #include "search.h"
 #include "version-etc.h"
 #include "xalloc.h"
-#include "xfreopen.h"
+#include "xbinary-io.h"
 #include "xstrtol.h"
 
 enum { SEP_CHAR_SELECTED = ':' };
@@ -1700,6 +1700,7 @@ static bool
 grepfile (int dirdesc, char const *name, bool follow, bool command_line)
 {
   int oflag = (O_RDONLY | O_NOCTTY
+               | (binary ? O_BINARY : 0)
                | (follow ? 0 : O_NOFOLLOW)
                | (skip_devices (command_line) ? O_NONBLOCK : 0));
   int desc = openat_safer (dirdesc, name, oflag);
@@ -1854,11 +1855,6 @@ grepdesc (int desc, bool command_line)
       goto closeout;
     }
 
-  /* Set input to binary mode.  Pipes are simulated with files
-     on DOS, so this includes the case of "foo | grep bar".  */
-  if (binary && !isatty (desc))
-    set_binary_mode (desc, O_BINARY);
-
   count = grep (desc, &st, &ineof);
   if (count_matches)
     {
@@ -1899,6 +1895,8 @@ grep_command_line_arg (char const *arg)
   if (STREQ (arg, "-"))
     {
       filename = label;
+      if (binary)
+        xset_binary_mode (STDIN_FILENO, O_BINARY);
       return grepdesc (STDIN_FILENO, true);
     }
   else
@@ -2579,14 +2577,15 @@ main (int argc, char **argv)
         if (STREQ (optarg, "-"))
           {
             if (binary)
-              xfreopen (NULL, "rb", stdin);
+              xset_binary_mode (STDIN_FILENO, O_BINARY);
             fp = stdin;
           }
         else
-          fp = fopen (optarg, binary ? "rb" : "r");
-
-        if (!fp)
-          die (EXIT_TROUBLE, errno, "%s", optarg);
+          {
+            fp = fopen (optarg, binary ? "rb" : "r");
+            if (!fp)
+              die (EXIT_TROUBLE, errno, "%s", optarg);
+          }
         oldcc = keycc;
         for (;; keycc += cc)
           {
@@ -2897,10 +2896,8 @@ main (int argc, char **argv)
   if ((argc - optind > 1 && !no_filenames) || with_filenames)
     out_file = 1;
 
-  /* Output is set to binary mode because we shouldn't convert
-     NL to CR-LF pairs, especially when grepping binary files.  */
-  if (binary && !isatty (STDOUT_FILENO))
-    xfreopen (NULL, "wb", stdout);
+  if (binary)
+    xset_binary_mode (STDOUT_FILENO, O_BINARY);
 
   /* Prefer sysconf for page size, as getpagesize typically returns int.  */
 #ifdef _SC_PAGESIZE
diff --git a/src/system.h b/src/system.h
index 05d8f1a..6292a28 100644
--- a/src/system.h
+++ b/src/system.h
@@ -23,7 +23,6 @@
 #include <unistd.h>
 #include <errno.h>
 
-#include "binary-io.h"
 #include "configmake.h"
 #include "dirname.h"
 #include "ignore-value.h"

-----------------------------------------------------------------------

Summary of changes:
 NEWS           |   7 ++
 bootstrap.conf |   6 +-
 doc/grep.texi  |  55 ++++++--------
 gnulib         |   2 +-
 src/dosbuf.c   | 222 ---------------------------------------------------------
 src/grep.c     |  47 ++++++------
 src/system.h   |   1 -
 7 files changed, 55 insertions(+), 285 deletions(-)
 delete mode 100644 src/dosbuf.c


hooks/post-receive
-- 
grep



reply via email to

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