SWRU455M February 2017 – October 2020 CC3120 , CC3120MOD , CC3130 , CC3135 , CC3135MOD , CC3220MOD , CC3220MODA , CC3220R , CC3220S , CC3220SF , CC3230S , CC3230SF , CC3235MODAS , CC3235MODASF , CC3235MODS , CC3235MODSF , CC3235S , CC3235SF
To read a file, the host requires the file handle, the offset to read, and the output buffer. A file can be read from random offsets.
The sl_FsRead returns the actual bytes read, or a negative value which represents an error.
Table 9-9 shows a partial list of errors that might be returned by the open-for-read function.
Error | Description |
---|---|
SL_ERROR_FS_OFFSET_OUT_OF_RANGE | The file system set the actual file size as a higher offset than was written. Trying to read a file from an offset which is higher than the actual file size results in an error. |
SL_ERROR_FS_NO_MEMORY | The read operation requires a system resource (RX-socket). The system may return that if there are not available resources (sockets) for the operation; in this case, the host can repeat the read operation after a while (or reduce the traffic overload while reading a file). |
Example:
_i32 FileHdl;
_i32 Status;
_u32 Offset = 0;
unsigned char pData[100];
_u32 Len = 0;
Status = sl_FsRead( FileHdl, Offset, pData, Len );
if( Status < 0 )
{
/*error */
/* abort */
Status = sl_FsClose(FileHdl,0,'A',1);
}