{
  "slug": "fclose",
  "term": "fclose",
  "aliases": [
    "fclose()",
    "fclose(3)"
  ],
  "definition": "fclose is a C standard-I/O operation that flushes pending output and closes a stream, releasing its underlying file descriptor when one is present.",
  "note": "On Linux, check the return: zero indicates success and EOF reports failure with errno set, potentially from writing, flushing or closing. Earlier buffered output can appear successful before fclose reports an error. Neither successful fclose nor successful fflush adds fsync semantics. [linux-fclose]\n\nAfter fclose returns, including failure, the FILE pointer must not be used again; retrying fclose on it has undefined behavior. This stream-lifetime rule is distinct from the platform-specific close(2) descriptor rules. Do not confuse a retired stream with an open file descriptor. [linux-fclose]",
  "status": "shipping",
  "advantages": [],
  "limitations": [
    "Stream closure is not proof of persistent file data.",
    "A failed fclose cannot be retried using the same FILE pointer."
  ],
  "related": [
    "fflush",
    "fwrite",
    "close",
    "fsync",
    "file-descriptor"
  ],
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "citations": [
    {
      "id": "linux-fclose",
      "title": "Linux man-pages 6.19: fclose(3)",
      "url": "https://man7.org/linux/man-pages/man3/fclose.3.html",
      "accessed": "2026-10-21"
    },
    {
      "id": "linux-fflush",
      "title": "Linux man-pages 6.19: fflush(3)",
      "url": "https://man7.org/linux/man-pages/man3/fflush.3.html",
      "accessed": "2026-10-21"
    },
    {
      "id": "hesela-stdio",
      "title": "Hesela: The user-space buffer comes before fsync",
      "url": "https://hesela.com/analyses/fsync-failure-retry-durability/#stdio-buffer",
      "accessed": "2026-10-21"
    }
  ],
  "updated": "2026-10-21"
}
