e0f2c9fdbbdcacb1a11104ac6a9d4b40bf87f095
* 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.3 (Berkeley) %G%";
int ch
, fflag
, rflag
, hflag
, Hflag
;
fts_options
= FTS_PHYSICAL
;
fflag
= rflag
= hflag
= Hflag
= 0;
while ((ch
= getopt(argc
, argv
, "HRXfghorstuwx")) != EOF
)
fts_options
|= FTS_COMFOLLOW
;
case 'f': /* XXX: no longer documented. */
fts_options
&= ~FTS_PHYSICAL
;
fts_options
|= FTS_LOGICAL
;
* "-[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')
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
)
while ((p
= fts_read(ftsp
)) != NULL
)
fts_set(ftsp
, p
, FTS_SKIP
);
err(1, "%s", p
->fts_path
);
if (p
->fts_info
== FTS_SL
&& !(hflag
||
(Hflag
&& p
->fts_level
== FTS_ROOTLEVEL
)))
if (chmod(p
->fts_accpath
, oct
? omode
:
getmode(set
, p
->fts_statp
->st_mode
)) && !fflag
) {
(void)fprintf(stderr
, "usage: chmod [-HRh] mode file ...\n");