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