8999 SMBIOS: cleanup 32-bit specific code
[unleashed.git] / usr / src / man / man3c / fread.3c
blob86206c8adea43b92fd1b11ba01e702453b6e501a
1 '\" te
2 .\" Copyright (c) 1997, The Open Group. All Rights Reserved.
3 .\" Copyright 1989 AT&T
4 .\" Portions Copyright (c) 2002, Sun Microsystems, Inc.  All Rights Reserved
5 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
6 .\" http://www.opengroup.org/bookstore/.
7 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
8 .\"  This notice shall appear on any product containing this material.
9 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
10 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
11 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
12 .TH FREAD 3C "Jul 24, 2002"
13 .SH NAME
14 fread \- binary input
15 .SH SYNOPSIS
16 .LP
17 .nf
18 #include <stdio.h>
20 \fBsize_t\fR \fBfread\fR(\fBvoid *\fR\fIptr\fR, \fBsize_t\fR \fIsize\fR, \fBsize_t\fR \fInitems\fR, \fBFILE *\fR\fIstream\fR);
21 .fi
23 .SH DESCRIPTION
24 .sp
25 .LP
26 The \fBfread()\fR function reads into the array pointed to by \fIptr\fR up to
27 \fInitems\fR elements whose size is specified by \fIsize\fR in bytes, from the
28 stream pointed to by \fIstream\fR. For each object, \fIsize\fR calls are made
29 to the \fBfgetc\fR(3C) function and the results stored, in the order read, in
30 an array of \fBunsigned char\fR exactly overlaying the object. The
31 file-position indicator for the stream (if defined) is advanced by the number
32 of bytes successfully read. If an error occurs, the resulting value of the
33 file-position indicator for the stream is unspecified. If a partial element is
34 read, its value is unspecified.
35 .sp
36 .LP
37 The \fBfread()\fR function may mark the \fBst_atime\fR field of the file
38 associated with \fIstream\fR for update. The \fBst_atime\fR field will be
39 marked for update by the first successful execution of \fBfgetc\fR(3C),
40 \fBfgets\fR(3C), \fBfgetwc\fR(3C), \fBfgetws\fR(3C), \fBfread()\fR,
41 \fBfscanf\fR(3C), \fBgetc\fR(3C), \fBgetchar\fR(3C), \fBgets\fR(3C), or
42 \fBscanf\fR(3C) using \fIstream\fR that returns data not supplied by a prior
43 call to \fBungetc\fR(3C) or \fBungetwc\fR(3C).
44 .SH RETURN VALUES
45 .sp
46 .LP
47 Upon successful completion, \fBfread()\fR returns the number of elements
48 successfully read, which is less than \fInitems\fR only if a read error or
49 end-of-file is encountered. If \fIsize\fR or \fInitems\fR is 0, \fBfread()\fR
50 returns 0 and the contents of the array and the state of the stream remain
51 unchanged.  Otherwise, if a read error occurs, the error indicator for the
52 stream is set and \fBerrno\fR is set to indicate the error.
53 .SH ERRORS
54 .sp
55 .LP
56 Refer to \fBfgetc\fR(3C).
57 .SH EXAMPLES
58 .LP
59 \fBExample 1 \fRReading from a Stream
60 .sp
61 .LP
62 The following example reads a single element from the \fIfp\fR stream into the
63 array pointed to by \fIbuf\fR.
65 .sp
66 .in +2
67 .nf
68 #include <stdio.h>
69 \&...
70 size_t bytes_read;
71 char buf[100];
72 FILE *fp;
73 \&...
74 bytes_read = fread(buf, sizeof(buf), 1, fp);
75 \&...
76 .fi
77 .in -2
79 .SH USAGE
80 .sp
81 .LP
82 The \fBferror()\fR or \fBfeof()\fR functions must be used to distinguish
83 between an error condition and end-of-file condition. See \fBferror\fR(3C).
84 .sp
85 .LP
86 Because of possible differences in element length and byte ordering, files
87 written using \fBfwrite\fR(3C) are application-dependent, and possibly cannot
88 be read using \fBfread()\fR by a different application or by the same
89 application on a different processor.
90 .SH ATTRIBUTES
91 .sp
92 .LP
93 See \fBattributes\fR(5) for descriptions of the following attributes:
94 .sp
96 .sp
97 .TS
98 box;
99 c | c
100 l | l .
101 ATTRIBUTE TYPE  ATTRIBUTE VALUE
103 Interface Stability     Standard
105 MT-Level        MT-Safe
108 .SH SEE ALSO
111 \fBread\fR(2), \fBfclose\fR(3C), \fBferror\fR(3C), \fBfopen\fR(3C),
112 \fBgetc\fR(3C), \fBgets\fR(3C), \fBprintf\fR(3C), \fBputc\fR(3C),
113 \fBputs\fR(3C), \fBattributes\fR(5), \fBstandards\fR(5)