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 */
243 boolean close_stdin
; /* If true, close stdin in the child. */
245 struct path_arg
*paths
; /* Array of args with path replacements. */
246 char **vec
; /* Array of args to pass to program. */
250 /* The format string for a -printf or -fprintf is chopped into one or
251 more `struct segment', linked together into a list.
252 Each stretch of plain text is a segment, and
253 each \c and `%' conversion is a segment. */
255 /* Special values for the `kind' field of `struct segment'. */
256 #define KIND_PLAIN 0 /* Segment containing just plain text. */
257 #define KIND_STOP 1 /* \c -- stop printing and flush output. */
261 int kind
; /* Format chars or KIND_{PLAIN,STOP}. */
262 char *text
; /* Plain text or `%' format string. */
263 int text_len
; /* Length of `text'. */
264 struct segment
*next
; /* Next segment for this predicate. */
269 struct segment
*segment
; /* Linked list of segments. */
270 FILE *stream
; /* Output stream to print on. */
271 boolean dest_is_tty
; /* True if the destination is a terminal. */
272 struct quoting_options
*quote_opts
;
277 /* Pointer to the function that implements this predicate. */
280 /* Only used for debugging, but defined unconditionally so individual
281 modules can be compiled with -DDEBUG. */
284 /* The type of this node. There are two kinds. The first is real
285 predicates ("primaries") such as -perm, -print, or -exec. The
286 other kind is operators for combining predicates. */
287 enum predicate_type p_type
;
289 /* The precedence of this node. Only has meaning for operators. */
290 enum predicate_precedence p_prec
;
292 /* True if this predicate node produces side effects.
293 If side_effects are produced
294 then optimization will not be performed */
295 boolean side_effects
;
297 /* True if this predicate node requires default print be turned off. */
298 boolean no_default_print
;
300 /* True if this predicate node requires a stat system call to execute. */
303 /* True if this predicate node requires knowledge of the file type. */
306 /* Information needed by the predicate processor.
307 Next to each member are listed the predicates that use it. */
310 char *str
; /* fstype [i]lname [i]name [i]path */
311 struct re_pattern_buffer
*regex
; /* regex */
312 struct exec_val exec_vec
; /* exec ok */
313 struct long_val info
; /* atime ctime gid inum links mtime
315 struct size_val size
; /* size */
316 uid_t uid
; /* user */
317 gid_t gid
; /* group */
318 time_t time
; /* newer */
319 struct perm_val perm
; /* perm */
320 struct dir_id fileid
; /* samefile */
321 mode_t type
; /* type */
322 FILE *stream
; /* ls fls fprint0 */
323 struct format_val printf_vec
; /* printf fprintf fprint */
326 /* The next predicate in the user input sequence,
327 which represents the order in which the user supplied the
328 predicates on the command line. */
329 struct predicate
*pred_next
;
331 /* The right and left branches from this node in the expression
332 tree, which represents the order in which the nodes should be
334 struct predicate
*pred_left
;
335 struct predicate
*pred_right
;
337 const struct parser_table
* parser_entry
;
341 int get_info
PARAMS((const char *pathname
, const char *name
, struct stat
*p
, struct predicate
*pred_ptr
));
342 int following_links(void);
345 /* find library function declarations. */
348 char *dirname
PARAMS((char *path
));
351 void error
PARAMS((int status
, int errnum
, char *message
, ...));
354 void list_file
PARAMS((char *name
, char *relname
, struct stat
*statp
, time_t current_time
, int output_block_size
, FILE *stream
));
355 char *get_link_name
PARAMS((char *name
, char *relname
));
359 char *stpcpy
PARAMS((char *dest
, const char *src
));
363 char *xgetcwd
PARAMS((void));
372 /* find global function declarations. */
375 /* SymlinkOption represents the choice of
376 * -P, -L or -P (default) on the command line.
380 SYMLINK_NEVER_DEREF
, /* Option -P */
381 SYMLINK_ALWAYS_DEREF
, /* Option -L */
382 SYMLINK_DEREF_ARGSONLY
/* Option -H */
384 extern enum SymlinkOption symlink_handling
; /* defined in find.c. */
386 void set_follow_state
PARAMS((enum SymlinkOption opt
));
390 char *filesystem_type
PARAMS((const struct stat
*statp
, const char *path
));
391 char * get_mounted_filesystems (void);
392 dev_t
* get_mounted_devices
PARAMS((size_t *));
398 ARG_OPTION
, /* regular options like -maxdepth */
399 ARG_POSITIONAL_OPTION
, /* options whose position is important (-follow) */
400 ARG_TEST
, /* a like -name */
401 ARG_PUNCTUATION
, /* like -o or ( */
402 ARG_ACTION
/* like -print */
407 /* Pointer to a parser function. */
408 typedef boolean (*PARSE_FUNC
)(const struct parser_table
*p
,
409 char *argv
[], int *arg_ptr
);
414 PARSE_FUNC parser_func
;
419 const struct parser_table
* find_parser
PARAMS((char *search_name
));
420 boolean parse_open
PARAMS((const struct parser_table
* entry
, char *argv
[], int *arg_ptr
));
421 boolean parse_close
PARAMS((const struct parser_table
* entry
, char *argv
[], int *arg_ptr
));
422 boolean parse_print
PARAMS((const struct parser_table
*, char *argv
[], int *arg_ptr
));
423 void pred_sanity_check
PARAMS((const struct predicate
*predicates
));
424 void parse_begin_user_args
PARAMS((char **args
, int argno
, const struct predicate
*last
, const struct predicate
*predicates
));
425 void parse_end_user_args
PARAMS((char **args
, int argno
, const struct predicate
*last
, const struct predicate
*predicates
));
428 boolean pred_amin
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
429 boolean pred_and
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
430 boolean pred_anewer
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
431 boolean pred_atime
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
432 boolean pred_closeparen
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
433 boolean pred_cmin
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
434 boolean pred_cnewer
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
435 boolean pred_comma
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
436 boolean pred_ctime
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
437 boolean pred_delete
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
438 boolean pred_empty
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
439 boolean pred_exec
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
440 boolean pred_execdir
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
441 boolean pred_false
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
442 boolean pred_fls
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
443 boolean pred_fprint
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
444 boolean pred_fprint0
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
445 boolean pred_fprintf
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
446 boolean pred_fstype
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
447 boolean pred_gid
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
448 boolean pred_group
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
449 boolean pred_ilname
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
450 boolean pred_iname
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
451 boolean pred_inum
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
452 boolean pred_ipath
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
453 boolean pred_links
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
454 boolean pred_lname
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
455 boolean pred_ls
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
456 boolean pred_mmin
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
457 boolean pred_mtime
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
458 boolean pred_name
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
459 boolean pred_negate
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
460 boolean pred_newer
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
461 boolean pred_nogroup
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
462 boolean pred_nouser
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
463 boolean pred_ok
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
464 boolean pred_okdir
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
465 boolean pred_openparen
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
466 boolean pred_or
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
467 boolean pred_path
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
468 boolean pred_perm
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
469 boolean pred_print
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
470 boolean pred_print0
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
471 boolean pred_prune
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
472 boolean pred_quit
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
473 boolean pred_regex
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
474 boolean pred_samefile
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
475 boolean pred_size
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
476 boolean pred_true
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
477 boolean pred_type
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
478 boolean pred_uid
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
479 boolean pred_used
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
480 boolean pred_user
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
481 boolean pred_xtype
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
485 int launch
PARAMS((const struct buildcmd_control
*ctl
,
486 struct buildcmd_state
*buildstate
));
489 char *find_pred_name
PARAMS((PRED_FUNC pred_func
));
494 void print_tree
PARAMS((FILE*, struct predicate
*node
, int indent
));
495 void print_list
PARAMS((FILE*, struct predicate
*node
));
496 void print_optlist
PARAMS((FILE *fp
, struct predicate
*node
));
501 get_expr
PARAMS((struct predicate
**input
, short int prev_prec
));
502 boolean opt_expr
PARAMS((struct predicate
**eval_treep
));
503 boolean mark_stat
PARAMS((struct predicate
*tree
));
504 boolean mark_type
PARAMS((struct predicate
*tree
));
507 struct predicate
*get_new_pred
PARAMS((const struct parser_table
*entry
));
508 struct predicate
*get_new_pred_chk_op
PARAMS((const struct parser_table
*entry
));
509 struct predicate
*insert_primary
PARAMS((const struct parser_table
*entry
));
510 struct predicate
*insert_primary_withpred
PARAMS((const struct parser_table
*entry
, PRED_FUNC fptr
));
511 void usage
PARAMS((char *msg
));
513 extern char *program_name
;
514 extern struct predicate
*predicates
;
515 extern struct predicate
*last_pred
;
519 /* If true, process directory before contents. True unless -depth given. */
520 boolean do_dir_first
;
522 /* If >=0, don't descend more than this many levels of subdirectories. */
525 /* If >=0, don't process files above this level. */
528 /* If true, do not assume that files in directories with nlink == 2
529 are non-directories. */
530 boolean no_leaf_check
;
532 /* If true, don't cross filesystem boundaries. */
533 boolean stay_on_filesystem
;
535 /* If true, we ignore the problem where we find that a directory entry
536 * no longer exists by the time we get around to processing it.
538 boolean ignore_readdir_race
;
540 /* If true, we issue warning messages
543 time_t start_time
; /* Time at start of execution. */
545 /* Seconds between 00:00 1/1/70 and either one day before now
546 (the default), or the start of today (if -daystart is given). */
547 time_t cur_day_start
;
549 /* If true, cur_day_start has been adjusted to the start of the day. */
552 int output_block_size
; /* Output block size. */
554 enum SymlinkOption symlink_handling
;
557 /* Pointer to the function used to stat files. */
558 int (*xstat
) (const char *name
, struct stat
*statbuf
);
561 /* Indicate if we can implement safely_chdir() using the O_NOFOLLOW
564 boolean open_nofollow_available
;
566 /* The variety of regular expression that we support.
567 * The default is POSIX Basic Regular Expressions, but this
568 * can be changed with the positional option, -regextype.
572 extern struct options options
;
577 /* Current depth; 0 means current path is a command line arg. */
580 /* If true, we have called stat on the current path. */
583 /* If true, we know the type of the current path. */
585 mode_t type
; /* this is the actual type */
587 /* The file being operated on, relative to the current directory.
588 Used for stat, readlink, remove, and opendir. */
591 /* Length of current path. */
594 /* If true, don't descend past current directory.
595 Can be set by -prune, -maxdepth, and -xdev/-mount. */
596 boolean stop_at_current_level
;
598 /* Status value to return to system. */
601 extern struct state state
;
603 extern char const *starting_dir
;
604 extern int starting_desc
;
605 #if ! defined HAVE_FCHDIR && ! defined fchdir
606 # define fchdir(fd) (-1)