diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-16 00:30:52 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-16 00:30:52 +0000 |
commit | 53a0e971960a520bd859b8aac6dbebec2045115f (patch) | |
tree | 7fbf136ec7cba71b8e463825b32c5ef3a9eb6ce2 | |
parent | b941129ccb7901b0715c6affa9d0347f6fa5e64d (diff) | |
download | busybox-w32-53a0e971960a520bd859b8aac6dbebec2045115f.tar.gz busybox-w32-53a0e971960a520bd859b8aac6dbebec2045115f.tar.bz2 busybox-w32-53a0e971960a520bd859b8aac6dbebec2045115f.zip |
find: make -size match GNU find
-rw-r--r-- | findutils/Config.in | 2 | ||||
-rw-r--r-- | findutils/find.c | 36 | ||||
-rw-r--r-- | include/usage.h | 31 | ||||
-rw-r--r-- | libbb/xatonum_template.c | 4 |
4 files changed, 54 insertions, 19 deletions
diff --git a/findutils/Config.in b/findutils/Config.in index bcdc02446..f8ad98de1 100644 --- a/findutils/Config.in +++ b/findutils/Config.in | |||
@@ -30,7 +30,7 @@ config FEATURE_FIND_MTIME | |||
30 | files, in days. | 30 | files, in days. |
31 | 31 | ||
32 | config FEATURE_FIND_MMIN | 32 | config FEATURE_FIND_MMIN |
33 | bool "Enable modified time matching (-min) option" | 33 | bool "Enable modified time matching (-mmin) option" |
34 | default y | 34 | default y |
35 | depends on FIND | 35 | depends on FIND |
36 | help | 36 | help |
diff --git a/findutils/find.c b/findutils/find.c index 386bc54ad..036d13f4a 100644 --- a/findutils/find.c +++ b/findutils/find.c | |||
@@ -45,6 +45,14 @@ | |||
45 | * (no output) | 45 | * (no output) |
46 | */ | 46 | */ |
47 | 47 | ||
48 | /* Testing script | ||
49 | * ./busybox find "$@" | tee /tmp/bb_find | ||
50 | * echo ================== | ||
51 | * /path/to/gnu/find "$@" | tee /tmp/std_find | ||
52 | * echo ================== | ||
53 | * diff -u /tmp/std_find /tmp/bb_find && echo Identical | ||
54 | */ | ||
55 | |||
48 | #include <fnmatch.h> | 56 | #include <fnmatch.h> |
49 | #include "libbb.h" | 57 | #include "libbb.h" |
50 | #if ENABLE_FEATURE_FIND_REGEX | 58 | #if ENABLE_FEATURE_FIND_REGEX |
@@ -82,7 +90,7 @@ USE_FEATURE_FIND_EXEC( ACTS(exec, char **exec_argv; unsigned *subst_count; int | |||
82 | USE_FEATURE_FIND_USER( ACTS(user, uid_t uid;)) | 90 | USE_FEATURE_FIND_USER( ACTS(user, uid_t uid;)) |
83 | USE_FEATURE_FIND_GROUP( ACTS(group, gid_t gid;)) | 91 | USE_FEATURE_FIND_GROUP( ACTS(group, gid_t gid;)) |
84 | USE_FEATURE_FIND_PAREN( ACTS(paren, action ***subexpr;)) | 92 | USE_FEATURE_FIND_PAREN( ACTS(paren, action ***subexpr;)) |
85 | USE_FEATURE_FIND_SIZE( ACTS(size, off_t size;)) | 93 | USE_FEATURE_FIND_SIZE( ACTS(size, char size_char; off_t size;)) |
86 | USE_FEATURE_FIND_PRUNE( ACTS(prune)) | 94 | USE_FEATURE_FIND_PRUNE( ACTS(prune)) |
87 | USE_FEATURE_FIND_DELETE(ACTS(delete)) | 95 | USE_FEATURE_FIND_DELETE(ACTS(delete)) |
88 | 96 | ||
@@ -314,6 +322,10 @@ ACTF(paren) | |||
314 | #if ENABLE_FEATURE_FIND_SIZE | 322 | #if ENABLE_FEATURE_FIND_SIZE |
315 | ACTF(size) | 323 | ACTF(size) |
316 | { | 324 | { |
325 | if (ap->size_char == '+') | ||
326 | return statbuf->st_size > ap->size; | ||
327 | if (ap->size_char == '-') | ||
328 | return statbuf->st_size < ap->size; | ||
317 | return statbuf->st_size == ap->size; | 329 | return statbuf->st_size == ap->size; |
318 | } | 330 | } |
319 | #endif | 331 | #endif |
@@ -714,11 +726,31 @@ static action*** parse_params(char **argv) | |||
714 | #endif | 726 | #endif |
715 | #if ENABLE_FEATURE_FIND_SIZE | 727 | #if ENABLE_FEATURE_FIND_SIZE |
716 | else if (parm == PARM_size) { | 728 | else if (parm == PARM_size) { |
729 | /* -size n[bckw]: file uses n units of space | ||
730 | * b (default): units are 512-byte blocks | ||
731 | * c: 1 byte | ||
732 | * k: kilobytes | ||
733 | * w: 2-byte words | ||
734 | */ | ||
735 | #if ENABLE_LFS | ||
736 | #define XATOU_SFX xatoull_sfx | ||
737 | #else | ||
738 | #define XATOU_SFX xatoul_sfx | ||
739 | #endif | ||
740 | static const struct suffix_mult find_suffixes[] = { | ||
741 | { "c", 1 }, | ||
742 | { "w", 2 }, | ||
743 | { "b"+1, 512 }, | ||
744 | { "b", 512 }, | ||
745 | { "k", 1024 }, | ||
746 | { NULL, 0 } | ||
747 | }; | ||
717 | action_size *ap; | 748 | action_size *ap; |
718 | if (!*++argv) | 749 | if (!*++argv) |
719 | bb_error_msg_and_die(bb_msg_requires_arg, arg); | 750 | bb_error_msg_and_die(bb_msg_requires_arg, arg); |
720 | ap = ALLOC_ACTION(size); | 751 | ap = ALLOC_ACTION(size); |
721 | ap->size = XATOOFF(arg1); | 752 | ap->size_char = arg1[0]; |
753 | ap->size = XATOU_SFX(plus_minus_num(arg1), find_suffixes); | ||
722 | } | 754 | } |
723 | #endif | 755 | #endif |
724 | #if ENABLE_FEATURE_FIND_PRUNE | 756 | #if ENABLE_FEATURE_FIND_PRUNE |
diff --git a/include/usage.h b/include/usage.h index 8c438e285..1c4442e33 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -948,15 +948,15 @@ | |||
948 | USE_FEATURE_FIND_MAXDEPTH( \ | 948 | USE_FEATURE_FIND_MAXDEPTH( \ |
949 | "\n -maxdepth N Descend at most N levels. -maxdepth 0 applies" \ | 949 | "\n -maxdepth N Descend at most N levels. -maxdepth 0 applies" \ |
950 | "\n tests/actions to command line arguments only") \ | 950 | "\n tests/actions to command line arguments only") \ |
951 | "\n -name PATTERN File name (leading directories removed) matches PATTERN" \ | 951 | "\n -name PATTERN File name (w/o directory name) matches PATTERN" \ |
952 | "\n -print Print (default and assumed)" \ | 952 | USE_FEATURE_FIND_PATH( \ |
953 | USE_FEATURE_FIND_PRINT0( \ | 953 | "\n -path PATTERN Path matches PATTERN") \ |
954 | "\n -print0 Delimit output with null characters rather than" \ | 954 | USE_FEATURE_FIND_REGEX( \ |
955 | "\n newlines") \ | 955 | "\n -regex PATTERN Path matches regex PATTERN") \ |
956 | USE_FEATURE_FIND_TYPE( \ | 956 | USE_FEATURE_FIND_TYPE( \ |
957 | "\n -type X Filetype matches X (where X is one of: f,d,l,b,c,...)") \ | 957 | "\n -type X File type is X (X is one of: f,d,l,b,c,...)") \ |
958 | USE_FEATURE_FIND_PERM( \ | 958 | USE_FEATURE_FIND_PERM( \ |
959 | "\n -perm PERMS Permissions match any of (+NNN), all of (-NNN)," \ | 959 | "\n -perm NNN Permissions match any of (+NNN), all of (-NNN)," \ |
960 | "\n or exactly (NNN)") \ | 960 | "\n or exactly (NNN)") \ |
961 | USE_FEATURE_FIND_MTIME( \ | 961 | USE_FEATURE_FIND_MTIME( \ |
962 | "\n -mtime DAYS Modified time is greater than (+N), less than (-N)," \ | 962 | "\n -mtime DAYS Modified time is greater than (+N), less than (-N)," \ |
@@ -968,23 +968,26 @@ | |||
968 | "\n -newer FILE Modified time is more recent than FILE's") \ | 968 | "\n -newer FILE Modified time is more recent than FILE's") \ |
969 | USE_FEATURE_FIND_INUM( \ | 969 | USE_FEATURE_FIND_INUM( \ |
970 | "\n -inum N File has inode number N") \ | 970 | "\n -inum N File has inode number N") \ |
971 | USE_FEATURE_FIND_EXEC( \ | ||
972 | "\n -exec CMD Execute CMD with all instances of {} replaced by the" \ | ||
973 | "\n files matching EXPRESSION") \ | ||
974 | USE_FEATURE_FIND_USER( \ | 971 | USE_FEATURE_FIND_USER( \ |
975 | "\n -user NAME File is owned by user NAME (numeric user ID allowed)") \ | 972 | "\n -user NAME File is owned by user NAME (numeric user ID allowed)") \ |
976 | USE_FEATURE_FIND_GROUP( \ | 973 | USE_FEATURE_FIND_GROUP( \ |
977 | "\n -group NAME File belongs to group NAME (numeric group ID allowed)") \ | 974 | "\n -group NAME File belongs to group NAME (numeric group ID allowed)") \ |
978 | USE_FEATURE_FIND_DEPTH( \ | 975 | USE_FEATURE_FIND_DEPTH( \ |
979 | "\n -depth Process directory after traversing it") \ | 976 | "\n -depth Process directory name after traversing it") \ |
980 | USE_FEATURE_FIND_SIZE( \ | 977 | USE_FEATURE_FIND_SIZE( \ |
981 | "\n -size N File size is N") \ | 978 | "\n -size N[bck] File size is N (c:bytes,k:kbytes,b:512 bytes(def.))." \ |
979 | "\n +/-N: file size is bigger/smaller than N") \ | ||
980 | "\n -print Print (default and assumed)" \ | ||
981 | USE_FEATURE_FIND_PRINT0( \ | ||
982 | "\n -print0 Delimit output with null characters rather than" \ | ||
983 | "\n newlines") \ | ||
984 | USE_FEATURE_FIND_EXEC( \ | ||
985 | "\n -exec CMD ARG ; Execute CMD with all instances of {} replaced by the" \ | ||
986 | "\n matching files") \ | ||
982 | USE_FEATURE_FIND_PRUNE( \ | 987 | USE_FEATURE_FIND_PRUNE( \ |
983 | "\n -prune Stop traversing current subtree") \ | 988 | "\n -prune Stop traversing current subtree") \ |
984 | USE_FEATURE_FIND_DELETE( \ | 989 | USE_FEATURE_FIND_DELETE( \ |
985 | "\n -delete Delete files, turns on -depth option") \ | 990 | "\n -delete Delete files, turns on -depth option") \ |
986 | USE_FEATURE_FIND_PATH( \ | ||
987 | "\n -path Path matches PATTERN") \ | ||
988 | USE_FEATURE_FIND_PAREN( \ | 991 | USE_FEATURE_FIND_PAREN( \ |
989 | "\n (EXPR) Group an expression") \ | 992 | "\n (EXPR) Group an expression") \ |
990 | 993 | ||
diff --git a/libbb/xatonum_template.c b/libbb/xatonum_template.c index ce0199594..bc8116056 100644 --- a/libbb/xatonum_template.c +++ b/libbb/xatonum_template.c | |||
@@ -49,9 +49,8 @@ unsigned type xstrtou(_range_sfx)(const char *numstr, int base, | |||
49 | if (strcmp(suffixes->suffix, e) == 0) { | 49 | if (strcmp(suffixes->suffix, e) == 0) { |
50 | if (XSTR_UTYPE_MAX / suffixes->mult < r) | 50 | if (XSTR_UTYPE_MAX / suffixes->mult < r) |
51 | goto range; /* overflow! */ | 51 | goto range; /* overflow! */ |
52 | ++e; | ||
53 | r *= suffixes->mult; | 52 | r *= suffixes->mult; |
54 | break; | 53 | goto chk_range; |
55 | } | 54 | } |
56 | ++suffixes; | 55 | ++suffixes; |
57 | } | 56 | } |
@@ -61,6 +60,7 @@ unsigned type xstrtou(_range_sfx)(const char *numstr, int base, | |||
61 | It would be easy enough to allow though if desired. */ | 60 | It would be easy enough to allow though if desired. */ |
62 | if (*e) | 61 | if (*e) |
63 | goto inval; | 62 | goto inval; |
63 | chk_range: | ||
64 | /* Finally, check for range limits. */ | 64 | /* Finally, check for range limits. */ |
65 | if (r >= lower && r <= upper) | 65 | if (r >= lower && r <= upper) |
66 | return r; | 66 | return r; |