diff --git a/usr.bin/locate/locate/fastfind.c b/usr.bin/locate/locate/fastfind.c index 8e29355857b9..e132dbd53e59 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 27b750e08d90..dca91bb141c1 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 928359951f8d..a1883f2927dc 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;