]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Split archive_read_extract2 from archive_read_extract 71/head
authorPaul Barker <paul@paulbarker.me.uk>
Sun, 6 Apr 2014 14:48:24 +0000 (15:48 +0100)
committerPaul Barker <paul@paulbarker.me.uk>
Sun, 6 Apr 2014 14:48:24 +0000 (15:48 +0100)
The function archive_read_extract requires a call to
archive_write_disk_set_standard_lookup but the functions archive_read_extract2
and archive_read_extract_set_progress_callback do not. Therefore, the latter
pair of functions, the internal function __archive_read_get_extract and the
static function copy_data are moved out of archive_read_extract.c into the new
file archive_read_extract2.c.

This ensures that when statically linking, the standard user and group lookup
functions will not be linked into a program unless they are really needed.

Signed-off-by: Paul Barker <paul@paulbarker.me.uk>
Makefile.am
libarchive/archive_read_extract.c
libarchive/archive_read_extract2.c [new file with mode: 0644]

index 63a1d098fff975678099b6c69bc05196c6b699fc..3584bfe6e448bc9fd4f575563fc63dd3bd1f8898 100644 (file)
@@ -129,6 +129,7 @@ libarchive_la_SOURCES= \
        libarchive/archive_read_disk_private.h \
        libarchive/archive_read_disk_set_standard_lookup.c \
        libarchive/archive_read_extract.c \
+       libarchive/archive_read_extract2.c \
        libarchive/archive_read_open_fd.c \
        libarchive/archive_read_open_file.c \
        libarchive/archive_read_open_filename.c \
index 6558b683a31bb843b0d9119b93a6deeea0b5d58e..ce76a6cadf8b54be704ec5a3fccc0421ff7f8c07 100644 (file)
 #include "archive_platform.h"
 __FBSDID("$FreeBSD: src/lib/libarchive/archive_read_extract.c,v 1.61 2008/05/26 17:00:22 kientzle Exp $");
 
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
 #ifdef HAVE_ERRNO_H
 #include <errno.h>
 #endif
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
 
 #include "archive.h"
 #include "archive_entry.h"
 #include "archive_private.h"
 #include "archive_read_private.h"
-#include "archive_write_disk_private.h"
 
 static int     archive_read_extract_cleanup(struct archive_read *);
-static int     copy_data(struct archive *ar, struct archive *aw);
-
-/* 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 (a->extract == NULL) {
-               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));
-       }
-       return (a->extract);
-}
 
 int
 archive_read_extract(struct archive *_a, struct archive_entry *entry, int flags)
@@ -90,82 +62,6 @@ archive_read_extract(struct archive *_a, struct archive_entry *entry, int flags)
        return (archive_read_extract2(&a->archive, entry, extract->ad));
 }
 
-int
-archive_read_extract2(struct archive *_a, struct archive_entry *entry,
-    struct archive *ad)
-{
-       struct archive_read *a = (struct archive_read *)_a;
-       int r, r2;
-
-       /* Set up for this particular entry. */
-       if (a->skip_file_set)
-               archive_write_disk_set_skip_file(ad,
-                   a->skip_file_dev, a->skip_file_ino);
-       r = archive_write_header(ad, entry);
-       if (r < ARCHIVE_WARN)
-               r = ARCHIVE_WARN;
-       if (r != ARCHIVE_OK)
-               /* If _write_header failed, copy the error. */
-               archive_copy_error(&a->archive, ad);
-       else if (!archive_entry_size_is_set(entry) || archive_entry_size(entry) > 0)
-               /* Otherwise, pour data into the entry. */
-               r = copy_data(_a, ad);
-       r2 = archive_write_finish_entry(ad);
-       if (r2 < ARCHIVE_WARN)
-               r2 = ARCHIVE_WARN;
-       /* Use the first message. */
-       if (r2 != ARCHIVE_OK && r == ARCHIVE_OK)
-               archive_copy_error(&a->archive, ad);
-       /* Use the worst error return. */
-       if (r2 < r)
-               r = r2;
-       return (r);
-}
-
-void
-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 archive_read_extract *extract = __archive_read_get_extract(a);
-       if (extract != NULL) {
-               extract->extract_progress = progress_func;
-               extract->extract_progress_user_data = user_data;
-       }
-}
-
-static int
-copy_data(struct archive *ar, struct archive *aw)
-{
-       int64_t offset;
-       const void *buff;
-       struct archive_read_extract *extract;
-       size_t size;
-       int r;
-
-       extract = __archive_read_get_extract((struct archive_read *)ar);
-       if (extract == NULL)
-               return (ARCHIVE_FATAL);
-       for (;;) {
-               r = archive_read_data_block(ar, &buff, &size, &offset);
-               if (r == ARCHIVE_EOF)
-                       return (ARCHIVE_OK);
-               if (r != ARCHIVE_OK)
-                       return (r);
-               r = (int)archive_write_data_block(aw, buff, size, offset);
-               if (r < ARCHIVE_WARN)
-                       r = ARCHIVE_WARN;
-               if (r != ARCHIVE_OK) {
-                       archive_set_error(ar, archive_errno(aw),
-                           "%s", archive_error_string(aw));
-                       return (r);
-               }
-               if (extract->extract_progress)
-                       (extract->extract_progress)
-                           (extract->extract_progress_user_data);
-       }
-}
-
 /*
  * Cleanup function for archive_extract.
  */
diff --git a/libarchive/archive_read_extract2.c b/libarchive/archive_read_extract2.c
new file mode 100644 (file)
index 0000000..3c65e80
--- /dev/null
@@ -0,0 +1,137 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "archive_platform.h"
+__FBSDID("$FreeBSD: src/lib/libarchive/archive_read_extract.c,v 1.61 2008/05/26 17:00:22 kientzle Exp $");
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include "archive.h"
+#include "archive_entry.h"
+#include "archive_private.h"
+#include "archive_read_private.h"
+
+static int     copy_data(struct archive *ar, struct archive *aw);
+
+/* 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 (a->extract == NULL) {
+               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));
+       }
+       return (a->extract);
+}
+
+int
+archive_read_extract2(struct archive *_a, struct archive_entry *entry,
+    struct archive *ad)
+{
+       struct archive_read *a = (struct archive_read *)_a;
+       int r, r2;
+
+       /* Set up for this particular entry. */
+       if (a->skip_file_set)
+               archive_write_disk_set_skip_file(ad,
+                   a->skip_file_dev, a->skip_file_ino);
+       r = archive_write_header(ad, entry);
+       if (r < ARCHIVE_WARN)
+               r = ARCHIVE_WARN;
+       if (r != ARCHIVE_OK)
+               /* If _write_header failed, copy the error. */
+               archive_copy_error(&a->archive, ad);
+       else if (!archive_entry_size_is_set(entry) || archive_entry_size(entry) > 0)
+               /* Otherwise, pour data into the entry. */
+               r = copy_data(_a, ad);
+       r2 = archive_write_finish_entry(ad);
+       if (r2 < ARCHIVE_WARN)
+               r2 = ARCHIVE_WARN;
+       /* Use the first message. */
+       if (r2 != ARCHIVE_OK && r == ARCHIVE_OK)
+               archive_copy_error(&a->archive, ad);
+       /* Use the worst error return. */
+       if (r2 < r)
+               r = r2;
+       return (r);
+}
+
+void
+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 archive_read_extract *extract = __archive_read_get_extract(a);
+       if (extract != NULL) {
+               extract->extract_progress = progress_func;
+               extract->extract_progress_user_data = user_data;
+       }
+}
+
+static int
+copy_data(struct archive *ar, struct archive *aw)
+{
+       int64_t offset;
+       const void *buff;
+       struct archive_read_extract *extract;
+       size_t size;
+       int r;
+
+       extract = __archive_read_get_extract((struct archive_read *)ar);
+       if (extract == NULL)
+               return (ARCHIVE_FATAL);
+       for (;;) {
+               r = archive_read_data_block(ar, &buff, &size, &offset);
+               if (r == ARCHIVE_EOF)
+                       return (ARCHIVE_OK);
+               if (r != ARCHIVE_OK)
+                       return (r);
+               r = (int)archive_write_data_block(aw, buff, size, offset);
+               if (r < ARCHIVE_WARN)
+                       r = ARCHIVE_WARN;
+               if (r != ARCHIVE_OK) {
+                       archive_set_error(ar, archive_errno(aw),
+                           "%s", archive_error_string(aw));
+                       return (r);
+               }
+               if (extract->extract_progress)
+                       (extract->extract_progress)
+                           (extract->extract_progress_user_data);
+       }
+}