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 - fbopen() open a binary file http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 fbopen()            Open a binary file
------------------------------------------------------------------------------
 Declaration
   fileio.hdr

 Syntax
   func logical fbopen extern
   param       _HFILE hFile, ;
         const char   cFileName, ;
         value int    iMode

 Arguments
   hFile receives the handle of the file.
   cFileName is the name of the file to open.
   iMode is the open mode.

 Return
   A logical indicating if the file has been successfully opened.

 Description
   The fbopen() function opens any type of file - ASCII, text, binary - for
   read, write or append, depending upon iMode. If the file cFileName could
   not be opened, fbopen() returns .F.

   If the file could be opened, fbopen() initializes the parameter hFile.
   The value in hFile must be used on all subsequent accesses to the file.

   The parameter iMode specifies how the file is to be treated. See the
   Binary file open table.

 Example
   #define EXAMPLE_FILE
   #include example.hdr

   func logical FieldList
   param const char filename
   // Print the field name and type from header.
   vardef
      _HFILE  hFile
      byte    aBuffer[32]
      char    cField based aBuffer
      logical lSuccess
   enddef
   lSuccess := .f.
   if fbopen( hFile, filename, FB_READ )
      fbread( hFile, aBuffer[], 32 )       // read 1st 32 bytes
      do while .not. fbeof( hFile )
         fbread( hFile, aBuffer[], 32 )
         if aBuffer[0] == 0xd              // 0D marks the end
            lSuccess := .t.
            exit
         endif
         ? cField, chr( aBuffer[11] )
      enddo
      fbclose( hFile )
   endif
   return( lSuccess )
   endproc
   
   func logical FileCopy
   param const char cSource, const char cDest
   // File copy function
   vardef
      _HFILE  hSrc, hDest
      byte    aBuffer[4096]                // 4096 bytes copy buffer
      uint    nBytes
      logical lSuccess
   enddef
   lSuccess := .f.
   if fbopen( hSrc, cSource, FB_READ )
      if fbopen( hDest, cDest, FB_CWRITE )
         repeat
            nBytes := fbread( hSrc, aBuffer[], 4096 )
            fbwrite( hDest, aBuffer[], nBytes )
         until .t.
         fbclose( hSrc )
         lSuccess := .t.
      endif
      fbclose( hDest )
   endif
   return( lSuccess )
   endproc
   
   dbfdef sTemp
      char( 10 ) name
      uint(  2 ) age
   enddef
   
   proc Test_fbopen
   build "stemp.dbf" from alias sTemp     // create database
   FieldList( "stemp.dbf" )               // display fields
   if FileCopy( "stemp.dbf", "copy.dbf" ) // copy file
      ? "Database copied"
      erase "copy.dbf"
   endif
   erase "stemp.dbf"
   endproc
   

   proc main
   Test_fbopen()
   endproc

See Also: Binary file open table fbclose() fbreopen()

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