Blame SOURCES/patch-2.7.6-cleanups-in-do_ed_script.patch

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