]> granicus.if.org Git - file/commitdiff
PR/514: David Macek: Don't fail to handle uncompress when stdin is closed
authorChristos Zoulas <christos@zoulas.com>
Mon, 8 Feb 2016 01:29:49 +0000 (01:29 +0000)
committerChristos Zoulas <christos@zoulas.com>
Mon, 8 Feb 2016 01:29:49 +0000 (01:29 +0000)
and 0 holds the descriptor to the input file.

src/compress.c

index 783ba00663cc71a164026743e900a123b5a96609..a774b16ecde35c8fb2799457538430aa77228dc4 100644 (file)
@@ -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);