|
|
1.1 root 1: /*
2: readdir -- read next entry from a directory stream
3:
4: last edit: 25-Apr-1987 D A Gwyn
5: */
6:
7: #include <sys/errno.h>
8: #include <sys/types.h>
9: #include "usr.dirent.h"
10:
11: #ifndef GETDENTS
12: extern int getdents(); /* SVR3 system call, or emulation */
13:
14: extern int errno;
15:
16: #ifndef NULL
17: #define NULL 0
18: #endif
19:
20: struct dirent *
21: readdir( dirp )
22: register DIR *dirp; /* stream from opendir() */
23: {
24: register struct dirent *dp; /* -> directory data */
25:
26: if ( dirp == NULL || dirp->dd_buf == NULL )
27: {
28: errno = EFAULT;
29: return NULL; /* invalid pointer */
30: }
31:
32: do {
33: if ( dirp->dd_loc >= dirp->dd_size ) /* empty or obsolete */
34: dirp->dd_loc = dirp->dd_size = 0;
35:
36: if ( dirp->dd_size == 0 /* need to refill buffer */
37: && (dirp->dd_size =
38: getdents( dirp->dd_fd, dirp->dd_buf, (unsigned)DIRBUF )
39: ) <= 0
40: )
41: return NULL; /* EOF or error */
42:
43: dp = (struct dirent *)&dirp->dd_buf[dirp->dd_loc];
44: dirp->dd_loc += dp->d_reclen;
45: }
46: while ( dp->d_ino == 0L ); /* don't rely on getdents() */
47:
48: return dp;
49: }
50: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.