From e80e2a3660bf09cc549cb2dfd2bdeb77ccde1231 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Fri, 27 Oct 2006 23:28:38 +0000 Subject: chgrp: just call chown! :) --- coreutils/Kbuild | 2 +- coreutils/chgrp.c | 48 ++++++++++-------------------------------------- 2 files changed, 11 insertions(+), 39 deletions(-) (limited to 'coreutils') 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 lib-$(CONFIG_CAL) += cal.o lib-$(CONFIG_CAT) += cat.o lib-$(CONFIG_CATV) += catv.o -lib-$(CONFIG_CHGRP) += chgrp.o +lib-$(CONFIG_CHGRP) += chgrp.o chown.o lib-$(CONFIG_CHMOD) += chmod.o lib-$(CONFIG_CHOWN) += chown.o 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 @@ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */ -/* BB_AUDIT SUSv3 defects - unsupported options -h, -H, -L, and -P. */ -/* BB_AUDIT GNU defects - unsupported options -h, -c, -f, -v, and long options. */ -/* BB_AUDIT Note: gnu chgrp does not support -H, -L, or -P. */ +/* BB_AUDIT SUSv3 defects - unsupported options -H, -L, and -P. */ +/* BB_AUDIT GNU defects - unsupported long options. */ /* http://www.opengroup.org/onlinepubs/007904975/utilities/chgrp.html */ -#include -#include #include "busybox.h" -static int fileAction(const char *fileName, struct stat *statbuf, void* junk) -{ - if (lchown(fileName, statbuf->st_uid, *((long *) junk)) == 0) { - return (TRUE); - } - bb_perror_msg("%s", fileName); /* Avoid multibyte problems. */ - return (FALSE); -} - int chgrp_main(int argc, char **argv) { - long gid; - int recursiveFlag; - int retval = EXIT_SUCCESS; - - recursiveFlag = getopt32(argc, argv, "R"); - - if (argc - optind < 2) { - bb_show_usage(); - } - - argv += optind; - - /* Find the selected group */ - gid = get_ug_id(*argv, bb_xgetgrnam); - ++argv; - - /* Ok, ready to do the deed now */ - do { - if (! recursive_action (*argv, recursiveFlag, FALSE, FALSE, - fileAction, fileAction, &gid)) { - retval = EXIT_FAILURE; + /* "chgrp [opts] abc file(s)" == "chown [opts] :abc file(s)" */ + char **p = argv; + while (*++p) { + if (p[0][0] != '-') { + p[0] = xasprintf(":%s", p[0]); + break; } - } while (*++argv); - - return retval; + } + return chown_main(argc, argv); } -- cgit v1.2.3