Quality RTOS & Embedded Software


ff_truncate() [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. 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 stdioGET_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. */
/* 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
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.