7.12 read Function

Read data from a file.

Attention: This interface function is not implemented by MPLAB XC8 C compilers.

Include

<unistd.h>

Prototype

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

Arguments

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

Return Value

This function should be implemented to 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 and errno is set to indicate the kind of error. Appropriate values may be EBADF or EINVAL, among others.

Remarks

This function is implemented as a stub that must be completed to suit the application.

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.

Source File

read.c