summaryrefslogtreecommitdiff
path: root/coreutils/chown.c
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils/chown.c')
-rw-r--r--coreutils/chown.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/coreutils/chown.c b/coreutils/chown.c
index 15d2faeae..f92299e36 100644
--- a/coreutils/chown.c
+++ b/coreutils/chown.c
@@ -13,10 +13,6 @@
13 13
14#include "busybox.h" 14#include "busybox.h"
15 15
16static struct bb_uidgid_t ugid = { -1, -1 };
17
18static int (*chown_func)(const char *, uid_t, gid_t) = chown;
19
20#define OPT_STR ("Rh" USE_DESKTOP("vcfLHP")) 16#define OPT_STR ("Rh" USE_DESKTOP("vcfLHP"))
21#define BIT_RECURSE 1 17#define BIT_RECURSE 1
22#define OPT_RECURSE (option_mask32 & 1) 18#define OPT_RECURSE (option_mask32 & 1)
@@ -38,13 +34,17 @@ static int (*chown_func)(const char *, uid_t, gid_t) = chown;
38#define BIT_TRAVERSE_TOP (0x20|0x40) 34#define BIT_TRAVERSE_TOP (0x20|0x40)
39#define OPT_TRAVERSE_TOP (USE_DESKTOP(option_mask32 & BIT_TRAVERSE_TOP) SKIP_DESKTOP(0)) 35#define OPT_TRAVERSE_TOP (USE_DESKTOP(option_mask32 & BIT_TRAVERSE_TOP) SKIP_DESKTOP(0))
40 36
37typedef int (*chown_fptr)(const char *, uid_t, gid_t);
38
39static struct bb_uidgid_t ugid = { -1, -1 };
40
41static int fileAction(const char *fileName, struct stat *statbuf, 41static int fileAction(const char *fileName, struct stat *statbuf,
42 void ATTRIBUTE_UNUSED *junk, int depth) 42 void *cf, int depth)
43{ 43{
44 uid_t u = (ugid.uid == (uid_t)-1) ? statbuf->st_uid : ugid.uid; 44 uid_t u = (ugid.uid == (uid_t)-1) ? statbuf->st_uid : ugid.uid;
45 gid_t g = (ugid.gid == (gid_t)-1) ? statbuf->st_gid : ugid.gid; 45 gid_t g = (ugid.gid == (gid_t)-1) ? statbuf->st_gid : ugid.gid;
46 46
47 if (!chown_func(fileName, u, g)) { 47 if (!((chown_fptr)cf)(fileName, u, g)) {
48 if (OPT_VERBOSE 48 if (OPT_VERBOSE
49 || (OPT_CHANGED && (statbuf->st_uid != u || statbuf->st_gid != g)) 49 || (OPT_CHANGED && (statbuf->st_uid != u || statbuf->st_gid != g))
50 ) { 50 ) {
@@ -62,12 +62,14 @@ int chown_main(int argc, char **argv);
62int chown_main(int argc, char **argv) 62int chown_main(int argc, char **argv)
63{ 63{
64 int retval = EXIT_SUCCESS; 64 int retval = EXIT_SUCCESS;
65 chown_fptr chown_func;
65 66
66 opt_complementary = "-2"; 67 opt_complementary = "-2";
67 getopt32(argc, argv, OPT_STR); 68 getopt32(argc, argv, OPT_STR);
68 argv += optind; 69 argv += optind;
69 70
70 /* This matches coreutils behavior (almost - see below) */ 71 /* This matches coreutils behavior (almost - see below) */
72 chown_func = chown;
71 if (OPT_NODEREF 73 if (OPT_NODEREF
72 /* || (OPT_RECURSE && !OPT_TRAVERSE_TOP): */ 74 /* || (OPT_RECURSE && !OPT_TRAVERSE_TOP): */
73 USE_DESKTOP( || (option_mask32 & (BIT_RECURSE|BIT_TRAVERSE_TOP)) == BIT_RECURSE) 75 USE_DESKTOP( || (option_mask32 & (BIT_RECURSE|BIT_TRAVERSE_TOP)) == BIT_RECURSE)
@@ -95,7 +97,7 @@ int chown_main(int argc, char **argv)
95 FALSE, // depth first 97 FALSE, // depth first
96 fileAction, // file action 98 fileAction, // file action
97 fileAction, // dir action 99 fileAction, // dir action
98 NULL, // user data 100 chown_func, // user data
99 0) // depth 101 0) // depth
100 ) { 102 ) {
101 retval = EXIT_FAILURE; 103 retval = EXIT_FAILURE;