summaryrefslogtreecommitdiffstats
path: root/usr.bin/find/find.c
diff options
context:
space:
mode:
authorwosch <wosch@FreeBSD.org>1998-11-29 00:54:21 +0000
committerwosch <wosch@FreeBSD.org>1998-11-29 00:54:21 +0000
commitd13a028d3d91883f7904f1da506602a7585990de (patch)
tree34fdcb14518f32cb2556ae8ef2c24cedb9653bdc /usr.bin/find/find.c
parent083b0d7688fa9abeb57de744e997044767be0259 (diff)
downloadFreeBSD-src-d13a028d3d91883f7904f1da506602a7585990de.zip
FreeBSD-src-d13a028d3d91883f7904f1da506602a7585990de.tar.gz
Added a sort option to find(1).
The sort option make it possible to build the locate database without large (usually 20-100MB) temp files.
Diffstat (limited to 'usr.bin/find/find.c')
-rw-r--r--usr.bin/find/find.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/usr.bin/find/find.c b/usr.bin/find/find.c
index 8afadf8b..c63362a 100644
--- a/usr.bin/find/find.c
+++ b/usr.bin/find/find.c
@@ -50,6 +50,8 @@ static char sccsid[] = "@(#)find.c 8.5 (Berkeley) 8/5/94";
#include "find.h"
+static int find_compare(const FTSENT **s1, const FTSENT **s2);
+
/*
* find_formplan --
* process the command line and create a "plan" corresponding to the
@@ -142,6 +144,18 @@ find_formplan(argv)
FTS *tree; /* pointer to top of FTS hierarchy */
/*
+ * find_compare --
+ * A function which be used in fts_open() to order the
+ * traversal of the hierarchy.
+ * This function give you a lexicographical sorted output.
+ */
+static int find_compare(s1, s2)
+ const FTSENT **s1, **s2;
+{
+ return strcoll( (*s1)->fts_name, (*s2)->fts_name );
+}
+
+/*
* find_execute --
* take a search plan and an array of search paths and executes the plan
* over all FTSENT's returned for the given search paths.
@@ -155,7 +169,8 @@ find_execute(plan, paths)
PLAN *p;
int rval;
- if ((tree = fts_open(paths, ftsoptions, (int (*)())NULL)) == NULL)
+ if ((tree = fts_open(paths, ftsoptions,
+ (issort ? find_compare : NULL) )) == NULL)
err(1, "ftsopen");
for (rval = 0; (entry = fts_read(tree)) != NULL;) {
OpenPOWER on IntegriCloud