read Function

Read data from a file.

Include

None

Prototype

int read(int handle, void *buffer, unsigned int len);

Arguments

handle handle referring to an opened file
buffer points to the storage location for read data
len the maximum number of characters to read

Return Value

Returns the number of characters read, which may be less than len if there are fewer than len characters left in the file or if the file was opened in text mode, in which case, each carriage return-linefeed (CR-LF) pair is replaced with a single linefeed character. Only the single linefeed character is counted in the return value. The replacement does not affect the file pointer. If the function tries to read at end-of-file, it returns ‘0’. If the handle is invalid, or the file is not open for reading or the file is locked, the function returns ‘-1’.

Remarks

This helper function is called by the Standard C Library functions fgetc(), fgets(), fread() and gets().

Default Behavior

As distributed, the parameters are passed to the host file system through the simulator. The return value is the value returned by the host file system.

File

read.c