aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-03-08 16:14:46 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-03-08 16:14:46 +0000
commita12a9dc1528e9073ce3d00c9fd6d8f73531d0f73 (patch)
treeec8696c1a863b042d9798c6bb6104d293a7794b6 /coreutils
parent49399b9218031ed1e7adaad07eb351ef3b953e42 (diff)
downloadbusybox-w32-a12a9dc1528e9073ce3d00c9fd6d8f73531d0f73.tar.gz
busybox-w32-a12a9dc1528e9073ce3d00c9fd6d8f73531d0f73.tar.bz2
busybox-w32-a12a9dc1528e9073ce3d00c9fd6d8f73531d0f73.zip
chown: fix comment, fix verbose message
git-svn-id: svn://busybox.net/trunk/busybox@18037 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/chown.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/coreutils/chown.c b/coreutils/chown.c
index 439b62ac8..15d2faeae 100644
--- a/coreutils/chown.c
+++ b/coreutils/chown.c
@@ -7,7 +7,7 @@
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 */ 8 */
9 9
10/* BB_AUDIT SUSv3 defects - unsupported options -H, -L, and -P. */ 10/* BB_AUDIT SUSv3 defects - none? */
11/* BB_AUDIT GNU defects - unsupported long options. */ 11/* BB_AUDIT GNU defects - unsupported long options. */
12/* http://www.opengroup.org/onlinepubs/007904975/utilities/chown.html */ 12/* http://www.opengroup.org/onlinepubs/007904975/utilities/chown.html */
13 13
@@ -19,9 +19,6 @@ static int (*chown_func)(const char *, uid_t, gid_t) = chown;
19 19
20#define OPT_STR ("Rh" USE_DESKTOP("vcfLHP")) 20#define OPT_STR ("Rh" USE_DESKTOP("vcfLHP"))
21#define BIT_RECURSE 1 21#define BIT_RECURSE 1
22#define BIT_NODEREF 2
23#define BIT_TRAVERSE 0x20
24#define BIT_TRAVERSETOP (0x20|0x40)
25#define OPT_RECURSE (option_mask32 & 1) 22#define OPT_RECURSE (option_mask32 & 1)
26#define OPT_NODEREF (option_mask32 & 2) 23#define OPT_NODEREF (option_mask32 & 2)
27#define OPT_VERBOSE (USE_DESKTOP(option_mask32 & 0x04) SKIP_DESKTOP(0)) 24#define OPT_VERBOSE (USE_DESKTOP(option_mask32 & 0x04) SKIP_DESKTOP(0))
@@ -35,22 +32,24 @@ static int (*chown_func)(const char *, uid_t, gid_t) = chown;
35 * "Specifying more than one of -H, -L, and -P is not an error. 32 * "Specifying more than one of -H, -L, and -P is not an error.
36 * The last option specified shall determine the behavior of the utility." */ 33 * The last option specified shall determine the behavior of the utility." */
37/* -L */ 34/* -L */
38#define OPT_TRAVERSE (USE_DESKTOP(option_mask32 & BIT_TRAVERSE) SKIP_DESKTOP(0)) 35#define BIT_TRAVERSE 0x20
36#define OPT_TRAVERSE (USE_DESKTOP(option_mask32 & BIT_TRAVERSE) SKIP_DESKTOP(0))
39/* -H or -L */ 37/* -H or -L */
40#define OPT_TRAVERSETOP (USE_DESKTOP(option_mask32 & BIT_TRAVERSETOP) SKIP_DESKTOP(0)) 38#define BIT_TRAVERSE_TOP (0x20|0x40)
39#define OPT_TRAVERSE_TOP (USE_DESKTOP(option_mask32 & BIT_TRAVERSE_TOP) SKIP_DESKTOP(0))
41 40
42static int fileAction(const char *fileName, struct stat *statbuf, 41static int fileAction(const char *fileName, struct stat *statbuf,
43 void ATTRIBUTE_UNUSED *junk, int depth) 42 void ATTRIBUTE_UNUSED *junk, int depth)
44{ 43{
45 if (!chown_func(fileName, 44 uid_t u = (ugid.uid == (uid_t)-1) ? statbuf->st_uid : ugid.uid;
46 (ugid.uid == (uid_t)-1) ? statbuf->st_uid : ugid.uid, 45 gid_t g = (ugid.gid == (gid_t)-1) ? statbuf->st_gid : ugid.gid;
47 (ugid.gid == (gid_t)-1) ? statbuf->st_gid : ugid.gid) 46
48 ) { 47 if (!chown_func(fileName, u, g)) {
49 if (OPT_VERBOSE 48 if (OPT_VERBOSE
50 || (OPT_CHANGED && (statbuf->st_uid != ugid.uid || statbuf->st_gid != ugid.gid)) 49 || (OPT_CHANGED && (statbuf->st_uid != u || statbuf->st_gid != g))
51 ) { 50 ) {
52 printf("changed ownership of '%s' to %u:%u\n", 51 printf("changed ownership of '%s' to %u:%u\n",
53 fileName, ugid.uid, ugid.gid); 52 fileName, (unsigned)u, (unsigned)g);
54 } 53 }
55 return TRUE; 54 return TRUE;
56 } 55 }
@@ -70,8 +69,8 @@ int chown_main(int argc, char **argv)
70 69
71 /* This matches coreutils behavior (almost - see below) */ 70 /* This matches coreutils behavior (almost - see below) */
72 if (OPT_NODEREF 71 if (OPT_NODEREF
73 /* || (OPT_RECURSE && !OPT_TRAVERSETOP): */ 72 /* || (OPT_RECURSE && !OPT_TRAVERSE_TOP): */
74 USE_DESKTOP( || (option_mask32 & (BIT_RECURSE|BIT_TRAVERSETOP)) == BIT_RECURSE) 73 USE_DESKTOP( || (option_mask32 & (BIT_RECURSE|BIT_TRAVERSE_TOP)) == BIT_RECURSE)
75 ) { 74 ) {
76 chown_func = lchown; 75 chown_func = lchown;
77 } 76 }
@@ -83,7 +82,7 @@ int chown_main(int argc, char **argv)
83 do { 82 do {
84 char *arg = *argv; 83 char *arg = *argv;
85 84
86 if (OPT_TRAVERSETOP) { 85 if (OPT_TRAVERSE_TOP) {
87 /* resolves symlink (even recursive) */ 86 /* resolves symlink (even recursive) */
88 arg = xmalloc_realpath(arg); 87 arg = xmalloc_realpath(arg);
89 if (!arg) 88 if (!arg)
@@ -102,7 +101,7 @@ int chown_main(int argc, char **argv)
102 retval = EXIT_FAILURE; 101 retval = EXIT_FAILURE;
103 } 102 }
104 103
105 if (OPT_TRAVERSETOP) 104 if (OPT_TRAVERSE_TOP)
106 free(arg); 105 free(arg);
107 } while (*++argv); 106 } while (*++argv);
108 107