From c5da382c0baa822606236fe65527c027c1250822 Mon Sep 17 00:00:00 2001 From: Andreas Gruenbacher Date: Sat, 28 Feb 2015 14:00:42 +0100 Subject: Move error reporting out of make_tempfile() * src/util.c (make_tempfile): Remove error reporting here. * src/inp.c (plan_b): Readd error reporting here. * src/patch.c (main): Likewise. * src/pch.c (open_patch_file): Likewise. --- src/inp.c | 2 ++ src/patch.c | 4 ++++ src/pch.c | 5 ++++- src/util.c | 2 -- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/inp.c b/src/inp.c index 4969837..32d0919 100644 --- a/src/inp.c +++ b/src/inp.c @@ -365,6 +365,8 @@ plan_b (char const *filename) { tifd = make_tempfile (&TMPINNAME, 'i', NULL, O_RDWR | O_BINARY, S_IRUSR | S_IWUSR); + if (tifd == -1) + pfatal ("Can't create temporary file %s", TMPINNAME); TMPINNAME_needs_removal = true; } i = 0; diff --git a/src/patch.c b/src/patch.c index 6b41f79..42d0267 100644 --- a/src/patch.c +++ b/src/patch.c @@ -309,6 +309,8 @@ main (int argc, char **argv) outfd = make_tempfile (&TMPOUTNAME, 'o', outname, O_WRONLY | binary_transput, instat.st_mode & S_IRWXUGO); + if (outfd == -1) + pfatal ("Can't create temporary file %s", TMPOUTNAME); TMPOUTNAME_needs_removal = true; if (diff_type == ED_DIFF) { outstate.zero_output = false; @@ -1586,6 +1588,8 @@ init_reject (char const *outname) int fd; fd = make_tempfile (&TMPREJNAME, 'r', outname, O_WRONLY | binary_transput, 0666); + if (fd == -1) + pfatal ("Can't create temporary file %s", TMPREJNAME); TMPREJNAME_needs_removal = true; rejfp = fdopen (fd, binary_transput ? "wb" : "w"); if (! rejfp) diff --git a/src/pch.c b/src/pch.c index 1f12285..9d74471 100644 --- a/src/pch.c +++ b/src/pch.c @@ -138,8 +138,11 @@ open_patch_file (char const *filename) else { size_t charsread; - int fd = make_tempfile (&TMPPATNAME, 'p', NULL, O_RDWR | O_BINARY, 0); + int fd; FILE *read_pfp = pfp; + fd = make_tempfile (&TMPPATNAME, 'p', NULL, O_RDWR | O_BINARY, 0); + if (fd == -1) + pfatal ("Can't create temporary file %s", TMPPATNAME); TMPPATNAME_needs_removal = true; pfp = fdopen (fd, "w+b"); if (! pfp) diff --git a/src/util.c b/src/util.c index 0cbffb4..82a7e37 100644 --- a/src/util.c +++ b/src/util.c @@ -1660,8 +1660,6 @@ make_tempfile (char const **name, char letter, char const *real_name, sprintf (template, "%s/p%cXXXXXX", tmpdir, letter); } fd = try_tempname(template, 0, &args, try_safe_open); - if (fd == -1) - pfatal ("Can't create temporary file %s", template); *name = template; return fd; } -- cgit v1.2.1