Work around compilation failure with GCC 4 and AIX 5.1, in which open is #defined...
[findutils.git] / find / defs.h
blobc5bfaf7ac31f0d6f097f28682ffd95471372a793
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));
87 int get_statinfo PARAMS((const char *pathname, const char *name, struct stat *p));
91 #ifndef S_ISUID
92 # define S_ISUID 0004000
93 #endif
94 #ifndef S_ISGID
95 # define S_ISGID 0002000
96 #endif
97 #ifndef S_ISVTX
98 # define S_ISVTX 0001000
99 #endif
100 #ifndef S_IRUSR
101 # define S_IRUSR 0000400
102 #endif
103 #ifndef S_IWUSR
104 # define S_IWUSR 0000200
105 #endif
106 #ifndef S_IXUSR
107 # define S_IXUSR 0000100
108 #endif
109 #ifndef S_IRGRP
110 # define S_IRGRP 0000040
111 #endif
112 #ifndef S_IWGRP
113 # define S_IWGRP 0000020
114 #endif
115 #ifndef S_IXGRP
116 # define S_IXGRP 0000010
117 #endif
118 #ifndef S_IROTH
119 # define S_IROTH 0000004
120 #endif
121 #ifndef S_IWOTH
122 # define S_IWOTH 0000002
123 #endif
124 #ifndef S_IXOTH
125 # define S_IXOTH 0000001
126 #endif
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)
134 #if 1
135 #include <stdbool.h>
136 typedef bool boolean;
137 #else
138 /* Not char because of type promotion; NeXT gcc can't handle it. */
139 typedef int boolean;
140 #define true 1
141 #define false 0
142 #endif
144 struct predicate;
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. */
154 enum comparison_type
156 COMP_GT,
157 COMP_LT,
158 COMP_EQ
161 enum permissions_type
163 PERM_AT_LEAST,
164 PERM_ANY,
165 PERM_EXACT
168 enum predicate_type
170 NO_TYPE,
171 PRIMARY_TYPE,
172 UNI_OP,
173 BI_OP,
174 OPEN_PAREN,
175 CLOSE_PAREN
178 enum predicate_precedence
180 NO_PREC,
181 COMMA_PREC,
182 OR_PREC,
183 AND_PREC,
184 NEGATE_PREC,
185 MAX_PREC
188 struct long_val
190 enum comparison_type kind;
191 boolean negative; /* Defined only when representing time_t. */
192 uintmax_t l_val;
195 struct perm_val
197 enum permissions_type kind;
198 mode_t val;
201 /* dir_id is used to support loop detection in find.c and
202 * also to support the -samefile test.
204 struct dir_id
206 ino_t ino;
207 dev_t dev;
210 struct size_val
212 enum comparison_type kind;
213 int blocksize;
214 uintmax_t size;
217 #define NEW_EXEC 1
219 #undef NEW_EXEC
222 #if !defined(NEW_EXEC)
223 struct path_arg
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. */
229 #endif
231 #include "buildcmd.h"
233 struct exec_val
235 #if defined(NEW_EXEC)
236 /* new-style */
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) */
241 int num_args;
242 boolean use_current_dir; /* If nonzero, don't chdir to start dir */
243 boolean close_stdin; /* If true, close stdin in the child. */
244 #else
245 struct path_arg *paths; /* Array of args with path replacements. */
246 char **vec; /* Array of args to pass to program. */
247 #endif
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. */
259 struct segment
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. */
267 struct format_val
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;
275 struct predicate
277 /* Pointer to the function that implements this predicate. */
278 PRED_FUNC pred_func;
280 /* Only used for debugging, but defined unconditionally so individual
281 modules can be compiled with -DDEBUG. */
282 char *p_name;
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. */
301 boolean need_stat;
303 /* True if this predicate node requires knowledge of the file type. */
304 boolean need_type;
306 /* Information needed by the predicate processor.
307 Next to each member are listed the predicates that use it. */
308 union
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
314 size uid */
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 */
324 } args;
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
333 processed. */
334 struct predicate *pred_left;
335 struct predicate *pred_right;
337 const struct parser_table* parser_entry;
340 /* find.c. */
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. */
347 /* dirname.c */
348 char *dirname PARAMS((char *path));
350 /* error.c */
351 void error PARAMS((int status, int errnum, char *message, ...));
353 /* listfile.c */
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));
357 /* stpcpy.c */
358 #if !HAVE_STPCPY
359 char *stpcpy PARAMS((char *dest, const char *src));
360 #endif
362 /* xgetcwd.c */
363 char *xgetcwd PARAMS((void));
365 /* xmalloc.c */
366 #if __STDC__
367 #define VOID void
368 #else
369 #define VOID char
370 #endif
372 /* find global function declarations. */
374 /* find.c */
375 /* SymlinkOption represents the choice of
376 * -P, -L or -P (default) on the command line.
378 enum SymlinkOption
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));
387 void cleanup(void);
389 /* fstype.c */
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 *));
396 enum arg_type
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 */
406 struct parser_table;
407 /* Pointer to a parser function. */
408 typedef boolean (*PARSE_FUNC)(const struct parser_table *p,
409 char *argv[], int *arg_ptr);
410 struct parser_table
412 enum arg_type type;
413 char *parser_name;
414 PARSE_FUNC parser_func;
415 PRED_FUNC pred_func;
418 /* parser.c */
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));
427 /* pred.c */
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));
493 #ifdef DEBUG
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));
497 #endif /* DEBUG */
499 /* tree.c */
500 struct predicate *
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));
506 /* util.c */
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;
517 struct options
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. */
523 int maxdepth;
525 /* If >=0, don't process files above this level. */
526 int mindepth;
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
542 boolean warnings;
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. */
550 boolean full_days;
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
562 * flag to open(2).
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.
570 int regex_options;
572 extern struct options options;
575 struct state
577 /* Current depth; 0 means current path is a command line arg. */
578 int curdepth;
580 /* If true, we have called stat on the current path. */
581 boolean have_stat;
583 /* If true, we know the type of the current path. */
584 boolean have_type;
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. */
589 char *rel_pathname;
591 /* Length of current path. */
592 int path_length;
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. */
599 int exit_status;
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)
607 #endif
609 #endif