* Copyright (c) 1992, 1993, 1994
* The Regents of the University of California. All rights reserved.
* %sccs.include.redist.c%
static char copyright
[] =
"@(#) Copyright (c) 1992, 1993, 1994\n\
The Regents of the University of California. All rights reserved.\n";
static char sccsid
[] = "@(#)chflags.c 8.4 (Berkeley) %G%";
u_long string_to_flags
__P((char **, u_long
*, u_long
*));
int Hflag
, Lflag
, Pflag
, Rflag
, ch
, fts_options
, oct
, rval
;
Hflag
= Lflag
= Pflag
= Rflag
= 0;
while ((ch
= getopt(argc
, argv
, "HLPR")) != EOF
)
fts_options
= FTS_PHYSICAL
;
fts_options
|= FTS_COMFOLLOW
;
fts_options
&= ~FTS_PHYSICAL
;
fts_options
|= FTS_LOGICAL
;
if (*flags
>= '0' && *flags
<= '7') {
val
= strtol(flags
, &ep
, 8);
err(1, "invalid flags: %s", flags
);
errx(1, "invalid flags: %s", flags
);
if (string_to_flags(&flags
, &set
, &clear
))
errx(1, "invalid flag: %s", flags
);
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_DNR
: /* Warn, chflag, 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 (!chflags(p
->fts_accpath
, set
))
p
->fts_statp
->st_flags
|= set
;
p
->fts_statp
->st_flags
&= clear
;
if (!chflags(p
->fts_accpath
, p
->fts_statp
->st_flags
))
"usage: chflags [-R [-H | -L | -P]] flags file ...\n");