Debian Codegraph @

upstream/mageia-cauldron/man3/fclose.3

raw
1 '\" t
2 .\" Copyright 1990-1991, The Regents of the University of California.
3 .\" Copyright, the authors of the Linux man-pages project
4 .\"
5 .\" SPDX-License-Identifier: BSD-4-Clause-UC
6 .\"
7 .TH fclose 3 2025-09-21 "Linux man-pages 6.17"
8 .SH NAME
9 fclose \- close a stream
10 .SH LIBRARY
11 Standard C library
12 .RI ( libc ,\~ \-lc )
13 .SH SYNOPSIS
14 .nf
15 .B #include <stdio.h>
16 .P
17 .BI "int fclose(FILE *" stream );
18 .fi
19 .SH DESCRIPTION
20 The
21 .BR fclose ()
22 function flushes the stream pointed to by
23 .I stream
24 (writing any buffered output data using
25 .BR fflush (3))
26 and closes the underlying file descriptor.
27 .SH RETURN VALUE
28 Upon successful completion, 0 is returned.
29 Otherwise,
30 .B EOF
31 is returned and
32 .I errno
33 is set to indicate the error.
34 In either case, any further access
35 (including another call to
36 .BR fclose ())
37 to the stream results in undefined behavior.
38 .SH ERRORS
39 .TP
40 .B EBADF
41 The file descriptor underlying
42 .I stream
43 is not valid.
44 .\" This error cannot occur unless you are mixing ANSI C stdio operations and
45 .\" low-level file operations on the same stream. If you do get this error,
46 .\" you must have closed the stream's low-level file descriptor using
47 .\" something like close(fileno(stream)).
48 .P
49 The
50 .BR fclose ()
51 function may also fail and set
52 .I errno
53 for any of the errors specified for the routines
54 .BR close (2),
55 .BR write (2),
56 or
57 .BR fflush (3).
58 .SH ATTRIBUTES
59 For an explanation of the terms used in this section, see
60 .BR attributes (7).
61 .TS
62 allbox;
63 lbx lb lb
64 l l l.
65 Interface Attribute Value
66 T{
67 .na
68 .nh
69 .BR fclose ()
70 T} Thread safety MT-Safe
71 .TE
72 .SH STANDARDS
73 C11, POSIX.1-2008.
74 .SH HISTORY
75 C89, POSIX.1-2001.
76 .SH NOTES
77 Note that
78 .BR fclose ()
79 flushes only the user-space buffers provided by the
80 C library.
81 To ensure that the data is physically stored
82 on disk the kernel buffers must be flushed too, for example, with
83 .BR sync (2)
84 or
85 .BR fsync (2).
86 .SH SEE ALSO
87 .BR close (2),
88 .BR fcloseall (3),
89 .BR fflush (3),
90 .BR fileno (3),
91 .BR fopen (3),
92 .BR setbuf (3)