date and time created 83/07/01 16:14:31 by root
[unix-history] / usr / src / lib / libc / gen / readdir.c
CommitLineData
f20e5624
KM
1/* Copyright (c) 1982 Regents of the University of California */
2
c9f0b4d5 3static char sccsid[] = "@(#)readdir.c 4.4 %G%";
f20e5624 4
c4a04593 5#include <sys/param.h>
c9f0b4d5 6#include <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}