diff options
author | deischen <deischen@FreeBSD.org> | 2001-02-11 22:06:43 +0000 |
---|---|---|
committer | deischen <deischen@FreeBSD.org> | 2001-02-11 22:06:43 +0000 |
commit | 1143b5e42a7816a7665798bcab7d5db4a37935b3 (patch) | |
tree | 3a588c82070b992d27ef67e1a69bcb90121e4ece /lib/libc/stdio/fflush.c | |
parent | d5657ce8b69e343a4dda07786bb158c464f9b4d6 (diff) | |
download | FreeBSD-src-1143b5e42a7816a7665798bcab7d5db4a37935b3.zip FreeBSD-src-1143b5e42a7816a7665798bcab7d5db4a37935b3.tar.gz |
libc MT-safety, part 2.
Add a lock to FILE. flockfile and friends are now implemented
(for the most part) in libc. flockfile_debug is implemented in
libc_r; I suppose it's about time to kill it but will do it in
a future commit.
Fix a potential deadlock in _fwalk in a threaded environment.
A file flag (__SIGN) was added to stdio.h that, when set, tells
_fwalk to ignore it in its walk. This seemed to be needed in
refill.c because each file needs to be locked when flushing.
Add a stub for pthread_self in libc. This is needed by flockfile
which is allowed by POSIX to be recursive.
Make fgetpos() error return value (-1) match man page.
Remove recursive calls to locked functions (stdio); I think I've
got them all, but I may have missed a couple.
A few K&R -> ANSI conversions along with removal of a few instances
of "register".
$Id$ -> $FreeBSD$ in libc/stdio/rget.c
Not objected to: -arch, a few months ago
Diffstat (limited to 'lib/libc/stdio/fflush.c')
-rw-r--r-- | lib/libc/stdio/fflush.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/libc/stdio/fflush.c b/lib/libc/stdio/fflush.c index 09d346b..5c1eaa1 100644 --- a/lib/libc/stdio/fflush.c +++ b/lib/libc/stdio/fflush.c @@ -49,6 +49,8 @@ static const char rcsid[] = #include "libc_private.h" #include "local.h" +static int sflush_locked(FILE *); + /* * Flush a single file, or (if fp is NULL) all files. * MT-safe version @@ -59,7 +61,7 @@ fflush(FILE *fp) int retval; if (fp == NULL) - return (_fwalk(__sflush)); + return (_fwalk(sflush_locked)); FLOCKFILE(fp); if ((fp->_flags & (__SWR | __SRW)) == 0) { errno = EBADF; @@ -80,7 +82,7 @@ __fflush(FILE *fp) int retval; if (fp == NULL) - return (_fwalk(__sflush)); + return (_fwalk(sflush_locked)); if ((fp->_flags & (__SWR | __SRW)) == 0) { errno = EBADF; retval = EOF; @@ -120,3 +122,14 @@ __sflush(FILE *fp) } return (0); } + +static int +sflush_locked(FILE *fp) +{ + int ret; + + FLOCKFILE(fp); + ret = __sflush(fp); + FUNLOCKFILE(fp); + return (ret); +} |