Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - fbseek() position the read/write pointer of a binary file http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 fbseek()            Position the read/write pointer of a binary file
------------------------------------------------------------------------------
 Declaration
   fileio.hdr

 Syntax
   func ulong fbseek extern
   param value _HFILE hFile, ;
         value long   gOffset, ;
         value int    iWhence

 Arguments
   hFile is the handle of the file to manipulate.
   gOffset is the number of bytes to move from the origin.
   iWhence is the origin of seek.

 Return
   The number of bytes from the origin to the end of the seek.

 Description
   The fbseek() function repositions the DOS read/write pointer for the
   file associated with hFile. The iWhence parameter defines the origin for
   gOffset. iWhence can refer to the beginning of the file, the current
   offset, or the end of the file.

   For example, if iWhence indicates beginning of file, then the offset is
   calculated relative to the beginning of file. The header file fileio.hdr
   contains definitions for the values of iWhence. Refer to the File seek
   table.

   The fbseek() function has no meaning when used with the DOS predefined
   file handles.

 Example
   #define EXAMPLE_FILE
   #include example.hdr

   func ulong FileLength
   param const char cFile
   // Determine size of file by seeking 0 bytes from the end of the file
   vardef
      _HFILE hFile
      ulong nLength
   enddef
   nLength := 0
   if fbopen( hFile, cFile, FB_READ )
      nLength := fbseek( hFile, 0, FB_END )
      fbclose( hFile )
   endif
   return( nLength )
   endfunc
   
   dbfdef sSample
      char( 4 ) f1
      date      f2
      uint( 3 ) f3
      logical   f4
   enddef
   
   proc Test_fbseek
   vardef
       char(4) cBuffer
       int     nValue
       uint    nRead
       _HFILE  hFile
       ulong   offset
       uint    uHeaderSize
   enddef
   build "sample.dbf" from alias sSample
   open "sample.dbf" alias sSample
   append blank
   sSample->f1 := "rock"
   sSample->f3 := 234
   uHeaderSize := header()
   close sSample          // database must be closed before using fbread()
   ? "size of database file is", istr( FileLength( "sample.dbf" ) ), "bytes"
   // read directly the contents of the char and the uint field
   if fbopen( hFile, "sample.dbf", FB_READ )
      fbseek( hFile, uHeaderSize + 1, FB_BEGIN ) // +1 is for the delete field
      cBuffer := ""
      nRead := fbread( hFile, cBuffer, 4 )
      ? "char field conatins: ", cBuffer
      // seek from the current position + 8 to get the uint field
      nRead := fbseek( hFile, 8, FB_CURRENT ) // skip the date field
      nRead := fbread( hFile, cBuffer, 3 )
      fbclose( hFile )
      nValue := ival( cBuffer )
      ? "uint field contains: ", istr( nValue )
   endif
   erase "sample.dbf"
   endproc

   proc main
   Test_fbseek()
   endproc

See Also: File seek table fbread() fbwrite()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson