xref: /netbsd-src/include/dirent.h (revision 984ee458feb6c4917624ddd2c24f4a86cb3289c9)
1*984ee458Snia /*	$NetBSD: dirent.h,v 1.38 2022/12/28 11:51:21 nia Exp $	*/
24d2cbfceScgd 
361f28255Scgd /*-
4587fd4ceSmycroft  * Copyright (c) 1989, 1993
5587fd4ceSmycroft  *	The Regents of the University of California.  All rights reserved.
661f28255Scgd  *
761f28255Scgd  * Redistribution and use in source and binary forms, with or without
861f28255Scgd  * modification, are permitted provided that the following conditions
961f28255Scgd  * are met:
1061f28255Scgd  * 1. Redistributions of source code must retain the above copyright
1161f28255Scgd  *    notice, this list of conditions and the following disclaimer.
1261f28255Scgd  * 2. Redistributions in binary form must reproduce the above copyright
1361f28255Scgd  *    notice, this list of conditions and the following disclaimer in the
1461f28255Scgd  *    documentation and/or other materials provided with the distribution.
15039cc956Sagc  * 3. Neither the name of the University nor the names of its contributors
1661f28255Scgd  *    may be used to endorse or promote products derived from this software
1761f28255Scgd  *    without specific prior written permission.
1861f28255Scgd  *
1961f28255Scgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2061f28255Scgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2161f28255Scgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2261f28255Scgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2361f28255Scgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2461f28255Scgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2561f28255Scgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2661f28255Scgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2761f28255Scgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2861f28255Scgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2961f28255Scgd  * SUCH DAMAGE.
3061f28255Scgd  *
311fc62d21Smycroft  *	@(#)dirent.h	8.2 (Berkeley) 7/28/94
3261f28255Scgd  */
3361f28255Scgd 
3461f28255Scgd #ifndef _DIRENT_H_
3561f28255Scgd #define _DIRENT_H_
3661f28255Scgd 
374881197cSkleink #include <sys/featuretest.h>
38955f6c4aSjtc #include <sys/types.h>
39955f6c4aSjtc 
40587fd4ceSmycroft /*
41587fd4ceSmycroft  * The kernel defines the format of directory entries returned by
4282c43e19Schristos  * the getdents(2) system call.
43587fd4ceSmycroft  */
44dd9637d6Sjtc #include <sys/dirent.h>
4561f28255Scgd 
464be7a2dcSbjh21 #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
474881197cSkleink #define	d_ino		d_fileno	/* backward compatibility */
484881197cSkleink #endif
494881197cSkleink 
508758baf5Sbjh21 typedef struct _dirdesc DIR;
518758baf5Sbjh21 
528758baf5Sbjh21 #if defined(_NETBSD_SOURCE)
53587fd4ceSmycroft 
54587fd4ceSmycroft /* definitions for library routines operating on directories. */
55587fd4ceSmycroft #define	DIRBLKSIZ	1024
56587fd4ceSmycroft 
5761f28255Scgd /* structure describing an open directory. */
588758baf5Sbjh21 struct _dirdesc {
595c3967c0Syamt 	/*
605c3967c0Syamt 	 * dd_fd should be kept intact to preserve ABI compat.  see dirfd().
615c3967c0Syamt 	 */
6261f28255Scgd 	int	dd_fd;		/* file descriptor associated with directory */
635c3967c0Syamt 	/*
645c3967c0Syamt 	 * the rest is hidden from user.
655c3967c0Syamt 	 */
6661f28255Scgd 	long	dd_loc;		/* offset in current buffer */
670df65206Sfvdl 	long	dd_size;	/* amount of data returned by getdents */
6861f28255Scgd 	char	*dd_buf;	/* data buffer */
6961f28255Scgd 	int	dd_len;		/* size of data buffer */
700df65206Sfvdl 	off_t	dd_seek;	/* magic cookie returned by getdents */
7154595e99Schristos 	void	*dd_internal;	/* state for seekdir/telldir */
721fc62d21Smycroft 	int	dd_flags;	/* flags for readdir */
730cc4f4a6Schristos 	void	*dd_lock;	/* lock for concurrent access */
748758baf5Sbjh21 };
7561f28255Scgd 
7661f28255Scgd #define	dirfd(dirp)	((dirp)->dd_fd)
7761f28255Scgd 
784881197cSkleink /* flags for __opendir2() */
791fc62d21Smycroft #define DTF_HIDEW	0x0001	/* hide whiteout entries */
801fc62d21Smycroft #define DTF_NODUP	0x0002	/* don't return duplicate names */
811fc62d21Smycroft #define DTF_REWIND	0x0004	/* rewind after reading union stack */
821fc62d21Smycroft #define __DTF_READALL	0x0008	/* everything has been read */
83ab5972b0Syamt #define __DTF_RETRY_ON_BADCOOKIE 0x0001	/* retry on EINVAL
84ab5972b0Syamt 					(only valid with __DTF_READALL) */
851fc62d21Smycroft 
866f29805eSkleink #include <sys/null.h>
87587fd4ceSmycroft 
888758baf5Sbjh21 #endif
8961f28255Scgd 
90362f2aadSjtc #ifndef _KERNEL
9161f28255Scgd 
9261f28255Scgd #include <sys/cdefs.h>
9361f28255Scgd 
9461f28255Scgd __BEGIN_DECLS
9519b7469aSperry int closedir(DIR *);
9619b7469aSperry void rewinddir(DIR *);
9766412e72Schristos #ifndef __LIBC12_SOURCE__
9833037645Schristos DIR *opendir(const char *) __RENAME(__opendir30);
9933037645Schristos struct dirent *readdir(DIR *) __RENAME(__readdir30);
100fb11ba2dSchristos int readdir_r(DIR * __restrict, struct dirent * __restrict,
10133037645Schristos     struct dirent ** __restrict) __RENAME(__readdir_r30);
10233037645Schristos #endif
1034be7a2dcSbjh21 #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
10419b7469aSperry void seekdir(DIR *, long);
10554595e99Schristos long telldir(DIR *);
1064be7a2dcSbjh21 #endif /* defined(_NETBSD_SOURCE) || defined(_XOPEN_SOURCE) */
1073c1a792cSnros #if (_POSIX_C_SOURCE - 0) >= 200809L || (_XOPEN_SOURCE - 0) >= 700 || \
1083c1a792cSnros     defined(_NETBSD_SOURCE)
10966412e72Schristos #ifndef __LIBC12_SOURCE__
110117c67b2Sad DIR *fdopendir(int);
111*984ee458Snia int scandir(const char *, struct dirent ***,
112*984ee458Snia     int (*)(const struct dirent *), int (*)(const struct dirent **,
113*984ee458Snia     const struct dirent **))
114*984ee458Snia     __RENAME(__scandir30);
115*984ee458Snia int alphasort(const struct dirent **, const struct dirent **)
116*984ee458Snia     __RENAME(__alphasort30);
1173c1a792cSnros #endif
1183c1a792cSnros #endif
1193c1a792cSnros #if defined(_NETBSD_SOURCE)
1203c1a792cSnros #ifndef __LIBC12_SOURCE__
12133037645Schristos DIR *__opendir2(const char *, int) __RENAME(__opendir230);
12233037645Schristos int getdents(int, char *, size_t) __RENAME(__getdents30);
12333037645Schristos #endif
1244be7a2dcSbjh21 #endif /* defined(_NETBSD_SOURCE) */
12561f28255Scgd __END_DECLS
12661f28255Scgd 
127362f2aadSjtc #endif /* !_KERNEL */
128587fd4ceSmycroft 
12961f28255Scgd #endif /* !_DIRENT_H_ */
130