aboutsummaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>2012-05-28 21:25:19 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>2012-05-28 21:25:19 +0000
commit15142adaed4920765a6c800f3d8f919d6088581d (patch)
treea049729d594e868df10d750f17f77e20a3ca7295 /usr.bin
parenta7abcbab69b7fd2f69aad8ffa07e04da9bfa9f51 (diff)
downloadsrc-15142adaed4920765a6c800f3d8f919d6088581d.tar.gz
src-15142adaed4920765a6c800f3d8f919d6088581d.zip
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
Notes
Notes: svn path=/stable/8/; revision=236201
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/unzip/unzip.17
-rw-r--r--usr.bin/unzip/unzip.c14
2 files changed, 14 insertions, 7 deletions
diff --git a/usr.bin/unzip/unzip.1 b/usr.bin/unzip/unzip.1
index 86b0fa3a22af..04ecd2339c04 100644
--- a/usr.bin/unzip/unzip.1
+++ b/usr.bin/unzip/unzip.1
@@ -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
diff --git a/usr.bin/unzip/unzip.c b/usr.bin/unzip/unzip.c
index bdc32fbce689..f3c6f9723bd0 100644
--- a/usr.bin/unzip/unzip.c
+++ b/usr.bin/unzip/unzip.c
@@ -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) {