Package: grep / 2.27-2

upstream-grep-simplify-finalize_input.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
From a3721c43f96beb255c533118bfaba1ddf8d9a6be Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Wed, 7 Dec 2016 12:20:04 -0800
Subject: [PATCH] grep: simplify finalize_input

* src/grep.c (finalize_input): Simplify without changing behavior.
It's still a bit of a rat's-nest, but it's a cozier rat's-nest.
---
 src/grep.c | 31 ++++++++-----------------------
 1 file changed, 8 insertions(+), 23 deletions(-)

diff --git a/src/grep.c b/src/grep.c
index 4538f225..1e910cb7 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -1758,29 +1758,14 @@ drain_input (int fd, struct stat const *st)
 static void
 finalize_input (int fd, struct stat const *st, bool ineof)
 {
-  if (fd != STDIN_FILENO)
-    return;
-
-  if (outleft)
-    {
-      if (ineof)
-        return;
-      if (seek_failed)
-        {
-          if (drain_input (fd, st))
-            return;
-        }
-      else if (0 <= lseek (fd, 0, SEEK_END))
-        return;
-    }
-  else
-    {
-      if (seek_failed || bufoffset == after_last_match
-          || 0 <= lseek (fd, after_last_match, SEEK_SET))
-        return;
-    }
-
-  suppressible_error (errno);
+  if (fd == STDIN_FILENO
+      && (outleft
+          ? (!ineof && (seek_failed
+                        ? ! drain_input (fd, st)
+                        : lseek (fd, 0, SEEK_END) < 0))
+          : (bufoffset != after_last_match && !seek_failed
+             && lseek (fd, after_last_match, SEEK_SET) < 0)))
+    suppressible_error (errno);
 }
 
 static bool
-- 
2.11.0