fread(3)

fread3

Binary stream input/output

Usage

#include <stdio.h>

size_t

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

size_t

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

Library

Standard C Library (libc, -lc)

Overview

The function fread() reads nitems objects, each size bytes long, from the stream pointed to by stream, storing them at the location given by ptr.

The function fwrite() writes nitems objects, each size bytes long, to the stream pointed to by stream, obtaining them from the location given by ptr.

Return values

The functions fread() and fwrite() advance the file position indicator for the stream by the number of bytes read or written. They return the number of objects read or written. If an error occurs, or the end-of-file is reached, the return value is a short object count (or zero).

The function fread() does not distinguish between end-of-file and error; callers must use feof(3) and ferror(3) to determine which occurred. The function fwrite() returns a value less than nitems only if a write error has occurred.

Releases

163 releases since Mac OS X 10.0; the text changed 4 times.

  1. 10.0–10.1.5
  2. 10.2–10.2.8
  3. 10.3–10.4.11
  4. 10.5–10.6.8
  5. 10.7–26.5

Standards

The functions fread() and fwrite() conform to ISO/IEC 9899:1990 (“ISO C90”).

From Libc 1752.120.2 in macOS 26.5. Parsed by carta from the page's mdoc source.