tList the content of an archive - pm - barely a pack manager
HTML git clone git://z3bra.org/pm
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
DIR commit 96d5fa5f539e7b9efff7b2e243a652c0ef12a830
HTML Author: z3bra <willyatmailoodotorg>
Date: Fri, 18 Dec 2015 12:48:07 +0100
List the content of an archive
Diffstat:
A makefile | 11 +++++++++++
A pack.c | 45 +++++++++++++++++++++++++++++++
2 files changed, 56 insertions(+), 0 deletions(-)
---
DIR diff --git a/makefile b/makefile
t@@ -0,0 +1,10 @@
+CC = cc
+LD = $(CC)
+
+CFLAGS = -Wall
+LDFLAGS = -larchive
+
+all: pack
+
+clean:
+ rm -f pack
+\ No newline at end of file
DIR diff --git a/pack.c b/pack.c
t@@ -0,0 +1,44 @@
+#include <stdio.h>
+#include <archive.h>
+#include <archive_entry.h>
+
+/*
+ * output the content of an archive
+ */
+int
+pack_list(char *filename)
+{
+ struct archive *a;
+ struct archive_entry *e;
+ int r;
+
+ a = archive_read_new();
+ archive_read_support_filter_all(a);
+ archive_read_support_format_all(a);
+
+ /* set blocksize to 0 as libarchive will choose the best size anyway */
+ r = archive_read_open_filename(a, filename, 0);
+
+ if (r != ARCHIVE_OK)
+ return 1;
+
+ while(archive_read_next_header(a, &e) == ARCHIVE_OK) {
+ puts(archive_entry_pathname(e));
+ }
+
+ r = archive_read_free(a);
+
+ if (r != ARCHIVE_OK)
+ return 1;
+
+ return 0;
+}
+
+int
+main (int argc, char **argv)
+{
+ while (*(++argv))
+ pack_list(*argv);
+
+ return 0;
+}
+\ No newline at end of file