---
name: "fclose"
section: "3"
platform: "linux"
package: "man-pages"
version: "6.19-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux", "freebsd", "macos"]
url: "https://new.carta.tech/fclose"
---

# fclose(3)

close a stream

## NAME

fclose - close a stream

## LIBRARY

Standard C library (*libc*, *-lc*)

## SYNOPSIS

```
#include <stdio.h>
```

**int fclose(FILE \****stream***);**

## DESCRIPTION

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

## RETURN VALUE

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

- **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)](/close/2.md), [**write**(2)](/write/2.md), or [**fflush**(3)](/fflush/3.md).

## ATTRIBUTES

For an explanation of the terms used in this section, see [**attributes**(7)](/attributes/7.md).

| | | |
| --- | --- | --- |
| **Interface** | **Attribute** | **Value** |
| **fclose**() | Thread safety | MT-Safe |

## STANDARDS

C11, POSIX.1-2008.

## HISTORY

C89, POSIX.1-2001.

## NOTES

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)](/sync/2.md) or [**fsync**(2)](/fsync/2.md).

## SEE ALSO

[**close**(2)](/close/2.md), [**fcloseall**(3)](/fcloseall/3.md), [**fflush**(3)](/fflush/3.md), [**fileno**(3)](/fileno/3.md), [**fopen**(3)](/fopen/3.md), [**setbuf**(3)](/setbuf/3.md)
