[Midnightbsd-cvs] src [11545] trunk/usr.bin/find: sync find with freebsd.

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Jul 7 16:40:42 EDT 2018


Revision: 11545
          http://svnweb.midnightbsd.org/src/?rev=11545
Author:   laffer1
Date:     2018-07-07 16:40:42 -0400 (Sat, 07 Jul 2018)
Log Message:
-----------
sync find with freebsd.

Modified Paths:
--------------
    trunk/usr.bin/find/Makefile
    trunk/usr.bin/find/extern.h
    trunk/usr.bin/find/find.1
    trunk/usr.bin/find/find.c
    trunk/usr.bin/find/find.h
    trunk/usr.bin/find/function.c
    trunk/usr.bin/find/getdate.y
    trunk/usr.bin/find/ls.c
    trunk/usr.bin/find/main.c
    trunk/usr.bin/find/misc.c
    trunk/usr.bin/find/option.c

Property Changed:
----------------
    trunk/usr.bin/find/find.1
    trunk/usr.bin/find/getdate.y

Modified: trunk/usr.bin/find/Makefile
===================================================================
--- trunk/usr.bin/find/Makefile	2018-07-07 20:40:15 UTC (rev 11544)
+++ trunk/usr.bin/find/Makefile	2018-07-07 20:40:42 UTC (rev 11545)
@@ -1,5 +1,6 @@
+# $MidnightBSD$
 #	@(#)Makefile	8.1 (Berkeley) 6/6/93
-# $MidnightBSD$
+# $FreeBSD: stable/10/usr.bin/find/Makefile 249657 2013-04-19 19:45:00Z ed $
 
 PROG=	find
 SRCS=	find.c function.c ls.c main.c misc.c operator.c option.c \
@@ -6,4 +7,6 @@
 	getdate.y
 YFLAGS=
 
+NO_WMISSING_VARIABLE_DECLARATIONS=
+
 .include <bsd.prog.mk>

Modified: trunk/usr.bin/find/extern.h
===================================================================
--- trunk/usr.bin/find/extern.h	2018-07-07 20:40:15 UTC (rev 11544)
+++ trunk/usr.bin/find/extern.h	2018-07-07 20:40:42 UTC (rev 11545)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1991, 1993, 1994
  *	The Regents of the University of California.  All rights reserved.
@@ -27,12 +28,12 @@
  * SUCH DAMAGE.
  *
  *	@(#)extern.h	8.3 (Berkeley) 4/16/94
- *	$MidnightBSD$
+ *	$FreeBSD: stable/10/usr.bin/find/extern.h 287266 2015-08-28 20:53:08Z jilles $
  */
 
 #include <sys/cdefs.h>
 
-void	 brace_subst(char *, char **, char *, int);
+void	 brace_subst(char *, char **, char *, size_t);
 PLAN	*find_create(char ***);
 int	 find_execute(PLAN *, char **);
 PLAN	*find_formplan(char **);
@@ -58,6 +59,7 @@
 creat_f	c_follow;
 creat_f	c_fstype;
 creat_f	c_group;
+creat_f	c_ignore_readdir_race;
 creat_f	c_inum;
 creat_f	c_links;
 creat_f	c_ls;
@@ -72,6 +74,7 @@
 creat_f	c_samefile;
 creat_f	c_simple;
 creat_f	c_size;
+creat_f	c_sparse;
 creat_f	c_type;
 creat_f	c_user;
 creat_f	c_xdev;
@@ -108,10 +111,12 @@
 exec_f	f_quit;
 exec_f	f_regex;
 exec_f	f_size;
+exec_f	f_sparse;
 exec_f	f_type;
 exec_f	f_user;
 
-extern int ftsoptions, isdeprecated, isdepth, isoutput, issort, isxargs;
+extern int ftsoptions, ignore_readdir_race, isdeprecated, isdepth, isoutput;
+extern int issort, isxargs;
 extern int mindepth, maxdepth;
 extern int regexp_flags;
 extern time_t now;

Modified: trunk/usr.bin/find/find.1
===================================================================
--- trunk/usr.bin/find/find.1	2018-07-07 20:40:15 UTC (rev 11544)
+++ trunk/usr.bin/find/find.1	2018-07-07 20:40:42 UTC (rev 11545)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\" Copyright (c) 1990, 1993
 .\"	The Regents of the University of California.  All rights reserved.
 .\"
@@ -29,9 +30,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	@(#)find.1	8.7 (Berkeley) 5/9/95
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/usr.bin/find/find.1 316197 2017-03-30 02:00:42Z sevan $
 .\"
-.Dd September 9, 2012
+.Dd January 24, 2017
 .Dt FIND 1
 .Os
 .Sh NAME
@@ -156,7 +157,6 @@
 primary.
 .El
 .Sh PRIMARIES
-.Pp
 All primaries which take a numeric argument allow the number to be
 preceded by a plus sign
 .Pq Dq Li +
@@ -204,12 +204,19 @@
 See
 .Xr acl 3
 for more information.
-.It Ic -amin Ar n
+.It Ic -amin Oo Cm - Ns | Ns Cm + Oc Ns Ar n
 True if the difference between the file last access time and the time
 .Nm
 was started, rounded up to the next full minute, is
+more than
 .Ar n
-minutes.
+.Pq + Ns Ar n ,
+less than
+.Ar n
+.Pq - Ns Ar n ,
+or exactly
+.Ar n
+minutes ago.
 .It Ic -anewer Ar file
 Same as
 .Ic -neweram .
@@ -251,13 +258,20 @@
 or
 .Cm -
 modifier.
-.It Ic -cmin Ar n
+.It Ic -cmin Oo Cm - Ns | Ns Cm + Oc Ns Ar n
 True if the difference between the time of last change of file status
 information and the time
 .Nm
 was started, rounded up to the next full minute, is
+more than
 .Ar n
-minutes.
+.Pq + Ns Ar n ,
+less than
+.Ar n
+.Pq - Ns Ar n ,
+or exactly
+.Ar n
+minutes ago.
 .It Ic -cnewer Ar file
 Same as
 .Ic -newercm .
@@ -299,6 +313,9 @@
 .Dq Pa \&.
 for security reasons.
 Depth-first traversal processing is implied by this option.
+The
+.Ic -delete
+primary will fail to delete a directory if it is not empty.
 Following symlinks is incompatible with this option.
 .It Ic -depth
 Always true;
@@ -468,7 +485,9 @@
 .Ar gname
 is treated as a group ID.
 .It Ic -ignore_readdir_race
-This option is for GNU find compatibility and is ignored.
+Ignore errors because a file or a directory is deleted
+after reading the name from a directory.
+This option does not affect errors occurring on starting points.
 .It Ic -ilname Ar pattern
 Like
 .Ic -lname ,
@@ -502,6 +521,8 @@
 .Ic -name ,
 but the contents of the symbolic link are matched instead of the file
 name.
+Note that this only matches broken symbolic links
+if symbolic links are being followed.
 This is a GNU find extension.
 .It Ic -ls
 This primary always evaluates to true.
@@ -508,7 +529,7 @@
 The following information for the current file is written to standard output:
 its inode number, size in 512-byte blocks, file permissions, number of hard
 links, owner, group, size in bytes, last modification time, and pathname.
-If the file is a block or character special file, the major and minor numbers
+If the file is a block or character special file, the device number
 will be displayed instead of the size in bytes.
 If the file is a symbolic link, the pathname of the linked-to file will be
 displayed preceded by
@@ -536,12 +557,19 @@
 not normally be evaluated.
 .Dq Ic -mindepth Li 1
 processes all but the command line arguments.
-.It Ic -mmin Ar n
+.It Ic -mmin Oo Cm - Ns | Ns Cm + Oc Ns Ar n
 True if the difference between the file last modification time and the time
 .Nm
 was started, rounded up to the next full minute, is
+more than
 .Ar n
-minutes.
+.Pq + Ns Ar n ,
+less than
+.Ar n
+.Pq - Ns Ar n ,
+or exactly
+.Ar n
+minutes ago.
 .It Ic -mnewer Ar file
 Same as
 .Ic -newer .
@@ -616,7 +644,9 @@
 .It Ic -nogroup
 True if the file belongs to an unknown group.
 .It Ic -noignore_readdir_race
-This option is for GNU find compatibility and is ignored.
+Turn off the effect of
+.Ic -ignore_readdir_race .
+This is default behaviour.
 .It Ic -noleaf
 This option is for GNU find compatibility.
 In GNU find it disables an optimization not relevant to
@@ -738,7 +768,7 @@
 .It Ic -quit
 Causes
 .Nm
-to immediately terminate.
+to immediately terminate successfully.
 .It Ic -regex Ar pattern
 True if the whole path of the file matches
 .Ar pattern
@@ -790,6 +820,10 @@
 .It Cm P
 petabytes (1024 terabytes)
 .El
+.It Ic -sparse
+True if the current file is sparse,
+i.e. has fewer blocks allocated than expected based on its size in bytes.
+This might also match files that have been compressed by the filesystem.
 .It Ic -type Ar t
 True if the file is of the specified type.
 Possible file types are as follows:
@@ -971,7 +1005,7 @@
 as well as
 .Ic -amin , -anewer , -cmin , -cnewer , -delete , -empty , -fstype ,
 .Ic -iname , -inum , -iregex , -ls , -maxdepth , -mindepth , -mmin ,
-.Ic -path , -print0 , -regex
+.Ic -path , -print0 , -regex , -sparse
 and all of the
 .Ic -B*
 birthtime related primaries are extensions to


Property changes on: trunk/usr.bin/find/find.1
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/find/find.c
===================================================================
--- trunk/usr.bin/find/find.c	2018-07-07 20:40:15 UTC (rev 11544)
+++ trunk/usr.bin/find/find.c	2018-07-07 20:40:42 UTC (rev 11545)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1991, 1993, 1994
  *	The Regents of the University of California.  All rights reserved.
@@ -38,7 +39,7 @@
 #endif /* not lint */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/find/find.c 238780 2012-07-25 21:59:10Z jilles $");
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -197,8 +198,12 @@
 				continue;
 			break;
 		case FTS_DNR:
+		case FTS_NS:
+			if (ignore_readdir_race &&
+			    entry->fts_errno == ENOENT && entry->fts_level > 0)
+				continue;
+			/* FALLTHROUGH */
 		case FTS_ERR:
-		case FTS_NS:
 			(void)fflush(stdout);
 			warnx("%s: %s",
 			    entry->fts_path, strerror(entry->fts_errno));
@@ -228,7 +233,7 @@
 		for (p = plan; p && (p->execute)(p, entry); p = p->next);
 	}
 	finish_execplus();
-	if (errno)
+	if (errno && (!ignore_readdir_race || errno != ENOENT))
 		err(1, "fts_read");
 	return (rval);
 }

Modified: trunk/usr.bin/find/find.h
===================================================================
--- trunk/usr.bin/find/find.h	2018-07-07 20:40:15 UTC (rev 11544)
+++ trunk/usr.bin/find/find.h	2018-07-07 20:40:42 UTC (rev 11545)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -30,7 +31,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)find.h	8.1 (Berkeley) 6/6/93
- *	$MidnightBSD$
+ *	$FreeBSD: stable/10/usr.bin/find/find.h 248446 2013-03-17 22:51:58Z jilles $
  */
 
 #include <regex.h>

Modified: trunk/usr.bin/find/function.c
===================================================================
--- trunk/usr.bin/find/function.c	2018-07-07 20:40:15 UTC (rev 11544)
+++ trunk/usr.bin/find/function.c	2018-07-07 20:40:42 UTC (rev 11545)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1990, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -37,7 +38,7 @@
 #endif /* not lint */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/find/function.c 326790 2017-12-12 04:08:30Z delphij $");
 
 #include <sys/param.h>
 #include <sys/ucred.h>
@@ -404,7 +405,6 @@
 	acl_free(facl);
 	if (ret) {
 		warn("%s", entry->fts_accpath);
-		acl_free(facl);
 		return (0);
 	}
 	if (trivial)
@@ -442,7 +442,8 @@
 		errx(1, "-delete: forbidden when symlinks are followed");
 
 	/* Potentially unsafe - do not accept relative paths whatsoever */
-	if (strchr(entry->fts_accpath, '/') != NULL)
+	if (entry->fts_level > FTS_ROOTLEVEL &&
+	    strchr(entry->fts_accpath, '/') != NULL)
 		errx(1, "-delete: %s: relative path potentially not safe",
 			entry->fts_accpath);
 
@@ -474,6 +475,14 @@
 	isoutput = 1;			/* possible output */
 	isdepth = 1;			/* -depth implied */
 
+	/*
+	 * Try to avoid the confusing error message about relative paths
+	 * being potentially not safe.
+	 */
+	if (ftsoptions & FTS_NOCHDIR)
+		errx(1, "%s: forbidden when the current directory cannot be opened",
+		    "-delete");
+
 	return palloc(option);
 }
 
@@ -646,7 +655,8 @@
 		/* NOTREACHED */
 	case 0:
 		/* change dir back from where we started */
-		if (!(plan->flags & F_EXECDIR) && fchdir(dotfd)) {
+		if (!(plan->flags & F_EXECDIR) &&
+		    !(ftsoptions & FTS_NOCHDIR) && fchdir(dotfd)) {
 			warn("chdir");
 			_exit(1);
 		}
@@ -679,6 +689,11 @@
 	int cnt, i;
 	char **argv, **ap, **ep, *p;
 
+	/* This would defeat -execdir's intended security. */
+	if (option->flags & F_EXECDIR && ftsoptions & FTS_NOCHDIR)
+		errx(1, "%s: forbidden when the current directory cannot be opened",
+		    "-execdir");
+
 	/* XXX - was in c_execdir, but seems unnecessary!?
 	ftsoptions &= ~FTS_NOSTAT;
 	*/
@@ -713,7 +728,13 @@
 		for (ep = environ; *ep != NULL; ep++)
 			argmax -= strlen(*ep) + 1 + sizeof(*ep);
 		argmax -= 1 + sizeof(*ep);
-		new->e_pnummax = argmax / 16;
+		/*
+		 * Ensure that -execdir ... {} + does not mix files
+		 * from different directories in one invocation.
+		 * Files from the same directory should be handled
+		 * in one invocation but there is no code for it.
+		 */
+		new->e_pnummax = new->flags & F_EXECDIR ? 1 : argmax / 16;
 		argmax -= sizeof(char *) * new->e_pnummax;
 		if (argmax <= 0)
 			errx(1, "no space for arguments");
@@ -977,6 +998,25 @@
 }
 
 /*
+ * -ignore_readdir_race functions --
+ *
+ *	Always true. Ignore errors which occur if a file or a directory
+ *	in a starting point gets deleted between reading the name and calling
+ *	stat on it while find is traversing the starting point.
+ */
+
+PLAN *
+c_ignore_readdir_race(OPTION *option, char ***argvp __unused)
+{
+	if (strcmp(option->name, "-ignore_readdir_race") == 0)
+		ignore_readdir_race = 1;
+	else
+		ignore_readdir_race = 0;
+
+	return palloc(option);
+}
+
+/*
  * -inum n functions --
  *
  *	True if the file has inode # n.
@@ -1082,11 +1122,24 @@
 {
 	char fn[PATH_MAX];
 	const char *name;
+	ssize_t len;
 
 	if (plan->flags & F_LINK) {
+		/*
+		 * The below test both avoids obviously useless readlink()
+		 * calls and ensures that symlinks with existent target do
+		 * not match if symlinks are being followed.
+		 * Assumption: fts will stat all symlinks that are to be
+		 * followed and will return the stat information.
+		 */
+		if (entry->fts_info != FTS_NSOK && entry->fts_info != FTS_SL &&
+		    entry->fts_info != FTS_SLNONE)
+			return 0;
+		len = readlink(entry->fts_accpath, fn, sizeof(fn) - 1);
+		if (len == -1)
+			return 0;
+		fn[len] = '\0';
 		name = fn;
-		if (readlink(entry->fts_path, fn, sizeof(fn)) == -1)
-			return 0;
 	} else
 		name = entry->fts_name;
 	return !fnmatch(plan->c_data, name,
@@ -1467,6 +1520,29 @@
 }
 
 /*
+ * -sparse functions --
+ *
+ *      Check if a file is sparse by finding if it occupies fewer blocks
+ *      than we expect based on its size.
+ */
+int
+f_sparse(PLAN *plan __unused, FTSENT *entry)
+{
+	off_t expected_blocks;
+
+	expected_blocks = (entry->fts_statp->st_size + 511) / 512;
+	return entry->fts_statp->st_blocks < expected_blocks;
+}
+
+PLAN *
+c_sparse(OPTION *option, char ***argvp __unused)
+{
+	ftsoptions &= ~FTS_NOSTAT;
+
+	return palloc(option);
+}
+
+/*
  * -type c functions --
  *
  *	True if the type of the file is c, where c is b, c, d, p, f or w
@@ -1692,6 +1768,7 @@
 int
 f_quit(PLAN *plan __unused, FTSENT *entry __unused)
 {
+	finish_execplus();
 	exit(0);
 }
 

Modified: trunk/usr.bin/find/getdate.y
===================================================================
--- trunk/usr.bin/find/getdate.y	2018-07-07 20:40:15 UTC (rev 11544)
+++ trunk/usr.bin/find/getdate.y	2018-07-07 20:40:42 UTC (rev 11545)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 %{
 /*
 **  Originally written by Steven M. Bellovin <smb at research.att.com> while
@@ -13,7 +14,7 @@
 /* SUPPRESS 288 on yyerrlab *//* Label unused */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/find/getdate.y 235789 2012-05-22 16:33:10Z bapt $");
 
 #include <stdio.h>
 #include <ctype.h>
@@ -60,7 +61,6 @@
 
 #include <time.h>
 
-#define yyparse getdate_yyparse
 #define yylex getdate_yylex
 #define yyerror getdate_yyerror
 


Property changes on: trunk/usr.bin/find/getdate.y
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/find/ls.c
===================================================================
--- trunk/usr.bin/find/ls.c	2018-07-07 20:40:15 UTC (rev 11544)
+++ trunk/usr.bin/find/ls.c	2018-07-07 20:40:42 UTC (rev 11545)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Copyright (c) 1989, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -34,7 +35,7 @@
 #endif /* not lint */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/find/ls.c 241015 2012-09-27 23:31:19Z mdf $");
 
 #include <sys/param.h>
 #include <sys/stat.h>
@@ -63,7 +64,7 @@
 {
 	char modep[15];
 
-	(void)printf("%6lu %8"PRId64" ", (u_long) sb->st_ino, sb->st_blocks);
+	(void)printf("%6ju %8"PRId64" ", (uintmax_t)sb->st_ino, sb->st_blocks);
 	(void)strmode(sb->st_mode, modep);
 	(void)printf("%s %3u %-*s %-*s ", modep, sb->st_nlink, MAXLOGNAME - 1,
 	    user_from_uid(sb->st_uid, 0), MAXLOGNAME - 1,
@@ -70,8 +71,7 @@
 	    group_from_gid(sb->st_gid, 0));
 
 	if (S_ISCHR(sb->st_mode) || S_ISBLK(sb->st_mode))
-		(void)printf("%3d, %3d ", major(sb->st_rdev),
-		    minor(sb->st_rdev));
+		(void)printf("%#8jx ", (uintmax_t)sb->st_rdev);
 	else
 		(void)printf("%8"PRId64" ", sb->st_size);
 	printtime(sb->st_mtime);

Modified: trunk/usr.bin/find/main.c
===================================================================
--- trunk/usr.bin/find/main.c	2018-07-07 20:40:15 UTC (rev 11544)
+++ trunk/usr.bin/find/main.c	2018-07-07 20:40:42 UTC (rev 11545)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1990, 1993, 1994
  *	The Regents of the University of California.  All rights reserved.
@@ -31,7 +32,7 @@
  */
 
 #ifndef lint
-char copyright[] =
+static const char copyright[] =
 "@(#) Copyright (c) 1990, 1993, 1994\n\
 	The Regents of the University of California.  All rights reserved.\n";
 #endif /* not lint */
@@ -43,7 +44,7 @@
 #endif /* not lint */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/find/main.c 246628 2013-02-10 18:56:37Z jilles $");
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -64,6 +65,7 @@
 time_t now;			/* time find was run */
 int dotfd;			/* starting directory */
 int ftsoptions;			/* options for the ftsopen(3) call */
+int ignore_readdir_race;	/* ignore readdir race */
 int isdeprecated;		/* using deprecated syntax */
 int isdepth;			/* do directories on post-order visit */
 int isoutput;			/* user specified output operator */
@@ -151,7 +153,7 @@
 	*p = NULL;
 
 	if ((dotfd = open(".", O_RDONLY | O_CLOEXEC, 0)) < 0)
-		err(1, ".");
+		ftsoptions |= FTS_NOCHDIR;
 
 	exit(find_execute(find_formplan(argv), start));
 }

Modified: trunk/usr.bin/find/misc.c
===================================================================
--- trunk/usr.bin/find/misc.c	2018-07-07 20:40:15 UTC (rev 11544)
+++ trunk/usr.bin/find/misc.c	2018-07-07 20:40:42 UTC (rev 11545)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1990, 1993, 1994
  *	The Regents of the University of California.  All rights reserved.
@@ -38,7 +39,7 @@
 #endif /* not lint */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/find/misc.c 287266 2015-08-28 20:53:08Z jilles $");
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -57,23 +58,33 @@
  *	Replace occurrences of {} in s1 with s2 and return the result string.
  */
 void
-brace_subst(char *orig, char **store, char *path, int len)
+brace_subst(char *orig, char **store, char *path, size_t len)
 {
-	int plen;
-	char ch, *p;
+	const char *pastorigend, *p, *q;
+	char *dst;
+	size_t newlen, plen;
 
 	plen = strlen(path);
-	for (p = *store; (ch = *orig) != '\0'; ++orig)
-		if (ch == '{' && orig[1] == '}') {
-			while ((p - *store) + plen > len)
-				if (!(*store = realloc(*store, len *= 2)))
-					err(1, NULL);
-			memmove(p, path, plen);
-			p += plen;
-			++orig;
-		} else
-			*p++ = ch;
-	*p = '\0';
+	newlen = strlen(orig) + 1;
+	pastorigend = orig + newlen;
+	for (p = orig; (q = strstr(p, "{}")) != NULL; p = q + 2) {
+		if (plen > 2 && newlen + plen - 2 < newlen)
+			errx(2, "brace_subst overflow");
+		newlen += plen - 2;
+	}
+	if (newlen > len) {
+		*store = reallocf(*store, newlen);
+		if (*store == NULL)
+			err(2, NULL);
+	}
+	dst = *store;
+	for (p = orig; (q = strstr(p, "{}")) != NULL; p = q + 2) {
+		memcpy(dst, p, q - p);
+		dst += q - p;
+		memcpy(dst, path, plen);
+		dst += plen;
+	}
+	memcpy(dst, p, pastorigend - p);
 }
 
 /*

Modified: trunk/usr.bin/find/option.c
===================================================================
--- trunk/usr.bin/find/option.c	2018-07-07 20:40:15 UTC (rev 11544)
+++ trunk/usr.bin/find/option.c	2018-07-07 20:40:42 UTC (rev 11545)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1990, 1993, 1994
  *	The Regents of the University of California.  All rights reserved.
@@ -37,7 +38,7 @@
 #endif /* not lint */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/find/option.c 247730 2013-03-03 20:10:56Z dwmalone $");
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -88,7 +89,7 @@
 	{ "-fstype",	c_fstype,	f_fstype,	0 },
 	{ "-gid",	c_group,	f_group,	0 },
 	{ "-group",	c_group,	f_group,	0 },
-	{ "-ignore_readdir_race",c_simple, f_always_true,0 },
+	{ "-ignore_readdir_race",c_ignore_readdir_race, f_always_true,0 },
 	{ "-ilname",	c_name,		f_name,		F_LINK | F_IGNCASE },
 	{ "-iname",	c_name,		f_name,		F_IGNCASE },
 	{ "-inum",	c_inum,		f_inum,		0 },
@@ -127,7 +128,7 @@
 	{ "-newermm",	c_newer,	f_newer,	0 },
 	{ "-newermt",	c_newer,	f_newer,	F_TIME2_T },
 	{ "-nogroup",	c_nogroup,	f_nogroup,	0 },
-	{ "-noignore_readdir_race",c_simple, f_always_true,0 },
+	{ "-noignore_readdir_race",c_ignore_readdir_race, f_always_true,0 },
 	{ "-noleaf",	c_simple,	f_always_true,	0 },
 	{ "-not",	c_simple,	f_not,		0 },
 	{ "-nouser",	c_nouser,	f_nouser,	0 },
@@ -145,6 +146,7 @@
 	{ "-regex",	c_regex,	f_regex,	0 },
 	{ "-samefile",	c_samefile,	f_inum,		0 },
 	{ "-size",	c_size,		f_size,		0 },
+	{ "-sparse",	c_sparse,	f_sparse,	0 },
 	{ "-true",	c_simple,	f_always_true,	0 },
 	{ "-type",	c_type,		f_type,		0 },
 	{ "-uid",	c_user,		f_user,		0 },



More information about the Midnightbsd-cvs mailing list