summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorTim J. Robbins <tjr@FreeBSD.org>2003-01-30 11:46:25 +0000
committerTim J. Robbins <tjr@FreeBSD.org>2003-01-30 11:46:25 +0000
commit21d4d23958555cce7b9346b2b8fc94abf479b48c (patch)
tree38634c3fccf7d9ff85bf2bca2d9308458cdc2302 /lib/libc
parentbf17219d59ddde98b8c8c0d1b040ac679e12c1f5 (diff)
Notes
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/stdio/gets.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/libc/stdio/gets.c b/lib/libc/stdio/gets.c
index 932b828629f1..e24727150de0 100644
--- a/lib/libc/stdio/gets.c
+++ b/lib/libc/stdio/gets.c
@@ -45,6 +45,8 @@ __FBSDID("$FreeBSD$");
#include <stdio.h>
#include <sys/cdefs.h>
#include "un-namespace.h"
+#include "libc_private.h"
+#include "local.h"
__warn_references(gets, "warning: this program uses gets(), which is unsafe.");
@@ -58,20 +60,22 @@ gets(buf)
static char w[] =
"warning: this program uses gets(), which is unsafe.\n";
- /* Orientation set by getchar(). */
-
+ FLOCKFILE(stdin);
+ ORIENT(stdin, -1);
if (!warned) {
(void) _write(STDERR_FILENO, w, sizeof(w) - 1);
warned = 1;
}
- for (s = buf; (c = getchar()) != '\n';)
+ for (s = buf; (c = __sgetc(stdin)) != '\n';)
if (c == EOF)
- if (s == buf)
+ if (s == buf) {
+ FUNLOCKFILE(stdin);
return (NULL);
- else
+ } else
break;
else
*s++ = c;
*s = 0;
+ FUNLOCKFILE(stdin);
return (buf);
}