diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/minitar/Makefile | 8 | ||||
| -rw-r--r-- | examples/minitar/minitar.c | 34 | ||||
| -rw-r--r-- | examples/untar.c | 6 |
3 files changed, 34 insertions, 14 deletions
diff --git a/examples/minitar/Makefile b/examples/minitar/Makefile index 1ec4593df66b..e2cc0899fbba 100644 --- a/examples/minitar/Makefile +++ b/examples/minitar/Makefile @@ -8,13 +8,19 @@ CFLAGS= \ -I../../libarchive \ -g +# +# You may need to add additional libraries or link options here +# For example, many Linux systems require -lacl +# +LIBS= -lz -lbz2 + # How to link against libarchive. LIBARCHIVE= ../../libarchive/libarchive.a all: minitar minitar: minitar.o - cc -g -o minitar minitar.o $(LIBARCHIVE) -lz -lbz2 + cc -g -o minitar minitar.o $(LIBARCHIVE) $(LIBS) strip minitar ls -l minitar diff --git a/examples/minitar/minitar.c b/examples/minitar/minitar.c index 0ff6263ebf84..81e5e11c7985 100644 --- a/examples/minitar/minitar.c +++ b/examples/minitar/minitar.c @@ -249,7 +249,7 @@ create(const char *filename, int compress, const char **argv) break; } archive_write_set_format_ustar(a); - if (strcmp(filename, "-") == 0) + if (filename != NULL && strcmp(filename, "-") == 0) filename = NULL; archive_write_open_filename(a, filename); @@ -367,6 +367,7 @@ extract(const char *filename, int do_extract, int flags) exit(r); } for (;;) { + int needcr = 0; r = archive_read_next_header(a, &entry); if (r == ARCHIVE_EOF) break; @@ -377,16 +378,24 @@ extract(const char *filename, int do_extract, int flags) } if (verbose && do_extract) msg("x "); - if (verbose || !do_extract) + if (verbose || !do_extract) { msg(archive_entry_pathname(entry)); + msg(" "); + needcr = 1; + } if (do_extract) { r = archive_write_header(ext, entry); - if (r != ARCHIVE_OK) + if (r != ARCHIVE_OK) { errmsg(archive_error_string(a)); - else - copy_data(a, ext); + needcr = 1; + } + else { + r = copy_data(a, ext); + if (r != ARCHIVE_OK) + needcr = 1; + } } - if (verbose || !do_extract) + if (needcr) msg("\n"); } archive_read_close(a); @@ -400,16 +409,16 @@ copy_data(struct archive *ar, struct archive *aw) int r; const void *buff; size_t size; - off_t offset; + int64_t offset; for (;;) { r = archive_read_data_block(ar, &buff, &size, &offset); - if (r == ARCHIVE_EOF) { - errmsg(archive_error_string(ar)); + if (r == ARCHIVE_EOF) return (ARCHIVE_OK); - } - if (r != ARCHIVE_OK) + if (r != ARCHIVE_OK) { + errmsg(archive_error_string(ar)); return (r); + } r = archive_write_data_block(aw, buff, size, offset); if (r != ARCHIVE_OK) { errmsg(archive_error_string(ar)); @@ -427,6 +436,9 @@ msg(const char *m) static void errmsg(const char *m) { + if (m == NULL) { + m = "Error: No error description provided.\n"; + } write(2, m, strlen(m)); } diff --git a/examples/untar.c b/examples/untar.c index b22d8361a012..dab75d2ede53 100644 --- a/examples/untar.c +++ b/examples/untar.c @@ -53,7 +53,6 @@ */ #include <sys/types.h> -__FBSDID("$FreeBSD$"); #include <sys/stat.h> @@ -191,6 +190,9 @@ extract(const char *filename, int do_extract, int flags) } archive_read_close(a); archive_read_free(a); + + archive_write_close(ext); + archive_write_free(ext); exit(0); } @@ -200,7 +202,7 @@ copy_data(struct archive *ar, struct archive *aw) int r; const void *buff; size_t size; -#if ARCHIVE_VERSION >= 3000000 +#if ARCHIVE_VERSION_NUMBER >= 3000000 int64_t offset; #else off_t offset; |
