HP-UX Reference (11i v2 04/09) - 3 Library Functions A-M (vol 6)

f
fclose(3S) fclose(3S)
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()
,orfflush_unlocked() fails, errno is set to one
of:
[EAGAIN] The
O_NONBLOCK flag is set for the file descriptor underlying stream and the pro-
cess 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 con-
trolling 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 com-
patibility with existing DCE applications. New multithreaded applications should use fclose() and
fflush().
SEE ALSO
close(2), exit(2), lseek(2), write(2), flockfile(3S), fopen(3S), setbuf(3S), thread_safety(5).
Section 3286 Hewlett-Packard Company 1 HP-UX 11i Version 2: September 2004