summaryrefslogtreecommitdiffstats
path: root/monop
diff options
context:
space:
mode:
authordholland <dholland@NetBSD.org>2008-02-23 20:12:15 +0000
committerdholland <dholland@NetBSD.org>2008-02-23 20:12:15 +0000
commit5bca13d3536be2816d3c9452b0ca2e4081c3bb55 (patch)
tree422f68ee18b7d8547613a550a4eed12373726376 /monop
parent2a802b1b97c90f057ddfb32bc583ca0c928bef8d (diff)
downloadbsdgames-darwin-5bca13d3536be2816d3c9452b0ca2e4081c3bb55.tar.gz
bsdgames-darwin-5bca13d3536be2816d3c9452b0ca2e4081c3bb55.tar.zst
bsdgames-darwin-5bca13d3536be2816d3c9452b0ca2e4081c3bb55.zip
Sanity fixes for input buffer handling. From OpenBSD
Diffstat (limited to 'monop')
-rw-r--r--monop/getinp.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/monop/getinp.c b/monop/getinp.c
index 4e1c2881..92546ac6 100644
--- a/monop/getinp.c
+++ b/monop/getinp.c
@@ -1,4 +1,4 @@
-/* $NetBSD: getinp.c,v 1.16 2008/02/19 09:45:02 dholland Exp $ */
+/* $NetBSD: getinp.c,v 1.17 2008/02/23 20:12:15 dholland Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)getinp.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: getinp.c,v 1.16 2008/02/19 09:45:02 dholland Exp $");
+__RCSID("$NetBSD: getinp.c,v 1.17 2008/02/23 20:12:15 dholland Exp $");
#endif
#endif /* not lint */
@@ -55,18 +55,13 @@ getinp(prompt, lst)
{
int i, n_match, match = 0;
char *sp;
- int c;
for (;;) {
printf("%s", prompt);
- for (sp = buf; (c = getchar()) != '\n'; ) {
- if (c == -1)
- return 0;
- *sp = c;
- if (sp != buf || *sp != ' ')
- sp++;
+ fgets(buf, sizeof(buf), stdin);
+ if (feof(stdin)) {
+ return 0;
}
- *sp = c;
if (buf[0] == '?' && buf[1] == '\n') {
printf("Valid inputs are: ");
for (i = 0, match = 18; lst[i]; i++) {
@@ -88,7 +83,8 @@ getinp(prompt, lst)
}
continue;
}
- *sp = '\0';
+ if ((sp = strchr(buf, '\n')) != NULL)
+ *sp = '\0';
for (sp = buf; *sp; sp++)
*sp = tolower((unsigned char)*sp);
for (i = n_match = 0; lst[i]; i++)