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
11

NAME

13       fclose — close a stream
14

SYNOPSIS

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

DESCRIPTION

21       The functionality described on this reference page is aligned with  the
22       ISO C  standard.  Any  conflict between the requirements described here
23       and the ISO C standard is unintentional. This  volume  of  POSIX.1‐2008
24       defers to the ISO C standard.
25
26       The fclose() function shall cause the stream pointed to by stream to be
27       flushed and the associated file to be closed.  Any  unwritten  buffered
28       data  for  the stream shall be written to the file; any unread buffered
29       data shall be discarded. Whether or not the call succeeds,  the  stream
30       shall be disassociated from the file and any buffer set by the setbuf()
31       or setvbuf() function shall be disassociated from the  stream.  If  the
32       associated buffer was automatically allocated, it shall be deallocated.
33
34       If the file is not already at EOF, and the file is one capable of seek‐
35       ing, the file offset of the underlying open file description  shall  be
36       set to the file position of the stream if the stream is the active han‐
37       dle to the underlying file description.
38
39       The fclose() function shall mark for update the last data  modification
40       and  last  file status change timestamps of the underlying file, if the
41       stream was writable, and if buffered data remains that has not yet been
42       written to the file. The fclose() function shall perform the equivalent
43       of a close() on the file descriptor that is associated with the  stream
44       pointed to by stream.
45
46       After  the  call  to  fclose(),  any use of stream results in undefined
47       behavior.
48

RETURN VALUE

50       Upon successful completion, fclose()  shall  return  0;  otherwise,  it
51       shall return EOF and set errno to indicate the error.
52

ERRORS

54       The fclose() function shall fail if:
55
56       EAGAIN The  O_NONBLOCK  flag  is set for the file descriptor underlying
57              stream and the thread would be delayed in the write operation.
58
59       EBADF  The file descriptor underlying stream is not valid.
60
61       EFBIG  An attempt was made to write a file  that  exceeds  the  maximum
62              file size.
63
64       EFBIG  An  attempt  was made to write a file that exceeds the file size
65              limit of the process.
66
67       EFBIG  The file is a regular file and an attempt was made to  write  at
68              or  beyond  the offset maximum associated with the corresponding
69              stream.
70
71       EINTR  The fclose() function was interrupted by a signal.
72
73       EIO    The process is a member of a background process group attempting
74              to write to its controlling terminal, TOSTOP is set, the calling
75              thread is not blocking SIGTTOU,  the  process  is  not  ignoring
76              SIGTTOU, and the process group of the process is orphaned.  This
77              error may also be returned under  implementation-defined  condi‐
78              tions.
79
80       ENOMEM The   underlying  stream  was  created  by  open_memstream()  or
81              open_wmemstream() and insufficient memory is available.
82
83       ENOSPC There was no free space remaining on the device  containing  the
84              file or in the buffer used by the fmemopen() function.
85
86       EPIPE  An  attempt  is made to write to a pipe or FIFO that is not open
87              for reading by any process. A SIGPIPE signal shall also be  sent
88              to the thread.
89
90       The fclose() function may fail if:
91
92       ENXIO  A  request  was made of a nonexistent device, or the request was
93              outside the capabilities of the device.
94
95       The following sections are informative.
96

EXAMPLES

98       None.
99

APPLICATION USAGE

101       None.
102

RATIONALE

104       None.
105

FUTURE DIRECTIONS

107       None.
108

SEE ALSO

110       Section 2.5, Standard I/O Streams, close(), fmemopen(), fopen(),  getr‐
111       limit(), open_memstream(), ulimit()
112
113       The Base Definitions volume of POSIX.1‐2008, <stdio.h>
114
116       Portions  of  this text are reprinted and reproduced in electronic form
117       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
118       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
119       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
120       cal  and  Electronics  Engineers,  Inc  and  The  Open Group.  (This is
121       POSIX.1-2008 with the 2013 Technical Corrigendum  1  applied.)  In  the
122       event of any discrepancy between this version and the original IEEE and
123       The Open Group Standard, the original IEEE and The Open Group  Standard
124       is  the  referee document. The original Standard can be obtained online
125       at http://www.unix.org/online.html .
126
127       Any typographical or formatting errors that appear  in  this  page  are
128       most likely to have been introduced during the conversion of the source
129       files to man page format. To report such errors,  see  https://www.ker
130       nel.org/doc/man-pages/reporting_bugs.html .
131
132
133
134IEEE/The Open Group                  2013                           FCLOSE(3P)
Impressum