+/* Dump zeros to file->fd until offset is reached. It is used instead of
+ lseek if the output file is not seekable */
+static long
+dump_zeros (struct tar_sparse_file *file, off_t offset)
+{
+ char buf[BLOCKSIZE];
+
+ if (offset - file->offset < 0)
+ {
+ errno = EINVAL;
+ return -1;
+ }
+
+ memset (buf, 0, sizeof buf);
+ while (file->offset < offset)
+ {
+ size_t size = offset - file->offset;
+ size_t wrbytes;
+
+ if (size > sizeof buf)
+ size = sizeof buf;
+ wrbytes = write (file->fd, buf, size);
+ if (wrbytes <= 0)
+ {
+ if (wrbytes == 0)
+ errno = EINVAL;
+ return -1;
+ }
+ file->offset += wrbytes;
+ }
+ return file->offset;
+}
+