Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

fopen, freopen, fdopen

getc, fgetc, getchar, getw, getwc, fgetwc, getwchar

gets, fgets, getws, fgetws

printf, fprintf, sprintf, NLprintf, NLfprintf, NLsprintf, wsprintf

putc, putchar, fputc, putw, putwc, putwchar, fputwc

puts, fputs, putws, fputws

read, readv, readx

scanf, fscanf, sscanf, NLscanf, NLfscanf, NLsscanf, wsscanf

stdio

write, writex



FREAD(3s,L)                 AIX Technical Reference                 FREAD(3s,L)



-------------------------------------------------------------------------------
fread, fwrite



PURPOSE

Performs binary input/output.

LIBRARY

Standard I/O Library (libc.a)

SYNTAX

#include <stdio.h>

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

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

DESCRIPTION

The fread subroutine copies nitems items of data from the input stream into an
array beginning at the location pointed to by the ptr parameter.  Each data
item has the type *ptr.

The fread subroutine stops copying bytes if an end-of-file or error condition
is encountered while reading from the input (1) specified by the stream
parameter or (2) when the number of data items specified by the nitems
parameter have been copied.  fread leaves the file pointer of stream, if
defined, pointing to the byte following the last byte read, if there is one.
The fread subroutine does not change the contents of stream.

The fwrite subroutine appends nitems items of data of the type *ptr from the
array pointed to by the ptr parameter to the output stream.

The fwrite subroutine stops writing bytes if (1) an error condition is
encountered on stream or (2) when the number of items of data specified by the
nitems parameter have been written.  The fwrite subroutine does not change the
contents of the array pointed to by the ptr parameter.

RETURN VALUE




Processed November 7, 1990        FREAD(3s,L)                                 1





FREAD(3s,L)                 AIX Technical Reference                 FREAD(3s,L)



The fread and fwrite subroutines return the number of items actually read or
written.  If the nitems parameter is negative or 0, no characters are read or
written, and a value of 0 is returned.

ERROR CONDITIONS

The fread subroutine fails if one or more of the following are true:

EAGAIN    The O_NONBLOCK flag is set for the file descriptor underlying stream
          and the process would be delayed in the fgetc operation.

EBADF     The file descriptor underlying stream is not a valid file descriptor
          open for reading.

EINTR     The read operation was terminated due to the receipt of a signal and
          no data was transferred.

EIO       The process is a member of a background process attempting to read
          from its controlling terminal, the process is either ignoring or
          blocking the SIGTTIN signal or the process group is orphaned.

ENOMEM    Insufficient storage space is available.

ENXIO     A request was made of a non-existent device, or the request was
          outside the capabilities of the device.

The fwrite subroutine fails if one or more of the following is true:

EAGAIN    The O_NONBLOCK flag is set for the file descriptor underlying stream
          and the process would be delayed in the write operation.

EBADF     The file descriptor underlying stream is not a valid file descriptor
          open for writing.

EFBIG     An attempt was made to write to a file that exceeds the process's
          file size limit or the maximum file size.

EINTR     The write operation was terminated due to the receipt of a signal and
          no data was transferred.

EIO       The process is a member of a background process group attempting to
          write to its controlling terminal, TOSTOP is set, the process is
          neither ignoring nor blocking SIGTTOU and the process group of the
          process is orphaned.

ENOSPC    There was no free space remaining on the device containing the file.

ENXIO     A request was made of a non-existent device, or the request was
          outside the capabilities of the device.






Processed November 7, 1990        FREAD(3s,L)                                 2





FREAD(3s,L)                 AIX Technical Reference                 FREAD(3s,L)



EPIPE     An attempt is made to write to a pipe or FIFO that is not open for
          reading by any process.  A SIGPIPE signal will also be sent to the
          process.

ENOMEM    Insufficient storage space is available.

RELATED INFORMATION

In this book:  "fopen, freopen, fdopen," "getc, fgetc, getchar, getw, getwc,
fgetwc, getwchar," "gets, fgets, getws, fgetws," "printf, fprintf, sprintf,
NLprintf, NLfprintf, NLsprintf, wsprintf," "putc, putchar, fputc, putw, putwc,
putwchar, fputwc," "puts, fputs, putws, fputws," "read, readv, readx," "scanf,
fscanf, sscanf, NLscanf, NLfscanf, NLsscanf, wsscanf," "stdio," and "write,
writex."









































Processed November 7, 1990        FREAD(3s,L)                                 3



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026