From: Tim Kientzle Date: Tue, 24 Mar 2009 20:01:00 +0000 (-0400) Subject: Add archive_read_next_header2(), which populates the archive_entry X-Git-Tag: v2.7.0~93 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ff12dfa8d4260d76144a427e400c93095acf88e6;p=thirdparty%2Flibarchive.git Add archive_read_next_header2(), which populates the archive_entry object passed into it. Make archive_read_next_header() be the obvious wrapper that just reuses a single entry object. This has been shown to provide a big speedup for cases where people want to generate a list of every entry in an archive; creating a new entry is faster than cloning an existing entry. Thanks to: Brian Harring SVN-Revision: 841 --- diff --git a/libarchive/archive.h b/libarchive/archive.h index 936161754..6e35b4323 100644 --- a/libarchive/archive.h +++ b/libarchive/archive.h @@ -355,6 +355,10 @@ __LA_DECL int archive_read_open_FILE(struct archive *, FILE *_file); __LA_DECL int archive_read_next_header(struct archive *, struct archive_entry **); +/* Parses and returns next entry header using the archive_entry passed in */ +__LA_DECL int archive_read_next_header2(struct archive *, + struct archive_entry *); + /* * Retrieve the byte offset in UNCOMPRESSED data where last-read * header started. diff --git a/libarchive/archive_read.3 b/libarchive/archive_read.3 index bb56ec47b..d6d2c74c8 100644 --- a/libarchive/archive_read.3 +++ b/libarchive/archive_read.3 @@ -51,6 +51,7 @@ .Nm archive_read_open_filename , .Nm archive_read_open_memory , .Nm archive_read_next_header , +.Nm archive_read_next_header2 , .Nm archive_read_data , .Nm archive_read_data_block , .Nm archive_read_data_skip , @@ -132,6 +133,8 @@ .Fn archive_read_open_memory "struct archive *" "void *buff" "size_t size" .Ft int .Fn archive_read_next_header "struct archive *" "struct archive_entry **" +.Ft int +.Fn archive_read_next_header2 "struct archive *" "struct archive_entry *" .Ft ssize_t .Fn archive_read_data "struct archive *" "void *buff" "size_t len" .Ft int @@ -317,6 +320,14 @@ memory containing the archive data. Read the header for the next entry and return a pointer to a .Tn struct archive_entry . +This is a convenience wrapper around +.Fn archive_read_next_header2 +that uses an internal +.Tn struct archive_entry +object. +.It Fn archive_read_next_header2 +Read the header for the next entry and populate the provided +.Tn struct archive_entry . .It Fn archive_read_data Read data associated with the header just read. Internally, this is a convenience function that calls diff --git a/libarchive/archive_read.c b/libarchive/archive_read.c index cb2cc3eb1..29d5a1f24 100644 --- a/libarchive/archive_read.c +++ b/libarchive/archive_read.c @@ -368,18 +368,15 @@ build_stream(struct archive_read *a) * Read header of next entry. */ int -archive_read_next_header(struct archive *_a, struct archive_entry **entryp) +archive_read_next_header2(struct archive *_a, struct archive_entry *entry) { struct archive_read *a = (struct archive_read *)_a; - struct archive_entry *entry; int slot, ret; __archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA, "archive_read_next_header"); - *entryp = NULL; - entry = a->entry; archive_entry_clear(entry); archive_clear_error(&a->archive); @@ -437,12 +434,22 @@ archive_read_next_header(struct archive *_a, struct archive_entry **entryp) break; } - *entryp = entry; a->read_data_output_offset = 0; a->read_data_remaining = 0; return (ret); } +int +archive_read_next_header(struct archive *_a, struct archive_entry **entryp) +{ + int ret; + struct archive_read *a = (struct archive_read *)_a; + *entryp = NULL; + ret = archive_read_next_header2(_a, a->entry); + *entryp = a->entry; + return ret; +} + /* * Allow each registered format to bid on whether it wants to handle * the next entry. Return index of winning bidder.