4.3BSD beta release manual page
[unix-history] / usr / src / lib / libc / gen / readdir.c
CommitLineData
455b164d
SL
1#ifndef lint
2static char sccsid[] = "@(#)readdir.c 4.5 (Berkeley) %G%";
3#endif
f20e5624 4
c4a04593 5#include <sys/param.h>
455b164d 6#include <sys/dir.h>
6a2babc1 7
f20e5624
KM
8/*
9 * get next entry in a directory.
10 */
11struct direct *
12readdir(dirp)
13 register DIR *dirp;
14{
c9f0b4d5 15 register struct direct *dp;
f20e5624
KM
16
17 for (;;) {
18 if (dirp->dd_loc == 0) {
7d09c938 19 dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf,
4dad72b6 20 DIRBLKSIZ);
f20e5624
KM
21 if (dirp->dd_size <= 0)
22 return NULL;
23 }
24 if (dirp->dd_loc >= dirp->dd_size) {
25 dirp->dd_loc = 0;
26 continue;
27 }
c9f0b4d5
KM
28 dp = (struct direct *)(dirp->dd_buf + dirp->dd_loc);
29 if (dp->d_reclen <= 0 ||
30 dp->d_reclen > DIRBLKSIZ + 1 - dirp->dd_loc)
31 return NULL;
32 dirp->dd_loc += dp->d_reclen;
d3d77310
KM
33 if (dp->d_ino == 0)
34 continue;
c9f0b4d5 35 return (dp);
f20e5624
KM
36 }
37}