diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2000-07-08 16:09:35 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2000-07-08 16:09:35 +0000 |
commit | cd8ea8cdc894d70ddf43571501e038680691c29c (patch) | |
tree | 131fdbf8f5d79b1b82f9788eabc1069103107d4c /usr.bin/find/function.c | |
parent | c5a66fdd2a472878fb5f7aee24ce086c099c6cc4 (diff) |
Add a -flags option similar to -perm but for filke flags (ala
chflags). Adapted from FreeBSD.
Diffstat (limited to 'usr.bin/find/function.c')
-rw-r--r-- | usr.bin/find/function.c | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c index 3713de164ee..fb969903b6c 100644 --- a/usr.bin/find/function.c +++ b/usr.bin/find/function.c @@ -1,4 +1,4 @@ -/* $OpenBSD: function.c,v 1.18 2000/06/07 15:25:30 deraadt Exp $ */ +/* $OpenBSD: function.c,v 1.19 2000/07/08 16:09:34 millert Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -38,7 +38,7 @@ #ifndef lint /*static char sccsid[] = "from: @(#)function.c 8.1 (Berkeley) 6/6/93";*/ -static char rcsid[] = "$OpenBSD: function.c,v 1.18 2000/06/07 15:25:30 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: function.c,v 1.19 2000/07/08 16:09:34 millert Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -545,6 +545,54 @@ c_execdir(argvp) *argvp = argv + 1; return (new); } + +/* + * -flags functions -- + * + * The flags argument is used to represent file flags bits. + */ +int +f_flags(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + u_int flags; + + flags = entry->fts_statp->st_flags & + (UF_NODUMP | UF_IMMUTABLE | UF_APPEND | UF_OPAQUE | + SF_ARCHIVED | SF_IMMUTABLE | SF_APPEND); + if (plan->flags == F_ATLEAST) + /* note that plan->fl_flags always is a subset of + plan->fl_mask */ + return ((flags & plan->fl_mask) == plan->fl_flags); + else + return (flags == plan->fl_flags); + /* NOTREACHED */ +} + +PLAN * +c_flags(flags_str) + char *flags_str; +{ + PLAN *new; + u_int flags, notflags; + + ftsoptions &= ~FTS_NOSTAT; + + new = palloc(N_FLAGS, f_flags); + + if (*flags_str == '-') { + new->flags = F_ATLEAST; + ++flags_str; + } + + if (string_to_flags(&flags_str, &flags, ¬flags) == 1) + errx(1, "-flags: %s: illegal flags string", flags_str); + + new->fl_flags = flags; + new->fl_mask = flags | notflags; + return (new); +} /* * -follow functions -- @@ -1151,7 +1199,7 @@ c_perm(perm) } if ((set = setmode(perm)) == NULL) - err(1, "-perm: %s: illegal mode string", perm); + errx(1, "-perm: %s: illegal mode string", perm); new->m_data = getmode(set, 0); free(set); |