chgrp.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. int readgid(char*);
  12. int uflag;
  13. void
  14. main(int argc, char *argv[])
  15. {
  16. int i;
  17. Dir dir;
  18. char *group;
  19. char *errs;
  20. ARGBEGIN {
  21. default:
  22. usage:
  23. fprint(2, "usage: chgrp [ -uo ] group file ....\n");
  24. exits("usage");
  25. return;
  26. case 'u':
  27. case 'o':
  28. uflag++;
  29. break;
  30. } ARGEND
  31. if(argc < 1)
  32. goto usage;
  33. group = argv[0];
  34. errs = 0;
  35. for(i=1; i<argc; i++){
  36. nulldir(&dir);
  37. if(uflag)
  38. dir.uid = group;
  39. else
  40. dir.gid = group;
  41. if(dirwstat(argv[i], &dir) == -1) {
  42. fprint(2, "chgrp: can't wstat %s: %r\n", argv[i]);
  43. errs = "can't wstat";
  44. continue;
  45. }
  46. }
  47. exits(errs);
  48. }