diff options
author | Robert Griebl <griebl@gmx.de> | 2002-07-24 00:34:48 +0000 |
---|---|---|
committer | Robert Griebl <griebl@gmx.de> | 2002-07-24 00:34:48 +0000 |
commit | 41369af3f2bd415c58266618aa3fd1fe6badacfa (patch) | |
tree | 7f63622ca8a24ec94fae746979a1dfc9be339db3 | |
parent | 80cd3cfdbc924b1a032b0634be8930af3daf791f (diff) | |
download | busybox-w32-41369af3f2bd415c58266618aa3fd1fe6badacfa.tar.gz busybox-w32-41369af3f2bd415c58266618aa3fd1fe6badacfa.tar.bz2 busybox-w32-41369af3f2bd415c58266618aa3fd1fe6badacfa.zip |
Patch for bug #1183: Added a -xdev option to find (configurable)
-rw-r--r-- | findutils/config.in | 1 | ||||
-rw-r--r-- | findutils/find.c | 43 |
2 files changed, 44 insertions, 0 deletions
diff --git a/findutils/config.in b/findutils/config.in index 770d75245..d5a3714d2 100644 --- a/findutils/config.in +++ b/findutils/config.in | |||
@@ -11,6 +11,7 @@ if [ "$CONFIG_FIND" = "y" ] ; then | |||
11 | bool ' Enable modified time matching (-mtime) option' CONFIG_FEATURE_FIND_MTIME | 11 | bool ' Enable modified time matching (-mtime) option' CONFIG_FEATURE_FIND_MTIME |
12 | bool ' Enable permissions matching (-perm) option' CONFIG_FEATURE_FIND_PERM | 12 | bool ' Enable permissions matching (-perm) option' CONFIG_FEATURE_FIND_PERM |
13 | bool ' Enable filetype matching (-type) option' CONFIG_FEATURE_FIND_TYPE | 13 | bool ' Enable filetype matching (-type) option' CONFIG_FEATURE_FIND_TYPE |
14 | bool ' Enable stay in filesystem (-xdev) option' CONFIG_FEATURE_FIND_XDEV | ||
14 | fi | 15 | fi |
15 | bool 'grep' CONFIG_GREP | 16 | bool 'grep' CONFIG_GREP |
16 | if [ "$CONFIG_GREP" = "y" ] ; then | 17 | if [ "$CONFIG_GREP" = "y" ] ; then |
diff --git a/findutils/find.c b/findutils/find.c index 0ff0893a6..dd02206e3 100644 --- a/findutils/find.c +++ b/findutils/find.c | |||
@@ -51,6 +51,12 @@ static char mtime_char; | |||
51 | static int mtime_days; | 51 | static int mtime_days; |
52 | #endif | 52 | #endif |
53 | 53 | ||
54 | #ifdef CONFIG_FEATURE_FIND_XDEV | ||
55 | static dev_t *xdev_dev; | ||
56 | static int xdev_count = 0; | ||
57 | #endif | ||
58 | |||
59 | |||
54 | static int fileAction(const char *fileName, struct stat *statbuf, void* junk) | 60 | static int fileAction(const char *fileName, struct stat *statbuf, void* junk) |
55 | { | 61 | { |
56 | if (pattern != NULL) { | 62 | if (pattern != NULL) { |
@@ -88,6 +94,22 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk) | |||
88 | goto no_match; | 94 | goto no_match; |
89 | } | 95 | } |
90 | #endif | 96 | #endif |
97 | #ifdef CONFIG_FEATURE_FIND_XDEV | ||
98 | if (xdev_count) { | ||
99 | int i; | ||
100 | for (i=0; i<xdev_count; i++) { | ||
101 | if (xdev_dev[i] == statbuf-> st_dev) | ||
102 | break; | ||
103 | } | ||
104 | if (i == xdev_count) { | ||
105 | if(S_ISDIR(statbuf->st_mode)) | ||
106 | return SKIP; | ||
107 | else | ||
108 | goto no_match; | ||
109 | } | ||
110 | } | ||
111 | #endif | ||
112 | |||
91 | puts(fileName); | 113 | puts(fileName); |
92 | no_match: | 114 | no_match: |
93 | return (TRUE); | 115 | return (TRUE); |
@@ -180,6 +202,27 @@ int find_main(int argc, char **argv) | |||
180 | if ((mtime_char = argv[i][0]) == '-') | 202 | if ((mtime_char = argv[i][0]) == '-') |
181 | mtime_days = -mtime_days; | 203 | mtime_days = -mtime_days; |
182 | #endif | 204 | #endif |
205 | #ifdef CONFIG_FEATURE_FIND_XDEV | ||
206 | } else if (strcmp(argv[i], "-xdev") == 0) { | ||
207 | struct stat stbuf; | ||
208 | |||
209 | xdev_count = ( firstopt - 1 ) ? ( firstopt - 1 ) : 1; | ||
210 | xdev_dev = xmalloc ( xdev_count * sizeof( dev_t )); | ||
211 | |||
212 | if ( firstopt == 1 ) { | ||
213 | if ( stat ( ".", &stbuf ) < 0 ) | ||
214 | error_msg_and_die("could not stat '.'" ); | ||
215 | xdev_dev [0] = stbuf. st_dev; | ||
216 | } | ||
217 | else { | ||
218 | |||
219 | for (i = 1; i < firstopt; i++) { | ||
220 | if ( stat ( argv [i], &stbuf ) < 0 ) | ||
221 | error_msg_and_die("could not stat '%s'", argv [i] ); | ||
222 | xdev_dev [i-1] = stbuf. st_dev; | ||
223 | } | ||
224 | } | ||
225 | #endif | ||
183 | } else | 226 | } else |
184 | show_usage(); | 227 | show_usage(); |
185 | } | 228 | } |