1fclose(3C)               Standard C Library Functions               fclose(3C)
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  causes  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 is written to the file; any unread buffered data is
18       discarded. The stream is disassociated from the file. If the associated
19       buffer was automatically allocated, it is deallocated.
20
21
22       The fclose() function marks for update the st_ctime and st_mtime fields
23       of the underlying file if the stream is writable and if  buffered  data
24       has not yet been written to the file.  It will perform a close(2) oper‐
25       ation on the file descriptor that is associated with the stream pointed
26       to by stream.
27
28
29       After  the  call to fclose(), any use of stream causes undefined behav‐
30       ior.
31
32
33       The fclose() function is performed automatically  for  all  open  files
34       upon calling exit(2).
35

RETURN VALUES

37       Upon  successful  completion, fclose() returns 0. Otherwise, it returns
38       EOF and sets errno to indicate the error.
39

ERRORS

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

ATTRIBUTES

83       See attributes(5) for descriptions of the following attributes:
84
85
86
87
88       ┌─────────────────────────────┬─────────────────────────────┐
89       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
90       ├─────────────────────────────┼─────────────────────────────┤
91       │Interface Stability          │Standard                     │
92       ├─────────────────────────────┼─────────────────────────────┤
93       │MT-Level                     │MT-Safe                      │
94       └─────────────────────────────┴─────────────────────────────┘
95

SEE ALSO

97       close(2),  exit(2),  getrlimit(2),  ulimit(2),  fopen(3C),   stdio(3C),
98       attributes(5), standards(5)
99
100
101
102SunOS 5.11                        1 Nov 2003                        fclose(3C)
Impressum