summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/freopen.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/stdio/freopen.c')
-rw-r--r--lib/libc/stdio/freopen.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/lib/libc/stdio/freopen.c b/lib/libc/stdio/freopen.c
index e0104c8..3d6cc89 100644
--- a/lib/libc/stdio/freopen.c
+++ b/lib/libc/stdio/freopen.c
@@ -68,7 +68,7 @@ freopen(const char * __restrict file, const char * __restrict mode,
return (NULL);
}
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
if (!__sdidinit)
__sinit();
@@ -81,24 +81,24 @@ freopen(const char * __restrict file, const char * __restrict mode,
if (file == NULL) {
/* See comment below regarding freopen() of closed files. */
if (fp->_flags == 0) {
- FUNLOCKFILE(fp);
errno = EINVAL;
- return (NULL);
+ fp = NULL;
+ goto end;
}
if ((dflags = _fcntl(fp->_file, F_GETFL)) < 0) {
sverrno = errno;
fclose(fp);
- FUNLOCKFILE(fp);
errno = sverrno;
- return (NULL);
+ fp = NULL;
+ goto end;
}
/* Work around incorrect O_ACCMODE. */
if ((dflags & O_ACCMODE) != O_RDWR &&
(dflags & (O_ACCMODE | O_EXEC)) != (oflags & O_ACCMODE)) {
fclose(fp);
- FUNLOCKFILE(fp);
errno = EBADF;
- return (NULL);
+ fp = NULL;
+ goto end;
}
if (fp->_flags & __SWR)
(void) __sflush(fp);
@@ -108,9 +108,9 @@ freopen(const char * __restrict file, const char * __restrict mode,
if (_fcntl(fp->_file, F_SETFL, dflags) < 0) {
sverrno = errno;
fclose(fp);
- FUNLOCKFILE(fp);
errno = sverrno;
- return (NULL);
+ fp = NULL;
+ goto end;
}
}
if (oflags & O_TRUNC)
@@ -193,9 +193,9 @@ finish:
if (isopen)
(void) (*fp->_close)(fp->_cookie);
fp->_flags = 0; /* set it free */
- FUNLOCKFILE(fp);
errno = sverrno; /* restore in case _close clobbered */
- return (NULL);
+ fp = NULL;
+ goto end;
}
/*
@@ -221,9 +221,9 @@ finish:
*/
if (f > SHRT_MAX) {
fp->_flags = 0; /* set it free */
- FUNLOCKFILE(fp);
errno = EMFILE;
- return (NULL);
+ fp = NULL;
+ goto end;
}
fp->_flags = flags;
@@ -245,6 +245,7 @@ finish:
fp->_flags2 |= __S2OAP;
(void) _sseek(fp, (fpos_t)0, SEEK_END);
}
- FUNLOCKFILE(fp);
+end:
+ FUNLOCKFILE_CANCELSAFE();
return (fp);
}
OpenPOWER on IntegriCloud