1.2.7.4.21 SYS_FS_FileTruncate Function
C
SYS_FS_RESULT SYS_FS_FileTruncate ( SYS_FS_HANDLE handle );
Summary
Truncates a file
Description
This function truncates the file size to the current file read/write pointer. This function has no effect if the file read/write pointer is already pointing to end of the file.
Precondition
A valid file handle has to be passed as input to the function. The file has to be opened in a mode where writes to file is possible (such as read plus or write mode).
Parameters
Param | Description |
---|---|
handle | A valid handle which was obtained while opening the file. |
Returns
SYS_FS_RES_SUCCESS - File truncate operation was successful.
SYS_FS_RES_FAILURE - File truncate operation was unsuccessful. The reason for the failure can be retrieved with SYS_FS_Error or SYS_FS_FileError.
Example
SYS_FS_HANDLE fileHandle;
size_t nbytes;
size_t bytes_read;
SYS_FS_RESULT res;
fileHandle = SYS_FS_FileOpen("/mnt/myDrive/FILE.JPG", (SYS_FS_FILE_OPEN_READ));
if(fileHandle != SYS_FS_HANDLE_INVALID)
{
// File open is successful
}
// Read the file content
nbytes = sizeof(buf);
bytes_read = SYS_FS_FileRead(fileHandle, buf, nbytes);
// Truncate the file
res = SYS_FS_FileTruncate(fileHandle);
if(res != SYS_FS_RES_SUCCESS)
{
// Truncation failed.
}
SYS_FS_FileClose(fileHandle);
Remarks
None.