[Midnightbsd-cvs] src [7772] trunk/usr.bin/patch: update patch to 2.0-12u11, syncing with freebsd 11

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Sep 3 21:22:34 EDT 2016


Revision: 7772
          http://svnweb.midnightbsd.org/src/?rev=7772
Author:   laffer1
Date:     2016-09-03 21:22:34 -0400 (Sat, 03 Sep 2016)
Log Message:
-----------
update patch to 2.0-12u11, syncing with freebsd 11

Modified Paths:
--------------
    trunk/usr.bin/patch/Makefile
    trunk/usr.bin/patch/backupfile.c
    trunk/usr.bin/patch/backupfile.h
    trunk/usr.bin/patch/common.h
    trunk/usr.bin/patch/inp.c
    trunk/usr.bin/patch/inp.h
    trunk/usr.bin/patch/mkpath.c
    trunk/usr.bin/patch/patch.1
    trunk/usr.bin/patch/patch.c
    trunk/usr.bin/patch/pathnames.h
    trunk/usr.bin/patch/pch.c
    trunk/usr.bin/patch/pch.h
    trunk/usr.bin/patch/util.c
    trunk/usr.bin/patch/util.h

Modified: trunk/usr.bin/patch/Makefile
===================================================================
--- trunk/usr.bin/patch/Makefile	2016-09-03 21:46:31 UTC (rev 7771)
+++ trunk/usr.bin/patch/Makefile	2016-09-04 01:22:34 UTC (rev 7772)
@@ -1,6 +1,6 @@
+# $MidnightBSD$
 #	$OpenBSD: Makefile,v 1.4 2005/05/16 15:22:46 espie Exp $
-# $FreeBSD: stable/10/usr.bin/patch/Makefile 255014 2013-08-29 00:38:24Z pfg $
-# $MidnightBSD$
+# $FreeBSD: stable/11/usr.bin/patch/Makefile 255014 2013-08-29 00:38:24Z pfg $
 
 PROG=	patch
 

Modified: trunk/usr.bin/patch/backupfile.c
===================================================================
--- trunk/usr.bin/patch/backupfile.c	2016-09-03 21:46:31 UTC (rev 7771)
+++ trunk/usr.bin/patch/backupfile.c	2016-09-04 01:22:34 UTC (rev 7772)
@@ -14,7 +14,7 @@
  * David MacKenzie <djm at ai.mit.edu>. Some algorithms adapted from GNU Emacs.
  *
  * $OpenBSD: backupfile.c,v 1.20 2009/10/27 23:59:41 deraadt Exp $
- * $FreeBSD: stable/10/usr.bin/patch/backupfile.c 246091 2013-01-29 20:05:16Z delphij $
+ * $FreeBSD: stable/11/usr.bin/patch/backupfile.c 285772 2015-07-21 22:57:27Z cem $
  */
 
 #include <ctype.h>
@@ -220,11 +220,11 @@
 }
 
 static const char *backup_args[] = {
-	"never", "simple", "nil", "existing", "t", "numbered", 0
+	"none", "never", "simple", "nil", "existing", "t", "numbered", 0
 };
 
 static enum backup_type backup_types[] = {
-	simple, simple, numbered_existing,
+	none, simple, simple, numbered_existing,
 	numbered_existing, numbered, numbered
 };
 

Modified: trunk/usr.bin/patch/backupfile.h
===================================================================
--- trunk/usr.bin/patch/backupfile.h	2016-09-03 21:46:31 UTC (rev 7771)
+++ trunk/usr.bin/patch/backupfile.h	2016-09-04 01:22:34 UTC (rev 7772)
@@ -12,7 +12,7 @@
  * backupfile.h -- declarations for making Emacs style backup file names
  *
  * $OpenBSD: backupfile.h,v 1.6 2003/07/28 18:35:36 otto Exp $
- * $FreeBSD: stable/10/usr.bin/patch/backupfile.h 246091 2013-01-29 20:05:16Z delphij $
+ * $FreeBSD: stable/11/usr.bin/patch/backupfile.h 246091 2013-01-29 20:05:16Z delphij $
  */
 
 /* When to make backup files. */

Modified: trunk/usr.bin/patch/common.h
===================================================================
--- trunk/usr.bin/patch/common.h	2016-09-03 21:46:31 UTC (rev 7771)
+++ trunk/usr.bin/patch/common.h	2016-09-04 01:22:34 UTC (rev 7772)
@@ -25,7 +25,7 @@
  * behaviour
  *
  * $OpenBSD: common.h,v 1.26 2006/03/11 19:41:30 otto Exp $
- * $FreeBSD: stable/10/usr.bin/patch/common.h 285976 2015-07-28 19:58:44Z delphij $
+ * $FreeBSD: stable/11/usr.bin/patch/common.h 286795 2015-08-15 00:42:33Z delphij $
  */
 
 #include <sys/types.h>
@@ -43,12 +43,6 @@
 #define	BUFFERSIZE 4096
 #define	LINENUM_MAX LONG_MAX
 
-#define	SCCSPREFIX "s."
-
-#define	RCSSUFFIX ",v"
-#define	CHECKOUT "/usr/bin/co"
-#define	RCSDIFF "/usr/bin/rcsdiff"
-
 #define	ORIGEXT ".orig"
 #define	REJEXT ".rej"
 

Modified: trunk/usr.bin/patch/inp.c
===================================================================
--- trunk/usr.bin/patch/inp.c	2016-09-03 21:46:31 UTC (rev 7771)
+++ trunk/usr.bin/patch/inp.c	2016-09-04 01:22:34 UTC (rev 7772)
@@ -25,7 +25,7 @@
  * behaviour
  *
  * $OpenBSD: inp.c,v 1.36 2012/04/10 14:46:34 ajacoutot Exp $
- * $FreeBSD: stable/10/usr.bin/patch/inp.c 285976 2015-07-28 19:58:44Z delphij $
+ * $FreeBSD: stable/11/usr.bin/patch/inp.c 286795 2015-08-15 00:42:33Z delphij $
  */
 
 #include <sys/types.h>
@@ -37,8 +37,10 @@
 #include <ctype.h>
 #include <errno.h>
 #include <libgen.h>
-#include <limits.h>
+#include <paths.h>
+#include <spawn.h>
 #include <stddef.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -60,8 +62,9 @@
 static int	tifd = -1;	/* plan b virtual string array */
 static char	*tibuf[2];	/* plan b buffers */
 static LINENUM	tiline[2] = {-1, -1};	/* 1st line in each buffer */
-static LINENUM	lines_per_buf;	/* how many lines per buffer */
-static int	tireclen;	/* length of records in tmp file */
+static size_t	lines_per_buf;	/* how many lines per buffer */
+static size_t	tibuflen;	/* plan b buffer length */
+static size_t	tireclen;	/* length of records in tmp file */
 
 static bool	rev_in_string(const char *);
 static bool	reallocate_lines(size_t *);
@@ -135,14 +138,12 @@
 static bool
 plan_a(const char *filename)
 {
-	int		ifd, statfailed, devnull, pstat;
-	char		*p, *s, lbuf[INITLINELEN];
+	int		ifd, statfailed;
+	char		*p, *s;
 	struct stat	filestat;
 	ptrdiff_t	sz;
 	size_t		i;
 	size_t		iline, lines_allocated;
-	pid_t		pid;
-	char		*argp[4] = {NULL};
 
 #ifdef DEBUGGING
 	if (debug & 8)
@@ -168,103 +169,8 @@
 		close(creat(filename, 0666));
 		statfailed = stat(filename, &filestat);
 	}
-	if (statfailed && check_only)
-		fatal("%s not found, -C mode, can't probe further\n", filename);
-	/* For nonexistent or read-only files, look for RCS versions.  */
-
-	if (statfailed ||
-	    /* No one can write to it.  */
-	    (filestat.st_mode & 0222) == 0 ||
-	    /* I can't write to it.  */
-	    ((filestat.st_mode & 0022) == 0 && filestat.st_uid != getuid())) {
-		char	*filebase, *filedir;
-		struct stat	cstat;
-		char *tmp_filename1, *tmp_filename2;
-
-		tmp_filename1 = strdup(filename);
-		tmp_filename2 = strdup(filename);
-		if (tmp_filename1 == NULL || tmp_filename2 == NULL)
-			fatal("strdupping filename");
-
-		filebase = basename(tmp_filename1);
-		filedir = dirname(tmp_filename2);
-
-#define try(f, a1, a2, a3) \
-	(snprintf(lbuf, sizeof(lbuf), f, a1, a2, a3), stat(lbuf, &cstat) == 0)
-
-		/*
-		 * else we can't write to it but it's not under a version
-		 * control system, so just proceed.
-		 */
-		if (try("%s/RCS/%s%s", filedir, filebase, RCSSUFFIX) ||
-		    try("%s/RCS/%s%s", filedir, filebase, "") ||
-		    try("%s/%s%s", filedir, filebase, RCSSUFFIX)) {
-			if (!statfailed) {
-				if ((filestat.st_mode & 0222) != 0)
-					/* The owner can write to it.  */
-					fatal("file %s seems to be locked "
-					    "by somebody else under RCS\n",
-					    filename);
-				/*
-				 * It might be checked out unlocked.  See if
-				 * it's safe to check out the default version
-				 * locked.
-				 */
-				if (verbose)
-					say("Comparing file %s to default "
-					    "RCS version...\n", filename);
-
-				switch (pid = fork()) {
-				case -1:
-					fatal("can't fork: %s\n",
-					    strerror(errno));
-				case 0:
-					devnull = open("/dev/null", O_RDONLY);
-					if (devnull == -1) {
-						fatal("can't open /dev/null: %s",
-						    strerror(errno));
-					}
-					(void)dup2(devnull, STDOUT_FILENO);
-					argp[0] = strdup(RCSDIFF);
-					argp[1] = strdup(filename);
-					execv(RCSDIFF, argp);
-					exit(127);
-				}
-				pid = waitpid(pid, &pstat, 0);
-				if (pid == -1 || WEXITSTATUS(pstat) != 0) {
-					fatal("can't check out file %s: "
-					    "differs from default RCS version\n",
-					    filename);
-				}
-			}
-
-			if (verbose)
-				say("Checking out file %s from RCS...\n",
-				    filename);
-
-			switch (pid = fork()) {
-			case -1:
-				fatal("can't fork: %s\n", strerror(errno));
-			case 0:
-				argp[0] = strdup(CHECKOUT);
-				argp[1] = strdup("-l");
-				argp[2] = strdup(filename);
-				execv(CHECKOUT, argp);
-				exit(127);
-			}
-			pid = waitpid(pid, &pstat, 0);
-			if (pid == -1 || WEXITSTATUS(pstat) != 0 ||
-			    stat(filename, &filestat)) {
-				fatal("can't check out file %s from RCS\n",
-				    filename);
-			}
-		} else if (statfailed) {
-			fatal("can't find %s\n", filename);
-		}
-		free(tmp_filename1);
-		free(tmp_filename2);
-	}
-
+	if (statfailed)
+		fatal("can't find %s\n", filename);
 	filemode = filestat.st_mode;
 	if (!S_ISREG(filemode))
 		fatal("%s is not a normal file--can't patch\n", filename);
@@ -346,7 +252,7 @@
 	/* now check for revision, if any */
 
 	if (revision != NULL) {
-		if (!rev_in_string(i_womp)) {
+		if (i_womp == NULL || !rev_in_string(i_womp)) {
 			if (force) {
 				if (verbose)
 					say("Warning: this file doesn't appear "
@@ -376,8 +282,8 @@
 plan_b(const char *filename)
 {
 	FILE	*ifp;
-	size_t	i = 0, j, maxlen = 1;
-	char	*p;
+	size_t	i = 0, j, len, maxlen = 1;
+	char	*lbuf = NULL, *p;
 	bool	found_revision = (revision == NULL);
 
 	using_plan_a = false;
@@ -386,15 +292,28 @@
 	unlink(TMPINNAME);
 	if ((tifd = open(TMPINNAME, O_EXCL | O_CREAT | O_WRONLY, 0666)) < 0)
 		pfatal("can't open file %s", TMPINNAME);
-	while (fgets(buf, buf_size, ifp) != NULL) {
-		if (revision != NULL && !found_revision && rev_in_string(buf))
+	while ((p = fgetln(ifp, &len)) != NULL) {
+		if (p[len - 1] == '\n')
+			p[len - 1] = '\0';
+		else {
+			/* EOF without EOL, copy and add the NUL */
+			if ((lbuf = malloc(len + 1)) == NULL)
+				fatal("out of memory\n");
+			memcpy(lbuf, p, len);
+			lbuf[len] = '\0';
+			p = lbuf;
+
+			last_line_missing_eol = true;
+			len++;
+		}
+		if (revision != NULL && !found_revision && rev_in_string(p))
 			found_revision = true;
-		if ((i = strlen(buf)) > maxlen)
-			maxlen = i;	/* find longest line */
+		if (len > maxlen)
+			maxlen = len;   /* find longest line */
 	}
-	last_line_missing_eol = i > 0 && buf[i - 1] != '\n';
-	if (last_line_missing_eol && maxlen == i)
-		maxlen++;
+	free(lbuf);
+	if (ferror(ifp))
+		pfatal("can't read file %s", filename);
 
 	if (revision != NULL) {
 		if (!found_revision) {
@@ -419,23 +338,26 @@
 			    revision);
 	}
 	fseek(ifp, 0L, SEEK_SET);	/* rewind file */
-	lines_per_buf = BUFFERSIZE / maxlen;
 	tireclen = maxlen;
-	tibuf[0] = malloc(BUFFERSIZE + 1);
+	tibuflen = maxlen > BUFFERSIZE ? maxlen : BUFFERSIZE;
+	lines_per_buf = tibuflen / maxlen;
+	tibuf[0] = malloc(tibuflen + 1);
 	if (tibuf[0] == NULL)
 		fatal("out of memory\n");
-	tibuf[1] = malloc(BUFFERSIZE + 1);
+	tibuf[1] = malloc(tibuflen + 1);
 	if (tibuf[1] == NULL)
 		fatal("out of memory\n");
 	for (i = 1;; i++) {
 		p = tibuf[0] + maxlen * (i % lines_per_buf);
 		if (i % lines_per_buf == 0)	/* new block */
-			if (write(tifd, tibuf[0], BUFFERSIZE) < BUFFERSIZE)
+			if (write(tifd, tibuf[0], tibuflen) !=
+			    (ssize_t) tibuflen)
 				pfatal("can't write temp file");
 		if (fgets(p, maxlen + 1, ifp) == NULL) {
 			input_lines = i - 1;
 			if (i % lines_per_buf != 0)
-				if (write(tifd, tibuf[0], BUFFERSIZE) < BUFFERSIZE)
+				if (write(tifd, tibuf[0], tibuflen) !=
+				    (ssize_t) tibuflen)
 					pfatal("can't write temp file");
 			break;
 		}
@@ -477,10 +399,11 @@
 			tiline[whichbuf] = baseline;
 
 			if (lseek(tifd, (off_t) (baseline / lines_per_buf *
-			    BUFFERSIZE), SEEK_SET) < 0)
+			    tibuflen), SEEK_SET) < 0)
 				pfatal("cannot seek in the temporary input file");
 
-			if (read(tifd, tibuf[whichbuf], BUFFERSIZE) < 0)
+			if (read(tifd, tibuf[whichbuf], tibuflen) !=
+			    (ssize_t) tibuflen)
 				pfatal("error reading tmp file %s", TMPINNAME);
 		}
 		return tibuf[whichbuf] + (tireclen * offline);

Modified: trunk/usr.bin/patch/inp.h
===================================================================
--- trunk/usr.bin/patch/inp.h	2016-09-03 21:46:31 UTC (rev 7771)
+++ trunk/usr.bin/patch/inp.h	2016-09-04 01:22:34 UTC (rev 7772)
@@ -25,7 +25,7 @@
  * behaviour
  *
  * $OpenBSD: inp.h,v 1.8 2003/08/15 08:00:51 otto Exp $
- * $FreeBSD: stable/10/usr.bin/patch/inp.h 246091 2013-01-29 20:05:16Z delphij $
+ * $FreeBSD: stable/11/usr.bin/patch/inp.h 246091 2013-01-29 20:05:16Z delphij $
  */
 
 void		re_input(void);

Modified: trunk/usr.bin/patch/mkpath.c
===================================================================
--- trunk/usr.bin/patch/mkpath.c	2016-09-03 21:46:31 UTC (rev 7771)
+++ trunk/usr.bin/patch/mkpath.c	2016-09-04 01:22:34 UTC (rev 7772)
@@ -28,7 +28,7 @@
  * SUCH DAMAGE.
  *
  * $OpenBSD: mkpath.c,v 1.2 2005/06/20 07:14:06 otto Exp $
- * $FreeBSD: stable/10/usr.bin/patch/mkpath.c 246091 2013-01-29 20:05:16Z delphij $
+ * $FreeBSD: stable/11/usr.bin/patch/mkpath.c 246091 2013-01-29 20:05:16Z delphij $
  */
 
 #include <sys/types.h>

Modified: trunk/usr.bin/patch/patch.1
===================================================================
--- trunk/usr.bin/patch/patch.1	2016-09-03 21:46:31 UTC (rev 7771)
+++ trunk/usr.bin/patch/patch.1	2016-09-04 01:22:34 UTC (rev 7772)
@@ -20,8 +20,8 @@
 .\" SUCH DAMAGE.
 .\"
 .\" $OpenBSD: patch.1,v 1.27 2014/04/15 06:26:54 jmc Exp $
-.\" $FreeBSD: stable/10/usr.bin/patch/patch.1 267747 2014-06-22 20:29:51Z pfg $
-.Dd June 15, 2014
+.\" $FreeBSD: stable/11/usr.bin/patch/patch.1 286795 2015-08-15 00:42:33Z delphij $
+.Dd August 15, 2015
 .Dt PATCH 1
 .Os
 .Sh NAME
@@ -39,7 +39,7 @@
 .Op Fl o Ar out-file
 .Op Fl p Ar strip-count
 .Op Fl r Ar rej-name
-.Op Fl V Cm t | nil | never
+.Op Fl V Cm t | nil | never | none
 .Op Fl x Ar number
 .Op Fl z Ar backup-ext
 .Op Fl Fl posix
@@ -175,7 +175,7 @@
 .Fl Fl input Ar patchfile
 .Xc
 Causes the next argument to be interpreted as the input file name
-(i.e. a patchfile).
+(i.e., a patchfile).
 This option may be specified multiple times.
 .It Fl l , Fl Fl ignore-whitespace
 Causes the pattern matching to be done loosely, in case the tabs and
@@ -245,7 +245,7 @@
 Tells
 .Nm
 that this patch was created with the old and new files swapped.
-(Yes, I'm afraid that does happen occasionally, human nature being what it
+(Yes, I am afraid that does happen occasionally, human nature being what it
 is.)
 .Nm
 will attempt to swap each hunk around before applying it.
@@ -263,7 +263,7 @@
 option set.
 If it cannot, the patch will continue to be applied normally.
 (Note: this method cannot detect a reversed patch if it is a normal diff
-and if the first command is an append (i.e. it should have been a delete)
+and if the first command is an append (i.e., it should have been a delete)
 since appends always succeed, due to the fact that a null context will match
 anywhere.
 Luckily, most patches add or change lines rather than delete them, so most
@@ -296,8 +296,8 @@
 .Nm
 to interpret the patch file as a unified context diff (a unidiff).
 .It Xo
-.Fl V Cm t | nil | never ,
-.Fl Fl version-control Cm t | nil | never
+.Fl V Cm t | nil | never | none ,
+.Fl Fl version-control Cm t | nil | never | none
 .Xc
 Causes the next argument to be interpreted as a method for creating
 backup file names.
@@ -328,6 +328,8 @@
 simple backups of the others.
 .It Cm never , simple
 Always make simple backups.
+.It Cm none
+Do not make backups.
 .El
 .It Fl v , Fl Fl version
 Causes
@@ -385,7 +387,7 @@
 First
 .Nm
 looks for a place where all lines of the context match.
-If no such place is found, and it's a context diff, and the maximum fuzz factor
+If no such place is found, and it is a context diff, and the maximum fuzz factor
 is set to 1 or more, then another scan takes place ignoring the first and last
 line of context.
 If that fails, and the maximum fuzz factor is set to 2 or more,
@@ -481,15 +483,6 @@
 file name, and choose the file name with the fewest path components,
 the shortest basename, and the shortest total file name length (in that order).
 .It
-If no file exists,
-.Nm
-checks for the existence of the files in an SCCS or RCS directory
-(using the appropriate prefix or suffix) using the criteria specified
-above.
-If found,
-.Nm
-will attempt to get or check out the file.
-.It
 If no suitable file was found to patch, the patch file is a context or
 unified diff, and the old file was zero length, the new file name is
 created and used.

Modified: trunk/usr.bin/patch/patch.c
===================================================================
--- trunk/usr.bin/patch/patch.c	2016-09-03 21:46:31 UTC (rev 7771)
+++ trunk/usr.bin/patch/patch.c	2016-09-04 01:22:34 UTC (rev 7772)
@@ -25,7 +25,7 @@
  * behaviour
  *
  * $OpenBSD: patch.c,v 1.54 2014/12/13 10:31:07 tobias Exp $
- * $FreeBSD: stable/10/usr.bin/patch/patch.c 276807 2015-01-08 03:44:54Z pfg $
+ * $FreeBSD: stable/11/usr.bin/patch/patch.c 298531 2016-04-24 04:28:04Z pfg $
  *
  */
 
@@ -110,6 +110,8 @@
 /* true if -R was specified on command line.  */
 static bool	reverse_flag_specified = false;
 
+static bool	Vflag = false;
+
 /* buffer holding the name of the rejected patch file. */
 static char	rejname[NAME_MAX + 1];
 
@@ -202,7 +204,7 @@
 	Argv = argv;
 	get_some_switches();
 
-	if (backup_type == none) {
+	if (!Vflag) {
 		if ((v = getenv("PATCH_VERSION_CONTROL")) == NULL)
 			v = getenv("VERSION_CONTROL");
 		if (v != NULL || !posix)
@@ -596,6 +598,7 @@
 			break;
 		case 'V':
 			backup_type = get_version(optarg);
+			Vflag = true;
 			break;
 #ifdef DEBUGGING
 		case 'x':
@@ -632,8 +635,8 @@
 	fprintf(stderr,
 "usage: patch [-bCcEeflNnRstuv] [-B backup-prefix] [-D symbol] [-d directory]\n"
 "             [-F max-fuzz] [-i patchfile] [-o out-file] [-p strip-count]\n"
-"             [-r rej-name] [-V t | nil | never] [-x number] [-z backup-ext]\n"
-"             [--posix] [origfile [patchfile]]\n"
+"             [-r rej-name] [-V t | nil | never | none] [-x number]\n"
+"             [-z backup-ext] [--posix] [origfile [patchfile]]\n"
 "       patch <patchfile\n");
 	my_exit(EXIT_FAILURE);
 }
@@ -744,7 +747,7 @@
 static void
 rej_line(int ch, LINENUM i)
 {
-	unsigned short len;
+	size_t len;
 	const char *line = pfetch(i);
 
 	len = strnlen(line, USHRT_MAX);

Modified: trunk/usr.bin/patch/pathnames.h
===================================================================
--- trunk/usr.bin/patch/pathnames.h	2016-09-03 21:46:31 UTC (rev 7771)
+++ trunk/usr.bin/patch/pathnames.h	2016-09-04 01:22:34 UTC (rev 7772)
@@ -1,9 +1,10 @@
+/* $MidnightBSD$ */
 /*-
  * Placed in the public domain by Todd C. Miller <Todd.Miller at courtesan.com>
  * on July 29, 2003.
  *
  * $OpenBSD: pathnames.h,v 1.1 2003/07/29 20:10:17 millert Exp $
- * $FreeBSD: stable/10/usr.bin/patch/pathnames.h 286348 2015-08-05 22:05:02Z delphij $
+ * $FreeBSD: stable/11/usr.bin/patch/pathnames.h 286346 2015-08-05 22:04:54Z delphij $
  */
 
 

Modified: trunk/usr.bin/patch/pch.c
===================================================================
--- trunk/usr.bin/patch/pch.c	2016-09-03 21:46:31 UTC (rev 7771)
+++ trunk/usr.bin/patch/pch.c	2016-09-04 01:22:34 UTC (rev 7772)
@@ -1,5 +1,4 @@
 /* $MidnightBSD$ */
-
 /*-
  * Copyright 1986, Larry Wall
  * 
@@ -26,7 +25,7 @@
  * behaviour
  *
  * $OpenBSD: pch.c,v 1.43 2014/11/18 17:03:35 tobias Exp $
- * $FreeBSD: stable/10/usr.bin/patch/pch.c 286348 2015-08-05 22:05:02Z delphij $
+ * $FreeBSD: stable/11/usr.bin/patch/pch.c 298530 2016-04-24 04:08:36Z pfg $
  */
 
 #include <sys/types.h>
@@ -35,6 +34,7 @@
 #include <ctype.h>
 #include <libgen.h>
 #include <limits.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -500,7 +500,7 @@
 	LINENUM	fillcnt;			/* #lines of missing ptrn or repl */
 	LINENUM	fillsrc;			/* index of first line to copy */
 	LINENUM	filldst;			/* index of first missing line */
-	bool	ptrn_spaces_eaten;		/* ptrn was slightly misformed */
+	bool	ptrn_spaces_eaten;		/* ptrn was slightly malformed */
 	bool	repl_could_be_missing;		/* no + or ! lines in this hunk */
 	bool	repl_missing;			/* we are now backtracking */
 	off_t	repl_backtrack_position;	/* file pos of first repl line */
@@ -1143,7 +1143,7 @@
 			say("Not enough memory to swap next hunk!\n");
 #ifdef DEBUGGING
 	if (debug & 2) {
-		int	i;
+		LINENUM	i;
 		char	special;
 
 		for (i = 0; i <= p_end; i++) {
@@ -1151,7 +1151,7 @@
 				special = '^';
 			else
 				special = ' ';
-			fprintf(stderr, "%3d %c %c %s", i, p_char[i],
+			fprintf(stderr, "%3ld %c %c %s", i, p_char[i],
 			    special, p_line[i]);
 			fflush(stderr);
 		}
@@ -1502,18 +1502,9 @@
 	}
 	if (path == NULL && !assume_exists) {
 		/*
-		 * No files found, look for something we can checkout from
-		 * RCS/SCCS dirs.  Same order as above.
+		 * No files found, check to see if the diff could be
+		 * creating a new file.
 		 */
-		for (i = 0; i < MAX_FILE; i++) {
-			if (names[i].path != NULL &&
-			    (path = checked_in(names[i].path)) != NULL)
-				break;
-		}
-		/*
-		 * Still no match?  Check to see if the diff could be creating
-		 * a new file.
-		 */
 		if (path == NULL && ok_to_create_file &&
 		    names[NEW_FILE].path != NULL)
 			path = names[NEW_FILE].path;
@@ -1523,7 +1514,7 @@
 }
 
 static char *
-compare_names(const struct file_name *names, bool assume_exists, int phase)
+compare_names(const struct file_name *names, bool assume_exists)
 {
 	size_t min_components, min_baselen, min_len, tmp;
 	char *best = NULL;
@@ -1540,9 +1531,7 @@
 	min_components = min_baselen = min_len = SIZE_MAX;
 	for (i = INDEX_FILE; i >= OLD_FILE; i--) {
 		path = names[i].path;
-		if (path == NULL ||
-		    (phase == 1 && !names[i].exists && !assume_exists) ||
-		    (phase == 2 && checked_in(path) == NULL))
+		if (path == NULL || (!names[i].exists && !assume_exists))
 			continue;
 		if ((tmp = num_components(path)) > min_components)
 			continue;
@@ -1573,18 +1562,12 @@
 {
 	char *best;
 
-	best = compare_names(names, assume_exists, 1);
-	if (best == NULL) {
-		best = compare_names(names, assume_exists, 2);
-		/*
-		 * Still no match?  Check to see if the diff could be creating
-		 * a new file.
-		 */
-		if (best == NULL && ok_to_create_file &&
-		    names[NEW_FILE].path != NULL)
-			best = names[NEW_FILE].path;
-	}
+	best = compare_names(names, assume_exists);
 
+	/* No match?  Check to see if the diff could be creating a new file. */
+	if (best == NULL && ok_to_create_file)
+		best = names[NEW_FILE].path;
+
 	return best ? xstrdup(best) : NULL;
 }
 

Modified: trunk/usr.bin/patch/pch.h
===================================================================
--- trunk/usr.bin/patch/pch.h	2016-09-03 21:46:31 UTC (rev 7771)
+++ trunk/usr.bin/patch/pch.h	2016-09-04 01:22:34 UTC (rev 7772)
@@ -25,7 +25,7 @@
  * behaviour
  *
  * $OpenBSD: pch.h,v 1.9 2003/10/31 20:20:45 millert Exp $
- * $FreeBSD: stable/10/usr.bin/patch/pch.h 267746 2014-06-22 20:24:17Z pfg $
+ * $FreeBSD: stable/11/usr.bin/patch/pch.h 267490 2014-06-15 03:54:23Z pfg $
  */
 
 #define	OLD_FILE	0

Modified: trunk/usr.bin/patch/util.c
===================================================================
--- trunk/usr.bin/patch/util.c	2016-09-03 21:46:31 UTC (rev 7771)
+++ trunk/usr.bin/patch/util.c	2016-09-04 01:22:34 UTC (rev 7772)
@@ -25,10 +25,9 @@
  * behaviour
  *
  * $OpenBSD: util.c,v 1.35 2010/07/24 01:10:12 ray Exp $
- * $FreeBSD: stable/10/usr.bin/patch/util.c 276807 2015-01-08 03:44:54Z pfg $
+ * $FreeBSD: stable/11/usr.bin/patch/util.c 286795 2015-08-15 00:42:33Z delphij $
  */
 
-#include <sys/param.h>
 #include <sys/stat.h>
 
 #include <ctype.h>
@@ -35,6 +34,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <libgen.h>
+#include <limits.h>
 #include <paths.h>
 #include <signal.h>
 #include <stdarg.h>
@@ -97,7 +97,7 @@
 backup_file(const char *orig)
 {
 	struct stat	filestat;
-	char		bakname[MAXPATHLEN], *s, *simplename;
+	char		bakname[PATH_MAX], *s, *simplename;
 	dev_t		orig_device;
 	ino_t		orig_inode;
 
@@ -400,36 +400,10 @@
 	return name;
 }
 
-/*
- * Takes the name returned by fetchname and looks in RCS/SCCS directories
- * for a checked in version.
- */
-char *
-checked_in(char *file)
-{
-	char		*filebase, *filedir, tmpbuf[MAXPATHLEN];
-	struct stat	filestat;
-
-	filebase = basename(file);
-	filedir = dirname(file);
-
-#define try(f, a1, a2, a3) \
-(snprintf(tmpbuf, sizeof tmpbuf, f, a1, a2, a3), stat(tmpbuf, &filestat) == 0)
-
-	if (try("%s/RCS/%s%s", filedir, filebase, RCSSUFFIX) ||
-	    try("%s/RCS/%s%s", filedir, filebase, "") ||
-	    try("%s/%s%s", filedir, filebase, RCSSUFFIX) ||
-	    try("%s/SCCS/%s%s", filedir, SCCSPREFIX, filebase) ||
-	    try("%s/%s%s", filedir, SCCSPREFIX, filebase))
-		return file;
-
-	return NULL;
-}
-
 void
 version(void)
 {
-	printf("patch 2.0-12u10 MidnightBSD\n");
+	printf("patch 2.0-12u11 MidnightBSD\n");
 	my_exit(EXIT_SUCCESS);
 }
 

Modified: trunk/usr.bin/patch/util.h
===================================================================
--- trunk/usr.bin/patch/util.h	2016-09-03 21:46:31 UTC (rev 7771)
+++ trunk/usr.bin/patch/util.h	2016-09-04 01:22:34 UTC (rev 7772)
@@ -25,11 +25,10 @@
  * behaviour
  *
  * $OpenBSD: util.h,v 1.16 2014/12/13 10:31:07 tobias Exp $
- * $FreeBSD: stable/10/usr.bin/patch/util.h 276807 2015-01-08 03:44:54Z pfg $
+ * $FreeBSD: stable/11/usr.bin/patch/util.h 286795 2015-08-15 00:42:33Z delphij $
  */
 
 char		*fetchname(const char *, bool *, int);
-char		*checked_in(char *);
 int		backup_file(const char *);
 int		move_file(const char *, const char *);
 int		copy_file(const char *, const char *);



More information about the Midnightbsd-cvs mailing list