fclose or fflush Subroutine

Purpose

Closes or flushes a stream.

Library

Standard C Library (libc.a)

Syntax

#include <stdio.h>

int fclose ( Stream)
FILE *Stream;

int fflush ( Stream)
FILE *Stream;

Description

The fclose subroutine writes buffered data to the stream specified by the Stream parameter, and then closes the stream. The fclose subroutine is automatically called for all open files when the exit subroutine is invoked.

The fflush subroutine writes any buffered data for the stream specified by the Stream parameter and leaves the stream open. The fflush subroutine marks the st_ctime and st_mtime fields of the underlying file for update.

If the Stream parameter is a null pointer, the fflush subroutine performs this flushing action on all streams for which the behavior is defined.

Parameters

Item Description
Stream Specifies the output stream.

Return Values

Upon successful completion, the fclose and fflush subroutines return a value of 0. Otherwise, a value of EOF is returned.

Error Codes

If the fclose and fflush subroutines are unsuccessful, the following errors are returned through the errno global variable:

Item Description
EAGAIN The O_NONBLOCK or O_NDELAY 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 Stream is not valid.
EFBIG An attempt was made to write a file that exceeds the process' file size limit or the maximum file size. See the ulimit subroutine.
EFBIG The file is a regular file and an attempt was made to write at or beyond the offset maximum associated with the corresponding stream.
EINTR The fflush subroutine was interrupted by a signal.
EIO The process is a member of a background process group attempting to write to its controlling terminal, the TOSTOP signal is set, the process is neither ignoring nor blocking the SIGTTOU signal and the process group of the process is orphaned. This error may also be returned under implementation-dependent conditions.
ENOMEM The underlying stream was created by open_memstream() or open_wmemstream( ) and insufficient memory is available.
ENOSPC No free space remained on the device containing the file or in the buffer used by the fmemopen( ) function.
EPIPE An attempt is made to write to a pipe or FIFO that is not open for reading by any process. A SIGPIPE signal is sent to the process.
ENXIO A request was made of a non-existent device, or the request was outside the capabilities of the device