summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gruenbacher <agruen@suse.de>2010-05-07 17:32:12 +0200
committerAndreas Gruenbacher <agruen@suse.de>2010-09-17 01:33:45 +0200
commit0eef74e98122c0fdc29769d1179bba4520231239 (patch)
tree6eb0459ce0ff5c15e76b86bbba438b149647fb88
parent206e87000c812d924e833e2657fbb8314793c680 (diff)
downloadpatch-0eef74e98122c0fdc29769d1179bba4520231239.tar.gz
do_ed_script(): Pass in the filenames to use
* src/pch.c (do_ed_script): Add inname, outname, and outname_needs_removal arguments. This isolates TMPOUTNAME and TMPOUTNAME_needs_removal to patch.c. * src/patch.c (main): Update do_ed_script() call.
-rw-r--r--ChangeLog5
-rw-r--r--src/patch.c3
-rw-r--r--src/pch.c18
-rw-r--r--src/pch.h2
4 files changed, 18 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 248e7d8..db28f50 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,11 @@
* src/patch.c (open_outfile): New function.
(init_output): Split into open_outfile() and the rest.
+ * src/pch.c (do_ed_script): Add inname, outname, and
+ outname_needs_removal arguments. This isolates TMPOUTNAME and
+ TMPOUTNAME_needs_removal to patch.c.
+ * src/patch.c (main): Update do_ed_script() call.
+
2010-07-27 Tim Waugh <twaugh@redhat.com>
* src/patch.c: Stops "patch --get 1" from segfaulting.
diff --git a/src/patch.c b/src/patch.c
index 4ffb17f..4f9562d 100644
--- a/src/patch.c
+++ b/src/patch.c
@@ -229,7 +229,8 @@ main (int argc, char **argv)
if (diff_type == ED_DIFF) {
outstate.zero_output = false;
somefailed |= skip_rest_of_patch;
- do_ed_script (outstate.ofp);
+ do_ed_script (inname, TMPOUTNAME, &TMPOUTNAME_needs_removal,
+ outstate.ofp);
if (! dry_run && ! outfile && ! skip_rest_of_patch)
{
struct stat statbuf;
diff --git a/src/pch.c b/src/pch.c
index 6a4941e..a87f9cd 100644
--- a/src/pch.c
+++ b/src/pch.c
@@ -2280,7 +2280,8 @@ get_ed_command_letter (char const *line)
/* Apply an ed script by feeding ed itself. */
void
-do_ed_script (FILE *ofp)
+do_ed_script (char const *inname, char const *outname,
+ int *outname_needs_removal, FILE *ofp)
{
static char const editor_program[] = EDITOR_PROGRAM;
@@ -2289,12 +2290,13 @@ do_ed_script (FILE *ofp)
size_t chars_read;
if (! dry_run && ! skip_rest_of_patch) {
- int exclusive = TMPOUTNAME_needs_removal ? 0 : O_EXCL;
+ int exclusive = *outname_needs_removal ? 0 : O_EXCL;
assert (! inerrno);
- TMPOUTNAME_needs_removal = 1;
- copy_file (inname, TMPOUTNAME, 0, exclusive, instat.st_mode, true);
- sprintf (buf, "%s %s%s", editor_program, verbosity == VERBOSE ? "" : "- ",
- TMPOUTNAME);
+ *outname_needs_removal = 1;
+ copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
+ sprintf (buf, "%s %s%s", editor_program,
+ verbosity == VERBOSE ? "" : "- ",
+ outname);
fflush (stdout);
pipefp = popen(buf, binary_transput ? "wb" : "w");
if (!pipefp)
@@ -2340,10 +2342,10 @@ do_ed_script (FILE *ofp)
if (ofp)
{
- FILE *ifp = fopen (TMPOUTNAME, binary_transput ? "rb" : "r");
+ FILE *ifp = fopen (outname, binary_transput ? "rb" : "r");
int c;
if (!ifp)
- pfatal ("can't open `%s'", TMPOUTNAME);
+ pfatal ("can't open `%s'", outname);
while ((c = getc (ifp)) != EOF)
if (putc (c, ofp) == EOF)
write_fatal ();
diff --git a/src/pch.h b/src/pch.h
index 6c9c899..74f766c 100644
--- a/src/pch.h
+++ b/src/pch.h
@@ -42,7 +42,7 @@ size_t pch_line_len (lin);
const char *pch_name(enum nametype);
bool pch_copy (void);
bool pch_rename (void);
-void do_ed_script (FILE *);
+void do_ed_script (char const *, char const *, int *, FILE *);
void open_patch_file (char const *);
void re_patch (void);
void set_hunkmax (void);