<< Previous | Next >>

fread (FS2)

int fread( File * f, void * buf, int len );

Description

Read data from the "current position" of the given file. When the file is opened, the current position is 0, meaning the start of the file. Subsequent reads or writes advance the position by the number of bytes read or written. fseek() can also be used to position the read point.

If the application permits, it is much more efficient to read multiple data bytes rather than reading one-by-one.

Parameters

f
Pointer to file descriptor (initialized by fopen_rd(), fopen_wr() or fcreate()).

buf
Data buffer located in root data memory or stack. This must be dimensioned with at least len bytes.

len
Length of data to read (0 to 32767 inclusive).

Return value

 len: Success.

<len: Partial success. Returns amount successfully read. errno gives further details (probably 0 meaning that end-of-file was encountered).

 0: Failure, or len was zero.

Library

FS2.LIB

ERRNO values

EBADFD - File descriptor not opened.
EINVAL - len less than zero.
0 - Success, but len was zero or EOF was reached prior to reading len bytes.
EIO - I/O error.

See also

fseek (FS2), fwrite (FS2)


Dynamic C Functions << Previous | Next >> rabbit.com