161180Sbostic.\" Copyright (c) 1990, 1991, 1993 261180Sbostic.\" The Regents of the University of California. All rights reserved. 320394Smckusick.\" 446083Sbostic.\" This code is derived from software contributed to Berkeley by 550299Sbostic.\" Chris Torek and the American National Standards Committee X3, 650299Sbostic.\" on Information Processing Systems. 750299Sbostic.\" 846083Sbostic.\" %sccs.include.redist.man% 946083Sbostic.\" 10*66327Sbostic.\" @(#)fread.3 8.2 (Berkeley) 03/08/94 1146083Sbostic.\" 1248352Scael.Dd 1348352Scael.Dt FREAD 3 1448352Scael.Os 1548352Scael.Sh NAME 1648352Scael.Nm fread , 1748352Scael.Nm fwrite 1848352Scael.Nd binary stream input/output 1948352Scael.Sh SYNOPSIS 2048352Scael.Fd #include <stdio.h> 2148352Scael.Ft int 2248352Scael.Fn fread "void *ptr" "size_t size" "size_t nmemb" "FILE *stream" 2348352Scael.Ft int 24*66327Sbostic.Fn fwrite "const void *ptr" "size_t size" "size_t nmemb" "FILE *stream" 2548352Scael.Sh DESCRIPTION 2648352ScaelThe function 2748352Scael.Fn fread 2846083Sbosticreads 2948352Scael.Fa nmemb 3050854Sbosticobjects, each 3148352Scael.Xr size 3248352Scaelbytes long, from the stream pointed to by 3348352Scael.Fa stream , 3446083Sbosticstoring them at the location given by 3548352Scael.Fa ptr . 3648352Scael.Pp 3748352ScaelThe function 3848352Scael.Fn fwrite 3948352Scaelwrites 4048352Scael.Fa nmemb 4150854Sbosticobjects, each 4248352Scael.Fa size 4348352Scaelbytes long, to the stream pointed to by 4448352Scael.Fa stream , 4548352Scaelobtaining them from the location given by 4648352Scael.Fa ptr . 4748352Scael.Sh RETURN VALUES 4848352ScaelThe functions 4948352Scael.Fn fread 5048352Scaeland 5148352Scael.Fn fwrite 5248352Scaeladvance the file position indicator for the stream 5350854Sbosticby the number of bytes read or written. 5450854SbosticThey return the number of objects read or written. 5548352ScaelIf an error occurs, or the end-of-file is reached, 5650854Sbosticthe return value is a short object count (or zero). 5748352Scael.Pp 5848352ScaelThe function 5948352Scael.Fn fread 6048352Scaeldoes not distinguish between end-of-file and error, and callers 6147013Sbosticmust use 6248352Scael.Xr feof 3 6347013Sbosticand 6448352Scael.Xr ferror 3 6547013Sbosticto determine which occurred. 6652349SbosticThe function 6752349Sbostic.Fn fwrite 6852349Sbosticreturns a value less than 6952349Sbostic.Fa nmemb 7052349Sbosticonly if a write error has occurred. 7148352Scael.Sh SEE ALSO 7248352Scael.Xr read 2 , 7348352Scael.Xr write 2 7448352Scael.Sh STANDARDS 7548352ScaelThe functions 7648352Scael.Fn fread 7748352Scaeland 7848352Scael.Fn fwrite 7948352Scaelconform to 8048352Scael.St -ansiC . 81