Declaration:
int read(long handle, void buf[], int len);
Description
Reads from file.
read attempts to read len bytes from the file associated with handle into the buffer pointed to by buf. For a file opened in text mode, then read removes the carriage returns and reports the end-of-file, when it reaches Ctrl-Z. The handle file handle is obtained from the creat, open, dup, or dup2 call. On disk files, read begins reading at the current file pointer. When the reading is complete, it increments the file pointer by the number of bytes read. On devices, the bytes are read directly from the device.
Returned Value
On successful completion, read returns an integer indicating the number of bytes placed in the buffer. If the file is opened in the text mode, then read does not count the carriage returns or Ctrl-Z characters in the number of bytes read. On the end-of-file, read returns 0. On error, read returns -1 and sets the errno global variable to one of the following two values:
EACCES Permission denied
EBADF Bad file number
|