chgrp.c 1.9 KB

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