* changed libc dependencies to remove libc6-dev build-depends (closes:
[findutils.git] / find / defs.h
blob026813823db883b2897ce2c678adb8580b099a34
1 /* defs.h -- data types and declarations.
2 Copyright (C) 1990, 91, 92, 93, 94, 2000 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
18 #include <config.h>
19 #include <sys/types.h>
20 #include <sys/stat.h>
21 #include <stdio.h>
23 #if defined(HAVE_STRING_H) || defined(STDC_HEADERS)
24 #include <string.h>
25 #else
26 #include <strings.h>
27 #ifndef strchr
28 #define strchr index
29 #endif
30 #ifndef strrchr
31 #define strrchr rindex
32 #endif
33 #endif
35 #include <errno.h>
36 #ifndef errno
37 extern int errno;
38 #endif
40 #ifdef STDC_HEADERS
41 #include <stdlib.h>
42 #endif
44 #ifdef HAVE_UNISTD_H
45 #include <unistd.h>
46 #endif
48 #include <time.h>
50 #if HAVE_LIMITS_H
51 # include <limits.h>
52 #endif
53 #ifndef CHAR_BIT
54 # define CHAR_BIT 8
55 #endif
57 #if HAVE_INTTYPES_H
58 # include <inttypes.h>
59 #endif
61 #include "regex.h"
63 #ifndef S_IFLNK
64 #define lstat stat
65 #endif
67 # ifndef PARAMS
68 # if defined PROTOTYPES || (defined __STDC__ && __STDC__)
69 # define PARAMS(Args) Args
70 # else
71 # define PARAMS(Args) ()
72 # endif
73 # endif
75 int lstat PARAMS((const char *__path, struct stat *__statbuf));
76 int stat PARAMS((const char *__path, struct stat *__statbuf));
78 #ifndef S_ISUID
79 # define S_ISUID 0004000
80 #endif
81 #ifndef S_ISGID
82 # define S_ISGID 0002000
83 #endif
84 #ifndef S_ISVTX
85 # define S_ISVTX 0001000
86 #endif
87 #ifndef S_IRUSR
88 # define S_IRUSR 0000400
89 #endif
90 #ifndef S_IWUSR
91 # define S_IWUSR 0000200
92 #endif
93 #ifndef S_IXUSR
94 # define S_IXUSR 0000100
95 #endif
96 #ifndef S_IRGRP
97 # define S_IRGRP 0000040
98 #endif
99 #ifndef S_IWGRP
100 # define S_IWGRP 0000020
101 #endif
102 #ifndef S_IXGRP
103 # define S_IXGRP 0000010
104 #endif
105 #ifndef S_IROTH
106 # define S_IROTH 0000004
107 #endif
108 #ifndef S_IWOTH
109 # define S_IWOTH 0000002
110 #endif
111 #ifndef S_IXOTH
112 # define S_IXOTH 0000001
113 #endif
115 #define MODE_WXUSR (S_IWUSR | S_IXUSR)
116 #define MODE_R (S_IRUSR | S_IRGRP | S_IROTH)
117 #define MODE_RW (S_IWUSR | S_IWGRP | S_IWOTH | MODE_R)
118 #define MODE_RWX (S_IXUSR | S_IXGRP | S_IXOTH | MODE_RW)
119 #define MODE_ALL (S_ISUID | S_ISGID | S_ISVTX | MODE_RWX)
121 /* Not char because of type promotion; NeXT gcc can't handle it. */
122 typedef int boolean;
123 #define true 1
124 #define false 0
126 /* Pointer to function returning boolean. */
127 typedef boolean (*PFB)();
129 /* The number of seconds in a day. */
130 #define DAYSECS 86400
132 /* Argument structures for predicates. */
134 enum comparison_type
136 COMP_GT,
137 COMP_LT,
138 COMP_EQ
141 enum permissions_type
143 PERM_AT_LEAST,
144 PERM_ANY,
145 PERM_EXACT
148 enum predicate_type
150 NO_TYPE,
151 PRIMARY_TYPE,
152 UNI_OP,
153 BI_OP,
154 OPEN_PAREN,
155 CLOSE_PAREN
158 enum predicate_precedence
160 NO_PREC,
161 COMMA_PREC,
162 OR_PREC,
163 AND_PREC,
164 NEGATE_PREC,
165 MAX_PREC
168 struct long_val
170 enum comparison_type kind;
171 boolean negative; /* Defined only when representing time_t. */
172 uintmax_t l_val;
175 struct perm_val
177 enum permissions_type kind;
178 mode_t val;
181 struct size_val
183 enum comparison_type kind;
184 int blocksize;
185 uintmax_t size;
188 struct path_arg
190 short offset; /* Offset in `vec' of this arg. */
191 short count; /* Number of path replacements in this arg. */
192 char *origarg; /* Arg with "{}" intact. */
195 struct exec_val
197 struct path_arg *paths; /* Array of args with path replacements. */
198 char **vec; /* Array of args to pass to program. */
201 /* The format string for a -printf or -fprintf is chopped into one or
202 more `struct segment', linked together into a list.
203 Each stretch of plain text is a segment, and
204 each \c and `%' conversion is a segment. */
206 /* Special values for the `kind' field of `struct segment'. */
207 #define KIND_PLAIN 0 /* Segment containing just plain text. */
208 #define KIND_STOP 1 /* \c -- stop printing and flush output. */
210 struct segment
212 int kind; /* Format chars or KIND_{PLAIN,STOP}. */
213 char *text; /* Plain text or `%' format string. */
214 int text_len; /* Length of `text'. */
215 struct segment *next; /* Next segment for this predicate. */
218 struct format_val
220 struct segment *segment; /* Linked list of segments. */
221 FILE *stream; /* Output stream to print on. */
224 struct predicate
226 /* Pointer to the function that implements this predicate. */
227 PFB pred_func;
229 /* Only used for debugging, but defined unconditionally so individual
230 modules can be compiled with -DDEBUG. */
231 char *p_name;
233 /* The type of this node. There are two kinds. The first is real
234 predicates ("primaries") such as -perm, -print, or -exec. The
235 other kind is operators for combining predicates. */
236 enum predicate_type p_type;
238 /* The precedence of this node. Only has meaning for operators. */
239 enum predicate_precedence p_prec;
241 /* True if this predicate node produces side effects.
242 If side_effects are produced
243 then optimization will not be performed */
244 boolean side_effects;
246 /* True if this predicate node requires default print be turned off. */
247 boolean no_default_print;
249 /* True if this predicate node requires a stat system call to execute. */
250 boolean need_stat;
252 /* Information needed by the predicate processor.
253 Next to each member are listed the predicates that use it. */
254 union
256 char *str; /* fstype [i]lname [i]name [i]path */
257 struct re_pattern_buffer *regex; /* regex */
258 struct exec_val exec_vec; /* exec ok */
259 struct long_val info; /* atime ctime gid inum links mtime
260 size uid */
261 struct size_val size; /* size */
262 uid_t uid; /* user */
263 gid_t gid; /* group */
264 time_t time; /* newer */
265 struct perm_val perm; /* perm */
266 mode_t type; /* type */
267 FILE *stream; /* fprint fprint0 */
268 struct format_val printf_vec; /* printf fprintf */
269 } args;
271 /* The next predicate in the user input sequence,
272 which repesents the order in which the user supplied the
273 predicates on the command line. */
274 struct predicate *pred_next;
276 /* The right and left branches from this node in the expression
277 tree, which represents the order in which the nodes should be
278 processed. */
279 struct predicate *pred_left;
280 struct predicate *pred_right;
283 /* find library function declarations. */
285 /* dirname.c */
286 char *dirname PARAMS((char *path));
288 /* error.c */
289 void error PARAMS((int status, int errnum, char *message, ...));
291 /* listfile.c */
292 void list_file PARAMS((char *name, char *relname, struct stat *statp, time_t current_time, int output_block_size, FILE *stream));
293 char *get_link_name PARAMS((char *name, char *relname));
295 /* stpcpy.c */
296 #if !HAVE_STPCPY
297 char *stpcpy PARAMS((char *dest, const char *src));
298 #endif
300 /* xgetcwd.c */
301 char *xgetcwd PARAMS((void));
303 /* xmalloc.c */
304 #if __STDC__
305 #define VOID void
306 #else
307 #define VOID char
308 #endif
310 VOID *xmalloc PARAMS((size_t n));
311 VOID *xrealloc PARAMS((VOID *p, size_t n));
313 /* xstrdup.c */
314 char *xstrdup PARAMS((char *string));
316 /* find global function declarations. */
318 /* fstype.c */
319 char *filesystem_type PARAMS((char *path, char *relpath, struct stat *statp));
321 /* parser.c */
322 PFB find_parser PARAMS((char *search_name));
323 boolean parse_close PARAMS((char *argv[], int *arg_ptr));
324 boolean parse_open PARAMS((char *argv[], int *arg_ptr));
325 boolean parse_print PARAMS((char *argv[], int *arg_ptr));
327 /* pred.c */
328 boolean pred_amin PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
329 boolean pred_and PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
330 boolean pred_anewer PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
331 boolean pred_atime PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
332 boolean pred_close PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
333 boolean pred_cmin PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
334 boolean pred_cnewer PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
335 boolean pred_comma PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
336 boolean pred_ctime PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
337 boolean pred_empty PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
338 boolean pred_exec PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
339 boolean pred_false PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
340 boolean pred_fls PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
341 boolean pred_fprint PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
342 boolean pred_fprint0 PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
343 boolean pred_fprintf PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
344 boolean pred_fstype PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
345 boolean pred_gid PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
346 boolean pred_group PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
347 boolean pred_ilname PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
348 boolean pred_iname PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
349 boolean pred_inum PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
350 boolean pred_ipath PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
351 boolean pred_links PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
352 boolean pred_lname PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
353 boolean pred_ls PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
354 boolean pred_mmin PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
355 boolean pred_mtime PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
356 boolean pred_name PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
357 boolean pred_negate PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
358 boolean pred_newer PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
359 boolean pred_nogroup PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
360 boolean pred_nouser PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
361 boolean pred_ok PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
362 boolean pred_open PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
363 boolean pred_or PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
364 boolean pred_path PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
365 boolean pred_perm PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
366 boolean pred_print PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
367 boolean pred_print0 PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
368 boolean pred_prune PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
369 boolean pred_regex PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
370 boolean pred_size PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
371 boolean pred_true PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
372 boolean pred_type PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
373 boolean pred_uid PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
374 boolean pred_used PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
375 boolean pred_user PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
376 boolean pred_xtype PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
377 char *find_pred_name PARAMS((PFB pred_func));
378 #ifdef DEBUG
379 void print_tree PARAMS((struct predicate *node, int indent));
380 void print_list PARAMS((struct predicate *node));
381 #endif /* DEBUG */
383 /* tree.c */
384 struct predicate *
385 get_expr PARAMS((struct predicate **input, short int prev_prec));
386 boolean opt_expr PARAMS((struct predicate **eval_treep));
387 boolean mark_stat PARAMS((struct predicate *tree));
389 /* util.c */
390 struct predicate *get_new_pred PARAMS((void));
391 struct predicate *get_new_pred_chk_op PARAMS((void));
392 struct predicate *insert_primary PARAMS((boolean (*pred_func )()));
393 void usage PARAMS((char *msg));
395 extern char *program_name;
396 extern struct predicate *predicates;
397 extern struct predicate *last_pred;
398 extern boolean do_dir_first;
399 extern int maxdepth;
400 extern int mindepth;
401 extern int curdepth;
402 extern int output_block_size;
403 extern time_t start_time;
404 extern time_t cur_day_start;
405 extern boolean full_days;
406 extern boolean no_leaf_check;
407 extern boolean stay_on_filesystem;
408 extern boolean stop_at_current_level;
409 extern boolean have_stat;
410 extern char *rel_pathname;
411 extern char const *starting_dir;
412 extern int starting_desc;
413 #if ! defined HAVE_FCHDIR && ! defined fchdir
414 # define fchdir(fd) (-1)
415 #endif
416 extern int exit_status;
417 extern int path_length;
418 extern int (*xstat) ();
419 extern boolean dereference;