Syntax | #include <stdio.h> int fclose(FILE *stream); |
Description | fclose() causes the buffer of 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. The fclose() function will perform a close() on the file descriptor that is associated with the stream pointed to by stream.
After the call to fclose() , the behavior of stream is undefined. |
Return val. | 0 EOF
| if successful if an error occurs; errno is set to indicate the error. |
Errors | fclose() will fail if:
|
| 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. Extension The BS2000 file is not accessible in the process. (End) |
| EFBIG
| An attempt was made to write a file that exceeds the maximum file size or the process file size limit (see also ulimit() ). |
| EINTR
| fclose() was interrupted by a signal.
|
| EIO
| An I/O error occurred. 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 the SIGTTOU signal, and the process group of the process is orphaned. |
| ENOSPC
| There was no free space remaining on the device containing the file. |
| ENXIO
| A request was made of a non-existent device, or the request was outside the capabilities of the device. |
| 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. If threads are used, then the function affects the process or a thread in the following manner: If an EPIPE error occurs, the SIGPIPE signal is not sent to the process, but is sent to the calling thread instead. |
Notes | Whenever a program is terminated normally or with exit() , an fclose() is automatically executed for every open file. In other words, fclose() need not be called explicitly except in cases when a file needs to be closed before program termination, e.g. to avoid exceeding the limit for open files (=2048). The program environment determines whether fclose() is executed for a BS2000 or POSIX file. BS2000 If stream does not point to a FILE structure, the program is aborted. Since no data is buffered for record I/O, there is no internal call to the fflush() function. (End) |
See also | close() , exit() , fflush() , fopen() , setbuf() , stdio.h .
|