From 0806ef3ea2dece311389233faf4b899ebb0557cc Mon Sep 17 00:00:00 2001 From: glebius Date: Thu, 21 Oct 2010 17:05:15 +0000 Subject: Make it possible to read input from stdin. Without this change I don't see a way to unpack a multivolume archive without wasting disk space for a temporary file. --- usr.bin/unzip/unzip.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'usr.bin/unzip/unzip.c') diff --git a/usr.bin/unzip/unzip.c b/usr.bin/unzip/unzip.c index 87927d2..a3852f7 100644 --- a/usr.bin/unzip/unzip.c +++ b/usr.bin/unzip/unzip.c @@ -859,7 +859,9 @@ unzip(const char *fn) int fd, ret; uintmax_t total_size, file_count, error_count; - if ((fd = open(fn, O_RDONLY)) < 0) + if (strcmp(fn, "-") == 0) + fd = STDIN_FILENO; + else if ((fd = open(fn, O_RDONLY)) < 0) error("%s", fn); if ((a = archive_read_new()) == NULL) @@ -913,7 +915,7 @@ unzip(const char *fn) ac(archive_read_close(a)); (void)archive_read_finish(a); - if (close(fd) != 0) + if (fd != STDIN_FILENO && close(fd) != 0) error("%s", fn); if (t_opt) { -- cgit v1.1