diff options
author | Eric Andersen <andersen@codepoet.org> | 2003-01-23 05:27:42 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2003-01-23 05:27:42 +0000 |
commit | 97d86f2bb59751be52fb3ee5cdb8b06e7b3bb98f (patch) | |
tree | 68724d2a1026005a4ab84f2dcf161b7fa09f4d97 /findutils/find.c | |
parent | be65c350ae535f80ea369be5366e09f730ab7ba8 (diff) | |
download | busybox-w32-97d86f2bb59751be52fb3ee5cdb8b06e7b3bb98f.tar.gz busybox-w32-97d86f2bb59751be52fb3ee5cdb8b06e7b3bb98f.tar.bz2 busybox-w32-97d86f2bb59751be52fb3ee5cdb8b06e7b3bb98f.zip |
Apply patch from Ghozlane Toumi to add -inum support to find.
Apply patch from Ghozlane Toumi to make find smaller by combining
similar error messages
Forward port find -newer support from busybox stable that was
missing from unstable. -Erik.
Fixup usage messages for find. -Erik
Diffstat (limited to 'findutils/find.c')
-rw-r--r-- | findutils/find.c | 60 |
1 files changed, 49 insertions, 11 deletions
diff --git a/findutils/find.c b/findutils/find.c index b0f4bca6b..048aac503 100644 --- a/findutils/find.c +++ b/findutils/find.c | |||
@@ -34,6 +34,9 @@ | |||
34 | #include <ctype.h> | 34 | #include <ctype.h> |
35 | #include "busybox.h" | 35 | #include "busybox.h" |
36 | 36 | ||
37 | //XXX just found out about libbb/messages.c . maybe move stuff there ? - ghoz | ||
38 | const char msg_req_arg[] = "option `%s' requires an argument"; | ||
39 | const char msg_invalid_arg[] = "invalid argument `%s' to `%s'"; | ||
37 | 40 | ||
38 | static char *pattern; | 41 | static char *pattern; |
39 | 42 | ||
@@ -56,6 +59,13 @@ static dev_t *xdev_dev; | |||
56 | static int xdev_count = 0; | 59 | static int xdev_count = 0; |
57 | #endif | 60 | #endif |
58 | 61 | ||
62 | #ifdef CONFIG_FEATURE_FIND_NEWER | ||
63 | time_t newer_mtime; | ||
64 | #endif | ||
65 | |||
66 | #ifdef CONFIG_FEATURE_FIND_INUM | ||
67 | static ino_t inode_num; | ||
68 | #endif | ||
59 | 69 | ||
60 | static int fileAction(const char *fileName, struct stat *statbuf, void* junk) | 70 | static int fileAction(const char *fileName, struct stat *statbuf, void* junk) |
61 | { | 71 | { |
@@ -109,7 +119,19 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk) | |||
109 | } | 119 | } |
110 | } | 120 | } |
111 | #endif | 121 | #endif |
112 | 122 | #ifdef CONFIG_FEATURE_FIND_NEWER | |
123 | if (newer_mtime != 0) { | ||
124 | time_t file_age = newer_mtime - statbuf->st_mtime; | ||
125 | if (file_age >= 0) | ||
126 | goto no_match; | ||
127 | } | ||
128 | #endif | ||
129 | #ifdef CONFIG_FEATURE_FIND_INUM | ||
130 | if (inode_num != 0) { | ||
131 | if (!(statbuf->st_ino == inode_num)) | ||
132 | goto no_match; | ||
133 | } | ||
134 | #endif | ||
113 | puts(fileName); | 135 | puts(fileName); |
114 | no_match: | 136 | no_match: |
115 | return (TRUE); | 137 | return (TRUE); |
@@ -145,7 +167,7 @@ static int find_type(char *type) | |||
145 | } | 167 | } |
146 | 168 | ||
147 | if (mask == 0 || type[1] != '\0') | 169 | if (mask == 0 || type[1] != '\0') |
148 | error_msg_and_die("invalid argument `%s' to `-type'", type); | 170 | error_msg_and_die(msg_invalid_arg, type, "-type"); |
149 | 171 | ||
150 | return mask; | 172 | return mask; |
151 | } | 173 | } |
@@ -170,24 +192,22 @@ int find_main(int argc, char **argv) | |||
170 | } | 192 | } |
171 | else if (strcmp(argv[i], "-name") == 0) { | 193 | else if (strcmp(argv[i], "-name") == 0) { |
172 | if (++i == argc) | 194 | if (++i == argc) |
173 | error_msg_and_die("option `-name' requires an argument"); | 195 | error_msg_and_die(msg_req_arg, "-name"); |
174 | pattern = argv[i]; | 196 | pattern = argv[i]; |
175 | #ifdef CONFIG_FEATURE_FIND_TYPE | 197 | #ifdef CONFIG_FEATURE_FIND_TYPE |
176 | } else if (strcmp(argv[i], "-type") == 0) { | 198 | } else if (strcmp(argv[i], "-type") == 0) { |
177 | if (++i == argc) | 199 | if (++i == argc) |
178 | error_msg_and_die("option `-type' requires an argument"); | 200 | error_msg_and_die(msg_req_arg, "-type"); |
179 | type_mask = find_type(argv[i]); | 201 | type_mask = find_type(argv[i]); |
180 | #endif | 202 | #endif |
181 | #ifdef CONFIG_FEATURE_FIND_PERM | 203 | #ifdef CONFIG_FEATURE_FIND_PERM |
182 | } else if (strcmp(argv[i], "-perm") == 0) { | 204 | } else if (strcmp(argv[i], "-perm") == 0) { |
183 | char *end; | 205 | char *end; |
184 | if (++i == argc) | 206 | if (++i == argc) |
185 | error_msg_and_die("option `-perm' requires an argument"); | 207 | error_msg_and_die(msg_req_arg, "-perm"); |
186 | perm_mask = strtol(argv[i], &end, 8); | 208 | perm_mask = strtol(argv[i], &end, 8); |
187 | if (end[0] != '\0') | 209 | if ((end[0] != '\0') || (perm_mask > 07777)) |
188 | error_msg_and_die("invalid argument `%s' to `-perm'", argv[i]); | 210 | error_msg_and_die(msg_invalid_arg, argv[i], "-perm"); |
189 | if (perm_mask > 07777) | ||
190 | error_msg_and_die("invalid argument `%s' to `-perm'", argv[i]); | ||
191 | if ((perm_char = argv[i][0]) == '-') | 211 | if ((perm_char = argv[i][0]) == '-') |
192 | perm_mask = -perm_mask; | 212 | perm_mask = -perm_mask; |
193 | #endif | 213 | #endif |
@@ -195,10 +215,10 @@ int find_main(int argc, char **argv) | |||
195 | } else if (strcmp(argv[i], "-mtime") == 0) { | 215 | } else if (strcmp(argv[i], "-mtime") == 0) { |
196 | char *end; | 216 | char *end; |
197 | if (++i == argc) | 217 | if (++i == argc) |
198 | error_msg_and_die("option `-mtime' requires an argument"); | 218 | error_msg_and_die(msg_req_arg, "-mtime"); |
199 | mtime_days = strtol(argv[i], &end, 10); | 219 | mtime_days = strtol(argv[i], &end, 10); |
200 | if (end[0] != '\0') | 220 | if (end[0] != '\0') |
201 | error_msg_and_die("invalid argument `%s' to `-mtime'", argv[i]); | 221 | error_msg_and_die(msg_invalid_arg, argv[i], "-mtime"); |
202 | if ((mtime_char = argv[i][0]) == '-') | 222 | if ((mtime_char = argv[i][0]) == '-') |
203 | mtime_days = -mtime_days; | 223 | mtime_days = -mtime_days; |
204 | #endif | 224 | #endif |
@@ -223,6 +243,24 @@ int find_main(int argc, char **argv) | |||
223 | } | 243 | } |
224 | } | 244 | } |
225 | #endif | 245 | #endif |
246 | #ifdef CONFIG_FEATURE_FIND_NEWER | ||
247 | } else if (strcmp(argv[i], "-newer") == 0) { | ||
248 | struct stat stat_newer; | ||
249 | if (++i == argc) | ||
250 | error_msg_and_die(msg_req_arg, "-newer"); | ||
251 | if (stat (argv[i], &stat_newer) != 0) | ||
252 | error_msg_and_die("file %s not found", argv[i]); | ||
253 | newer_mtime = stat_newer.st_mtime; | ||
254 | #endif | ||
255 | #ifdef CONFIG_FEATURE_FIND_INUM | ||
256 | } else if (strcmp(argv[i], "-inum") == 0) { | ||
257 | char *end; | ||
258 | if (++i == argc) | ||
259 | error_msg_and_die(msg_req_arg, "-inum"); | ||
260 | inode_num = strtol(argv[i], &end, 10); | ||
261 | if (end[0] != '\0') | ||
262 | error_msg_and_die(msg_invalid_arg, argv[i], "-inum"); | ||
263 | #endif | ||
226 | } else | 264 | } else |
227 | show_usage(); | 265 | show_usage(); |
228 | } | 266 | } |