xref: /titanic_41/usr/src/head/ftw.h (revision fa9e4066f08beec538e775443c5be79dd423fcab)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1988 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 
31 #ifndef	_FTW_H
32 #define	_FTW_H
33 
34 #pragma ident	"%Z%%M%	%I%	%E% SMI"
35 
36 #include <sys/feature_tests.h>
37 
38 #include <sys/types.h>
39 #include <sys/stat.h>
40 
41 #ifdef	__cplusplus
42 extern "C" {
43 #endif
44 
45 /*
46  *	Codes for the third argument to the user-supplied function
47  *	which is passed as the second argument to ftwalk
48  */
49 
50 #define	FTW_F	0	/* file */
51 #define	FTW_D	1	/* directory */
52 #define	FTW_DNR	2	/* directory without read permission */
53 #define	FTW_NS	3	/* unknown type, stat failed */
54 #define	FTW_SL	4	/* symbolic link */
55 #define	FTW_DP	6	/* directory */
56 #define	FTW_SLN	7	/* symbolic link that points to nonexistent file */
57 
58 /*
59  *	Codes for the fourth argument to ftwalk.  You can specify the
60  *	union of these flags.
61  */
62 
63 #define	FTW_PHYS	01  /* use lstat instead of stat */
64 #define	FTW_MOUNT	02  /* do not cross a mount point */
65 #define	FTW_CHDIR	04  /* chdir to each directory before reading */
66 #define	FTW_DEPTH	010 /* call descendents before calling the parent */
67 #define	FTW_ANYERR	020 /* return FTW_NS on any stat failure */
68 #define	FTW_HOPTION	040 /* private interface for find utility */
69 
70 #if defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) || defined(_XPG4_2)
71 struct FTW
72 {
73 #if defined(_XPG4_2)
74 	int	__quit;
75 #else
76 	int	quit;
77 #endif
78 	int	base;
79 	int	level;
80 };
81 #endif /* defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) ... */
82 
83 /*
84  * legal values for quit
85  */
86 
87 #define	FTW_SKD		1
88 #define	FTW_FOLLOW	2
89 #define	FTW_PRUNE	4
90 
91 /* large file compilation environment setup */
92 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
93 #ifdef	__PRAGMA_REDEFINE_EXTNAME
94 #pragma redefine_extname	_xftw	_xftw64
95 #pragma redefine_extname	_ftw	_ftw64
96 #if !defined(_XOPEN_SOURCE) || defined(_XPG5)
97 #pragma redefine_extname	nftw	nftw64
98 #endif
99 #else	/* __PRAGMA_REDEFINE_EXTNAME */
100 #define	_xftw			_xftw64
101 #define	_ftw			_ftw64
102 #if !defined(_XOPEN_SOURCE) || defined(_XPG5)
103 #define	nftw			nftw64
104 #endif
105 #endif	/* __PRAGMA_REDEFINE_EXTNAME */
106 #endif /* !_LP64 && _FILE_OFFSET_BITS == 64 */
107 
108 /* In the LP64 compilation environment, all APIs are already large file */
109 #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
110 #ifdef	__PRAGMA_REDEFINE_EXTNAME
111 #pragma	redefine_extname	_xftw64		_xftw
112 #pragma	redefine_extname	_ftw64		_ftw
113 #if !defined(_XOPEN_SOURCE) || defined(_XPG5)
114 #pragma	redefine_extname	nftw64		nftw
115 #endif
116 #else	/* __PRAGMA_REDEFINE_EXTNAME */
117 #define	_xftw64		_xftw
118 #define	_ftw64		_ftw
119 #if !defined(_XOPEN_SOURCE) || defined(_XPG5)
120 #define	nftw64		nftw
121 #endif
122 #endif	/* __PRAGMA_REDEFINE_EXTNAME */
123 #endif	/* _LP64 && _LARGEFILE64_SOURCE */
124 
125 #if defined(__STDC__)
126 
127 extern int ftw(const char *,
128 	int (*)(const char *, const struct stat *, int), int);
129 extern int _xftw(int, const char *,
130 	int (*)(const char *, const struct stat *, int), int);
131 #if defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) || defined(_XPG4_2)
132 extern int nftw(const char *,
133 	int (*)(const char *, const struct stat *, int, struct FTW *),
134 	int, int);
135 #endif /* defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) ... */
136 
137 /*
138  * transitional large file interface versions
139  */
140 #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
141 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
142 extern int ftw64(const char *,
143 	int (*)(const char *, const struct stat64 *, int), int);
144 extern int _xftw64(int, const char *,
145 	int (*)(const char *, const struct stat64 *, int), int);
146 #if !defined(_XOPEN_SOURCE)
147 extern int nftw64(const char *,
148 	int (*)(const char *, const struct stat64 *, int, struct FTW *),
149 	int, int);
150 #endif /* !defined(_XOPEN_SOURCE) */
151 #endif /* _LARGEFILE64_SOURCE .. */
152 
153 #else /* __STDC__ */
154 
155 extern int ftw(), _xftw();
156 
157 #if defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) || defined(_XPG4_2)
158 extern int nftw();
159 #endif /* defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) ... */
160 
161 /* transitional large file interface versions */
162 #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
163 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
164 extern int ftw64();
165 extern int _xftw64();
166 #if !defined(_XOPEN_SOURCE)
167 extern int nftw64();
168 #endif /* !defined(_XOPEN_SOURCE) */
169 #endif /* _LARGEFILE64_SOURCE .. */
170 
171 #endif /* __STDC__ */
172 
173 #define	_XFTWVER	2	/* version of file tree walk */
174 
175 #define	ftw(path, fn, depth)	_xftw(_XFTWVER, (path), (fn), (depth))
176 
177 #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
178 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
179 #define	ftw64(path, fn, depth)	_xftw64(_XFTWVER, (path), (fn), (depth))
180 #endif
181 
182 #ifdef	__cplusplus
183 }
184 #endif
185 
186 #endif	/* _FTW_H */
187