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