1 /* Copyright (c) 1982 Regents of the University of California */ 2 3 static char sccsid[] = "@(#)seekdir.c 4.9 03/25/83"; 4 5 #include <sys/param.h> 6 #include <dir.h> 7 8 /* 9 * seek to an entry in a directory. 10 * Only values returned by "telldir" should be passed to seekdir. 11 */ 12 void 13 seekdir(dirp, loc) 14 register DIR *dirp; 15 long loc; 16 { 17 long curloc, base, offset; 18 struct direct *dp; 19 extern long lseek(); 20 21 curloc = telldir(dirp); 22 if (loc == curloc) 23 return; 24 base = loc & ~(DIRBLKSIZ - 1); 25 offset = loc & (DIRBLKSIZ - 1); 26 (void) lseek(dirp->dd_fd, base, 0); 27 dirp->dd_loc = 0; 28 while (dirp->dd_loc < offset) { 29 dp = readdir(dirp); 30 if (dp == NULL) 31 return; 32 } 33 } 34