You are currently viewing the documentation for:
ECF_SetFileSize allows you to extend or truncate an open file.
ECF_ErrorCode ECF_SetFileSize(
   struct ECF_FileHandle *pFileHandle,
   uint32_t newFileSize
A pointer to an open file handle.
The desired file size.
Return value
Returns one of the EcFAT error codes (ECFERR_SUCCESS on success)
Use ECF_SetFileSize to extend a file if you know that you will write a lot of data to it. Otherwise the file size will grow with each call to ECF_WriteFile which will update the FAT table and directory structure on each write. Note: If you extend a file using ECF_SetFileSize, the content of the extended part will be be undefined. If you wish to extend it and zero it, you will need to fall ECF_WriteFile with a zeroed buffer instead. The reason for this is that the main purpose of extending a file and then using ECF_WriteFile is for speed. If ECF_SetFileSize had zeroed the file, that would have been slower than just writing it using ECF_WriteFile. You can also use ECF_SetFileSize to truncate a file if you have written to much data in the end. Your file cursor will not be affected unless you the file cursor is pointing to a part that you are truncating. If so, the file cursor will point to the end of the file and the end of the operation.
See also