2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Cimarron D. Taylor of the University of California, Berkeley.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 static const char sccsid[] = "@(#)function.c 8.10 (Berkeley) 5/4/95";
41 static const char rcsid[] =
46 #include <sys/param.h>
47 #include <sys/ucred.h>
50 #include <sys/mount.h>
66 #define COMPARE(a, b) { \
67 switch (plan->flags) { \
79 static PLAN *palloc __P((enum ntype, int (*) __P((PLAN *, FTSENT *))));
83 * Parse a string of the form [+-]# and return the value.
86 find_parsenum(plan, option, vp, endch)
88 char *option, *vp, *endch;
91 char *endchar, *str; /* Pointer to character ending conversion. */
93 /* Determine comparison from leading + or -. */
98 plan->flags = F_GREATER;
102 plan->flags = F_LESSTHAN;
105 plan->flags = F_EQUAL;
110 * Convert the string with strtoq(). Note, if strtoq() returns zero
111 * and endchar points to the beginning of the string we know we have
114 value = strtoq(str, &endchar, 10);
115 if (value == 0 && endchar == str)
116 errx(1, "%s: %s: illegal numeric value", option, vp);
117 if (endchar[0] && (endch == NULL || endchar[0] != *endch))
118 errx(1, "%s: %s: illegal trailing character", option, vp);
125 * The value of n for the inode times (atime, ctime, and mtime) is a range,
126 * i.e. n matches from (n - 1) to n 24 hour periods. This interacts with
127 * -n, such that "-mtime -1" would be less than 0 days, which isn't what the
128 * user wanted. Correct so that -1 is "less than 1".
130 #define TIME_CORRECT(p, ttype) \
131 if ((p)->type == ttype && (p)->flags == F_LESSTHAN) \
135 * -amin n functions --
137 * True if the difference between the file access time and the
138 * current time is n min periods.
147 COMPARE((now - entry->fts_statp->st_atime +
148 60 - 1) / 60, plan->t_data);
157 ftsoptions &= ~FTS_NOSTAT;
159 new = palloc(N_AMIN, f_amin);
160 new->t_data = find_parsenum(new, "-amin", arg, NULL);
161 TIME_CORRECT(new, N_AMIN);
167 * -atime n functions --
169 * True if the difference between the file access time and the
170 * current time is n 24 hour periods.
179 COMPARE((now - entry->fts_statp->st_atime +
180 86400 - 1) / 86400, plan->t_data);
189 ftsoptions &= ~FTS_NOSTAT;
191 new = palloc(N_ATIME, f_atime);
192 new->t_data = find_parsenum(new, "-atime", arg, NULL);
193 TIME_CORRECT(new, N_ATIME);
199 * -cmin n functions --
201 * True if the difference between the last change of file
202 * status information and the current time is n min periods.
211 COMPARE((now - entry->fts_statp->st_ctime +
212 60 - 1) / 60, plan->t_data);
221 ftsoptions &= ~FTS_NOSTAT;
223 new = palloc(N_CMIN, f_cmin);
224 new->t_data = find_parsenum(new, "-cmin", arg, NULL);
225 TIME_CORRECT(new, N_CMIN);
230 * -ctime n functions --
232 * True if the difference between the last change of file
233 * status information and the current time is n 24 hour periods.
242 COMPARE((now - entry->fts_statp->st_ctime +
243 86400 - 1) / 86400, plan->t_data);
252 ftsoptions &= ~FTS_NOSTAT;
254 new = palloc(N_CTIME, f_ctime);
255 new->t_data = find_parsenum(new, "-ctime", arg, NULL);
256 TIME_CORRECT(new, N_CTIME);
262 * -depth functions --
264 * Always true, causes descent of the directory hierarchy to be done
265 * so that all entries in a directory are acted on before the directory
269 f_always_true(plan, entry)
281 return (palloc(N_DEPTH, f_always_true));
285 * [-exec | -ok] utility [arg ... ] ; functions --
287 * True if the executed utility returns a zero value as exit status.
288 * The end of the primary expression is delimited by a semicolon. If
289 * "{}" occurs anywhere, it gets replaced by the current pathname.
290 * The current directory for the execution of utility is the same as
291 * the current directory when the find utility was started.
293 * The primary -ok is different in that it requests affirmation of the
294 * user before executing the utility.
306 for (cnt = 0; plan->e_argv[cnt]; ++cnt)
307 if (plan->e_len[cnt])
308 brace_subst(plan->e_orig[cnt], &plan->e_argv[cnt],
309 entry->fts_path, plan->e_len[cnt]);
311 if (plan->flags == F_NEEDOK && !queryuser(plan->e_argv))
314 /* make sure find output is interspersed correctly with subprocesses */
317 switch (pid = fork()) {
326 execvp(plan->e_argv[0], plan->e_argv);
327 warn("%s", plan->e_argv[0]);
330 pid = waitpid(pid, &status, 0);
331 return (pid != -1 && WIFEXITED(status) && !WEXITSTATUS(status));
336 * build three parallel arrays, one with pointers to the strings passed
337 * on the command line, one with (possibly duplicated) pointers to the
338 * argv array, and one with integer values that are lengths of the
339 * strings, but also flags meaning that the string has to be massaged.
346 PLAN *new; /* node returned */
348 register char **argv, **ap, *p;
352 new = palloc(N_EXEC, f_exec);
354 new->flags = F_NEEDOK;
356 for (ap = argv = *argvp;; ++ap) {
359 "%s: no terminating \";\"", isok ? "-ok" : "-exec");
364 cnt = ap - *argvp + 1;
365 new->e_argv = (char **)emalloc((u_int)cnt * sizeof(char *));
366 new->e_orig = (char **)emalloc((u_int)cnt * sizeof(char *));
367 new->e_len = (int *)emalloc((u_int)cnt * sizeof(int));
369 for (argv = *argvp, cnt = 0; argv < ap; ++argv, ++cnt) {
370 new->e_orig[cnt] = *argv;
371 for (p = *argv; *p; ++p)
372 if (p[0] == '{' && p[1] == '}') {
373 new->e_argv[cnt] = emalloc((u_int)MAXPATHLEN);
374 new->e_len[cnt] = MAXPATHLEN;
378 new->e_argv[cnt] = *argv;
382 new->e_argv[cnt] = new->e_orig[cnt] = NULL;
389 * -empty functions --
391 * True if the file or directory is empty
398 if (S_ISREG(entry->fts_statp->st_mode) && entry->fts_statp->st_size == 0)
400 if (S_ISDIR(entry->fts_statp->st_mode)) {
406 dir = opendir(entry->fts_accpath);
408 err(1, "%s", entry->fts_accpath);
409 for (dp = readdir(dir); dp; dp = readdir(dir))
410 if (dp->d_name[0] != '.' ||
411 (dp->d_name[1] != '\0' &&
412 (dp->d_name[1] != '.' || dp->d_name[2] != '\0'))) {
425 ftsoptions &= ~FTS_NOSTAT;
427 return (palloc(N_EMPTY, f_empty));
431 * -execdir utility [arg ... ] ; functions --
433 * True if the executed utility returns a zero value as exit status.
434 * The end of the primary expression is delimited by a semicolon. If
435 * "{}" occurs anywhere, it gets replaced by the unqualified pathname.
436 * The current directory for the execution of utility is the same as
437 * the directory where the file lives.
440 f_execdir(plan, entry)
449 /* XXX - if file/dir ends in '/' this will not work -- can it? */
450 if ((file = strrchr(entry->fts_path, '/')))
453 file = entry->fts_path;
455 for (cnt = 0; plan->e_argv[cnt]; ++cnt)
456 if (plan->e_len[cnt])
457 brace_subst(plan->e_orig[cnt], &plan->e_argv[cnt],
458 file, plan->e_len[cnt]);
460 /* don't mix output of command with find output */
464 switch (pid = fork()) {
469 execvp(plan->e_argv[0], plan->e_argv);
470 warn("%s", plan->e_argv[0]);
473 pid = waitpid(pid, &status, 0);
474 return (pid != -1 && WIFEXITED(status) && !WEXITSTATUS(status));
479 * build three parallel arrays, one with pointers to the strings passed
480 * on the command line, one with (possibly duplicated) pointers to the
481 * argv array, and one with integer values that are lengths of the
482 * strings, but also flags meaning that the string has to be massaged.
488 PLAN *new; /* node returned */
490 register char **argv, **ap, *p;
492 ftsoptions &= ~FTS_NOSTAT;
495 new = palloc(N_EXECDIR, f_execdir);
497 for (ap = argv = *argvp;; ++ap) {
500 "-execdir: no terminating \";\"");
505 cnt = ap - *argvp + 1;
506 new->e_argv = (char **)emalloc((u_int)cnt * sizeof(char *));
507 new->e_orig = (char **)emalloc((u_int)cnt * sizeof(char *));
508 new->e_len = (int *)emalloc((u_int)cnt * sizeof(int));
510 for (argv = *argvp, cnt = 0; argv < ap; ++argv, ++cnt) {
511 new->e_orig[cnt] = *argv;
512 for (p = *argv; *p; ++p)
513 if (p[0] == '{' && p[1] == '}') {
514 new->e_argv[cnt] = emalloc((u_int)MAXPATHLEN);
515 new->e_len[cnt] = MAXPATHLEN;
519 new->e_argv[cnt] = *argv;
523 new->e_argv[cnt] = new->e_orig[cnt] = NULL;
530 * -follow functions --
532 * Always true, causes symbolic links to be followed on a global
538 ftsoptions &= ~FTS_PHYSICAL;
539 ftsoptions |= FTS_LOGICAL;
541 return (palloc(N_FOLLOW, f_always_true));
545 * -fstype functions --
547 * True if the file is of a certain type.
550 f_fstype(plan, entry)
554 static dev_t curdev; /* need a guaranteed illegal dev value */
555 static int first = 1;
557 static int val_type, val_flags;
560 /* Only check when we cross mount point. */
561 if (first || curdev != entry->fts_statp->st_dev) {
562 curdev = entry->fts_statp->st_dev;
565 * Statfs follows symlinks; find wants the link's file system,
566 * not where it points.
568 if (entry->fts_info == FTS_SL ||
569 entry->fts_info == FTS_SLNONE) {
570 if ((p = strrchr(entry->fts_accpath, '/')) != NULL)
573 p = entry->fts_accpath;
582 if (statfs(entry->fts_accpath, &sb))
583 err(1, "%s", entry->fts_accpath);
593 * Further tests may need both of these values, so
594 * always copy both of them.
596 val_flags = sb.f_flags;
597 val_type = sb.f_type;
599 switch (plan->flags) {
601 return (val_flags & plan->mt_data) != 0;
603 return (val_type == plan->mt_data);
609 #if !defined(__NetBSD__)
611 f_always_false(plan, entry)
625 ftsoptions &= ~FTS_NOSTAT;
627 new = palloc(N_FSTYPE, f_fstype);
630 * Check first for a filesystem name.
632 if (getvfsbyname(arg, &vfc) == 0) {
633 new->flags = F_MTTYPE;
634 new->mt_data = vfc.vfc_typenum;
640 if (!strcmp(arg, "local")) {
641 new->flags = F_MTFLAG;
642 new->mt_data = MNT_LOCAL;
647 if (!strcmp(arg, "rdonly")) {
648 new->flags = F_MTFLAG;
649 new->mt_data = MNT_RDONLY;
655 * We need to make filesystem checks for filesystems
656 * that exists but aren't in the kernel work.
658 fprintf(stderr, "Warning: Unknown filesystem type %s\n", arg);
661 return (palloc(N_FSTYPE, f_always_false));
666 * -group gname functions --
668 * True if the file belongs to the group gname. If gname is numeric and
669 * an equivalent of the getgrnam() function does not return a valid group
670 * name, gname is taken as a group ID.
677 return (entry->fts_statp->st_gid == plan->g_data);
688 ftsoptions &= ~FTS_NOSTAT;
693 if (gid == 0 && gname[0] != '0')
694 errx(1, "-group: %s: no such group", gname);
698 new = palloc(N_GROUP, f_group);
704 * -inum n functions --
706 * True if the file has inode # n.
713 COMPARE(entry->fts_statp->st_ino, plan->i_data);
722 ftsoptions &= ~FTS_NOSTAT;
724 new = palloc(N_INUM, f_inum);
725 new->i_data = find_parsenum(new, "-inum", arg, NULL);
730 * -links n functions --
732 * True if the file has n links.
739 COMPARE(entry->fts_statp->st_nlink, plan->l_data);
748 ftsoptions &= ~FTS_NOSTAT;
750 new = palloc(N_LINKS, f_links);
751 new->l_data = (nlink_t)find_parsenum(new, "-links", arg, NULL);
758 * Always true - prints the current entry to stdout in "ls" format.
765 printlong(entry->fts_path, entry->fts_accpath, entry->fts_statp);
772 ftsoptions &= ~FTS_NOSTAT;
775 return (palloc(N_LS, f_ls));
779 * -maxdepth n functions --
781 * Does the same as -prune if the level of the current file is greater
782 * than the specified maximum depth.
784 * Note that -maxdepth and -mindepth are handled specially in
785 * find_execute() so their f_* functions here do nothing.
788 f_maxdepth(plan, entry)
802 /* all other errors handled by find_parsenum() */
803 errx(1, "-maxdepth: %s: value must be positive", arg);
805 new = palloc(N_MAXDEPTH, f_maxdepth);
806 maxdepth = find_parsenum(new, "-maxdepth", arg, NULL);
811 * -mindepth n functions --
813 * True if the current file is at or deeper than the specified minimum
817 f_mindepth(plan, entry)
831 /* all other errors handled by find_parsenum() */
832 errx(1, "-maxdepth: %s: value must be positive", arg);
834 new = palloc(N_MINDEPTH, f_mindepth);
835 mindepth = find_parsenum(new, "-mindepth", arg, NULL);
840 * -mtime n functions --
842 * True if the difference between the file modification time and the
843 * current time is n 24 hour periods.
852 COMPARE((now - entry->fts_statp->st_mtime + 86400 - 1) /
853 86400, plan->t_data);
862 ftsoptions &= ~FTS_NOSTAT;
864 new = palloc(N_MTIME, f_mtime);
865 new->t_data = find_parsenum(new, "-mtime", arg, NULL);
866 TIME_CORRECT(new, N_MTIME);
871 * -mmin n functions --
873 * True if the difference between the file modification time and the
874 * current time is n min periods.
883 COMPARE((now - entry->fts_statp->st_mtime + 60 - 1) /
893 ftsoptions &= ~FTS_NOSTAT;
895 new = palloc(N_MMIN, f_mmin);
896 new->t_data = find_parsenum(new, "-mmin", arg, NULL);
897 TIME_CORRECT(new, N_MMIN);
905 * True if the basename of the filename being examined
906 * matches pattern using Pattern Matching Notation S3.14
913 return (!fnmatch(plan->c_data, entry->fts_name, 0));
922 new = palloc(N_NAME, f_name);
923 new->c_data = pattern;
928 * -newer file functions --
930 * True if the current file has been modified more recently
931 * then the modification time of the file named by the pathname
939 return (entry->fts_statp->st_mtime > plan->t_data);
949 ftsoptions &= ~FTS_NOSTAT;
951 if (stat(filename, &sb))
952 err(1, "%s", filename);
953 new = palloc(N_NEWER, f_newer);
954 new->t_data = sb.st_mtime;
959 * -nogroup functions --
961 * True if file belongs to a user ID for which the equivalent
962 * of the getgrnam() 9.2.1 [POSIX.1] function returns NULL.
965 f_nogroup(plan, entry)
969 return (group_from_gid(entry->fts_statp->st_gid, 1) ? 0 : 1);
975 ftsoptions &= ~FTS_NOSTAT;
977 return (palloc(N_NOGROUP, f_nogroup));
981 * -nouser functions --
983 * True if file belongs to a user ID for which the equivalent
984 * of the getpwuid() 9.2.2 [POSIX.1] function returns NULL.
987 f_nouser(plan, entry)
991 return (user_from_uid(entry->fts_statp->st_uid, 1) ? 0 : 1);
997 ftsoptions &= ~FTS_NOSTAT;
999 return (palloc(N_NOUSER, f_nouser));
1003 * -path functions --
1005 * True if the path of the filename being examined
1006 * matches pattern using Pattern Matching Notation S3.14
1013 return (!fnmatch(plan->c_data, entry->fts_path, 0));
1022 new = palloc(N_NAME, f_path);
1023 new->c_data = pattern;
1028 * -perm functions --
1030 * The mode argument is used to represent file mode bits. If it starts
1031 * with a leading digit, it's treated as an octal mode, otherwise as a
1041 mode = entry->fts_statp->st_mode &
1042 (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO);
1043 if (plan->flags == F_ATLEAST)
1044 return ((plan->m_data | mode) == mode);
1045 else if (plan->flags == F_ANY )
1046 return (plan->m_data & mode);
1048 return (mode == plan->m_data);
1059 ftsoptions &= ~FTS_NOSTAT;
1061 new = palloc(N_PERM, f_perm);
1064 new->flags = F_ATLEAST;
1066 } else if (*perm == '+') {
1071 if ((set = setmode(perm)) == NULL)
1072 errx(1, "-perm: %s: illegal mode string", perm);
1074 new->m_data = getmode(set, 0);
1080 * -flags functions --
1082 * The flags argument is used to represent file flags bits.
1085 f_flags(plan, entry)
1091 flags = entry->fts_statp->st_flags &
1092 (UF_NODUMP | UF_IMMUTABLE | UF_APPEND | UF_OPAQUE |
1093 SF_ARCHIVED | SF_IMMUTABLE | SF_APPEND);
1094 if (plan->flags == F_ATLEAST)
1095 /* note that plan->fl_flags always is a subset of
1097 return (flags & plan->fl_mask) == plan->fl_flags;
1099 return flags == plan->fl_flags;
1108 u_long flags, notflags;
1110 ftsoptions &= ~FTS_NOSTAT;
1112 new = palloc(N_FLAGS, f_flags);
1114 if (*flags_str == '-') {
1115 new->flags = F_ATLEAST;
1118 if (strtofflags(&flags_str, &flags, ¬flags) == 1)
1119 errx(1, "-flags: %s: illegal flags string", flags_str);
1121 new->fl_flags = flags;
1122 new->fl_mask = flags | notflags;
1124 printf("flags = %08x, mask = %08x (%08x, %08x)\n",
1125 new->fl_flags, new->fl_mask, flags, notflags);
1131 * -print functions --
1133 * Always true, causes the current pathame to be written to
1137 f_print(plan, entry)
1141 (void)puts(entry->fts_path);
1150 return (palloc(N_PRINT, f_print));
1154 * -print0 functions --
1156 * Always true, causes the current pathame to be written to
1157 * standard output followed by a NUL character
1160 f_print0(plan, entry)
1164 fputs(entry->fts_path, stdout);
1165 fputc('\0', stdout);
1174 return (palloc(N_PRINT0, f_print0));
1178 * -prune functions --
1180 * Prune a portion of the hierarchy.
1183 f_prune(plan, entry)
1189 if (fts_set(tree, entry, FTS_SKIP))
1190 err(1, "%s", entry->fts_path);
1197 return (palloc(N_PRUNE, f_prune));
1201 * -size n[c] functions --
1203 * True if the file size in bytes, divided by an implementation defined
1204 * value and rounded up to the next integer, is n. If n is followed by
1205 * a c, the size is in bytes.
1207 #define FIND_SIZE 512
1208 static int divsize = 1;
1217 size = divsize ? (entry->fts_statp->st_size + FIND_SIZE - 1) /
1218 FIND_SIZE : entry->fts_statp->st_size;
1219 COMPARE(size, plan->o_data);
1229 ftsoptions &= ~FTS_NOSTAT;
1231 new = palloc(N_SIZE, f_size);
1233 new->o_data = find_parsenum(new, "-size", arg, &endch);
1240 * -type c functions --
1242 * True if the type of the file is c, where c is b, c, d, p, f or w
1243 * for block special file, character special file, directory, FIFO,
1244 * regular file or whiteout respectively.
1251 return ((entry->fts_statp->st_mode & S_IFMT) == plan->m_data);
1261 ftsoptions &= ~FTS_NOSTAT;
1263 switch (typestring[0]) {
1288 ftsoptions |= FTS_WHITEOUT;
1290 #endif /* FTS_WHITEOUT */
1292 errx(1, "-type: %s: unknown type", typestring);
1295 new = palloc(N_TYPE, f_type);
1301 * -delete functions --
1303 * True always. Makes it's best shot and continues on regardless.
1306 f_delete(plan, entry)
1310 /* ignore these from fts */
1311 if (strcmp(entry->fts_accpath, ".") == 0 ||
1312 strcmp(entry->fts_accpath, "..") == 0)
1316 if (isdepth == 0 || /* depth off */
1317 (ftsoptions & FTS_NOSTAT) || /* not stat()ing */
1318 !(ftsoptions & FTS_PHYSICAL) || /* physical off */
1319 (ftsoptions & FTS_LOGICAL)) /* or finally, logical on */
1320 errx(1, "-delete: insecure options got turned on");
1322 /* Potentially unsafe - do not accept relative paths whatsoever */
1323 if (strchr(entry->fts_accpath, '/') != NULL)
1324 errx(1, "-delete: %s: relative path potentially not safe",
1325 entry->fts_accpath);
1327 /* Turn off user immutable bits if running as root */
1328 if ((entry->fts_statp->st_flags & (UF_APPEND|UF_IMMUTABLE)) &&
1329 !(entry->fts_statp->st_flags & (SF_APPEND|SF_IMMUTABLE)) &&
1331 chflags(entry->fts_accpath,
1332 entry->fts_statp->st_flags &= ~(UF_APPEND|UF_IMMUTABLE));
1334 /* rmdir directories, unlink everything else */
1335 if (S_ISDIR(entry->fts_statp->st_mode)) {
1336 if (rmdir(entry->fts_accpath) < 0 && errno != ENOTEMPTY)
1337 warn("-delete: rmdir(%s)", entry->fts_path);
1339 if (unlink(entry->fts_accpath) < 0)
1340 warn("-delete: unlink(%s)", entry->fts_path);
1351 ftsoptions &= ~FTS_NOSTAT; /* no optimise */
1352 ftsoptions |= FTS_PHYSICAL; /* disable -follow */
1353 ftsoptions &= ~FTS_LOGICAL; /* disable -follow */
1354 isoutput = 1; /* possible output */
1355 isdepth = 1; /* -depth implied */
1357 return (palloc(N_DELETE, f_delete));
1361 * -user uname functions --
1363 * True if the file belongs to the user uname. If uname is numeric and
1364 * an equivalent of the getpwnam() S9.2.2 [POSIX.1] function does not
1365 * return a valid user name, uname is taken as a user ID.
1372 return (entry->fts_statp->st_uid == plan->u_data);
1383 ftsoptions &= ~FTS_NOSTAT;
1385 p = getpwnam(username);
1387 uid = atoi(username);
1388 if (uid == 0 && username[0] != '0')
1389 errx(1, "-user: %s: no such user", username);
1393 new = palloc(N_USER, f_user);
1399 * -xdev functions --
1401 * Always true, causes find not to decend past directories that have a
1402 * different device ID (st_dev, see stat() S5.6.2 [POSIX.1])
1407 ftsoptions |= FTS_XDEV;
1409 return (palloc(N_XDEV, f_always_true));
1413 * ( expression ) functions --
1415 * True if expression is true.
1426 for (p = plan->p_data[0];
1427 p && (state = (p->eval)(p, entry)); p = p->next);
1432 * N_OPENPAREN and N_CLOSEPAREN nodes are temporary place markers. They are
1433 * eliminated during phase 2 of find_formplan() --- the '(' node is converted
1434 * to a N_EXPR node containing the expression and the ')' node is discarded.
1439 return (palloc(N_OPENPAREN, (int (*)())-1));
1445 return (palloc(N_CLOSEPAREN, (int (*)())-1));
1449 * ! expression functions --
1451 * Negation of a primary; the unary NOT operator.
1462 for (p = plan->p_data[0];
1463 p && (state = (p->eval)(p, entry)); p = p->next);
1470 return (palloc(N_NOT, f_not));
1474 * expression -o expression functions --
1476 * Alternation of primaries; the OR operator. The second expression is
1477 * not evaluated if the first expression is true.
1488 for (p = plan->p_data[0];
1489 p && (state = (p->eval)(p, entry)); p = p->next);
1494 for (p = plan->p_data[1];
1495 p && (state = (p->eval)(p, entry)); p = p->next);
1502 return (palloc(N_OR, f_or));
1508 int (*f) __P((PLAN *, FTSENT *));
1512 if ((new = malloc(sizeof(PLAN))) == NULL)