xref: /openbsd/lib/libc/stdio/fclose.3 (revision 73471bf0)
1.\"	$OpenBSD: fclose.3,v 1.9 2015/11/04 21:30:13 tedu Exp $
2.\"
3.\" Copyright (c) 1990, 1991, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" Chris Torek and the American National Standards Committee X3,
8.\" on Information Processing Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\"    notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in the
17.\"    documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\"    may be used to endorse or promote products derived from this software
20.\"    without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd $Mdocdate: November 4 2015 $
35.Dt FCLOSE 3
36.Os
37.Sh NAME
38.Nm fclose
39.Nd close a stream
40.Sh SYNOPSIS
41.In stdio.h
42.Ft int
43.Fn fclose "FILE *stream"
44.Sh DESCRIPTION
45The
46.Fn fclose
47function dissociates the named
48.Fa stream
49from its underlying file or set of functions.
50If the stream was being used for output, any buffered data is written
51first, using
52.Xr fflush 3 .
53.Sh RETURN VALUES
54Upon successful completion 0 is returned.
55Otherwise,
56.Dv EOF
57is returned and the global variable
58.Va errno
59is set to indicate the error.
60In either case no further access to the stream is possible.
61.Sh ERRORS
62.Bl -tag -width Er
63.It Bq Er EBADF
64The argument
65.Fa stream
66is not an open stream.
67.El
68.Pp
69The
70.Fn fclose
71function may also fail and set
72.Va errno
73for any of the errors specified for the routines
74.Xr close 2
75or
76.Xr fflush 3 .
77.Sh SEE ALSO
78.Xr close 2 ,
79.Xr fflush 3 ,
80.Xr fopen 3 ,
81.Xr setvbuf 3
82.Sh STANDARDS
83The
84.Fn fclose
85function conforms to
86.St -ansiC .
87.Sh HISTORY
88The
89.Fn fclose
90function first appeared in
91.At v7 .
92