xref: /freebsd/include/dirent.h (revision 5a1d14419a5b620430949a46cb6ee63148a43cb9)
159deaec5SRodney W. Grimes /*-
22321c474SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
32321c474SPedro F. Giffuni  *
459deaec5SRodney W. Grimes  * Copyright (c) 1989, 1993
559deaec5SRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
659deaec5SRodney W. Grimes  *
759deaec5SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
859deaec5SRodney W. Grimes  * modification, are permitted provided that the following conditions
959deaec5SRodney W. Grimes  * are met:
1059deaec5SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
1159deaec5SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
1259deaec5SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
1359deaec5SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
1459deaec5SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
15f2556687SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
1659deaec5SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
1759deaec5SRodney W. Grimes  *    without specific prior written permission.
1859deaec5SRodney W. Grimes  *
1959deaec5SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2059deaec5SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2159deaec5SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2259deaec5SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2359deaec5SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2459deaec5SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2559deaec5SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2659deaec5SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2759deaec5SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2859deaec5SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2959deaec5SRodney W. Grimes  * SUCH DAMAGE.
3059deaec5SRodney W. Grimes  */
3159deaec5SRodney W. Grimes 
3259deaec5SRodney W. Grimes #ifndef _DIRENT_H_
3359deaec5SRodney W. Grimes #define _DIRENT_H_
3459deaec5SRodney W. Grimes 
3559deaec5SRodney W. Grimes /*
3659deaec5SRodney W. Grimes  * The kernel defines the format of directory entries returned by
3759deaec5SRodney W. Grimes  * the getdirentries(2) system call.
3859deaec5SRodney W. Grimes  */
399ad8e31eSMike Barcroft #include <sys/cdefs.h>
40611c29baSEd Schouten #include <sys/_types.h>
4159deaec5SRodney W. Grimes #include <sys/dirent.h>
4259deaec5SRodney W. Grimes 
4369921123SKonstantin Belousov #if __BSD_VISIBLE
4469921123SKonstantin Belousov 
4569921123SKonstantin Belousov #ifndef _SIZE_T_DECLARED
4669921123SKonstantin Belousov typedef	__size_t	size_t;
4769921123SKonstantin Belousov #define	_SIZE_T_DECLARED
4869921123SKonstantin Belousov #endif
4969921123SKonstantin Belousov 
5069921123SKonstantin Belousov #ifndef _SSIZE_T_DECLARED
5169921123SKonstantin Belousov typedef	__ssize_t	ssize_t;
5269921123SKonstantin Belousov #define	_SSIZE_T_DECLARED
5369921123SKonstantin Belousov #endif
5469921123SKonstantin Belousov 
5569921123SKonstantin Belousov #ifndef _OFF_T_DECLARED
5669921123SKonstantin Belousov typedef	__off_t		off_t;
5769921123SKonstantin Belousov #define	_OFF_T_DECLARED
5869921123SKonstantin Belousov #endif
5969921123SKonstantin Belousov 
6069921123SKonstantin Belousov #endif /* __BSD_VISIBLE */
6169921123SKonstantin Belousov 
62448f5f73SJilles Tjoelker #if __XSI_VISIBLE
63611c29baSEd Schouten 
64611c29baSEd Schouten #ifndef _INO_T_DECLARED
65611c29baSEd Schouten typedef	__ino_t		ino_t;
66611c29baSEd Schouten #define	_INO_T_DECLARED
67611c29baSEd Schouten #endif
68611c29baSEd Schouten 
699ad8e31eSMike Barcroft /*
709ad8e31eSMike Barcroft  * XXX this is probably illegal in the __XSI_VISIBLE case, but brings us closer
719ad8e31eSMike Barcroft  * to the specification.
729ad8e31eSMike Barcroft  */
739ad8e31eSMike Barcroft #define	d_ino		d_fileno	/* backward and XSI compatibility */
74611c29baSEd Schouten 
75611c29baSEd Schouten #endif /* __XSI_VISIBLE */
7659deaec5SRodney W. Grimes 
779ad8e31eSMike Barcroft #if __BSD_VISIBLE
7859deaec5SRodney W. Grimes 
7912eb46c8SMarcel Moolenaar #include <sys/_null.h>
8012eb46c8SMarcel Moolenaar 
8159deaec5SRodney W. Grimes /* definitions for library routines operating on directories. */
8259deaec5SRodney W. Grimes #define	DIRBLKSIZ	1024
8359deaec5SRodney W. Grimes 
840bb2aabfSGleb Kurtsou struct _dirdesc;
850bb2aabfSGleb Kurtsou typedef struct _dirdesc DIR;
8659deaec5SRodney W. Grimes 
8748eaae48SPeter Wemm /* flags for opendir2 */
8848eaae48SPeter Wemm #define DTF_HIDEW	0x0001	/* hide whiteout entries */
8948eaae48SPeter Wemm #define DTF_NODUP	0x0002	/* don't return duplicate names */
9048eaae48SPeter Wemm #define DTF_REWIND	0x0004	/* rewind after reading union stack */
9148eaae48SPeter Wemm #define __DTF_READALL	0x0008	/* everything has been read */
929f72c032SJohn Baldwin #define	__DTF_SKIPREAD	0x0010  /* assume internal buffer is populated */
9348eaae48SPeter Wemm 
949ad8e31eSMike Barcroft #else /* !__BSD_VISIBLE */
959ad8e31eSMike Barcroft 
969ad8e31eSMike Barcroft typedef	void *	DIR;
979ad8e31eSMike Barcroft 
989ad8e31eSMike Barcroft #endif /* __BSD_VISIBLE */
9959deaec5SRodney W. Grimes 
100c4473420SPeter Wemm #ifndef _KERNEL
10159deaec5SRodney W. Grimes 
10259deaec5SRodney W. Grimes __BEGIN_DECLS
103c4ecd13bSKonstantin Belousov #if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 700
104c4ecd13bSKonstantin Belousov int	 alphasort(const struct dirent **, const struct dirent **);
1050bb2aabfSGleb Kurtsou int	 dirfd(DIR *);
106c4ecd13bSKonstantin Belousov #endif
1079ad8e31eSMike Barcroft #if __BSD_VISIBLE
108*05c9a015SAymeric Wibo int	 versionsort(const struct dirent **, const struct dirent **);
109bb28f3c2SWarner Losh DIR	*__opendir2(const char *, int);
11050079a51SPawel Jakub Dawidek int	 fdclosedir(DIR *);
11169921123SKonstantin Belousov ssize_t	 getdents(int, char *, size_t);
11269921123SKonstantin Belousov ssize_t	 getdirentries(int, char *, size_t, off_t *);
1139ad8e31eSMike Barcroft #endif
1149ad8e31eSMike Barcroft DIR	*opendir(const char *);
1156fda52baSXin LI DIR	*fdopendir(int);
1169ad8e31eSMike Barcroft struct dirent *
1179ad8e31eSMike Barcroft 	 readdir(DIR *);
1189ad8e31eSMike Barcroft #if __POSIX_VISIBLE >= 199506 || __XSI_VISIBLE >= 500
119bb28f3c2SWarner Losh int	 readdir_r(DIR *, struct dirent *, struct dirent **);
1209ad8e31eSMike Barcroft #endif
1219ad8e31eSMike Barcroft void	 rewinddir(DIR *);
122c4ecd13bSKonstantin Belousov #if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 700
1239ad8e31eSMike Barcroft int	 scandir(const char *, struct dirent ***,
1244176dd52SKonstantin Belousov 	    int (*)(const struct dirent *), int (*)(const struct dirent **,
1254176dd52SKonstantin Belousov 	    const struct dirent **));
12646cdc140SDavid Chisnall #ifdef __BLOCKS__
12746cdc140SDavid Chisnall int	 scandir_b(const char *, struct dirent ***,
12846cdc140SDavid Chisnall 	    int (^)(const struct dirent *),
12946cdc140SDavid Chisnall 	    int (^)(const struct dirent **, const struct dirent **));
13046cdc140SDavid Chisnall #endif
1319ad8e31eSMike Barcroft #endif
1329fb8e8eeSKonstantin Belousov #if __BSD_VISIBLE
1339fb8e8eeSKonstantin Belousov int	 scandirat(int, const char *, struct dirent ***,
1349fb8e8eeSKonstantin Belousov 	    int (*)(const struct dirent *), int (*)(const struct dirent **,
1359fb8e8eeSKonstantin Belousov 	    const struct dirent **));
1369fb8e8eeSKonstantin Belousov #endif
1379ad8e31eSMike Barcroft #if __XSI_VISIBLE
1389ad8e31eSMike Barcroft void	 seekdir(DIR *, long);
1399ad8e31eSMike Barcroft long	 telldir(DIR *);
1409ad8e31eSMike Barcroft #endif
1419ad8e31eSMike Barcroft int	 closedir(DIR *);
14259deaec5SRodney W. Grimes __END_DECLS
14359deaec5SRodney W. Grimes 
144c4473420SPeter Wemm #endif /* !_KERNEL */
14559deaec5SRodney W. Grimes 
14659deaec5SRodney W. Grimes #endif /* !_DIRENT_H_ */
147