1.2.7.4.20 SYS_FS_FileSync Function
C
SYS_FS_RESULT SYS_FS_FileSync ( SYS_FS_HANDLE handle );
Summary
Flushes the cached information when writing to a file.
Description
This function flushes the cached information when writing to a file. The SYS_FS_FileSync function performs the same process as SYS_FS_FileClose function; however, the file is left open and can continue read/write/seek operations to the file.
Precondition
A valid file handle has to be passed as input to the function. The file which has to be flushed, has to be present and should have been opened in write mode.
Parameters
Param | Description |
---|---|
handle | valid file handle |
Returns
SYS_FS_RES_SUCCESS - File sync operation was successful.
SYS_FS_RES_FAILURE - File sync operation was unsuccessful. The reason for the failure can be retrieved with SYS_FS_Error or SYS_FS_FileError.
Example
SYS_FS_RESULT res; SYS_FS_HANDLE fileHandle; const char *buf = "Hello World"; size_t nbytes; size_t bytes_written; fileHandle = SYS_FS_FileOpen("/mnt/myDrive/FILE.txt", (SYS_FS_FILE_OPEN_WRITE)); if(fileHandle != SYS_FS_HANDLE_INVALID) { // File open is successful } // Write data to the file bytes_written = SYS_FS_FileWrite(fileHandle, (const void *)buf, nbytes); // Flush the file res = SYS_FS_FileSync(fileHandle); if( res != SYS_FS_RES_SUCCESS) { // Sync failed }
Remarks
None.