mirror of
https://github.com/sheumann/hush.git
synced 2024-12-27 01:32:08 +00:00
chgrp: just call chown! :)
This commit is contained in:
parent
3b8fc1c582
commit
e80e2a3660
@ -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
|
||||
|
@ -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 <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#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);
|
||||
}
|
||||
|
@ -169,11 +169,17 @@
|
||||
"\t-v\tset the file's version/generation number"
|
||||
|
||||
#define chgrp_trivial_usage \
|
||||
"[OPTION]... GROUP FILE..."
|
||||
"[-Rh"USE_DESKTOP("cvf")"]... GROUP FILE..."
|
||||
#define chgrp_full_usage \
|
||||
"Change the group membership of each FILE to GROUP.\n" \
|
||||
"\nOptions:\n" \
|
||||
"\t-R\tChanges files and directories recursively"
|
||||
"\t-R\tChanges files and directories recursively\n" \
|
||||
"\t-h\tDo not dereference symbolic links" \
|
||||
USE_DESKTOP( \
|
||||
"\n\t-c\tList changed files" \
|
||||
"\n\t-v\tList all files" \
|
||||
"\n\t-f\tHide errors" \
|
||||
)
|
||||
#define chgrp_example_usage \
|
||||
"$ ls -l /tmp/foo\n" \
|
||||
"-r--r--r-- 1 andersen andersen 0 Apr 12 18:25 /tmp/foo\n" \
|
||||
|
Loading…
Reference in New Issue
Block a user