- Fread
fread is a function that reads
buffered binary input from a file. It is included from thestdio.h header file in thestandard C library .:
size_t fread (void * restrict ptr, size_t size, size_t nmemb, FILE * restrict stream)
The
fread
function copiesnmemb
items of data of sizesize
from the named inputstream
into an array pointed to byptr
. An item of data is a sequence of bytes (not necessarily terminated by a null byte) of lengthsize
.fread
stops appending bytes whennmemb
items have been read,end of file has been reached, or an error has occurred. Upon returning,fread
sets the file pointer in the stream pointing to the byte past the last byte that has been read. The contents ofstream
remain unchanged. Thefread
function returns the number of items actually read. Ifnmemb
is zero, no action is taken and the function will return 0.Diagnostics
The function may fail with the following error codes:
*EAGAIN - Cannot read the input stream immediately without blocking the process, and the O_NONBLOCK flag is set for the file descriptor associated with stream.
*EBADF - Not a valid file descriptor open for reading.
*EINTR - The read operation was terminated by a signal before any data was read.
*EIO - Cannot read from the controlling terminal. This happens when the process is in a background process group and the attempt by the process to read from its controlling terminal fails, either because the process group is orphaned, or because the process is ignoring or blocking the SIGTTIN signal.
*ENOMEM - Insufficient storage space is available.
*ENXIO - Attempt to read from a non-existent device, or from a device whose capabilities are exceeded.References
*http://docsrv.sco.com:507/en/man/html.S/fread.S.html
Wikimedia Foundation. 2010.