secondary cache feature in vm.
[minix.git] / lib / libc / posix / _readdir.c
blob48b71604dab889c8e40a7c52dec3980bd7c12bff
1 /* readdir() Author: Kees J. Bot
2 * 24 Apr 1989
3 */
4 #define nil 0
5 #define readdir _readdir
6 #define getdents _getdents
7 #include <sys/types.h>
8 #include <dirent.h>
9 #include <unistd.h>
10 #include <stddef.h>
11 #include <stdlib.h>
12 #include <errno.h>
13 #include <string.h>
15 struct dirent *readdir(DIR *dp)
16 /* Return the next entry in a directory. */
18 struct dirent *entp;
19 int count, pos, reclen;
21 if (dp == nil) { errno= EBADF; return nil; }
23 count= dp->_count;
24 pos= dp->_pos;
25 if (count == 0 || pos >= count)
27 count= getdents(dp->_fd, (struct dirent *)dp->_buf,
28 sizeof(dp->_buf));
29 if (count <= 0) return nil;
30 dp->_count= count;
31 dp->_pos= pos= 0;
33 entp= (struct dirent *)&((char *)dp->_buf)[pos];
34 reclen= entp->d_reclen;
35 dp->_pos= pos+reclen;
37 return entp;
41 * $PchId: _readdir.c,v 1.6 2005/01/27 21:46:42 philip Exp $