1
0
mirror of https://git.FreeBSD.org/src.git synced 2025-01-06 13:09:50 +00:00

Add fcloseall() to libc. This removes the need to export _cleanup().

Linux also provides an fcloseall() implementation.

Discussed on:	arch
This commit is contained in:
Daniel Eischen 2006-04-22 15:09:15 +00:00
parent 5bb234b1a6
commit b62c955c52
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=157959
5 changed files with 60 additions and 4 deletions

View File

@ -4,9 +4,9 @@
# stdio sources
.PATH: ${.CURDIR}/stdio
SRCS+= _flock_stub.c asprintf.c clrerr.c fclose.c fdopen.c feof.c ferror.c \
fflush.c fgetc.c fgetln.c fgetpos.c fgets.c fgetwc.c fgetwln.c \
fgetws.c \
SRCS+= _flock_stub.c asprintf.c clrerr.c fclose.c fcloseall.c fdopen.c \
feof.c ferror.c fflush.c fgetc.c fgetln.c fgetpos.c fgets.c fgetwc.c \
fgetwln.c fgetws.c \
fileno.c findfp.c flags.c fopen.c fprintf.c fpurge.c fputc.c fputs.c \
fputwc.c fputws.c fread.c freopen.c fscanf.c fseek.c fsetpos.c \
ftell.c funopen.c fvwrite.c fwalk.c fwide.c fwprintf.c fwscanf.c \
@ -36,6 +36,7 @@ MAN+= fclose.3 ferror.3 fflush.3 fgetln.3 fgets.3 fgetwln.3 fgetws.3 \
printf.3 putc.3 putwc.3 remove.3 scanf.3 setbuf.3 stdio.3 tmpnam.3 \
ungetc.3 ungetwc.3 wprintf.3 wscanf.3
MLINKS+=fclose.3 fcloseall.3
MLINKS+=ferror.3 ferror_unlocked.3 \
ferror.3 clearerr.3 ferror.3 clearerr_unlocked.3 \
ferror.3 feof.3 ferror.3 feof_unlocked.3 \

View File

@ -7,6 +7,7 @@ FBSD_1.0 {
asprintf;
clearerr;
fclose;
fcloseall;
fdopen;
feof;
ferror;

View File

@ -40,7 +40,8 @@
.Dt FCLOSE 3
.Os
.Sh NAME
.Nm fclose
.Nm fclose ,
.Nm fcloseall
.Nd close a stream
.Sh LIBRARY
.Lb libc
@ -48,6 +49,8 @@
.In stdio.h
.Ft int
.Fn fclose "FILE *stream"
.Ft void
.Fn fcloseall void
.Sh DESCRIPTION
The
.Fn fclose
@ -58,6 +61,12 @@ from its underlying file or set of functions.
If the stream was being used for output, any buffered data is written
first, using
.Xr fflush 3 .
.Pp
The
.Fn fcloseall
function calls
.Fn fclose
on all open streams.
.Sh RETURN VALUES
Upon successful completion 0 is returned.
Otherwise,
@ -99,3 +108,8 @@ The
function
conforms to
.St -isoC .
.Pp
The
.Fn fcloseall
function first appeared in
.Fx 7.0 .

View File

@ -0,0 +1,39 @@
/*-
* Copyright (C) 2006 Daniel M. Eischen. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <stdio.h>
#include "local.h"
__weak_reference(__fcloseall, fclose);
void
__fcloseall(void)
{
(void)_fwalk(fclose);
}

View File

@ -53,6 +53,7 @@ extern fpos_t _sseek(FILE *, fpos_t, int);
extern int _ftello(FILE *, fpos_t *);
extern int _fseeko(FILE *, off_t, int, int);
extern int __fflush(FILE *fp);
extern void __fcloseall(void);
extern wint_t __fgetwc(FILE *);
extern wint_t __fputwc(wchar_t, FILE *);
extern int __sflush(FILE *);