summaryrefslogtreecommitdiffstats
path: root/usr.bin/find
diff options
context:
space:
mode:
authorwollman <wollman@FreeBSD.org>1995-05-09 19:02:06 +0000
committerwollman <wollman@FreeBSD.org>1995-05-09 19:02:06 +0000
commit715c2b0756e915aec3e15087ab41a14e903bd7f1 (patch)
tree3824a53da4fe2907a82c2e56c64ecc75e069be0b /usr.bin/find
parentbf8c6b4473f2382b18fd53796f80b17d6ae323e3 (diff)
downloadFreeBSD-src-715c2b0756e915aec3e15087ab41a14e903bd7f1.zip
FreeBSD-src-715c2b0756e915aec3e15087ab41a14e903bd7f1.tar.gz
Add GNU-style `-print0' primary. This exists so that one can safely
do `find some-nasty-expression -print0 | perl -n0e unlink' and have all the files actuallly get deleted. (Using `xargs' and `rm' is not safe.)
Diffstat (limited to 'usr.bin/find')
-rw-r--r--usr.bin/find/extern.h1
-rw-r--r--usr.bin/find/find.116
-rw-r--r--usr.bin/find/find.h1
-rw-r--r--usr.bin/find/function.c24
-rw-r--r--usr.bin/find/option.c1
5 files changed, 39 insertions, 4 deletions
diff --git a/usr.bin/find/extern.h b/usr.bin/find/extern.h
index 3db2d5f..c9aba6f 100644
--- a/usr.bin/find/extern.h
+++ b/usr.bin/find/extern.h
@@ -64,6 +64,7 @@ PLAN *c_nouser __P((void));
PLAN *c_path __P((char *));
PLAN *c_perm __P((char *));
PLAN *c_print __P((void));
+PLAN *c_print0 __P((void));
PLAN *c_prune __P((void));
PLAN *c_size __P((char *));
PLAN *c_type __P((char *));
diff --git a/usr.bin/find/find.1 b/usr.bin/find/find.1
index 6523bba..b92f95c 100644
--- a/usr.bin/find/find.1
+++ b/usr.bin/find/find.1
@@ -265,12 +265,19 @@ Note, the first character of a symbolic mode may not be a dash (``\-'').
.It Ic -print
This primary always evaluates to true.
It prints the pathname of the current file to standard output.
-The expression is appended to the user specified expression if neither
+The expression is appended to the user specified expression if none of
.Ic -exec ,
-.Ic -ls
+.Ic -ls ,
+.Ic -print0 ,
or
.Ic \&-ok
-is specified.
+are specified.
+.It Ic -print0
+This primary always evaluates to true.
+It prints the pathname of the current file to standard output, followed by a
+.Tn ASCII
+.Tn NUL
+character (character code 0).
.It Ic -prune
This primary always evaluates to true.
It causes
@@ -404,7 +411,8 @@ The
and
.Fl X
options and the
-.Ic -inum
+.Ic -inum ,
+.Ic -print0 ,
and
.Ic -ls
primaries are extensions to
diff --git a/usr.bin/find/find.h b/usr.bin/find/find.h
index 4c4ffa5..8066d37 100644
--- a/usr.bin/find/find.h
+++ b/usr.bin/find/find.h
@@ -43,6 +43,7 @@ enum ntype {
N_FSTYPE, N_GROUP, N_INUM, N_LINKS, N_LS, N_MTIME, N_NAME, N_NEWER,
N_NOGROUP, N_NOT, N_NOUSER, N_OK, N_OPENPAREN, N_OR, N_PATH,
N_PERM, N_PRINT, N_PRUNE, N_SIZE, N_TYPE, N_USER, N_XDEV,
+ N_PRINT0
};
/* node definition */
diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c
index f537676..52e0f43 100644
--- a/usr.bin/find/function.c
+++ b/usr.bin/find/function.c
@@ -794,6 +794,30 @@ c_print()
}
/*
+ * -print0 functions --
+ *
+ * Always true, causes the current pathame to be written to
+ * standard output followed by a NUL character
+ */
+int
+f_print0(plan, entry)
+ PLAN *plan;
+ FTSENT *entry;
+{
+ fputs(entry->fts_path, stdout);
+ fputc('\0', stdout);
+ return (1);
+}
+
+PLAN *
+c_print0()
+{
+ isoutput = 1;
+
+ return (palloc(N_PRINT0, f_print0));
+}
+
+/*
* -prune functions --
*
* Prune a portion of the hierarchy.
diff --git a/usr.bin/find/option.c b/usr.bin/find/option.c
index 9b25cee..66596c3 100644
--- a/usr.bin/find/option.c
+++ b/usr.bin/find/option.c
@@ -79,6 +79,7 @@ static OPTION const options[] = {
{ "-path", N_PATH, c_path, O_ARGV },
{ "-perm", N_PERM, c_perm, O_ARGV },
{ "-print", N_PRINT, c_print, O_ZERO },
+ { "-print0", N_PRINT0, c_print0, O_ZERO },
{ "-prune", N_PRUNE, c_prune, O_ZERO },
{ "-size", N_SIZE, c_size, O_ARGV },
{ "-type", N_TYPE, c_type, O_ARGV },
OpenPOWER on IntegriCloud