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: }

Defined functions

isnumber defined in line 44; used 1 times
  • in line 25
main defined in line 16; never used

Defined variables

gid defined in line 13; used 3 times
gr defined in line 11; used 2 times
status defined in line 14; used 2 times
stbuf defined in line 12; used 2 times
Last modified: 1981-07-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 744
Valid CSS Valid XHTML 1.0 Strict