1*48660Sbostic static char sccsid[] = "@(#)seekdir.c 4.6 9/12/82"; 2*48660Sbostic 3*48660Sbostic #include <sys/param.h> 4*48660Sbostic #include <ndir.h> 5*48660Sbostic 6*48660Sbostic /* 7*48660Sbostic * seek to an entry in a directory. 8*48660Sbostic * Only values returned by "telldir" should be passed to seekdir. 9*48660Sbostic */ 10*48660Sbostic void seekdir(dirp,loc)11*48660Sbosticseekdir(dirp, loc) 12*48660Sbostic register DIR *dirp; 13*48660Sbostic long loc; 14*48660Sbostic { 15*48660Sbostic long base, offset; 16*48660Sbostic struct direct *dp; 17*48660Sbostic 18*48660Sbostic /* rti!trt: Always seek. Slower, but safer. This may even fix a bug. 19*48660Sbostic if (loc == telldir(dirp)) 20*48660Sbostic return; 21*48660Sbostic */ 22*48660Sbostic base = loc & ~(DIRBLKSIZ - 1); 23*48660Sbostic offset = loc & (DIRBLKSIZ - 1); 24*48660Sbostic lseek(dirp->dd_fd, base, 0); 25*48660Sbostic dirp->dd_loc = 0; 26*48660Sbostic while (dirp->dd_loc < offset) { 27*48660Sbostic dp = readdir(dirp); 28*48660Sbostic if (dp == NULL) 29*48660Sbostic return; 30*48660Sbostic } 31*48660Sbostic } 32