fclose()

close stream 

Function


SYNOPSIS

#include <stdio.h>

int fclose(FILE *stream);


DESCRIPTION

The fclose() function causes the stream pointed to by stream to be flushed and the associated file to be closed. Any unwritten buffered data for the stream is 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. If the stream was writable and if buffered data had not yet been written to the file, the fclose() function marks the st_ctime and st_mtime fields of the underlying file for update.

The fclose() function performs a close() on the file descriptor that is associated with the stream pointed to by stream.

After the call to fclose(), any use of stream causes undefined behavior.

Upon calling exit(), fclose() is performed automatically for all open files.


PARAMETERS

stream 

Points to the stream to be flushed.


RETURN VALUES

If successful, fclose() returns a value of zero. On failure, it returns EOF, and sets errno to one of the following values:

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 

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 fclose() function was interrupted by a signal.

ENOSPC 

There was no free space remaining on the device containing the file.

EPIPE 

An attempt was made to write to a pipe or FIFO that is not open for reading by any process. A SIGPIPE signal is also sent to the process.


CONFORMANCE

ANSI/ISO 9899-1990.


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

None.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
close(), exit(), fdopen(), fflush(), fopen(), freopen(), setbuf()


PTC MKS Toolkit 10.1 patch 1 Documentation Build 2.