OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / user / fileutils / chmod.c
1 /*
2  * Copyright (c) 1993 by David I. Bell
3  * Permission is granted to use, distribute, or modify this source,
4  * provided that this copyright notice remains intact.
5  *
6  * Most simple built-in commands are here.
7  */
8
9 #include "futils.h"
10
11 #include <sys/types.h>
12 #include <sys/stat.h>
13 #include <unistd.h>
14 #include <fcntl.h>
15 #include <signal.h>
16 #include <pwd.h>
17 #include <grp.h>
18 #include <utime.h>
19 #include <errno.h>
20
21 int
22 main(argc, argv)
23         char    **argv;
24 {
25         char    *cp;
26         int     mode;
27
28         mode = 0;
29         cp = argv[1];
30         while (isoctal(*cp))
31                 mode = mode * 8 + (*cp++ - '0');
32
33         if (*cp) {
34                 fprintf(stderr, "Mode must be octal\n");
35                 exit(1);
36         }
37         argc--;
38         argv++;
39
40         while (argc-- > 1) {
41                 if (chmod(argv[1], mode) < 0)
42                         perror(argv[1]);
43                 argv++;
44         }
45         exit(0);
46 }