1*21355Sdist /* 2*21355Sdist * Copyright (c) 1983 Regents of the University of California. 3*21355Sdist * All rights reserved. The Berkeley software License Agreement 4*21355Sdist * specifies the terms and conditions for redistribution. 5*21355Sdist */ 6*21355Sdist 713582Ssam #ifndef lint 8*21355Sdist static char sccsid[] = "@(#)readdir.c 5.1 (Berkeley) 05/30/85"; 9*21355Sdist #endif not lint 105751Smckusick 116370Smckusic #include <sys/param.h> 1213582Ssam #include <sys/dir.h> 135751Smckusick 145751Smckusick /* 155751Smckusick * get next entry in a directory. 165751Smckusick */ 175751Smckusick struct direct * 185751Smckusick readdir(dirp) 195751Smckusick register DIR *dirp; 205751Smckusick { 216712Smckusick register struct direct *dp; 225751Smckusick 235751Smckusick for (;;) { 245751Smckusick if (dirp->dd_loc == 0) { 255756Smckusic dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf, 265872Smckusic DIRBLKSIZ); 275751Smckusick if (dirp->dd_size <= 0) 285751Smckusick return NULL; 295751Smckusick } 305751Smckusick if (dirp->dd_loc >= dirp->dd_size) { 315751Smckusick dirp->dd_loc = 0; 325751Smckusick continue; 335751Smckusick } 346712Smckusick dp = (struct direct *)(dirp->dd_buf + dirp->dd_loc); 356712Smckusick if (dp->d_reclen <= 0 || 366712Smckusick dp->d_reclen > DIRBLKSIZ + 1 - dirp->dd_loc) 376712Smckusick return NULL; 386712Smckusick dirp->dd_loc += dp->d_reclen; 395766Smckusic if (dp->d_ino == 0) 405766Smckusic continue; 416712Smckusick return (dp); 425751Smckusick } 435751Smckusick } 44