FDCLOSE(3C) Standard C Library Functions FDCLOSE(3C)

NAME


fdclose - close a standard I/O stream without closing the underlying
file descriptor

LIBRARY


Standard C Library (libc, -lc)

SYNOPSIS


#include <stdio.h>

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

DESCRIPTION


The fdclose() function is equivalent to fclose(3C), closing the given
standard I/O stream, except that it does not close the underlying file
descriptor.

If fdp is not NULL, it will be used to return the underlying file
descriptor of the I/O stream. If the stream does not have an
underlying file descriptor associated with it, fdp will be set to -1.
This is always done, regardless of any error returned by fdclose().

If fdp is NULL, no file descriptor will be returned. Note that
regardless of the value passed for fdp, the I/O stream will be closed
without closing the underlying file descriptor. Usually callers who
pass NULL for fdp already have the file descriptor's value available.

The equivalent of fflush(3C) is called on the stream before closing,
thus any buffered or pending input is discarded while any buffered or
pending output is written out to the underlying file. This includes
the standard streams, stdin, stdout, and stderr.

After the call to fdclose(), any use of stream causes undefined
behavior.

RETURN VALUES


Upon successful completion, the fdclose() function returns 0.
Otherwise, EOF is returned and the global variable errno is set to
indicate the error.

ERRORS


The fdclose() function will fail if:

ENOTSUP The stream does not have an associated file
descriptor. The stream was closed nonetheless, and
if fdp was not NULL, it will have been set to -1.

The fdclose() function may also fail and set errno for any of the
errors specified in fflush(3C).

Even in the case of an error returned by fdclose(), stream should be
considered closed.

INTERFACE STABILITY


Committed

MT-LEVEL
Mt-Safe

SEE ALSO


fclose(3C), fflush(3C), attributes(7)

illumos April 25, 2024 illumos

tribblix@gmail.com :: GitHub :: Privacy