xref: /freebsd/lib/libc/stdio/fclose.3 (revision fbbd9655e5107c68e4e0146ff22b73d7350475bc)
1fd109954SMariusz Zaborski.\" Copyright (c) 1990, 1991, 1993 The Regents of the University of California.
2fd109954SMariusz Zaborski.\" Copyright (c) 2015 Mariusz Zaborski <oshogbo@FreeBSD.org>
3fd109954SMariusz Zaborski.\" All rights reserved.
458f0484fSRodney W. Grimes.\"
558f0484fSRodney W. Grimes.\" This code is derived from software contributed to Berkeley by
658f0484fSRodney W. Grimes.\" Chris Torek and the American National Standards Committee X3,
758f0484fSRodney W. Grimes.\" on Information Processing Systems.
858f0484fSRodney W. Grimes.\"
958f0484fSRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without
1058f0484fSRodney W. Grimes.\" modification, are permitted provided that the following conditions
1158f0484fSRodney W. Grimes.\" are met:
1258f0484fSRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright
1358f0484fSRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer.
1458f0484fSRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright
1558f0484fSRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer in the
1658f0484fSRodney W. Grimes.\"    documentation and/or other materials provided with the distribution.
17*fbbd9655SWarner Losh.\" 3. Neither the name of the University nor the names of its contributors
1858f0484fSRodney W. Grimes.\"    may be used to endorse or promote products derived from this software
1958f0484fSRodney W. Grimes.\"    without specific prior written permission.
2058f0484fSRodney W. Grimes.\"
2158f0484fSRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2258f0484fSRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2358f0484fSRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2458f0484fSRodney W. Grimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2558f0484fSRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2658f0484fSRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2758f0484fSRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2858f0484fSRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2958f0484fSRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3058f0484fSRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3158f0484fSRodney W. Grimes.\" SUCH DAMAGE.
3258f0484fSRodney W. Grimes.\"
3358f0484fSRodney W. Grimes.\"     @(#)fclose.3	8.1 (Berkeley) 6/4/93
347f3dea24SPeter Wemm.\" $FreeBSD$
3558f0484fSRodney W. Grimes.\"
36fd109954SMariusz Zaborski.Dd July 4, 2015
3758f0484fSRodney W. Grimes.Dt FCLOSE 3
3858f0484fSRodney W. Grimes.Os
3958f0484fSRodney W. Grimes.Sh NAME
40b62c955cSDaniel Eischen.Nm fclose ,
41fd109954SMariusz Zaborski.Nm fdclose ,
42b62c955cSDaniel Eischen.Nm fcloseall
4358f0484fSRodney W. Grimes.Nd close a stream
4425bb73e0SAlexey Zelkin.Sh LIBRARY
4525bb73e0SAlexey Zelkin.Lb libc
4658f0484fSRodney W. Grimes.Sh SYNOPSIS
4732eef9aeSRuslan Ermilov.In stdio.h
4858f0484fSRodney W. Grimes.Ft int
4958f0484fSRodney W. Grimes.Fn fclose "FILE *stream"
50fd109954SMariusz Zaborski.Ft int
51fd109954SMariusz Zaborski.Fn fdclose "FILE *stream" "int *fdp"
52b62c955cSDaniel Eischen.Ft void
53b62c955cSDaniel Eischen.Fn fcloseall void
5458f0484fSRodney W. Grimes.Sh DESCRIPTION
5558f0484fSRodney W. GrimesThe
5658f0484fSRodney W. Grimes.Fn fclose
5758f0484fSRodney W. Grimesfunction
5858f0484fSRodney W. Grimesdissociates the named
5958f0484fSRodney W. Grimes.Fa stream
6058f0484fSRodney W. Grimesfrom its underlying file or set of functions.
6158f0484fSRodney W. GrimesIf the stream was being used for output, any buffered data is written
6258f0484fSRodney W. Grimesfirst, using
6358f0484fSRodney W. Grimes.Xr fflush 3 .
64b62c955cSDaniel Eischen.Pp
65b62c955cSDaniel EischenThe
66fd109954SMariusz Zaborski.Fn fdclose
67fd109954SMariusz Zaborskifunction is equivalent to
68fd109954SMariusz Zaborski.Fn fclose
69fd109954SMariusz Zaborskiexcept that it does not close the underlying file descriptor.
70fd109954SMariusz ZaborskiIf
71fd109954SMariusz Zaborski.Fa fdp
72fd109954SMariusz Zaborskiis not
73fd109954SMariusz Zaborski.Dv NULL ,
74fd109954SMariusz Zaborskithe file descriptor will be written to it.
75fd109954SMariusz ZaborskiIf the
76fd109954SMariusz Zaborski.Fa fdp
77fd109954SMariusz Zaborskiargument will be different then NULL the file descriptor will be returned in it,
78fd109954SMariusz ZaborskiIf the stream does not have an associated file descriptor,
79fd109954SMariusz Zaborski.Fa fdp
80fd109954SMariusz Zaborskiwill be set to -1.
81fd109954SMariusz ZaborskiThis type of stream is created with functions such as
82fd109954SMariusz Zaborski.Xr fmemopen 3 ,
83fd109954SMariusz Zaborski.Xr funopen 3 ,
84fd109954SMariusz Zaborskior
85fd109954SMariusz Zaborski.Xr open_memstream 3 .
86fd109954SMariusz Zaborski.Pp
87fd109954SMariusz ZaborskiThe
88b62c955cSDaniel Eischen.Fn fcloseall
89b62c955cSDaniel Eischenfunction calls
90b62c955cSDaniel Eischen.Fn fclose
91b62c955cSDaniel Eischenon all open streams.
9258f0484fSRodney W. Grimes.Sh RETURN VALUES
93fd109954SMariusz Zaborski.Fn fcloseall
94fd109954SMariusz Zaborskidoes not return a value.
95fd109954SMariusz Zaborski.Pp
96fd109954SMariusz ZaborskiUpon successful completion the
97fd109954SMariusz Zaborski.Fn fclose
98fd109954SMariusz Zaborskiand
99fd109954SMariusz Zaborski.Fn fdclose
100fd109954SMariusz Zaborskifunctions return 0.
10158f0484fSRodney W. GrimesOtherwise,
10258f0484fSRodney W. Grimes.Dv EOF
10358f0484fSRodney W. Grimesis returned and the global variable
10458f0484fSRodney W. Grimes.Va errno
10558f0484fSRodney W. Grimesis set to indicate the error.
10670efdda9SEivind Eklund.Sh ERRORS
107fd109954SMariusz Zaborski.Fn fdclose
108fd109954SMariusz Zaborskifails if:
109fd109954SMariusz Zaborski.Bl -tag -width Er
110fd109954SMariusz Zaborski.It Bq Er EOPNOTSUPP
111fd109954SMariusz ZaborskiThe stream does not have an associated file descriptor.
112fd109954SMariusz Zaborski.El
113fd109954SMariusz Zaborski.Pp
11458f0484fSRodney W. GrimesThe
11558f0484fSRodney W. Grimes.Fn fclose
116fd109954SMariusz Zaborskiand
117fd109954SMariusz Zaborski.Fn fdclose
118fd109954SMariusz Zaborskifunctions may also fail and set
11958f0484fSRodney W. Grimes.Va errno
120fd109954SMariusz Zaborskifor any of the errors specified for
12158f0484fSRodney W. Grimes.Xr fflush 3 .
122fd109954SMariusz Zaborski.Pp
123fd109954SMariusz ZaborskiThe
124fd109954SMariusz Zaborski.Fn fclose
125fd109954SMariusz Zaborskifunction may also fail and set errno for any of the errors specified for
126fd109954SMariusz Zaborski.Xr close 2 .
127b41c848dSEivind Eklund.Sh NOTES
1281fae73b1SRuslan ErmilovThe
1298bd4c216SEivind Eklund.Fn fclose
130fd109954SMariusz Zaborskiand
131fd109954SMariusz Zaborski.Fn fdclose
132fd109954SMariusz Zaborskifunctions do not handle NULL arguments in the
133fd109954SMariusz Zaborski.Fa stream
134fd109954SMariusz Zaborskivariable; this will result in a segmentation violation.
135fd109954SMariusz ZaborskiThis is intentional.
136fd109954SMariusz ZaborskiIt makes it easier to make sure programs written under
137b5c508fbSRuslan Ermilov.Fx
138b5c508fbSRuslan Ermilovare bug free.
13970efdda9SEivind EklundThis behaviour is an implementation detail, and programs should not
14070efdda9SEivind Eklundrely upon it.
14158f0484fSRodney W. Grimes.Sh SEE ALSO
14258f0484fSRodney W. Grimes.Xr close 2 ,
14358f0484fSRodney W. Grimes.Xr fflush 3 ,
14458f0484fSRodney W. Grimes.Xr fopen 3 ,
14558f0484fSRodney W. Grimes.Xr setbuf 3
14658f0484fSRodney W. Grimes.Sh STANDARDS
14758f0484fSRodney W. GrimesThe
14858f0484fSRodney W. Grimes.Fn fclose
14958f0484fSRodney W. Grimesfunction
15058f0484fSRodney W. Grimesconforms to
151588a200cSRuslan Ermilov.St -isoC .
152fd109954SMariusz Zaborski.Sh HISTORY
153b62c955cSDaniel EischenThe
154b62c955cSDaniel Eischen.Fn fcloseall
155b62c955cSDaniel Eischenfunction first appeared in
156b62c955cSDaniel Eischen.Fx 7.0 .
157fd109954SMariusz Zaborski.Pp
158fd109954SMariusz ZaborskiThe
159fd109954SMariusz Zaborski.Fn fdclose
160fd109954SMariusz Zaborskifunction first appeared in
161fd109954SMariusz Zaborski.Fx 11.0 .
162