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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
23 #include <sys/types.h>
27 #if defined(HAVE_STRING_H) || defined(STDC_HEADERS)
35 #define strrchr rindex
62 # include <inttypes.h>
72 # if defined PROTOTYPES || (defined __STDC__ && __STDC__)
73 # define PARAMS(Args) Args
75 # define PARAMS(Args) ()
79 int lstat
PARAMS((const char *__path
, struct stat
*__statbuf
));
80 int stat
PARAMS((const char *__path
, struct stat
*__statbuf
));
82 int optionl_stat
PARAMS((const char *name
, struct stat
*p
));
83 int optionp_stat
PARAMS((const char *name
, struct stat
*p
));
84 int optionh_stat
PARAMS((const char *name
, struct stat
*p
));
86 int get_statinfo
PARAMS((const char *pathname
, const char *name
, struct stat
*p
));
91 # define S_ISUID 0004000
94 # define S_ISGID 0002000
97 # define S_ISVTX 0001000
100 # define S_IRUSR 0000400
103 # define S_IWUSR 0000200
106 # define S_IXUSR 0000100
109 # define S_IRGRP 0000040
112 # define S_IWGRP 0000020
115 # define S_IXGRP 0000010
118 # define S_IROTH 0000004
121 # define S_IWOTH 0000002
124 # define S_IXOTH 0000001
127 #define MODE_WXUSR (S_IWUSR | S_IXUSR)
128 #define MODE_R (S_IRUSR | S_IRGRP | S_IROTH)
129 #define MODE_RW (S_IWUSR | S_IWGRP | S_IWOTH | MODE_R)
130 #define MODE_RWX (S_IXUSR | S_IXGRP | S_IXOTH | MODE_RW)
131 #define MODE_ALL (S_ISUID | S_ISGID | S_ISVTX | MODE_RWX)
135 typedef bool boolean
;
137 /* Not char because of type promotion; NeXT gcc can't handle it. */
143 /* Pointer to function returning boolean. */
144 typedef boolean (*PFB
)();
146 /* The number of seconds in a day. */
147 #define DAYSECS 86400
149 /* Argument structures for predicates. */
158 enum permissions_type
175 enum predicate_precedence
187 enum comparison_type kind
;
188 boolean negative
; /* Defined only when representing time_t. */
194 enum permissions_type kind
;
198 /* dir_id is used to support loop detection in find.c and
199 * also to support the -samefile test.
209 enum comparison_type kind
;
219 #if !defined(NEW_EXEC)
222 short offset
; /* Offset in `vec' of this arg. */
223 short count
; /* Number of path replacements in this arg. */
224 char *origarg
; /* Arg with "{}" intact. */
228 #include "buildcmd.h"
232 #if defined(NEW_EXEC)
234 boolean multiple
; /* -exec {} \+ denotes multiple argument. */
235 struct buildcmd_control ctl
;
236 struct buildcmd_state state
;
237 char **replace_vec
; /* Command arguments (for ";" style) */
239 boolean use_current_dir
; /* If nonzero, don't chdir to start dir */
241 struct path_arg
*paths
; /* Array of args with path replacements. */
242 char **vec
; /* Array of args to pass to program. */
246 /* The format string for a -printf or -fprintf is chopped into one or
247 more `struct segment', linked together into a list.
248 Each stretch of plain text is a segment, and
249 each \c and `%' conversion is a segment. */
251 /* Special values for the `kind' field of `struct segment'. */
252 #define KIND_PLAIN 0 /* Segment containing just plain text. */
253 #define KIND_STOP 1 /* \c -- stop printing and flush output. */
257 int kind
; /* Format chars or KIND_{PLAIN,STOP}. */
258 char *text
; /* Plain text or `%' format string. */
259 int text_len
; /* Length of `text'. */
260 struct segment
*next
; /* Next segment for this predicate. */
265 struct segment
*segment
; /* Linked list of segments. */
266 FILE *stream
; /* Output stream to print on. */
271 /* Pointer to the function that implements this predicate. */
274 /* Only used for debugging, but defined unconditionally so individual
275 modules can be compiled with -DDEBUG. */
278 /* The type of this node. There are two kinds. The first is real
279 predicates ("primaries") such as -perm, -print, or -exec. The
280 other kind is operators for combining predicates. */
281 enum predicate_type p_type
;
283 /* The precedence of this node. Only has meaning for operators. */
284 enum predicate_precedence p_prec
;
286 /* True if this predicate node produces side effects.
287 If side_effects are produced
288 then optimization will not be performed */
289 boolean side_effects
;
291 /* True if this predicate node requires default print be turned off. */
292 boolean no_default_print
;
294 /* True if this predicate node requires a stat system call to execute. */
297 /* True if this predicate node requires knowledge of the file type. */
300 /* Information needed by the predicate processor.
301 Next to each member are listed the predicates that use it. */
304 char *str
; /* fstype [i]lname [i]name [i]path */
305 struct re_pattern_buffer
*regex
; /* regex */
306 struct exec_val exec_vec
; /* exec ok */
307 struct long_val info
; /* atime ctime gid inum links mtime
309 struct size_val size
; /* size */
310 uid_t uid
; /* user */
311 gid_t gid
; /* group */
312 time_t time
; /* newer */
313 struct perm_val perm
; /* perm */
314 struct dir_id fileid
; /* samefile */
315 mode_t type
; /* type */
316 FILE *stream
; /* fprint fprint0 */
317 struct format_val printf_vec
; /* printf fprintf */
320 /* The next predicate in the user input sequence,
321 which repesents the order in which the user supplied the
322 predicates on the command line. */
323 struct predicate
*pred_next
;
325 /* The right and left branches from this node in the expression
326 tree, which represents the order in which the nodes should be
328 struct predicate
*pred_left
;
329 struct predicate
*pred_right
;
333 int get_info
PARAMS((const char *pathname
, const char *name
, struct stat
*p
, struct predicate
*pred_ptr
));
336 /* find library function declarations. */
339 char *dirname
PARAMS((char *path
));
342 void error
PARAMS((int status
, int errnum
, char *message
, ...));
345 void list_file
PARAMS((char *name
, char *relname
, struct stat
*statp
, time_t current_time
, int output_block_size
, FILE *stream
));
346 char *get_link_name
PARAMS((char *name
, char *relname
));
350 char *stpcpy
PARAMS((char *dest
, const char *src
));
354 char *xgetcwd
PARAMS((void));
363 /* find global function declarations. */
366 /* SymlinkOption represents the choice of
367 * -P, -L or -P (default) on the command line.
371 SYMLINK_NEVER_DEREF
, /* Option -P */
372 SYMLINK_ALWAYS_DEREF
, /* Option -L */
373 SYMLINK_DEREF_ARGSONLY
/* Option -H */
375 extern enum SymlinkOption symlink_handling
; /* defined in find.c. */
377 void set_follow_state
PARAMS((enum SymlinkOption opt
));
381 char *filesystem_type
PARAMS((const struct stat
*statp
));
382 char * get_mounted_filesystems (void);
383 dev_t
* get_mounted_devices
PARAMS((size_t *));
386 PFB find_parser
PARAMS((char *search_name
));
387 boolean parse_close
PARAMS((char *argv
[], int *arg_ptr
));
388 boolean parse_open
PARAMS((char *argv
[], int *arg_ptr
));
389 boolean parse_print
PARAMS((char *argv
[], int *arg_ptr
));
392 boolean pred_amin
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
393 boolean pred_and
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
394 boolean pred_anewer
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
395 boolean pred_atime
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
396 boolean pred_close
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
397 boolean pred_cmin
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
398 boolean pred_cnewer
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
399 boolean pred_comma
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
400 boolean pred_ctime
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
401 boolean pred_delete
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
402 boolean pred_empty
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
403 boolean pred_exec
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
404 boolean pred_execdir
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
405 boolean pred_false
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
406 boolean pred_fls
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
407 boolean pred_fprint
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
408 boolean pred_fprint0
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
409 boolean pred_fprintf
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
410 boolean pred_fstype
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
411 boolean pred_gid
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
412 boolean pred_group
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
413 boolean pred_ilname
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
414 boolean pred_iname
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
415 boolean pred_inum
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
416 boolean pred_ipath
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
417 boolean pred_links
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
418 boolean pred_lname
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
419 boolean pred_ls
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
420 boolean pred_mmin
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
421 boolean pred_mtime
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
422 boolean pred_name
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
423 boolean pred_negate
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
424 boolean pred_newer
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
425 boolean pred_nogroup
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
426 boolean pred_nouser
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
427 boolean pred_ok
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
428 boolean pred_okdir
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
429 boolean pred_open
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
430 boolean pred_or
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
431 boolean pred_path
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
432 boolean pred_perm
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
433 boolean pred_print
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
434 boolean pred_print0
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
435 boolean pred_prune
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
436 boolean pred_quit
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
437 boolean pred_regex
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
438 boolean pred_samefile
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
439 boolean pred_size
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
440 boolean pred_true
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
441 boolean pred_type
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
442 boolean pred_uid
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
443 boolean pred_used
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
444 boolean pred_user
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
445 boolean pred_xtype
PARAMS((char *pathname
, struct stat
*stat_buf
, struct predicate
*pred_ptr
));
447 int launch
PARAMS((const struct buildcmd_control
*ctl
,
448 struct buildcmd_state
*buildstate
));
451 char *find_pred_name
PARAMS((PFB pred_func
));
456 void print_tree
PARAMS((FILE*, struct predicate
*node
, int indent
));
457 void print_list
PARAMS((FILE*, struct predicate
*node
));
458 void print_optlist
PARAMS((FILE *fp
, struct predicate
*node
));
463 get_expr
PARAMS((struct predicate
**input
, short int prev_prec
));
464 boolean opt_expr
PARAMS((struct predicate
**eval_treep
));
465 boolean mark_stat
PARAMS((struct predicate
*tree
));
466 boolean mark_type
PARAMS((struct predicate
*tree
));
469 struct predicate
*get_new_pred
PARAMS((void));
470 struct predicate
*get_new_pred_chk_op
PARAMS((void));
471 struct predicate
*insert_primary
PARAMS((boolean (*pred_func
)()));
472 void usage
PARAMS((char *msg
));
474 extern char *program_name
;
475 extern struct predicate
*predicates
;
476 extern struct predicate
*last_pred
;
480 /* If true, process directory before contents. True unless -depth given. */
481 boolean do_dir_first
;
483 /* If >=0, don't descend more than this many levels of subdirectories. */
486 /* If >=0, don't process files above this level. */
489 /* If true, do not assume that files in directories with nlink == 2
490 are non-directories. */
491 boolean no_leaf_check
;
493 /* If true, don't cross filesystem boundaries. */
494 boolean stay_on_filesystem
;
496 /* If true, we ignore the problem where we find that a directory entry
497 * no longer exists by the time we get around to processing it.
499 boolean ignore_readdir_race
;
501 /* If true, we issue warning messages
504 time_t start_time
; /* Time at start of execution. */
506 /* Seconds between 00:00 1/1/70 and either one day before now
507 (the default), or the start of today (if -daystart is given). */
508 time_t cur_day_start
;
510 /* If true, cur_day_start has been adjusted to the start of the day. */
513 int output_block_size
; /* Output block size. */
515 enum SymlinkOption symlink_handling
;
518 /* Pointer to the function used to stat files. */
519 int (*xstat
) (const char *name
, struct stat
*statbuf
);
521 extern struct options options
;
526 /* Current depth; 0 means current path is a command line arg. */
529 /* If true, we have called stat on the current path. */
532 /* If true, we know the type of the current path. */
534 mode_t type
; /* this is the actual type */
536 /* The file being operated on, relative to the current directory.
537 Used for stat, readlink, remove, and opendir. */
540 /* Length of current path. */
543 /* If true, don't descend past current directory.
544 Can be set by -prune, -maxdepth, and -xdev/-mount. */
545 boolean stop_at_current_level
;
547 /* Status value to return to system. */
550 extern struct state state
;
552 extern char const *starting_dir
;
553 extern int starting_desc
;
554 #if ! defined HAVE_FCHDIR && ! defined fchdir
555 # define fchdir(fd) (-1)