summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2012-06-05 12:24:49 +0200
committerJim Meyering <meyering@redhat.com>2012-06-05 19:55:26 +0200
commit295ee521bc1a4f473ee8b7b5a4be32c5b5c7386f (patch)
treeb118600100717eb2b4d653d02f397acf96bc7971 /src
parent5fdd5c6310098c5ce3cbc608450d5c4104f18c2f (diff)
downloadcoreutils-295ee521bc1a4f473ee8b7b5a4be32c5b5c7386f.tar.xz
head: with --lines=-N (-n-N) reset file pointer on seekable input
* src/head.c (elide_tail_lines_seekable): Reset file pointer after printing up to an end-relative line-counted offset. Anoop Sharma reported the problem and suggested the fix. * tests/misc/head-pos: Add coverage via a very similar, existing test. Also add coverage for a previously untested block of code. * tests/misc/head-elide-tail ($READ_BUFSIZE): Update to 8192, to match the value of BUFSIZ I see today on Fedora 17/x86_64 (unrelated to this fix). * NEWS (Bug fixes): Mention it. Improved-by: Pádraig Brady
Diffstat (limited to 'src')
-rw-r--r--src/head.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/head.c b/src/head.c
index d7e83b716..0d5e1b2c6 100644
--- a/src/head.c
+++ b/src/head.c
@@ -667,6 +667,14 @@ elide_tail_lines_seekable (const char *pretty_filename, int fd,
Don't bother testing for failure for such a small amount.
Any failure will be detected upon close. */
fwrite (buffer, 1, n + 1, stdout);
+
+ /* Set file pointer to the byte after what we've output. */
+ if (lseek (fd, pos + n + 1, SEEK_SET) < 0)
+ {
+ error (0, errno, "%s: failed to reset file pointer",
+ quote (pretty_filename));
+ return false;
+ }
return true;
}
}