f_filelength


Use this function to get the length of a file.

Format

long f_filelength ( const char * filename )

Arguments

Argument Description Type
filename The name of the file, with or without the path. char *

Return Values

Return value Description
filelength The number of bytes in the file.
F_INVALID There is an error in the file.
F_ERR_INVALID The file does not exist or the volume is not working.

Example

int myreadfunc( char *filename, char *buffer, unsigned long buffsize )
{
    F_FILE *file = f_open( filename, "r" );
    unsigned long size = f_filelength( filename );
    if (!file)
    {
        printf( "%s cannot be opened!", filename );
        return 1;
    }
    if (size > buffsize)
    {
        printf( "Not enough memory!" );
        return 2;
    }
    f_read( buffer, size, 1, file );
    f_close( file );
    return 0;
}