blob: 7076db62f9bab7d35ebbaad4f408aa36edddd521 [file] [log] [blame]
Eric Andersen9f0fedb2001-04-24 18:07:19 +00001/* vi: set sw=4 ts=4: */
2/*
Eric Andersenbdfd0d72001-10-24 05:00:29 +00003 * Mini chgrp implementation for busybox
Eric Andersen9f0fedb2001-04-24 18:07:19 +00004 *
Eric Andersenc7bda1c2004-03-15 08:29:22 +00005 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
Eric Andersen9f0fedb2001-04-24 18:07:19 +00006 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02007 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Eric Andersen9f0fedb2001-04-24 18:07:19 +00008 */
9
Denis Vlasenko02f0c4c2007-03-09 10:08:53 +000010/* BB_AUDIT SUSv3 defects - none? */
Denis Vlasenkoe80e2a32006-10-27 23:28:38 +000011/* BB_AUDIT GNU defects - unsupported long options. */
Manuel Novoa III cad53642003-03-19 09:13:01 +000012/* http://www.opengroup.org/onlinepubs/007904975/utilities/chgrp.html */
13
Pere Orga34425382011-03-31 14:43:25 +020014//usage:#define chgrp_trivial_usage
15//usage: "[-RhLHP"IF_DESKTOP("cvf")"]... GROUP FILE..."
16//usage:#define chgrp_full_usage "\n\n"
17//usage: "Change the group membership of each FILE to GROUP\n"
Pere Orga34425382011-03-31 14:43:25 +020018//usage: "\n -R Recurse"
19//usage: "\n -h Affect symlinks instead of symlink targets"
20//usage: "\n -L Traverse all symlinks to directories"
21//usage: "\n -H Traverse symlinks on command line only"
22//usage: "\n -P Don't traverse symlinks (default)"
23//usage: IF_DESKTOP(
24//usage: "\n -c List changed files"
25//usage: "\n -v Verbose"
26//usage: "\n -f Hide errors"
27//usage: )
28//usage:
29//usage:#define chgrp_example_usage
30//usage: "$ ls -l /tmp/foo\n"
31//usage: "-r--r--r-- 1 andersen andersen 0 Apr 12 18:25 /tmp/foo\n"
32//usage: "$ chgrp root /tmp/foo\n"
33//usage: "$ ls -l /tmp/foo\n"
34//usage: "-r--r--r-- 1 andersen root 0 Apr 12 18:25 /tmp/foo\n"
35
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000036#include "libbb.h"
Eric Andersen9f0fedb2001-04-24 18:07:19 +000037
Denis Vlasenko99912ca2007-04-10 15:43:37 +000038/* This is a NOEXEC applet. Be very careful! */
39
40
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000041int chgrp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Eric Andersen9f0fedb2001-04-24 18:07:19 +000042int chgrp_main(int argc, char **argv)
43{
Denis Vlasenkoe80e2a32006-10-27 23:28:38 +000044 /* "chgrp [opts] abc file(s)" == "chown [opts] :abc file(s)" */
45 char **p = argv;
46 while (*++p) {
47 if (p[0][0] != '-') {
48 p[0] = xasprintf(":%s", p[0]);
49 break;
Eric Andersen9f0fedb2001-04-24 18:07:19 +000050 }
Denis Vlasenkoe80e2a32006-10-27 23:28:38 +000051 }
52 return chown_main(argc, argv);
Eric Andersen9f0fedb2001-04-24 18:07:19 +000053}