xref: /netbsd-src/lib/libc/stdio/fread.3 (revision 23c8222edbfb0f0932d88a8351d3a0cf817dfb9e)
1.\"	$NetBSD: fread.3,v 1.12 2003/08/07 16:43:25 agc 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.\"     @(#)fread.3	8.2 (Berkeley) 3/8/94
35.\"
36.Dd March 8, 1994
37.Dt FREAD 3
38.Os
39.Sh NAME
40.Nm fread ,
41.Nm fwrite
42.Nd binary stream input/output
43.Sh LIBRARY
44.Lb libc
45.Sh SYNOPSIS
46.In stdio.h
47.Ft size_t
48.Fn fread "void * restrict ptr" "size_t size" "size_t nmemb" "FILE * restrict stream"
49.Ft size_t
50.Fn fwrite "const void * restrict ptr" "size_t size" "size_t nmemb" "FILE * restrict stream"
51.Sh DESCRIPTION
52The function
53.Fn fread
54reads
55.Fa nmemb
56objects, each
57.Fa size
58bytes long, from the stream pointed to by
59.Fa stream ,
60storing them at the location given by
61.Fa ptr .
62.Pp
63The function
64.Fn fwrite
65writes
66.Fa nmemb
67objects, each
68.Fa size
69bytes long, to the stream pointed to by
70.Fa stream ,
71obtaining them from the location given by
72.Fa ptr .
73.Sh RETURN VALUES
74The functions
75.Fn fread
76and
77.Fn fwrite
78advance the file position indicator for the stream
79by the number of bytes read or written.
80They return the number of objects read or written.
81If
82.Fa size
83or
84.Fa nmemb
85is 0, the functions return 0 and the state of
86.Fa stream
87remains unchanged.
88If an error occurs, or the end-of-file is reached,
89the return value is a short object count (or zero).
90.Pp
91The function
92.Fn fread
93does not distinguish between end-of-file and error, and callers
94must use
95.Xr feof 3
96and
97.Xr ferror 3
98to determine which occurred.
99The function
100.Fn fwrite
101returns a value less than
102.Fa nmemb
103only if a write error has occurred.
104.Sh SEE ALSO
105.Xr read 2 ,
106.Xr write 2
107.Sh STANDARDS
108The functions
109.Fn fread
110and
111.Fn fwrite
112conform to
113.St -ansiC .
114