ack/lang/cem/libcc/gen/seekdir.c

35 lines
705 B
C
Raw Normal View History

1987-03-31 10:45:53 +00:00
/* $Header$ */
1987-01-27 15:57:55 +00:00
#include <sys/types.h>
#include <sys/dir.h>
/*
* seek to an entry in a directory.
* Only values returned by "telldir" should be passed to seekdir.
*/
seekdir(dirp, loc)
register DIR *dirp;
long loc;
{
long curloc, base, offset;
extern long telldir();
extern struct direct *readdir();
curloc = telldir(dirp);
if (loc == curloc)
return;
1987-02-24 13:10:59 +00:00
offset = loc % dirp->dd_bsize;
base = loc - offset;
if (dirp->dd_loc != -1 &&
1987-02-24 13:10:59 +00:00
(curloc - (curloc % dirp->dd_bsize)) == base) {
1987-01-27 15:57:55 +00:00
dirp->dd_loc = offset;
return;
}
(void) lseek(dirp->dd_fd, base, 0);
dirp->dd_loc = -1;
1987-01-27 15:57:55 +00:00
dirp->dd_size = 0;
1987-02-24 13:10:59 +00:00
while (dirp->dd_loc < offset) {
if (readdir(dirp) == (struct direct *) 0)
return;
1987-01-27 15:57:55 +00:00
}
}