xref: /original-bsd/lib/libc/stdio/fread.3 (revision d852a0c9)
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.\"
8.\" %sccs.include.redist.man%
9.\"
10.\"     @(#)fread.3	6.7 (Berkeley) 08/16/91
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 "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.
66.Sh SEE ALSO
67.Xr read 2 ,
68.Xr write 2
69.Sh STANDARDS
70The functions
71.Fn fread
72and
73.Fn fwrite
74conform to
75.St -ansiC .
76