]> git.ipfire.org Git - thirdparty/glibc.git/blame - dirent/dirent.h
* sysdeps/mach/hurd/dirstream.h: Define `struct __dirstream'
[thirdparty/glibc.git] / dirent / dirent.h
CommitLineData
22a1292a 1/* Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
28f540f4
RM
2This file is part of the GNU C Library.
3
4The GNU C Library is free software; you can redistribute it and/or
5modify it under the terms of the GNU Library General Public License as
6published by the Free Software Foundation; either version 2 of the
7License, or (at your option) any later version.
8
9The GNU C Library is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12Library General Public License for more details.
13
14You should have received a copy of the GNU Library General Public
15License along with the GNU C Library; see the file COPYING.LIB. If
16not, write to the, 1992 Free Software Foundation, Inc., 675 Mass Ave,
17Cambridge, MA 02139, USA. */
18
19/*
20 * POSIX Standard: 5.1.2 Directory Operations <dirent.h>
21 */
22
23#ifndef _DIRENT_H
24
25#define _DIRENT_H 1
26#include <features.h>
27
28__BEGIN_DECLS
29
30#include <gnu/types.h>
31
32
33/* Directory entry structure.
34
35 This structure is laid out identically to the `struct direct' that
36 represents directory entries in the GNU Hurd and in BSD 4.4 (and
37 incidentally, on disk in the Berkeley fast file system). The `readdir'
38 implementations for GNU and BSD know this; you must change them if you
39 change this structure. */
40
41struct dirent
42 {
43 __ino_t d_fileno; /* File serial number. */
44 unsigned short int d_reclen; /* Length of the whole `struct dirent'. */
45 unsigned char d_type; /* File type, possibly unknown. */
46 unsigned char d_namlen; /* Length of the file name. */
47
48 /* Only this member is in the POSIX standard. */
49 char d_name[1]; /* File name (actually longer). */
50 };
51
52#if defined(__USE_BSD) || defined(__USE_MISC)
53#define d_ino d_fileno /* Backward compatibility. */
54#endif
55
56#ifdef __USE_BSD
57/* File types for `d_type'. */
58enum
59 {
60 DT_UNKNOWN = 0,
61 DT_FIFO = 1,
62 DT_CHR = 2,
63 DT_DIR = 4,
64 DT_BLK = 6,
65 DT_REG = 8,
66 DT_LNK = 10,
67 DT_SOCK = 12
68 };
69
70/* Convert between stat structure types and directory types. */
71#define IFTODT(mode) (((mode) & 0170000) >> 12)
72#define DTTOIF(dirtype) ((dirtype) << 12)
73#endif
74
75
76/* Get the system-dependent definition of `DIR',
77 the data type of directory stream objects. */
78#include <dirstream.h>
79
80/* Open a directory stream on NAME.
81 Return a DIR stream on the directory, or NULL if it could not be opened. */
82extern DIR *opendir __P ((__const char *__name));
83
84/* Close the directory stream DIRP.
85 Return 0 if successful, -1 if not. */
86extern int closedir __P ((DIR * __dirp));
87
88/* Read a directory entry from DIRP.
89 Return a pointer to a `struct dirent' describing the entry,
90 or NULL for EOF or error. The storage returned may be overwritten
91 by a later readdir call on the same DIR stream. */
92extern struct dirent *readdir __P ((DIR * __dirp));
93
94/* Rewind DIRP to the beginning of the directory. */
95extern void rewinddir __P ((DIR * __dirp));
96
97#if defined(__USE_BSD) || defined(__USE_MISC)
98
22a1292a
RM
99/* Return the file descriptor used by DIRP. */
100extern int dirfd __P ((DIR *__dirp));
101
102#if defined (__OPTIMIZE__) && defined (_DIR_dirfd)
103#define dirfd(dirp) _DIR_dirfd (dirp)
104#endif
105
28f540f4
RM
106#ifndef MAXNAMLEN
107/* Get the definitions of the POSIX.1 limits. */
108#include <posix1_lim.h>
109
110/* `MAXNAMLEN' is the BSD name for what POSIX calls `NAME_MAX'. */
111#ifdef NAME_MAX
112#define MAXNAMLEN NAME_MAX
113#else
114#define MAXNAMLEN 255
115#endif
116#endif
117
118#include <gnu/types.h>
119#define __need_size_t
120#include <stddef.h>
121
122/* Seek to position POS on DIRP. */
123extern void seekdir __P ((DIR * __dirp, __off_t __pos));
124
125/* Return the current position of DIRP. */
126extern __off_t telldir __P ((DIR * __dirp));
127
128/* Scan the directory DIR, calling SELECT on each directory entry.
129 Entries for which SELECT returns nonzero are individually malloc'd,
130 sorted using qsort with CMP, and collected in a malloc'd array in
131 *NAMELIST. Returns the number of entries selected, or -1 on error. */
132extern int scandir __P ((__const char *__dir,
133 struct dirent ***__namelist,
134 int (*__select) __P ((struct dirent *)),
135 int (*__cmp) __P ((__const __ptr_t,
136 __const __ptr_t))));
137
138/* Function to compare two `struct dirent's alphabetically. */
139extern int alphasort __P ((__const __ptr_t, __const __ptr_t));
140
141
142/* Read directory entries from FD into BUF, reading at most NBYTES.
143 Reading starts at offset *BASEP, and *BASEP is updated with the new
144 position after reading. Returns the number of bytes read; zero when at
145 end of directory; or -1 for errors. */
146extern __ssize_t __getdirentries __P ((int __fd, char *__buf,
147 size_t __nbytes, __off_t *__basep));
148extern __ssize_t getdirentries __P ((int __fd, char *__buf,
149 size_t __nbytes, __off_t *__basep));
150
151
152#endif /* Use BSD or misc. */
153
154__END_DECLS
155
156#endif /* dirent.h */