diff options
author | Jim Meyering <meyering@redhat.com> | 2011-05-24 16:20:59 +0200 |
---|---|---|
committer | Jim Meyering <meyering@redhat.com> | 2011-05-25 16:47:33 +0200 |
commit | 586239e353e0e4b71f8828f5fda06496229b8874 (patch) | |
tree | 98b8183962c281328c17b7f96ef3a7a5e3069e23 | |
parent | 5853a727de5cd84da483f90cf6f4191549265dae (diff) | |
download | patch-586239e353e0e4b71f8828f5fda06496229b8874.tar.gz |
don't call fdopen with a negative FD upon dup failure
* src/patch.c (open_outfile): If dup fails, don't clobber its
errno value by calling fdopen with -1.
-rw-r--r-- | src/patch.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/patch.c b/src/patch.c index 44b6571..d73aaaf 100644 --- a/src/patch.c +++ b/src/patch.c @@ -1466,9 +1466,12 @@ open_outfile (char const *name) return create_output_file (name, 0); else { + FILE *ofp; int stdout_dup = dup (fileno (stdout)); - FILE *ofp = fdopen (stdout_dup, "a"); - if (stdout_dup == -1 || ! ofp) + if (stdout_dup == -1) + pfatal ("Failed to duplicate standard output"); + ofp = fdopen (stdout_dup, "a"); + if (! ofp) pfatal ("Failed to duplicate standard output"); if (dup2 (fileno (stderr), fileno (stdout)) == -1) pfatal ("Failed to redirect messages to standard error"); |