224 lines
9.6 KiB
HTML
224 lines
9.6 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
|
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
|
|
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
|
|
<title>fgetc</title>
|
|
</head>
|
|
<body bgcolor="white">
|
|
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
|
|
</script>
|
|
|
|
<basefont size="3"> <a name="fgetc"></a> <a name="tag_03_162"></a><!-- fgetc -->
|
|
<!--header start-->
|
|
<center><font size="2">The Open Group Base Specifications Issue 6<br>
|
|
IEEE Std 1003.1-2001<br>
|
|
Copyright © 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
|
|
|
|
<!--header end-->
|
|
<hr size="2" noshade>
|
|
<h4><a name="tag_03_162_01"></a>NAME</h4>
|
|
|
|
<blockquote>fgetc - get a byte from a stream</blockquote>
|
|
|
|
<h4><a name="tag_03_162_02"></a>SYNOPSIS</h4>
|
|
|
|
<blockquote class="synopsis">
|
|
<p><code><tt>#include <<a href="../basedefs/stdio.h.html">stdio.h</a>><br>
|
|
<br>
|
|
int fgetc(FILE *</tt><i>stream</i><tt>);<br>
|
|
</tt></code></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_162_03"></a>DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<div class="box"><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]"
|
|
border="0"> The functionality described on this reference page is aligned with the ISO C standard. Any conflict between the
|
|
requirements described here and the ISO C standard is unintentional. This volume of IEEE Std 1003.1-2001 defers to
|
|
the ISO C standard. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></div>
|
|
|
|
<p>If the end-of-file indicator for the input stream pointed to by <i>stream</i> is not set and a next byte is present, the
|
|
<i>fgetc</i>() function shall obtain the next byte as an <b>unsigned char</b> converted to an <b>int</b>, from the input stream
|
|
pointed to by <i>stream</i>, and advance the associated file position indicator for the stream (if defined). Since <i>fgetc</i>()
|
|
operates on bytes, reading a character consisting of multiple bytes (or "a multi-byte character") may require multiple calls to
|
|
<i>fgetc</i>().</p>
|
|
|
|
<p><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> The
|
|
<i>fgetc</i>() function may mark the <i>st_atime</i> field of the file associated with <i>stream</i> for update. The
|
|
<i>st_atime</i> field shall be marked for update by the first successful execution of <i>fgetc</i>(), <a href=
|
|
"../functions/fgets.html"><i>fgets</i>()</a>, <a href="../functions/fgetwc.html"><i>fgetwc</i>()</a>, <a href=
|
|
"../functions/fgetws.html"><i>fgetws</i>()</a>, <a href="../functions/fread.html"><i>fread</i>()</a>, <a href=
|
|
"../functions/fscanf.html"><i>fscanf</i>()</a>, <a href="../functions/getc.html"><i>getc</i>()</a>, <a href=
|
|
"../functions/getchar.html"><i>getchar</i>()</a>, <a href="../functions/gets.html"><i>gets</i>()</a>, or <a href=
|
|
"../functions/scanf.html"><i>scanf</i>()</a> using <i>stream</i> that returns data not supplied by a prior call to <a href=
|
|
"../functions/ungetc.html"><i>ungetc</i>()</a> or <a href="../functions/ungetwc.html"><i>ungetwc</i>()</a>. <img src=
|
|
"../images/opt-end.gif" alt="[Option End]" border="0"></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_162_04"></a>RETURN VALUE</h4>
|
|
|
|
<blockquote>
|
|
<p>Upon successful completion, <i>fgetc</i>() shall return the next byte from the input stream pointed to by <i>stream</i>. If the
|
|
end-of-file indicator for the stream is set, or if the stream is at end-of-file, the end-of-file indicator for the stream shall be
|
|
set and <i>fgetc</i>() shall return EOF. If a read error occurs, the error indicator for the stream shall be set, <i>fgetc</i>()
|
|
shall return EOF, <sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]"
|
|
border="0"> and shall set <i>errno</i> to indicate the error. <img src="../images/opt-end.gif" alt="[Option End]" border=
|
|
"0"></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_162_05"></a>ERRORS</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>fgetc</i>() function shall fail if data needs to be read and:</p>
|
|
|
|
<dl compact>
|
|
<dt>[EAGAIN]</dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
The O_NONBLOCK flag is set for the file descriptor underlying <i>stream</i> and the process would be delayed in the <i>fgetc</i>()
|
|
operation. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd>
|
|
|
|
<dt>[EBADF]</dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
The file descriptor underlying <i>stream</i> is not a valid file descriptor open for reading. <img src="../images/opt-end.gif" alt=
|
|
"[Option End]" border="0"></dd>
|
|
|
|
<dt>[EINTR]</dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
The read operation was terminated due to the receipt of a signal, and no data was transferred. <img src="../images/opt-end.gif"
|
|
alt="[Option End]" border="0"></dd>
|
|
|
|
<dt>[EIO]</dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> A
|
|
physical I/O error has occurred, or the process is in a background process group attempting to read from its controlling terminal,
|
|
and either the process is ignoring or blocking the SIGTTIN signal or the process group is orphaned. This error may also be
|
|
generated for implementation-defined reasons. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd>
|
|
|
|
<dt>[EOVERFLOW]</dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
The file is a regular file and an attempt was made to read at or beyond the offset maximum associated with the corresponding
|
|
stream. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd>
|
|
</dl>
|
|
|
|
<p>The <i>fgetc</i>() function may fail if:</p>
|
|
|
|
<dl compact>
|
|
<dt>[ENOMEM]</dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
Insufficient storage space is available. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd>
|
|
|
|
<dt>[ENXIO]</dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> A
|
|
request was made of a nonexistent device, or the request was outside the capabilities of the device. <img src=
|
|
"../images/opt-end.gif" alt="[Option End]" border="0"></dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<hr>
|
|
<div class="box"><em>The following sections are informative.</em></div>
|
|
|
|
<h4><a name="tag_03_162_06"></a>EXAMPLES</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_162_07"></a>APPLICATION USAGE</h4>
|
|
|
|
<blockquote>
|
|
<p>If the integer value returned by <i>fgetc</i>() is stored into a variable of type <b>char</b> and then compared against the
|
|
integer constant EOF, the comparison may never succeed, because sign-extension of a variable of type <b>char</b> on widening to
|
|
integer is implementation-defined.</p>
|
|
|
|
<p>The <a href="../functions/ferror.html"><i>ferror</i>()</a> or <a href="../functions/feof.html"><i>feof</i>()</a> functions must
|
|
be used to distinguish between an error condition and an end-of-file condition.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_162_08"></a>RATIONALE</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_162_09"></a>FUTURE DIRECTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_162_10"></a>SEE ALSO</h4>
|
|
|
|
<blockquote>
|
|
<p><a href="feof.html"><i>feof</i>()</a> , <a href="ferror.html"><i>ferror</i>()</a> , <a href="fopen.html"><i>fopen</i>()</a> , <a
|
|
href="getchar.html"><i>getchar</i>()</a> , <a href="getc.html"><i>getc</i>()</a> , the Base Definitions volume of
|
|
IEEE Std 1003.1-2001, <a href="../basedefs/stdio.h.html"><i><stdio.h></i></a></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_162_11"></a>CHANGE HISTORY</h4>
|
|
|
|
<blockquote>
|
|
<p>First released in Issue 1. Derived from Issue 1 of the SVID.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_162_12"></a>Issue 5</h4>
|
|
|
|
<blockquote>
|
|
<p>Large File Summit extensions are added.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_162_13"></a>Issue 6</h4>
|
|
|
|
<blockquote>
|
|
<p>Extensions beyond the ISO C standard are marked.</p>
|
|
|
|
<p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>The [EIO] and [EOVERFLOW] mandatory error conditions are added.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The [ENOMEM] and [ENXIO] optional error conditions are added.</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<p>The following changes are made for alignment with the ISO/IEC 9899:1999 standard:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>The DESCRIPTION is updated to clarify the behavior when the end-of-file indicator for the input stream is not set.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The RETURN VALUE section is updated to note that the error indicator shall be set for the stream.</p>
|
|
</li>
|
|
</ul>
|
|
</blockquote>
|
|
|
|
<div class="box"><em>End of informative text.</em></div>
|
|
|
|
<hr>
|
|
<hr size="2" noshade>
|
|
<center><font size="2"><!--footer start-->
|
|
UNIX ® is a registered Trademark of The Open Group.<br>
|
|
POSIX ® is a registered Trademark of The IEEE.<br>
|
|
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
|
|
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
|
|
]</font></center>
|
|
|
|
<!--footer end-->
|
|
<hr size="2" noshade>
|
|
</body>
|
|
</html>
|
|
|