Open System Services Library Calls Reference Manual (G06.29+, H06.08+, J06.03+)

fclose(3) OSS Library Calls Reference Manual
NAME
fclose - Closes a stream
LIBRARY
G-series native Guardian processes: $SYSTEM.SYSnn.ZCRTLSRL
G-series native OSS processes: /G/system/sysnn/zcrtlsrl
H-series and J-series native Guardian processes: $SYSTEM.ZDLLnnn.ZCRTLDLL
32-bit H-series and J-series OSS processes: /G/system/zdllnnn/zcrtldll
64-bit H-series and J-series OSS processes: /G/system/zdllnnn/ycrtldll
SYNOPSIS
#include <stdio.h>
int fclose (
FILE *stream);
PARAMETERS
stream Specifies the output or update stream.
DESCRIPTION
The fclose( ) function writes buffered data to the stream specified by the stream parameter, and
then closes the associated file. It is automatically called for all open files when the exit() func-
tion is invoked. Any unwritten buffered data for the stream is delivered to the host environment
to be written to the file; any unread buffered data is discarded. The stream is disassociated from
the file. If the associated buffer was automatically allocated, it is deallocated. Any further use of
the stream specified by the stream parameter causes undefined behavior.
The fclose( ) function performs the close( ) function on the file descriptor associated with the
stream parameter. If the stream was writable and buffered data was not yet written to the file, it
marks the st_ctime and st_mtime elds of the underlying file for update. If the file is not already
at EOF, and is capable of seeking, the file pointer of the underlying open file descriptor is
adjusted so that the next operation on the open file descriptor deals with the byte after the last
one read from or written to the stream being closed.
RETURN VALUES
Upon successful completion, the fclose( ) function returns a value of 0 (zero). Otherwise, EOF is
returned, and errno is set to indicate the error.
ERRORS
If any of the following conditions occurs, the fclose( ) function sets errno to the value that
corresponds to the condition.
[EAGAIN] The O_NONBLOCK flag is set for the file descriptor underlying the stream
parameter and the process would be delayed in the write operation.
[EBADF] The file descriptor underlying the stream parameter is not valid.
[EFBIG] The application attempted to write beyond the file offset maximum.
[EINTR] The fclose( ) function was interrupted by a signal that was caught.
[EIO] The TOSTOP tty local mode causes a background process to get a SIGTTOU
signal if it attempts to write to the controlling terminal. The SIGTTOU signal, if
it is not caught or ignored, will cause the process to block in a stopped state. A
process in an orphaned process group is not allowed to become stopped, since
there is no unprivileged process to unblock it. This condition only applies to
operations on stdio streams associated with ttys.
[EIO] is also associated with driver errors.
238 Hewlett-Packard Company 527187-017