From: Jim Meyering Date: Thu, 24 Aug 2000 08:34:33 +0000 (+0000) Subject: (skip): Assume lseek failed if it returned zero, since a zero return is X-Git-Tag: FILEUTILS-4_0z~112 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=69450c7b8eeea81c4c1a2f3198ca325f9449ee82;p=thirdparty%2Fcoreutils.git (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. --- diff --git a/src/dd.c b/src/dd.c index 2a89b6b014..9291a1a2c1 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) {