1 /* Copyright (c) 1982 Regents of the University of California */ 2 3 static char sccsid[] = "@(#)readdir.c 1.2 02/11/82"; 4 5 #include <sys/types.h> 6 #include <ndir.h> 7 8 /* 9 * get next entry in a directory. 10 */ 11 struct direct * 12 readdir(dirp) 13 register DIR *dirp; 14 { 15 struct direct *dp; 16 17 for (;;) { 18 if (dirp->dd_loc == 0) { 19 dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf, 20 MAXDIRSIZ); 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 dirp->dd_loc += sizeof(struct direct); 30 if (dp->d_ino != 0) 31 return dp; 32 } 33 } 34