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)
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,
23 #include <sys/types.h>
27 #if defined(HAVE_STRING_H) || defined(STDC_HEADERS)
35 #define strrchr rindex
48 /* The presence of unistd.h is assumed by gnulib these days, so we
49 * might as well assume it too.
63 # include <inttypes.h>
73 # if defined PROTOTYPES || (defined __STDC__ && __STDC__)
74 # define PARAMS(Args) Args
76 # define PARAMS(Args) ()
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
));
87 int get_statinfo
PARAMS((const char *pathname
, const char *name
, struct stat
*p
));
92 # define S_ISUID 0004000
95 # define S_ISGID 0002000
98 # define S_ISVTX 0001000
101 # define S_IRUSR 0000400
104 # define S_IWUSR 0000200
107 # define S_IXUSR 0000100
110 # define S_IRGRP 0000040
113 # define S_IWGRP 0000020
116 # define S_IXGRP 0000010
119 # define S_IROTH 0000004
122 # define S_IWOTH 0000002
125 # define S_IXOTH 0000001
128 #define MODE_WXUSR (S_IWUSR | S_IXUSR)
129 #define MODE_R (S_IRUSR | S_IRGRP | S_IROTH)
130 #define MODE_RW (S_IWUSR | S_IWGRP | S_IWOTH | MODE_R)
131 #define MODE_RWX (S_IXUSR | S_IXGRP | S_IXOTH | MODE_RW)
132 #define MODE_ALL (S_ISUID | S_ISGID | S_ISVTX | MODE_RWX)
136 typedef bool boolean
;
138 /* Not char because of type promotion; NeXT gcc can't handle it. */
146 /* Pointer to a predicate function. */
147 typedef boolean (*PRED_FUNC
)(char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
);
149 /* The number of seconds in a day. */
150 #define DAYSECS 86400
152 /* Argument structures for predicates. */
161 enum permissions_type
178 enum predicate_precedence
190 enum comparison_type kind
;
191 boolean negative
; /* Defined only when representing time_t. */
197 enum permissions_type kind
;
201 /* dir_id is used to support loop detection in find.c and
202 * also to support the -samefile test.
212 enum comparison_type kind
;
222 #if !defined(NEW_EXEC)
225 short offset
; /* Offset in `vec' of this arg. */
226 short count
; /* Number of path replacements in this arg. */
227 char *origarg
; /* Arg with "{}" intact. */
231 #include "buildcmd.h"
235 #if defined(NEW_EXEC)
237 boolean multiple
; /* -exec {} \+ denotes multiple argument. */
238 struct buildcmd_control ctl
;
239 struct buildcmd_state state
;
240 char **replace_vec
; /* Command arguments (for ";" style) */
242 boolean use_current_dir
; /* If nonzero, don't chdir to start dir */
244 struct path_arg
*paths
; /* Array of args with path replacements. */
245 char **vec
; /* Array of args to pass to program. */
249 /* The format string for a -printf or -fprintf is chopped into one or
250 more `struct segment', linked together into a list.
251 Each stretch of plain text is a segment, and
252 each \c and `%' conversion is a segment. */
254 /* Special values for the `kind' field of `struct segment'. */
255 #define KIND_PLAIN 0 /* Segment containing just plain text. */
256 #define KIND_STOP 1 /* \c -- stop printing and flush output. */
260 int kind
; /* Format chars or KIND_{PLAIN,STOP}. */
261 char *text
; /* Plain text or `%' format string. */
262 int text_len
; /* Length of `text'. */
263 struct segment
*next
; /* Next segment for this predicate. */
268 struct segment
*segment
; /* Linked list of segments. */
269 FILE *stream
; /* Output stream to print on. */
270 boolean dest_is_tty
; /* True if the destination is a terminal. */
271 struct quoting_options
*quote_opts
;
276 /* Pointer to the function that implements this predicate. */
279 /* Only used for debugging, but defined unconditionally so individual
280 modules can be compiled with -DDEBUG. */
283 /* The type of this node. There are two kinds. The first is real
284 predicates ("primaries") such as -perm, -print, or -exec. The
285 other kind is operators for combining predicates. */
286 enum predicate_type p_type
;
288 /* The precedence of this node. Only has meaning for operators. */
289 enum predicate_precedence p_prec
;
291 /* True if this predicate node produces side effects.
292 If side_effects are produced
293 then optimization will not be performed */
294 boolean side_effects
;
296 /* True if this predicate node requires default print be turned off. */
297 boolean no_default_print
;
299 /* True if this predicate node requires a stat system call to execute. */
302 /* True if this predicate node requires knowledge of the file type. */
305 /* Information needed by the predicate processor.
306 Next to each member are listed the predicates that use it. */
309 char *str
; /* fstype [i]lname [i]name [i]path */
310 struct re_pattern_buffer
*regex
; /* regex */
311 struct exec_val exec_vec
; /* exec ok */
312 struct long_val info
; /* atime ctime gid inum links mtime
314 struct size_val size
; /* size */
315 uid_t uid
; /* user */
316 gid_t gid
; /* group */
317 time_t time
; /* newer */
318 struct perm_val perm
; /* perm */
319 struct dir_id fileid
; /* samefile */
320 mode_t type
; /* type */
321 FILE *stream
; /* ls fls fprint0 */
322 struct format_val printf_vec
; /* printf fprintf fprint */
325 /* The next predicate in the user input sequence,
326 which represents the order in which the user supplied the
327 predicates on the command line. */
328 struct predicate
*pred_next
;
330 /* The right and left branches from this node in the expression
331 tree, which represents the order in which the nodes should be
333 struct predicate
*pred_left
;
334 struct predicate
*pred_right
;
336 const struct parser_table
* parser_entry
;
340 int get_info
PARAMS((const char *pathname
, const char *name
, struct stat
*p
, struct predicate
*pred_ptr
));
341 int following_links(void);
344 /* find library function declarations. */
347 char *dirname
PARAMS((char *path
));
350 void error
PARAMS((int status
, int errnum
, char *message
, ...));
353 void list_file
PARAMS((char *name
, char *relname
, struct stat
*statp
, time_t current_time
, int output_block_size
, FILE *stream
));
354 char *get_link_name
PARAMS((char *name
, char *relname
));
358 char *stpcpy
PARAMS((char *dest
, const char *src
));
362 char *xgetcwd
PARAMS((void));
371 /* find global function declarations. */
374 /* SymlinkOption represents the choice of
375 * -P, -L or -P (default) on the command line.
379 SYMLINK_NEVER_DEREF
, /* Option -P */
380 SYMLINK_ALWAYS_DEREF
, /* Option -L */
381 SYMLINK_DEREF_ARGSONLY
/* Option -H */
383 extern enum SymlinkOption symlink_handling
; /* defined in find.c. */
385 void set_follow_state
PARAMS((enum SymlinkOption opt
));
389 char *filesystem_type
PARAMS((const struct stat
*statp
));
390 char * get_mounted_filesystems (void);
391 dev_t
* get_mounted_devices
PARAMS((size_t *));
397 ARG_OPTION
, /* regular options like -maxdepth */
398 ARG_POSITIONAL_OPTION
, /* options whose position is important (-follow) */
399 ARG_TEST
, /* a like -name */
400 ARG_PUNCTUATION
, /* like -o or ( */
401 ARG_ACTION
/* like -print */
406 /* Pointer to a parser function. */
407 typedef boolean (*PARSE_FUNC
)(const struct parser_table
*p
,
408 char *argv
[], int *arg_ptr
);
413 PARSE_FUNC parser_func
;
418 const struct parser_table
* find_parser
PARAMS((char *search_name
));
419 boolean parse_open
PARAMS((const struct parser_table
* entry
, char *argv
[], int *arg_ptr
));
420 boolean parse_close
PARAMS((const struct parser_table
* entry
, char *argv
[], int *arg_ptr
));
421 boolean parse_print
PARAMS((const struct parser_table
*, char *argv
[], int *arg_ptr
));
422 void pred_sanity_check
PARAMS((const struct predicate
*predicates
));
426 boolean pred_amin
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
427 boolean pred_and
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
428 boolean pred_anewer
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
429 boolean pred_atime
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
430 boolean pred_close
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
431 boolean pred_cmin
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
432 boolean pred_cnewer
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
433 boolean pred_comma
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
434 boolean pred_ctime
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
435 boolean pred_delete
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
436 boolean pred_empty
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
437 boolean pred_exec
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
438 boolean pred_execdir
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
439 boolean pred_false
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
440 boolean pred_fls
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
441 boolean pred_fprint
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
442 boolean pred_fprint0
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
443 boolean pred_fprintf
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
444 boolean pred_fstype
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
445 boolean pred_gid
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
446 boolean pred_group
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
447 boolean pred_ilname
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
448 boolean pred_iname
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
449 boolean pred_inum
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
450 boolean pred_ipath
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
451 boolean pred_links
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
452 boolean pred_lname
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
453 boolean pred_ls
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
454 boolean pred_mmin
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
455 boolean pred_mtime
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
456 boolean pred_name
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
457 boolean pred_negate
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
458 boolean pred_newer
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
459 boolean pred_nogroup
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
460 boolean pred_nouser
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
461 boolean pred_ok
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
462 boolean pred_okdir
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
463 boolean pred_open
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
464 boolean pred_or
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
465 boolean pred_path
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
466 boolean pred_perm
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
467 boolean pred_print
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
468 boolean pred_print0
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
469 boolean pred_prune
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
470 boolean pred_quit
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
471 boolean pred_regex
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
472 boolean pred_samefile
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
473 boolean pred_size
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
474 boolean pred_true
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
475 boolean pred_type
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
476 boolean pred_uid
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
477 boolean pred_used
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
478 boolean pred_user
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
479 boolean pred_xtype
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
483 int launch
PARAMS((const struct buildcmd_control
*ctl
,
484 struct buildcmd_state
*buildstate
));
487 char *find_pred_name
PARAMS((PRED_FUNC pred_func
));
492 void print_tree
PARAMS((FILE*, struct predicate
*node
, int indent
));
493 void print_list
PARAMS((FILE*, struct predicate
*node
));
494 void print_optlist
PARAMS((FILE *fp
, struct predicate
*node
));
499 get_expr
PARAMS((struct predicate
**input
, short int prev_prec
));
500 boolean opt_expr
PARAMS((struct predicate
**eval_treep
));
501 boolean mark_stat
PARAMS((struct predicate
*tree
));
502 boolean mark_type
PARAMS((struct predicate
*tree
));
505 struct predicate
*get_new_pred
PARAMS((const struct parser_table
*entry
));
506 struct predicate
*get_new_pred_chk_op
PARAMS((const struct parser_table
*entry
));
507 struct predicate
*insert_primary
PARAMS((const struct parser_table
*entry
));
508 struct predicate
*insert_primary_withpred
PARAMS((const struct parser_table
*entry
, PRED_FUNC fptr
));
509 void usage
PARAMS((char *msg
));
511 extern char *program_name
;
512 extern struct predicate
*predicates
;
513 extern struct predicate
*last_pred
;
517 /* If true, process directory before contents. True unless -depth given. */
518 boolean do_dir_first
;
520 /* If >=0, don't descend more than this many levels of subdirectories. */
523 /* If >=0, don't process files above this level. */
526 /* If true, do not assume that files in directories with nlink == 2
527 are non-directories. */
528 boolean no_leaf_check
;
530 /* If true, don't cross filesystem boundaries. */
531 boolean stay_on_filesystem
;
533 /* If true, we ignore the problem where we find that a directory entry
534 * no longer exists by the time we get around to processing it.
536 boolean ignore_readdir_race
;
538 /* If true, we issue warning messages
541 time_t start_time
; /* Time at start of execution. */
543 /* Seconds between 00:00 1/1/70 and either one day before now
544 (the default), or the start of today (if -daystart is given). */
545 time_t cur_day_start
;
547 /* If true, cur_day_start has been adjusted to the start of the day. */
550 int output_block_size
; /* Output block size. */
552 enum SymlinkOption symlink_handling
;
555 /* Pointer to the function used to stat files. */
556 int (*xstat
) (const char *name
, struct stat
*statbuf
);
559 /* Indicate if we can implement safely_chdir() using the O_NOFOLLOW
562 boolean open_nofollow_available
;
565 /* Which regular expression syntex we currently use. This can be
566 * changed with the positional option -regextype, which takes the
569 * posix-basic, posix-extended, posix-grep, posix-egrep, posix-awk
576 extern struct options options
;
581 /* Current depth; 0 means current path is a command line arg. */
584 /* If true, we have called stat on the current path. */
587 /* If true, we know the type of the current path. */
589 mode_t type
; /* this is the actual type */
591 /* The file being operated on, relative to the current directory.
592 Used for stat, readlink, remove, and opendir. */
595 /* Length of current path. */
598 /* If true, don't descend past current directory.
599 Can be set by -prune, -maxdepth, and -xdev/-mount. */
600 boolean stop_at_current_level
;
602 /* Status value to return to system. */
605 extern struct state state
;
607 extern char const *starting_dir
;
608 extern int starting_desc
;
609 #if ! defined HAVE_FCHDIR && ! defined fchdir
610 # define fchdir(fd) (-1)