From b76343c9d970e1ae1935c4f629bd4c24dd531b40 Mon Sep 17 00:00:00 2001
From: Rob Landley <rob@landley.net>
Date: Sat, 20 Jan 2018 22:29:25 -0600
Subject: Fix gunzip to past test_gunzip.

---
 toys/pending/gzip.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

(limited to 'toys')

diff --git a/toys/pending/gzip.c b/toys/pending/gzip.c
index 894a2914..72e8fe4c 100644
--- a/toys/pending/gzip.c
+++ b/toys/pending/gzip.c
@@ -102,7 +102,7 @@ static void do_gunzip(int in_fd, char *arg)
   int len, out_fd = 0;
   char *out_name = 0;
 
-  // Are we writing to stderr?
+  // Are we writing to stdout?
   if (!in_fd || (toys.optflags&FLAG_c)) out_fd = 1;
   if (isatty(in_fd)) {
     if (!(toys.optflags&FLAG_f)) {
@@ -118,7 +118,7 @@ static void do_gunzip(int in_fd, char *arg)
       error_msg("no .gz: %s", arg);
       return;
     }
-    if (!stat(arg, &sb)) {
+    if (fstat(in_fd, &sb)) {
       perror_msg("%s", arg);
       return;
     }
@@ -130,9 +130,9 @@ static void do_gunzip(int in_fd, char *arg)
     if (out_fd == -1) return;
   }
 
-  if (CFG_TOYBOX_LIBZ)
+//  if (CFG_TOYBOX_LIBZ)
     if (zlib_inflate(in_fd, out_fd) && out_name) arg = out_name;
-  close(out_fd);
+  if (out_fd != 1) close(out_fd);
 
   if (out_name) {
     fix_time(out_name, &sb);
-- 
cgit v1.2.3