* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
static char sccsid
[] = "@(#)chmod.c 5.5 (Berkeley) %G%";
* chmod options mode files
* mode is [ugoa][+-=][rwxXstugo] or an octal number
register char *p
, *flags
;
"Usage: chmod [-Rf] [ugoa][+-=][rwxXstugo] file ...\n");
while (argc
> 0 && argv
[0][0] == '-') {
for (p
= &argv
[0][1]; *p
; p
++) switch (*p
) {
for (i
= 1; i
< argc
; i
++) {
/* do stat for directory arguments */
if (rflag
&& (st
.st_mode
&S_IFMT
) == S_IFDIR
) {
status
+= chmodr(p
, newmode(st
.st_mode
));
if ((st
.st_mode
&S_IFMT
) == S_IFLNK
&& stat(p
, &st
) < 0) {
if (chmod(p
, newmode(st
.st_mode
)) < 0) {
register struct direct
*dp
;
fatal(255, "%s", savedir
);
* Change what we are given before doing it's contents
if (chmod(dir
, newmode(mode
)) < 0 && Perror(dir
))
if ((dirp
= opendir(".")) == NULL
) {
dp
= readdir(dirp
); /* read "." and ".." */
for (dp
= readdir(dirp
); dp
!= NULL
; dp
= readdir(dirp
)) {
if (lstat(dp
->d_name
, &st
) < 0) {
ecode
= Perror(dp
->d_name
);
if ((st
.st_mode
&S_IFMT
) == S_IFDIR
) {
ecode
= chmodr(dp
->d_name
, newmode(st
.st_mode
));
if ((st
.st_mode
&S_IFMT
) == S_IFLNK
)
if (chmod(dp
->d_name
, newmode(st
.st_mode
)) < 0 &&
(ecode
= Perror(dp
->d_name
)))
fatal(255, "can't change back to %s", savedir
);
fprintf(stderr
, "chmod: ");
fprintf(stderr
, "chmod: ");
fatal(255, "invalid mode");
while ((c
= *ms
++) >= '0' && c
<= '7')
i
= (i
<< 3) + (c
- '0');
#define USER 05700 /* user's bits */
#define GROUP 02070 /* group's bits */
#define OTHER 00007 /* other's bits */
#define ALL 01777 /* all (note absence of setuid, etc) */
#define READ 00444 /* read permit */
#define WRITE 00222 /* write permit */
#define EXEC 00111 /* exec permit */
#define SETID 06000 /* set[ug]id */
#define STICKY 01000 /* sticky bit */
for (;;) switch (*ms
++) {
m
|= (m
<< 3) | (m
<< 6);
for (;;) switch (*ms
++) {
if ((om
& S_IFDIR
) || (om
& EXEC
))