1*11442Smckusick static char *sccsid = "@(#)chown.c 4.2 (Berkeley) 03/08/83"; 2975Sbill /* 3975Sbill * chown uid file ... 4975Sbill */ 5975Sbill 6975Sbill #include <stdio.h> 7975Sbill #include <ctype.h> 8975Sbill #include <sys/types.h> 9975Sbill #include <sys/stat.h> 10975Sbill #include <pwd.h> 11975Sbill 12975Sbill struct passwd *pwd,*getpwnam(); 13975Sbill struct stat stbuf; 14975Sbill int uid; 15975Sbill int status; 16*11442Smckusick int fflag; 17975Sbill 18975Sbill main(argc, argv) 19975Sbill char *argv[]; 20975Sbill { 21975Sbill register c; 22975Sbill 23975Sbill if(argc < 3) { 24*11442Smckusick printf("usage: chown -f uid file ...\n"); 25975Sbill exit(4); 26975Sbill } 27*11442Smckusick if (strcmp(argv[1], "-f") == 0) { 28*11442Smckusick fflag++; 29*11442Smckusick argv++, argc--; 30*11442Smckusick } 31975Sbill if(isnumber(argv[1])) { 32975Sbill uid = atoi(argv[1]); 33975Sbill goto cho; 34975Sbill } 35975Sbill if((pwd=getpwnam(argv[1])) == NULL) { 36975Sbill printf("unknown user id: %s\n",argv[1]); 37975Sbill exit(4); 38975Sbill } 39975Sbill uid = pwd->pw_uid; 40975Sbill 41975Sbill cho: 42975Sbill for(c=2; c<argc; c++) { 43975Sbill stat(argv[c], &stbuf); 44*11442Smckusick if(chown(argv[c], uid, stbuf.st_gid) < 0 && !fflag) { 45975Sbill perror(argv[c]); 46975Sbill status = 1; 47975Sbill } 48975Sbill } 49975Sbill exit(status); 50975Sbill } 51975Sbill 52975Sbill isnumber(s) 53975Sbill char *s; 54975Sbill { 55975Sbill register c; 56975Sbill 57975Sbill while(c = *s++) 58975Sbill if(!isdigit(c)) 59975Sbill return(0); 60975Sbill return(1); 61975Sbill } 62