diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-27 23:28:38 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-27 23:28:38 +0000 |
| commit | e80e2a3660bf09cc549cb2dfd2bdeb77ccde1231 (patch) | |
| tree | 94303277042044e84dbdc28e2c2457e5b27009d4 | |
| parent | 3b8fc1c582884d356df04b4984db3963bc129c48 (diff) | |
| download | busybox-w32-e80e2a3660bf09cc549cb2dfd2bdeb77ccde1231.tar.gz busybox-w32-e80e2a3660bf09cc549cb2dfd2bdeb77ccde1231.tar.bz2 busybox-w32-e80e2a3660bf09cc549cb2dfd2bdeb77ccde1231.zip | |
chgrp: just call chown! :)
| -rw-r--r-- | coreutils/Kbuild | 2 | ||||
| -rw-r--r-- | coreutils/chgrp.c | 48 | ||||
| -rw-r--r-- | include/usage.h | 10 |
3 files changed, 19 insertions, 41 deletions
diff --git a/coreutils/Kbuild b/coreutils/Kbuild index cf1718419..cfb508d81 100644 --- a/coreutils/Kbuild +++ b/coreutils/Kbuild | |||
| @@ -11,7 +11,7 @@ lib-$(CONFIG_BASENAME) += basename.o | |||
| 11 | lib-$(CONFIG_CAL) += cal.o | 11 | lib-$(CONFIG_CAL) += cal.o |
| 12 | lib-$(CONFIG_CAT) += cat.o | 12 | lib-$(CONFIG_CAT) += cat.o |
| 13 | lib-$(CONFIG_CATV) += catv.o | 13 | lib-$(CONFIG_CATV) += catv.o |
| 14 | lib-$(CONFIG_CHGRP) += chgrp.o | 14 | lib-$(CONFIG_CHGRP) += chgrp.o chown.o |
| 15 | lib-$(CONFIG_CHMOD) += chmod.o | 15 | lib-$(CONFIG_CHMOD) += chmod.o |
| 16 | lib-$(CONFIG_CHOWN) += chown.o | 16 | lib-$(CONFIG_CHOWN) += chown.o |
| 17 | lib-$(CONFIG_CHROOT) += chroot.o | 17 | lib-$(CONFIG_CHROOT) += chroot.o |
diff --git a/coreutils/chgrp.c b/coreutils/chgrp.c index e62bd16f0..da5b12964 100644 --- a/coreutils/chgrp.c +++ b/coreutils/chgrp.c | |||
| @@ -7,49 +7,21 @@ | |||
| 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, -H, -L, and -P. */ | 10 | /* BB_AUDIT SUSv3 defects - unsupported options -H, -L, and -P. */ |
| 11 | /* BB_AUDIT GNU defects - unsupported options -h, -c, -f, -v, and long options. */ | 11 | /* BB_AUDIT GNU defects - unsupported long options. */ |
| 12 | /* BB_AUDIT Note: gnu chgrp does not support -H, -L, or -P. */ | ||
| 13 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/chgrp.html */ | 12 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/chgrp.html */ |
| 14 | 13 | ||
| 15 | #include <stdlib.h> | ||
| 16 | #include <unistd.h> | ||
| 17 | #include "busybox.h" | 14 | #include "busybox.h" |
| 18 | 15 | ||
| 19 | static int fileAction(const char *fileName, struct stat *statbuf, void* junk) | ||
| 20 | { | ||
| 21 | if (lchown(fileName, statbuf->st_uid, *((long *) junk)) == 0) { | ||
| 22 | return (TRUE); | ||
| 23 | } | ||
| 24 | bb_perror_msg("%s", fileName); /* Avoid multibyte problems. */ | ||
| 25 | return (FALSE); | ||
| 26 | } | ||
| 27 | |||
| 28 | int chgrp_main(int argc, char **argv) | 16 | int chgrp_main(int argc, char **argv) |
| 29 | { | 17 | { |
| 30 | long gid; | 18 | /* "chgrp [opts] abc file(s)" == "chown [opts] :abc file(s)" */ |
| 31 | int recursiveFlag; | 19 | char **p = argv; |
| 32 | int retval = EXIT_SUCCESS; | 20 | while (*++p) { |
| 33 | 21 | if (p[0][0] != '-') { | |
| 34 | recursiveFlag = getopt32(argc, argv, "R"); | 22 | p[0] = xasprintf(":%s", p[0]); |
| 35 | 23 | break; | |
| 36 | if (argc - optind < 2) { | ||
| 37 | bb_show_usage(); | ||
| 38 | } | ||
| 39 | |||
| 40 | argv += optind; | ||
| 41 | |||
| 42 | /* Find the selected group */ | ||
| 43 | gid = get_ug_id(*argv, bb_xgetgrnam); | ||
| 44 | ++argv; | ||
| 45 | |||
| 46 | /* Ok, ready to do the deed now */ | ||
| 47 | do { | ||
| 48 | if (! recursive_action (*argv, recursiveFlag, FALSE, FALSE, | ||
| 49 | fileAction, fileAction, &gid)) { | ||
| 50 | retval = EXIT_FAILURE; | ||
| 51 | } | 24 | } |
| 52 | } while (*++argv); | 25 | } |
| 53 | 26 | return chown_main(argc, argv); | |
| 54 | return retval; | ||
| 55 | } | 27 | } |
diff --git a/include/usage.h b/include/usage.h index 8d61c2907..46bb9eca4 100644 --- a/include/usage.h +++ b/include/usage.h | |||
| @@ -169,11 +169,17 @@ | |||
| 169 | "\t-v\tset the file's version/generation number" | 169 | "\t-v\tset the file's version/generation number" |
| 170 | 170 | ||
| 171 | #define chgrp_trivial_usage \ | 171 | #define chgrp_trivial_usage \ |
| 172 | "[OPTION]... GROUP FILE..." | 172 | "[-Rh"USE_DESKTOP("cvf")"]... GROUP FILE..." |
| 173 | #define chgrp_full_usage \ | 173 | #define chgrp_full_usage \ |
| 174 | "Change the group membership of each FILE to GROUP.\n" \ | 174 | "Change the group membership of each FILE to GROUP.\n" \ |
| 175 | "\nOptions:\n" \ | 175 | "\nOptions:\n" \ |
| 176 | "\t-R\tChanges files and directories recursively" | 176 | "\t-R\tChanges files and directories recursively\n" \ |
| 177 | "\t-h\tDo not dereference symbolic links" \ | ||
| 178 | USE_DESKTOP( \ | ||
| 179 | "\n\t-c\tList changed files" \ | ||
| 180 | "\n\t-v\tList all files" \ | ||
| 181 | "\n\t-f\tHide errors" \ | ||
| 182 | ) | ||
| 177 | #define chgrp_example_usage \ | 183 | #define chgrp_example_usage \ |
| 178 | "$ ls -l /tmp/foo\n" \ | 184 | "$ ls -l /tmp/foo\n" \ |
| 179 | "-r--r--r-- 1 andersen andersen 0 Apr 12 18:25 /tmp/foo\n" \ | 185 | "-r--r--r-- 1 andersen andersen 0 Apr 12 18:25 /tmp/foo\n" \ |
