📄 fclose.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-2003 The Open Group, All Rights Reserved --><title>fclose</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="fclose"></a> <a name="tag_03_140"></a><!-- fclose --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright © 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_140_01"></a>NAME</h4><blockquote>fclose - close a stream</blockquote><h4><a name="tag_03_140_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><p><code><tt>#include <<a href="../basedefs/stdio.h.html">stdio.h</a>><br><br> int fclose(FILE *</tt><i>stream</i><tt>);<br></tt></code></p></blockquote><h4><a name="tag_03_140_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 therequirements described here and the ISO C standard is unintentional. This volume of IEEE Std 1003.1-2001 defers tothe ISO C standard. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></div><p>The <i>fclose</i>() function shall cause the stream pointed to by <i>stream</i> to be flushed and the associated file to beclosed. Any unwritten buffered data for the stream shall be written to the file; any unread buffered data shall be discarded.Whether or not the call succeeds, the stream shall be disassociated from the file and any buffer set by the <a href="../functions/setbuf.html"><i>setbuf</i>()</a> or <a href="../functions/setvbuf.html"><i>setvbuf</i>()</a> function shall bedisassociated from the stream. If the associated buffer was automatically allocated, it shall be deallocated.</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>fclose</i>() function shall mark for update the <i>st_ctime</i> and <i>st_mtime</i> fields of the underlying file, if the streamwas writable, and if buffered data remains that has not yet been written to the file. The <i>fclose</i>() function shall performthe equivalent of a <a href="../functions/close.html"><i>close</i>()</a> on the file descriptor that is associated with the streampointed to by <i>stream</i>. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p><p>After the call to <i>fclose</i>(), any use of <i>stream</i> results in undefined behavior.</p></blockquote><h4><a name="tag_03_140_04"></a>RETURN VALUE</h4><blockquote><p>Upon successful completion, <i>fclose</i>() shall return 0; otherwise, it 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 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_140_05"></a>ERRORS</h4><blockquote><p>The <i>fclose</i>() function shall fail if:</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 writeoperation. <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 stream is not valid. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd><dt>[EFBIG]</dt><dd><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> Anattempt was made to write a file that exceeds the maximum file size. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd><dt>[EFBIG]</dt><dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">An attempt was made to write a file that exceeds the process' file size limit. <img src="../images/opt-end.gif" alt="[Option End]"border="0"></dd><dt>[EFBIG]</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 write at or beyond the offset maximum associated with the correspondingstream. <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 <i>fclose</i>() function was interrupted by a signal. <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">The process is a member of a background process group attempting to write to its controlling terminal, TOSTOP is set, the processis neither ignoring nor blocking SIGTTOU, and the process group of the process is orphaned. This error may also be returned underimplementation-defined conditions. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd><dt>[ENOSPC]</dt><dd><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">There was no free space remaining on the device containing the file. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd><dt>[EPIPE]</dt><dd><sup>[<a href="javascript:open_code('CX')">CX</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> Anattempt is made to write to a pipe or FIFO that is not open for reading by any process. A SIGPIPE signal shall also be sent to thethread. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd></dl><p>The <i>fclose</i>() function may fail if:</p><dl compact><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"> Arequest 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_140_06"></a>EXAMPLES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_140_07"></a>APPLICATION USAGE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_140_08"></a>RATIONALE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_140_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_140_10"></a>SEE ALSO</h4><blockquote><p><a href="close.html"><i>close</i>()</a> , <a href="fopen.html"><i>fopen</i>()</a> , <a href="getrlimit.html"><i>getrlimit</i>()</a> , <a href="ulimit.html"><i>ulimit</i>()</a> , the Base Definitions volume ofIEEE Std 1003.1-2001, <a href="../basedefs/stdio.h.html"><i><stdio.h></i></a></p></blockquote><h4><a name="tag_03_140_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_140_12"></a>Issue 5</h4><blockquote><p>Large File Summit extensions are added.</p></blockquote><h4><a name="tag_03_140_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 [EFBIG] error is added as part of the large file support extensions.</p></li><li><p>The [ENXIO] optional error condition is added.</p></li></ul><p>The DESCRIPTION is updated to note that the stream and any buffer are disassociated whether or not the call succeeds. This isfor alignment with the ISO/IEC 9899:1999 standard.</p></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>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -