1.\" Copyright (c) 1990, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" This code is derived from software contributed to Berkeley by 5.\" Chris Torek and the American National Standards Committee X3, 6.\" on Information Processing Systems. 7.\" 8.\" %sccs.include.redist.man% 9.\" 10.\" @(#)fread.3 8.2 (Berkeley) 03/08/94 11.\" 12.Dd 13.Dt FREAD 3 14.Os 15.Sh NAME 16.Nm fread , 17.Nm fwrite 18.Nd binary stream input/output 19.Sh SYNOPSIS 20.Fd #include <stdio.h> 21.Ft int 22.Fn fread "void *ptr" "size_t size" "size_t nmemb" "FILE *stream" 23.Ft int 24.Fn fwrite "const void *ptr" "size_t size" "size_t nmemb" "FILE *stream" 25.Sh DESCRIPTION 26The function 27.Fn fread 28reads 29.Fa nmemb 30objects, each 31.Xr size 32bytes long, from the stream pointed to by 33.Fa stream , 34storing them at the location given by 35.Fa ptr . 36.Pp 37The function 38.Fn fwrite 39writes 40.Fa nmemb 41objects, each 42.Fa size 43bytes long, to the stream pointed to by 44.Fa stream , 45obtaining them from the location given by 46.Fa ptr . 47.Sh RETURN VALUES 48The functions 49.Fn fread 50and 51.Fn fwrite 52advance the file position indicator for the stream 53by the number of bytes read or written. 54They return the number of objects read or written. 55If an error occurs, or the end-of-file is reached, 56the return value is a short object count (or zero). 57.Pp 58The function 59.Fn fread 60does not distinguish between end-of-file and error, and callers 61must use 62.Xr feof 3 63and 64.Xr ferror 3 65to determine which occurred. 66The function 67.Fn fwrite 68returns a value less than 69.Fa nmemb 70only if a write error has occurred. 71.Sh SEE ALSO 72.Xr read 2 , 73.Xr write 2 74.Sh STANDARDS 75The functions 76.Fn fread 77and 78.Fn fwrite 79conform to 80.St -ansiC . 81