find: small improvement

This commit is contained in:
Denis Vlasenko 2006-10-29 19:03:56 +00:00
parent df0553bbd2
commit e2fb719ba3

View File

@ -30,6 +30,8 @@
* file.txt file.txt * file.txt file.txt
* file.txt * file.txt
* /tmp * /tmp
* # find -name '*.c' -o -name '*.h'
* [shows files, *.c and *.h intermixed]
*/ */
#include "busybox.h" #include "busybox.h"
@ -93,7 +95,6 @@ static char* subst(const char *src, int count, const char* filename)
{ {
char *buf, *dst, *end; char *buf, *dst, *end;
int flen = strlen(filename); int flen = strlen(filename);
//puts(src);
/* we replace each '{}' with filename: growth by strlen-2 */ /* we replace each '{}' with filename: growth by strlen-2 */
buf = dst = xmalloc(strlen(src) + count*(flen-2) + 1); buf = dst = xmalloc(strlen(src) + count*(flen-2) + 1);
while ((end = strstr(src, "{}"))) { while ((end = strstr(src, "{}"))) {
@ -104,7 +105,6 @@ static char* subst(const char *src, int count, const char* filename)
dst += flen; dst += flen;
} }
strcpy(dst, src); strcpy(dst, src);
//puts(buf);
return buf; return buf;
} }
@ -363,16 +363,20 @@ int find_main(int argc, char **argv)
} }
if (firstopt == 1) { if (firstopt == 1) {
if (!recursive_action(".", TRUE, dereference, FALSE, fileAction, static const char *const dot[] = { ".", NULL };
fileAction, NULL, 0)) firstopt++;
status = EXIT_FAILURE; argv = (char**)dot - 1;
} else { }
for (i = 1; i < firstopt; i++) { for (i = 1; i < firstopt; i++) {
if (!recursive_action(argv[i], TRUE, dereference, FALSE, if (!recursive_action(argv[i],
fileAction, fileAction, NULL, 0)) TRUE, // recurse
status = EXIT_FAILURE; dereference, // follow links
} FALSE, // depth first
fileAction, // file action
fileAction, // dir action
NULL, // user data
0)) // depth
status = EXIT_FAILURE;
} }
return status; return status;
} }