summaryrefslogtreecommitdiffstats
path: root/usr.bin/locate
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2005-12-07 12:22:46 +0000
committerdes <des@FreeBSD.org>2005-12-07 12:22:46 +0000
commit0ec9711525940fa0e2a966d61cbce54fdaed9be7 (patch)
tree09ed7d6a8ecf3b6268303ca98411073458b6e97f /usr.bin/locate
parent3b456162b8cdf22fdf884e2a9cbbda19c96ea004 (diff)
downloadFreeBSD-src-0ec9711525940fa0e2a966d61cbce54fdaed9be7.zip
FreeBSD-src-0ec9711525940fa0e2a966d61cbce54fdaed9be7.tar.gz
Add a -0 option for interoperability with xargs -0.
PR: bin/56558 Submitted by: Eugene Grosbein <eugen@grosbein.pp.ru> MFC after: 2 weeks
Diffstat (limited to 'usr.bin/locate')
-rw-r--r--usr.bin/locate/locate/fastfind.c5
-rw-r--r--usr.bin/locate/locate/locate.17
-rw-r--r--usr.bin/locate/locate/locate.c6
3 files changed, 14 insertions, 4 deletions
diff --git a/usr.bin/locate/locate/fastfind.c b/usr.bin/locate/locate/fastfind.c
index 8e29355..e132dbd 100644
--- a/usr.bin/locate/locate/fastfind.c
+++ b/usr.bin/locate/locate/fastfind.c
@@ -103,6 +103,7 @@ statistic (fp, path_fcodes)
}
#endif /* _LOCATE_STATISTIC_ */
+extern char separator;
void
#ifdef FF_MMAP
@@ -315,11 +316,11 @@ fastfind
else if (f_limit) {
counter++;
if (f_limit >= counter)
- (void)puts(path);
+ (void)printf("%s%c",path,separator);
else
errx(0, "[show only %d lines]", counter - 1);
} else
- (void)puts(path);
+ (void)printf("%s%c",path,separator);
}
break;
}
diff --git a/usr.bin/locate/locate/locate.1 b/usr.bin/locate/locate/locate.1
index 27b750e..dca91bb 100644
--- a/usr.bin/locate/locate/locate.1
+++ b/usr.bin/locate/locate/locate.1
@@ -41,7 +41,7 @@
.Nd find filenames quickly
.Sh SYNOPSIS
.Nm
-.Op Fl Scims
+.Op Fl 0Scims
.Op Fl l Ar limit
.Op Fl d Ar database
.Ar pattern ...
@@ -90,6 +90,11 @@ are stored in 2 bytes.
.Pp
The following options are available:
.Bl -tag -width 10n
+.It Fl 0
+Print pathnames separated by an
+.Tn ASCII NUL
+character (character code 0) instead of default NL
+(newline, character code 10).
.It Fl S
Print some statistic about the database and exit.
.It Fl c
diff --git a/usr.bin/locate/locate/locate.c b/usr.bin/locate/locate/locate.c
index 9283599..a1883f2 100644
--- a/usr.bin/locate/locate/locate.c
+++ b/usr.bin/locate/locate/locate.c
@@ -112,6 +112,7 @@ int f_statistic; /* print statistic */
int f_silent; /* suppress output, show only count of matches */
int f_limit; /* limit number of output lines, 0 == infinite */
u_int counter; /* counter for matches [-c] */
+char separator='\n'; /* line separator */
void usage(void);
@@ -145,8 +146,11 @@ main(argc, argv)
#endif
(void) setlocale(LC_ALL, "");
- while ((ch = getopt(argc, argv, "Scd:il:ms")) != -1)
+ while ((ch = getopt(argc, argv, "0Scd:il:ms")) != -1)
switch(ch) {
+ case '0': /* 'find -print0' style */
+ separator = '\0';
+ break;
case 'S': /* statistic lines */
f_statistic = 1;
break;
OpenPOWER on IntegriCloud