OSDN Git Service

ef8116c4fc3d4864329f620dbb21df7dd3ed2c6c
[linuxjm/LDP_man-pages.git] / original / man3 / fclose.3
1 .\" Copyright (c) 1990, 1991 The Regents of the University of California.
2 .\" All rights reserved.
3 .\"
4 .\" This code is derived from software contributed to Berkeley by
5 .\" Chris Torek and the American National Standards Committee X3,
6 .\" on Information Processing Systems.
7 .\"
8 .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
11 .\" are met:
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\"    notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\"    notice, this list of conditions and the following disclaimer in the
16 .\"    documentation and/or other materials provided with the distribution.
17 .\" 3. All advertising materials mentioning features or use of this software
18 .\"    must display the following acknowledgement:
19 .\"     This product includes software developed by the University of
20 .\"     California, Berkeley and its contributors.
21 .\" 4. Neither the name of the University nor the names of its contributors
22 .\"    may be used to endorse or promote products derived from this software
23 .\"    without specific prior written permission.
24 .\"
25 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 .\" SUCH DAMAGE.
36 .\" %%%LICENSE_END
37 .\"
38 .\"     @(#)fclose.3    6.7 (Berkeley) 6/29/91
39 .\"
40 .\" Converted for Linux, Mon Nov 29 15:19:14 1993, faith@cs.unc.edu
41 .\"
42 .\" Modified 2000-07-22 by Nicolás Lichtmaier <nick@debian.org>
43 .\"
44 .TH FCLOSE 3  2009-02-23 "GNU" "Linux Programmer's Manual"
45 .SH NAME
46 fclose \- close a stream
47 .SH SYNOPSIS
48 .B #include <stdio.h>
49 .sp
50 .BI "int fclose(FILE *" fp );
51 .SH DESCRIPTION
52 The
53 .BR fclose ()
54 function flushes the stream pointed to by
55 .I fp
56 (writing any buffered output data using
57 .BR fflush (3))
58 and closes the underlying file descriptor.
59 .SH RETURN VALUE
60 Upon successful completion 0 is returned.
61 Otherwise,
62 .B EOF
63 is returned and
64 .I errno
65 is set to indicate the error.
66 In either case any further access
67 (including another call to
68 .BR fclose ())
69 to the stream results in undefined behavior.
70 .SH ERRORS
71 .TP
72 .B EBADF
73 The file descriptor underlying
74 .I fp
75 is not valid.
76 .\"  This error cannot occur unless you are mixing ANSI C stdio operations and
77 .\"  low-level file operations on the same stream. If you do get this error,
78 .\"  you must have closed the stream's low-level file descriptor using
79 .\"  something like close(fileno(fp)).
80 .PP
81 The
82 .BR fclose ()
83 function may also fail and set
84 .I errno
85 for any of the errors specified for the routines
86 .BR close (2),
87 .BR write (2)
88 or
89 .BR fflush (3).
90 .SH CONFORMING TO
91 C89, C99.
92 .SH NOTES
93 Note that
94 .BR fclose ()
95 only flushes the user-space buffers provided by the
96 C library.
97 To ensure that the data is physically stored
98 on disk the kernel buffers must be flushed too, for example, with
99 .BR sync (2)
100 or
101 .BR fsync (2).
102 .SH SEE ALSO
103 .BR close (2),
104 .BR fcloseall (3),
105 .BR fflush (3),
106 .BR fopen (3),
107 .BR setbuf (3)
108 .SH COLOPHON
109 This page is part of release 3.67 of the Linux
110 .I man-pages
111 project.
112 A description of the project,
113 information about reporting bugs,
114 and the latest version of this page,
115 can be found at
116 \%http://www.kernel.org/doc/man\-pages/.