Commit | Line | Data |
---|---|---|
bb0cfa24 DF |
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 | ||
455b164d | 7 | #ifndef lint |
bb0cfa24 DF |
8 | static char sccsid[] = "@(#)seekdir.c 5.1 (Berkeley) %G%"; |
9 | #endif not lint | |
07063983 | 10 | |
c4a04593 | 11 | #include <sys/param.h> |
455b164d | 12 | #include <sys/dir.h> |
07063983 KM |
13 | |
14 | /* | |
67d6a82e | 15 | * seek to an entry in a directory. |
8b57b083 | 16 | * Only values returned by "telldir" should be passed to seekdir. |
07063983 KM |
17 | */ |
18 | void | |
67d6a82e KM |
19 | seekdir(dirp, loc) |
20 | register DIR *dirp; | |
21 | long loc; | |
07063983 | 22 | { |
0ba12054 KM |
23 | long curloc, base, offset; |
24 | struct direct *dp; | |
17b5e9d0 | 25 | extern long lseek(); |
0ba12054 KM |
26 | |
27 | curloc = telldir(dirp); | |
28 | if (loc == curloc) | |
29 | return; | |
30 | base = loc & ~(DIRBLKSIZ - 1); | |
31 | offset = loc & (DIRBLKSIZ - 1); | |
17b5e9d0 | 32 | (void) lseek(dirp->dd_fd, base, 0); |
0ba12054 KM |
33 | dirp->dd_loc = 0; |
34 | while (dirp->dd_loc < offset) { | |
35 | dp = readdir(dirp); | |
36 | if (dp == NULL) | |
37 | return; | |
38 | } | |
07063983 | 39 | } |