Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 28 May 2012 21:25:19 +0000 (UTC)
From:      Dag-Erling Smorgrav <des@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r236201 - stable/8/usr.bin/unzip
Message-ID:  <201205282125.q4SLPJmN034337@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: des
Date: Mon May 28 21:25:19 2012
New Revision: 236201
URL: http://svn.freebsd.org/changeset/base/236201

Log:
  MFH r208957: check return value from archive_read_new()
  MFH r214137, r214140, r214174, r224584: support reading from stdin
  MFH r230044, r233456: style and markup nits
  MFH r234311: correct name in copyright statement

Modified:
  stable/8/usr.bin/unzip/unzip.1
  stable/8/usr.bin/unzip/unzip.c
Directory Properties:
  stable/8/usr.bin/unzip/   (props changed)

Modified: stable/8/usr.bin/unzip/unzip.1
==============================================================================
--- stable/8/usr.bin/unzip/unzip.1	Mon May 28 21:19:33 2012	(r236200)
+++ stable/8/usr.bin/unzip/unzip.1	Mon May 28 21:25:19 2012	(r236201)
@@ -1,5 +1,5 @@
 .\"-
-.\" Copyright (c) 2007-2008 Dag-Erling Coïdan Smørgrav
+.\" Copyright (c) 2007-2008 Dag-Erling Smørgrav
 .\" All rights reserved.
 .\"
 .\" Redistribution and use in source and binary forms, with or without
@@ -38,7 +38,6 @@
 .Ar zipfile
 .Sh DESCRIPTION
 .\" ...
-.Pp
 The following options are available:
 .Bl -tag -width Fl
 .It Fl a
@@ -121,6 +120,10 @@ Note that only one of
 and
 .Fl u
 may be specified.
+If specified filename is
+.Qq - ,
+then data is read from
+.Va stdin .
 .Sh ENVIRONMENT
 If the
 .Ev UNZIP_DEBUG

Modified: stable/8/usr.bin/unzip/unzip.c
==============================================================================
--- stable/8/usr.bin/unzip/unzip.c	Mon May 28 21:19:33 2012	(r236200)
+++ stable/8/usr.bin/unzip/unzip.c	Mon May 28 21:25:19 2012	(r236201)
@@ -1,6 +1,6 @@
 /*-
  * Copyright (c) 2009 Joerg Sonnenberger <joerg@NetBSD.org>
- * Copyright (c) 2007-2008 Dag-Erling Coïdan Smørgrav
+ * Copyright (c) 2007-2008 Dag-Erling Smørgrav
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -426,7 +426,7 @@ handle_existing_file(char **path)
 		fprintf(stderr,
 		    "replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ",
 		    *path);
-		if (fgets(buf, sizeof(buf), stdin) == 0) {
+		if (fgets(buf, sizeof(buf), stdin) == NULL) {
 			clearerr(stdin);
 			printf("NULL\n(EOF or read error, "
 			    "treating as \"[N]one\"...)\n");
@@ -868,10 +868,14 @@ 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);
 
-	a = archive_read_new();
+	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));
 
@@ -929,7 +933,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?201205282125.q4SLPJmN034337>