static struct fixup_entry *sort_dir_list(struct fixup_entry *p);
static ssize_t write_data_block(struct archive_write_disk *,
const char *, size_t);
+static void close_file_descriptor(struct archive_write_disk *);
static int _archive_write_disk_close(struct archive *);
static int _archive_write_disk_free(struct archive *);
r = hfs_write_data_block(
a, null_d, a->file_remaining_bytes);
if (r < 0)
+ close_file_descriptor(a->fd);
return ((int)r);
}
#endif
a->filesize == 0) {
archive_set_error(&a->archive, errno,
"File size could not be restored");
+ close_file_descriptor(a->fd);
return (ARCHIVE_FAILED);
}
#endif
*/
a->pst = NULL;
if ((ret = lazy_stat(a)) != ARCHIVE_OK)
+ close_file_descriptor(a->fd);
return (ret);
/* We can use lseek()/write() to extend the file if
* ftruncate didn't work or isn't available. */
if (lseek(a->fd, a->filesize - 1, SEEK_SET) < 0) {
archive_set_error(&a->archive, errno,
"Seek failed");
+ close_file_descriptor(a->fd);
return (ARCHIVE_FATAL);
}
if (write(a->fd, &nul, 1) < 0) {
archive_set_error(&a->archive, errno,
"Write to restore size failed");
+ close_file_descriptor(a->fd);
return (ARCHIVE_FATAL);
}
a->pst = NULL;
}
#endif
+/*
+ * Close the file descriptor if one is open.
+ */
+static void close_file_descriptor(struct archive_write_disk* a)
+{
+ if (a->fd >= 0) {
+ close(a->fd);
+ a->fd = -1;
+ }
+}
+
+
#endif /* !_WIN32 || __CYGWIN__ */