1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
/* @(#)walk.h 1.15 06/09/15 Copyright 2004-2006 J. Schilling */
/*
* Definitions for directory tree walking
*
* Copyright (c) 2004-2006 J. Schilling
*/
/*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* See the file CDDL.Schily.txt in this distribution for details.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file CDDL.Schily.txt from this distribution.
*/
#ifndef _WALK_H
#define _WALK_H
/*
* Flags to control treewalk() via 'walkflags'.
*
* WALK_CHDIR is not implemented, treewalk() always does chdir()
*
* WALK_PHYS Clearing WALK_PHYS has highest precedence and equals
* 'find -follow'. If WALK_PHYS is clear, always use stat.
* By default, WALK_PHYS should be set.
*
* WALK_ARGFOLLOW If WALK_ARGFOLLOW is set, symlinks that are used as
* the first argument for trewalk() are followed even
* if WALK_PHYS is set. Setting WALK_ARGFOLLOW equals
* 'find -H'.
*
* WALK_ALLFOLLOW If WALK_ALLFOLLOW is set, all symlinks are followed
* even if WALK_PHYS is set. Setting WALK_ALLFOLLOW
* equals 'find -L'.
*/
#define WALK_PHYS 1 /* Use lstat() instead of stat() */
#define WALK_MOUNT 2 /* Do not cross mount points */
#define WALK_DEPTH 4 /* Call content before calling the dir */
#define WALK_CHDIR 8 /* Use chdir() to each directory */
#define WALK_ARGFOLLOW 0x10 /* Use stat() for top level args only */
#define WALK_ALLFOLLOW 0x20 /* Use stat() for all files */
#define WALK_NOSTAT 0x40 /* Avoid to call stat() if st_nlink =>2 */
#define WALK_NOEXIT 0x100 /* Do not exit() in case of hard errors */
#define WALK_NOMSG 0x200 /* Do not write messages to stderr */
#define WALK_LS_ATIME 0x1000 /* -ls lists atime instead of mtime */
#define WALK_LS_CTIME 0x2000 /* -ls lists ctime instead of mtime */
/*
* The 'type' argument to walkfun.
*/
#define WALK_F 1 /* File */
#define WALK_SL 2 /* Symbolic Link */
#define WALK_D 3 /* Directory */
#define WALK_DP 4 /* Directory previously visited */
#define WALK_DNR 5 /* Directory with no read permission */
#define WALK_NS 6 /* Unknown file type stat failed */
#define WALK_SLN 7 /* Symbolic Link that points to nonexistent file */
struct WALK {
int flags; /* Flags for communication with (*walkfun)() */
int base; /* Filename offset in path for (*walkfun)() */
int level; /* The nesting level set up for (*walkfun)() */
int walkflags; /* treewalk() control flags */
void *twprivate; /* treewalk() private do not touch */
int maxdepth; /* (*walkfun)() private, unused by treewalk */
int mindepth; /* (*walkfun)() private, unused by treewalk */
char *lname; /* (*walkfun)() private, unused by treewalk */
void *tree; /* (*walkfun)() private, unused by treewalk */
void *patstate; /* (*walkfun)() private, unused by treewalk */
int err; /* (*walkfun)() private, unused by treewalk */
int pflags; /* (*walkfun)() private, unused by treewalk */
int auxi; /* (*walkfun)() private, unused by treewalk */
void *auxp; /* (*walkfun)() private, unused by treewalk */
};
/*
* Flags in struct WALK used to communicate with (*walkfun)()
*/
#define WALK_WF_PRUNE 1 /* (*walkfun)() -> walk(): abort waking tree */
#define WALK_WF_NOCHDIR 2 /* walk() -> (*walkfun)(): WALK_DNR is cannot chdir() */
#define WALK_WF_NOCWD 4 /* walk() -> caller: cannot get working dir */
#define WALK_WF_NOHOME 8 /* walk() -> caller: cannot chdir("..") */
typedef int (*walkfun) __PR((char *_nm, struct stat *_fs, int _type, struct WALK *_state));
extern int treewalk __PR((char *_nm, walkfun _fn, struct WALK *_state));
extern int walkhome __PR((struct WALK *_state));
extern int walkclose __PR((struct WALK *_state));
#endif /* _WALK_H */
|