diff options
Diffstat (limited to 'usr.bin/find')
-rw-r--r-- | usr.bin/find/extern.h | 1 | ||||
-rw-r--r-- | usr.bin/find/find.c | 5 | ||||
-rw-r--r-- | usr.bin/find/find.h | 2 | ||||
-rw-r--r-- | usr.bin/find/function.c | 17 |
4 files changed, 21 insertions, 4 deletions
diff --git a/usr.bin/find/extern.h b/usr.bin/find/extern.h index 2ee85102688b..a6f09f47db75 100644 --- a/usr.bin/find/extern.h +++ b/usr.bin/find/extern.h @@ -49,6 +49,7 @@ struct stat; void printlong(char *, char *, struct stat *); int queryuser(char **); OPTION *lookup_option(const char *); +void finish_execplus(void); creat_f c_Xmin; creat_f c_Xtime; diff --git a/usr.bin/find/find.c b/usr.bin/find/find.c index 0486e8b096b5..cc2d797a541d 100644 --- a/usr.bin/find/find.c +++ b/usr.bin/find/find.c @@ -231,10 +231,7 @@ find_execute(PLAN *plan, char *paths[]) */ for (p = plan; p && (p->execute)(p, entry); p = p->next); } - /* Finish any pending -exec ... {} + functions. */ - for (p = plan; p != NULL; p = p->next) - if (p->execute == f_exec && p->flags & F_EXECPLUS) - (p->execute)(p, NULL); + finish_execplus(); if (errno) err(1, "fts_read"); return (rval); diff --git a/usr.bin/find/find.h b/usr.bin/find/find.h index 7f1acaf1175c..c7366fa5246d 100644 --- a/usr.bin/find/find.h +++ b/usr.bin/find/find.h @@ -105,6 +105,7 @@ typedef struct _plandata { int _e_psize; /* number of bytes of args. */ int _e_pbsize; /* base num. of bytes of args */ int _e_psizemax; /* max num. of bytes of args */ + struct _plandata *_e_next;/* next F_EXECPLUS in tree */ } ex; char *_a_data[2]; /* array of char pointers */ char *_c_data; /* char pointer */ @@ -135,6 +136,7 @@ typedef struct _plandata { #define e_psize p_un.ex._e_psize #define e_pbsize p_un.ex._e_pbsize #define e_psizemax p_un.ex._e_psizemax +#define e_next p_un.ex._e_next typedef struct _option { const char *name; /* option name */ diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c index 38bf813510d3..f1c473ea240a 100644 --- a/usr.bin/find/function.c +++ b/usr.bin/find/function.c @@ -76,6 +76,8 @@ static char *nextarg(OPTION *, char ***); extern char **environ; +static PLAN *lastexecplus = NULL; + #define COMPARE(a, b) do { \ switch (plan->flags & F_ELG_MASK) { \ case F_EQUAL: \ @@ -711,6 +713,8 @@ c_exec(OPTION *option, char ***argvp) new->e_psizemax = argmax; new->e_pbsize = 0; cnt += new->e_pnummax + 1; + new->e_next = lastexecplus; + lastexecplus = new; } if ((new->e_argv = malloc(cnt * sizeof(char *))) == NULL) err(1, NULL); @@ -754,6 +758,19 @@ done: *argvp = argv + 1; return new; } +/* Finish any pending -exec ... {} + functions. */ +void +finish_execplus() +{ + PLAN *p; + + p = lastexecplus; + while (p != NULL) { + (p->execute)(p, NULL); + p = p->e_next; + } +} + int f_flags(PLAN *plan, FTSENT *entry) { |