]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. |
2 | .\" All rights reserved. | |
3 | .\" | |
4 | .\" This code is derived from software contributed to Berkeley by | |
5 | .\" Chris Torek and the American National Standards Committee X3, | |
6 | .\" on Information Processing Systems. | |
7 | .\" | |
a9cd9cb7 | 8 | .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB) |
fea681da MK |
9 | .\" Redistribution and use in source and binary forms, with or without |
10 | .\" modification, are permitted provided that the following conditions | |
11 | .\" are met: | |
12 | .\" 1. Redistributions of source code must retain the above copyright | |
13 | .\" notice, this list of conditions and the following disclaimer. | |
14 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
15 | .\" notice, this list of conditions and the following disclaimer in the | |
16 | .\" documentation and/or other materials provided with the distribution. | |
17 | .\" 3. All advertising materials mentioning features or use of this software | |
18 | .\" must display the following acknowledgement: | |
19 | .\" This product includes software developed by the University of | |
20 | .\" California, Berkeley and its contributors. | |
21 | .\" 4. Neither the name of the University nor the names of its contributors | |
22 | .\" may be used to endorse or promote products derived from this software | |
23 | .\" without specific prior written permission. | |
24 | .\" | |
25 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
26 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
27 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
28 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
29 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
30 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
31 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
32 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
33 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
34 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
35 | .\" SUCH DAMAGE. | |
8c9302dc | 36 | .\" %%%LICENSE_END |
fea681da MK |
37 | .\" |
38 | .\" @(#)fclose.3 6.7 (Berkeley) 6/29/91 | |
39 | .\" | |
40 | .\" Converted for Linux, Mon Nov 29 15:19:14 1993, faith@cs.unc.edu | |
41 | .\" | |
e00c3a07 | 42 | .\" Modified 2000-07-22 by Nicolás Lichtmaier <nick@debian.org> |
fea681da | 43 | .\" |
35deeb87 | 44 | .TH FCLOSE 3 2016-12-12 "GNU" "Linux Programmer's Manual" |
fea681da MK |
45 | .SH NAME |
46 | fclose \- close a stream | |
47 | .SH SYNOPSIS | |
48 | .B #include <stdio.h> | |
68e4db0a | 49 | .PP |
300791ed | 50 | .BI "int fclose(FILE *" stream ); |
fea681da MK |
51 | .SH DESCRIPTION |
52 | The | |
e511ffb6 | 53 | .BR fclose () |
c0adf09e | 54 | function flushes the stream pointed to by |
300791ed | 55 | .I stream |
fea681da MK |
56 | (writing any buffered output data using |
57 | .BR fflush (3)) | |
0dc60a99 | 58 | and closes the underlying file descriptor. |
47297adb | 59 | .SH RETURN VALUE |
1ca319af | 60 | Upon successful completion, 0 is returned. |
c13182ef | 61 | Otherwise, |
fea681da | 62 | .B EOF |
0dc60a99 | 63 | is returned and |
fea681da | 64 | .I errno |
c13182ef | 65 | is set to indicate the error. |
1ca319af | 66 | In either case, any further access |
fea681da MK |
67 | (including another call to |
68 | .BR fclose ()) | |
d9bfdb9c | 69 | to the stream results in undefined behavior. |
fea681da MK |
70 | .SH ERRORS |
71 | .TP | |
72 | .B EBADF | |
9fdfa163 | 73 | The file descriptor underlying |
300791ed | 74 | .I stream |
fea681da MK |
75 | is not valid. |
76 | .\" This error cannot occur unless you are mixing ANSI C stdio operations and | |
77 | .\" low-level file operations on the same stream. If you do get this error, | |
78 | .\" you must have closed the stream's low-level file descriptor using | |
300791ed | 79 | .\" something like close(fileno(stream)). |
fea681da MK |
80 | .PP |
81 | The | |
e511ffb6 | 82 | .BR fclose () |
fea681da MK |
83 | function may also fail and set |
84 | .I errno | |
85 | for any of the errors specified for the routines | |
86 | .BR close (2), | |
1ca319af | 87 | .BR write (2), |
fea681da MK |
88 | or |
89 | .BR fflush (3). | |
87314159 MS |
90 | .SH ATTRIBUTES |
91 | For an explanation of the terms used in this section, see | |
92 | .BR attributes (7). | |
93 | .TS | |
94 | allbox; | |
95 | lb lb lb | |
96 | l l l. | |
97 | Interface Attribute Value | |
98 | T{ | |
99 | .BR fclose () | |
100 | T} Thread safety MT-Safe | |
101 | .TE | |
47297adb | 102 | .SH CONFORMING TO |
56d5ba64 | 103 | POSIX.1-2001, POSIX.1-2008, C89, C99. |
fea681da MK |
104 | .SH NOTES |
105 | Note that | |
e511ffb6 | 106 | .BR fclose () |
f3f1456f | 107 | flushes only the user-space buffers provided by the |
c13182ef MK |
108 | C library. |
109 | To ensure that the data is physically stored | |
75b94dc3 | 110 | on disk the kernel buffers must be flushed too, for example, with |
fea681da MK |
111 | .BR sync (2) |
112 | or | |
113 | .BR fsync (2). | |
47297adb | 114 | .SH SEE ALSO |
fea681da MK |
115 | .BR close (2), |
116 | .BR fcloseall (3), | |
117 | .BR fflush (3), | |
f65efcf5 | 118 | .BR fileno (3), |
fea681da MK |
119 | .BR fopen (3), |
120 | .BR setbuf (3) |