summaryrefslogtreecommitdiff
path: root/usr.bin/find/find.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/find/find.c')
-rw-r--r--usr.bin/find/find.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/usr.bin/find/find.c b/usr.bin/find/find.c
index 20efeaca741..85034ad53e9 100644
--- a/usr.bin/find/find.c
+++ b/usr.bin/find/find.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: find.c,v 1.5 1997/06/30 23:54:07 millert Exp $ */
+/* $OpenBSD: find.c,v 1.6 1999/10/03 19:07:35 millert Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -38,7 +38,7 @@
#ifndef lint
/*static char sccsid[] = "from: @(#)find.c 8.1 (Berkeley) 6/6/93";*/
-static char rcsid[] = "$OpenBSD: find.c,v 1.5 1997/06/30 23:54:07 millert Exp $";
+static char rcsid[] = "$OpenBSD: find.c,v 1.6 1999/10/03 19:07:35 millert Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -163,7 +163,7 @@ find_execute(plan, paths)
err(1, "ftsopen");
while ((entry = fts_read(tree))) {
- switch(entry->fts_info) {
+ switch (entry->fts_info) {
case FTS_D:
if (isdepth)
continue;
@@ -185,13 +185,25 @@ find_execute(plan, paths)
warnx("%s: illegal path", entry->fts_path);
continue;
}
+
+ /*
+ * Since fts does not chdir for the root node we
+ * have to do this ourselves to make -execdir work.
+ */
+ if (entry->fts_level == FTS_ROOTLEVEL)
+ chdir(entry->fts_accpath);
/*
- * call all the functions in the execution plan until one is
+ * Call all the functions in the execution plan until one is
* false or all have been executed. This is where we do all
* the work specified by the user on the command line.
*/
- for (p = plan; p && (p->eval)(p, entry); p = p->next);
+ for (p = plan; p && (p->eval)(p, entry); p = p->next)
+ ;
+
+ /* Undo the chdir above to make fts happy. */
+ if (entry->fts_level == FTS_ROOTLEVEL)
+ fchdir(tree->fts_rfd);
}
(void)fts_close(tree);
}