1.\" $OpenBSD: fread.3,v 1.4 2007/05/31 19:19:31 jmc Exp $ 2.\" 3.\" Copyright (c) 1990, 1991, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" This code is derived from software contributed to Berkeley by 7.\" Chris Torek and the American National Standards Committee X3, 8.\" on Information Processing Systems. 9.\" 10.\" Redistribution and use in source and binary forms, with or without 11.\" modification, are permitted provided that the following conditions 12.\" are met: 13.\" 1. Redistributions of source code must retain the above copyright 14.\" notice, this list of conditions and the following disclaimer. 15.\" 2. Redistributions in binary form must reproduce the above copyright 16.\" notice, this list of conditions and the following disclaimer in the 17.\" documentation and/or other materials provided with the distribution. 18.\" 3. Neither the name of the University nor the names of its contributors 19.\" may be used to endorse or promote products derived from this software 20.\" without specific prior written permission. 21.\" 22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32.\" SUCH DAMAGE. 33.\" 34.Dd $Mdocdate: May 31 2007 $ 35.Dt FREAD 3 36.Os 37.Sh NAME 38.Nm fread , 39.Nm fwrite 40.Nd binary stream input/output 41.Sh SYNOPSIS 42.Fd #include <stdio.h> 43.Ft size_t 44.Fn fread "void *ptr" "size_t size" "size_t nmemb" "FILE *stream" 45.Ft size_t 46.Fn fwrite "const void *ptr" "size_t size" "size_t nmemb" "FILE *stream" 47.Sh DESCRIPTION 48The function 49.Fn fread 50reads 51.Fa nmemb 52objects, each 53.Fa size 54bytes long, from the stream pointed to by 55.Fa stream , 56storing them at the location given by 57.Fa ptr . 58.Pp 59The function 60.Fn fwrite 61writes 62.Fa nmemb 63objects, each 64.Fa size 65bytes long, to the stream pointed to by 66.Fa stream , 67obtaining them from the location given by 68.Fa ptr . 69.Sh RETURN VALUES 70The functions 71.Fn fread 72and 73.Fn fwrite 74advance the file position indicator for the stream 75by the number of bytes read or written. 76They return the number of objects read or written. 77If an error occurs, or the end-of-file is reached, 78the return value is a short object count (or zero). 79.Pp 80The function 81.Fn fread 82does not distinguish between end-of-file and error, and callers 83must use 84.Xr feof 3 85and 86.Xr ferror 3 87to determine which occurred. 88The function 89.Fn fwrite 90returns a value less than 91.Fa nmemb 92only if a write error has occurred. 93.Sh SEE ALSO 94.Xr read 2 , 95.Xr write 2 96.Sh STANDARDS 97The functions 98.Fn fread 99and 100.Fn fwrite 101conform to 102.St -ansiC . 103