/* Seek to an entry previously returned by telldir. We rewind the directory and call readdir repeatedly until either dd_stat is the position number or -1 (off the end). This is not perfect, in that the directory may have changed while we weren't looking. But that is probably the case with any such system.  */
void _tseekdir(_TDIR *dirp, long lPos)
/* Seek to an entry previously returned by telldir. We rewind the directory and call readdir repeatedly until either dd_stat is the position number or -1 (off the end). This is not perfect, in that the directory may have changed while we weren't looking. But that is probably the case with any such system.  */
void _tseekdir(_TDIR *dirp, long lPos)
{
  errno = 0;
  if (!dirp)
    {
      errno = EFAULT;
      return;
    }
  if (lPos < -1)
    {
      errno = EINVAL;
      return;
    }
  else if (lPos == -1)
    {
      if (dirp->dd_handle != -1)
	{
	  _findclose (dirp->dd_handle);
	}
      dirp->dd_handle = -1;
      dirp->dd_stat = -1;
    }
  else
    {
      _trewinddir (dirp);
      while ((dirp->dd_stat < lPos) && _treaddir (dirp))
	;
    }
}