grep/backport-grep-s-does-not-suppress-binary-file-matches.patch

51 lines
1.7 KiB
Diff

From af79b17356f2edeca2908c14d922a24f659d4a96 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sat, 20 Nov 2021 22:53:55 -0800
Subject: [PATCH] =?UTF-8?q?grep:=20-s=20does=20not=20suppress=20?=
=?UTF-8?q?=E2=80=9Cbinary=20file=20matches=E2=80=9D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* src/grep.c (grep): Implement this.
* tests/binary-file-matches: Add regression test.
---
src/grep.c | 2 +-
tests/binary-file-matches | 8 +++++---
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/src/grep.c b/src/grep.c
index a55194c..19dff43 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -1646,7 +1646,7 @@ grep (int fd, struct stat const *st, bool *ineof)
finish_grep:
done_on_match = done_on_match_0;
out_quiet = out_quiet_0;
- if (binary_files == BINARY_BINARY_FILES && ! (out_quiet | suppress_errors)
+ if (binary_files == BINARY_BINARY_FILES && !out_quiet
&& (encoding_error_output
|| (0 <= nlines_first_null && nlines_first_null < nlines)))
error (0, 0, _("%s: binary file matches"), input_filename ());
diff --git a/tests/binary-file-matches b/tests/binary-file-matches
index 7fc4a11..8fea071 100755
--- a/tests/binary-file-matches
+++ b/tests/binary-file-matches
@@ -14,8 +14,10 @@ fail=0
echo "grep: (standard input): binary file matches" > exp \
|| framework_failure_
-printf 'a\0' | grep a > out 2> err || fail=1
-compare /dev/null out || fail=1
-compare exp err || fail=1
+for option in '' -s; do
+ printf 'a\0' | grep $option a > out 2> err || fail=1
+ compare /dev/null out || fail=1
+ compare exp err || fail=1
+done
Exit $fail
--
1.8.3.1