summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2023-02-05 19:52:31 +0000
committerPádraig Brady <P@draigBrady.com>2023-04-08 12:19:40 +0100
commitce630dfc7ef32ff7e35c627bd061a45ce9053d9d (patch)
treee198bd7070f7ce510498c61af2243096e4913104 /src
parentf6c21f6d3addb6461c41af612e73fbb15d21545f (diff)
downloadcoreutils-ce630dfc7ef32ff7e35c627bd061a45ce9053d9d.tar.gz
wc: ensure we update file offset
* src/wc.c (wc): Update the offset when not reading, and do read if we can't update the offset. * tests/misc/wc-proc.sh: Add a test case. * NEWS: Mention the bug fix. Fixes https://bugs.gnu.org/61300
Diffstat (limited to 'src')
-rw-r--r--src/wc.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/wc.c b/src/wc.c
index 801396a15..becceda98 100644
--- a/src/wc.c
+++ b/src/wc.c
@@ -450,7 +450,10 @@ wc (int fd, char const *file_x, struct fstatus *fstatus, off_t current_pos)
beyond the end of the file. As in the example above. */
bytes = end_pos < current_pos ? 0 : end_pos - current_pos;
- skip_read = true;
+ if (bytes && 0 <= lseek (fd, bytes, SEEK_CUR))
+ skip_read = true;
+ else
+ bytes = 0;
}
else
{