1.2.7.4.21 SYS_FS_FileTruncate Function
1.2.7.4.21 C
SYS_FS_RESULT SYS_FS_FileTruncate
(
SYS_FS_HANDLE handle
);
1.2.7.4.21 Summary
Truncates a file.
1.2.7.4.21 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.
1.2.7.4.21 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.
1.2.7.4.21 Parameters
| Parameters | Description |
|---|---|
| handle | A valid handle which was obtained while opening the file |
1.2.7.4.21 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.
1.2.7.4.21 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);
1.2.7.4.21 Remarks
None.
