[FreeRTOS+FAT Standard API Reference]
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.
|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.|
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.
void vSampleFunction( char *pcFileName, long lLength )
/* 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. */
/* 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