vdso.7: Minor tweak to Alejandro Colomar's patch
[man-pages.git] / man3 / fclose.3
blob86a0a11a0deb72e0dc01d8b0026ef110b3dbb492
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 .\"
8 .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
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.
36 .\" %%%LICENSE_END
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 .\"
42 .\" Modified 2000-07-22 by Nicolás Lichtmaier <nick@debian.org>
43 .\"
44 .TH FCLOSE 3  2021-03-22 "GNU" "Linux Programmer's Manual"
45 .SH NAME
46 fclose \- close a stream
47 .SH SYNOPSIS
48 .nf
49 .B #include <stdio.h>
50 .PP
51 .BI "int fclose(FILE *" stream );
52 .fi
53 .SH DESCRIPTION
54 The
55 .BR fclose ()
56 function flushes the stream pointed to by
57 .I stream
58 (writing any buffered output data using
59 .BR fflush (3))
60 and closes the underlying file descriptor.
61 .SH RETURN VALUE
62 Upon successful completion, 0 is returned.
63 Otherwise,
64 .B EOF
65 is returned and
66 .I errno
67 is set to indicate the error.
68 In either case, any further access
69 (including another call to
70 .BR fclose ())
71 to the stream results in undefined behavior.
72 .SH ERRORS
73 .TP
74 .B EBADF
75 The file descriptor underlying
76 .I stream
77 is not valid.
78 .\"  This error cannot occur unless you are mixing ANSI C stdio operations and
79 .\"  low-level file operations on the same stream. If you do get this error,
80 .\"  you must have closed the stream's low-level file descriptor using
81 .\"  something like close(fileno(stream)).
82 .PP
83 The
84 .BR fclose ()
85 function may also fail and set
86 .I errno
87 for any of the errors specified for the routines
88 .BR close (2),
89 .BR write (2),
91 .BR fflush (3).
92 .SH ATTRIBUTES
93 For an explanation of the terms used in this section, see
94 .BR attributes (7).
95 .ad l
96 .nh
97 .TS
98 allbox;
99 lbx lb lb
100 l l l.
101 Interface       Attribute       Value
103 .BR fclose ()
104 T}      Thread safety   MT-Safe
108 .sp 1
109 .SH CONFORMING TO
110 POSIX.1-2001, POSIX.1-2008, C89, C99.
111 .SH NOTES
112 Note that
113 .BR fclose ()
114 flushes only the user-space buffers provided by the
115 C library.
116 To ensure that the data is physically stored
117 on disk the kernel buffers must be flushed too, for example, with
118 .BR sync (2)
120 .BR fsync (2).
121 .SH SEE ALSO
122 .BR close (2),
123 .BR fcloseall (3),
124 .BR fflush (3),
125 .BR fileno (3),
126 .BR fopen (3),
127 .BR setbuf (3)