Loading...
--- Libc/Libc-1725.40.4/stdio/FreeBSD/freopen.c
+++ Libc/Libc-825.26/stdio/FreeBSD/freopen.c
@@ -48,7 +48,6 @@
#include "un-namespace.h"
#include "libc_private.h"
#include "local.h"
-#include "libc_hooks_impl.h"
/*
* Re-direct an existing, open (probably) file to some other file.
@@ -56,14 +55,13 @@
* all possible, no matter what.
*/
FILE *
-freopen(const char * __restrict file, const char * __restrict mode, FILE *fp)
+freopen(file, mode, fp)
+ const char * __restrict file;
+ const char * __restrict mode;
+ FILE *fp;
{
int f;
int dflags, flags, isopen, oflags, sverrno, wantfd;
-
- libc_hooks_will_read_cstring(file);
- libc_hooks_will_read_cstring(mode);
- libc_hooks_will_write(fp, sizeof(*fp));
if ((flags = __sflags(mode, &oflags)) == 0) {
sverrno = errno;
@@ -72,9 +70,10 @@
return (NULL);
}
- pthread_once(&__sdidinit, __sinit);
-
FLOCKFILE(fp);
+
+ if (!__sdidinit)
+ __sinit();
/*
* If the filename is a NULL pointer, the caller is asking us to
@@ -196,8 +195,8 @@
memset(&fp->_mbstate, 0, sizeof(mbstate_t));
if (f < 0) { /* did not get it after all */
+ __sfprelease(fp); /* set it free */
FUNLOCKFILE(fp);
- __sfprelease(fp); /* set it free */
errno = sverrno; /* restore in case _close clobbered */
return (NULL);
}
@@ -222,8 +221,8 @@
* open.
*/
if (f > SHRT_MAX) {
+ __sfprelease(fp); /* set it free */
FUNLOCKFILE(fp);
- __sfprelease(fp); /* set it free */
errno = EMFILE;
return (NULL);
}