home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V7 / usr / src / cmd / chgrp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1979-01-10  |  754 b   |  54 lines

  1. /*
  2.  * chgrp gid file ...
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <ctype.h>
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include <grp.h>
  10.  
  11. struct    group    *gr,*getgrnam();
  12. struct    stat    stbuf;
  13. int    gid;
  14. int    status;
  15.  
  16. main(argc, argv)
  17. char *argv[];
  18. {
  19.     register c;
  20.  
  21.     if(argc < 3) {
  22.         printf("usage: chgrp gid file ...\n");
  23.         exit(4);
  24.     }
  25.     if(isnumber(argv[1])) {
  26.         gid = atoi(argv[1]);
  27.     } else {
  28.         if((gr=getgrnam(argv[1])) == NULL) {
  29.             printf("unknown group: %s\n",argv[1]);
  30.             exit(4);
  31.         }
  32.         gid = gr->gr_gid;
  33.     }
  34.     for(c=2; c<argc; c++) {
  35.         stat(argv[c], &stbuf);
  36.         if(chown(argv[c], stbuf.st_uid, gid) < 0) {
  37.             perror(argv[c]);
  38.             status = 1;
  39.         }
  40.     }
  41.     exit(status);
  42. }
  43.  
  44. isnumber(s)
  45. char *s;
  46. {
  47.     register c;
  48.  
  49.     while(c = *s++)
  50.         if(!isdigit(c))
  51.             return(0);
  52.     return(1);
  53. }
  54.