* Copyright (c) 1989, 1993, 1994
* The Regents of the University of California. All rights reserved.
* %sccs.include.redist.c%
static char copyright
[] =
"@(#) Copyright (c) 1989, 1993, 1994\n\
The Regents of the University of California. All rights reserved.\n";
static char sccsid
[] = "@(#)chmod.c 8.4 (Berkeley) %G%";
int Hflag
, Lflag
, Pflag
, Rflag
, ch
, fflag
, fts_options
, hflag
, rval
;
Hflag
= Lflag
= Pflag
= Rflag
= fflag
= hflag
= 0;
while ((ch
= getopt(argc
, argv
, "HLPRXfgorstuwx")) != EOF
)
case 'f': /* XXX: undocumented. */
* In System V (and probably POSIX.2) the -h option
* causes chmod to change the mode of the symbolic
* link. 4.4BSD's symbolic links don't have modes,
* so it's an undocumented noop. Do syntax checking,
* "-[rwx]" are valid mode commands. If they are the entire
* argument, getopt has moved past them, so decrement optind.
* Regardless, we're done argument processing.
case 'g': case 'o': case 'r': case 's':
case 't': case 'u': case 'w': case 'X': case 'x':
if (argv
[optind
- 1][0] == '-' &&
argv
[optind
- 1][1] == ch
&&
argv
[optind
- 1][2] == '\0')
fts_options
= FTS_PHYSICAL
;
"the -R and -h options may not be specified together.");
fts_options
|= FTS_COMFOLLOW
;
fts_options
&= ~FTS_PHYSICAL
;
fts_options
|= FTS_LOGICAL
;
if (*mode
>= '0' && *mode
<= '7') {
omode
= (int)strtol(mode
, &ep
, 8);
errx(1, "invalid file mode: %s", mode
);
if ((set
= setmode(mode
)) == NULL
)
errx(1, "invalid file mode: %s", mode
);
if ((ftsp
= fts_open(++argv
, fts_options
, 0)) == NULL
)
for (rval
= 0; (p
= fts_read(ftsp
)) != NULL
;) {
if (Rflag
) /* Change it at FTS_DP. */
fts_set(ftsp
, p
, FTS_SKIP
);
case FTS_DC
: /* Ignore. */
case FTS_DNR
: /* Warn, chmod, continue. */
case FTS_ERR
: /* Warn, continue. */
case FTS_SL
: /* Ignore. */
* The only symlinks that end up here are ones that
* don't point to anything and ones that we found
if (chmod(p
->fts_accpath
, oct
? omode
:
getmode(set
, p
->fts_statp
->st_mode
)) && !fflag
) {
"usage: chmod [-R [-H | -L | -P]] mode file ...\n");