function.c revision 1.21 1 1.21 lukem /* $NetBSD: function.c,v 1.21 1997/10/19 11:52:32 lukem Exp $ */
2 1.18 tls
3 1.1 cgd /*-
4 1.10 jtc * Copyright (c) 1990, 1993
5 1.10 jtc * The Regents of the University of California. All rights reserved.
6 1.1 cgd *
7 1.1 cgd * This code is derived from software contributed to Berkeley by
8 1.1 cgd * Cimarron D. Taylor of the University of California, Berkeley.
9 1.1 cgd *
10 1.1 cgd * Redistribution and use in source and binary forms, with or without
11 1.1 cgd * modification, are permitted provided that the following conditions
12 1.1 cgd * are met:
13 1.1 cgd * 1. Redistributions of source code must retain the above copyright
14 1.1 cgd * notice, this list of conditions and the following disclaimer.
15 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 cgd * notice, this list of conditions and the following disclaimer in the
17 1.1 cgd * documentation and/or other materials provided with the distribution.
18 1.1 cgd * 3. All advertising materials mentioning features or use of this software
19 1.1 cgd * must display the following acknowledgement:
20 1.1 cgd * This product includes software developed by the University of
21 1.1 cgd * California, Berkeley and its contributors.
22 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
23 1.1 cgd * may be used to endorse or promote products derived from this software
24 1.1 cgd * without specific prior written permission.
25 1.1 cgd *
26 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 1.1 cgd * SUCH DAMAGE.
37 1.1 cgd */
38 1.1 cgd
39 1.21 lukem #include <sys/cdefs.h>
40 1.1 cgd #ifndef lint
41 1.21 lukem #if 0
42 1.21 lukem static char sccsid[] = "from: @(#)function.c 8.1 (Berkeley) 6/6/93";
43 1.21 lukem #else
44 1.21 lukem __RCSID("$NetBSD: function.c,v 1.21 1997/10/19 11:52:32 lukem Exp $");
45 1.21 lukem #endif
46 1.1 cgd #endif /* not lint */
47 1.1 cgd
48 1.1 cgd #include <sys/param.h>
49 1.10 jtc #include <sys/ucred.h>
50 1.1 cgd #include <sys/stat.h>
51 1.1 cgd #include <sys/wait.h>
52 1.1 cgd #include <sys/mount.h>
53 1.10 jtc
54 1.10 jtc #include <err.h>
55 1.1 cgd #include <errno.h>
56 1.10 jtc #include <fnmatch.h>
57 1.10 jtc #include <fts.h>
58 1.1 cgd #include <grp.h>
59 1.1 cgd #include <pwd.h>
60 1.1 cgd #include <stdio.h>
61 1.1 cgd #include <stdlib.h>
62 1.1 cgd #include <string.h>
63 1.10 jtc #include <tzfile.h>
64 1.10 jtc #include <unistd.h>
65 1.10 jtc
66 1.1 cgd #include "find.h"
67 1.1 cgd
68 1.10 jtc #define COMPARE(a, b) { \
69 1.10 jtc switch (plan->flags) { \
70 1.10 jtc case F_EQUAL: \
71 1.10 jtc return (a == b); \
72 1.10 jtc case F_LESSTHAN: \
73 1.10 jtc return (a < b); \
74 1.10 jtc case F_GREATER: \
75 1.10 jtc return (a > b); \
76 1.10 jtc default: \
77 1.10 jtc abort(); \
78 1.10 jtc } \
79 1.1 cgd }
80 1.1 cgd
81 1.21 lukem static long find_parsenum __P((PLAN *, char *, char *, char *));
82 1.21 lukem int f_always_true __P((PLAN *, FTSENT *));
83 1.21 lukem int f_atime __P((PLAN *, FTSENT *));
84 1.21 lukem int f_ctime __P((PLAN *, FTSENT *));
85 1.21 lukem int f_exec __P((PLAN *, FTSENT *));
86 1.21 lukem int f_fstype __P((PLAN *, FTSENT *));
87 1.21 lukem int f_group __P((PLAN *, FTSENT *));
88 1.21 lukem int f_inum __P((PLAN *, FTSENT *));
89 1.21 lukem int f_links __P((PLAN *, FTSENT *));
90 1.21 lukem int f_ls __P((PLAN *, FTSENT *));
91 1.21 lukem int f_mtime __P((PLAN *, FTSENT *));
92 1.21 lukem int f_name __P((PLAN *, FTSENT *));
93 1.21 lukem int f_newer __P((PLAN *, FTSENT *));
94 1.21 lukem int f_nogroup __P((PLAN *, FTSENT *));
95 1.21 lukem int f_nouser __P((PLAN *, FTSENT *));
96 1.21 lukem int f_path __P((PLAN *, FTSENT *));
97 1.21 lukem int f_perm __P((PLAN *, FTSENT *));
98 1.21 lukem int f_print __P((PLAN *, FTSENT *));
99 1.21 lukem int f_print0 __P((PLAN *, FTSENT *));
100 1.21 lukem int f_prune __P((PLAN *, FTSENT *));
101 1.21 lukem int f_size __P((PLAN *, FTSENT *));
102 1.21 lukem int f_type __P((PLAN *, FTSENT *));
103 1.21 lukem int f_user __P((PLAN *, FTSENT *));
104 1.21 lukem int f_not __P((PLAN *, FTSENT *));
105 1.21 lukem int f_or __P((PLAN *, FTSENT *));
106 1.21 lukem static PLAN *palloc __P((enum ntype, int (*) __P((PLAN *, FTSENT *))));
107 1.1 cgd
108 1.1 cgd /*
109 1.1 cgd * find_parsenum --
110 1.1 cgd * Parse a string of the form [+-]# and return the value.
111 1.1 cgd */
112 1.10 jtc static long
113 1.10 jtc find_parsenum(plan, option, vp, endch)
114 1.1 cgd PLAN *plan;
115 1.10 jtc char *option, *vp, *endch;
116 1.1 cgd {
117 1.1 cgd long value;
118 1.10 jtc char *endchar, *str; /* Pointer to character ending conversion. */
119 1.1 cgd
120 1.10 jtc /* Determine comparison from leading + or -. */
121 1.10 jtc str = vp;
122 1.10 jtc switch (*str) {
123 1.1 cgd case '+':
124 1.1 cgd ++str;
125 1.10 jtc plan->flags = F_GREATER;
126 1.1 cgd break;
127 1.1 cgd case '-':
128 1.1 cgd ++str;
129 1.10 jtc plan->flags = F_LESSTHAN;
130 1.1 cgd break;
131 1.1 cgd default:
132 1.10 jtc plan->flags = F_EQUAL;
133 1.1 cgd break;
134 1.1 cgd }
135 1.1 cgd
136 1.1 cgd /*
137 1.10 jtc * Convert the string with strtol(). Note, if strtol() returns zero
138 1.1 cgd * and endchar points to the beginning of the string we know we have
139 1.1 cgd * a syntax error.
140 1.1 cgd */
141 1.1 cgd value = strtol(str, &endchar, 10);
142 1.10 jtc if (value == 0 && endchar == str)
143 1.10 jtc errx(1, "%s: %s: illegal numeric value", option, vp);
144 1.10 jtc if (endchar[0] && (endch == NULL || endchar[0] != *endch))
145 1.10 jtc errx(1, "%s: %s: illegal trailing character", option, vp);
146 1.1 cgd if (endch)
147 1.1 cgd *endch = endchar[0];
148 1.10 jtc return (value);
149 1.1 cgd }
150 1.1 cgd
151 1.1 cgd /*
152 1.10 jtc * The value of n for the inode times (atime, ctime, and mtime) is a range,
153 1.10 jtc * i.e. n matches from (n - 1) to n 24 hour periods. This interacts with
154 1.10 jtc * -n, such that "-mtime -1" would be less than 0 days, which isn't what the
155 1.10 jtc * user wanted. Correct so that -1 is "less than 1".
156 1.10 jtc */
157 1.10 jtc #define TIME_CORRECT(p, ttype) \
158 1.10 jtc if ((p)->type == ttype && (p)->flags == F_LESSTHAN) \
159 1.10 jtc ++((p)->t_data);
160 1.10 jtc
161 1.10 jtc /*
162 1.1 cgd * -atime n functions --
163 1.1 cgd *
164 1.1 cgd * True if the difference between the file access time and the
165 1.1 cgd * current time is n 24 hour periods.
166 1.1 cgd */
167 1.10 jtc int
168 1.1 cgd f_atime(plan, entry)
169 1.1 cgd PLAN *plan;
170 1.1 cgd FTSENT *entry;
171 1.1 cgd {
172 1.1 cgd extern time_t now;
173 1.1 cgd
174 1.7 deraadt COMPARE((now - entry->fts_statp->st_atime +
175 1.1 cgd SECSPERDAY - 1) / SECSPERDAY, plan->t_data);
176 1.1 cgd }
177 1.1 cgd
178 1.1 cgd PLAN *
179 1.1 cgd c_atime(arg)
180 1.1 cgd char *arg;
181 1.1 cgd {
182 1.1 cgd PLAN *new;
183 1.1 cgd
184 1.1 cgd ftsoptions &= ~FTS_NOSTAT;
185 1.1 cgd
186 1.1 cgd new = palloc(N_ATIME, f_atime);
187 1.1 cgd new->t_data = find_parsenum(new, "-atime", arg, NULL);
188 1.10 jtc TIME_CORRECT(new, N_ATIME);
189 1.10 jtc return (new);
190 1.1 cgd }
191 1.1 cgd /*
192 1.1 cgd * -ctime n functions --
193 1.1 cgd *
194 1.1 cgd * True if the difference between the last change of file
195 1.1 cgd * status information and the current time is n 24 hour periods.
196 1.1 cgd */
197 1.10 jtc int
198 1.1 cgd f_ctime(plan, entry)
199 1.1 cgd PLAN *plan;
200 1.1 cgd FTSENT *entry;
201 1.1 cgd {
202 1.1 cgd extern time_t now;
203 1.1 cgd
204 1.7 deraadt COMPARE((now - entry->fts_statp->st_ctime +
205 1.1 cgd SECSPERDAY - 1) / SECSPERDAY, plan->t_data);
206 1.1 cgd }
207 1.1 cgd
208 1.1 cgd PLAN *
209 1.1 cgd c_ctime(arg)
210 1.1 cgd char *arg;
211 1.1 cgd {
212 1.1 cgd PLAN *new;
213 1.1 cgd
214 1.1 cgd ftsoptions &= ~FTS_NOSTAT;
215 1.1 cgd
216 1.1 cgd new = palloc(N_CTIME, f_ctime);
217 1.10 jtc new->t_data = find_parsenum(new, "-ctime", arg, NULL);
218 1.10 jtc TIME_CORRECT(new, N_CTIME);
219 1.10 jtc return (new);
220 1.1 cgd }
221 1.1 cgd
222 1.1 cgd /*
223 1.1 cgd * -depth functions --
224 1.1 cgd *
225 1.1 cgd * Always true, causes descent of the directory hierarchy to be done
226 1.1 cgd * so that all entries in a directory are acted on before the directory
227 1.1 cgd * itself.
228 1.1 cgd */
229 1.10 jtc int
230 1.1 cgd f_always_true(plan, entry)
231 1.1 cgd PLAN *plan;
232 1.1 cgd FTSENT *entry;
233 1.1 cgd {
234 1.10 jtc return (1);
235 1.1 cgd }
236 1.1 cgd
237 1.1 cgd PLAN *
238 1.1 cgd c_depth()
239 1.1 cgd {
240 1.1 cgd isdepth = 1;
241 1.1 cgd
242 1.10 jtc return (palloc(N_DEPTH, f_always_true));
243 1.1 cgd }
244 1.1 cgd
245 1.1 cgd /*
246 1.1 cgd * [-exec | -ok] utility [arg ... ] ; functions --
247 1.1 cgd *
248 1.1 cgd * True if the executed utility returns a zero value as exit status.
249 1.1 cgd * The end of the primary expression is delimited by a semicolon. If
250 1.1 cgd * "{}" occurs anywhere, it gets replaced by the current pathname.
251 1.1 cgd * The current directory for the execution of utility is the same as
252 1.1 cgd * the current directory when the find utility was started.
253 1.1 cgd *
254 1.1 cgd * The primary -ok is different in that it requests affirmation of the
255 1.1 cgd * user before executing the utility.
256 1.1 cgd */
257 1.10 jtc int
258 1.1 cgd f_exec(plan, entry)
259 1.21 lukem PLAN *plan;
260 1.1 cgd FTSENT *entry;
261 1.1 cgd {
262 1.1 cgd extern int dotfd;
263 1.21 lukem int cnt;
264 1.1 cgd pid_t pid;
265 1.1 cgd int status;
266 1.1 cgd
267 1.1 cgd for (cnt = 0; plan->e_argv[cnt]; ++cnt)
268 1.1 cgd if (plan->e_len[cnt])
269 1.1 cgd brace_subst(plan->e_orig[cnt], &plan->e_argv[cnt],
270 1.1 cgd entry->fts_path, plan->e_len[cnt]);
271 1.1 cgd
272 1.10 jtc if (plan->flags == F_NEEDOK && !queryuser(plan->e_argv))
273 1.10 jtc return (0);
274 1.11 jtc
275 1.11 jtc /* don't mix output of command with find output */
276 1.11 jtc fflush(stdout);
277 1.11 jtc fflush(stderr);
278 1.1 cgd
279 1.10 jtc switch (pid = vfork()) {
280 1.1 cgd case -1:
281 1.10 jtc err(1, "fork");
282 1.1 cgd /* NOTREACHED */
283 1.1 cgd case 0:
284 1.1 cgd if (fchdir(dotfd)) {
285 1.10 jtc warn("chdir");
286 1.1 cgd _exit(1);
287 1.1 cgd }
288 1.1 cgd execvp(plan->e_argv[0], plan->e_argv);
289 1.10 jtc warn("%s", plan->e_argv[0]);
290 1.1 cgd _exit(1);
291 1.1 cgd }
292 1.1 cgd pid = waitpid(pid, &status, 0);
293 1.10 jtc return (pid != -1 && WIFEXITED(status) && !WEXITSTATUS(status));
294 1.1 cgd }
295 1.1 cgd
296 1.1 cgd /*
297 1.1 cgd * c_exec --
298 1.1 cgd * build three parallel arrays, one with pointers to the strings passed
299 1.1 cgd * on the command line, one with (possibly duplicated) pointers to the
300 1.1 cgd * argv array, and one with integer values that are lengths of the
301 1.1 cgd * strings, but also flags meaning that the string has to be massaged.
302 1.1 cgd */
303 1.1 cgd PLAN *
304 1.1 cgd c_exec(argvp, isok)
305 1.1 cgd char ***argvp;
306 1.1 cgd int isok;
307 1.1 cgd {
308 1.1 cgd PLAN *new; /* node returned */
309 1.21 lukem int cnt;
310 1.21 lukem char **argv, **ap, *p;
311 1.1 cgd
312 1.1 cgd isoutput = 1;
313 1.1 cgd
314 1.1 cgd new = palloc(N_EXEC, f_exec);
315 1.10 jtc if (isok)
316 1.10 jtc new->flags = F_NEEDOK;
317 1.1 cgd
318 1.1 cgd for (ap = argv = *argvp;; ++ap) {
319 1.1 cgd if (!*ap)
320 1.10 jtc errx(1,
321 1.10 jtc "%s: no terminating \";\"", isok ? "-ok" : "-exec");
322 1.1 cgd if (**ap == ';')
323 1.1 cgd break;
324 1.1 cgd }
325 1.1 cgd
326 1.1 cgd cnt = ap - *argvp + 1;
327 1.1 cgd new->e_argv = (char **)emalloc((u_int)cnt * sizeof(char *));
328 1.1 cgd new->e_orig = (char **)emalloc((u_int)cnt * sizeof(char *));
329 1.1 cgd new->e_len = (int *)emalloc((u_int)cnt * sizeof(int));
330 1.1 cgd
331 1.1 cgd for (argv = *argvp, cnt = 0; argv < ap; ++argv, ++cnt) {
332 1.1 cgd new->e_orig[cnt] = *argv;
333 1.1 cgd for (p = *argv; *p; ++p)
334 1.1 cgd if (p[0] == '{' && p[1] == '}') {
335 1.1 cgd new->e_argv[cnt] = emalloc((u_int)MAXPATHLEN);
336 1.1 cgd new->e_len[cnt] = MAXPATHLEN;
337 1.1 cgd break;
338 1.1 cgd }
339 1.1 cgd if (!*p) {
340 1.1 cgd new->e_argv[cnt] = *argv;
341 1.1 cgd new->e_len[cnt] = 0;
342 1.1 cgd }
343 1.1 cgd }
344 1.1 cgd new->e_argv[cnt] = new->e_orig[cnt] = NULL;
345 1.1 cgd
346 1.1 cgd *argvp = argv + 1;
347 1.10 jtc return (new);
348 1.1 cgd }
349 1.1 cgd
350 1.1 cgd /*
351 1.1 cgd * -follow functions --
352 1.1 cgd *
353 1.1 cgd * Always true, causes symbolic links to be followed on a global
354 1.1 cgd * basis.
355 1.1 cgd */
356 1.1 cgd PLAN *
357 1.1 cgd c_follow()
358 1.1 cgd {
359 1.1 cgd ftsoptions &= ~FTS_PHYSICAL;
360 1.1 cgd ftsoptions |= FTS_LOGICAL;
361 1.1 cgd
362 1.10 jtc return (palloc(N_FOLLOW, f_always_true));
363 1.1 cgd }
364 1.1 cgd
365 1.1 cgd /*
366 1.1 cgd * -fstype functions --
367 1.1 cgd *
368 1.1 cgd * True if the file is of a certain type.
369 1.1 cgd */
370 1.10 jtc int
371 1.1 cgd f_fstype(plan, entry)
372 1.1 cgd PLAN *plan;
373 1.1 cgd FTSENT *entry;
374 1.1 cgd {
375 1.1 cgd static dev_t curdev; /* need a guaranteed illegal dev value */
376 1.1 cgd static int first = 1;
377 1.10 jtc struct statfs sb;
378 1.10 jtc static short val;
379 1.16 cgd static char fstype[MFSNAMELEN];
380 1.1 cgd char *p, save[2];
381 1.1 cgd
382 1.10 jtc /* Only check when we cross mount point. */
383 1.7 deraadt if (first || curdev != entry->fts_statp->st_dev) {
384 1.7 deraadt curdev = entry->fts_statp->st_dev;
385 1.1 cgd
386 1.1 cgd /*
387 1.1 cgd * Statfs follows symlinks; find wants the link's file system,
388 1.1 cgd * not where it points.
389 1.1 cgd */
390 1.1 cgd if (entry->fts_info == FTS_SL ||
391 1.1 cgd entry->fts_info == FTS_SLNONE) {
392 1.21 lukem if ((p = strrchr(entry->fts_accpath, '/')) != NULL)
393 1.1 cgd ++p;
394 1.1 cgd else
395 1.1 cgd p = entry->fts_accpath;
396 1.1 cgd save[0] = p[0];
397 1.1 cgd p[0] = '.';
398 1.1 cgd save[1] = p[1];
399 1.1 cgd p[1] = '\0';
400 1.1 cgd
401 1.1 cgd } else
402 1.1 cgd p = NULL;
403 1.1 cgd
404 1.1 cgd if (statfs(entry->fts_accpath, &sb))
405 1.10 jtc err(1, "%s", entry->fts_accpath);
406 1.1 cgd
407 1.1 cgd if (p) {
408 1.1 cgd p[0] = save[0];
409 1.1 cgd p[1] = save[1];
410 1.1 cgd }
411 1.1 cgd
412 1.1 cgd first = 0;
413 1.15 mycroft
414 1.15 mycroft /*
415 1.15 mycroft * Further tests may need both of these values, so
416 1.15 mycroft * always copy both of them.
417 1.15 mycroft */
418 1.15 mycroft val = sb.f_flags;
419 1.15 mycroft strncpy(fstype, sb.f_fstypename, MFSNAMELEN);
420 1.10 jtc }
421 1.14 mycroft switch (plan->flags) {
422 1.10 jtc case F_MTFLAG:
423 1.10 jtc return (val & plan->mt_data);
424 1.10 jtc case F_MTTYPE:
425 1.13 cgd return (strncmp(fstype, plan->c_data, MFSNAMELEN) == 0);
426 1.10 jtc default:
427 1.10 jtc abort();
428 1.1 cgd }
429 1.1 cgd }
430 1.1 cgd
431 1.1 cgd PLAN *
432 1.1 cgd c_fstype(arg)
433 1.1 cgd char *arg;
434 1.1 cgd {
435 1.21 lukem PLAN *new;
436 1.1 cgd
437 1.1 cgd ftsoptions &= ~FTS_NOSTAT;
438 1.1 cgd
439 1.1 cgd new = palloc(N_FSTYPE, f_fstype);
440 1.10 jtc switch (*arg) {
441 1.1 cgd case 'l':
442 1.1 cgd if (!strcmp(arg, "local")) {
443 1.10 jtc new->flags = F_MTFLAG;
444 1.10 jtc new->mt_data = MNT_LOCAL;
445 1.10 jtc return (new);
446 1.1 cgd }
447 1.1 cgd break;
448 1.2 cgd case 'r':
449 1.2 cgd if (!strcmp(arg, "rdonly")) {
450 1.10 jtc new->flags = F_MTFLAG;
451 1.10 jtc new->mt_data = MNT_RDONLY;
452 1.10 jtc return (new);
453 1.1 cgd }
454 1.1 cgd break;
455 1.1 cgd }
456 1.13 cgd
457 1.13 cgd new->flags = F_MTTYPE;
458 1.13 cgd new->c_data = arg;
459 1.13 cgd return (new);
460 1.1 cgd }
461 1.1 cgd
462 1.1 cgd /*
463 1.1 cgd * -group gname functions --
464 1.1 cgd *
465 1.1 cgd * True if the file belongs to the group gname. If gname is numeric and
466 1.1 cgd * an equivalent of the getgrnam() function does not return a valid group
467 1.1 cgd * name, gname is taken as a group ID.
468 1.1 cgd */
469 1.10 jtc int
470 1.1 cgd f_group(plan, entry)
471 1.1 cgd PLAN *plan;
472 1.1 cgd FTSENT *entry;
473 1.1 cgd {
474 1.10 jtc return (entry->fts_statp->st_gid == plan->g_data);
475 1.1 cgd }
476 1.1 cgd
477 1.1 cgd PLAN *
478 1.1 cgd c_group(gname)
479 1.1 cgd char *gname;
480 1.1 cgd {
481 1.1 cgd PLAN *new;
482 1.1 cgd struct group *g;
483 1.1 cgd gid_t gid;
484 1.1 cgd
485 1.1 cgd ftsoptions &= ~FTS_NOSTAT;
486 1.1 cgd
487 1.1 cgd g = getgrnam(gname);
488 1.1 cgd if (g == NULL) {
489 1.1 cgd gid = atoi(gname);
490 1.1 cgd if (gid == 0 && gname[0] != '0')
491 1.10 jtc errx(1, "-group: %s: no such group", gname);
492 1.1 cgd } else
493 1.1 cgd gid = g->gr_gid;
494 1.1 cgd
495 1.1 cgd new = palloc(N_GROUP, f_group);
496 1.1 cgd new->g_data = gid;
497 1.10 jtc return (new);
498 1.1 cgd }
499 1.1 cgd
500 1.1 cgd /*
501 1.1 cgd * -inum n functions --
502 1.1 cgd *
503 1.1 cgd * True if the file has inode # n.
504 1.1 cgd */
505 1.10 jtc int
506 1.1 cgd f_inum(plan, entry)
507 1.1 cgd PLAN *plan;
508 1.1 cgd FTSENT *entry;
509 1.1 cgd {
510 1.7 deraadt COMPARE(entry->fts_statp->st_ino, plan->i_data);
511 1.1 cgd }
512 1.1 cgd
513 1.1 cgd PLAN *
514 1.1 cgd c_inum(arg)
515 1.1 cgd char *arg;
516 1.1 cgd {
517 1.1 cgd PLAN *new;
518 1.1 cgd
519 1.1 cgd ftsoptions &= ~FTS_NOSTAT;
520 1.1 cgd
521 1.1 cgd new = palloc(N_INUM, f_inum);
522 1.10 jtc new->i_data = find_parsenum(new, "-inum", arg, NULL);
523 1.10 jtc return (new);
524 1.1 cgd }
525 1.1 cgd
526 1.1 cgd /*
527 1.1 cgd * -links n functions --
528 1.1 cgd *
529 1.1 cgd * True if the file has n links.
530 1.1 cgd */
531 1.10 jtc int
532 1.1 cgd f_links(plan, entry)
533 1.1 cgd PLAN *plan;
534 1.1 cgd FTSENT *entry;
535 1.1 cgd {
536 1.7 deraadt COMPARE(entry->fts_statp->st_nlink, plan->l_data);
537 1.1 cgd }
538 1.1 cgd
539 1.1 cgd PLAN *
540 1.1 cgd c_links(arg)
541 1.1 cgd char *arg;
542 1.1 cgd {
543 1.1 cgd PLAN *new;
544 1.1 cgd
545 1.1 cgd ftsoptions &= ~FTS_NOSTAT;
546 1.1 cgd
547 1.1 cgd new = palloc(N_LINKS, f_links);
548 1.10 jtc new->l_data = (nlink_t)find_parsenum(new, "-links", arg, NULL);
549 1.10 jtc return (new);
550 1.1 cgd }
551 1.1 cgd
552 1.1 cgd /*
553 1.1 cgd * -ls functions --
554 1.1 cgd *
555 1.1 cgd * Always true - prints the current entry to stdout in "ls" format.
556 1.1 cgd */
557 1.10 jtc int
558 1.1 cgd f_ls(plan, entry)
559 1.1 cgd PLAN *plan;
560 1.1 cgd FTSENT *entry;
561 1.1 cgd {
562 1.7 deraadt printlong(entry->fts_path, entry->fts_accpath, entry->fts_statp);
563 1.10 jtc return (1);
564 1.1 cgd }
565 1.1 cgd
566 1.1 cgd PLAN *
567 1.1 cgd c_ls()
568 1.1 cgd {
569 1.1 cgd ftsoptions &= ~FTS_NOSTAT;
570 1.1 cgd isoutput = 1;
571 1.1 cgd
572 1.10 jtc return (palloc(N_LS, f_ls));
573 1.10 jtc }
574 1.10 jtc
575 1.10 jtc /*
576 1.10 jtc * -mtime n functions --
577 1.10 jtc *
578 1.10 jtc * True if the difference between the file modification time and the
579 1.10 jtc * current time is n 24 hour periods.
580 1.10 jtc */
581 1.10 jtc int
582 1.10 jtc f_mtime(plan, entry)
583 1.10 jtc PLAN *plan;
584 1.10 jtc FTSENT *entry;
585 1.10 jtc {
586 1.10 jtc extern time_t now;
587 1.10 jtc
588 1.10 jtc COMPARE((now - entry->fts_statp->st_mtime + SECSPERDAY - 1) /
589 1.10 jtc SECSPERDAY, plan->t_data);
590 1.10 jtc }
591 1.10 jtc
592 1.10 jtc PLAN *
593 1.10 jtc c_mtime(arg)
594 1.10 jtc char *arg;
595 1.10 jtc {
596 1.10 jtc PLAN *new;
597 1.10 jtc
598 1.10 jtc ftsoptions &= ~FTS_NOSTAT;
599 1.10 jtc
600 1.10 jtc new = palloc(N_MTIME, f_mtime);
601 1.10 jtc new->t_data = find_parsenum(new, "-mtime", arg, NULL);
602 1.10 jtc TIME_CORRECT(new, N_MTIME);
603 1.10 jtc return (new);
604 1.1 cgd }
605 1.1 cgd
606 1.1 cgd /*
607 1.1 cgd * -name functions --
608 1.1 cgd *
609 1.1 cgd * True if the basename of the filename being examined
610 1.1 cgd * matches pattern using Pattern Matching Notation S3.14
611 1.1 cgd */
612 1.10 jtc int
613 1.1 cgd f_name(plan, entry)
614 1.1 cgd PLAN *plan;
615 1.1 cgd FTSENT *entry;
616 1.1 cgd {
617 1.10 jtc return (!fnmatch(plan->c_data, entry->fts_name, 0));
618 1.1 cgd }
619 1.1 cgd
620 1.1 cgd PLAN *
621 1.1 cgd c_name(pattern)
622 1.1 cgd char *pattern;
623 1.1 cgd {
624 1.1 cgd PLAN *new;
625 1.1 cgd
626 1.1 cgd new = palloc(N_NAME, f_name);
627 1.1 cgd new->c_data = pattern;
628 1.10 jtc return (new);
629 1.1 cgd }
630 1.1 cgd
631 1.1 cgd /*
632 1.1 cgd * -newer file functions --
633 1.1 cgd *
634 1.1 cgd * True if the current file has been modified more recently
635 1.1 cgd * then the modification time of the file named by the pathname
636 1.1 cgd * file.
637 1.1 cgd */
638 1.10 jtc int
639 1.1 cgd f_newer(plan, entry)
640 1.1 cgd PLAN *plan;
641 1.1 cgd FTSENT *entry;
642 1.1 cgd {
643 1.10 jtc return (entry->fts_statp->st_mtime > plan->t_data);
644 1.1 cgd }
645 1.1 cgd
646 1.1 cgd PLAN *
647 1.1 cgd c_newer(filename)
648 1.1 cgd char *filename;
649 1.1 cgd {
650 1.1 cgd PLAN *new;
651 1.1 cgd struct stat sb;
652 1.1 cgd
653 1.1 cgd ftsoptions &= ~FTS_NOSTAT;
654 1.1 cgd
655 1.1 cgd if (stat(filename, &sb))
656 1.10 jtc err(1, "%s", filename);
657 1.1 cgd new = palloc(N_NEWER, f_newer);
658 1.1 cgd new->t_data = sb.st_mtime;
659 1.10 jtc return (new);
660 1.1 cgd }
661 1.1 cgd
662 1.1 cgd /*
663 1.1 cgd * -nogroup functions --
664 1.1 cgd *
665 1.1 cgd * True if file belongs to a user ID for which the equivalent
666 1.1 cgd * of the getgrnam() 9.2.1 [POSIX.1] function returns NULL.
667 1.1 cgd */
668 1.10 jtc int
669 1.1 cgd f_nogroup(plan, entry)
670 1.1 cgd PLAN *plan;
671 1.1 cgd FTSENT *entry;
672 1.1 cgd {
673 1.12 andrew return (group_from_gid(entry->fts_statp->st_gid, 1) ? 0 : 1);
674 1.1 cgd }
675 1.1 cgd
676 1.1 cgd PLAN *
677 1.1 cgd c_nogroup()
678 1.1 cgd {
679 1.1 cgd ftsoptions &= ~FTS_NOSTAT;
680 1.1 cgd
681 1.10 jtc return (palloc(N_NOGROUP, f_nogroup));
682 1.1 cgd }
683 1.1 cgd
684 1.1 cgd /*
685 1.1 cgd * -nouser functions --
686 1.1 cgd *
687 1.1 cgd * True if file belongs to a user ID for which the equivalent
688 1.1 cgd * of the getpwuid() 9.2.2 [POSIX.1] function returns NULL.
689 1.1 cgd */
690 1.10 jtc int
691 1.1 cgd f_nouser(plan, entry)
692 1.1 cgd PLAN *plan;
693 1.1 cgd FTSENT *entry;
694 1.1 cgd {
695 1.12 andrew return (user_from_uid(entry->fts_statp->st_uid, 1) ? 0 : 1);
696 1.1 cgd }
697 1.1 cgd
698 1.1 cgd PLAN *
699 1.1 cgd c_nouser()
700 1.1 cgd {
701 1.1 cgd ftsoptions &= ~FTS_NOSTAT;
702 1.1 cgd
703 1.10 jtc return (palloc(N_NOUSER, f_nouser));
704 1.10 jtc }
705 1.10 jtc
706 1.10 jtc /*
707 1.10 jtc * -path functions --
708 1.10 jtc *
709 1.10 jtc * True if the path of the filename being examined
710 1.10 jtc * matches pattern using Pattern Matching Notation S3.14
711 1.10 jtc */
712 1.10 jtc int
713 1.10 jtc f_path(plan, entry)
714 1.10 jtc PLAN *plan;
715 1.10 jtc FTSENT *entry;
716 1.10 jtc {
717 1.10 jtc return (!fnmatch(plan->c_data, entry->fts_path, 0));
718 1.10 jtc }
719 1.10 jtc
720 1.10 jtc PLAN *
721 1.10 jtc c_path(pattern)
722 1.10 jtc char *pattern;
723 1.10 jtc {
724 1.10 jtc PLAN *new;
725 1.10 jtc
726 1.10 jtc new = palloc(N_NAME, f_path);
727 1.10 jtc new->c_data = pattern;
728 1.10 jtc return (new);
729 1.1 cgd }
730 1.1 cgd
731 1.1 cgd /*
732 1.1 cgd * -perm functions --
733 1.1 cgd *
734 1.1 cgd * The mode argument is used to represent file mode bits. If it starts
735 1.1 cgd * with a leading digit, it's treated as an octal mode, otherwise as a
736 1.1 cgd * symbolic mode.
737 1.1 cgd */
738 1.10 jtc int
739 1.1 cgd f_perm(plan, entry)
740 1.1 cgd PLAN *plan;
741 1.1 cgd FTSENT *entry;
742 1.1 cgd {
743 1.1 cgd mode_t mode;
744 1.1 cgd
745 1.7 deraadt mode = entry->fts_statp->st_mode &
746 1.1 cgd (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO);
747 1.10 jtc if (plan->flags == F_ATLEAST)
748 1.10 jtc return ((plan->m_data | mode) == mode);
749 1.1 cgd else
750 1.10 jtc return (mode == plan->m_data);
751 1.1 cgd /* NOTREACHED */
752 1.1 cgd }
753 1.1 cgd
754 1.1 cgd PLAN *
755 1.1 cgd c_perm(perm)
756 1.1 cgd char *perm;
757 1.1 cgd {
758 1.1 cgd PLAN *new;
759 1.1 cgd mode_t *set;
760 1.1 cgd
761 1.1 cgd ftsoptions &= ~FTS_NOSTAT;
762 1.1 cgd
763 1.1 cgd new = palloc(N_PERM, f_perm);
764 1.1 cgd
765 1.1 cgd if (*perm == '-') {
766 1.10 jtc new->flags = F_ATLEAST;
767 1.1 cgd ++perm;
768 1.1 cgd }
769 1.1 cgd
770 1.1 cgd if ((set = setmode(perm)) == NULL)
771 1.10 jtc err(1, "-perm: %s: illegal mode string", perm);
772 1.1 cgd
773 1.1 cgd new->m_data = getmode(set, 0);
774 1.10 jtc return (new);
775 1.1 cgd }
776 1.1 cgd
777 1.1 cgd /*
778 1.1 cgd * -print functions --
779 1.1 cgd *
780 1.1 cgd * Always true, causes the current pathame to be written to
781 1.1 cgd * standard output.
782 1.1 cgd */
783 1.10 jtc int
784 1.1 cgd f_print(plan, entry)
785 1.1 cgd PLAN *plan;
786 1.1 cgd FTSENT *entry;
787 1.1 cgd {
788 1.1 cgd (void)printf("%s\n", entry->fts_path);
789 1.1 cgd return(1);
790 1.1 cgd }
791 1.9 jtc
792 1.21 lukem int
793 1.9 jtc f_print0(plan, entry)
794 1.9 jtc PLAN *plan;
795 1.9 jtc FTSENT *entry;
796 1.9 jtc {
797 1.9 jtc (void)fputs(entry->fts_path, stdout);
798 1.9 jtc (void)fputc('\0', stdout);
799 1.9 jtc return(1);
800 1.9 jtc }
801 1.1 cgd
802 1.1 cgd PLAN *
803 1.1 cgd c_print()
804 1.1 cgd {
805 1.1 cgd isoutput = 1;
806 1.1 cgd
807 1.1 cgd return(palloc(N_PRINT, f_print));
808 1.9 jtc }
809 1.9 jtc
810 1.9 jtc PLAN *
811 1.9 jtc c_print0()
812 1.9 jtc {
813 1.9 jtc isoutput = 1;
814 1.9 jtc
815 1.9 jtc return(palloc(N_PRINT0, f_print0));
816 1.1 cgd }
817 1.1 cgd
818 1.1 cgd /*
819 1.1 cgd * -prune functions --
820 1.1 cgd *
821 1.1 cgd * Prune a portion of the hierarchy.
822 1.1 cgd */
823 1.10 jtc int
824 1.1 cgd f_prune(plan, entry)
825 1.1 cgd PLAN *plan;
826 1.1 cgd FTSENT *entry;
827 1.1 cgd {
828 1.1 cgd extern FTS *tree;
829 1.1 cgd
830 1.1 cgd if (fts_set(tree, entry, FTS_SKIP))
831 1.10 jtc err(1, "%s", entry->fts_path);
832 1.10 jtc return (1);
833 1.1 cgd }
834 1.1 cgd
835 1.1 cgd PLAN *
836 1.1 cgd c_prune()
837 1.1 cgd {
838 1.10 jtc return (palloc(N_PRUNE, f_prune));
839 1.1 cgd }
840 1.1 cgd
841 1.1 cgd /*
842 1.1 cgd * -size n[c] functions --
843 1.1 cgd *
844 1.1 cgd * True if the file size in bytes, divided by an implementation defined
845 1.1 cgd * value and rounded up to the next integer, is n. If n is followed by
846 1.1 cgd * a c, the size is in bytes.
847 1.1 cgd */
848 1.1 cgd #define FIND_SIZE 512
849 1.1 cgd static int divsize = 1;
850 1.1 cgd
851 1.10 jtc int
852 1.1 cgd f_size(plan, entry)
853 1.1 cgd PLAN *plan;
854 1.1 cgd FTSENT *entry;
855 1.1 cgd {
856 1.1 cgd off_t size;
857 1.1 cgd
858 1.7 deraadt size = divsize ? (entry->fts_statp->st_size + FIND_SIZE - 1) /
859 1.7 deraadt FIND_SIZE : entry->fts_statp->st_size;
860 1.1 cgd COMPARE(size, plan->o_data);
861 1.1 cgd }
862 1.1 cgd
863 1.1 cgd PLAN *
864 1.1 cgd c_size(arg)
865 1.1 cgd char *arg;
866 1.1 cgd {
867 1.1 cgd PLAN *new;
868 1.1 cgd char endch;
869 1.1 cgd
870 1.1 cgd ftsoptions &= ~FTS_NOSTAT;
871 1.1 cgd
872 1.1 cgd new = palloc(N_SIZE, f_size);
873 1.8 cgd endch = 'c';
874 1.1 cgd new->o_data = find_parsenum(new, "-size", arg, &endch);
875 1.1 cgd if (endch == 'c')
876 1.1 cgd divsize = 0;
877 1.10 jtc return (new);
878 1.1 cgd }
879 1.1 cgd
880 1.1 cgd /*
881 1.1 cgd * -type c functions --
882 1.1 cgd *
883 1.1 cgd * True if the type of the file is c, where c is b, c, d, p, or f for
884 1.1 cgd * block special file, character special file, directory, FIFO, or
885 1.1 cgd * regular file, respectively.
886 1.1 cgd */
887 1.10 jtc int
888 1.1 cgd f_type(plan, entry)
889 1.1 cgd PLAN *plan;
890 1.1 cgd FTSENT *entry;
891 1.1 cgd {
892 1.10 jtc return ((entry->fts_statp->st_mode & S_IFMT) == plan->m_data);
893 1.1 cgd }
894 1.1 cgd
895 1.1 cgd PLAN *
896 1.1 cgd c_type(typestring)
897 1.1 cgd char *typestring;
898 1.1 cgd {
899 1.1 cgd PLAN *new;
900 1.1 cgd mode_t mask;
901 1.1 cgd
902 1.1 cgd ftsoptions &= ~FTS_NOSTAT;
903 1.1 cgd
904 1.1 cgd switch (typestring[0]) {
905 1.17 mrg #ifdef S_IFWHT
906 1.17 mrg case 'W':
907 1.19 matthias #ifdef FTS_WHITEOUT
908 1.19 matthias ftsoptions |= FTS_WHITEOUT;
909 1.19 matthias #endif
910 1.17 mrg mask = S_IFWHT;
911 1.17 mrg break;
912 1.17 mrg #endif
913 1.1 cgd case 'b':
914 1.1 cgd mask = S_IFBLK;
915 1.1 cgd break;
916 1.1 cgd case 'c':
917 1.1 cgd mask = S_IFCHR;
918 1.1 cgd break;
919 1.1 cgd case 'd':
920 1.1 cgd mask = S_IFDIR;
921 1.1 cgd break;
922 1.1 cgd case 'f':
923 1.1 cgd mask = S_IFREG;
924 1.1 cgd break;
925 1.1 cgd case 'l':
926 1.1 cgd mask = S_IFLNK;
927 1.1 cgd break;
928 1.1 cgd case 'p':
929 1.1 cgd mask = S_IFIFO;
930 1.1 cgd break;
931 1.1 cgd case 's':
932 1.1 cgd mask = S_IFSOCK;
933 1.1 cgd break;
934 1.1 cgd default:
935 1.10 jtc errx(1, "-type: %s: unknown type", typestring);
936 1.1 cgd }
937 1.1 cgd
938 1.1 cgd new = palloc(N_TYPE, f_type);
939 1.1 cgd new->m_data = mask;
940 1.10 jtc return (new);
941 1.1 cgd }
942 1.1 cgd
943 1.1 cgd /*
944 1.1 cgd * -user uname functions --
945 1.1 cgd *
946 1.1 cgd * True if the file belongs to the user uname. If uname is numeric and
947 1.1 cgd * an equivalent of the getpwnam() S9.2.2 [POSIX.1] function does not
948 1.1 cgd * return a valid user name, uname is taken as a user ID.
949 1.1 cgd */
950 1.10 jtc int
951 1.1 cgd f_user(plan, entry)
952 1.1 cgd PLAN *plan;
953 1.1 cgd FTSENT *entry;
954 1.1 cgd {
955 1.10 jtc return (entry->fts_statp->st_uid == plan->u_data);
956 1.1 cgd }
957 1.1 cgd
958 1.1 cgd PLAN *
959 1.1 cgd c_user(username)
960 1.1 cgd char *username;
961 1.1 cgd {
962 1.1 cgd PLAN *new;
963 1.1 cgd struct passwd *p;
964 1.1 cgd uid_t uid;
965 1.1 cgd
966 1.1 cgd ftsoptions &= ~FTS_NOSTAT;
967 1.1 cgd
968 1.1 cgd p = getpwnam(username);
969 1.1 cgd if (p == NULL) {
970 1.1 cgd uid = atoi(username);
971 1.1 cgd if (uid == 0 && username[0] != '0')
972 1.10 jtc errx(1, "-user: %s: no such user", username);
973 1.1 cgd } else
974 1.1 cgd uid = p->pw_uid;
975 1.1 cgd
976 1.1 cgd new = palloc(N_USER, f_user);
977 1.1 cgd new->u_data = uid;
978 1.10 jtc return (new);
979 1.1 cgd }
980 1.1 cgd
981 1.1 cgd /*
982 1.1 cgd * -xdev functions --
983 1.1 cgd *
984 1.1 cgd * Always true, causes find not to decend past directories that have a
985 1.1 cgd * different device ID (st_dev, see stat() S5.6.2 [POSIX.1])
986 1.1 cgd */
987 1.1 cgd PLAN *
988 1.1 cgd c_xdev()
989 1.1 cgd {
990 1.1 cgd ftsoptions |= FTS_XDEV;
991 1.1 cgd
992 1.10 jtc return (palloc(N_XDEV, f_always_true));
993 1.1 cgd }
994 1.1 cgd
995 1.1 cgd /*
996 1.1 cgd * ( expression ) functions --
997 1.1 cgd *
998 1.1 cgd * True if expression is true.
999 1.1 cgd */
1000 1.10 jtc int
1001 1.1 cgd f_expr(plan, entry)
1002 1.1 cgd PLAN *plan;
1003 1.1 cgd FTSENT *entry;
1004 1.1 cgd {
1005 1.21 lukem PLAN *p;
1006 1.21 lukem int state;
1007 1.1 cgd
1008 1.21 lukem state = 0;
1009 1.1 cgd for (p = plan->p_data[0];
1010 1.1 cgd p && (state = (p->eval)(p, entry)); p = p->next);
1011 1.10 jtc return (state);
1012 1.1 cgd }
1013 1.1 cgd
1014 1.1 cgd /*
1015 1.1 cgd * N_OPENPAREN and N_CLOSEPAREN nodes are temporary place markers. They are
1016 1.1 cgd * eliminated during phase 2 of find_formplan() --- the '(' node is converted
1017 1.1 cgd * to a N_EXPR node containing the expression and the ')' node is discarded.
1018 1.1 cgd */
1019 1.1 cgd PLAN *
1020 1.1 cgd c_openparen()
1021 1.1 cgd {
1022 1.21 lukem return (palloc(N_OPENPAREN, (int (*) __P((PLAN *, FTSENT *)))-1));
1023 1.1 cgd }
1024 1.1 cgd
1025 1.1 cgd PLAN *
1026 1.1 cgd c_closeparen()
1027 1.1 cgd {
1028 1.21 lukem return (palloc(N_CLOSEPAREN, (int (*) __P((PLAN *, FTSENT *)))-1));
1029 1.1 cgd }
1030 1.1 cgd
1031 1.1 cgd /*
1032 1.1 cgd * ! expression functions --
1033 1.1 cgd *
1034 1.1 cgd * Negation of a primary; the unary NOT operator.
1035 1.1 cgd */
1036 1.10 jtc int
1037 1.1 cgd f_not(plan, entry)
1038 1.1 cgd PLAN *plan;
1039 1.1 cgd FTSENT *entry;
1040 1.1 cgd {
1041 1.21 lukem PLAN *p;
1042 1.21 lukem int state;
1043 1.1 cgd
1044 1.21 lukem state = 0;
1045 1.1 cgd for (p = plan->p_data[0];
1046 1.1 cgd p && (state = (p->eval)(p, entry)); p = p->next);
1047 1.10 jtc return (!state);
1048 1.1 cgd }
1049 1.1 cgd
1050 1.1 cgd PLAN *
1051 1.1 cgd c_not()
1052 1.1 cgd {
1053 1.10 jtc return (palloc(N_NOT, f_not));
1054 1.1 cgd }
1055 1.1 cgd
1056 1.1 cgd /*
1057 1.1 cgd * expression -o expression functions --
1058 1.1 cgd *
1059 1.1 cgd * Alternation of primaries; the OR operator. The second expression is
1060 1.1 cgd * not evaluated if the first expression is true.
1061 1.1 cgd */
1062 1.10 jtc int
1063 1.1 cgd f_or(plan, entry)
1064 1.1 cgd PLAN *plan;
1065 1.1 cgd FTSENT *entry;
1066 1.1 cgd {
1067 1.21 lukem PLAN *p;
1068 1.21 lukem int state;
1069 1.1 cgd
1070 1.21 lukem state = 0;
1071 1.1 cgd for (p = plan->p_data[0];
1072 1.1 cgd p && (state = (p->eval)(p, entry)); p = p->next);
1073 1.1 cgd
1074 1.1 cgd if (state)
1075 1.10 jtc return (1);
1076 1.1 cgd
1077 1.1 cgd for (p = plan->p_data[1];
1078 1.1 cgd p && (state = (p->eval)(p, entry)); p = p->next);
1079 1.10 jtc return (state);
1080 1.1 cgd }
1081 1.1 cgd
1082 1.1 cgd PLAN *
1083 1.1 cgd c_or()
1084 1.1 cgd {
1085 1.10 jtc return (palloc(N_OR, f_or));
1086 1.1 cgd }
1087 1.1 cgd
1088 1.1 cgd static PLAN *
1089 1.1 cgd palloc(t, f)
1090 1.1 cgd enum ntype t;
1091 1.10 jtc int (*f) __P((PLAN *, FTSENT *));
1092 1.1 cgd {
1093 1.1 cgd PLAN *new;
1094 1.1 cgd
1095 1.21 lukem if ((new = malloc(sizeof(PLAN))) != NULL) {
1096 1.1 cgd new->type = t;
1097 1.1 cgd new->eval = f;
1098 1.1 cgd new->flags = 0;
1099 1.1 cgd new->next = NULL;
1100 1.10 jtc return (new);
1101 1.1 cgd }
1102 1.21 lukem err(1, "malloc");
1103 1.1 cgd /* NOTREACHED */
1104 1.1 cgd }
1105