summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/fflush.c
diff options
context:
space:
mode:
authorjulian <julian@FreeBSD.org>1996-01-22 00:02:33 +0000
committerjulian <julian@FreeBSD.org>1996-01-22 00:02:33 +0000
commit619b731f5bb5e09dcf1eaf1fbd96383ca64398fd (patch)
treea89c7f50ec371cef4418259b9dccdd31ebb2f61f /lib/libc/stdio/fflush.c
parent663b14fb2f3198fb0bfb62ae16b6b56c2a4dd055 (diff)
downloadFreeBSD-src-619b731f5bb5e09dcf1eaf1fbd96383ca64398fd.zip
FreeBSD-src-619b731f5bb5e09dcf1eaf1fbd96383ca64398fd.tar.gz
Reviewed by: julian and (hsu?)
Submitted by: John Birrel(L?) changes for threadsafe operations
Diffstat (limited to 'lib/libc/stdio/fflush.c')
-rw-r--r--lib/libc/stdio/fflush.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/libc/stdio/fflush.c b/lib/libc/stdio/fflush.c
index 4a5cf0f..fce8932 100644
--- a/lib/libc/stdio/fflush.c
+++ b/lib/libc/stdio/fflush.c
@@ -41,21 +41,36 @@ static char sccsid[] = "@(#)fflush.c 8.1 (Berkeley) 6/4/93";
#include <errno.h>
#include <stdio.h>
#include "local.h"
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+#endif
/* Flush a single file, or (if fp is NULL) all files. */
+int
fflush(fp)
register FILE *fp;
{
+ int retval;
if (fp == NULL)
return (_fwalk(__sflush));
+#ifdef _THREAD_SAFE
+ _thread_flockfile(fp,__FILE__,__LINE__);
+#endif
if ((fp->_flags & (__SWR | __SRW)) == 0) {
errno = EBADF;
- return (EOF);
+ retval = EOF;
+ } else {
+ retval = __sflush(fp);
}
- return (__sflush(fp));
+#ifdef _THREAD_SAFE
+ _thread_funlockfile(fp);
+#endif
+ return (retval);
}
+int
__sflush(fp)
register FILE *fp;
{
OpenPOWER on IntegriCloud