summaryrefslogtreecommitdiff
path: root/usr.bin/unzip
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>2012-05-29 09:11:19 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>2012-05-29 09:11:19 +0000
commit5fca4d10aa2d4c787f14c7a097cb351019539be6 (patch)
treea644643a8304eff81b00ad114c08d36bb9a67104 /usr.bin/unzip
parente3b56b660467696d128c3059fe7b0c0e8fbe78d9 (diff)
downloadsrc-test-5fca4d10aa2d4c787f14c7a097cb351019539be6.tar.gz
src-test-5fca4d10aa2d4c787f14c7a097cb351019539be6.zip
Pass a filename, rather than a file descriptor, to libarchive.
Submitted by: Alex Kozlov <spam@rm-rf.kiev.ua> MFC after: 1 week
Notes
Notes: svn path=/head/; revision=236226
Diffstat (limited to 'usr.bin/unzip')
-rw-r--r--usr.bin/unzip/unzip.c15
1 files changed, 5 insertions, 10 deletions
diff --git a/usr.bin/unzip/unzip.c b/usr.bin/unzip/unzip.c
index f3c6f9723bd0a..c43c72a5f0893 100644
--- a/usr.bin/unzip/unzip.c
+++ b/usr.bin/unzip/unzip.c
@@ -865,19 +865,14 @@ unzip(const char *fn)
{
struct archive *a;
struct archive_entry *e;
- int fd, ret;
+ int ret;
uintmax_t total_size, file_count, error_count;
- if (strcmp(fn, "-") == 0)
- fd = STDIN_FILENO;
- else if ((fd = open(fn, O_RDONLY)) < 0)
- error("%s", fn);
-
if ((a = archive_read_new()) == NULL)
error("archive_read_new failed");
ac(archive_read_support_format_zip(a));
- ac(archive_read_open_fd(a, fd, 8192));
+ ac(archive_read_open_filename(a, fn, 8192));
if (!zipinfo_mode) {
if (!p_opt && !q_opt)
@@ -933,9 +928,6 @@ unzip(const char *fn)
ac(archive_read_close(a));
(void)archive_read_finish(a);
- if (fd != STDIN_FILENO && close(fd) != 0)
- error("%s", fn);
-
if (t_opt) {
if (error_count > 0) {
errorx("%d checksum error(s) found.", error_count);
@@ -1061,6 +1053,9 @@ main(int argc, char *argv[])
usage();
zipfile = argv[nopts++];
+ if (strcmp(zipfile, "-") == 0)
+ zipfile = NULL; /* STDIN */
+
while (nopts < argc && *argv[nopts] != '-')
add_pattern(&include, argv[nopts++]);