Visit Our UNIX and Linux User Community

Linux and UNIX Man Pages

Test Your Knowledge in Computers #362
Difficulty: Medium
The sed command first appears in Version 5 AT&T UNIX.
True or False?
Linux & Unix Commands - Search Man Pages

fclose(3c) [opensolaris man page]

fclose(3C)						   Standard C Library Functions 						fclose(3C)

NAME
fclose - close a stream 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 asso- ciated buffer was automatically allocated, it is deallocated. The fclose() function marks for update the st_ctime and st_mtime fields of the underlying file if the stream is writable and if buffered data has not yet been written to the file. It will perform a close(2) operation 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. The fclose() function is performed automatically for all open files upon calling exit(2). RETURN VALUES
Upon successful completion, fclose() returns 0. Otherwise, it returns EOF and sets errno to indicate the error. ERRORS
The fclose() function 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. EFBIG An attempt was made to write a file that exceeds the maximum file size or the process's file size limit; or 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. 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 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 calling thread. The fclose() function may fail if: ENXIO A request was made of a non-existent device, or the request was beyond the limits of the device. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
close(2), exit(2), getrlimit(2), ulimit(2), fopen(3C), stdio(3C), attributes(5), standards(5) SunOS 5.11 1 Nov 2003 fclose(3C)

Check Out this Related Man Page

fclose(3)						     Library Functions Manual							 fclose(3)

NAME
fclose, fflush, fclose_unlocked, fflush_unlocked - Closes or flushes a stream LIBRARY
Standard C Library (libc.so, libc.a) SYNOPSIS
#include <stdio.h> int fclose ( FILE *stream); int fclose_unlocked( FILE *stream); int fflush( FILE *stream); int fflush_unlocked( FILE *stream); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: fclose(), fflush(): XSH5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Specifies the output or update stream. DESCRIPTION
The fclose() function writes buffered data to the stream specified by the stream parameter, and then closes the associated file. The func- tion is automatically called for all open files when the exit() function is invoked. Any unwritten buffered data for the stream is deliv- ered 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 the close() function 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. 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 was previously defined. The st_ctime and st_mtime fields of the underlying file are marked for update. [Tru64 UNIX] The fclose_unlocked() and fflush_unlocked() functions are functionally identical to the fclose() and fflush() functions, except that fclose_unlocked() and fflush_unlocked() may be safely used only within a scope that is protected by the flockfile() and fun- lockfile() functions used as a pair. The caller must ensure that the stream is locked before these functions are used. RETURN VALUES
Upon successful completion, the fclose(), fflush(), fclose_unlocked(), and fflush_unlocked() functions return a value of 0 (zero). Other- wise, EOF is returned, and errno is set to indicate the error. ERRORS
The fclose(), fflush(), fclose_unlocked(), and fflush_unlocked() functions set errno to the specified value for following conditions: The O_NONBLOCK flag is set for the file descriptor underlying the stream parameter and the process would be delayed in the write operation. The file descriptor underlying the stream parameter 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 the ulimit(3) reference page). The file is a regular file and an attempt was made to write at or beyond the offset maximum associated with the corresponding stream. The function was interrupted by a signal that was caught. The TOSTOP tty local mode causes a background process to get a SIGTTOU signal if it attempts to write to the controlling terminal. The SIGTTOU signal, if it is not caught or ignored, will cause the process to block in a stopped state. A process in an orphaned process group is not allowed to become stopped, since there is no unprivileged process to unblock it. This condition only applies to operations on stdio streams associated with ttys. [EIO] is also associated with driver errors. There was no free space remaining on the device containing the file. 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. A request was made of a nonexistent device or the request was outside the capabilities of the device. RELATED INFORMATION
Functions: close(2), exit(2), fopen(3), setbuf(3) Standards: standards(5) delim off fclose(3)

Featured Tech Videos