]> Dogcows Code - chaz/tar/commitdiff
(expand_sparse): use ftruncate to handle the trailing hole
authorSergey Poznyakoff <gray@gnu.org.ua>
Fri, 19 Jan 2007 15:41:55 +0000 (15:41 +0000)
committerSergey Poznyakoff <gray@gnu.org.ua>
Fri, 19 Jan 2007 15:41:55 +0000 (15:41 +0000)
scripts/xsparse.c

index 87fad1a9dd82ef6fdcf4c78d21989c8618be8d89..99bb82a05ae805355d583b8d17270a534daac20d 100644 (file)
@@ -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);
This page took 0.019377 seconds and 4 git commands to generate.