1FCLOSE(3P)                 POSIX Programmer's Manual                FCLOSE(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       fclose - close a stream
13

SYNOPSIS

15       #include <stdio.h>
16
17       int fclose(FILE *stream);
18
19

DESCRIPTION

21       The fclose() function shall cause the stream pointed to by stream to be
22       flushed  and  the  associated file to be closed. Any unwritten buffered
23       data for the stream shall be written to the file; any  unread  buffered
24       data  shall be discarded.  Whether or not the call succeeds, the stream
25       shall be disassociated from the file and any buffer set by the setbuf()
26       or  setvbuf()  function  shall be disassociated from the stream. If the
27       associated buffer was automatically allocated, it shall be deallocated.
28
29       The fclose() function shall mark for update the st_ctime  and  st_mtime
30       fields  of  the  underlying  file,  if  the stream was writable, and if
31       buffered data remains that has not yet been written to  the  file.  The
32       fclose() function shall perform the equivalent of a close() on the file
33       descriptor that is associated with the stream pointed to by stream.
34
35       After the call to fclose(), any use  of  stream  results  in  undefined
36       behavior.
37

RETURN VALUE

39       Upon  successful  completion,  fclose()  shall  return 0; otherwise, it
40       shall return EOF  and set errno to indicate the error.
41

ERRORS

43       The fclose() function shall fail if:
44
45       EAGAIN The O_NONBLOCK flag is set for the  file  descriptor  underlying
46              stream and the process would be delayed in the write operation.
47
48       EBADF  The file descriptor underlying stream is not valid.
49
50       EFBIG  An  attempt  was  made  to write a file that exceeds the maximum
51              file size.
52
53       EFBIG  An attempt was made to write a file that  exceeds  the  process'
54              file size limit.
55
56       EFBIG  The  file  is a regular file and an attempt was made to write at
57              or beyond the offset maximum associated with  the  corresponding
58              stream.
59
60       EINTR  The fclose() function was interrupted by a signal.
61
62       EIO    The process is a member of a background process group attempting
63              to write to its controlling terminal, TOSTOP is set, the process
64              is  neither ignoring nor blocking SIGTTOU, and the process group
65              of the process is orphaned. This  error  may  also  be  returned
66              under implementation-defined conditions.
67
68       ENOSPC There  was  no free space remaining on the device containing the
69              file.
70
71       EPIPE  An attempt is made to write to a pipe or FIFO that is  not  open
72              for  reading by any process. A SIGPIPE signal shall also be sent
73              to the thread.
74
75
76       The fclose() function may fail if:
77
78       ENXIO  A request was made of a nonexistent device, or the  request  was
79              outside the capabilities of the device.
80
81
82       The following sections are informative.
83

EXAMPLES

85       None.
86

APPLICATION USAGE

88       None.
89

RATIONALE

91       None.
92

FUTURE DIRECTIONS

94       None.
95

SEE ALSO

97       close(), fopen(), getrlimit(), ulimit(), the Base Definitions volume of
98       IEEE Std 1003.1-2001, <stdio.h>
99
101       Portions of this text are reprinted and reproduced in  electronic  form
102       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
103       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
104       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
105       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
106       event of any discrepancy between this version and the original IEEE and
107       The Open Group Standard, the original IEEE and The Open Group  Standard
108       is  the  referee document. The original Standard can be obtained online
109       at http://www.opengroup.org/unix/online.html .
110
111
112
113IEEE/The Open Group                  2003                           FCLOSE(3P)
Impressum