dirent.h revision 69655
11539Srgrimes/*-
21539Srgrimes * Copyright (c) 1989, 1993
31539Srgrimes *	The Regents of the University of California.  All rights reserved.
41539Srgrimes *
51539Srgrimes * Redistribution and use in source and binary forms, with or without
61539Srgrimes * modification, are permitted provided that the following conditions
71539Srgrimes * are met:
81539Srgrimes * 1. Redistributions of source code must retain the above copyright
91539Srgrimes *    notice, this list of conditions and the following disclaimer.
101539Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111539Srgrimes *    notice, this list of conditions and the following disclaimer in the
121539Srgrimes *    documentation and/or other materials provided with the distribution.
131539Srgrimes * 3. All advertising materials mentioning features or use of this software
141539Srgrimes *    must display the following acknowledgement:
151539Srgrimes *	This product includes software developed by the University of
161539Srgrimes *	California, Berkeley and its contributors.
171539Srgrimes * 4. Neither the name of the University nor the names of its contributors
181539Srgrimes *    may be used to endorse or promote products derived from this software
191539Srgrimes *    without specific prior written permission.
201539Srgrimes *
211539Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221539Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231539Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241539Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251539Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261539Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271539Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281539Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291539Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301539Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311539Srgrimes * SUCH DAMAGE.
321539Srgrimes *
3323654Speter *	@(#)dirent.h	8.2 (Berkeley) 7/28/94
3453812Salfred * $FreeBSD: head/include/dirent.h 69655 2000-12-06 03:14:28Z deischen $
351539Srgrimes */
361539Srgrimes
371539Srgrimes#ifndef _DIRENT_H_
381539Srgrimes#define _DIRENT_H_
391539Srgrimes
401539Srgrimes/*
418858Srgrimes * The kernel defines the format of directory entries returned by
421539Srgrimes * the getdirentries(2) system call.
431539Srgrimes */
441539Srgrimes#include <sys/dirent.h>
4569655Sdeischen#include <sys/queue.h>
461539Srgrimes
471539Srgrimes#ifdef _POSIX_SOURCE
481539Srgrimestypedef void *	DIR;
491539Srgrimes#else
501539Srgrimes
511539Srgrimes#define	d_ino		d_fileno	/* backward compatibility */
521539Srgrimes
531539Srgrimes/* definitions for library routines operating on directories. */
541539Srgrimes#define	DIRBLKSIZ	1024
551539Srgrimes
5669655Sdeischenstruct _ddloc;
5769655Sdeischen
581539Srgrimes/* structure describing an open directory. */
591539Srgrimestypedef struct _dirdesc {
601539Srgrimes	int	dd_fd;		/* file descriptor associated with directory */
611539Srgrimes	long	dd_loc;		/* offset in current buffer */
621539Srgrimes	long	dd_size;	/* amount of data returned by getdirentries */
631539Srgrimes	char	*dd_buf;	/* data buffer */
641539Srgrimes	int	dd_len;		/* size of data buffer */
651539Srgrimes	long	dd_seek;	/* magic cookie returned by getdirentries */
661539Srgrimes	long	dd_rewind;	/* magic cookie for rewinding */
6723654Speter	int	dd_flags;	/* flags for readdir */
6869655Sdeischen	long	dd_loccnt;	/* Index of entry for sequential readdir's */
6969655Sdeischen	LIST_HEAD(, _ddloc) dd_locq; /* telldir position recording */
701539Srgrimes} DIR;
711539Srgrimes
721539Srgrimes#define	dirfd(dirp)	((dirp)->dd_fd)
731539Srgrimes
7423654Speter/* flags for opendir2 */
7523654Speter#define DTF_HIDEW	0x0001	/* hide whiteout entries */
7623654Speter#define DTF_NODUP	0x0002	/* don't return duplicate names */
7723654Speter#define DTF_REWIND	0x0004	/* rewind after reading union stack */
7823654Speter#define __DTF_READALL	0x0008	/* everything has been read */
7923654Speter
801539Srgrimes#ifndef NULL
811539Srgrimes#define	NULL	0
821539Srgrimes#endif
831539Srgrimes
841539Srgrimes#endif /* _POSIX_SOURCE */
851539Srgrimes
8655206Speter#ifndef _KERNEL
871539Srgrimes
881539Srgrimes#include <sys/cdefs.h>
891539Srgrimes
901539Srgrimes__BEGIN_DECLS
911539SrgrimesDIR *opendir __P((const char *));
921539Srgrimesstruct dirent *readdir __P((DIR *));
931539Srgrimesvoid rewinddir __P((DIR *));
941539Srgrimesint closedir __P((DIR *));
951539Srgrimes#ifndef _POSIX_SOURCE
9623654SpeterDIR *__opendir2 __P((const char *, int));
9769655Sdeischenlong telldir __P((DIR *));
981539Srgrimesvoid seekdir __P((DIR *, long));
991539Srgrimesint scandir __P((const char *, struct dirent ***,
1001539Srgrimes    int (*)(struct dirent *), int (*)(const void *, const void *)));
1011539Srgrimesint alphasort __P((const void *, const void *));
10255030Sbdeint getdents __P((int, char *, int));
1031539Srgrimesint getdirentries __P((int, char *, int, long *));
10453892Salfredint readdir_r __P((DIR *, struct dirent *, struct dirent **));
1051539Srgrimes#endif /* not POSIX */
1061539Srgrimes__END_DECLS
1071539Srgrimes
10855206Speter#endif /* !_KERNEL */
1091539Srgrimes
1101539Srgrimes#endif /* !_DIRENT_H_ */
111