1 /* Copyright (C) 1991 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is distributed in the hope that it will be useful, but
5 WITHOUT ANY WARRANTY. No author or distributor accepts responsibility for
6 the consequences of using it or for whether it serves any particular
7 purpose or works at all, unless he says so in writing. Refer to the GNU
8 C Library General Public License (in the file COPYING) for full details.
10 Everyone is granted permission to copy, modify and redistribute
11 the GNU C Library, but only under the conditions described in the
12 GNU C Library General Public License. Among other things, this notice
13 must not be changed and a copy of the license must be included. */
23 #include <sys/types.h>
25 #ifndef READ_DIRECTORY
26 #define READ_DIRECTORY \
28 int bytes = __read(dirp->__fd, dirp->__data, dirp->__allocation); \
31 dirp->__size = (size_t) bytes; \
35 /* Read a directory entry from DIRP. */
37 DEFUN(readdir, (dirp), DIR *dirp)
39 if (dirp == NULL || dirp->__data == NULL)
49 if (dirp->__offset >= dirp->__size)
51 /* We've emptied out our buffer. Refill it. */
53 /* Reset the offset into the buffer. */
57 dp = (struct direct *) &dirp->__data[dirp->__offset];
58 dirp->__offset += dp->d_reclen;
62 /* Not a deleted file. */
63 register struct dirent *d = &dirp->__entry;
64 d->d_fileno = (ino_t) dp->d_ino;
65 d->d_namlen = (size_t) dp->d_namlen;
66 if (d->d_namlen > NAME_MAX)
67 d->d_namlen = NAME_MAX;
68 (void) strncpy(d->d_name, dp->d_name, d->d_namlen + 1);