|
|
1.1 root 1: #ifndef lint
2: static char sccsid[] = "@(#)readdir.c 4.5 (Berkeley) 7/1/83";
3: #endif
4:
5: #include <sys/param.h>
6: #include <sys/dir.h>
7:
8: /*
9: * get next entry in a directory.
10: */
11: struct direct *
12: readdir(dirp)
13: register DIR *dirp;
14: {
15: register struct direct *dp;
16:
17: for (;;) {
18: if (dirp->dd_loc == 0) {
19: dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf,
20: DIRBLKSIZ);
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: }
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;
33: if (dp->d_ino == 0)
34: continue;
35: return (dp);
36: }
37: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.