From: Christos Zoulas Date: Mon, 8 Feb 2016 01:29:49 +0000 (+0000) Subject: PR/514: David Macek: Don't fail to handle uncompress when stdin is closed X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3c519de11ab161c3573c252999f072ae79d9ae67;p=file PR/514: David Macek: Don't fail to handle uncompress when stdin is closed and 0 holds the descriptor to the input file. --- diff --git a/src/compress.c b/src/compress.c index 783ba006..a774b16e 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.91 2015/11/13 15:42:18 christos Exp $") +FILE_RCSID("@(#)$File: compress.c,v 1.92 2016/02/08 01:29:49 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);