summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Fox2006-05-12 14:47:20 +0000
committerPaul Fox2006-05-12 14:47:20 +0000
commitd7384296f621e39e2fd86e6e3aae7e743b0aee65 (patch)
tree6899ecf80d354cafe43ba2697b1bcb0b98df60bb
parentf7897ec47babe54f0b57ab81873ff82fd3e1ea5b (diff)
downloadbusybox-d7384296f621e39e2fd86e6e3aae7e743b0aee65.zip
busybox-d7384296f621e39e2fd86e6e3aae7e743b0aee65.tar.gz
implement -print0 for find
-rw-r--r--findutils/Config.in10
-rw-r--r--findutils/find.c11
-rw-r--r--include/usage.h4
3 files changed, 24 insertions, 1 deletions
diff --git a/findutils/Config.in b/findutils/Config.in
index 3a9a506..8329a6c 100644
--- a/findutils/Config.in
+++ b/findutils/Config.in
@@ -11,6 +11,16 @@ config CONFIG_FIND
help
find is used to search your system to find specified files.
+config CONFIG_FEATURE_FIND_PRINT0
+ bool "Enable -print0 option"
+ default y
+ depends on CONFIG_FIND
+ help
+ Causes output names to be separated by a null character
+ rather than a newline. This allows names that contain
+ newlines and other whitespace to be more easily
+ interpreted by other programs.
+
config CONFIG_FEATURE_FIND_MTIME
bool "Enable modified time matching (-mtime) option"
default y
diff --git a/findutils/find.c b/findutils/find.c
index 7a71af9..17a1a56 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -38,6 +38,9 @@ static const char msg_req_arg[] = "option `%s' requires an argument";
static const char msg_invalid_arg[] = "invalid argument `%s' to `%s'";
static char *pattern;
+#ifdef CONFIG_FEATURE_FIND_PRINT0
+static char printsep = '\n';
+#endif
#ifdef CONFIG_FEATURE_FIND_TYPE
static int type_mask = 0;
@@ -159,7 +162,11 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
}
#endif
+#ifdef CONFIG_FEATURE_FIND_PRINT0
+ printf("%s%c", fileName, printsep);
+#else
puts(fileName);
+#endif
no_match:
return (TRUE);
}
@@ -217,6 +224,10 @@ int find_main(int argc, char **argv)
else if (strcmp(argv[i], "-print") == 0) {
;
}
+#ifdef CONFIG_FEATURE_FIND_PRINT0
+ else if (strcmp(argv[i], "-print0") == 0)
+ printsep = '\0';
+#endif
else if (strcmp(argv[i], "-name") == 0) {
if (++i == argc)
bb_error_msg_and_die(msg_req_arg, "-name");
diff --git a/include/usage.h b/include/usage.h
index d09c110..0e3ecae 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -748,7 +748,9 @@ USE_FEATURE_DATE_ISOFMT( \
"\t-follow\t\tDereference symbolic links\n" \
"\t-name PATTERN\tFile name (leading directories removed) matches PATTERN\n" \
"\t-print\t\tPrint (default and assumed)\n" \
- USE_FEATURE_FIND_TYPE( \
+ USE_FEATURE_FIND_PRINT0( \
+ "\t-print0\t\tDelimit output with null characters rather than\n\t\t\tnewlines" \
+) USE_FEATURE_FIND_TYPE( \
"\n\t-type X\t\tFiletype matches X (where X is one of: f,d,l,b,c,...)" \
) USE_FEATURE_FIND_PERM( \
"\n\t-perm PERMS\tPermissions match any of (+NNN); all of (-NNN);\n\t\t\tor exactly (NNN)" \