diff --git a/ChangeLog b/ChangeLog index 95e8688..19af831 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,9 @@ * bootstrap.conf: Use the gnulib tempname module. * src/util.c (make_tempfile): New function. + * src/inp.c (plan_b): Compute TMPINNAME with make_tempfile() if needed + instead of precomputing it in src/patch.c (main). + 2010-07-27 Tim Waugh * src/patch.c: Stops "patch --get 1" from segfaulting. diff --git a/src/inp.c b/src/inp.c index fb262f1..8507d09 100644 --- a/src/inp.c +++ b/src/inp.c @@ -353,16 +353,22 @@ plan_b (char const *filename) char const *rev; size_t revlen; lin line = 1; - int exclusive; if (instat.st_size == 0) filename = NULL_DEVICE; if (! (ifp = fopen (filename, binary_transput ? "rb" : "r"))) pfatal ("Can't open file %s", quotearg (filename)); - exclusive = TMPINNAME_needs_removal ? 0 : O_EXCL; - TMPINNAME_needs_removal = 1; - tifd = create_file (TMPINNAME, O_RDWR | O_BINARY | exclusive, (mode_t) 0, - true); + if (TMPINNAME_needs_removal) + { + /* Reopen the existing temporary file. */ + tifd = create_file (TMPINNAME, O_RDWR | O_BINARY, 0, true); + } + else + { + tifd = make_tempfile (&TMPINNAME, 'i', NULL, O_RDWR | O_BINARY, + S_IRUSR | S_IWUSR); + TMPINNAME_needs_removal = 1; + } i = 0; len = 0; maxlen = 1; diff --git a/src/patch.c b/src/patch.c index 4f9562d..8f1a03a 100644 --- a/src/patch.c +++ b/src/patch.c @@ -140,7 +140,6 @@ main (int argc, char **argv) /* Cons up the names of the global temporary files. Do this before `cleanup' can possibly be called (e.g. by `pfatal'). */ TMPOUTNAME = make_temp ('o'); - TMPINNAME = make_temp ('i'); TMPREJNAME = make_temp ('r'); TMPPATNAME = make_temp ('p');