diff options
author | deischen <deischen@FreeBSD.org> | 2006-04-22 15:09:15 +0000 |
---|---|---|
committer | deischen <deischen@FreeBSD.org> | 2006-04-22 15:09:15 +0000 |
commit | fa251f3c898137af2d52090430b62484040c0b9f (patch) | |
tree | eb538745a1bbe98b41a010bfe61eadd8ae9c02ae /lib/libc | |
parent | 99320e5a001df974492e41d02ec5d9de19dddb64 (diff) | |
download | FreeBSD-src-fa251f3c898137af2d52090430b62484040c0b9f.zip FreeBSD-src-fa251f3c898137af2d52090430b62484040c0b9f.tar.gz |
Add fcloseall() to libc. This removes the need to export _cleanup().
Linux also provides an fcloseall() implementation.
Discussed on: arch
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/stdio/Makefile.inc | 7 | ||||
-rw-r--r-- | lib/libc/stdio/Symbol.map | 1 | ||||
-rw-r--r-- | lib/libc/stdio/fclose.3 | 16 | ||||
-rw-r--r-- | lib/libc/stdio/fcloseall.c | 39 | ||||
-rw-r--r-- | lib/libc/stdio/local.h | 1 |
5 files changed, 60 insertions, 4 deletions
diff --git a/lib/libc/stdio/Makefile.inc b/lib/libc/stdio/Makefile.inc index d49e2fa..d815c97 100644 --- a/lib/libc/stdio/Makefile.inc +++ b/lib/libc/stdio/Makefile.inc @@ -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 \ diff --git a/lib/libc/stdio/Symbol.map b/lib/libc/stdio/Symbol.map index 6687f1b..ba8974e 100644 --- a/lib/libc/stdio/Symbol.map +++ b/lib/libc/stdio/Symbol.map @@ -7,6 +7,7 @@ FBSD_1.0 { asprintf; clearerr; fclose; + fcloseall; fdopen; feof; ferror; diff --git a/lib/libc/stdio/fclose.3 b/lib/libc/stdio/fclose.3 index 9d48228..320de29 100644 --- a/lib/libc/stdio/fclose.3 +++ b/lib/libc/stdio/fclose.3 @@ -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 . diff --git a/lib/libc/stdio/fcloseall.c b/lib/libc/stdio/fcloseall.c new file mode 100644 index 0000000..52c9e14 --- /dev/null +++ b/lib/libc/stdio/fcloseall.c @@ -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); +} diff --git a/lib/libc/stdio/local.h b/lib/libc/stdio/local.h index de038fa..7d5f79a 100644 --- a/lib/libc/stdio/local.h +++ b/lib/libc/stdio/local.h @@ -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 *); |