diff options
-rw-r--r-- | chown.c | 14 | ||||
-rw-r--r-- | coreutils/chown.c | 14 |
2 files changed, 22 insertions, 6 deletions
@@ -36,9 +36,11 @@ | |||
36 | static long uid; | 36 | static long uid; |
37 | static long gid; | 37 | static long gid; |
38 | 38 | ||
39 | static int (*chown_func)() = chown; | ||
40 | |||
39 | static int fileAction(const char *fileName, struct stat *statbuf, void* junk) | 41 | static int fileAction(const char *fileName, struct stat *statbuf, void* junk) |
40 | { | 42 | { |
41 | if (lchown(fileName, uid, (gid == -1) ? statbuf->st_gid : gid) == 0) { | 43 | if (chown_func(fileName, uid, (gid == -1) ? statbuf->st_gid : gid) == 0) { |
42 | return (TRUE); | 44 | return (TRUE); |
43 | } | 45 | } |
44 | perror(fileName); | 46 | perror(fileName); |
@@ -48,21 +50,27 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk) | |||
48 | int chown_main(int argc, char **argv) | 50 | int chown_main(int argc, char **argv) |
49 | { | 51 | { |
50 | int opt; | 52 | int opt; |
51 | int recursiveFlag = FALSE; | 53 | int recursiveFlag = FALSE, |
54 | noderefFlag = FALSE; | ||
52 | char *groupName=NULL; | 55 | char *groupName=NULL; |
53 | char *p=NULL; | 56 | char *p=NULL; |
54 | 57 | ||
55 | /* do normal option parsing */ | 58 | /* do normal option parsing */ |
56 | while ((opt = getopt(argc, argv, "R")) > 0) { | 59 | while ((opt = getopt(argc, argv, "Rh")) > 0) { |
57 | switch (opt) { | 60 | switch (opt) { |
58 | case 'R': | 61 | case 'R': |
59 | recursiveFlag = TRUE; | 62 | recursiveFlag = TRUE; |
60 | break; | 63 | break; |
64 | case 'h': | ||
65 | noderefFlag = TRUE; | ||
66 | break; | ||
61 | default: | 67 | default: |
62 | show_usage(); | 68 | show_usage(); |
63 | } | 69 | } |
64 | } | 70 | } |
65 | 71 | ||
72 | if (noderefFlag) chown_func = lchown; | ||
73 | |||
66 | if (argc > optind && argc > 2 && argv[optind]) { | 74 | if (argc > optind && argc > 2 && argv[optind]) { |
67 | /* First, check if there is a group name here */ | 75 | /* First, check if there is a group name here */ |
68 | groupName = strchr(argv[optind], '.'); | 76 | groupName = strchr(argv[optind], '.'); |
diff --git a/coreutils/chown.c b/coreutils/chown.c index 011403378..a65607204 100644 --- a/coreutils/chown.c +++ b/coreutils/chown.c | |||
@@ -36,9 +36,11 @@ | |||
36 | static long uid; | 36 | static long uid; |
37 | static long gid; | 37 | static long gid; |
38 | 38 | ||
39 | static int (*chown_func)() = chown; | ||
40 | |||
39 | static int fileAction(const char *fileName, struct stat *statbuf, void* junk) | 41 | static int fileAction(const char *fileName, struct stat *statbuf, void* junk) |
40 | { | 42 | { |
41 | if (lchown(fileName, uid, (gid == -1) ? statbuf->st_gid : gid) == 0) { | 43 | if (chown_func(fileName, uid, (gid == -1) ? statbuf->st_gid : gid) == 0) { |
42 | return (TRUE); | 44 | return (TRUE); |
43 | } | 45 | } |
44 | perror(fileName); | 46 | perror(fileName); |
@@ -48,21 +50,27 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk) | |||
48 | int chown_main(int argc, char **argv) | 50 | int chown_main(int argc, char **argv) |
49 | { | 51 | { |
50 | int opt; | 52 | int opt; |
51 | int recursiveFlag = FALSE; | 53 | int recursiveFlag = FALSE, |
54 | noderefFlag = FALSE; | ||
52 | char *groupName=NULL; | 55 | char *groupName=NULL; |
53 | char *p=NULL; | 56 | char *p=NULL; |
54 | 57 | ||
55 | /* do normal option parsing */ | 58 | /* do normal option parsing */ |
56 | while ((opt = getopt(argc, argv, "R")) > 0) { | 59 | while ((opt = getopt(argc, argv, "Rh")) > 0) { |
57 | switch (opt) { | 60 | switch (opt) { |
58 | case 'R': | 61 | case 'R': |
59 | recursiveFlag = TRUE; | 62 | recursiveFlag = TRUE; |
60 | break; | 63 | break; |
64 | case 'h': | ||
65 | noderefFlag = TRUE; | ||
66 | break; | ||
61 | default: | 67 | default: |
62 | show_usage(); | 68 | show_usage(); |
63 | } | 69 | } |
64 | } | 70 | } |
65 | 71 | ||
72 | if (noderefFlag) chown_func = lchown; | ||
73 | |||
66 | if (argc > optind && argc > 2 && argv[optind]) { | 74 | if (argc > optind && argc > 2 && argv[optind]) { |
67 | /* First, check if there is a group name here */ | 75 | /* First, check if there is a group name here */ |
68 | groupName = strchr(argv[optind], '.'); | 76 | groupName = strchr(argv[optind], '.'); |