Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ fread(3S) — bsd — Apollo Domain/OS SR10.4.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

cc(1)

read(2)

write(2)

fopen(3S)

getc(3S)

putc(3S)

gets(3S)

puts(3S)

printf(3S)

scanf(3S)

FREAD(3S)                            BSD                             FREAD(3S)



NAME
     fread, fwrite - buffered binary input/output

SYNOPSIS
     #include <stdio.h>

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

     size_t fwrite(ptr, size, nmemb, stream)
     const void *ptr;
     size_t size;
     size_t nmemb;
     FILE *stream;

DESCRIPTION
     The fread function reads, into the array pointed to by ptr, up to nmemb
     elements whose size is specified by size, from the stream pointed to by
     stream.  The file position indicator for the stream (if defined) is
     advanced by the number of characters successfully read.  If an error
     occurs, the resulting value of the file position indicator for the stream
     is indeterminate.  If a partial element is read, its value is
     indeterminate.

     If stream is stdin or is unbuffered or line-buffered, then all active
     line-buffered output streams are flushed before any call to read(2) to
     satisfy the fread.

     fread returns the number of elements successfully read, which may be less
     than nmemb if a read error or EOF is encountered.  If size or nmemb is
     zero, fread returns zero and the contents of the array and the state of
     the stream remain unchanged.

     The fwrite function writes, from the array pointed to by ptr, up to nmemb
     elements whose size is specified by size, to the stream pointed to by
     stream.  The file position indicator for the stream (if defined) is
     advanced by the number of characters successfully written.  If an error
     occurs, the resulting value of the file position indicator for the stream
     is indeterminate.

     fwrite returns the number of items actually written, which will be less
     than nmemb only if a write error is encountered.

NOTES
     If the fwrite call indicates that less data was written than had been
     requested, an underlying error has ocrurred and [ERRNO] will be set.

     To be compatible with common C usage, make fread and fwrite return an int
     by compiling your program with the

          -A nansi

     option and inserting the directive

          #define _CLASSIC_TYPES

     before any

          #include

     directives.  See cc(1).

SEE ALSO
     cc(1), read(2), write(2), fopen(3S), getc(3S), putc(3S), gets(3S),
     puts(3S), printf(3S), scanf(3S)

DIAGNOSTICS
     fread and fwrite return 0 upon end-of-file or error.

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