* 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.2 (Berkeley) %G%";
* chmod options mode files
* mode is [ugoa][+-=][rwxXstugo] or a octal number
#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 */
register char *p
, *flags
;
,"Usage: chmod [-R] [ugoa][+-=][rwxXstugo] file ...\n");
if (strcmp(argv
[0], "-R") == 0) {
for (i
= 1; i
< argc
; i
++) {
fprintf(stderr
, "chmod: can't access %s\n", p
);
if (rflag
&& st
.st_mode
& S_IFDIR
) {
status
+= chmodr(p
, newmode(st
.st_mode
));
} else if (chmod(p
, newmode(st
.st_mode
)) < 0) {
fprintf(stderr
, "chmod: can't change %s\n", p
);
register struct direct
*dp
;
if (getwd(savedir
) == 0) {
fprintf(stderr
, "chmod: %s\n", savedir
);
** chmod what we are given before doing it's contents
chmod(dir
, newmode(mode
));
if ((dirp
= opendir(".")) == NULL
) {
dp
= readdir(dirp
); /* read "." and ".." */
for (dp
= readdir(dirp
); dp
!= NULL
; dp
= readdir(dirp
)) {
if (stat(dp
->d_name
, &st
) < 0) {
fprintf(stderr
, "chmod: can't access %s\n", dp
->d_name
);
chmod(dp
->d_name
, newmode(st
.st_mode
));
if (st
.st_mode
& S_IFDIR
)
chmodr(dp
->d_name
, mode
);
fprintf(stderr
, "chmod: invalid mode\n");
while ((c
= *ms
++) >= '0' && c
<= '7')
i
= (i
<< 3) + (c
- '0');
for (;;) switch (*ms
++) {
m
|= (m
<< 3) | (m
<< 6);
for (;;) switch (*ms
++) {
if ((om
& S_IFDIR
) || (om
& EXEC
))