Commit | Line | Data |
---|---|---|
bb0cfa24 DF |
1 | /* |
2 | * Copyright (c) 1983 Regents of the University of California. | |
3 | * All rights reserved. The Berkeley software License Agreement | |
4 | * specifies the terms and conditions for redistribution. | |
5 | */ | |
6 | ||
455b164d | 7 | #ifndef lint |
bb0cfa24 DF |
8 | static char sccsid[] = "@(#)readdir.c 5.1 (Berkeley) %G%"; |
9 | #endif not lint | |
f20e5624 | 10 | |
c4a04593 | 11 | #include <sys/param.h> |
455b164d | 12 | #include <sys/dir.h> |
6a2babc1 | 13 | |
f20e5624 KM |
14 | /* |
15 | * get next entry in a directory. | |
16 | */ | |
17 | struct direct * | |
18 | readdir(dirp) | |
19 | register DIR *dirp; | |
20 | { | |
c9f0b4d5 | 21 | register struct direct *dp; |
f20e5624 KM |
22 | |
23 | for (;;) { | |
24 | if (dirp->dd_loc == 0) { | |
7d09c938 | 25 | dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf, |
4dad72b6 | 26 | DIRBLKSIZ); |
f20e5624 KM |
27 | if (dirp->dd_size <= 0) |
28 | return NULL; | |
29 | } | |
30 | if (dirp->dd_loc >= dirp->dd_size) { | |
31 | dirp->dd_loc = 0; | |
32 | continue; | |
33 | } | |
c9f0b4d5 KM |
34 | dp = (struct direct *)(dirp->dd_buf + dirp->dd_loc); |
35 | if (dp->d_reclen <= 0 || | |
36 | dp->d_reclen > DIRBLKSIZ + 1 - dirp->dd_loc) | |
37 | return NULL; | |
38 | dirp->dd_loc += dp->d_reclen; | |
d3d77310 KM |
39 | if (dp->d_ino == 0) |
40 | continue; | |
c9f0b4d5 | 41 | return (dp); |
f20e5624 KM |
42 | } |
43 | } |