Loading...
--- Libc/Libc-763.13/stdio/FreeBSD/fclose.c
+++ Libc/Libc-1353.100.2/stdio/FreeBSD/fclose.c
@@ -49,12 +49,18 @@
{
int r;
+ pthread_once(&__sdidinit, __sinit);
+
+ if (fp == NULL) {
+ errno = EFAULT;
+ return (EOF);
+ }
if (fp->_flags == 0) { /* not open! */
errno = EBADF;
return (EOF);
}
FLOCKFILE(fp);
- r = fp->_flags & __SWR ? __sflush(fp) : 0;
+ r = __sflush(fp);
if (fp->_close != NULL && (*fp->_close)(fp->_cookie) < 0)
r = EOF;
if (fp->_flags & __SMBF)
@@ -65,7 +71,7 @@
FREELB(fp);
fp->_file = -1;
fp->_r = fp->_w = 0; /* Mess up if reaccessed. */
- fp->_flags = 0; /* Release this FILE for reuse. */
FUNLOCKFILE(fp);
+ __sfprelease(fp); /* Release this FILE for reuse. */
return (r);
}