]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Refactor archive_read_extract
authorPaul Barker <paul@paulbarker.me.uk>
Sun, 6 Apr 2014 13:37:03 +0000 (14:37 +0100)
committerPaul Barker <paul@paulbarker.me.uk>
Sun, 6 Apr 2014 14:39:09 +0000 (15:39 +0100)
The initialisation of the archive_write_disk object and the call to
archive_write_disk_set_standard_lookup are only needed in the
archive_read_extract function, not in archive_read_extract2 or other related
functions. Therefore this initialisation is merged into archive_read_extract.

The static function get_extract is renamed to __archive_read_get_extract so that
is can be made non-static. The struct extract is renamed to archive_read_extract
so that it can be placed in a header file without risk of namespace clashes.
Both these declarations are then moved to the archive_read_private.h header.
This preparation is necessary so that the contents of archive_read_extract.c can
be split between two source files.

Signed-off-by: Paul Barker <paul@paulbarker.me.uk>
libarchive/archive_read_extract.c
libarchive/archive_read_private.h

index 795f2abea8477792d8c9805a474653dd4a585ab1..6558b683a31bb843b0d9119b93a6deeea0b5d58e 100644 (file)
@@ -45,37 +45,22 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_read_extract.c,v 1.61 2008/05/26
 #include "archive_read_private.h"
 #include "archive_write_disk_private.h"
 
-struct extract {
-       struct archive *ad; /* archive_write_disk object */
-
-       /* Progress function invoked during extract. */
-       void                    (*extract_progress)(void *);
-       void                     *extract_progress_user_data;
-};
-
 static int     archive_read_extract_cleanup(struct archive_read *);
 static int     copy_data(struct archive *ar, struct archive *aw);
-static struct extract *get_extract(struct archive_read *);
 
-static struct extract *
-get_extract(struct archive_read *a)
+/* Retrieve an extract object without initialising the associated
+ * archive_write_disk object.
+ */
+struct archive_read_extract *
+__archive_read_get_extract(struct archive_read *a)
 {
-       /* If we haven't initialized, do it now. */
-       /* This also sets up a lot of global state. */
        if (a->extract == NULL) {
-               a->extract = (struct extract *)malloc(sizeof(*a->extract));
+               a->extract = (struct archive_read_extract *)malloc(sizeof(*a->extract));
                if (a->extract == NULL) {
                        archive_set_error(&a->archive, ENOMEM, "Can't extract");
                        return (NULL);
                }
                memset(a->extract, 0, sizeof(*a->extract));
-               a->extract->ad = archive_write_disk_new();
-               if (a->extract->ad == NULL) {
-                       archive_set_error(&a->archive, ENOMEM, "Can't extract");
-                       return (NULL);
-               }
-               archive_write_disk_set_standard_lookup(a->extract->ad);
-               a->cleanup_archive_extract = archive_read_extract_cleanup;
        }
        return (a->extract);
 }
@@ -83,13 +68,26 @@ get_extract(struct archive_read *a)
 int
 archive_read_extract(struct archive *_a, struct archive_entry *entry, int flags)
 {
-       struct extract *extract;
+       struct archive_read_extract *extract;
+       struct archive_read * a = (struct archive_read *)_a;
 
-       extract = get_extract((struct archive_read *)_a);
+       extract = __archive_read_get_extract(a);
        if (extract == NULL)
                return (ARCHIVE_FATAL);
+
+       /* If we haven't initialized the archive_write_disk object, do it now. */
+       if (extract->ad == NULL) {
+               extract->ad = archive_write_disk_new();
+               if (extract->ad == NULL) {
+                       archive_set_error(&a->archive, ENOMEM, "Can't extract");
+                       return (ARCHIVE_FATAL);
+               }
+               archive_write_disk_set_standard_lookup(extract->ad);
+               a->cleanup_archive_extract = archive_read_extract_cleanup;
+       }
+
        archive_write_disk_set_options(extract->ad, flags);
-       return (archive_read_extract2(_a, entry, extract->ad));
+       return (archive_read_extract2(&a->archive, entry, extract->ad));
 }
 
 int
@@ -129,7 +127,7 @@ archive_read_extract_set_progress_callback(struct archive *_a,
     void (*progress_func)(void *), void *user_data)
 {
        struct archive_read *a = (struct archive_read *)_a;
-       struct extract *extract = get_extract(a);
+       struct archive_read_extract *extract = __archive_read_get_extract(a);
        if (extract != NULL) {
                extract->extract_progress = progress_func;
                extract->extract_progress_user_data = user_data;
@@ -141,11 +139,11 @@ copy_data(struct archive *ar, struct archive *aw)
 {
        int64_t offset;
        const void *buff;
-       struct extract *extract;
+       struct archive_read_extract *extract;
        size_t size;
        int r;
 
-       extract = get_extract((struct archive_read *)ar);
+       extract = __archive_read_get_extract((struct archive_read *)ar);
        if (extract == NULL)
                return (ARCHIVE_FATAL);
        for (;;) {
index 6636a596879469dcfbf708c1593ed3bed5c28ecd..27e203b7fbb152b6d3c9b400997ed0860c158878 100644 (file)
@@ -142,6 +142,14 @@ struct archive_read_client {
        struct archive_read_data_node *dataset;
 };
 
+struct archive_read_extract {
+       struct archive *ad; /* archive_write_disk object */
+
+       /* Progress function invoked during extract. */
+       void                    (*extract_progress)(void *);
+       void                     *extract_progress_user_data;
+};
+
 struct archive_read {
        struct archive  archive;
 
@@ -215,7 +223,7 @@ struct archive_read {
        /*
         * Various information needed by archive_extract.
         */
-       struct extract           *extract;
+       struct archive_read_extract             *extract;
        int                     (*cleanup_archive_extract)(struct archive_read *);
 };
 
@@ -245,4 +253,5 @@ int64_t     __archive_read_filter_consume(struct archive_read_filter *, int64_t);
 int __archive_read_program(struct archive_read_filter *, const char *);
 void __archive_read_free_filters(struct archive_read *);
 int  __archive_read_close_filters(struct archive_read *);
+struct archive_read_extract *__archive_read_get_extract(struct archive_read *);
 #endif