* Copyright (c) 1980, 1988 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
"@(#) Copyright (c) 1980, 1988 Regents of the University of California.\n\
static char sccsid
[] = "@(#)chmod.c 5.7 (Berkeley) %G%";
* chmod options mode files
* mode is [ugoa][+-=][rwxXstugo] or an octal number
static int fflag
, rflag
, retval
, um
;
static char *modestring
, *ms
;
extern int optind
, opterr
;
* since "-[rwx]" etc. are valid file modes, we don't let getopt(3)
* print error messages, and we mess around with optind as necessary.
while ((ch
= getopt(argc
, argv
, "Rf")) != EOF
)
fputs("usage: chmod [-Rf] [ugoa][+-=][rwxXstugo] file ...\n",
(void)newmode((u_short
)0);
register struct direct
*dp
;
if (lstat(file
, &buf
) || chmod(file
, newmode(buf
.st_mode
))) {
if (rflag
&& ((buf
.st_mode
& S_IFMT
) == S_IFDIR
)) {
if (chdir(file
) < 0 || !(dirp
= opendir("."))) {
for (dp
= readdir(dirp
); dp
; dp
= readdir(dirp
)) {
if (dp
->d_name
[0] == '.' && (!dp
->d_name
[1] ||
dp
->d_name
[1] == '.' && !dp
->d_name
[2]))
fputs("chmod: ", stderr
);
fputs("chmod: invalid mode.\n", stderr
);
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
))