diff options
| author | Konstantin Belousov <kib@FreeBSD.org> | 2017-07-17 14:09:34 +0000 |
|---|---|---|
| committer | Konstantin Belousov <kib@FreeBSD.org> | 2017-07-17 14:09:34 +0000 |
| commit | 1aad44dbd7ec77df8137d3e510d0a200256a02d3 (patch) | |
| tree | c44ef6d528ce250c6d8c2c124a1d91a8523a54a1 /lib/libc/stdio/gets.c | |
| parent | 5d49799eb6c6c0710b12180fb899fd0ea8f69639 (diff) | |
Notes
Diffstat (limited to 'lib/libc/stdio/gets.c')
| -rw-r--r-- | lib/libc/stdio/gets.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/libc/stdio/gets.c b/lib/libc/stdio/gets.c index c9438515323a..f31221a74c63 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); } |
