xref: /minix3/lib/libc/stdio/fread.3 (revision f14fb602092e015ff630df58e17c2a9cd57d29b3)
1*f14fb602SLionel Sambuc.\"	$NetBSD: fread.3,v 1.15 2011/09/11 04:55:48 jruoho Exp $
22fe8fb19SBen Gras.\"
32fe8fb19SBen Gras.\" Copyright (c) 1990, 1991, 1993
42fe8fb19SBen Gras.\"	The Regents of the University of California.  All rights reserved.
52fe8fb19SBen Gras.\"
62fe8fb19SBen Gras.\" This code is derived from software contributed to Berkeley by
72fe8fb19SBen Gras.\" Chris Torek and the American National Standards Committee X3,
82fe8fb19SBen Gras.\" on Information Processing Systems.
92fe8fb19SBen Gras.\"
102fe8fb19SBen Gras.\" Redistribution and use in source and binary forms, with or without
112fe8fb19SBen Gras.\" modification, are permitted provided that the following conditions
122fe8fb19SBen Gras.\" are met:
132fe8fb19SBen Gras.\" 1. Redistributions of source code must retain the above copyright
142fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer.
152fe8fb19SBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright
162fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer in the
172fe8fb19SBen Gras.\"    documentation and/or other materials provided with the distribution.
182fe8fb19SBen Gras.\" 3. Neither the name of the University nor the names of its contributors
192fe8fb19SBen Gras.\"    may be used to endorse or promote products derived from this software
202fe8fb19SBen Gras.\"    without specific prior written permission.
212fe8fb19SBen Gras.\"
222fe8fb19SBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
232fe8fb19SBen Gras.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
242fe8fb19SBen Gras.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
252fe8fb19SBen Gras.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
262fe8fb19SBen Gras.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
272fe8fb19SBen Gras.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
282fe8fb19SBen Gras.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
292fe8fb19SBen Gras.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
302fe8fb19SBen Gras.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
312fe8fb19SBen Gras.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
322fe8fb19SBen Gras.\" SUCH DAMAGE.
332fe8fb19SBen Gras.\"
342fe8fb19SBen Gras.\"     @(#)fread.3	8.2 (Berkeley) 3/8/94
352fe8fb19SBen Gras.\"
36*f14fb602SLionel Sambuc.Dd September 11, 2011
372fe8fb19SBen Gras.Dt FREAD 3
382fe8fb19SBen Gras.Os
392fe8fb19SBen Gras.Sh NAME
402fe8fb19SBen Gras.Nm fread ,
412fe8fb19SBen Gras.Nm fwrite
422fe8fb19SBen Gras.Nd binary stream input/output
432fe8fb19SBen Gras.Sh LIBRARY
442fe8fb19SBen Gras.Lb libc
452fe8fb19SBen Gras.Sh SYNOPSIS
462fe8fb19SBen Gras.In stdio.h
472fe8fb19SBen Gras.Ft size_t
482fe8fb19SBen Gras.Fn fread "void * restrict ptr" "size_t size" "size_t nmemb" "FILE * restrict stream"
492fe8fb19SBen Gras.Ft size_t
502fe8fb19SBen Gras.Fn fwrite "const void * restrict ptr" "size_t size" "size_t nmemb" "FILE * restrict stream"
512fe8fb19SBen Gras.Sh DESCRIPTION
522fe8fb19SBen GrasThe function
532fe8fb19SBen Gras.Fn fread
542fe8fb19SBen Grasreads
552fe8fb19SBen Gras.Fa nmemb
562fe8fb19SBen Grasobjects, each
572fe8fb19SBen Gras.Fa size
582fe8fb19SBen Grasbytes long, from the stream pointed to by
592fe8fb19SBen Gras.Fa stream ,
602fe8fb19SBen Grasstoring them at the location given by
612fe8fb19SBen Gras.Fa ptr .
622fe8fb19SBen Gras.Pp
632fe8fb19SBen GrasThe function
642fe8fb19SBen Gras.Fn fwrite
652fe8fb19SBen Graswrites
662fe8fb19SBen Gras.Fa nmemb
672fe8fb19SBen Grasobjects, each
682fe8fb19SBen Gras.Fa size
692fe8fb19SBen Grasbytes long, to the stream pointed to by
702fe8fb19SBen Gras.Fa stream ,
712fe8fb19SBen Grasobtaining them from the location given by
722fe8fb19SBen Gras.Fa ptr .
732fe8fb19SBen Gras.Pp
742fe8fb19SBen GrasMixing
752fe8fb19SBen Gras.Fn fread
762fe8fb19SBen Grasand
772fe8fb19SBen Gras.Fn fwrite
782fe8fb19SBen Grascalls without setting the file position explicitly using
79*f14fb602SLionel Sambuc.Xr fsetpos 3
802fe8fb19SBen Grasbetween read and write or write and read operations will lead to unexpected
812fe8fb19SBen Grasresults because of buffering the file pointer not being set to the
822fe8fb19SBen Grasexpected position after each operation completes.
832fe8fb19SBen GrasThis behavior is allowed by ANSI C for efficiency and it will not be changed.
842fe8fb19SBen Gras.Sh RETURN VALUES
852fe8fb19SBen GrasThe functions
862fe8fb19SBen Gras.Fn fread
872fe8fb19SBen Grasand
882fe8fb19SBen Gras.Fn fwrite
892fe8fb19SBen Grasadvance the file position indicator for the stream
902fe8fb19SBen Grasby the number of bytes read or written.
912fe8fb19SBen GrasThey return the number of objects read or written.
922fe8fb19SBen GrasIf
932fe8fb19SBen Gras.Fa size
942fe8fb19SBen Grasor
952fe8fb19SBen Gras.Fa nmemb
962fe8fb19SBen Grasis 0, the functions return 0 and the state of
972fe8fb19SBen Gras.Fa stream
982fe8fb19SBen Grasremains unchanged.
992fe8fb19SBen GrasIf an error occurs, or the end-of-file is reached,
1002fe8fb19SBen Grasthe return value is a short object count (or zero).
1012fe8fb19SBen Gras.Pp
1022fe8fb19SBen GrasThe function
1032fe8fb19SBen Gras.Fn fread
1042fe8fb19SBen Grasdoes not distinguish between end-of-file and error, and callers
1052fe8fb19SBen Grasmust use
1062fe8fb19SBen Gras.Xr feof 3
1072fe8fb19SBen Grasand
1082fe8fb19SBen Gras.Xr ferror 3
1092fe8fb19SBen Grasto determine which occurred.
1102fe8fb19SBen GrasThe function
1112fe8fb19SBen Gras.Fn fwrite
1122fe8fb19SBen Grasreturns a value less than
1132fe8fb19SBen Gras.Fa nmemb
1142fe8fb19SBen Grasonly if a write error has occurred.
1152fe8fb19SBen Gras.Sh SEE ALSO
1162fe8fb19SBen Gras.Xr read 2 ,
1172fe8fb19SBen Gras.Xr write 2
1182fe8fb19SBen Gras.Sh STANDARDS
1192fe8fb19SBen GrasThe functions
1202fe8fb19SBen Gras.Fn fread
1212fe8fb19SBen Grasand
1222fe8fb19SBen Gras.Fn fwrite
1232fe8fb19SBen Grasconform to
1242fe8fb19SBen Gras.St -ansiC .
125