summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2000-08-24 08:34:33 +0000
committerJim Meyering <jim@meyering.net>2000-08-24 08:34:33 +0000
commit69450c7b8eeea81c4c1a2f3198ca325f9449ee82 (patch)
tree66b69cf5cc623c35337b336c50d66176dea3459a /src
parent2abb1fd55d9b20c3eeb6a5e8fdaa5e0fe6c0349b (diff)
downloadcoreutils-69450c7b8eeea81c4c1a2f3198ca325f9449ee82.tar.xz
(skip): Assume lseek failed if it returned zero, since a zero return is
impossible and some buggy drivers return zero. Use SEEK_CUR rather than SEEK_SET; this fixes a bug when the file descriptor is not currently rewound.
Diffstat (limited to 'src')
-rw-r--r--src/dd.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/dd.c b/src/dd.c
index 2a89b6b01..9291a1a2c 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -720,7 +720,8 @@ swab_buffer (unsigned char *buf, size_t *nread)
/* Throw away RECORDS blocks of BLOCKSIZE bytes on file descriptor FDESC,
which is open with read permission for FILE. Store up to BLOCKSIZE
- bytes of the data at a time in BUF, if necessary. */
+ bytes of the data at a time in BUF, if necessary. RECORDS must be
+ nonzero. */
static void
skip (int fdesc, char *file, uintmax_t records, size_t blocksize,
@@ -729,10 +730,12 @@ skip (int fdesc, char *file, uintmax_t records, size_t blocksize,
off_t o;
/* Try lseek and if an error indicates it was an inappropriate
- operation, fall back on using read. */
+ operation, fall back on using read. Some broken versions of
+ lseek return zero, so count that as an error too as a valid zero
+ return is not possible here. */
o = records * blocksize;
if (o / blocksize != records
- || lseek (fdesc, o, SEEK_SET) == -1)
+ || lseek (fdesc, o, SEEK_CUR) <= 0)
{
while (records-- > 0)
{