Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 21 Oct 2010 17:05:15 +0000 (UTC)
From:      Gleb Smirnoff <glebius@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r214137 - head/usr.bin/unzip
Message-ID:  <201010211705.o9LH5GH5097260@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: glebius
Date: Thu Oct 21 17:05:15 2010
New Revision: 214137
URL: http://svn.freebsd.org/changeset/base/214137

Log:
  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.

Modified:
  head/usr.bin/unzip/unzip.c

Modified: head/usr.bin/unzip/unzip.c
==============================================================================
--- head/usr.bin/unzip/unzip.c	Thu Oct 21 16:20:48 2010	(r214136)
+++ head/usr.bin/unzip/unzip.c	Thu Oct 21 17:05:15 2010	(r214137)
@@ -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) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201010211705.o9LH5GH5097260>