]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Add archive_read_next_header2(), which populates the archive_entry
authorTim Kientzle <kientzle@gmail.com>
Tue, 24 Mar 2009 20:01:00 +0000 (16:01 -0400)
committerTim Kientzle <kientzle@gmail.com>
Tue, 24 Mar 2009 20:01:00 +0000 (16:01 -0400)
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

libarchive/archive.h
libarchive/archive_read.3
libarchive/archive_read.c

index 936161754c553ec8473e6a58789874e67736af3a..6e35b432318b6b9dae9a084aa44fa2bc8402d603 100644 (file)
@@ -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.
index bb56ec47b8c61d4622f260da160da6aaf080d4fb..d6d2c74c856b9a80973f39b083b5c08c37f95809 100644 (file)
@@ -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 ,
 .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
index cb2cc3eb169ef7eae6a9db0dbcd9c650544b7a79..29d5a1f2438068d8685a7cdae0fefaad6b9bc3a7 100644 (file)
@@ -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.