f_read


Use this function to read bytes from the current file position. The current file pointer is increased by the number of bytes read.  The file must be opened in “r”, "r+", "w+" or "a+" mode.

Format

long f_read (
    void *     bbuf,
    long       size,
    long       size_st,
    F_FILE *   filehandle )

Arguments

Argument
Description
Type
bbuf A pointer to the buffer to store data in. void *
size The size of the items to read. long
size_st The number of items to read. long
filehandle The handle of the file. F_FILE *

Return values

Return value
Description
number The number of items read successfully.
-1 Error.

Example

int myreadfunc( char *filename, char *buffer, long buffsize )
{
    F_FILE *file = f_open( filename, "r" );
    long size = f_filelength( filename );
    if (!file)
    {
        printf( "%s cannot be opened!", filename );
        return 1;
    }
    if (f_read( buffer, 1, size, file) != size )
    {
        printf( "Fewer bytes read than requested!" );
    }
    f_close( file );
    return 0;
}