Author: kevans
Date: Fri Mar  1 01:20:21 2019
New Revision: 344677
URL: https://svnweb.freebsd.org/changeset/base/344677

Log:
  patch(1): Exit successfully if we're fed a 0-length patch
  
  This change is made in the name of GNU patch compatibility. If GNU patch is
  fed a zero-length patch, it will exit successfully with no output. This is
  used in at least one port to date (comms/wsjtx), and we break on this usage.
  
  It seems unlikely that anyone relies on patch(1) calling their completely
  empty patch garbage and failing, and GNU compatibility is a plus if it helps
  with porting, so make the switch.
  
  Reported by:  db
  MFC after:    2 weeks

Modified:
  head/usr.bin/patch/common.h
  head/usr.bin/patch/patch.c
  head/usr.bin/patch/pch.c

Modified: head/usr.bin/patch/common.h
==============================================================================
--- head/usr.bin/patch/common.h Fri Mar  1 01:18:39 2019        (r344676)
+++ head/usr.bin/patch/common.h Fri Mar  1 01:20:21 2019        (r344677)
@@ -64,6 +64,7 @@ extern size_t buf_size;       /* size of general purpose buf
 
 extern bool    using_plan_a;   /* try to keep everything in memory */
 extern bool    out_of_mem;     /* ran out of memory in plan a */
+extern bool    nonempty_patchf_seen;   /* seen a non-zero-length patch file? */
 
 #define        MAXFILEC 2
 

Modified: head/usr.bin/patch/patch.c
==============================================================================
--- head/usr.bin/patch/patch.c  Fri Mar  1 01:18:39 2019        (r344676)
+++ head/usr.bin/patch/patch.c  Fri Mar  1 01:20:21 2019        (r344677)
@@ -53,6 +53,7 @@ size_t                buf_size;               /* size of the 
general purpose buff
 
 bool           using_plan_a = true;    /* try to keep everything in memory */
 bool           out_of_mem = false;     /* ran out of memory in plan a */
+bool           nonempty_patchf_seen = false;   /* seen nonempty patch file? */
 
 #define MAXFILEC 2
 
@@ -419,7 +420,7 @@ main(int argc, char *argv[])
                set_signals(1);
        }
 
-       if (!patch_seen)
+       if (!patch_seen && nonempty_patchf_seen)
                error = 2;
 
        my_exit(error);

Modified: head/usr.bin/patch/pch.c
==============================================================================
--- head/usr.bin/patch/pch.c    Fri Mar  1 01:18:39 2019        (r344676)
+++ head/usr.bin/patch/pch.c    Fri Mar  1 01:20:21 2019        (r344677)
@@ -179,6 +179,9 @@ there_is_another_patch(void)
                        say("done\n");
                return false;
        }
+       if (p_filesize == 0)
+               return false;
+       nonempty_patchf_seen = true;
        if (verbose)
                say("Hmm...");
        diff_type = intuit_diff_type();
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to