Applied (trivial) Martin Buchholz patch for typos/spelling errors, mostly in code...
[findutils.git] / find / defs.h
blobeb58ad570ab7d2fe97968e341b7278a192a83a68
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 #ifdef HAVE_UNISTD_H
49 #include <unistd.h>
50 #endif
52 #include <time.h>
54 #if HAVE_LIMITS_H
55 # include <limits.h>
56 #endif
57 #ifndef CHAR_BIT
58 # define CHAR_BIT 8
59 #endif
61 #if HAVE_INTTYPES_H
62 # include <inttypes.h>
63 #endif
65 #include "regex.h"
67 #ifndef S_IFLNK
68 #define lstat stat
69 #endif
71 # ifndef PARAMS
72 # if defined PROTOTYPES || (defined __STDC__ && __STDC__)
73 # define PARAMS(Args) Args
74 # else
75 # define PARAMS(Args) ()
76 # endif
77 # endif
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));
90 #ifndef S_ISUID
91 # define S_ISUID 0004000
92 #endif
93 #ifndef S_ISGID
94 # define S_ISGID 0002000
95 #endif
96 #ifndef S_ISVTX
97 # define S_ISVTX 0001000
98 #endif
99 #ifndef S_IRUSR
100 # define S_IRUSR 0000400
101 #endif
102 #ifndef S_IWUSR
103 # define S_IWUSR 0000200
104 #endif
105 #ifndef S_IXUSR
106 # define S_IXUSR 0000100
107 #endif
108 #ifndef S_IRGRP
109 # define S_IRGRP 0000040
110 #endif
111 #ifndef S_IWGRP
112 # define S_IWGRP 0000020
113 #endif
114 #ifndef S_IXGRP
115 # define S_IXGRP 0000010
116 #endif
117 #ifndef S_IROTH
118 # define S_IROTH 0000004
119 #endif
120 #ifndef S_IWOTH
121 # define S_IWOTH 0000002
122 #endif
123 #ifndef S_IXOTH
124 # define S_IXOTH 0000001
125 #endif
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)
133 #if 1
134 #include <stdbool.h>
135 typedef bool boolean;
136 #else
137 /* Not char because of type promotion; NeXT gcc can't handle it. */
138 typedef int boolean;
139 #define true 1
140 #define false 0
141 #endif
143 struct predicate;
145 /* Pointer to a predicate function. */
146 typedef boolean (*PRED_FUNC)(char *pathname, struct stat *stat_buf, struct predicate *pred_ptr);
148 /* The number of seconds in a day. */
149 #define DAYSECS 86400
151 /* Argument structures for predicates. */
153 enum comparison_type
155 COMP_GT,
156 COMP_LT,
157 COMP_EQ
160 enum permissions_type
162 PERM_AT_LEAST,
163 PERM_ANY,
164 PERM_EXACT
167 enum predicate_type
169 NO_TYPE,
170 PRIMARY_TYPE,
171 UNI_OP,
172 BI_OP,
173 OPEN_PAREN,
174 CLOSE_PAREN
177 enum predicate_precedence
179 NO_PREC,
180 COMMA_PREC,
181 OR_PREC,
182 AND_PREC,
183 NEGATE_PREC,
184 MAX_PREC
187 struct long_val
189 enum comparison_type kind;
190 boolean negative; /* Defined only when representing time_t. */
191 uintmax_t l_val;
194 struct perm_val
196 enum permissions_type kind;
197 mode_t val;
200 /* dir_id is used to support loop detection in find.c and
201 * also to support the -samefile test.
203 struct dir_id
205 ino_t ino;
206 dev_t dev;
209 struct size_val
211 enum comparison_type kind;
212 int blocksize;
213 uintmax_t size;
216 #define NEW_EXEC 1
218 #undef NEW_EXEC
221 #if !defined(NEW_EXEC)
222 struct path_arg
224 short offset; /* Offset in `vec' of this arg. */
225 short count; /* Number of path replacements in this arg. */
226 char *origarg; /* Arg with "{}" intact. */
228 #endif
230 #include "buildcmd.h"
232 struct exec_val
234 #if defined(NEW_EXEC)
235 /* new-style */
236 boolean multiple; /* -exec {} \+ denotes multiple argument. */
237 struct buildcmd_control ctl;
238 struct buildcmd_state state;
239 char **replace_vec; /* Command arguments (for ";" style) */
240 int num_args;
241 boolean use_current_dir; /* If nonzero, don't chdir to start dir */
242 #else
243 struct path_arg *paths; /* Array of args with path replacements. */
244 char **vec; /* Array of args to pass to program. */
245 #endif
248 /* The format string for a -printf or -fprintf is chopped into one or
249 more `struct segment', linked together into a list.
250 Each stretch of plain text is a segment, and
251 each \c and `%' conversion is a segment. */
253 /* Special values for the `kind' field of `struct segment'. */
254 #define KIND_PLAIN 0 /* Segment containing just plain text. */
255 #define KIND_STOP 1 /* \c -- stop printing and flush output. */
257 struct segment
259 int kind; /* Format chars or KIND_{PLAIN,STOP}. */
260 char *text; /* Plain text or `%' format string. */
261 int text_len; /* Length of `text'. */
262 struct segment *next; /* Next segment for this predicate. */
265 struct format_val
267 struct segment *segment; /* Linked list of segments. */
268 FILE *stream; /* Output stream to print on. */
269 boolean dest_is_tty; /* True if the destination is a terminal. */
270 struct quoting_options *quote_opts;
273 struct predicate
275 /* Pointer to the function that implements this predicate. */
276 PRED_FUNC pred_func;
278 /* Only used for debugging, but defined unconditionally so individual
279 modules can be compiled with -DDEBUG. */
280 char *p_name;
282 /* The type of this node. There are two kinds. The first is real
283 predicates ("primaries") such as -perm, -print, or -exec. The
284 other kind is operators for combining predicates. */
285 enum predicate_type p_type;
287 /* The precedence of this node. Only has meaning for operators. */
288 enum predicate_precedence p_prec;
290 /* True if this predicate node produces side effects.
291 If side_effects are produced
292 then optimization will not be performed */
293 boolean side_effects;
295 /* True if this predicate node requires default print be turned off. */
296 boolean no_default_print;
298 /* True if this predicate node requires a stat system call to execute. */
299 boolean need_stat;
301 /* True if this predicate node requires knowledge of the file type. */
302 boolean need_type;
304 /* Information needed by the predicate processor.
305 Next to each member are listed the predicates that use it. */
306 union
308 char *str; /* fstype [i]lname [i]name [i]path */
309 struct re_pattern_buffer *regex; /* regex */
310 struct exec_val exec_vec; /* exec ok */
311 struct long_val info; /* atime ctime gid inum links mtime
312 size uid */
313 struct size_val size; /* size */
314 uid_t uid; /* user */
315 gid_t gid; /* group */
316 time_t time; /* newer */
317 struct perm_val perm; /* perm */
318 struct dir_id fileid; /* samefile */
319 mode_t type; /* type */
320 FILE *stream; /* ls fls fprint0 */
321 struct format_val printf_vec; /* printf fprintf fprint */
322 } args;
324 /* The next predicate in the user input sequence,
325 which represents the order in which the user supplied the
326 predicates on the command line. */
327 struct predicate *pred_next;
329 /* The right and left branches from this node in the expression
330 tree, which represents the order in which the nodes should be
331 processed. */
332 struct predicate *pred_left;
333 struct predicate *pred_right;
336 /* find.c. */
337 int get_info PARAMS((const char *pathname, const char *name, struct stat *p, struct predicate *pred_ptr));
338 int following_links(void);
341 /* find library function declarations. */
343 /* dirname.c */
344 char *dirname PARAMS((char *path));
346 /* error.c */
347 void error PARAMS((int status, int errnum, char *message, ...));
349 /* listfile.c */
350 void list_file PARAMS((char *name, char *relname, struct stat *statp, time_t current_time, int output_block_size, FILE *stream));
351 char *get_link_name PARAMS((char *name, char *relname));
353 /* stpcpy.c */
354 #if !HAVE_STPCPY
355 char *stpcpy PARAMS((char *dest, const char *src));
356 #endif
358 /* xgetcwd.c */
359 char *xgetcwd PARAMS((void));
361 /* xmalloc.c */
362 #if __STDC__
363 #define VOID void
364 #else
365 #define VOID char
366 #endif
368 /* find global function declarations. */
370 /* find.c */
371 /* SymlinkOption represents the choice of
372 * -P, -L or -P (default) on the command line.
374 enum SymlinkOption
376 SYMLINK_NEVER_DEREF, /* Option -P */
377 SYMLINK_ALWAYS_DEREF, /* Option -L */
378 SYMLINK_DEREF_ARGSONLY /* Option -H */
380 extern enum SymlinkOption symlink_handling; /* defined in find.c. */
382 void set_follow_state PARAMS((enum SymlinkOption opt));
383 void cleanup(void);
385 /* fstype.c */
386 char *filesystem_type PARAMS((const struct stat *statp));
387 char * get_mounted_filesystems (void);
388 dev_t * get_mounted_devices PARAMS((size_t *));
390 /* Pointer to a parser function. */
391 typedef boolean (*PARSE_FUNC)(char *argv[], int *arg_ptr);
393 /* parser.c */
394 PARSE_FUNC find_parser PARAMS((char *search_name));
395 boolean parse_close PARAMS((char *argv[], int *arg_ptr));
396 boolean parse_open PARAMS((char *argv[], int *arg_ptr));
397 boolean parse_print PARAMS((char *argv[], int *arg_ptr));
399 /* pred.c */
400 boolean pred_amin PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
401 boolean pred_and PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
402 boolean pred_anewer PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
403 boolean pred_atime PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
404 boolean pred_close PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
405 boolean pred_cmin PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
406 boolean pred_cnewer PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
407 boolean pred_comma PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
408 boolean pred_ctime PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
409 boolean pred_delete PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
410 boolean pred_empty PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
411 boolean pred_exec PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
412 boolean pred_execdir PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
413 boolean pred_false PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
414 boolean pred_fls PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
415 boolean pred_fprint PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
416 boolean pred_fprint0 PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
417 boolean pred_fprintf PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
418 boolean pred_fstype PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
419 boolean pred_gid PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
420 boolean pred_group PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
421 boolean pred_ilname PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
422 boolean pred_iname PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
423 boolean pred_inum PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
424 boolean pred_ipath PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
425 boolean pred_links PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
426 boolean pred_lname PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
427 boolean pred_ls PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
428 boolean pred_mmin PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
429 boolean pred_mtime PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
430 boolean pred_name PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
431 boolean pred_negate PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
432 boolean pred_newer PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
433 boolean pred_nogroup PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
434 boolean pred_nouser PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
435 boolean pred_ok PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
436 boolean pred_okdir PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
437 boolean pred_open PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
438 boolean pred_or PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
439 boolean pred_path PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
440 boolean pred_perm PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
441 boolean pred_print PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
442 boolean pred_print0 PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
443 boolean pred_prune PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
444 boolean pred_quit PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
445 boolean pred_regex PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
446 boolean pred_samefile PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
447 boolean pred_size PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
448 boolean pred_true PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
449 boolean pred_type PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
450 boolean pred_uid PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
451 boolean pred_used PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
452 boolean pred_user PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
453 boolean pred_xtype PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
455 int launch PARAMS((const struct buildcmd_control *ctl,
456 struct buildcmd_state *buildstate));
459 char *find_pred_name PARAMS((PRED_FUNC pred_func));
463 #ifdef DEBUG
464 void print_tree PARAMS((FILE*, struct predicate *node, int indent));
465 void print_list PARAMS((FILE*, struct predicate *node));
466 void print_optlist PARAMS((FILE *fp, struct predicate *node));
467 #endif /* DEBUG */
469 /* tree.c */
470 struct predicate *
471 get_expr PARAMS((struct predicate **input, short int prev_prec));
472 boolean opt_expr PARAMS((struct predicate **eval_treep));
473 boolean mark_stat PARAMS((struct predicate *tree));
474 boolean mark_type PARAMS((struct predicate *tree));
476 /* util.c */
477 struct predicate *get_new_pred PARAMS((void));
478 struct predicate *get_new_pred_chk_op PARAMS((void));
479 struct predicate *insert_primary PARAMS((PRED_FUNC));
480 void usage PARAMS((char *msg));
482 extern char *program_name;
483 extern struct predicate *predicates;
484 extern struct predicate *last_pred;
486 struct options
488 /* If true, process directory before contents. True unless -depth given. */
489 boolean do_dir_first;
491 /* If >=0, don't descend more than this many levels of subdirectories. */
492 int maxdepth;
494 /* If >=0, don't process files above this level. */
495 int mindepth;
497 /* If true, do not assume that files in directories with nlink == 2
498 are non-directories. */
499 boolean no_leaf_check;
501 /* If true, don't cross filesystem boundaries. */
502 boolean stay_on_filesystem;
504 /* If true, we ignore the problem where we find that a directory entry
505 * no longer exists by the time we get around to processing it.
507 boolean ignore_readdir_race;
509 /* If true, we issue warning messages
511 boolean warnings;
512 time_t start_time; /* Time at start of execution. */
514 /* Seconds between 00:00 1/1/70 and either one day before now
515 (the default), or the start of today (if -daystart is given). */
516 time_t cur_day_start;
518 /* If true, cur_day_start has been adjusted to the start of the day. */
519 boolean full_days;
521 int output_block_size; /* Output block size. */
523 enum SymlinkOption symlink_handling;
526 /* Pointer to the function used to stat files. */
527 int (*xstat) (const char *name, struct stat *statbuf);
530 /* Indicate if we can implement safely_chdir() using the O_NOFOLLOW
531 * flag to open(2).
533 boolean open_nofollow_available;
535 extern struct options options;
538 struct state
540 /* Current depth; 0 means current path is a command line arg. */
541 int curdepth;
543 /* If true, we have called stat on the current path. */
544 boolean have_stat;
546 /* If true, we know the type of the current path. */
547 boolean have_type;
548 mode_t type; /* this is the actual type */
550 /* The file being operated on, relative to the current directory.
551 Used for stat, readlink, remove, and opendir. */
552 char *rel_pathname;
554 /* Length of current path. */
555 int path_length;
557 /* If true, don't descend past current directory.
558 Can be set by -prune, -maxdepth, and -xdev/-mount. */
559 boolean stop_at_current_level;
561 /* Status value to return to system. */
562 int exit_status;
564 extern struct state state;
566 extern char const *starting_dir;
567 extern int starting_desc;
568 #if ! defined HAVE_FCHDIR && ! defined fchdir
569 # define fchdir(fd) (-1)
570 #endif
572 #endif