From: Sergey Poznyakoff Date: Fri, 19 Jan 2007 15:41:55 +0000 (+0000) Subject: (expand_sparse): use ftruncate to handle the trailing hole X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Ftar;a=commitdiff_plain;h=868ee7402884604c679ee13f6fe9772e05ba3ddd (expand_sparse): use ftruncate to handle the trailing hole --- diff --git a/scripts/xsparse.c b/scripts/xsparse.c index 87fad1a..99bb82a 100644 --- a/scripts/xsparse.c +++ b/scripts/xsparse.c @@ -1,7 +1,7 @@ /* xsparse - expands compressed sparse file images extracted from GNU tar archives. - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2007 Free Software Foundation, Inc. Written by Sergey Poznyakoff @@ -302,15 +302,20 @@ expand_sparse (FILE *sfp, int ofd) { size_t size = sparse_map[i].numbytes; - lseek (ofd, sparse_map[i].offset, SEEK_SET); - while (size) + if (size == 0) + ftruncate (ofd, sparse_map[i].offset); + else { - size_t rdsize = (size < maxbytes) ? size : maxbytes; - if (rdsize != fread (buffer, 1, rdsize, sfp)) - die (1, "read error (%d)", errno); - if (rdsize != write (ofd, buffer, rdsize)) - die (1, "write error (%d)", errno); - size -= rdsize; + lseek (ofd, sparse_map[i].offset, SEEK_SET); + while (size) + { + size_t rdsize = (size < maxbytes) ? size : maxbytes; + if (rdsize != fread (buffer, 1, rdsize, sfp)) + die (1, "read error (%d)", errno); + if (rdsize != write (ofd, buffer, rdsize)) + die (1, "write error (%d)", errno); + size -= rdsize; + } } } free (buffer);