Findutils 4.3.x defaults to using the the FTS implementation of find.
[findutils.git] / find / defs.h
blob92dfa1afb878e66a6ba008765899cb89951ddd3f
1 /* defs.h -- data types and declarations.
2 Copyright (C) 1990, 91, 92, 93, 94, 2000, 2004 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17 USA.
19 #ifndef INC_DEFS_H
20 #define INC_DEFS_H 1
22 #include <config.h>
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <stdio.h>
27 #if defined(HAVE_STRING_H) || defined(STDC_HEADERS)
28 #include <string.h>
29 #else
30 #include <strings.h>
31 #ifndef strchr
32 #define strchr index
33 #endif
34 #ifndef strrchr
35 #define strrchr rindex
36 #endif
37 #endif
39 #include <errno.h>
40 #ifndef errno
41 extern int errno;
42 #endif
44 #ifdef STDC_HEADERS
45 #include <stdlib.h>
46 #endif
48 /* The presence of unistd.h is assumed by gnulib these days, so we
49 * might as well assume it too.
51 #include <unistd.h>
53 #include <time.h>
55 #if HAVE_LIMITS_H
56 # include <limits.h>
57 #endif
58 #ifndef CHAR_BIT
59 # define CHAR_BIT 8
60 #endif
62 #if HAVE_INTTYPES_H
63 # include <inttypes.h>
64 #endif
66 #include "regex.h"
68 #ifndef S_IFLNK
69 #define lstat stat
70 #endif
72 # ifndef PARAMS
73 # if defined PROTOTYPES || (defined __STDC__ && __STDC__)
74 # define PARAMS(Args) Args
75 # else
76 # define PARAMS(Args) ()
77 # endif
78 # endif
80 int lstat PARAMS((const char *__path, struct stat *__statbuf));
81 int stat PARAMS((const char *__path, struct stat *__statbuf));
83 int optionl_stat PARAMS((const char *name, struct stat *p));
84 int optionp_stat PARAMS((const char *name, struct stat *p));
85 int optionh_stat PARAMS((const char *name, struct stat *p));
86 int debug_stat PARAMS((const char *file, struct stat *bufp));
88 int get_statinfo PARAMS((const char *pathname, const char *name, struct stat *p));
90 #if ! defined HAVE_FCHDIR && ! defined fchdir
91 # define fchdir(fd) (-1)
92 #endif
96 #ifndef S_ISUID
97 # define S_ISUID 0004000
98 #endif
99 #ifndef S_ISGID
100 # define S_ISGID 0002000
101 #endif
102 #ifndef S_ISVTX
103 # define S_ISVTX 0001000
104 #endif
105 #ifndef S_IRUSR
106 # define S_IRUSR 0000400
107 #endif
108 #ifndef S_IWUSR
109 # define S_IWUSR 0000200
110 #endif
111 #ifndef S_IXUSR
112 # define S_IXUSR 0000100
113 #endif
114 #ifndef S_IRGRP
115 # define S_IRGRP 0000040
116 #endif
117 #ifndef S_IWGRP
118 # define S_IWGRP 0000020
119 #endif
120 #ifndef S_IXGRP
121 # define S_IXGRP 0000010
122 #endif
123 #ifndef S_IROTH
124 # define S_IROTH 0000004
125 #endif
126 #ifndef S_IWOTH
127 # define S_IWOTH 0000002
128 #endif
129 #ifndef S_IXOTH
130 # define S_IXOTH 0000001
131 #endif
133 #define MODE_WXUSR (S_IWUSR | S_IXUSR)
134 #define MODE_R (S_IRUSR | S_IRGRP | S_IROTH)
135 #define MODE_RW (S_IWUSR | S_IWGRP | S_IWOTH | MODE_R)
136 #define MODE_RWX (S_IXUSR | S_IXGRP | S_IXOTH | MODE_RW)
137 #define MODE_ALL (S_ISUID | S_ISGID | S_ISVTX | MODE_RWX)
139 #if 1
140 #include <stdbool.h>
141 typedef bool boolean;
142 #else
143 /* Not char because of type promotion; NeXT gcc can't handle it. */
144 typedef int boolean;
145 #define true 1
146 #define false 0
147 #endif
149 struct predicate;
151 /* Pointer to a predicate function. */
152 typedef boolean (*PRED_FUNC)(char *pathname, struct stat *stat_buf, struct predicate *pred_ptr);
154 /* The number of seconds in a day. */
155 #define DAYSECS 86400
157 /* Argument structures for predicates. */
159 enum comparison_type
161 COMP_GT,
162 COMP_LT,
163 COMP_EQ
166 enum permissions_type
168 PERM_AT_LEAST,
169 PERM_ANY,
170 PERM_EXACT
173 enum predicate_type
175 NO_TYPE,
176 PRIMARY_TYPE,
177 UNI_OP,
178 BI_OP,
179 OPEN_PAREN,
180 CLOSE_PAREN
183 enum predicate_precedence
185 NO_PREC,
186 COMMA_PREC,
187 OR_PREC,
188 AND_PREC,
189 NEGATE_PREC,
190 MAX_PREC
193 struct long_val
195 enum comparison_type kind;
196 boolean negative; /* Defined only when representing time_t. */
197 uintmax_t l_val;
200 struct perm_val
202 enum permissions_type kind;
203 mode_t val;
206 /* dir_id is used to support loop detection in find.c and
207 * also to support the -samefile test.
209 struct dir_id
211 ino_t ino;
212 dev_t dev;
215 struct size_val
217 enum comparison_type kind;
218 int blocksize;
219 uintmax_t size;
222 #define NEW_EXEC 1
224 #undef NEW_EXEC
227 #if !defined(NEW_EXEC)
228 struct path_arg
230 short offset; /* Offset in `vec' of this arg. */
231 short count; /* Number of path replacements in this arg. */
232 char *origarg; /* Arg with "{}" intact. */
234 #endif
236 #include "buildcmd.h"
238 struct exec_val
240 #if defined(NEW_EXEC)
241 /* new-style */
242 boolean multiple; /* -exec {} \+ denotes multiple argument. */
243 struct buildcmd_control ctl;
244 struct buildcmd_state state;
245 char **replace_vec; /* Command arguments (for ";" style) */
246 int num_args;
247 boolean use_current_dir; /* If nonzero, don't chdir to start dir */
248 boolean close_stdin; /* If true, close stdin in the child. */
249 #else
250 struct path_arg *paths; /* Array of args with path replacements. */
251 char **vec; /* Array of args to pass to program. */
252 #endif
255 /* The format string for a -printf or -fprintf is chopped into one or
256 more `struct segment', linked together into a list.
257 Each stretch of plain text is a segment, and
258 each \c and `%' conversion is a segment. */
260 /* Special values for the `kind' field of `struct segment'. */
261 #define KIND_PLAIN 0 /* Segment containing just plain text. */
262 #define KIND_STOP 1 /* \c -- stop printing and flush output. */
264 struct segment
266 int kind; /* Format chars or KIND_{PLAIN,STOP}. */
267 char *text; /* Plain text or `%' format string. */
268 int text_len; /* Length of `text'. */
269 struct segment *next; /* Next segment for this predicate. */
272 struct format_val
274 struct segment *segment; /* Linked list of segments. */
275 FILE *stream; /* Output stream to print on. */
276 boolean dest_is_tty; /* True if the destination is a terminal. */
277 struct quoting_options *quote_opts;
280 struct predicate
282 /* Pointer to the function that implements this predicate. */
283 PRED_FUNC pred_func;
285 /* Only used for debugging, but defined unconditionally so individual
286 modules can be compiled with -DDEBUG. */
287 char *p_name;
289 /* The type of this node. There are two kinds. The first is real
290 predicates ("primaries") such as -perm, -print, or -exec. The
291 other kind is operators for combining predicates. */
292 enum predicate_type p_type;
294 /* The precedence of this node. Only has meaning for operators. */
295 enum predicate_precedence p_prec;
297 /* True if this predicate node produces side effects.
298 If side_effects are produced
299 then optimization will not be performed */
300 boolean side_effects;
302 /* True if this predicate node requires default print be turned off. */
303 boolean no_default_print;
305 /* True if this predicate node requires a stat system call to execute. */
306 boolean need_stat;
308 /* True if this predicate node requires knowledge of the file type. */
309 boolean need_type;
311 /* Information needed by the predicate processor.
312 Next to each member are listed the predicates that use it. */
313 union
315 char *str; /* fstype [i]lname [i]name [i]path */
316 struct re_pattern_buffer *regex; /* regex */
317 struct exec_val exec_vec; /* exec ok */
318 struct long_val info; /* atime ctime gid inum links mtime
319 size uid */
320 struct size_val size; /* size */
321 uid_t uid; /* user */
322 gid_t gid; /* group */
323 time_t time; /* newer */
324 struct perm_val perm; /* perm */
325 struct dir_id fileid; /* samefile */
326 mode_t type; /* type */
327 FILE *stream; /* ls fls fprint0 */
328 struct format_val printf_vec; /* printf fprintf fprint */
329 } args;
331 /* The next predicate in the user input sequence,
332 which represents the order in which the user supplied the
333 predicates on the command line. */
334 struct predicate *pred_next;
336 /* The right and left branches from this node in the expression
337 tree, which represents the order in which the nodes should be
338 processed. */
339 struct predicate *pred_left;
340 struct predicate *pred_right;
342 const struct parser_table* parser_entry;
345 /* find.c, ftsfind.c */
346 boolean is_fts_enabled();
350 /* find library function declarations. */
352 /* dirname.c */
353 char *dirname PARAMS((char *path));
355 /* error.c */
356 void error PARAMS((int status, int errnum, char *message, ...));
358 /* listfile.c */
359 void list_file PARAMS((char *name, char *relname, struct stat *statp, time_t current_time, int output_block_size, FILE *stream));
360 char *get_link_name PARAMS((char *name, char *relname));
362 /* stpcpy.c */
363 #if !HAVE_STPCPY
364 char *stpcpy PARAMS((char *dest, const char *src));
365 #endif
367 /* xgetcwd.c */
368 char *xgetcwd PARAMS((void));
370 /* xmalloc.c */
371 #if __STDC__
372 #define VOID void
373 #else
374 #define VOID char
375 #endif
377 /* find global function declarations. */
379 /* find.c */
380 /* SymlinkOption represents the choice of
381 * -P, -L or -P (default) on the command line.
383 enum SymlinkOption
385 SYMLINK_NEVER_DEREF, /* Option -P */
386 SYMLINK_ALWAYS_DEREF, /* Option -L */
387 SYMLINK_DEREF_ARGSONLY /* Option -H */
389 extern enum SymlinkOption symlink_handling; /* defined in find.c. */
391 void set_follow_state PARAMS((enum SymlinkOption opt));
392 void cleanup(void);
394 /* fstype.c */
395 char *filesystem_type PARAMS((const struct stat *statp, const char *path));
396 char * get_mounted_filesystems (void);
397 dev_t * get_mounted_devices PARAMS((size_t *));
401 enum arg_type
403 ARG_OPTION, /* regular options like -maxdepth */
404 ARG_POSITIONAL_OPTION, /* options whose position is important (-follow) */
405 ARG_TEST, /* a like -name */
406 ARG_PUNCTUATION, /* like -o or ( */
407 ARG_ACTION /* like -print */
411 struct parser_table;
412 /* Pointer to a parser function. */
413 typedef boolean (*PARSE_FUNC)(const struct parser_table *p,
414 char *argv[], int *arg_ptr);
415 struct parser_table
417 enum arg_type type;
418 char *parser_name;
419 PARSE_FUNC parser_func;
420 PRED_FUNC pred_func;
423 /* parser.c */
424 const struct parser_table* find_parser PARAMS((char *search_name));
425 boolean parse_open PARAMS((const struct parser_table* entry, char *argv[], int *arg_ptr));
426 boolean parse_close PARAMS((const struct parser_table* entry, char *argv[], int *arg_ptr));
427 boolean parse_print PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
428 void pred_sanity_check PARAMS((const struct predicate *predicates));
429 void parse_begin_user_args PARAMS((char **args, int argno, const struct predicate *last, const struct predicate *predicates));
430 void parse_end_user_args PARAMS((char **args, int argno, const struct predicate *last, const struct predicate *predicates));
432 /* pred.c */
433 boolean pred_amin PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
434 boolean pred_and PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
435 boolean pred_anewer PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
436 boolean pred_atime PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
437 boolean pred_close PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
438 boolean pred_cmin PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
439 boolean pred_cnewer PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
440 boolean pred_comma PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
441 boolean pred_ctime PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
442 boolean pred_delete PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
443 boolean pred_empty PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
444 boolean pred_exec PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
445 boolean pred_execdir PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
446 boolean pred_false PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
447 boolean pred_fls PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
448 boolean pred_fprint PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
449 boolean pred_fprint0 PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
450 boolean pred_fprintf PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
451 boolean pred_fstype PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
452 boolean pred_gid PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
453 boolean pred_group PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
454 boolean pred_ilname PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
455 boolean pred_iname PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
456 boolean pred_inum PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
457 boolean pred_ipath PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
458 boolean pred_links PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
459 boolean pred_lname PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
460 boolean pred_ls PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
461 boolean pred_mmin PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
462 boolean pred_mtime PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
463 boolean pred_name PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
464 boolean pred_negate PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
465 boolean pred_newer PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
466 boolean pred_nogroup PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
467 boolean pred_nouser PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
468 boolean pred_ok PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
469 boolean pred_okdir PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
470 boolean pred_open PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
471 boolean pred_or PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
472 boolean pred_path PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
473 boolean pred_perm PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
474 boolean pred_print PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
475 boolean pred_print0 PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
476 boolean pred_prune PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
477 boolean pred_quit PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
478 boolean pred_regex PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
479 boolean pred_samefile PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
480 boolean pred_size PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
481 boolean pred_true PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
482 boolean pred_type PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
483 boolean pred_uid PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
484 boolean pred_used PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
485 boolean pred_user PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
486 boolean pred_xtype PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
490 int launch PARAMS((const struct buildcmd_control *ctl,
491 struct buildcmd_state *buildstate));
494 char *find_pred_name PARAMS((PRED_FUNC pred_func));
498 #ifdef DEBUG
499 void print_tree PARAMS((FILE*, struct predicate *node, int indent));
500 void print_list PARAMS((FILE*, struct predicate *node));
501 void print_optlist PARAMS((FILE *fp, struct predicate *node));
502 #endif /* DEBUG */
504 /* tree.c */
505 struct predicate *
506 get_expr PARAMS((struct predicate **input, short int prev_prec));
507 boolean opt_expr PARAMS((struct predicate **eval_treep));
508 boolean mark_stat PARAMS((struct predicate *tree));
509 boolean mark_type PARAMS((struct predicate *tree));
511 /* util.c */
512 struct predicate *get_new_pred PARAMS((const struct parser_table *entry));
513 struct predicate *get_new_pred_chk_op PARAMS((const struct parser_table *entry));
514 struct predicate *insert_primary PARAMS((const struct parser_table *entry));
515 struct predicate *insert_primary_withpred PARAMS((const struct parser_table *entry, PRED_FUNC fptr));
516 void usage PARAMS((char *msg));
517 extern boolean check_nofollow(void);
518 extern void complete_pending_execs(struct predicate *p);
519 extern void complete_pending_execdirs(struct predicate *p);
520 /* find.c. */
521 int get_info PARAMS((const char *pathname, const char *name, struct stat *p, struct predicate *pred_ptr));
522 int following_links(void);
523 int digest_mode(mode_t mode, const char *pathname, const char *name, struct stat *pstat, boolean leaf);
524 boolean default_prints (struct predicate *pred);
527 struct options
529 /* If true, process directory before contents. True unless -depth given. */
530 boolean do_dir_first;
532 /* If >=0, don't descend more than this many levels of subdirectories. */
533 int maxdepth;
535 /* If >=0, don't process files above this level. */
536 int mindepth;
538 /* If true, do not assume that files in directories with nlink == 2
539 are non-directories. */
540 boolean no_leaf_check;
542 /* If true, don't cross filesystem boundaries. */
543 boolean stay_on_filesystem;
545 /* If true, we ignore the problem where we find that a directory entry
546 * no longer exists by the time we get around to processing it.
548 boolean ignore_readdir_race;
550 /* If true, we issue warning messages
552 boolean warnings;
553 time_t start_time; /* Time at start of execution. */
555 /* Seconds between 00:00 1/1/70 and either one day before now
556 (the default), or the start of today (if -daystart is given). */
557 time_t cur_day_start;
559 /* If true, cur_day_start has been adjusted to the start of the day. */
560 boolean full_days;
562 int output_block_size; /* Output block size. */
564 enum SymlinkOption symlink_handling;
567 /* Pointer to the function used to stat files. */
568 int (*xstat) (const char *name, struct stat *statbuf);
571 /* Indicate if we can implement safely_chdir() using the O_NOFOLLOW
572 * flag to open(2).
574 boolean open_nofollow_available;
576 /* The variety of regular expression that we support.
577 * The default is POSIX Basic Regular Expressions, but this
578 * can be changed with the positional option, -regextype.
580 int regex_options;
582 extern struct options options;
585 struct state
587 /* Current depth; 0 means current path is a command line arg. */
588 int curdepth;
590 /* If true, we have called stat on the current path. */
591 boolean have_stat;
593 /* If true, we know the type of the current path. */
594 boolean have_type;
595 mode_t type; /* this is the actual type */
597 /* The file being operated on, relative to the current directory.
598 Used for stat, readlink, remove, and opendir. */
599 char *rel_pathname;
601 /* Length of starting path. */
602 int starting_path_length;
604 /* If true, don't descend past current directory.
605 Can be set by -prune, -maxdepth, and -xdev/-mount. */
606 boolean stop_at_current_level;
608 /* Status value to return to system. */
609 int exit_status;
612 /* finddata.c */
613 extern struct state state;
614 extern char const *starting_dir;
615 extern int starting_desc;
616 extern struct predicate *eval_tree;
617 extern char *program_name;
618 extern struct predicate *predicates;
619 extern struct predicate *last_pred;
622 #endif