3
0

chgrp.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. /* BB_AUDIT SUSv3 defects - none? */
  10. /* BB_AUDIT GNU defects - unsupported long options. */
  11. /* http://www.opengroup.org/onlinepubs/007904975/utilities/chgrp.html */
  12. //usage:#define chgrp_trivial_usage
  13. //usage: "[-RhLHP"IF_DESKTOP("cvf")"]... GROUP FILE..."
  14. //usage:#define chgrp_full_usage "\n\n"
  15. //usage: "Change the group membership of each FILE to GROUP\n"
  16. //usage: "\n -R Recurse"
  17. //usage: "\n -h Affect symlinks instead of symlink targets"
  18. //usage: "\n -L Traverse all symlinks to directories"
  19. //usage: "\n -H Traverse symlinks on command line only"
  20. //usage: "\n -P Don't traverse symlinks (default)"
  21. //usage: IF_DESKTOP(
  22. //usage: "\n -c List changed files"
  23. //usage: "\n -v Verbose"
  24. //usage: "\n -f Hide errors"
  25. //usage: )
  26. //usage:
  27. //usage:#define chgrp_example_usage
  28. //usage: "$ ls -l /tmp/foo\n"
  29. //usage: "-r--r--r-- 1 andersen andersen 0 Apr 12 18:25 /tmp/foo\n"
  30. //usage: "$ chgrp root /tmp/foo\n"
  31. //usage: "$ ls -l /tmp/foo\n"
  32. //usage: "-r--r--r-- 1 andersen root 0 Apr 12 18:25 /tmp/foo\n"
  33. #include "libbb.h"
  34. /* This is a NOEXEC applet. Be very careful! */
  35. int chgrp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  36. int chgrp_main(int argc, char **argv)
  37. {
  38. /* "chgrp [opts] abc file(s)" == "chown [opts] :abc file(s)" */
  39. char **p = argv;
  40. while (*++p) {
  41. if (p[0][0] != '-') {
  42. p[0] = xasprintf(":%s", p[0]);
  43. break;
  44. }
  45. }
  46. return chown_main(argc, argv);
  47. }