1 /* vi: set sw=4 ts=4: */
3 * Mini chgrp implementation for busybox
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
10 /* BB_AUDIT SUSv3 defects - unsupported options -h, -H, -L, and -P. */
11 /* BB_AUDIT GNU defects - unsupported options -h, -c, -f, -v, and 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 */
19 /* Don't use lchown glibc older then 2.1.x */
20 #if (__GLIBC__ <= 2) && (__GLIBC_MINOR__ < 1)
24 static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
26 if (lchown(fileName, statbuf->st_uid, *((long *) junk)) == 0) {
29 bb_perror_msg("%s", fileName); /* Avoid multibyte problems. */
33 int chgrp_main(int argc, char **argv)
37 int retval = EXIT_SUCCESS;
39 recursiveFlag = bb_getopt_ulflags(argc, argv, "R");
41 if (argc - optind < 2) {
47 /* Find the selected group */
48 gid = get_ug_id(*argv, bb_xgetgrnam);
51 /* Ok, ready to do the deed now */
53 if (! recursive_action (*argv, recursiveFlag, FALSE, FALSE,
54 fileAction, fileAction, &gid)) {
55 retval = EXIT_FAILURE;