Bell 32V development
[unix-history] / usr / src / cmd / chown.c
CommitLineData
3b600ead
TL
1/*
2 * chown uid file ...
3 */
4
5#include <stdio.h>
6#include <ctype.h>
7#include <sys/types.h>
8#include <sys/stat.h>
9#include <pwd.h>
10
11struct passwd *pwd,*getpwnam();
12struct stat stbuf;
13int uid;
14int status;
15
16main(argc, argv)
17char *argv[];
18{
19 register c;
20
21 if(argc < 3) {
22 printf("usage: chown uid file ...\n");
23 exit(4);
24 }
25 if(isnumber(argv[1])) {
26 uid = atoi(argv[1]);
27 goto cho;
28 }
29 if((pwd=getpwnam(argv[1])) == NULL) {
30 printf("unknown user id: %s\n",argv[1]);
31 exit(4);
32 }
33 uid = pwd->pw_uid;
34
35cho:
36 for(c=2; c<argc; c++) {
37 stat(argv[c], &stbuf);
38 if(chown(argv[c], uid, stbuf.st_gid) < 0) {
39 perror(argv[c]);
40 status = 1;
41 }
42 }
43 exit(status);
44}
45
46isnumber(s)
47char *s;
48{
49 register c;
50
51 while(c = *s++)
52 if(!isdigit(c))
53 return(0);
54 return(1);
55}