From 4865f22f17e125b17ab6a73451ba9fbde1fec74a Mon Sep 17 00:00:00 2001 From: des Date: Mon, 28 May 2012 21:25:19 +0000 Subject: [PATCH] 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 git-svn-id: svn://svn.freebsd.org/base/stable/8@236201 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- usr.bin/unzip/unzip.1 | 7 +++++-- usr.bin/unzip/unzip.c | 14 +++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/usr.bin/unzip/unzip.1 b/usr.bin/unzip/unzip.1 index 86b0fa3a2..04ecd2339 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 bdc32fbce..f3c6f9723 100644 --- a/usr.bin/unzip/unzip.c +++ b/usr.bin/unzip/unzip.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2009 Joerg Sonnenberger - * 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) { -- 2.45.0