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. 17fbbd9655SWarner 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.\" 33*1250c964SMaxim Konovalov.Dd February 13, 2024 3458f0484fSRodney W. Grimes.Dt FCLOSE 3 3558f0484fSRodney W. Grimes.Os 3658f0484fSRodney W. Grimes.Sh NAME 37b62c955cSDaniel Eischen.Nm fclose , 38fd109954SMariusz Zaborski.Nm fdclose , 39b62c955cSDaniel Eischen.Nm fcloseall 4058f0484fSRodney W. Grimes.Nd close a stream 4125bb73e0SAlexey Zelkin.Sh LIBRARY 4225bb73e0SAlexey Zelkin.Lb libc 4358f0484fSRodney W. Grimes.Sh SYNOPSIS 4432eef9aeSRuslan Ermilov.In stdio.h 4558f0484fSRodney W. Grimes.Ft int 4658f0484fSRodney W. Grimes.Fn fclose "FILE *stream" 47fd109954SMariusz Zaborski.Ft int 48fd109954SMariusz Zaborski.Fn fdclose "FILE *stream" "int *fdp" 49b62c955cSDaniel Eischen.Ft void 50b62c955cSDaniel Eischen.Fn fcloseall void 5158f0484fSRodney W. Grimes.Sh DESCRIPTION 5258f0484fSRodney W. GrimesThe 5358f0484fSRodney W. Grimes.Fn fclose 5458f0484fSRodney W. Grimesfunction 5558f0484fSRodney W. Grimesdissociates the named 5658f0484fSRodney W. Grimes.Fa stream 5758f0484fSRodney W. Grimesfrom its underlying file or set of functions. 5858f0484fSRodney W. GrimesIf the stream was being used for output, any buffered data is written 5958f0484fSRodney W. Grimesfirst, using 6058f0484fSRodney W. Grimes.Xr fflush 3 . 61b62c955cSDaniel Eischen.Pp 62b62c955cSDaniel EischenThe 63fd109954SMariusz Zaborski.Fn fdclose 64fd109954SMariusz Zaborskifunction is equivalent to 65fd109954SMariusz Zaborski.Fn fclose 66fd109954SMariusz Zaborskiexcept that it does not close the underlying file descriptor. 67fd109954SMariusz ZaborskiIf 68fd109954SMariusz Zaborski.Fa fdp 69fd109954SMariusz Zaborskiis not 70fd109954SMariusz Zaborski.Dv NULL , 71fd109954SMariusz Zaborskithe file descriptor will be written to it. 72fd109954SMariusz ZaborskiIf the stream does not have an associated file descriptor, 73fd109954SMariusz Zaborski.Fa fdp 74fd109954SMariusz Zaborskiwill be set to -1. 75fd109954SMariusz ZaborskiThis type of stream is created with functions such as 76fd109954SMariusz Zaborski.Xr fmemopen 3 , 77fd109954SMariusz Zaborski.Xr funopen 3 , 78fd109954SMariusz Zaborskior 79fd109954SMariusz Zaborski.Xr open_memstream 3 . 80fd109954SMariusz Zaborski.Pp 81fd109954SMariusz ZaborskiThe 82b62c955cSDaniel Eischen.Fn fcloseall 83b62c955cSDaniel Eischenfunction calls 84b62c955cSDaniel Eischen.Fn fclose 85b62c955cSDaniel Eischenon all open streams. 8658f0484fSRodney W. Grimes.Sh RETURN VALUES 87fd109954SMariusz Zaborski.Fn fcloseall 88fd109954SMariusz Zaborskidoes not return a value. 89fd109954SMariusz Zaborski.Pp 90fd109954SMariusz ZaborskiUpon successful completion the 91fd109954SMariusz Zaborski.Fn fclose 92fd109954SMariusz Zaborskiand 93fd109954SMariusz Zaborski.Fn fdclose 94fd109954SMariusz Zaborskifunctions return 0. 9558f0484fSRodney W. GrimesOtherwise, 9658f0484fSRodney W. Grimes.Dv EOF 9758f0484fSRodney W. Grimesis returned and the global variable 9858f0484fSRodney W. Grimes.Va errno 9958f0484fSRodney W. Grimesis set to indicate the error. 10070efdda9SEivind Eklund.Sh ERRORS 101fd109954SMariusz Zaborski.Fn fdclose 102fd109954SMariusz Zaborskifails if: 103fd109954SMariusz Zaborski.Bl -tag -width Er 104fd109954SMariusz Zaborski.It Bq Er EOPNOTSUPP 105fd109954SMariusz ZaborskiThe stream does not have an associated file descriptor. 106fd109954SMariusz Zaborski.El 107fd109954SMariusz Zaborski.Pp 10858f0484fSRodney W. GrimesThe 10958f0484fSRodney W. Grimes.Fn fclose 110fd109954SMariusz Zaborskiand 111fd109954SMariusz Zaborski.Fn fdclose 112fd109954SMariusz Zaborskifunctions may also fail and set 11358f0484fSRodney W. Grimes.Va errno 114fd109954SMariusz Zaborskifor any of the errors specified for 11558f0484fSRodney W. Grimes.Xr fflush 3 . 116fd109954SMariusz Zaborski.Pp 117fd109954SMariusz ZaborskiThe 118fd109954SMariusz Zaborski.Fn fclose 119fd109954SMariusz Zaborskifunction may also fail and set errno for any of the errors specified for 120fd109954SMariusz Zaborski.Xr close 2 . 121b41c848dSEivind Eklund.Sh NOTES 1221fae73b1SRuslan ErmilovThe 1238bd4c216SEivind Eklund.Fn fclose 124fd109954SMariusz Zaborskiand 125fd109954SMariusz Zaborski.Fn fdclose 126fd109954SMariusz Zaborskifunctions do not handle NULL arguments in the 127fd109954SMariusz Zaborski.Fa stream 128fd109954SMariusz Zaborskivariable; this will result in a segmentation violation. 129fd109954SMariusz ZaborskiThis is intentional. 130fd109954SMariusz ZaborskiIt makes it easier to make sure programs written under 131b5c508fbSRuslan Ermilov.Fx 132b5c508fbSRuslan Ermilovare bug free. 13370efdda9SEivind EklundThis behaviour is an implementation detail, and programs should not 13470efdda9SEivind Eklundrely upon it. 13558f0484fSRodney W. Grimes.Sh SEE ALSO 13658f0484fSRodney W. Grimes.Xr close 2 , 13758f0484fSRodney W. Grimes.Xr fflush 3 , 13858f0484fSRodney W. Grimes.Xr fopen 3 , 13958f0484fSRodney W. Grimes.Xr setbuf 3 14058f0484fSRodney W. Grimes.Sh STANDARDS 14158f0484fSRodney W. GrimesThe 14258f0484fSRodney W. Grimes.Fn fclose 14358f0484fSRodney W. Grimesfunction 14458f0484fSRodney W. Grimesconforms to 145588a200cSRuslan Ermilov.St -isoC . 146fd109954SMariusz Zaborski.Sh HISTORY 147b62c955cSDaniel EischenThe 148b62c955cSDaniel Eischen.Fn fcloseall 149b62c955cSDaniel Eischenfunction first appeared in 150b62c955cSDaniel Eischen.Fx 7.0 . 151fd109954SMariusz Zaborski.Pp 152fd109954SMariusz ZaborskiThe 153fd109954SMariusz Zaborski.Fn fdclose 154fd109954SMariusz Zaborskifunction first appeared in 155fd109954SMariusz Zaborski.Fx 11.0 . 156