From fc8d7478f775e06e7b05892d524b5cac0f28107e Mon Sep 17 00:00:00 2001 From: Tim Kientzle Date: Thu, 27 Aug 2009 00:24:19 -0400 Subject: [PATCH] If ftruncate() isn't available, we fall back to use 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 | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libarchive/archive_write_disk.c b/libarchive/archive_write_disk.c index 54fab828a..703ac1c1d 100644 --- a/libarchive/archive_write_disk.c +++ b/libarchive/archive_write_disk.c @@ -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); -- 2.47.3