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

NAME

6       fclose - close a stream
7

SYNOPSIS

9       #include <stdio.h>
10
11       int fclose(FILE *stream);
12
13

DESCRIPTION

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

RETURN VALUE

33       Upon successful completion, fclose()  shall  return  0;  otherwise,  it
34       shall return EOF    and set errno to indicate the error.
35

ERRORS

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

EXAMPLES

79       None.
80

APPLICATION USAGE

82       None.
83

RATIONALE

85       None.
86

FUTURE DIRECTIONS

88       None.
89

SEE ALSO

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