FDCLOSE(3C) | Standard C Library Functions | FDCLOSE(3C) |
fdclose
— close a
standard I/O stream without closing the underlying file
descriptor
Standard C Library (libc, -lc)
#include
<stdio.h>
int
fdclose
(FILE *stream,
int *fdp);
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.
Upon successful completion, the fdclose
()
function returns 0. Otherwise, EOF
is returned and
the global variable errno is set to indicate the
error.
The fdclose
() function will fail if:
ENOTSUP
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.
April 25, 2024 | OmniOS |