summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/gets.c
diff options
context:
space:
mode:
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