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 /findutils | |
parent | b941129ccb7901b0715c6affa9d0347f6fa5e64d (diff) | |
download | busybox-w32-53a0e971960a520bd859b8aac6dbebec2045115f.tar.gz busybox-w32-53a0e971960a520bd859b8aac6dbebec2045115f.tar.bz2 busybox-w32-53a0e971960a520bd859b8aac6dbebec2045115f.zip |
find: make -size match GNU find
Diffstat (limited to 'findutils')
-rw-r--r-- | findutils/Config.in | 2 | ||||
-rw-r--r-- | findutils/find.c | 36 |
2 files changed, 35 insertions, 3 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 |