/*
 *	Network Queueing System (NQS)
 *  This version of NQS is Copyright (C) 1992  John Roman
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 1, or (at your option)
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
/*++ seekdir.c - 
 *
 * $Source: /usr2/jrroma/nqs/nqs-3.35.6/libndir/RCS/seekdir.c,v $
 *
 * DESCRIPTION:
 *
 *	Emulate the Berkeley 4.2 UNIX library call of:  seekdir (3x)
 *	On top of the System V fixed name length directory structure.
 *
 *
 *	Author:
 *	-------
 *	Kirk McKusick, University of California, Berkeley.
 *	March 10, 1982.
 *
 *	Modifications:
 *	--------------
 *	Brent A. Kingsbury, Sterling Software Incorporated.
 *	September 10, 1985.
 *
 *	  Changed "#include <dir.h>" to read "#include "dir.4.2.h"" since
 *	  we are after the Berkeley definition, and not System V.
 *
 *
 * STANDARDS VIOLATIONS:
 *
 * REVISION HISTORY: ($Revision: 1.4 $ $Date: 1994/03/30 20:34:11 $ $State: Exp $)
 * $Log: seekdir.c,v $
 * Revision 1.4  1994/03/30  20:34:11  jrroma
 * Version 3.35.6
 *
 * Revision 1.3  92/06/18  13:33:29  jrroma
 * Added gnu header
 * 
 * Revision 1.2  92/03/03  14:13:52  jrroma
 * Used Cosmic V2 version.
 * 
 * Revision 3.2  91/02/11  16:56:30  root
 * Version 2.0 Source
 * 
 * Revision 2.2  87/04/22  14:58:06  hender
 * Sterling version 4/22/87
 * 
 *
 */

#include <sys/types.h>
#if	SYS52| UTS
#include "dir.4.2.h"
#else
#if	BSD43
#include <sys/dir.h>
#else
BAD SYSTEM TYPE
#endif
#endif

/*** seekdir
 *
 *
 *	void seekdir():
 *
 *	Seek to an entry in a directory.
 *	Only values returned by telldir() should be passed to seekdir().
 */
void seekdir(dirp, loc)
register DIR *dirp;
long loc;
{
	long curloc, base, offset;
	struct direct *dp;
	extern long lseek();

	curloc = telldir(dirp);
	if (loc == curloc)
		return;
	base = loc & ~(DIRBLKSIZ - 1);
	offset = loc & (DIRBLKSIZ - 1);
	(void) lseek(dirp->dd_fd, base, 0);
	dirp->dd_loc = 0;
	while (dirp->dd_loc < offset) {
		dp = readdir(dirp);
		if (dp == NULL)
			return;
	}
}
