summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2016-12-07 20:20:04 (GMT)
committerPaul Eggert <eggert@cs.ucla.edu>2016-12-07 20:20:26 (GMT)
commita3721c43f96beb255c533118bfaba1ddf8d9a6be (patch)
tree66393951de00b74c7066487a04b8760d8f766b1e
parent136a8987b003c2cee4c2419e2bf870ff0836f8f9 (diff)
downloadgrep-a3721c43f96beb255c533118bfaba1ddf8d9a6be.zip
grep-a3721c43f96beb255c533118bfaba1ddf8d9a6be.tar.gz
grep-a3721c43f96beb255c533118bfaba1ddf8d9a6be.tar.bz2
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.
-rw-r--r--src/grep.c31
1 files changed, 8 insertions, 23 deletions
diff --git a/src/grep.c b/src/grep.c
index 4538f22..1e910cb 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