summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorkaiw <kaiw@FreeBSD.org>2008-01-31 08:11:01 +0000
committerkaiw <kaiw@FreeBSD.org>2008-01-31 08:11:01 +0000
commite57ce2b6e66969617ddf24cf15e2a24e11871b15 (patch)
treedbc11b1ac87207f4bae8a0e0ee7f583067e1c146 /lib
parent213915cb49d168b2bec532920c73351ee0fb53ba (diff)
downloadFreeBSD-src-e57ce2b6e66969617ddf24cf15e2a24e11871b15.zip
FreeBSD-src-e57ce2b6e66969617ddf24cf15e2a24e11871b15.tar.gz
Add hook routine archive_write_ar_finish() which writes the 'ar'
global header if nothing else has been written before the closing of the archive. This will change the behaviour when creating archives without members, i.e., instead of generating a 0-size archive file, an archive with just the global header (8 bytes in total) will be created and it is indeed a valid archive by the definition of libarchive, thus subsequent operation on this archive will be accepted. This especially solves the failure caused by following sequence: (several ports do) % ar cru libfoo.a # without specifying obj files % ranlib libfoo.a Reviewed by: kientzle, jkoshy Approved by: kientzle Approved by: jkoshy (mentor) Reported by: erwin MFC after: 1 month
Diffstat (limited to 'lib')
-rw-r--r--lib/libarchive/archive_write_set_format_ar.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/libarchive/archive_write_set_format_ar.c b/lib/libarchive/archive_write_set_format_ar.c
index 9599070..6a223c3 100644
--- a/lib/libarchive/archive_write_set_format_ar.c
+++ b/lib/libarchive/archive_write_set_format_ar.c
@@ -75,6 +75,7 @@ static int archive_write_ar_header(struct archive_write *,
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_finish_entry(struct archive_write *);
static const char *ar_basename(const char *path);
static int format_octal(int64_t v, char *p, int s);
@@ -126,7 +127,7 @@ archive_write_set_format_ar(struct archive_write *a)
a->format_write_header = archive_write_ar_header;
a->format_write_data = archive_write_ar_data;
- a->format_finish = NULL;
+ a->format_finish = archive_write_ar_finish;
a->format_destroy = archive_write_ar_destroy;
a->format_finish_entry = archive_write_ar_finish_entry;
return (ARCHIVE_OK);
@@ -398,6 +399,23 @@ archive_write_ar_destroy(struct archive_write *a)
}
static int
+archive_write_ar_finish(struct archive_write *a)
+{
+ 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);
+ return (ret);
+ }
+
+ return (ARCHIVE_OK);
+}
+
+static int
archive_write_ar_finish_entry(struct archive_write *a)
{
struct ar_w *ar;
OpenPOWER on IntegriCloud