xref: /onnv-gate/usr/src/head/ftw.h (revision 3523:b9f12aa2fb57)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*3523Scf46844  * Common Development and Distribution License (the "License").
6*3523Scf46844  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*3523Scf46844  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
270Sstevel@tonic-gate /*	  All Rights Reserved  	*/
280Sstevel@tonic-gate 
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #ifndef	_FTW_H
310Sstevel@tonic-gate #define	_FTW_H
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #include <sys/feature_tests.h>
360Sstevel@tonic-gate 
370Sstevel@tonic-gate #include <sys/types.h>
380Sstevel@tonic-gate #include <sys/stat.h>
390Sstevel@tonic-gate 
400Sstevel@tonic-gate #ifdef	__cplusplus
410Sstevel@tonic-gate extern "C" {
420Sstevel@tonic-gate #endif
430Sstevel@tonic-gate 
440Sstevel@tonic-gate /*
45*3523Scf46844  *	Codes for the third argument to the user-supplied function.
460Sstevel@tonic-gate  */
470Sstevel@tonic-gate 
480Sstevel@tonic-gate #define	FTW_F	0	/* file */
490Sstevel@tonic-gate #define	FTW_D	1	/* directory */
500Sstevel@tonic-gate #define	FTW_DNR	2	/* directory without read permission */
510Sstevel@tonic-gate #define	FTW_NS	3	/* unknown type, stat failed */
520Sstevel@tonic-gate #define	FTW_SL	4	/* symbolic link */
530Sstevel@tonic-gate #define	FTW_DP	6	/* directory */
540Sstevel@tonic-gate #define	FTW_SLN	7	/* symbolic link that points to nonexistent file */
55*3523Scf46844 #define	FTW_DL	8	/* private interface for find utility */
560Sstevel@tonic-gate 
570Sstevel@tonic-gate /*
58*3523Scf46844  *	Codes for the fourth argument to nftw.  You can specify the
590Sstevel@tonic-gate  *	union of these flags.
600Sstevel@tonic-gate  */
610Sstevel@tonic-gate 
620Sstevel@tonic-gate #define	FTW_PHYS	01  /* use lstat instead of stat */
630Sstevel@tonic-gate #define	FTW_MOUNT	02  /* do not cross a mount point */
640Sstevel@tonic-gate #define	FTW_CHDIR	04  /* chdir to each directory before reading */
650Sstevel@tonic-gate #define	FTW_DEPTH	010 /* call descendents before calling the parent */
660Sstevel@tonic-gate #define	FTW_ANYERR	020 /* return FTW_NS on any stat failure */
670Sstevel@tonic-gate #define	FTW_HOPTION	040 /* private interface for find utility */
68*3523Scf46844 #define	FTW_NOLOOP	0100 /* private interface for find utility */
690Sstevel@tonic-gate 
700Sstevel@tonic-gate #if defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) || defined(_XPG4_2)
710Sstevel@tonic-gate struct FTW
720Sstevel@tonic-gate {
730Sstevel@tonic-gate #if defined(_XPG4_2)
740Sstevel@tonic-gate 	int	__quit;
750Sstevel@tonic-gate #else
760Sstevel@tonic-gate 	int	quit;
770Sstevel@tonic-gate #endif
780Sstevel@tonic-gate 	int	base;
790Sstevel@tonic-gate 	int	level;
800Sstevel@tonic-gate };
810Sstevel@tonic-gate #endif /* defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) ... */
820Sstevel@tonic-gate 
830Sstevel@tonic-gate /*
840Sstevel@tonic-gate  * legal values for quit
850Sstevel@tonic-gate  */
860Sstevel@tonic-gate 
870Sstevel@tonic-gate #define	FTW_SKD		1
880Sstevel@tonic-gate #define	FTW_FOLLOW	2
890Sstevel@tonic-gate #define	FTW_PRUNE	4
900Sstevel@tonic-gate 
910Sstevel@tonic-gate /* large file compilation environment setup */
920Sstevel@tonic-gate #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
930Sstevel@tonic-gate #ifdef	__PRAGMA_REDEFINE_EXTNAME
940Sstevel@tonic-gate #pragma redefine_extname	_xftw	_xftw64
950Sstevel@tonic-gate #pragma redefine_extname	_ftw	_ftw64
960Sstevel@tonic-gate #if !defined(_XOPEN_SOURCE) || defined(_XPG5)
970Sstevel@tonic-gate #pragma redefine_extname	nftw	nftw64
980Sstevel@tonic-gate #endif
990Sstevel@tonic-gate #else	/* __PRAGMA_REDEFINE_EXTNAME */
1000Sstevel@tonic-gate #define	_xftw			_xftw64
1010Sstevel@tonic-gate #define	_ftw			_ftw64
1020Sstevel@tonic-gate #if !defined(_XOPEN_SOURCE) || defined(_XPG5)
1030Sstevel@tonic-gate #define	nftw			nftw64
1040Sstevel@tonic-gate #endif
1050Sstevel@tonic-gate #endif	/* __PRAGMA_REDEFINE_EXTNAME */
1060Sstevel@tonic-gate #endif /* !_LP64 && _FILE_OFFSET_BITS == 64 */
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate /* In the LP64 compilation environment, all APIs are already large file */
1090Sstevel@tonic-gate #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
1100Sstevel@tonic-gate #ifdef	__PRAGMA_REDEFINE_EXTNAME
1110Sstevel@tonic-gate #pragma	redefine_extname	_xftw64		_xftw
1120Sstevel@tonic-gate #pragma	redefine_extname	_ftw64		_ftw
1130Sstevel@tonic-gate #if !defined(_XOPEN_SOURCE) || defined(_XPG5)
1140Sstevel@tonic-gate #pragma	redefine_extname	nftw64		nftw
1150Sstevel@tonic-gate #endif
1160Sstevel@tonic-gate #else	/* __PRAGMA_REDEFINE_EXTNAME */
1170Sstevel@tonic-gate #define	_xftw64		_xftw
1180Sstevel@tonic-gate #define	_ftw64		_ftw
1190Sstevel@tonic-gate #if !defined(_XOPEN_SOURCE) || defined(_XPG5)
1200Sstevel@tonic-gate #define	nftw64		nftw
1210Sstevel@tonic-gate #endif
1220Sstevel@tonic-gate #endif	/* __PRAGMA_REDEFINE_EXTNAME */
1230Sstevel@tonic-gate #endif	/* _LP64 && _LARGEFILE64_SOURCE */
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate #if defined(__STDC__)
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate extern int ftw(const char *,
1280Sstevel@tonic-gate 	int (*)(const char *, const struct stat *, int), int);
1290Sstevel@tonic-gate extern int _xftw(int, const char *,
1300Sstevel@tonic-gate 	int (*)(const char *, const struct stat *, int), int);
1310Sstevel@tonic-gate #if defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) || defined(_XPG4_2)
1320Sstevel@tonic-gate extern int nftw(const char *,
1330Sstevel@tonic-gate 	int (*)(const char *, const struct stat *, int, struct FTW *),
1340Sstevel@tonic-gate 	int, int);
1350Sstevel@tonic-gate #endif /* defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) ... */
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate /*
1380Sstevel@tonic-gate  * transitional large file interface versions
1390Sstevel@tonic-gate  */
1400Sstevel@tonic-gate #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
1410Sstevel@tonic-gate 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
1420Sstevel@tonic-gate extern int ftw64(const char *,
1430Sstevel@tonic-gate 	int (*)(const char *, const struct stat64 *, int), int);
1440Sstevel@tonic-gate extern int _xftw64(int, const char *,
1450Sstevel@tonic-gate 	int (*)(const char *, const struct stat64 *, int), int);
1460Sstevel@tonic-gate #if !defined(_XOPEN_SOURCE)
1470Sstevel@tonic-gate extern int nftw64(const char *,
1480Sstevel@tonic-gate 	int (*)(const char *, const struct stat64 *, int, struct FTW *),
1490Sstevel@tonic-gate 	int, int);
1500Sstevel@tonic-gate #endif /* !defined(_XOPEN_SOURCE) */
1510Sstevel@tonic-gate #endif /* _LARGEFILE64_SOURCE .. */
1520Sstevel@tonic-gate 
1530Sstevel@tonic-gate #else /* __STDC__ */
1540Sstevel@tonic-gate 
1550Sstevel@tonic-gate extern int ftw(), _xftw();
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate #if defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) || defined(_XPG4_2)
1580Sstevel@tonic-gate extern int nftw();
1590Sstevel@tonic-gate #endif /* defined(__EXTENSIONS__) || !defined(_XOPEN_SOURCE) ... */
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate /* transitional large file interface versions */
1620Sstevel@tonic-gate #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
1630Sstevel@tonic-gate 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
1640Sstevel@tonic-gate extern int ftw64();
1650Sstevel@tonic-gate extern int _xftw64();
1660Sstevel@tonic-gate #if !defined(_XOPEN_SOURCE)
1670Sstevel@tonic-gate extern int nftw64();
1680Sstevel@tonic-gate #endif /* !defined(_XOPEN_SOURCE) */
1690Sstevel@tonic-gate #endif /* _LARGEFILE64_SOURCE .. */
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate #endif /* __STDC__ */
1720Sstevel@tonic-gate 
1730Sstevel@tonic-gate #define	_XFTWVER	2	/* version of file tree walk */
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate #define	ftw(path, fn, depth)	_xftw(_XFTWVER, (path), (fn), (depth))
1760Sstevel@tonic-gate 
1770Sstevel@tonic-gate #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
1780Sstevel@tonic-gate 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
1790Sstevel@tonic-gate #define	ftw64(path, fn, depth)	_xftw64(_XFTWVER, (path), (fn), (depth))
1800Sstevel@tonic-gate #endif
1810Sstevel@tonic-gate 
1820Sstevel@tonic-gate #ifdef	__cplusplus
1830Sstevel@tonic-gate }
1840Sstevel@tonic-gate #endif
1850Sstevel@tonic-gate 
1860Sstevel@tonic-gate #endif	/* _FTW_H */
187