121358Sdist /* 221358Sdist * Copyright (c) 1983 Regents of the University of California. 321358Sdist * All rights reserved. The Berkeley software License Agreement 421358Sdist * specifies the terms and conditions for redistribution. 521358Sdist */ 621358Sdist 7*26583Sdonn #if defined(LIBC_SCCS) && !defined(lint) 8*26583Sdonn static char sccsid[] = "@(#)seekdir.c 5.2 (Berkeley) 03/09/86"; 9*26583Sdonn #endif LIBC_SCCS and not lint 105752Smckusick 116370Smckusic #include <sys/param.h> 1213582Ssam #include <sys/dir.h> 135752Smckusick 145752Smckusick /* 155928Smckusic * seek to an entry in a directory. 1611636Smckusick * Only values returned by "telldir" should be passed to seekdir. 175752Smckusick */ 185752Smckusick void 195928Smckusic seekdir(dirp, loc) 205928Smckusic register DIR *dirp; 215928Smckusic long loc; 225752Smckusick { 235947Smckusic long curloc, base, offset; 245947Smckusic struct direct *dp; 2511718Smckusick extern long lseek(); 265947Smckusic 275947Smckusic curloc = telldir(dirp); 285947Smckusic if (loc == curloc) 295947Smckusic return; 305947Smckusic base = loc & ~(DIRBLKSIZ - 1); 315947Smckusic offset = loc & (DIRBLKSIZ - 1); 3211718Smckusick (void) lseek(dirp->dd_fd, base, 0); 335947Smckusic dirp->dd_loc = 0; 345947Smckusic while (dirp->dd_loc < offset) { 355947Smckusic dp = readdir(dirp); 365947Smckusic if (dp == NULL) 375947Smckusic return; 385947Smckusic } 395752Smckusick } 40