bfsSeek()

PROTOTYPE

#include <bfs.h>

ui32 bfsSeek(long offset, int whence);

DESCRIPTION

bfsSeek() sets the file position indicator for the currently open file. The file must be open in read mode. The requested position is offset number of bytes from the position determined by whence, which must be one of the following:

  • BFS_SEEK_SET - set offset to offset bytes from the beginning of the file.
  • BFS_SEEK_CUR - set offset to its current value plus offset bytes.

bfsSeek() may not be used to move the file position indicator past the end of existing data.

If successful, bfsSeek() returns the new file position. Otherwise, it sets errno and returns (ui32) -1.

ERROR CODES

EACCES Seeking past end or file not open in read mode.
EINVAL whence is invalid.
other An I/O error occurred while reading a flash page.

EXAMPLE

/*-----------------------------------------------------------------*/
/* Implement binary search algorithm.                              */
/*-----------------------------------------------------------------*/
low = 0; high = NumRecords - 1;
for (;;)
{
  /*---------------------------------------------------------------*/
  /* Seek to half-way point.                                       */
  /*---------------------------------------------------------------*/
  pos = (low + high) / 2;
  if (bfsSeek(pos * sizeof(Record), BFS_SEEK_SET) == (ui32)-1)
    error("bfsSeek() failed");
  ++num_seeks;