f_ftruncate


Use this function to truncate a file that is open for writing to a specified length.

A file can only be truncated to a size less than or equal to its current size.

Format

int f_ftruncate (
    F_FILE *        filehandle,
    unsigned long   length )

Arguments

Argument Description Type
filehandle The file handle.  F_FILE *
length The new length of the file. unsigned long

Return values

Return value Description
F_NOERR Successful execution.
Else See Error Codes.

Example

int mytruncatefunc( F_FILE *file, unsigned long length )
{
    int ret = f_ftruncate( filename, length );

    if (ret)
    {
        printf( "Error:%d\n", ret );
    }
    else
    {
        printf( "File is truncated to %d bytes", length );
    }

    return ret;
}