summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/gets.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/gets.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/gets.c')
-rw-r--r--lib/libc/stdio/gets.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/libc/stdio/gets.c b/lib/libc/stdio/gets.c
index c943851..f31221a 100644
--- a/lib/libc/stdio/gets.c
+++ b/lib/libc/stdio/gets.c
@@ -50,27 +50,30 @@ char *
gets(char *buf)
{
int c;
- char *s;
+ char *s, *ret;
static int warned;
static const char w[] =
"warning: this program uses gets(), which is unsafe.\n";
- FLOCKFILE(stdin);
+ FLOCKFILE_CANCELSAFE(stdin);
ORIENT(stdin, -1);
if (!warned) {
(void) _write(STDERR_FILENO, w, sizeof(w) - 1);
warned = 1;
}
- for (s = buf; (c = __sgetc(stdin)) != '\n';)
+ for (s = buf; (c = __sgetc(stdin)) != '\n'; ) {
if (c == EOF)
if (s == buf) {
- FUNLOCKFILE(stdin);
- return (NULL);
+ ret = NULL;
+ goto end;
} else
break;
else
*s++ = c;
+ }
*s = 0;
- FUNLOCKFILE(stdin);
- return (buf);
+ ret = buf;
+end:
+ FUNLOCKFILE_CANCELSAFE();
+ return (ret);
}
OpenPOWER on IntegriCloud