chgrp.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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"
  23. //usage: "\n"
  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: )
  30. //next 4 options are the same for chmod/chown/chgrp:
  31. //usage: "\n -R Recurse"
  32. //usage: IF_DESKTOP(
  33. //usage: "\n -c List changed files"
  34. //usage: "\n -v Verbose"
  35. //usage: "\n -f Hide errors"
  36. //usage: )
  37. //usage:
  38. //usage:#define chgrp_example_usage
  39. //usage: "$ ls -l /tmp/foo\n"
  40. //usage: "-r--r--r-- 1 andersen andersen 0 Apr 12 18:25 /tmp/foo\n"
  41. //usage: "$ chgrp root /tmp/foo\n"
  42. //usage: "$ ls -l /tmp/foo\n"
  43. //usage: "-r--r--r-- 1 andersen root 0 Apr 12 18:25 /tmp/foo\n"
  44. #include "libbb.h"
  45. /* This is a NOEXEC applet. Be very careful! */
  46. int chgrp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  47. int chgrp_main(int argc, char **argv)
  48. {
  49. /* "chgrp [opts] abc file(s)" == "chown [opts] :abc file(s)" */
  50. char **p = argv;
  51. while (*++p) {
  52. if (p[0][0] != '-') {
  53. p[0] = xasprintf(":%s", p[0]);
  54. break;
  55. }
  56. }
  57. return chown_main(argc, argv);
  58. }