summaryrefslogtreecommitdiff
path: root/dviware/umddvi/libcompat/seekdir.c
blob: dc29f48baa42faee4416d2dc09437de0a37fef0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
	seekdir -- C library extension routine

	last edit:	21-Jan-1984	D A Gwyn
*/

#include	<dir.h>

extern long	lseek();

#define NULL	0

void
seekdir( dirp, loc )
	register DIR	*dirp;		/* stream from opendir() */
	long		loc;		/* position from telldir() */
	{
	long		base;		/* file location of block */
	long		offset; 	/* offset within block */

	if ( telldir( dirp ) == loc )
		return; 		/* save time */

	offset = loc % DIRBLKSIZ;
	base = loc - offset;

	(void)lseek( dirp->dd_fd, base, 0 );	/* change blocks */
	dirp->dd_loc = dirp->dd_size = 0;

	while ( dirp->dd_loc < offset ) /* skip entries */
		if ( readdir( dirp ) == NULL )
			return; 	/* "can't happen" */
	}