-static int
-finish_sparse_file (int file, off_t *sizeleft, off_t fullsize, char *name)
-{
- union block *start;
- size_t bufsize;
- int sparse_index = 0;
- ssize_t count;
-
- while (*sizeleft > 0)
- {
- start = find_next_block ();
- memset (start->buffer, 0, BLOCKSIZE);
- bufsize = sparsearray[sparse_index].numbytes;
- if (!bufsize)
- {
- /* We blew it, maybe. */
- char buf1[UINTMAX_STRSIZE_BOUND];
- char buf2[UINTMAX_STRSIZE_BOUND];
-
- ERROR ((0, 0, _("Wrote %s of %s bytes to file %s"),
- STRINGIFY_BIGINT (fullsize - *sizeleft, buf1),
- STRINGIFY_BIGINT (fullsize, buf2),
- name));
- break;
- }
-
- if (lseek (file, sparsearray[sparse_index++].offset, SEEK_SET) < 0)
- {
- char buf[UINTMAX_STRSIZE_BOUND];
- ERROR ((0, errno, _("lseek error at byte %s in file %s"),
- STRINGIFY_BIGINT (sparsearray[sparse_index - 1].offset, buf),
- name));
- break;
- }
-
- /* If the number of bytes to be written here exceeds the size of
- the temporary buffer, do it in steps. */
-
- while (bufsize > BLOCKSIZE)
- {
-#if 0
- if (amount_read)
- {
- count = safe_read (file, start->buffer + amount_read,
- BLOCKSIZE - amount_read);
- bufsize -= BLOCKSIZE - amount_read;
- amount_read = 0;
- set_next_block_after (start);
- start = find_next_block ();
- memset (start->buffer, 0, BLOCKSIZE);
- }
-#endif
- /* Store the data. */
-
- count = safe_read (file, start->buffer, BLOCKSIZE);
- if (count < 0)
- {
- char buf[UINTMAX_STRSIZE_BOUND];
- ERROR ((0, errno, _("\
-Read error at byte %s, reading %lu bytes, in file %s"),
- STRINGIFY_BIGINT (fullsize - *sizeleft, buf),
- (unsigned long) bufsize, name));
- return 1;
- }
- bufsize -= count;
- *sizeleft -= count;
- set_next_block_after (start);
- start = find_next_block ();
- memset (start->buffer, 0, BLOCKSIZE);
- }
-
- {
- char buffer[BLOCKSIZE];
-
- clear_buffer (buffer);
- count = safe_read (file, buffer, bufsize);
- memcpy (start->buffer, buffer, BLOCKSIZE);
- }
-
- if (count < 0)
- {
- char buf[UINTMAX_STRSIZE_BOUND];
-
- ERROR ((0, errno,
- _("Read error at byte %s, reading %lu bytes, in file %s"),
- STRINGIFY_BIGINT (fullsize - *sizeleft, buf),
- (unsigned long) bufsize, name));
- return 1;
- }
-#if 0
- if (amount_read >= BLOCKSIZE)
- {
- amount_read = 0;
- set_next_block_after (start + (count - 1) / BLOCKSIZE);
- if (count != bufsize)
- {
- ERROR ((0, 0,
- _("File %s shrunk, padding with zeros"),
- name));
- return 1;
- }
- start = find_next_block ();
- }
- else
- amount_read += bufsize;
-#endif
- *sizeleft -= count;
- set_next_block_after (start);
-
- }
- free (sparsearray);
-#if 0
- set_next_block_after (start + (count - 1) / BLOCKSIZE);
-#endif
- return 0;