- if (write (ofd, outbuf, wsz) != wsz)
- /* XXX Handle short writes. */
- error (EXIT_FAILURE, errno, "%s: write", filename);
+
+ if (is_zero (outbuf, wsz)) { /* Seek to preserve sparseness. */
+ if (lseek (ofd, wsz, SEEK_CUR) == (off_t) -1)
+ error (EXIT_FAILURE, errno, "%s: seek", filename);
+ } else {
+ if (write (ofd, outbuf, wsz) != wsz)
+ /* XXX Handle short writes. */
+ error (EXIT_FAILURE, errno, "%s: write", filename);
+ }
+