diff options
Diffstat (limited to 'contrib/libarchive/libarchive/archive_write_set_format_ar.c')
-rw-r--r-- | contrib/libarchive/libarchive/archive_write_set_format_ar.c | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/contrib/libarchive/libarchive/archive_write_set_format_ar.c b/contrib/libarchive/libarchive/archive_write_set_format_ar.c index cb8ddaa203e7..550d69172976 100644 --- a/contrib/libarchive/libarchive/archive_write_set_format_ar.c +++ b/contrib/libarchive/libarchive/archive_write_set_format_ar.c @@ -48,6 +48,7 @@ struct ar_w { uint64_t entry_padding; int is_strtab; int has_strtab; + char wrote_global_header; char *strtab; }; @@ -74,8 +75,8 @@ static int archive_write_ar_header(struct archive_write *, struct archive_entry *); static ssize_t archive_write_ar_data(struct archive_write *, const void *buff, size_t s); -static int archive_write_ar_destroy(struct archive_write *); -static int archive_write_ar_finish(struct archive_write *); +static int archive_write_ar_free(struct archive_write *); +static int archive_write_ar_close(struct archive_write *); static int archive_write_ar_finish_entry(struct archive_write *); static const char *ar_basename(const char *path); static int format_octal(int64_t v, char *p, int s); @@ -85,7 +86,11 @@ int archive_write_set_format_ar_bsd(struct archive *_a) { struct archive_write *a = (struct archive_write *)_a; - int r = archive_write_set_format_ar(a); + int r; + + archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_NEW, "archive_write_set_format_ar_bsd"); + r = archive_write_set_format_ar(a); if (r == ARCHIVE_OK) { a->archive.archive_format = ARCHIVE_FORMAT_AR_BSD; a->archive.archive_format_name = "ar (BSD)"; @@ -97,7 +102,11 @@ int archive_write_set_format_ar_svr4(struct archive *_a) { struct archive_write *a = (struct archive_write *)_a; - int r = archive_write_set_format_ar(a); + int r; + + archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_NEW, "archive_write_set_format_ar_svr4"); + r = archive_write_set_format_ar(a); if (r == ARCHIVE_OK) { a->archive.archive_format = ARCHIVE_FORMAT_AR_GNU; a->archive.archive_format_name = "ar (GNU/SVR4)"; @@ -114,8 +123,8 @@ archive_write_set_format_ar(struct archive_write *a) struct ar_w *ar; /* If someone else was already registered, unregister them. */ - if (a->format_destroy != NULL) - (a->format_destroy)(a); + if (a->format_free != NULL) + (a->format_free)(a); ar = (struct ar_w *)malloc(sizeof(*ar)); if (ar == NULL) { @@ -128,8 +137,8 @@ archive_write_set_format_ar(struct archive_write *a) a->format_name = "ar"; a->format_write_header = archive_write_ar_header; a->format_write_data = archive_write_ar_data; - a->format_finish = archive_write_ar_finish; - a->format_destroy = archive_write_ar_destroy; + a->format_close = archive_write_ar_close; + a->format_free = archive_write_ar_free; a->format_finish_entry = archive_write_ar_finish_entry; return (ARCHIVE_OK); } @@ -166,8 +175,10 @@ archive_write_ar_header(struct archive_write *a, struct archive_entry *entry) * If we are now at the beginning of the archive, * we need first write the ar global header. */ - if (a->archive.file_position == 0) - (a->compressor.write)(a, "!<arch>\n", 8); + if (!ar->wrote_global_header) { + __archive_write_output(a, "!<arch>\n", 8); + ar->wrote_global_header = 1; + } memset(buff, ' ', 60); strncpy(&buff[AR_fmag_offset], "`\n", 2); @@ -190,7 +201,7 @@ archive_write_ar_header(struct archive_write *a, struct archive_entry *entry) ar->is_strtab = 1; buff[AR_name_offset] = buff[AR_name_offset + 1] = '/'; /* - * For archive string table, only ar_size filed should + * For archive string table, only ar_size field should * be set. */ goto size; @@ -330,7 +341,7 @@ size: return (ARCHIVE_WARN); } - ret = (a->compressor.write)(a, buff, 60); + ret = __archive_write_output(a, buff, 60); if (ret != ARCHIVE_OK) return (ret); @@ -338,7 +349,7 @@ size: ar->entry_padding = ar->entry_bytes_remaining % 2; if (append_fn > 0) { - ret = (a->compressor.write)(a, filename, strlen(filename)); + ret = __archive_write_output(a, filename, strlen(filename)); if (ret != ARCHIVE_OK) return (ret); ar->entry_bytes_remaining -= strlen(filename); @@ -374,7 +385,7 @@ archive_write_ar_data(struct archive_write *a, const void *buff, size_t s) ar->has_strtab = 1; } - ret = (a->compressor.write)(a, buff, s); + ret = __archive_write_output(a, buff, s); if (ret != ARCHIVE_OK) return (ret); @@ -383,7 +394,7 @@ archive_write_ar_data(struct archive_write *a, const void *buff, size_t s) } static int -archive_write_ar_destroy(struct archive_write *a) +archive_write_ar_free(struct archive_write *a) { struct ar_w *ar; @@ -403,16 +414,19 @@ archive_write_ar_destroy(struct archive_write *a) } static int -archive_write_ar_finish(struct archive_write *a) +archive_write_ar_close(struct archive_write *a) { + struct ar_w *ar; int ret; /* * If we haven't written anything yet, we need to write * the ar global header now to make it a valid ar archive. */ - if (a->archive.file_position == 0) { - ret = (a->compressor.write)(a, "!<arch>\n", 8); + ar = (struct ar_w *)a->format_data; + if (!ar->wrote_global_header) { + ar->wrote_global_header = 1; + ret = __archive_write_output(a, "!<arch>\n", 8); return (ret); } @@ -439,12 +453,12 @@ archive_write_ar_finish_entry(struct archive_write *a) if (ar->entry_padding != 1) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Padding wrong size: %d should be 1 or 0", - (int)ar->entry_padding); + "Padding wrong size: %ju should be 1 or 0", + (uintmax_t)ar->entry_padding); return (ARCHIVE_WARN); } - ret = (a->compressor.write)(a, "\n", 1); + ret = __archive_write_output(a, "\n", 1); return (ret); } @@ -501,7 +515,7 @@ format_decimal(int64_t v, char *p, int s) len = s; h = p; - /* Negative values in ar header are meaningless , so use 0. */ + /* Negative values in ar header are meaningless, so use 0. */ if (v < 0) { while (len-- > 0) *p++ = '0'; |