aboutsummaryrefslogtreecommitdiff
path: root/findutils/find.c
diff options
context:
space:
mode:
Diffstat (limited to 'findutils/find.c')
-rw-r--r--findutils/find.c34
1 files changed, 2 insertions, 32 deletions
diff --git a/findutils/find.c b/findutils/find.c
index 5d5e24bfb..6d34f4d68 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -402,36 +402,6 @@ struct globals {
402 G.recurse_flags = ACTION_RECURSE; \ 402 G.recurse_flags = ACTION_RECURSE; \
403} while (0) 403} while (0)
404 404
405#if ENABLE_FEATURE_FIND_EXEC
406static unsigned count_subst(const char *str)
407{
408 unsigned count = 0;
409 while ((str = strstr(str, "{}")) != NULL) {
410 count++;
411 str++;
412 }
413 return count;
414}
415
416
417static char* subst(const char *src, unsigned count, const char* filename)
418{
419 char *buf, *dst, *end;
420 size_t flen = strlen(filename);
421 /* we replace each '{}' with filename: growth by strlen-2 */
422 buf = dst = xmalloc(strlen(src) + count*(flen-2) + 1);
423 while ((end = strstr(src, "{}"))) {
424 memcpy(dst, src, end - src);
425 dst += end - src;
426 src = end + 2;
427 memcpy(dst, filename, flen);
428 dst += flen;
429 }
430 strcpy(dst, src);
431 return buf;
432}
433#endif
434
435/* Return values of ACTFs ('action functions') are a bit mask: 405/* Return values of ACTFs ('action functions') are a bit mask:
436 * bit 1=1: prune (use SKIP constant for setting it) 406 * bit 1=1: prune (use SKIP constant for setting it)
437 * bit 0=1: matched successfully (TRUE) 407 * bit 0=1: matched successfully (TRUE)
@@ -615,7 +585,7 @@ ACTF(exec)
615 char *argv[ap->exec_argc + 1]; 585 char *argv[ap->exec_argc + 1];
616#endif 586#endif
617 for (i = 0; i < ap->exec_argc; i++) 587 for (i = 0; i < ap->exec_argc; i++)
618 argv[i] = subst(ap->exec_argv[i], ap->subst_count[i], fileName); 588 argv[i] = xmalloc_substitute_string(ap->exec_argv[i], ap->subst_count[i], "{}", fileName);
619 argv[i] = NULL; /* terminate the list */ 589 argv[i] = NULL; /* terminate the list */
620 590
621 rc = spawn_and_wait(argv); 591 rc = spawn_and_wait(argv);
@@ -1093,7 +1063,7 @@ static action*** parse_params(char **argv)
1093 ap->subst_count = xmalloc(ap->exec_argc * sizeof(int)); 1063 ap->subst_count = xmalloc(ap->exec_argc * sizeof(int));
1094 i = ap->exec_argc; 1064 i = ap->exec_argc;
1095 while (i--) 1065 while (i--)
1096 ap->subst_count[i] = count_subst(ap->exec_argv[i]); 1066 ap->subst_count[i] = count_strstr(ap->exec_argv[i], "{}");
1097 } 1067 }
1098#endif 1068#endif
1099#if ENABLE_FEATURE_FIND_PAREN 1069#if ENABLE_FEATURE_FIND_PAREN