dirent.h revision 1.14
1/*	$OpenBSD: dirent.h,v 1.14 2005/06/18 18:09:42 millert Exp $	*/
2/*	$NetBSD: dirent.h,v 1.9 1995/03/26 20:13:37 jtc Exp $	*/
3
4/*-
5 * Copyright (c) 1989, 1993
6 *	The Regents of the University of California.  All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 *    may be used to endorse or promote products derived from this software
18 *    without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 *	@(#)dirent.h	8.2 (Berkeley) 7/28/94
33 */
34
35#ifndef _DIRENT_H_
36#define _DIRENT_H_
37
38/*
39 * POSIX doesn't mandate this, but X/Open XPG 4.2 does.
40 */
41#ifndef _POSIX_SOURCE
42#include <sys/types.h>
43#endif
44
45/*
46 * The kernel defines the format of directory entries returned by
47 * the getdirentries(2) system call.
48 */
49#include <sys/dirent.h>
50
51#ifdef _POSIX_SOURCE
52typedef void *	DIR;
53#else
54
55#define	d_ino		d_fileno	/* backward compatibility */
56
57/* definitions for library routines operating on directories. */
58#define	DIRBLKSIZ	1024
59
60/* structure describing an open directory. */
61typedef struct _dirdesc {
62	int	dd_fd;		/* file descriptor associated with directory */
63	long	dd_loc;		/* offset in current buffer */
64	long	dd_size;	/* amount of data returned by getdirentries */
65	char	*dd_buf;	/* data buffer */
66	int	dd_len;		/* size of data buffer */
67	long	dd_seek;	/* magic cookie returned by getdirentries */
68	long	dd_rewind;	/* magic cookie for rewinding */
69	int	dd_flags;	/* flags for readdir */
70} DIR;
71
72#define	dirfd(dirp)	((dirp)->dd_fd)
73
74/* flags for opendir2 */
75#define DTF_NODUP	0x0002	/* don't return duplicate names */
76#define __DTF_READALL	0x0008	/* everything has been read */
77
78#ifndef NULL
79#ifdef 	__GNUG__
80#define	NULL	__null
81#else
82#define	NULL	0L
83#endif
84#endif
85
86#endif /* _POSIX_SOURCE */
87
88#ifndef _KERNEL
89
90#include <sys/cdefs.h>
91
92__BEGIN_DECLS
93DIR *opendir(const char *);
94struct dirent *readdir(DIR *);
95void rewinddir(DIR *);
96int closedir(DIR *);
97#ifndef _POSIX_SOURCE
98DIR *__opendir2(const char *, int);
99long telldir(const DIR *);
100void seekdir(DIR *, long);
101int scandir(const char *, struct dirent ***,
102    int (*)(struct dirent *), int (*)(const void *, const void *));
103int alphasort(const void *, const void *);
104int getdirentries(int, char *, int, long *)
105		__attribute__ ((__bounded__(__string__,2,3)));
106#endif /* not POSIX */
107int readdir_r(DIR *, struct dirent *, struct dirent **);
108__END_DECLS
109
110#endif /* !_KERNEL */
111
112#endif /* !_DIRENT_H_ */
113