+ if (!sparse) { /* Not sparse */
+#ifdef HAVE_POSIX_FALLOCATE
+ int err = posix_fallocate (fd, 0, size);
+ if (err != 0) {
+ errno = err;
+ perror ("fallocate");
+ close (fd);
+ unlink (filename);
+ return -1;
+ }
+#else
+ /* Slow emulation of posix_fallocate on platforms which don't have it. */
+ char buffer[BUFSIZ];
+ memset (buffer, 0, sizeof buffer);
+
+ size_t remaining = size;
+ while (remaining > 0) {
+ size_t n = remaining > sizeof buffer ? sizeof buffer : remaining;
+ ssize_t r = write (fd, buffer, n);
+ if (r == -1) {
+ perror ("write");
+ close (fd);
+ unlink (filename);
+ return -1;
+ }
+ remaining -= r;
+ }
+#endif
+ } else { /* Sparse */
+ if (lseek (fd, size-1, SEEK_SET) == (off_t) -1) {
+ perror ("lseek");
+ close (fd);
+ unlink (filename);
+ return -1;
+ }
+
+ if (write (fd, &c, 1) != 1) {
+ perror ("write");
+ close (fd);
+ unlink (filename);
+ return -1;
+ }