OpenBSD manual page server

Manual Page Search Parameters

FCLOSE(3) Library Functions Manual FCLOSE(3)

fclose, fdcloseclose a stream

#include <stdio.h>

int
fclose(FILE *stream);

int
fdclose(FILE *stream, int *fdp);

The () function dissociates the named stream from its underlying file or set of functions. If the stream was being used for output then any buffered data is written first, while if the stream was being used for input then the underlying file position may be updated, as if via fflush(3).

The () function is equivalent to fclose() except that it does not close the associated file descriptor. If fdp is not NULL, the file descriptor will be stored through it. If the stream was created with a function other than fopen(3), fdopen(3), or freopen(3) and as a result does not have an associated file descriptor then -1 will stored through fdp.

Upon successful completion 0 is returned. Otherwise, EOF is returned and the global variable errno is set to indicate the error. In either case no further access to the stream is possible.

The fclose() and fdclose() functions will fail if

[]
The argument stream is not an open stream.

The fdclose() function will fail if

[]
The argument stream does not have an associated file descriptor.

They may also fail and set errno for any of the errors specified for the fflush(3) routine.

The fclose() function may also fail and set errno for any of the errors specified for the close(2) routine.

close(2), fflush(3), fopen(3), setvbuf(3)

The fclose() function conforms to IEEE Std 1003.1-2024 (“POSIX.1”).

The fclose() function first appeared in Version 7 AT&T UNIX.

The fdclose() function first appeared in FreeBSD 11.0.

July 16, 2025 OpenBSD-7.8