diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1997-09-01 02:44:20 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1997-09-01 02:44:20 +0000 |
commit | debdcf8d7d06fd4e90452a13394126429ce16fd6 (patch) | |
tree | 6dcf80492503874fd3f63aa974d3039d14ccdf32 /usr.bin | |
parent | fd34f721763470ce8f5bd60862610862b508bd0c (diff) |
Fix problem with ``find -execdir'' not having the correct initial cwd.
Adds a new flag to fts(3).
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/find/function.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c index 9f8bccd957c..92d1a5a1c2a 100644 --- a/usr.bin/find/function.c +++ b/usr.bin/find/function.c @@ -1,4 +1,4 @@ -/* $OpenBSD: function.c,v 1.9 1997/06/30 23:54:07 millert Exp $ */ +/* $OpenBSD: function.c,v 1.10 1997/09/01 02:44:19 millert Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -38,7 +38,7 @@ #ifndef lint /*static char sccsid[] = "from: @(#)function.c 8.1 (Berkeley) 6/6/93";*/ -static char rcsid[] = "$OpenBSD: function.c,v 1.9 1997/06/30 23:54:07 millert Exp $"; +static char rcsid[] = "$OpenBSD: function.c,v 1.10 1997/09/01 02:44:19 millert Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -53,6 +53,7 @@ static char rcsid[] = "$OpenBSD: function.c,v 1.9 1997/06/30 23:54:07 millert Ex #include <fnmatch.h> #include <fts.h> #include <grp.h> +#include <libgen.h> #include <pwd.h> #include <stdio.h> #include <stdlib.h> @@ -379,18 +380,15 @@ f_execdir(plan, entry) register int cnt; pid_t pid; int status; - char *file; - - /* XXX - if file/dir ends in '/' this will not work -- can it? */ - if ((file = strrchr(entry->fts_path, '/'))) - file++; - else - file = entry->fts_path; + char base[MAXPATHLEN]; + /* Substitute basename(path) for {} since cwd is it's parent dir */ + (void)strncpy(base, basename(entry->fts_path), sizeof(base) - 1); + base[sizeof(base) - 1] = '\0'; for (cnt = 0; plan->e_argv[cnt]; ++cnt) if (plan->e_len[cnt]) brace_subst(plan->e_orig[cnt], &plan->e_argv[cnt], - file, plan->e_len[cnt]); + base, plan->e_len[cnt]); /* don't mix output of command with find output */ fflush(stdout); @@ -425,6 +423,7 @@ c_execdir(argvp) register char **argv, **ap, *p; ftsoptions &= ~FTS_NOSTAT; + ftsoptions |= FTS_CHDIRROOT; isoutput = 1; new = palloc(N_EXECDIR, f_execdir); |