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