summaryrefslogtreecommitdiffstats
path: root/patches/0009-Minor-cleanups-in-do_ed_script.patch
blob: 57cec52329a3f4c2330e3ed2afdd77937e442e60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
From 2a32bf09f5e9572da4be183bb0dbde8164351474 Mon Sep 17 00:00:00 2001
From: Andreas Gruenbacher <agruen@gnu.org>
Date: Fri, 6 Apr 2018 20:32:46 +0200
Subject: [PATCH 09/17] Minor cleanups in do_ed_script

* src/pch.c (do_ed_script): Minor cleanups.
---
 src/pch.c | 57 +++++++++++++++++++++++++++------------------------------
 1 file changed, 27 insertions(+), 30 deletions(-)

diff --git a/src/pch.c b/src/pch.c
index 1f14624..1055542 100644
--- a/src/pch.c
+++ b/src/pch.c
@@ -2396,6 +2396,10 @@ do_ed_script (char const *inname, char const *outname,
     char const *tmpname;
     int tmpfd;
     pid_t pid;
+    int exclusive = *outname_needs_removal ? 0 : O_EXCL;
+    char const **ed_argv;
+    int stdin_dup, status;
+
 
     if (! dry_run && ! skip_rest_of_patch)
       {
@@ -2443,7 +2447,7 @@ do_ed_script (char const *inname, char const *outname,
 	    break;
 	}
     }
-    if (!tmpfp)
+    if (dry_run || skip_rest_of_patch)
       return;
     if (fwrite ("w\nq\n", sizeof (char), (size_t) 4, tmpfp) == 0
 	|| fflush (tmpfp) != 0)
@@ -2452,36 +2456,29 @@ do_ed_script (char const *inname, char const *outname,
     if (lseek (tmpfd, 0, SEEK_SET) == -1)
       pfatal ("Can't rewind to the beginning of file %s", quotearg (tmpname));
 
-    if (! dry_run && ! skip_rest_of_patch) {
-	int exclusive = *outname_needs_removal ? 0 : O_EXCL;
-	char const **ed_argv;
-	int stdin_dup, status;
-
+    if (inerrno != ENOENT)
+      {
 	*outname_needs_removal = true;
-	if (inerrno != ENOENT)
-	  {
-	    *outname_needs_removal = true;
-	    copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
-	  }
-	fflush (stdout);
-
-	if ((stdin_dup = dup (0)) == -1
-	    || dup2 (tmpfd, 0) == -1)
-	  pfatal ("Failed to duplicate standard input");
-	assert (outname[0] != '!' && outname[0] != '-');
-	ed_argv = alloca (4 * sizeof * ed_argv);
-	ed_argv[0] = editor_program;
-	ed_argv[1] = "-";
-	ed_argv[2] = outname;
-	ed_argv[3] = (char  *) NULL;
-	status = execute (editor_program, editor_program, (char **)ed_argv,
-			  false, false, false, false, true, false, NULL);
-	if (status)
-	  fatal ("%s FAILED", editor_program);
-	if (dup2 (stdin_dup, 0) == -1
-	    || close (stdin_dup) == -1)
-	  pfatal ("Failed to duplicate standard input");
-    }
+	copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
+      }
+    fflush (stdout);
+
+    if ((stdin_dup = dup (0)) == -1
+	|| dup2 (tmpfd, 0) == -1)
+      pfatal ("Failed to duplicate standard input");
+    assert (outname[0] != '!' && outname[0] != '-');
+    ed_argv = alloca (4 * sizeof * ed_argv);
+    ed_argv[0] = editor_program;
+    ed_argv[1] = "-";
+    ed_argv[2] = outname;
+    ed_argv[3] = (char  *) NULL;
+    status = execute (editor_program, editor_program, (char **)ed_argv,
+		      false, false, false, false, true, false, NULL);
+    if (status)
+      fatal ("%s FAILED", editor_program);
+    if (dup2 (stdin_dup, 0) == -1
+	|| close (stdin_dup) == -1)
+      pfatal ("Failed to duplicate standard input");
 
     fclose (tmpfp);
     safe_unlink (tmpname);
-- 
2.11.0