1.2.7.4.8 SYS_FS_FileRead Function
C
size_t SYS_FS_FileRead ( SYS_FS_HANDLE handle, void *buf, size_t nbyte );
Summary
Read data from the file.
Description
This function attempts to read nbyte bytes of data from the file associated with the file handle into the buffer pointed to by buf.
Precondition
A valid file handle must be obtained before reading a file.
Parameters
Param | Description |
---|---|
handle | File handle obtained during file open. |
buf | Pointer to buffer into which data is read. |
nbyte | Number of bytes to be read |
Returns
On success - returns the number of bytes read 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.
Example
... char CACHE_ALIGN buf[256]; size_t nbytes; size_t bytes_read; SYS_FS_HANDLE fileHandle; fileHandle = SYS_FS_FileOpen("/mnt/myDrive/FILE.txt", (SYS_FS_FILE_OPEN_READ)); if(fileHandle != SYS_FS_HANDLE_INVALID) { // File open is successful } nbytes = sizeof(buf); bytes_read = SYS_FS_FileRead(fileHandle, buf, nbytes);
Remarks
None.