xref: /titanic_51/usr/src/lib/libast/common/include/fts.h (revision 24fe0b3bf671e123467ce1df0b67cadd3614c8e4)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2008 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                  David Korn <dgk@research.att.com>                   *
19 *                   Phong Vo <kpv@research.att.com>                    *
20 *                                                                      *
21 ***********************************************************************/
22 #pragma prototyped
23 /*
24  * Glenn Fowler
25  * David Korn
26  * Phong Vo
27  * AT&T Research
28  *
29  * fts interface definitions
30  */
31 
32 #ifndef	_FTS_H
33 #define _FTS_H
34 
35 #include <ls.h>
36 
37 /*
38  * fts_open flags
39  */
40 
41 #define FTS_LOGICAL	0	/* logical traversal, follow symlinks	*/
42 #define FTS_META	(1<<0)	/* follow top dir symlinks even if phys	*/
43 #define FTS_NOCHDIR	(1<<1)	/* don't chdir				*/
44 #define FTS_NOPOSTORDER	(1<<2)	/* no postorder visits			*/
45 #define FTS_NOPREORDER	(1<<3)	/* no preorder visits			*/
46 #define FTS_NOSEEDOTDIR	(1<<11)	/* never retain leading . dir		*/
47 #define FTS_NOSTAT	(1<<4)	/* don't stat children			*/
48 #define FTS_ONEPATH	(1<<5)	/* pathnames arg is one const char*	*/
49 #define FTS_PHYSICAL	(1<<6)	/* physical traversal, don't follow	*/
50 #define FTS_SEEDOT	(1<<7)	/* return . and ..			*/
51 #define FTS_SEEDOTDIR	(1<<10)	/* always retain leading . dir		*/
52 #define FTS_TOP		(1<<8)	/* don't traverse subdirectories	*/
53 #define FTS_XDEV	(1<<9)	/* don't cross mount points		*/
54 
55 #define FTS_USER	(1<<12)	/* first user flag bit			*/
56 
57 #define FTS_COMFOLLOW	FTS_META
58 
59 /*
60  * fts_info flags
61  */
62 
63 #define FTS_DEFAULT	0	/* ok, someone must have wanted this	*/
64 
65 #define FTS_NS		(1<<0)	/* stat failed				*/
66 #define FTS_F		(1<<1)	/* file - not directory or symbolic link*/
67 #define FTS_SL		(1<<2)	/* symbolic link			*/
68 #define FTS_D		(1<<3)	/* directory - pre-order visit		*/
69 
70 #define FTS_C		(1<<4)	/* causes cycle				*/
71 #define FTS_ERR		(1<<5)	/* some other error			*/
72 #define FTS_DD		(1<<6)	/* . or ..				*/
73 #define FTS_NR		(1<<7)	/* cannot read				*/
74 #define FTS_NX		(1<<8)	/* cannot search			*/
75 #define FTS_OK		(1<<9)	/* no info but otherwise ok		*/
76 #define FTS_P		(1<<10)	/* post-order visit			*/
77 
78 #define FTS_DC		(FTS_D|FTS_C)	/* dir - would cause cycle	*/
79 #define FTS_DNR		(FTS_D|FTS_NR)	/* dir - no read permission	*/
80 #define FTS_DNX		(FTS_D|FTS_NX)	/* dir - no search permission	*/
81 #define FTS_DOT		(FTS_D|FTS_DD)	/* . or ..			*/
82 #define FTS_DP		(FTS_D|FTS_P)	/* dir - post-order visit	*/
83 #define FTS_NSOK	(FTS_NS|FTS_OK)	/* no stat (because you asked)	*/
84 #define FTS_SLNONE	(FTS_SL|FTS_NS)	/* symlink - to nowhere		*/
85 
86 /*
87  * fts_set flags
88  */
89 
90 #define FTS_AGAIN	FTS_TOP		/* process entry again		*/
91 #define FTS_FOLLOW	FTS_META	/* follow FTS_SL symlink	*/
92 #define FTS_SKIP	FTS_NOSTAT	/* skip FTS_D directory		*/
93 #define FTS_STAT	FTS_PHYSICAL	/* stat() done by user		*/
94 
95 typedef struct Fts FTS;
96 typedef struct Ftsent FTSENT;
97 
98 struct Ftsent
99 {
100 	char*		fts_accpath;	/* path relative to .		*/
101 	char*		fts_name;	/* file name			*/
102 	char*		fts_path;	/* path relative to top dir	*/
103 	FTSENT*		fts_cycle;	/* offender if cycle		*/
104 	FTSENT*		fts_link;	/* next child			*/
105 	FTSENT*		fts_parent;	/* parent directory		*/
106 	struct stat*	fts_statp;	/* stat info			*/
107 #ifdef _FTSENT_LOCAL_PRIVATE_
108 	_FTSENT_LOCAL_PRIVATE_
109 #else
110 	void*		fts_pointer;	/* local pointer value		*/
111 #endif
112 	long		fts_number;	/* local numeric value		*/
113 	int		fts_errno;	/* errno for this entry		*/
114 	unsigned short	fts_info;	/* info flags			*/
115 	unsigned short	fts_namelen;	/* strlen(fts_name)		*/
116 	unsigned short	fts_pathlen;	/* strlen(fts_path)		*/
117 	short		fts_level;	/* file tree depth, 0 at top	*/
118 
119 #ifdef _FTSENT_PRIVATE_
120 	_FTSENT_PRIVATE_
121 #else
122 	short		_fts_pad_1;	/* <ftwalk.h> compatibility	*/
123 	struct stat	_fts_pad_2;	/* <ftwalk.h> compatibility	*/
124 	FTS*		fts;		/* fts_open() handle		*/
125 #endif
126 
127 };
128 
129 struct Fts
130 {
131 	int		fts_errno;	/* last errno			*/
132 	void*		fts_handle;	/* user defined handle		*/
133 
134 #ifdef _FTS_PRIVATE_
135 	_FTS_PRIVATE_
136 #endif
137 
138 };
139 
140 #if _BLD_ast && defined(__EXPORT__)
141 #define extern		__EXPORT__
142 #endif
143 
144 extern FTSENT*	fts_children(FTS*, int);
145 extern int	fts_close(FTS*);
146 extern int	fts_flags(void);
147 extern int	fts_local(FTSENT*);
148 extern int	fts_notify(int(*)(FTS*, FTSENT*, void*), void*);
149 extern FTS*	fts_open(char* const*, int, int(*)(FTSENT* const*, FTSENT* const*));
150 extern FTSENT*	fts_read(FTS*);
151 extern int	fts_set(FTS*, FTSENT*, int);
152 
153 #undef	extern
154 
155 #endif
156