aboutsummaryrefslogtreecommitdiff
path: root/busybox/coreutils/chgrp.c
diff options
context:
space:
mode:
Diffstat (limited to 'busybox/coreutils/chgrp.c')
-rw-r--r--busybox/coreutils/chgrp.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/busybox/coreutils/chgrp.c b/busybox/coreutils/chgrp.c
new file mode 100644
index 000000000..8cfb54241
--- /dev/null
+++ b/busybox/coreutils/chgrp.c
@@ -0,0 +1,81 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Mini chgrp implementation for busybox
4 *
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22
23/* BB_AUDIT SUSv3 defects - unsupported options -h, -H, -L, and -P. */
24/* BB_AUDIT GNU defects - unsupported options -h, -c, -f, -v, and long options. */
25/* BB_AUDIT Note: gnu chgrp does not support -H, -L, or -P. */
26/* http://www.opengroup.org/onlinepubs/007904975/utilities/chgrp.html */
27
28#include <stdlib.h>
29#include <unistd.h>
30#include "busybox.h"
31
32/* Don't use lchown glibc older then 2.1.x */
33#if (__GLIBC__ <= 2) && (__GLIBC_MINOR__ < 1)
34#define lchown chown
35#endif
36
37static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
38{
39 if (lchown(fileName, statbuf->st_uid, *((long *) junk)) == 0) {
40 return (TRUE);
41 }
42 bb_perror_msg("%s", fileName); /* Avoid multibyte problems. */
43 return (FALSE);
44}
45
46int chgrp_main(int argc, char **argv)
47{
48 long gid;
49 int recursiveFlag;
50 int retval = EXIT_SUCCESS;
51
52 recursiveFlag = bb_getopt_ulflags(argc, argv, "R");
53
54 if (argc - optind < 2) {
55 bb_show_usage();
56 }
57
58 argv += optind;
59
60 /* Find the selected group */
61 gid = get_ug_id(*argv, my_getgrnam);
62 ++argv;
63
64 /* Ok, ready to do the deed now */
65 do {
66 if (! recursive_action (*argv, recursiveFlag, FALSE, FALSE,
67 fileAction, fileAction, &gid)) {
68 retval = EXIT_FAILURE;
69 }
70 } while (*++argv);
71
72 return retval;
73}
74
75/*
76Local Variables:
77c-file-style: "linux"
78c-basic-offset: 4
79tab-width: 4
80End:
81*/