* Copyright (c) 1989 The Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
"@(#) Copyright (c) 1989 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)chmod.c 5.13 (Berkeley) %G%";
while ((ch
= getopt(argc
, argv
, "Rfrwx")) != EOF
)
/* "-[rwx]" are valid file modes */
if (*mode
>= '0' && *mode
<= '7') {
omode
= (int)strtol(mode
, (char **)NULL
, 8);
if (!(set
= setmode(mode
))) {
(void)fprintf(stderr
, "chmod: invalid file mode.\n");
if (!(fts
= ftsopen(++argv
,
(oct
? FTS_NOSTAT
: 0)|FTS_MULTIPLE
|FTS_PHYSICAL
, 0))) {
(void)fprintf(stderr
, "chmod: %s.\n", strerror(errno
));
while (p
= ftsread(fts
)) {
if (p
->fts_info
== FTS_D
)
if (p
->fts_info
== FTS_ERR
) {
if (chmod(p
->fts_accpath
, oct
?
omode
: getmode(set
, p
->fts_statb
.st_mode
)) &&
if (chmod(*argv
, omode
) && !fflag
)
if ((lstat(*argv
, &sb
) ||
chmod(*argv
, getmode(set
, sb
.st_mode
))) && !fflag
)
(void)fprintf(stderr
, "chmod: %s: %s.\n", name
, strerror(errno
));
(void)fprintf(stderr
, "chmod: chmod [-fR] mode file ...\n");