FCLOSE(3)

๐Ÿ“ฆ
version 15.1 ยท 2 versions
, in freebsd 15.1

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 named stream from its underlying file or set of functions. If the stream was being used for output, any buffered data is written first, using fflush(3). Like, flush first, then close โ€” main character energy fr fr.
  • fdclose(FILE *stream, int *fdp) โ€” equivalent to fclose(), except it does not close the underlying file descriptor. If fdp is not NULL, the file descriptor will be written to it. If the stream does not have an associated file descriptor, fdp will be set to -1. This type of stream is created with functions such as fmemopen(3), funopen(3), or open_memstream(3). Obsessed with the precision ngl.
  • fcloseall(void) โ€” calls fclose() 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
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms