]> Dogcows Code - chaz/tar/blobdiff - scripts/xsparse.c
Update
[chaz/tar] / scripts / xsparse.c
index 2728bbce22d919522e855c81982e778a0a6fa94f..c77c3f5ced78b0e1c96baf816726cdf754d59876 100644 (file)
@@ -1,13 +1,13 @@
 /* xsparse - expands compressed sparse file images extracted from GNU tar
    archives.
 
 /* 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
    
    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
 
    Written by Sergey Poznyakoff
    
    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
-   Free Software Foundation; either version 2, or (at your option) any later
+   Free Software Foundation; either version 3, or (at your option) any later
    version.
 
    This program is distributed in the hope that it will be useful, but
    version.
 
    This program is distributed in the hope that it will be useful, but
@@ -23,7 +23,6 @@
 #include <stdio.h>
 #include <stdarg.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <stdarg.h>
 #include <unistd.h>
-#include <getopt.h>
 #include <fcntl.h>
 #include <sys/stat.h>
 #include <limits.h>
 #include <fcntl.h>
 #include <sys/stat.h>
 #include <limits.h>
@@ -303,15 +302,20 @@ expand_sparse (FILE *sfp, int ofd)
     {
       size_t size = sparse_map[i].numbytes;
 
     {
       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);
        }
     }
   free (buffer);
This page took 0.020804 seconds and 4 git commands to generate.