summaryrefslogtreecommitdiff
path: root/findutils/find.c
diff options
context:
space:
mode:
authorDenys Vlasenko2014-02-27 11:17:06 +0100
committerDenys Vlasenko2014-02-27 11:17:06 +0100
commit6f068904dc142657bb596f91196f9113f1838cbe (patch)
treeac02741b3c8b74bf3a078aeb13ef7ff1c5e1e23f /findutils/find.c
parent6885e49ba596239a0b0d3631fd72fc2692fbb65c (diff)
downloadbusybox-6f068904dc142657bb596f91196f9113f1838cbe.zip
busybox-6f068904dc142657bb596f91196f9113f1838cbe.tar.gz
xargs: add support for -I and -i. Closes 493
function old new delta process_stdin_with_replace - 195 +195 xmalloc_substitute_string - 145 +145 xargs_main 808 884 +76 count_strstr - 45 +45 packed_usage 29580 29571 -9 parse_params 1445 1416 -29 func_exec 285 138 -147 ------------------------------------------------------------------------------ (add/remove: 4/0 grow/shrink: 1/3 up/down: 461/-185) Total: 276 bytes text data bss dec hex filename 922156 932 17692 940780 e5aec busybox_old 922440 932 17692 941064 e5c08 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'findutils/find.c')
-rw-r--r--findutils/find.c32
1 files changed, 2 insertions, 30 deletions
diff --git a/findutils/find.c b/findutils/find.c
index 044f010..6d34f4d 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -402,34 +402,6 @@ struct globals {
G.recurse_flags = ACTION_RECURSE; \
} while (0)
-#if ENABLE_FEATURE_FIND_EXEC
-static unsigned count_subst(const char *str)
-{
- unsigned count = 0;
- while ((str = strstr(str, "{}")) != NULL) {
- count++;
- str++;
- }
- return count;
-}
-
-
-static char* subst(const char *src, unsigned count, const char* filename)
-{
- char *buf, *dst, *end;
- size_t flen = strlen(filename);
- /* we replace each '{}' with filename: growth by strlen-2 */
- buf = dst = xmalloc(strlen(src) + count*(flen-2) + 1);
- while ((end = strstr(src, "{}")) != NULL) {
- dst = mempcpy(dst, src, end - src);
- dst = mempcpy(dst, filename, flen);
- src = end + 2;
- }
- strcpy(dst, src);
- return buf;
-}
-#endif
-
/* Return values of ACTFs ('action functions') are a bit mask:
* bit 1=1: prune (use SKIP constant for setting it)
* bit 0=1: matched successfully (TRUE)
@@ -613,7 +585,7 @@ ACTF(exec)
char *argv[ap->exec_argc + 1];
#endif
for (i = 0; i < ap->exec_argc; i++)
- argv[i] = subst(ap->exec_argv[i], ap->subst_count[i], fileName);
+ argv[i] = xmalloc_substitute_string(ap->exec_argv[i], ap->subst_count[i], "{}", fileName);
argv[i] = NULL; /* terminate the list */
rc = spawn_and_wait(argv);
@@ -1091,7 +1063,7 @@ static action*** parse_params(char **argv)
ap->subst_count = xmalloc(ap->exec_argc * sizeof(int));
i = ap->exec_argc;
while (i--)
- ap->subst_count[i] = count_subst(ap->exec_argv[i]);
+ ap->subst_count[i] = count_strstr(ap->exec_argv[i], "{}");
}
#endif
#if ENABLE_FEATURE_FIND_PAREN