fclose(3) — Linux manual page

NAME | SYNOPSIS | DESCRIPTION | RETURN VALUE | ERRORS | ATTRIBUTES | CONFORMING TO | NOTES | SEE ALSO | COLOPHON

FCLOSE(3)                 Linux Programmer's Manual                FCLOSE(3)

NAME top

       fclose - close a stream

SYNOPSIS top

       #include <stdio.h>

       int fclose(FILE *stream);

DESCRIPTION top

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

RETURN VALUE top

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

ERRORS top

       EBADF  The file descriptor underlying stream is not valid.

       The fclose() function may also fail and set errno for any of the
       errors specified for the routines close(2), write(2), or fflush(3).

ATTRIBUTES top

       For an explanation of the terms used in this section, see
       attributes(7).

       ┌──────────┬───────────────┬─────────┐
       │Interface Attribute     Value   │
       ├──────────┼───────────────┼─────────┤
       │fclose()  │ Thread safety │ MT-Safe │
       └──────────┴───────────────┴─────────┘

CONFORMING TO top

       POSIX.1-2001, POSIX.1-2008, C89, C99.

NOTES top

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

SEE ALSO top

       close(2), fcloseall(3), fflush(3), fileno(3), fopen(3), setbuf(3)

COLOPHON top

       This page is part of release 5.08 of the Linux man-pages project.  A
       description of the project, information about reporting bugs, and the
       latest version of this page, can be found at
       https://www.kernel.org/doc/man-pages/.

GNU                              2016-12-12                        FCLOSE(3)

Pages that refer to this page: gawk(1) , close(2) , abort(3) , addmntent(3) , clearerr(3) , endmntent(3) , fcloseall(3) , fdopen(3) , feof(3) , ferror(3) , fflush(3) , fileno(3) , fmemopen(3) , fopen(3) , fopencookie(3) , freopen(3) , getmntent(3) , getmntent_r(3) , hasmntopt(3) , open_memstream(3) , open_wmemstream(3) , pclose(3) , popen(3) , setbuf(3) , setbuffer(3) , setlinebuf(3) , setmntent(3) , setvbuf(3) , stdio(3) , xdr(3) , xdr_array(3) , xdr_bool(3) , xdr_bytes(3) , xdr_char(3) , xdr_destroy(3) , xdr_double(3) , xdr_enum(3) , xdr_float(3) , xdr_free(3) , xdr_getpos(3) , xdr_inline(3) , xdr_int(3) , xdr_long(3) , xdrmem_create(3) , xdr_opaque(3) , xdr_pointer(3) , xdrrec_create(3) , xdrrec_endofrecord(3) , xdrrec_eof(3) , xdrrec_skiprecord(3) , xdr_reference(3) , xdr_setpos(3) , xdr_short(3) , xdrstdio_create(3) , xdr_string(3) , xdr_u_char(3) , xdr_u_int(3) , xdr_u_long(3) , xdr_union(3) , xdr_u_short(3) , xdr_vector(3) , xdr_void(3) , xdr_wrapstring(3)