diff options
Diffstat (limited to 'examples/minitar/minitar.c')
| -rw-r--r-- | examples/minitar/minitar.c | 34 | 
1 files changed, 23 insertions, 11 deletions
| 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));  } | 
