aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Fox <pgf@brightstareng.com>2006-05-12 14:47:20 +0000
committerPaul Fox <pgf@brightstareng.com>2006-05-12 14:47:20 +0000
commitd7384296f621e39e2fd86e6e3aae7e743b0aee65 (patch)
tree6899ecf80d354cafe43ba2697b1bcb0b98df60bb
parentf7897ec47babe54f0b57ab81873ff82fd3e1ea5b (diff)
downloadbusybox-w32-d7384296f621e39e2fd86e6e3aae7e743b0aee65.tar.gz
busybox-w32-d7384296f621e39e2fd86e6e3aae7e743b0aee65.tar.bz2
busybox-w32-d7384296f621e39e2fd86e6e3aae7e743b0aee65.zip
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 3a9a506d7..8329a6c1f 100644
--- a/findutils/Config.in
+++ b/findutils/Config.in
@@ -11,6 +11,16 @@ config CONFIG_FIND
11 help 11 help
12 find is used to search your system to find specified files. 12 find is used to search your system to find specified files.
13 13
14config CONFIG_FEATURE_FIND_PRINT0
15 bool "Enable -print0 option"
16 default y
17 depends on CONFIG_FIND
18 help
19 Causes output names to be separated by a null character
20 rather than a newline. This allows names that contain
21 newlines and other whitespace to be more easily
22 interpreted by other programs.
23
14config CONFIG_FEATURE_FIND_MTIME 24config CONFIG_FEATURE_FIND_MTIME
15 bool "Enable modified time matching (-mtime) option" 25 bool "Enable modified time matching (-mtime) option"
16 default y 26 default y
diff --git a/findutils/find.c b/findutils/find.c
index 7a71af9eb..17a1a5656 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -38,6 +38,9 @@ static const char msg_req_arg[] = "option `%s' requires an argument";
38static const char msg_invalid_arg[] = "invalid argument `%s' to `%s'"; 38static const char msg_invalid_arg[] = "invalid argument `%s' to `%s'";
39 39
40static char *pattern; 40static char *pattern;
41#ifdef CONFIG_FEATURE_FIND_PRINT0
42static char printsep = '\n';
43#endif
41 44
42#ifdef CONFIG_FEATURE_FIND_TYPE 45#ifdef CONFIG_FEATURE_FIND_TYPE
43static int type_mask = 0; 46static int type_mask = 0;
@@ -159,7 +162,11 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
159 } 162 }
160#endif 163#endif
161 164
165#ifdef CONFIG_FEATURE_FIND_PRINT0
166 printf("%s%c", fileName, printsep);
167#else
162 puts(fileName); 168 puts(fileName);
169#endif
163no_match: 170no_match:
164 return (TRUE); 171 return (TRUE);
165} 172}
@@ -217,6 +224,10 @@ int find_main(int argc, char **argv)
217 else if (strcmp(argv[i], "-print") == 0) { 224 else if (strcmp(argv[i], "-print") == 0) {
218 ; 225 ;
219 } 226 }
227#ifdef CONFIG_FEATURE_FIND_PRINT0
228 else if (strcmp(argv[i], "-print0") == 0)
229 printsep = '\0';
230#endif
220 else if (strcmp(argv[i], "-name") == 0) { 231 else if (strcmp(argv[i], "-name") == 0) {
221 if (++i == argc) 232 if (++i == argc)
222 bb_error_msg_and_die(msg_req_arg, "-name"); 233 bb_error_msg_and_die(msg_req_arg, "-name");
diff --git a/include/usage.h b/include/usage.h
index d09c1108e..0e3ecae05 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -748,7 +748,9 @@ USE_FEATURE_DATE_ISOFMT( \
748 "\t-follow\t\tDereference symbolic links\n" \ 748 "\t-follow\t\tDereference symbolic links\n" \
749 "\t-name PATTERN\tFile name (leading directories removed) matches PATTERN\n" \ 749 "\t-name PATTERN\tFile name (leading directories removed) matches PATTERN\n" \
750 "\t-print\t\tPrint (default and assumed)\n" \ 750 "\t-print\t\tPrint (default and assumed)\n" \
751 USE_FEATURE_FIND_TYPE( \ 751 USE_FEATURE_FIND_PRINT0( \
752 "\t-print0\t\tDelimit output with null characters rather than\n\t\t\tnewlines" \
753) USE_FEATURE_FIND_TYPE( \
752 "\n\t-type X\t\tFiletype matches X (where X is one of: f,d,l,b,c,...)" \ 754 "\n\t-type X\t\tFiletype matches X (where X is one of: f,d,l,b,c,...)" \
753) USE_FEATURE_FIND_PERM( \ 755) USE_FEATURE_FIND_PERM( \
754 "\n\t-perm PERMS\tPermissions match any of (+NNN); all of (-NNN);\n\t\t\tor exactly (NNN)" \ 756 "\n\t-perm PERMS\tPermissions match any of (+NNN); all of (-NNN);\n\t\t\tor exactly (NNN)" \