|
|
1.1 ! root 1: static char *sccsid = "@(#)chown.c 4.2 (Berkeley) 3/8/83"; ! 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: int fflag; ! 17: ! 18: main(argc, argv) ! 19: char *argv[]; ! 20: { ! 21: register c; ! 22: ! 23: if(argc < 3) { ! 24: printf("usage: chown -f uid file ...\n"); ! 25: exit(4); ! 26: } ! 27: if (strcmp(argv[1], "-f") == 0) { ! 28: fflag++; ! 29: argv++, argc--; ! 30: } ! 31: if(isnumber(argv[1])) { ! 32: uid = atoi(argv[1]); ! 33: goto cho; ! 34: } ! 35: if((pwd=getpwnam(argv[1])) == NULL) { ! 36: printf("unknown user id: %s\n",argv[1]); ! 37: exit(4); ! 38: } ! 39: uid = pwd->pw_uid; ! 40: ! 41: cho: ! 42: for(c=2; c<argc; c++) { ! 43: stat(argv[c], &stbuf); ! 44: if(chown(argv[c], uid, stbuf.st_gid) < 0 && !fflag) { ! 45: perror(argv[c]); ! 46: status = 1; ! 47: } ! 48: } ! 49: exit(status); ! 50: } ! 51: ! 52: isnumber(s) ! 53: char *s; ! 54: { ! 55: register c; ! 56: ! 57: while(c = *s++) ! 58: if(!isdigit(c)) ! 59: return(0); ! 60: return(1); ! 61: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.