Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 29 May 2012 09:11:19 +0000 (UTC)
From:      Dag-Erling Smorgrav <des@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r236226 - head/usr.bin/unzip
Message-ID:  <201205290911.q4T9BJbK065231@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: des
Date: Tue May 29 09:11:19 2012
New Revision: 236226
URL: http://svn.freebsd.org/changeset/base/236226

Log:
  Pass a filename, rather than a file descriptor, to libarchive.
  
  Submitted by:	Alex Kozlov <spam@rm-rf.kiev.ua>
  MFC after:	1 week

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

Modified: head/usr.bin/unzip/unzip.c
==============================================================================
--- head/usr.bin/unzip/unzip.c	Tue May 29 08:56:56 2012	(r236225)
+++ head/usr.bin/unzip/unzip.c	Tue May 29 09:11:19 2012	(r236226)
@@ -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++]);
 



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