~ubuntu-branches/ubuntu/raring/findutils/raring

« back to all changes in this revision

Viewing changes to find/defs.h

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Metzler
  • Date: 2005-07-04 11:37:37 UTC
  • mto: (11.1.1 lenny) (1.1.10 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20050704113737-oxfumqxsqgfz5gay
Tags: upstream-4.2.22
ImportĀ upstreamĀ versionĀ 4.2.22

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* defs.h -- data types and declarations.
2
 
   Copyright (C) 1990, 91, 92, 93, 94, 2000 Free Software Foundation, Inc.
 
2
   Copyright (C) 1990, 91, 92, 93, 94, 2000, 2004 Free Software Foundation, Inc.
3
3
 
4
4
   This program is free software; you can redistribute it and/or modify
5
5
   it under the terms of the GNU General Public License as published by
13
13
 
14
14
   You should have received a copy of the GNU General Public License
15
15
   along with this program; if not, write to the Free Software
16
 
   Foundation, Inc., 9 Temple Place - Suite 330, Boston, MA 02111-1307,
 
16
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17
17
   USA.
18
18
*/
 
19
#ifndef INC_DEFS_H
 
20
#define INC_DEFS_H 1
19
21
 
20
 
#include <gnulib/config.h>
21
 
#undef VERSION
22
 
#undef PACKAGE_VERSION
23
 
#undef PACKAGE_TARNAME
24
 
#undef PACKAGE_STRING
25
 
#undef PACKAGE_NAME
26
 
#undef PACKAGE
27
22
#include <config.h>
28
23
#include <sys/types.h>
29
24
#include <sys/stat.h>
84
79
int lstat PARAMS((const char *__path, struct stat *__statbuf));
85
80
int stat PARAMS((const char *__path, struct stat *__statbuf));
86
81
 
 
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));
 
85
 
 
86
int get_statinfo PARAMS((const char *pathname, const char *name, struct stat *p));
 
87
 
 
88
 
 
89
 
87
90
#ifndef S_ISUID
88
91
# define S_ISUID 0004000
89
92
#endif
127
130
#define MODE_RWX        (S_IXUSR | S_IXGRP | S_IXOTH | MODE_RW)
128
131
#define MODE_ALL        (S_ISUID | S_ISGID | S_ISVTX | MODE_RWX)
129
132
 
 
133
#if 1
 
134
#include <stdbool.h>
 
135
typedef bool boolean;
 
136
#else
130
137
/* Not char because of type promotion; NeXT gcc can't handle it.  */
131
138
typedef int boolean;
132
139
#define         true    1
133
140
#define         false   0
134
 
 
135
 
/* Pointer to function returning boolean. */
136
 
typedef boolean (*PFB)();
 
141
#endif
 
142
 
 
143
struct predicate;
 
144
 
 
145
/* Pointer to a predicate function. */
 
146
typedef boolean (*PRED_FUNC)(char *pathname, struct stat *stat_buf, struct predicate *pred_ptr);
137
147
 
138
148
/* The number of seconds in a day. */
139
149
#define         DAYSECS     86400
187
197
  mode_t val;
188
198
};
189
199
 
 
200
/* dir_id is used to support loop detection in find.c and 
 
201
 * also to support the -samefile test.
 
202
 */
 
203
struct dir_id
 
204
{
 
205
  ino_t ino;
 
206
  dev_t dev;
 
207
};
 
208
 
190
209
struct size_val
191
210
{
192
211
  enum comparison_type kind;
194
213
  uintmax_t size;
195
214
};
196
215
 
 
216
#define NEW_EXEC 1
 
217
/*
 
218
#undef NEW_EXEC 
 
219
*/
 
220
 
 
221
#if !defined(NEW_EXEC)
197
222
struct path_arg
198
223
{
199
224
  short offset;                 /* Offset in `vec' of this arg. */
200
225
  short count;                  /* Number of path replacements in this arg. */
201
226
  char *origarg;                /* Arg with "{}" intact. */
202
227
};
 
228
#endif
 
229
 
 
230
#include "buildcmd.h"
203
231
 
204
232
struct exec_val
205
233
{
 
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
206
243
  struct path_arg *paths;       /* Array of args with path replacements. */
207
244
  char **vec;                   /* Array of args to pass to program. */
 
245
#endif
208
246
};
209
247
 
210
248
/* The format string for a -printf or -fprintf is chopped into one or
228
266
{
229
267
  struct segment *segment;      /* Linked list of segments. */
230
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;
231
271
};
232
272
 
233
273
struct predicate
234
274
{
235
275
  /* Pointer to the function that implements this predicate.  */
236
 
  PFB pred_func;
 
276
  PRED_FUNC pred_func;
237
277
 
238
278
  /* Only used for debugging, but defined unconditionally so individual
239
279
     modules can be compiled with -DDEBUG.  */
258
298
  /* True if this predicate node requires a stat system call to execute. */
259
299
  boolean need_stat;
260
300
 
 
301
  /* True if this predicate node requires knowledge of the file type. */
 
302
  boolean need_type;
 
303
 
261
304
  /* Information needed by the predicate processor.
262
305
     Next to each member are listed the predicates that use it. */
263
306
  union
272
315
    gid_t gid;                  /* group */
273
316
    time_t time;                /* newer */
274
317
    struct perm_val perm;       /* perm */
 
318
    struct dir_id   fileid;     /* samefile */
275
319
    mode_t type;                /* type */
276
 
    FILE *stream;               /* fprint fprint0 */
277
 
    struct format_val printf_vec; /* printf fprintf */
 
320
    FILE *stream;               /* ls fls fprint0 */
 
321
    struct format_val printf_vec; /* printf fprintf fprint  */
278
322
  } args;
279
323
 
280
324
  /* The next predicate in the user input sequence,
289
333
  struct predicate *pred_right;
290
334
};
291
335
 
 
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);
 
339
 
 
340
 
292
341
/* find library function declarations.  */
293
342
 
294
343
/* dirname.c */
316
365
#define VOID char
317
366
#endif
318
367
 
319
 
VOID *xmalloc PARAMS((size_t n));
320
 
VOID *xrealloc PARAMS((VOID *p, size_t n));
321
 
 
322
 
/* xstrdup.c */
323
 
char *xstrdup PARAMS((char *string));
324
 
 
325
368
/* find global function declarations.  */
326
369
 
 
370
/* find.c */
 
371
/* SymlinkOption represents the choice of 
 
372
 * -P, -L or -P (default) on the command line.
 
373
 */
 
374
enum SymlinkOption 
 
375
  {
 
376
    SYMLINK_NEVER_DEREF,        /* Option -P */
 
377
    SYMLINK_ALWAYS_DEREF,       /* Option -L */
 
378
    SYMLINK_DEREF_ARGSONLY      /* Option -H */
 
379
  };
 
380
extern enum SymlinkOption symlink_handling; /* defined in find.c. */
 
381
 
 
382
void set_follow_state PARAMS((enum SymlinkOption opt));
 
383
void cleanup(void);
 
384
 
327
385
/* fstype.c */
328
 
char *filesystem_type PARAMS((char *path, char *relpath, struct stat *statp));
 
386
char *filesystem_type PARAMS((const struct stat *statp));
 
387
char * get_mounted_filesystems (void);
 
388
dev_t * get_mounted_devices PARAMS((size_t *));
 
389
 
 
390
/* Pointer to a parser function. */
 
391
typedef boolean (*PARSE_FUNC)(char *argv[], int *arg_ptr);
329
392
 
330
393
/* parser.c */
331
 
PFB find_parser PARAMS((char *search_name));
 
394
PARSE_FUNC find_parser PARAMS((char *search_name));
332
395
boolean parse_close PARAMS((char *argv[], int *arg_ptr));
333
396
boolean parse_open PARAMS((char *argv[], int *arg_ptr));
334
397
boolean parse_print PARAMS((char *argv[], int *arg_ptr));
343
406
boolean pred_cnewer PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
344
407
boolean pred_comma PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
345
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));
346
410
boolean pred_empty PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
347
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));
348
413
boolean pred_false PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
349
414
boolean pred_fls PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
350
415
boolean pred_fprint PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
368
433
boolean pred_nogroup PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
369
434
boolean pred_nouser PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
370
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));
371
437
boolean pred_open PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
372
438
boolean pred_or PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
373
439
boolean pred_path PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
375
441
boolean pred_print PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
376
442
boolean pred_print0 PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
377
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));
378
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));
379
447
boolean pred_size PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
380
448
boolean pred_true PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
381
449
boolean pred_type PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
383
451
boolean pred_used PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
384
452
boolean pred_user PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
385
453
boolean pred_xtype PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
386
 
char *find_pred_name PARAMS((PFB pred_func));
 
454
 
 
455
int launch PARAMS((const struct buildcmd_control *ctl,
 
456
                   struct buildcmd_state *buildstate));
 
457
 
 
458
 
 
459
char *find_pred_name PARAMS((PRED_FUNC pred_func));
 
460
 
 
461
 
 
462
 
387
463
#ifdef DEBUG
388
 
void print_tree PARAMS((struct predicate *node, int indent));
389
 
void print_list PARAMS((struct predicate *node));
 
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));
390
467
#endif /* DEBUG */
391
468
 
392
469
/* tree.c */
394
471
get_expr PARAMS((struct predicate **input, short int prev_prec));
395
472
boolean opt_expr PARAMS((struct predicate **eval_treep));
396
473
boolean mark_stat PARAMS((struct predicate *tree));
 
474
boolean mark_type PARAMS((struct predicate *tree));
397
475
 
398
476
/* util.c */
399
477
struct predicate *get_new_pred PARAMS((void));
400
478
struct predicate *get_new_pred_chk_op PARAMS((void));
401
 
struct predicate *insert_primary PARAMS((boolean (*pred_func )()));
 
479
struct predicate *insert_primary PARAMS((PRED_FUNC));
402
480
void usage PARAMS((char *msg));
403
481
 
404
482
extern char *program_name;
405
483
extern struct predicate *predicates;
406
484
extern struct predicate *last_pred;
407
 
extern boolean do_dir_first;
408
 
extern int maxdepth;
409
 
extern int mindepth;
410
 
extern int curdepth;
411
 
extern int output_block_size;
412
 
extern time_t start_time;
413
 
extern time_t cur_day_start;
414
 
extern boolean full_days;
415
 
extern boolean no_leaf_check;
416
 
extern boolean stay_on_filesystem;
417
 
extern boolean stop_at_current_level;
418
 
extern boolean have_stat;
419
 
extern char *rel_pathname;
 
485
 
 
486
struct options
 
487
{
 
488
  /* If true, process directory before contents.  True unless -depth given. */
 
489
  boolean do_dir_first;
 
490
  
 
491
  /* If >=0, don't descend more than this many levels of subdirectories. */
 
492
  int maxdepth;
 
493
  
 
494
  /* If >=0, don't process files above this level. */
 
495
  int mindepth;
 
496
  
 
497
  /* If true, do not assume that files in directories with nlink == 2
 
498
     are non-directories. */
 
499
  boolean no_leaf_check;
 
500
  
 
501
  /* If true, don't cross filesystem boundaries. */
 
502
  boolean stay_on_filesystem;
 
503
  
 
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.
 
506
   */
 
507
  boolean ignore_readdir_race;
 
508
  
 
509
/* If true, we issue warning messages
 
510
 */
 
511
  boolean warnings;
 
512
  time_t start_time;            /* Time at start of execution.  */
 
513
  
 
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;
 
517
  
 
518
  /* If true, cur_day_start has been adjusted to the start of the day. */
 
519
  boolean full_days;
 
520
  
 
521
  int output_block_size;        /* Output block size.  */
 
522
  
 
523
  enum SymlinkOption symlink_handling;
 
524
  
 
525
  
 
526
  /* Pointer to the function used to stat files. */
 
527
  int (*xstat) (const char *name, struct stat *statbuf);
 
528
 
 
529
 
 
530
  /* Indicate if we can implement safely_chdir() using the O_NOFOLLOW 
 
531
   * flag to open(2). 
 
532
   */
 
533
  boolean open_nofollow_available;
 
534
};
 
535
extern struct options options;
 
536
 
 
537
 
 
538
struct state
 
539
{
 
540
  /* Current depth; 0 means current path is a command line arg. */
 
541
  int curdepth;
 
542
  
 
543
  /* If true, we have called stat on the current path. */
 
544
  boolean have_stat;
 
545
  
 
546
  /* If true, we know the type of the current path. */
 
547
  boolean have_type;
 
548
  mode_t type;                  /* this is the actual type */
 
549
  
 
550
  /* The file being operated on, relative to the current directory.
 
551
     Used for stat, readlink, remove, and opendir.  */
 
552
  char *rel_pathname;
 
553
 
 
554
  /* Length of current path. */
 
555
  int path_length;
 
556
 
 
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;
 
560
  
 
561
  /* Status value to return to system. */
 
562
  int exit_status;
 
563
};
 
564
extern struct state state;
 
565
 
420
566
extern char const *starting_dir;
421
567
extern int starting_desc;
422
568
#if ! defined HAVE_FCHDIR && ! defined fchdir
423
569
# define fchdir(fd) (-1)
424
570
#endif
425
 
extern int exit_status;
426
 
extern int path_length;
427
 
extern int (*xstat) ();
428
 
extern boolean dereference;
 
571
 
 
572
#endif