summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/fgets.c
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2017-07-13 09:27:11 +0000
committerkib <kib@FreeBSD.org>2017-07-13 09:27:11 +0000
commit668d59a23068fc4a8aa806b914d95c71e903e92f (patch)
tree2479fb648c9c841acba46263712cd58a9c7dc384 /lib/libc/stdio/fgets.c
parent55a89eef51d5a91be65f136631688b2c5b3371ab (diff)
downloadFreeBSD-src-668d59a23068fc4a8aa806b914d95c71e903e92f.zip
FreeBSD-src-668d59a23068fc4a8aa806b914d95c71e903e92f.tar.gz
MFC r320472,r320508,r320509:
Make stdio deferred cancel-safe.
Diffstat (limited to 'lib/libc/stdio/fgets.c')
-rw-r--r--lib/libc/stdio/fgets.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/lib/libc/stdio/fgets.c b/lib/libc/stdio/fgets.c
index a2e39ed..95d0ad9 100644
--- a/lib/libc/stdio/fgets.c
+++ b/lib/libc/stdio/fgets.c
@@ -53,17 +53,17 @@ char *
fgets(char * __restrict buf, int n, FILE * __restrict fp)
{
size_t len;
- char *s;
+ char *s, *ret;
unsigned char *p, *t;
- FLOCKFILE(fp);
+ FLOCKFILE_CANCELSAFE(fp);
ORIENT(fp, -1);
if (n <= 0) { /* sanity check */
fp->_flags |= __SERR;
errno = EINVAL;
- FUNLOCKFILE(fp);
- return (NULL);
+ ret = NULL;
+ goto end;
}
s = buf;
@@ -76,8 +76,8 @@ fgets(char * __restrict buf, int n, FILE * __restrict fp)
if (__srefill(fp)) {
/* EOF/error: stop with partial or no line */
if (!__sfeof(fp) || s == buf) {
- FUNLOCKFILE(fp);
- return (NULL);
+ ret = NULL;
+ goto end;
}
break;
}
@@ -100,8 +100,8 @@ fgets(char * __restrict buf, int n, FILE * __restrict fp)
fp->_p = t;
(void)memcpy((void *)s, (void *)p, len);
s[len] = 0;
- FUNLOCKFILE(fp);
- return (buf);
+ ret = buf;
+ goto end;
}
fp->_r -= len;
fp->_p += len;
@@ -110,6 +110,8 @@ fgets(char * __restrict buf, int n, FILE * __restrict fp)
n -= len;
}
*s = 0;
- FUNLOCKFILE(fp);
- return (buf);
+ ret = buf;
+end:
+ FUNLOCKFILE_CANCELSAFE();
+ return (ret);
}
OpenPOWER on IntegriCloud