Debian Codegraph @

upstream/debian-trixie/man3/fclose.3

raw
1 '\" t
2 .\" Copyright (c) 1990, 1991 The Regents of the University of California.
3 .\" All rights reserved.
4 .\"
5 .\" This code is derived from software contributed to Berkeley by
6 .\" Chris Torek and the American National Standards Committee X3,
7 .\" on Information Processing Systems.
8 .\"
9 .\" SPDX-License-Identifier: BSD-4-Clause-UC
10 .\"
11 .\" @(#)fclose.3 6.7 (Berkeley) 6/29/91
12 .\"
13 .\" Converted for Linux, Mon Nov 29 15:19:14 1993, [email protected]
14 .\"
15 .\" Modified 2000-07-22 by Nicolás Lichtmaier <[email protected]>
16 .\"
17 .TH fclose 3 2024-05-02 "Linux man-pages 6.9.1"
18 .SH NAME
19 fclose \- close a stream
20 .SH LIBRARY
21 Standard C library
22 .RI ( libc ", " \-lc )
23 .SH SYNOPSIS
24 .nf
25 .B #include <stdio.h>
26 .P
27 .BI "int fclose(FILE *" stream );
28 .fi
29 .SH DESCRIPTION
30 The
31 .BR fclose ()
32 function flushes the stream pointed to by
33 .I stream
34 (writing any buffered output data using
35 .BR fflush (3))
36 and closes the underlying file descriptor.
37 .\" Reviewed by upstream and rejected, May 2012, Debian#67239
38 .PP
39 The behaviour of
40 .BR fclose ()
41 is undefined if the
42 .I stream
43 parameter is an illegal pointer, or is a descriptor already passed
44 to a previous invocation of
45 .BR fclose ().
46 .\" End of patch
47 .SH RETURN VALUE
48 Upon successful completion, 0 is returned.
49 Otherwise,
50 .B EOF
51 is returned and
52 .I errno
53 is set to indicate the error.
54 In either case, any further access
55 (including another call to
56 .BR fclose ())
57 to the stream results in undefined behavior.
58 .SH ERRORS
59 .TP
60 .B EBADF
61 The file descriptor underlying
62 .I stream
63 is not valid.
64 .\" This error cannot occur unless you are mixing ANSI C stdio operations and
65 .\" low-level file operations on the same stream. If you do get this error,
66 .\" you must have closed the stream's low-level file descriptor using
67 .\" something like close(fileno(stream)).
68 .P
69 The
70 .BR fclose ()
71 function may also fail and set
72 .I errno
73 for any of the errors specified for the routines
74 .BR close (2),
75 .BR write (2),
76 or
77 .BR fflush (3).
78 .SH ATTRIBUTES
79 For an explanation of the terms used in this section, see
80 .BR attributes (7).
81 .TS
82 allbox;
83 lbx lb lb
84 l l l.
85 Interface Attribute Value
86 T{
87 .na
88 .nh
89 .BR fclose ()
90 T} Thread safety MT-Safe
91 .TE
92 .SH STANDARDS
93 C11, POSIX.1-2008.
94 .SH HISTORY
95 C89, POSIX.1-2001.
96 .SH NOTES
97 Note that
98 .BR fclose ()
99 flushes only the user-space buffers provided by the
100 C library.
101 To ensure that the data is physically stored
102 on disk the kernel buffers must be flushed too, for example, with
103 .BR sync (2)
104 or
105 .BR fsync (2).
106 .SH SEE ALSO
107 .BR close (2),
108 .BR fcloseall (3),
109 .BR fflush (3),
110 .BR fileno (3),
111 .BR fopen (3),
112 .BR setbuf (3)