sys_fhreadbuf
Previous Topic  Next Topic 

Synopsis:

        sys_fhreadbuf(file_handle,buf_handle,num_bytes)

Arguments:

        file_handle       -   The file handle to read from

        buf_handle       - The buffer handle of the buffer to read the data into

        num_bytes        - The number of bytes to read.


Description:    This function attempts to read num_bytes bytes from the given file_handle into the given buffer.       The buf_handle is a handle to a 1Kbyte buffer returnedd from a call to sys_bufuse().     


The maximum number of bytes that can be read is 1024 (the maximum size of a buffer).


Return Value


Returns 0 the number of bytes actually read or a negative error code (as returned by the windows function GetLastError()).     If an invalid argument is given then the function will return -1.




For eample the following code copies the contents of one file to another by reading 1024 bytes at a time:



main

   int fh1,fh2,bytes;

   int bufh;


   fh1=sys_fhopen("source.txt","rs");

   fh2=sys_fhopen("dest.txt","rwsct");

   bufh=sys_bufuse();

  


   do

      bytes=sys_fhread(fh1,bufh,1024);

      if(bytes > 0)

           sys_fhwrite(fh2,bufh,1024);

      endif

   until(bytes < 1024);

endmain