fread()

read from stream 

Function


SYNOPSIS

#include <stdio.h>

size_t fread(void *ptr, size_t size, size_t nitems, FILE *stream);


DESCRIPTION

The fread() function reads, into an array pointed to by ptr up to nitems members whose size is specified by size in bytes, from the stream pointed to by stream. The file position indicator for the stream (if defined) is advanced by the number of bytes successfully read. If an error occurs, the resulting value of the file position indicator for the stream is indeterminate. If a partial member is read, its value is indeterminate. A null byte does not necessarily terminate the sequence.

The fread() function may mark the st_atime field of the file associated with stream for update. The st_atime field is marked for update by the first successful execution of fgetc(), fgets(), fgetwc(), fgetws(), fread(), fscanf(), getc(), getchar(), gets(), or scanf() using stream that returns data not supplied by a prior call to ungetc() or ungetwc().


PARAMETERS

ptr 

Points to the buffer where the data read is be held.

size 

Is the size of one of the elements to be read.

nitems 

Is the number of elements to be read.

stream 

Points to the input stream.


RETURN VALUES

Upon successful completion, fread() returns the number of members successfully read which is less than nitems only if a read error or end-of-file is encountered. If size or nitems is 0, fread() returns 0 and the contents of the array and the state of the stream remain unchanged. Otherwise, if a read error occurs, the error indicator for the stream is set, fread() returns EOF and sets errno to one of the following values:

EACCES 

Another process has the file locked.

EAGAIN 

The underlying file descriptor is in non-blocking mode, and the process would be delayed waiting for data to become available.

EBADF 

stream is not a valid stream opened for reading.

EINTR 

A signal interrupted the call.

EIO 

An input error occurred.

EISDIR 

The open object is a directory, not a file.

ENOMEM 

Memory could not be allocated for internal buffers.

ENXIO 

A device error occurred.

EOVERFLOW 

The file is a regular file and an attempt was made to read at or beyond the offset maximum associated with the corresponding stream.

EWOULDBLOCK 

The underlying file descriptor is a non-blocking socket and no data is ready to be read.


CONFORMANCE

ANSI/ISO 9899-1990.


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

If the stream is from a file opened in text mode, the line-terminating character sequence of carriage return plus linefeed is translated to linefeed. No such translation occurs for files opened in binary mode.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
abort(), exit(), fclose(), fopen(), fwrite(), getc(), gets(), lseek(), printf(), putc(), puts(), read(), scanf(), write()


PTC MKS Toolkit 10.4 Documentation Build 39.