[ ]
Real time embedded FreeRTOS mailing list 
Homepage FreeRTOS Labs FreeRTOS+TCP FreeRTOS+FAT FreeRTOS+POSIX Contact / Enquiries


FreeRTOS+FAT is still in the lab
FreeRTOS+FAT is already in use in commercial products and we encourage you to try it yourself. Be aware however that FreeRTOS+FAT was acquired by Real Time Engineers Ltd., and is still being documented and updated to ensure it meets our strict quality standards. Please use the forum for support, or contact us directly if you have a specific business interest.

ff_truncate()

[FreeRTOS+FAT Standard API Reference]

ff_stdio.h
FF_FILE *ff_truncate( const char * pcFileName, long lTruncateSize );
		

Opens a file for writing, then truncates the file's length to lTruncateSize.

If the file was longer than lTruncateSize then the data past lTruncateSize is discarded.

If the file was shorter than lTruncateSize then new data added to the end of the file is set to 0.

Parameters:

pcFileName   A pointer to a standard null terminated C string that holds the name of the file being opened and truncated. The file name can include a relative path to the file.
lTruncateSize   The length, in byte, to which the file's length will be set.
Returns:

If the length of the file was successfully set to lTruncateSize then a pointer to the opened file is returned.

If the length of the file was not successfully set to lTruncateSize then NULL is returned, the file will remain closed, and the task's errno is set to indicate the reason. A task can obtain its errno value using the ff_errno() API function.

Example usage:


void vSampleFunction( char *pcFileName, long lLength )
{
FF_FILE *pxFile;

    /* Open and truncate the file specified by the pcFileName parameter. */
    pxFile = ff_truncate( pcFileName, lLength );

    if( pxFile == NULL )
    {
        /* The file could not be opened, or the file could not be truncated. */
    }
    else
    {
        /* The file was opened and the file length was set. */

        /*
         * The file can be accessed here.
         */

        /* Close the file when it is no longer required. */
        ff_fclose( pxFile );
    }
}
						
Example use of the ff_truncate() API function



[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ FreeRTOS Labs Sitemap ]    [ Main FreeRTOS Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.