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