]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
If ftruncate() isn't available, we fall back to use
authorTim Kientzle <kientzle@gmail.com>
Thu, 27 Aug 2009 04:24:19 +0000 (00:24 -0400)
committerTim Kientzle <kientzle@gmail.com>
Thu, 27 Aug 2009 04:24:19 +0000 (00:24 -0400)
lseek()/write() to extend a file.  Unfortunately, that
code was broken, as would be readily apparent to anyone who
ran the test suite on a platform that lacked ftruncate().

Thanks to: Daniel Mack for asking about this

SVN-Revision: 1394

libarchive/archive_write_disk.c

index 54fab828a303eccb0e375a7ae04efabf042f1208..703ac1c1d1090054010d91ad15b60696628a4bc9 100644 (file)
@@ -692,15 +692,18 @@ _archive_write_finish_entry(struct archive *_a)
                }
 #endif
                /*
-                * Explicitly stat the file as some platforms might not
-                * implement the XSI option to extend files via ftruncate.
+                * Not all platforms implement the XSI option to
+                * extend files via ftruncate.  Stat() the file again
+                * to see what happened.
                 */
                a->pst = NULL;
                if ((ret = _archive_write_disk_lazy_stat(a)) != ARCHIVE_OK)
                        return (ret);
-               if (a->st.st_size != a->filesize) {
+               /* We can use lseek()/write() to extend the file if
+                * ftruncate didn't work or isn't available. */
+               if (a->st.st_size < a->filesize) {
                        const char nul = '\0';
-                       if (lseek(a->fd, a->st.st_size - 1, SEEK_SET) < 0) {
+                       if (lseek(a->fd, a->filesize - 1, SEEK_SET) < 0) {
                                archive_set_error(&a->archive, errno,
                                    "Seek failed");
                                return (ARCHIVE_FATAL);