Commit Graph

81 Commits

Author SHA1 Message Date
andvar 82bba4e936 fix various typos in comments. 2024-02-05 21:46:04 +00:00
christos 7f63469776 PR/57313: Timo Buhrmester: Don't bail if "." cannot be opened. From FreeBSD 2023-04-01 15:57:20 +00:00
cheusov 93a814dc9d find: use POSIX strtoll(3) instead of legacy strtoq(3) 2021-03-18 18:24:14 +00:00
cheusov 4e50b167d1 find: use POSIX type uint32_t instead of u_int32_t 2021-03-18 18:21:18 +00:00
kre 2bdb5be389 Inspired by PR pkg/53543
When calculating the length of the args that can be
appended in a "find .... -exec something {} +"
usage, remember to allow for the arg pointers, which
form part of what is allowed in ARG_MAX.

From a fairly empty installation of HEAD on amd64
and with a "/tmp/args" command that simply prints
its arg count, and the length of the arg strings,
with this mod I see ..

netbsd# find / -exec /tmp/args {} +
Argc 5000 Arglen 107645
Argc 5000 Arglen 151324
Argc 5000 Arglen 187725
Argc 5000 Arglen 206591
Argc 5000 Arglen 172909
Argc 5000 Arglen 186264
Argc 5000 Arglen 167906
Argc 2881 Arglen 98260

The upper limit of 5000 args is in the code.

Using the biggest of those, 5000
args, plus 206591 bytes of strings
uses 246591 bytes total (this excludes
the command name, so add a few more).
That's fairly close to the ARG_MAX
of 262144.

On another system (with longer paths) I see:
(this is just a small part of the output, using a
different version of the dummy command, and a
slightly different invocation)

Args: 4546 Len 218030
Args: 4878 Len 217991
Args: 4813 Len 218028
Args: 4803 Len 218029

There, 4878*8 + 217991 == 257015 which is about
as close as we'd want to come to the arg limit.

XXX pullup -8
2018-09-04 15:16:15 +00:00
christos edba12e937 PR/52295: Anthony Mallet: find -delete: "relative path not safe" with absolute
paths ... Fix from OpenBSD
2017-06-13 13:10:32 +00:00
pgoyette fb5782856e Fix missing quote. Resolve automated test failure. 2016-06-13 02:06:44 +00:00
pgoyette cc610a3c94 Add new primaries -asince, -csince, and -since to compare file's
attributes against a user-specified timestamp (rather than the
attributes of a reference file).

Update the parse routines so they have access to the name of the
option being parsed.  This enables accurate error reporting for
"aliases" of primaries.

Now that aliases work, introduce some aliases for consistency with
Gnu findutils.
2016-06-13 00:04:40 +00:00
dholland 9d2811fca4 Extend the numeric handling for uids with -user to gids with -group, and
document it. Leftover bit of PR 46158.
2016-06-12 20:50:10 +00:00
uebayasi 1a3fcd0b6a find(1): Compare timestamp in nsec scale in -anewer/-cnewer/-newer. 2013-05-04 06:29:32 +00:00
wiz 30cf30e561 Make order of words in comment consistent with that within other
comments (helps with search actions).

Patch from Bug Hunting.
2012-08-26 14:26:37 +00:00
dholland 1d1104dd8c rest of previous.
BQS: 1. dholland: 0.
2012-05-05 21:16:16 +00:00
dholland f88a50da82 typo in comment 2012-05-05 20:48:51 +00:00
matt d34c2845b8 Use C89 function definitions 2012-03-20 20:34:57 +00:00
christos 8624929e77 Fix unchecked malloc, check for overflow (Maksymilian Arciemowicz)
While here, remove unused casts, fix types.
2011-09-22 12:49:57 +00:00
jmcneill e816b5f7a6 Don't error out while searching for empty directories, from FreeBSD:
http://lists.freebsd.org/pipermail/svn-src-head/2010-December/022913.html
2011-02-24 02:55:18 +00:00
dholland f4f54a9c39 Fix "-exec blah blah {} +" so it only matches when the {} is last, as
per the standard. Per (brief) discussion on tech-userlevel.

There should really be a form where you can do the equivalent of
"-exec blah {} blah +", but I think we're going to need to call it
something other than -exec. As it is it's sort of surprising that the
standards people didn't add a different name -- note what happens if
you try to do something like "find ... -exec expr {} + 2 \;".
2011-01-06 08:18:42 +00:00
daniel 02dcfb175e Add the '-E' option to interpret regexes as extended regexes. While we
are here, fix ordering in usage information by putting '-X' in the proper
place.

Addition of '-E' was discussed on tech-userlevel.
2007-07-19 07:49:30 +00:00
christos b1b89f5d46 eliminate MFSNAMELEN 2007-07-17 21:35:29 +00:00
elad a706fb0965 Add -delete from FreeBSD. 2007-02-06 13:25:01 +00:00
christos ca93cf9ea4 fix spello (from Anon Ymous) 2007-02-02 15:48:54 +00:00
he cb49bdddc9 Adapt find to the move of string_to_flags() and flags_to_string() to
libutil.
2006-12-14 20:55:56 +00:00
christos 1dcd74fde3 eliminate alloca use. 2006-11-09 20:50:53 +00:00
tacha 7a76839cea All members of PLAN should be initialized. 2006-10-12 08:46:18 +00:00
apb 2eed134b40 De-__P(), remove trailing spaces, sprinkle a few const, WARNS=4. 2006-10-11 19:51:10 +00:00
apb b90dcb5d01 Add support for "find ... -exec ... {} +".
The code is from John Hawkinson in PR 20470.  I adapted it to current,
and made some KNF and comment changes.
2006-10-07 17:04:02 +00:00
christos cdab3a7a06 More programs using efun. 2006-08-26 18:17:41 +00:00
mrg 084c052803 quell GCC 4.1 uninitialised variable warnings.
XXX: we should audit the tree for which old ones are no longer needed
after getting the older compilers out of the tree..
2006-05-10 21:53:14 +00:00
jschauma a32f19d465 Add a new primary '-exit n':
This primary causes find to stop traversing the filesystem and
exit immediately if a previous condition was met.  If no value is
specified, the exit value will be 0, else n.  Note that other
primaries will be evaluated and acted upon before exiting.

Ok matt@, garbled@.
2006-02-20 16:31:02 +00:00
reed 9695cc3899 Add -false switch. From man page:
-false  This primary always evaluates to false.  This can be used follow-
        ing a primary that caused the expression to be true to make the
	expression to be false.  This can be useful after using a -fprint
	primary so it can continue to the next expression (using an -or
	operator, for example).

This was brought up on the tech-userlevel list in October.

Using -fprint on findutils or new NetBSD find(1) does not do what
I wanted. For example, if saving results of all files that start
with a vowel or saving results of all files owned by group operator,
then the list of files owned by group operator would not include
the files starting with a vowel.

findutils's find has a workaround for this with -false and also a
"," comma opeator. (I made add this comma operator later; you can use
the comma to perform multiple independent tests.)
2005-11-09 00:47:16 +00:00
reed 4129c05469 This adds -fprint function. The primary name "-fprint" (but not the
code) comes from findutils; it behaves the same.

From my manpage addition:

 -fprint filename
	This primary always evaluates to true.  This creates filename or
	overwrites the file if it already exists.  The file is created at
	startup.  It writes the pathname of the current file to this
	file, followed by a newline character.  The file will be empty if
	no files are matched.

Here is an example usage:

find /etc \( -name "*pass*" -fprint file1 \) -o \( -group operator -fprint file2 \) -o -name "w*"

Note that this example will NOT include entry in file2 if it is
matched in first expression. (This also is same behaviour as
findutils, and I have implemented a -false primary to handle that.
I will commit it later.)

This creates the file as command line argument parsing time.
If there is an error somewhere on that line, such as missing values
or mismatched parenthesis, then a file may still be created.
(Even if a later -fprint filename is unwritable.) This is similar
behaviour to findutils. (It has been suggested that this find could
be code to create the files in an extra stage after the command-line
argument parsing and before the actual function processing.)

I will add -fprintx and -fprint0 soon.

This was discussed on tech-userlevel.
2005-10-12 20:03:59 +00:00
christos c05266af8a fix setmode error handling. 2005-10-01 20:23:54 +00:00
atatat 4b9429a08d Attack of the whiteout police, including the "fix whitespace problems"
department followed by the "and fix the the ifdefs as well" brigade,
leading to a janitorial "just combine those two" strike team.
2004-12-28 05:11:07 +00:00
christos 6bd1d6d4db Replace the statfs() family of system calls with statvfs().
Retain binary compatibility.
2004-04-21 01:05:31 +00:00
heas 171a04291f Whitespace nit 2004-03-30 22:51:55 +00:00
agc 89aaa1bb64 Move UCB-licensed code from 4-clause to 3-clause licence.
Patches provided by Joel Baker in PR 22365, verified by myself.
2003-08-07 11:13:06 +00:00
provos ccc5fba3de Implement -iname for case insensitive matching on file names.
From freebsd/openbsd.  Approved by jaromir@, manu@, perry@.
2003-08-03 19:46:03 +00:00
itojun 28f506f3a2 strlcpy 2003-07-12 13:57:49 +00:00
jhawk 980fe9aad7 Obey preceding - and + on -user when a numeric uid is specified (only).
Our behavior is now consistent with Solaris, and more useful than previous.

Unfortunately we end up strtol()-ing twice (once via atoi()) to avoid
changing find_parsenum().
2003-01-30 10:49:05 +00:00
matt 3e5306bedf With -printx also qoute $ and ` (since they are shell metacharaters). 2003-01-26 07:07:31 +00:00
provos 9972ef9ff8 support for -empty, -execdir, -mindepth, -maxdepth to match other UNIX-like
systems.  based on work by tholo@openbsd.org.  approved by perry.
2002-09-27 15:56:25 +00:00
kleink 4f0bdb5b24 Since we've already been down that road with -cnewer, support GNU find(1)'s
-anewer as well.
2001-12-02 12:46:39 +00:00
kleink e7566d6000 Add a "cnewer" primary which evaluates true if a file has a more recent
ctime than its argument.

From kre in PR bin/14802; originally suggested name was "updated" but
renamed due to GNU find(1) being prior art for this functionality.
2001-12-01 14:10:04 +00:00
enami 49f300855c Reallocate memory correctly while substituting the braces. 2001-09-21 07:11:33 +00:00
simonb 0e3b64a601 Back out previous vfork->fork change now that the cause of the problem
(execvp) has been fixed.
2001-09-18 05:11:15 +00:00
simonb 7a40d9c0cf Use fork() instead of vfork(). The child calls execvp(), which calls
strdup(), which calls malloc()...

Fixes problem with "find .. -exec" growing as reported by Kazushi Marukawa
on current-users@.
2001-09-14 08:19:25 +00:00
christos f6321b3b4d fixed nested externs 2001-02-05 01:53:48 +00:00
enami e92c3f2867 - The type of return value of setmode is a void * and getmode takes it,
rather than mode_t *.
- Free the storage allocated by setmode unless it is obvious that program
  exits immediately.
2000-10-10 14:30:40 +00:00
enami 7b4bdbc144 Cosmetic changes. 2000-03-16 18:44:29 +00:00
drochner 85cbf55d16 Since our gcc doesn't warn about NULL format strings anymore, we can
fix the incorrect err(1, "%s", "") et al.
Closes PR bin/7592 by cgd.
1999-11-09 15:06:30 +00:00