1 /* 2 * Copyright (c) 1983 Regents of the University of California. 3 * All rights reserved. The Berkeley software License Agreement 4 * specifies the terms and conditions for redistribution. 5 */ 6 7 #if defined(LIBC_SCCS) && !defined(lint) 8 static char sccsid[] = "@(#)seekdir.c 5.2 (Berkeley) 03/09/86"; 9 #endif LIBC_SCCS and not lint 10 11 #include <sys/param.h> 12 #include <sys/dir.h> 13 14 /* 15 * seek to an entry in a directory. 16 * Only values returned by "telldir" should be passed to seekdir. 17 */ 18 void 19 seekdir(dirp, loc) 20 register DIR *dirp; 21 long loc; 22 { 23 long curloc, base, offset; 24 struct direct *dp; 25 extern long lseek(); 26 27 curloc = telldir(dirp); 28 if (loc == curloc) 29 return; 30 base = loc & ~(DIRBLKSIZ - 1); 31 offset = loc & (DIRBLKSIZ - 1); 32 (void) lseek(dirp->dd_fd, base, 0); 33 dirp->dd_loc = 0; 34 while (dirp->dd_loc < offset) { 35 dp = readdir(dirp); 36 if (dp == NULL) 37 return; 38 } 39 } 40