NAME
fclose(), fflush(), fclose_unlocked(), fflush_unlocked() — close or flush a stream
SYNOPSIS
#include <stdio.h>
int fclose(FILE *stream);
int fflush(FILE *stream);
Obsolescent Interfaces
int fclose_unlocked(FILE *stream);
int fflush_unlocked(FILE *stream);
DESCRIPTION
fclose()
causes any buffered data for the named
stream
to be written out, and the
stream
to be closed.
Buffers allocated by the standard input/output system may be freed.
fclose()
is performed automatically for all open files upon calling
exit(2).
If
stream
points to an output stream or an update stream in which the
most recent operation was output,
fflush()
causes any buffered data for the
stream
to be written to that file; otherwise any buffered data is discarded.
The
stream
remains open.
If
stream
is a null pointer,
fflush()
performs this flushing action on all currently open streams.
Obsolescent Interfaces
fclose_unlocked()
and
fflush_unlocked()
close or flush a stream.
RETURN VALUE
Upon successful completion,
fclose()
and
fflush()
return 0.
Otherwise, they
return EOF and set
errno
to indicate the error.
ERRORS
If
fclose(),
fflush(),
fclose_unlocked(),
or
fflush_unlocked()
fails,
errno
is set to one of:
- EAGAIN
The
O_NONBLOCK
flag is set for the file descriptor underlying
stream
and the process would be delayed in the write operation.
- EBADF
The file descriptor underlying
stream
is not valid.
- EFBIG
An attempt was made to write a file
that exceeds the process's file size limit
or the maximum file size (see
ulimit(2)).
- EINTR
fclose()
or
fflush()
was interrupted by a signal.
- EIO
The process is in a background process group
and is attempting to write to its controlling terminal,
TOSTOP
is set, the process is neither ignoring nor blocking the
SIGTTOU
signal, and the process group of the process is orphaned.
- ENOSPC
There was no free space remaining on the device containing the file.
- EPIPE
An attempt was made to write to a pipe
that is not open for reading by any process.
A
SIGPIPE
signal is also sent to the process.
Additional
errno
values may be set by the underlying
write(),
lseek(),
and
close()
functions (see
write(2),
lseek(2)
and
close(2)).
WARNINGS
fclose_unlocked()
and
fflush_unlocked()
are obsolescent interfaces supported only for compatibility
with existing DCE applications.
New multithreaded applications should use
fclose()
and
fflush().
STANDARDS CONFORMANCE
fclose(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C
fflush(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C