~ubuntu-branches/ubuntu/precise/manpages-posix/precise

1 by Francesco Paolo Lovergine
rules: linking manpages-posix not manpages.
1
.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved 
2 by Francesco Paolo Lovergine
* Alligned to linux main manpages edition.
2
.TH "FREAD" P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual"
1 by Francesco Paolo Lovergine
rules: linking manpages-posix not manpages.
3
.\" fread 
4
.SH NAME
5
fread \- binary input
6
.SH SYNOPSIS
7
.LP
8
\fB#include <stdio.h>
9
.br
10
.sp
11
size_t fread(void *restrict\fP \fIptr\fP\fB, size_t\fP \fIsize\fP\fB,
12
size_t\fP \fInitems\fP\fB,
13
.br
14
\ \ \ \ \ \  FILE *restrict\fP \fIstream\fP\fB);
15
.br
16
\fP
17
.SH DESCRIPTION
18
.LP
19
The \fIfread\fP() function shall read into the array pointed to by
20
\fIptr\fP up to \fInitems\fP elements whose size is
21
specified by \fIsize\fP in bytes, from the stream pointed to by \fIstream\fP.
22
For each object, \fIsize\fP calls shall be made to
23
the \fIfgetc\fP() function and the results stored, in the order read,
24
in an array of
25
\fBunsigned char\fP exactly overlaying the object. The file position
26
indicator for the stream (if defined) shall be advanced by
27
the number of bytes successfully read. If an error occurs, the resulting
28
value of the file position indicator for the stream is
29
unspecified. If a partial element is read, its value is unspecified.
30
.LP
31
The
32
\fIfread\fP() function may mark the \fIst_atime\fP field of the file
33
associated with \fIstream\fP for update. The
34
\fIst_atime\fP field shall be marked for update by the first successful
35
execution of \fIfgetc\fP(), \fIfgets\fP(), \fIfgetwc\fP(), \fIfgetws\fP(),
36
\fIfread\fP(), \fIfscanf\fP(), \fIgetc\fP(), \fIgetchar\fP(), \fIgets\fP(),
37
or \fIscanf\fP() using \fIstream\fP that returns data not supplied
38
by a prior call to \fIungetc\fP() or \fIungetwc\fP(). 
39
.SH RETURN VALUE
40
.LP
41
Upon successful completion, \fIfread\fP() shall return the number
42
of elements successfully read which is less than
43
\fInitems\fP only if a read error or end-of-file is encountered. If
44
\fIsize\fP or \fInitems\fP is 0, \fIfread\fP() shall return
45
0 and the contents of the array and the state of the stream remain
46
unchanged. Otherwise, if a read error occurs, the error
47
indicator for the stream shall be set,   \ and \fIerrno\fP shall be
48
set to indicate the error. 
49
.SH ERRORS
50
.LP
51
Refer to \fIfgetc\fP() .
52
.LP
53
\fIThe following sections are informative.\fP
54
.SH EXAMPLES
55
.SS Reading from a Stream
56
.LP
57
The following example reads a single element from the \fIfp\fP stream
58
into the array pointed to by \fIbuf\fP.
59
.sp
60
.RS
61
.nf
62
63
\fB#include <stdio.h>
64
\&...
65
size_t bytes_read;
66
char buf[100];
67
FILE *fp;
68
\&...
69
bytes_read = fread(buf, sizeof(buf), 1, fp);
70
\&...
71
\fP
72
.fi
73
.RE
74
.SH APPLICATION USAGE
75
.LP
76
The \fIferror\fP() or \fIfeof\fP() functions must
77
be used to distinguish between an error condition and an end-of-file
78
condition.
79
.LP
80
Because of possible differences in element length and byte ordering,
81
files written using \fIfwrite\fP() are application-dependent, and
82
possibly cannot be read using \fIfread\fP() by a
83
different application or by the same application on a different processor.
84
.SH RATIONALE
85
.LP
86
None.
87
.SH FUTURE DIRECTIONS
88
.LP
89
None.
90
.SH SEE ALSO
91
.LP
92
\fIfeof\fP() , \fIferror\fP() , \fIfgetc\fP() , \fIfopen\fP() , \fIgetc\fP()
93
, \fIgets\fP() , \fIscanf\fP() , the Base Definitions volume of IEEE\ Std\ 1003.1-2001,
94
\fI<stdio.h>\fP
95
.SH COPYRIGHT
96
Portions of this text are reprinted and reproduced in electronic form
97
from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
98
-- Portable Operating System Interface (POSIX), The Open Group Base
99
Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
100
Electrical and Electronics Engineers, Inc and The Open Group. In the
101
event of any discrepancy between this version and the original IEEE and
102
The Open Group Standard, the original IEEE and The Open Group Standard
103
is the referee document. The original Standard can be obtained online at
104
http://www.opengroup.org/unix/online.html .