Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ fflush(3) — OSF/1 X2.0-8 MIPS

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

close(2)

exit(2)

fopen(3)

setbuf(3)

fclose(3)  —  Subroutines

OSF

NAME

fclose, fflush − Closes or flushes a stream

LIBRARY

Standard I/O package (libc.a)

SYNOPSIS

#include <stdio.h>

int fclose (
    FILE ∗stream );

int fflush (
    FILE ∗stream );

PARAMETERS

streamSpecifies the output or update stream. 

DESCRIPTION

The fclose() function writes buffered data to the stream specified by the stream parameter, and then closes the stream.  It is automatically called for all open files when the exit() function 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 close() 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 fields 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 description is adjusted so that the next operation on the open file description deals with the byte after the last one read from or written to the stream being closed. 

The fflush() function writes any buffered data for the stream specified by the stream parameter and leaves the stream open.  If stream is a null pointer, the fflush() function performs this flushing action on all streams for which the behavior is defined above.  The st_ctime and st_mtime fields of the underlying file are marked for update.  If the stream is open for reading, any unread data buffered in the stream is discarded.  If the file is not already at EOF, the stream is open for reading, and the file is capable of seeking, the file offset of the underlying open file description is adjusted so that the next operation on the open file description deals with the byte after the last one read from or written to the stream being flushed. 

NOTES

AES Support Level:
Full use

RETURN VALUES

Upon successful completion, both the fclose() and fflush() functions return a value of 0 (zero). Otherwise, EOF is returned and errno is set to indicate the error. 

ERRORS

If the fclose() function fails, errno may be set to one of the following values:

[EBADF]The file descriptor underlying the stream parameter is not valid. 

[EINTR]The fclose() function was interrupted by a signal which was caught. 

[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. 

[EFBIG]An attempt was made to write a file that exceeds the process’ file size limit or the maximum file size.  See the ulimit() function. 

[EIO]The process is a member of a background process group attempting to write to its controlling terminal, TOSTOP is set, the process is neither ignoring nor blocking SIGTTOU 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 or FIFO that is not open for reading by any process.  A SIGPIPE signal will also be sent to the process. 

If the fflush() function fails, errno may be set 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 the stream parameter 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() function. 

[EINTR]The fflush() function was interrupted by a signal which was caught. 

[EIO]The implementation supports job control, the process is a member of a background process group attempting to write to its controlling terminal, TOSTOP is set, the process is neither ignoring nor blocking SIGTTOU and the process group of the process is orphaned.  This error may also be returned under implementation-defined conditions. 

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

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

RELATED INFORMATION

Functions: close(2), exit(2), fopen(3), setbuf(3)

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026