1fclose(3)                  Library Functions Manual                  fclose(3)
2
3
4

NAME

6       fclose - close a stream
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <stdio.h>
13
14       int fclose(FILE *stream);
15

DESCRIPTION

17       The  fclose() function flushes the stream pointed to by stream (writing
18       any buffered output data using fflush(3))  and  closes  the  underlying
19       file descriptor.
20

RETURN VALUE

22       Upon  successful completion, 0 is returned.  Otherwise, EOF is returned
23       and errno is set to indicate the error.  In either  case,  any  further
24       access  (including  another  call to fclose()) to the stream results in
25       undefined behavior.
26

ERRORS

28       EBADF  The file descriptor underlying stream is not valid.
29
30       The fclose() function may also fail and set errno for any of the errors
31       specified for the routines close(2), write(2), or fflush(3).
32

ATTRIBUTES

34       For  an  explanation  of  the  terms  used  in  this  section,  see at‐
35       tributes(7).
36
37       ┌────────────────────────────────────────────┬───────────────┬─────────┐
38Interface                                   Attribute     Value   
39       ├────────────────────────────────────────────┼───────────────┼─────────┤
40fclose()                                    │ Thread safety │ MT-Safe │
41       └────────────────────────────────────────────┴───────────────┴─────────┘
42

STANDARDS

44       C11, POSIX.1-2008.
45

HISTORY

47       C89, POSIX.1-2001.
48

NOTES

50       Note that fclose() flushes only the user-space buffers provided by  the
51       C  library.   To  ensure that the data is physically stored on disk the
52       kernel buffers must be  flushed  too,  for  example,  with  sync(2)  or
53       fsync(2).
54

SEE ALSO

56       close(2), fcloseall(3), fflush(3), fileno(3), fopen(3), setbuf(3)
57
58
59
60Linux man-pages 6.04              2023-03-30                         fclose(3)
Impressum