Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX Reference > F


HP-UX 11i Version 3: February 2007

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index


fclose(), fflush(), fclose_unlocked(), fflush_unlocked() — close or flush a stream


#include <stdio.h>

int fclose(FILE *stream);

int fflush(FILE *stream);

Obsolescent Interfaces

int fclose_unlocked(FILE *stream);

int fflush_unlocked(FILE *stream);


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.


Upon successful completion, fclose() and fflush() return 0. Otherwise, they return EOF and set errno to indicate the error.


If fclose(), fflush(), fclose_unlocked(), or fflush_unlocked() fails, errno is set to one of:


The O_NONBLOCK flag is set for the file descriptor underlying stream and the process would be delayed in the write operation.


The file descriptor underlying stream is not valid.


An attempt was made to write a file that exceeds the process's file size limit or the maximum file size (see ulimit(2)).


fclose() or fflush() was interrupted by a signal.


The process is in a background process group and is attempting to write to its controlling terminal, TOSTOP is set, the process is neither ignoring nor blocking the SIGTTOU signal, and the process group of the process is orphaned.


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


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


fclose_unlocked() and fflush_unlocked() are obsolescent interfaces supported only for compatibility with existing DCE applications. New multithreaded applications should use fclose() and fflush().


fclose(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C

fflush(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-2007 Hewlett-Packard Development Company, L.P.