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