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 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 8 */ 9//config:config CHGRP 10//config: bool "chgrp (7.6 kb)" 11//config: default y 12//config: help 13//config: chgrp is used to change the group ownership of files. 14 15//applet:IF_CHGRP(APPLET_NOEXEC(chgrp, chgrp, BB_DIR_BIN, BB_SUID_DROP, chgrp)) 16 17//kbuild:lib-$(CONFIG_CHGRP) += chgrp.o chown.o 18 19/* BB_AUDIT SUSv3 defects - none? */ 20/* BB_AUDIT GNU defects - unsupported long options. */ 21/* http://www.opengroup.org/onlinepubs/007904975/utilities/chgrp.html */ 22 23//usage:#define chgrp_trivial_usage 24//usage: "[-Rh"IF_DESKTOP("LHPcvf")"]... GROUP FILE..." 25//usage:#define chgrp_full_usage "\n\n" 26//usage: "Change the group membership of FILEs to GROUP" 27//usage: "\n" 28//usage: "\n -h Affect symlinks instead of symlink targets" 29//usage: IF_DESKTOP( 30//usage: "\n -L Traverse all symlinks to directories" 31//usage: "\n -H Traverse symlinks on command line only" 32//usage: "\n -P Don't traverse symlinks (default)" 33//usage: ) 34//next 4 options are the same for chmod/chown/chgrp: 35//usage: "\n -R Recurse" 36//usage: IF_DESKTOP( 37//usage: "\n -c List changed files" 38//usage: "\n -v Verbose" 39//usage: "\n -f Hide errors" 40//usage: ) 41//usage: 42//usage:#define chgrp_example_usage 43//usage: "$ ls -l /tmp/foo\n" 44//usage: "-r--r--r-- 1 andersen andersen 0 Apr 12 18:25 /tmp/foo\n" 45//usage: "$ chgrp root /tmp/foo\n" 46//usage: "$ ls -l /tmp/foo\n" 47//usage: "-r--r--r-- 1 andersen root 0 Apr 12 18:25 /tmp/foo\n" 48 49#include "libbb.h" 50 51/* This is a NOEXEC applet. Be very careful! */ 52 53 54int chgrp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 55int chgrp_main(int argc, char **argv) 56{ 57 /* "chgrp [opts] abc file(s)" == "chown [opts] :abc file(s)" */ 58 char **p = argv; 59 while (*++p) { 60 if (p[0][0] != '-') { 61 p[0] = xasprintf(":%s", p[0]); 62 break; 63 } 64 } 65 return chown_main(argc, argv); 66} 67