]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/fread.3
err.3: EXAMPLES: use EXIT_FAILURE rather than 1 as exit status
[thirdparty/man-pages.git] / man3 / fread.3
CommitLineData
fea681da
MK
1.\" Copyright (c) 1990, 1991 The Regents of the University of California.
2.\" 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.\"
a9cd9cb7 8.\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
fea681da
MK
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in the
16.\" documentation and/or other materials provided with the distribution.
17.\" 3. All advertising materials mentioning features or use of this software
18.\" must display the following acknowledgement:
19.\" This product includes software developed by the University of
20.\" California, Berkeley and its contributors.
21.\" 4. Neither the name of the University nor the names of its contributors
22.\" may be used to endorse or promote products derived from this software
23.\" without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35.\" SUCH DAMAGE.
8c9302dc 36.\" %%%LICENSE_END
fea681da
MK
37.\"
38.\" @(#)fread.3 6.6 (Berkeley) 6/29/91
39.\"
40.\" Converted for Linux, Mon Nov 29 15:37:33 1993, faith@cs.unc.edu
41.\" Sun Feb 19 21:26:54 1995 by faith, return values
42.\" Modified Thu Apr 20 20:43:53 1995 by Jim Van Zandt <jrv@vanzandt.mv.com>
43.\" Modified Fri May 17 10:21:51 1996 by Martin Schulze <joey@infodrom.north.de>
44.\"
5722c835 45.TH FREAD 3 2015-07-23 "GNU" "Linux Programmer's Manual"
fea681da
MK
46.SH NAME
47fread, fwrite \- binary stream input/output
48.SH SYNOPSIS
b9f02710 49.nf
fea681da 50.B #include <stdio.h>
68e4db0a 51.PP
b9f02710
MK
52.BI "size_t fread(void *" ptr ", size_t " size ", size_t " nmemb \
53", FILE *" stream );
68e4db0a 54.PP
fea681da 55.BI "size_t fwrite(const void *" ptr ", size_t " size ", size_t " nmemb ,
b9f02710
MK
56.BI " FILE *" stream );
57.fi
fea681da
MK
58.SH DESCRIPTION
59The function
e511ffb6 60.BR fread ()
fea681da
MK
61reads
62.I nmemb
981fffea 63items of data, each
fea681da
MK
64.I size
65bytes long, from the stream pointed to by
66.IR stream ,
67storing them at the location given by
68.IR ptr .
69.PP
70The function
e511ffb6 71.BR fwrite ()
fea681da
MK
72writes
73.I nmemb
981fffea 74items of data, each
fea681da
MK
75.I size
76bytes long, to the stream pointed to by
77.IR stream ,
78obtaining them from the location given by
79.IR ptr .
80.PP
24b74457 81For nonlocking counterparts, see
fea681da 82.BR unlocked_stdio (3).
47297adb 83.SH RETURN VALUE
c294cd69 84On success,
e511ffb6 85.BR fread ()
fea681da 86and
e511ffb6 87.BR fwrite ()
981fffea 88return the number of items read or written.
c294cd69
RI
89This number equals the number of bytes transferred only when
90.I size
91is 1.
92If an error occurs, or the end of the file is reached,
93the return value is a short item count (or zero).
fea681da 94.PP
e511ffb6 95.BR fread ()
fea681da
MK
96does not distinguish between end-of-file and error, and callers must use
97.BR feof (3)
98and
99.BR ferror (3)
100to determine which occurred.
b7ab4b61
PH
101.SH ATTRIBUTES
102For an explanation of the terms used in this section, see
103.BR attributes (7).
104.TS
105allbox;
106lbw17 lb lb
107l l l.
108Interface Attribute Value
109T{
110.BR fread (),
111.BR fwrite ()
112T} Thread safety MT-Safe
113.TE
47297adb 114.SH CONFORMING TO
faa8ae8f 115POSIX.1-2001, POSIX.1-2008, C89.
47297adb 116.SH SEE ALSO
fea681da
MK
117.BR read (2),
118.BR write (2),
119.BR feof (3),
120.BR ferror (3),
121.BR unlocked_stdio (3)