FCLOSE(3)
okay bestie, welcome to FCLOSE(3) from the Library Functions Manual โ this is your stream-closing cheat sheet, and yes, she ate ๐
โจ
๐ NAME ๐
fclose, fdclose, fcloseall โ close a stream. The whole trio, no cap.
๐ฆ LIBRARY ๐ฆ
She lives in the Standard C Library (libc, -lc). Link her up with -lc, iykyk.
๐ธ SYNOPSIS ๐ธ
#include <stdio.h>
int
fclose(FILE *stream);
int
fdclose(FILE *stream, int *fdp);
void
fcloseall(void);
โจ DESCRIPTION โจ
fclose(FILE *stream)โ dissociates the namedstreamfrom its underlying file or set of functions. If the stream was being used for output, any buffered data is written first, usingfflush(3). Like, flush first, then close โ main character energy fr fr.fdclose(FILE *stream, int *fdp)โ equivalent tofclose(), except it does not close the underlying file descriptor. Iffdpis notNULL, the file descriptor will be written to it. If the stream does not have an associated file descriptor,fdpwill be set to-1. This type of stream is created with functions such asfmemopen(3),funopen(3), oropen_memstream(3). Obsessed with the precision ngl.fcloseall(void)โ callsfclose()on all open streams. Sheโs the โclose everythingโ bestie ๐
๐ RETURN VALUES ๐
fcloseall() does not return a value. Periodt.
Upon successful completion, the fclose() and fdclose() functions return 0. Otherwise, EOF is returned and the global variable errno is set to indicate the error. Not the vibe, but thatโs the contract ๐ซถ
๐ฅ ERRORS ๐ฅ
fdclose() fails if:
[EOPNOTSUPP]โ The stream does not have an associated file descriptor.
The fclose() and fdclose() functions may also fail and set errno for any of the errors specified for fflush(3).
The fclose() function may also fail and set errno for any of the errors specified for close(2).
๐ NOTES ๐
The fclose() and fdclose() functions do not handle NULL arguments in the stream variable; this will result in a segmentation violation. This is intentional. It makes it easier to make sure programs written under FreeBSD are bug free. This behaviour is an implementation detail, and programs should not rely upon it.
bestie, do not pass NULL and expect a cute little error message. She said no. Segfault city ๐ญ
๐ SEE ALSO ๐
โญ STANDARDS โญ
The fclose() function conforms to ISO/IEC 9899:1990 (โISO C90โ). Slay, standards icon ๐
๐ฆ HISTORY ๐ฆ
The fcloseall() function first appeared in FreeBSD 7.0.
The fdclose() function first appeared in FreeBSD 11.0.
later, bestie ๐๐ โ this page is from Debian, dated February 13, 2024. close those streams responsibly โจ
๐ฆ where this page comes from
- freebsd 15.1: base 15.1
- Copyright (c) 1990, 1991, 1993 The Regents of the University of California
- Copyright (c) 2015 Mariusz Zaborski <oshogbo@FreeBSD.org>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms