tail: refactor to skip stat call on failure

* src/tail.c (tail_bytes): New function.
(tail_bytes, tail_lines, tail): Accept struct stat pointer from
caller instead of calling fstat ourselves.  All callers changed.
(tail_file): Skip a call to fstat if fstat already failed.
* tests/tail/follow-stdin.sh: Adjust to match new behavior
on failure, which omits a redundant diagnostic.
This commit is contained in:
Paul Eggert
2025-07-29 08:24:58 -07:00
parent d58aa27d06
commit 09fc945b37
2 changed files with 47 additions and 48 deletions

View File

@@ -59,7 +59,6 @@ done
returns_ 1 timeout 10 tail -f - <&- 2>errt || fail=1
cat <<\EOF >exp || framework_failure_
tail: cannot fstat 'standard input'
tail: error reading 'standard input'
tail: no files remaining
EOF
sed 's/\(tail:.*\):.*/\1/' errt > err || framework_failure_