1.2.7.4.19 SYS_FS_FileWrite Function

1.2.7.4.19 C

size_t SYS_FS_FileWrite
(
    SYS_FS_HANDLE handle,
    const void *buf,
    size_t nbyte
);

1.2.7.4.19 Summary

Writes data to the file.

1.2.7.4.19 Description

This function attempts to write nbyte bytes from the buffer pointed to by buf to the file associated with the file handle.

1.2.7.4.19 Precondition

A valid file handle must be obtained before writing a file.

1.2.7.4.19 Parameters

ParametersDescription
handleFile handle obtained during file open
bufPointer to buffer from which data is to be written
nbyteNumber of bytes to be written

1.2.7.4.19 Returns

On success - Returns the number of bytes written successfully (0 or positive number).

On failure - Returns -1. The reason for the failure can be retrieved with SYS_FS_Error or SYS_FS_FileError.

1.2.7.4.19 Example

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);

1.2.7.4.19 Remarks

None.