From aa07a341e7a4840645641539a1c76185910c1e37 Mon Sep 17 00:00:00 2001 From: Christos Zoulas Date: Mon, 8 Feb 2016 01:29:49 +0000 Subject: [PATCH] PR/514: David Macek: Don't fail to handle uncompress when stdin is closed and 0 holds the descriptor to the input file. --- src/compress.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/compress.c b/src/compress.c index 7f0ef176..bf9897be 100644 --- a/src/compress.c +++ b/src/compress.c @@ -35,7 +35,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: compress.c,v 1.90 2015/11/13 15:35:10 christos Exp $") +FILE_RCSID("@(#)$File: compress.c,v 1.91 2015/11/13 15:42:18 christos Exp $") #endif #include "magic.h" @@ -555,10 +555,11 @@ closep(int *fd) static void copydesc(int i, int *fd) { - (void) close(i); - if (dup(fd[i == STDIN_FILENO ? 0 : 1]) == -1) { - abort(); - DPRINTF("dup[%d] failed (%s)\n", i, strerror(errno)); + int j = fd[i == STDIN_FILENO ? 0 : 1]; + if (j == i) + return; + if (dup2(j, i) == -1) { + DPRINTF("dup(%d, %d) failed (%s)\n", j, i, strerror(errno)); exit(1); } closep(fd); -- 2.40.0