aboutsummaryrefslogtreecommitdiff
path: root/findutils/find.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2005-10-06 16:39:17 +0000
committerRob Landley <rob@landley.net>2005-10-06 16:39:17 +0000
commitcee605c5253f2ae506ac1ee9e09bec0c2bba30aa (patch)
tree5fbdf1c15e20ed1bb49d2ac877b535ffb547c1bb /findutils/find.c
parent81c3a518d3121ac6a9fc991aabb916be95ebdea2 (diff)
downloadbusybox-w32-cee605c5253f2ae506ac1ee9e09bec0c2bba30aa.tar.gz
busybox-w32-cee605c5253f2ae506ac1ee9e09bec0c2bba30aa.tar.bz2
busybox-w32-cee605c5253f2ae506ac1ee9e09bec0c2bba30aa.zip
The supposedly trivial CONFIG->ENABLE conversion wasn't so trivial. The
-exec feature shouldn't be tangled up with this, so revert everything but the new exec feature for the moment.
Diffstat (limited to 'findutils/find.c')
-rw-r--r--findutils/find.c72
1 files changed, 50 insertions, 22 deletions
diff --git a/findutils/find.c b/findutils/find.c
index 25f57fd4f..75ed4e208 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -39,34 +39,34 @@ static const char msg_invalid_arg[] = "invalid argument `%s' to `%s'";
39 39
40static char *pattern; 40static char *pattern;
41 41
42#if ENABLE_FEATURE_FIND_TYPE 42#ifdef CONFIG_FEATURE_FIND_TYPE
43static int type_mask = 0; 43static int type_mask = 0;
44#endif 44#endif
45 45
46#if ENABLE_FEATURE_FIND_PERM 46#ifdef CONFIG_FEATURE_FIND_PERM
47static char perm_char = 0; 47static char perm_char = 0;
48static int perm_mask = 0; 48static int perm_mask = 0;
49#endif 49#endif
50 50
51#if ENABLE_FEATURE_FIND_MTIME 51#ifdef CONFIG_FEATURE_FIND_MTIME
52static char mtime_char; 52static char mtime_char;
53static int mtime_days; 53static int mtime_days;
54#endif 54#endif
55 55
56#if ENABLE_FEATURE_FIND_XDEV 56#ifdef CONFIG_FEATURE_FIND_XDEV
57static dev_t *xdev_dev; 57static dev_t *xdev_dev;
58static int xdev_count = 0; 58static int xdev_count = 0;
59#endif 59#endif
60 60
61#if ENABLE_FEATURE_FIND_NEWER 61#ifdef CONFIG_FEATURE_FIND_NEWER
62static time_t newer_mtime; 62static time_t newer_mtime;
63#endif 63#endif
64 64
65#if ENABLE_FEATURE_FIND_INUM 65#ifdef CONFIG_FEATURE_FIND_INUM
66static ino_t inode_num; 66static ino_t inode_num;
67#endif 67#endif
68 68
69#if ENABLE_FEATURE_FIND_EXEC 69#ifdef CONFIG_FEATURE_FIND_EXEC
70static char **exec_str; 70static char **exec_str;
71static int num_matches; 71static int num_matches;
72static int exec_opt; 72static int exec_opt;
@@ -84,17 +84,22 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
84 if (!(fnmatch(pattern, tmp, FNM_PERIOD) == 0)) 84 if (!(fnmatch(pattern, tmp, FNM_PERIOD) == 0))
85 goto no_match; 85 goto no_match;
86 } 86 }
87 if (ENABLE_FEATURE_FIND_TYPE && type_mask != 0) { 87#ifdef CONFIG_FEATURE_FIND_TYPE
88 if (type_mask != 0) {
88 if (!((statbuf->st_mode & S_IFMT) == type_mask)) 89 if (!((statbuf->st_mode & S_IFMT) == type_mask))
89 goto no_match; 90 goto no_match;
90 } 91 }
91 if (ENABLE_FEATURE_FIND_PERM && perm_mask != 0) { 92#endif
93#ifdef CONFIG_FEATURE_FIND_PERM
94 if (perm_mask != 0) {
92 if (!((isdigit(perm_char) && (statbuf->st_mode & 07777) == perm_mask) || 95 if (!((isdigit(perm_char) && (statbuf->st_mode & 07777) == perm_mask) ||
93 (perm_char == '-' && (statbuf->st_mode & perm_mask) == perm_mask) || 96 (perm_char == '-' && (statbuf->st_mode & perm_mask) == perm_mask) ||
94 (perm_char == '+' && (statbuf->st_mode & perm_mask) != 0))) 97 (perm_char == '+' && (statbuf->st_mode & perm_mask) != 0)))
95 goto no_match; 98 goto no_match;
96 } 99 }
97 if (ENABLE_FEATURE_FIND_MTIME && mtime_char != 0) { 100#endif
101#ifdef CONFIG_FEATURE_FIND_MTIME
102 if (mtime_char != 0) {
98 time_t file_age = time(NULL) - statbuf->st_mtime; 103 time_t file_age = time(NULL) - statbuf->st_mtime;
99 time_t mtime_secs = mtime_days * 24 * 60 * 60; 104 time_t mtime_secs = mtime_days * 24 * 60 * 60;
100 if (!((isdigit(mtime_char) && file_age >= mtime_secs && 105 if (!((isdigit(mtime_char) && file_age >= mtime_secs &&
@@ -103,7 +108,9 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
103 (mtime_char == '-' && file_age < mtime_secs))) 108 (mtime_char == '-' && file_age < mtime_secs)))
104 goto no_match; 109 goto no_match;
105 } 110 }
106 if (ENABLE_FEATURE_FIND_XDEV && xdev_count) { 111#endif
112#ifdef CONFIG_FEATURE_FIND_XDEV
113 if (xdev_count) {
107 int i; 114 int i;
108 for (i=0; i<xdev_count; i++) { 115 for (i=0; i<xdev_count; i++) {
109 if (xdev_dev[i] == statbuf-> st_dev) 116 if (xdev_dev[i] == statbuf-> st_dev)
@@ -116,16 +123,22 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
116 goto no_match; 123 goto no_match;
117 } 124 }
118 } 125 }
119 if (ENABLE_FEATURE_FIND_NEWER && newer_mtime != 0) { 126#endif
127#ifdef CONFIG_FEATURE_FIND_NEWER
128 if (newer_mtime != 0) {
120 time_t file_age = newer_mtime - statbuf->st_mtime; 129 time_t file_age = newer_mtime - statbuf->st_mtime;
121 if (file_age >= 0) 130 if (file_age >= 0)
122 goto no_match; 131 goto no_match;
123 } 132 }
124 if (ENABLE_FEATURE_FIND_INUM && inode_num != 0) { 133#endif
134#ifdef CONFIG_FEATURE_FIND_INUM
135 if (inode_num != 0) {
125 if (!(statbuf->st_ino == inode_num)) 136 if (!(statbuf->st_ino == inode_num))
126 goto no_match; 137 goto no_match;
127 } 138 }
128 if (ENABLE_FEATURE_FIND_EXEC && exec_opt) { 139#endif
140#ifdef CONFIG_FEATURE_FIND_EXEC
141 if (exec_opt) {
129 int i; 142 int i;
130 char *cmd_string = ""; 143 char *cmd_string = "";
131 for (i = 0; i < num_matches; i++) 144 for (i = 0; i < num_matches; i++)
@@ -134,13 +147,14 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
134 system(cmd_string); 147 system(cmd_string);
135 goto no_match; 148 goto no_match;
136 } 149 }
150#endif
137 151
138 puts(fileName); 152 puts(fileName);
139no_match: 153no_match:
140 return (TRUE); 154 return (TRUE);
141} 155}
142 156
143#if ENABLE_FEATURE_FIND_TYPE 157#ifdef CONFIG_FEATURE_FIND_TYPE
144static int find_type(char *type) 158static int find_type(char *type)
145{ 159{
146 int mask = 0; 160 int mask = 0;
@@ -197,11 +211,14 @@ int find_main(int argc, char **argv)
197 if (++i == argc) 211 if (++i == argc)
198 bb_error_msg_and_die(msg_req_arg, "-name"); 212 bb_error_msg_and_die(msg_req_arg, "-name");
199 pattern = argv[i]; 213 pattern = argv[i];
200 } else if (ENABLE_FEATURE_FIND_TYPE && strcmp(argv[i], "-type") == 0) { 214#ifdef CONFIG_FEATURE_FIND_TYPE
215 } else if (strcmp(argv[i], "-type") == 0) {
201 if (++i == argc) 216 if (++i == argc)
202 bb_error_msg_and_die(msg_req_arg, "-type"); 217 bb_error_msg_and_die(msg_req_arg, "-type");
203 type_mask = find_type(argv[i]); 218 type_mask = find_type(argv[i]);
204 } else if (ENABLE_FEATURE_FIND_PERM && strcmp(argv[i], "-perm") == 0) { 219#endif
220#ifdef CONFIG_FEATURE_FIND_PERM
221 } else if (strcmp(argv[i], "-perm") == 0) {
205 char *end; 222 char *end;
206 if (++i == argc) 223 if (++i == argc)
207 bb_error_msg_and_die(msg_req_arg, "-perm"); 224 bb_error_msg_and_die(msg_req_arg, "-perm");
@@ -210,7 +227,9 @@ int find_main(int argc, char **argv)
210 bb_error_msg_and_die(msg_invalid_arg, argv[i], "-perm"); 227 bb_error_msg_and_die(msg_invalid_arg, argv[i], "-perm");
211 if ((perm_char = argv[i][0]) == '-') 228 if ((perm_char = argv[i][0]) == '-')
212 perm_mask = -perm_mask; 229 perm_mask = -perm_mask;
213 } else if (ENABLE_FEATURE_FIND_MTIME && strcmp(argv[i], "-mtime") == 0) { 230#endif
231#ifdef CONFIG_FEATURE_FIND_MTIME
232 } else if (strcmp(argv[i], "-mtime") == 0) {
214 char *end; 233 char *end;
215 if (++i == argc) 234 if (++i == argc)
216 bb_error_msg_and_die(msg_req_arg, "-mtime"); 235 bb_error_msg_and_die(msg_req_arg, "-mtime");
@@ -219,7 +238,9 @@ int find_main(int argc, char **argv)
219 bb_error_msg_and_die(msg_invalid_arg, argv[i], "-mtime"); 238 bb_error_msg_and_die(msg_invalid_arg, argv[i], "-mtime");
220 if ((mtime_char = argv[i][0]) == '-') 239 if ((mtime_char = argv[i][0]) == '-')
221 mtime_days = -mtime_days; 240 mtime_days = -mtime_days;
222 } else if (ENABLE_FEATURE_FIND_XDEV && strcmp(argv[i], "-xdev") == 0) { 241#endif
242#ifdef CONFIG_FEATURE_FIND_XDEV
243 } else if (strcmp(argv[i], "-xdev") == 0) {
223 struct stat stbuf; 244 struct stat stbuf;
224 245
225 xdev_count = ( firstopt - 1 ) ? ( firstopt - 1 ) : 1; 246 xdev_count = ( firstopt - 1 ) ? ( firstopt - 1 ) : 1;
@@ -238,21 +259,27 @@ int find_main(int argc, char **argv)
238 xdev_dev [i-1] = stbuf. st_dev; 259 xdev_dev [i-1] = stbuf. st_dev;
239 } 260 }
240 } 261 }
241 } else if (ENABLE_FEATURE_FIND_NEWER && strcmp(argv[i], "-newer") == 0) { 262#endif
263#ifdef CONFIG_FEATURE_FIND_NEWER
264 } else if (strcmp(argv[i], "-newer") == 0) {
242 struct stat stat_newer; 265 struct stat stat_newer;
243 if (++i == argc) 266 if (++i == argc)
244 bb_error_msg_and_die(msg_req_arg, "-newer"); 267 bb_error_msg_and_die(msg_req_arg, "-newer");
245 if (stat (argv[i], &stat_newer) != 0) 268 if (stat (argv[i], &stat_newer) != 0)
246 bb_error_msg_and_die("file %s not found", argv[i]); 269 bb_error_msg_and_die("file %s not found", argv[i]);
247 newer_mtime = stat_newer.st_mtime; 270 newer_mtime = stat_newer.st_mtime;
248 } else if (ENABLE_FEATURE_FIND_INUM && strcmp(argv[i], "-inum") == 0) { 271#endif
272#ifdef CONFIG_FEATURE_FIND_INUM
273 } else if (strcmp(argv[i], "-inum") == 0) {
249 char *end; 274 char *end;
250 if (++i == argc) 275 if (++i == argc)
251 bb_error_msg_and_die(msg_req_arg, "-inum"); 276 bb_error_msg_and_die(msg_req_arg, "-inum");
252 inode_num = strtol(argv[i], &end, 10); 277 inode_num = strtol(argv[i], &end, 10);
253 if (end[0] != '\0') 278 if (end[0] != '\0')
254 bb_error_msg_and_die(msg_invalid_arg, argv[i], "-inum"); 279 bb_error_msg_and_die(msg_invalid_arg, argv[i], "-inum");
255 } else if (ENABLE_FEATURE_FIND_EXEC && strcmp(argv[i], "-exec") == 0) { 280#endif
281#ifdef CONFIG_FEATURE_FIND_EXEC
282 } else if (strcmp(argv[i], "-exec") == 0) {
256 int b_pos; 283 int b_pos;
257 char *cmd_string = ""; 284 char *cmd_string = "";
258 285
@@ -277,6 +304,7 @@ int find_main(int argc, char **argv)
277 } 304 }
278 exec_str[num_matches] = bb_xstrdup(cmd_string); 305 exec_str[num_matches] = bb_xstrdup(cmd_string);
279 exec_opt = 1; 306 exec_opt = 1;
307#endif
280 } else 308 } else
281 bb_show_usage(); 309 bb_show_usage();
282 } 310 }