]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Use archive_entry_XXX() functions more heavily.
authorTim Kientzle <kientzle@gmail.com>
Fri, 17 Jul 2009 06:31:13 +0000 (02:31 -0400)
committerTim Kientzle <kientzle@gmail.com>
Fri, 17 Jul 2009 06:31:13 +0000 (02:31 -0400)
This removes the need for major()/minor() and
reduces the use of struct stat in the client code.

SVN-Revision: 1233

tar/read.c

index 960ad4f025169698df2bea10cc42e6210611bab9..16709a3f767ffc8c7a08f17f5dd000a64b86dcd6 100644 (file)
@@ -29,11 +29,6 @@ __FBSDID("$FreeBSD: src/usr.bin/tar/read.c,v 1.40 2008/08/21 06:41:14 kientzle E
 #ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
-#ifdef MAJOR_IN_MKDEV
-#include <sys/mkdev.h>
-#elif defined(MAJOR_IN_SYSMACROS)
-#include <sys/sysmacros.h>
-#endif
 #ifdef HAVE_SYS_PARAM_H
 #include <sys/param.h>
 #endif
@@ -348,7 +343,6 @@ read_archive(struct bsdtar *bsdtar, char mode)
 static void
 list_item_verbose(struct bsdtar *bsdtar, FILE *out, struct archive_entry *entry)
 {
-       const struct stat       *st;
        char                     tmp[100];
        size_t                   w;
        const char              *p;
@@ -356,8 +350,6 @@ list_item_verbose(struct bsdtar *bsdtar, FILE *out, struct archive_entry *entry)
        time_t                   tim;
        static time_t            now;
 
-       st = archive_entry_stat(entry);
-
        /*
         * We avoid collecting the entire list in memory at once by
         * listing things as we see them.  However, that also means we can't
@@ -373,12 +365,13 @@ list_item_verbose(struct bsdtar *bsdtar, FILE *out, struct archive_entry *entry)
                time(&now);
        fprintf(out, "%s %d ",
            archive_entry_strmode(entry),
-           (int)(st->st_nlink));
+           archive_entry_nlink(entry));
 
        /* Use uname if it's present, else uid. */
        p = archive_entry_uname(entry);
        if ((p == NULL) || (*p == '\0')) {
-               sprintf(tmp, "%lu ", (unsigned long)st->st_uid);
+               sprintf(tmp, "%lu ",
+                   (unsigned long)archive_entry_uid(entry));
                p = tmp;
        }
        w = strlen(p);
@@ -392,7 +385,8 @@ list_item_verbose(struct bsdtar *bsdtar, FILE *out, struct archive_entry *entry)
                fprintf(out, "%s", p);
                w = strlen(p);
        } else {
-               sprintf(tmp, "%lu", (unsigned long)st->st_gid);
+               sprintf(tmp, "%lu",
+                   (unsigned long)archive_entry_gid(entry));
                w = strlen(tmp);
                fprintf(out, "%s", tmp);
        }
@@ -405,8 +399,8 @@ list_item_verbose(struct bsdtar *bsdtar, FILE *out, struct archive_entry *entry)
        if (archive_entry_filetype(entry) == AE_IFCHR
            || archive_entry_filetype(entry) == AE_IFBLK) {
                sprintf(tmp, "%lu,%lu",
-                   (unsigned long)major(st->st_rdev),
-                   (unsigned long)minor(st->st_rdev)); /* ls(1) also casts here. */
+                   (unsigned long)archive_entry_rdevmajor(entry),
+                   (unsigned long)archive_entry_rdevminor(entry));
        } else {
                /*
                 * Note the use of platform-dependent macros to format
@@ -414,14 +408,14 @@ list_item_verbose(struct bsdtar *bsdtar, FILE *out, struct archive_entry *entry)
                 * corresponding type for the cast.
                 */
                sprintf(tmp, BSDTAR_FILESIZE_PRINTF,
-                   (BSDTAR_FILESIZE_TYPE)st->st_size);
+                   (BSDTAR_FILESIZE_TYPE)archive_entry_size(entry));
        }
        if (w + strlen(tmp) >= bsdtar->gs_width)
                bsdtar->gs_width = w+strlen(tmp)+1;
        fprintf(out, "%*s", (int)(bsdtar->gs_width - w), tmp);
 
        /* Format the time using 'ls -l' conventions. */
-       tim = (time_t)st->st_mtime;
+       tim = archive_entry_mtime(entry);
 #if defined(_WIN32) && !defined(__CYGWIN__)
        /* Windows' strftime function does not support %e format. */
        if (abs(tim - now) > (365/2)*86400)