summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Janzen <pjanzen@cvs.openbsd.org>2000-09-23 02:58:41 +0000
committerPaul Janzen <pjanzen@cvs.openbsd.org>2000-09-23 02:58:41 +0000
commit72ac17839d819818408469ecafad2cae36fbb3e8 (patch)
tree10077ae1efc8e3595c94215fdaeb0423180c9f32
parentafd385d5be3864b929cbda3de31f9523c6fd9a24 (diff)
die() if stdin disappears, rather than just exiting; jsm@netbsd.org.
dump the end of the buffer if an input line was too long.
-rw-r--r--games/battlestar/getcom.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/games/battlestar/getcom.c b/games/battlestar/getcom.c
index badd560e799..113b3906442 100644
--- a/games/battlestar/getcom.c
+++ b/games/battlestar/getcom.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getcom.c,v 1.7 2000/09/17 21:28:33 pjanzen Exp $ */
+/* $OpenBSD: getcom.c,v 1.8 2000/09/23 02:58:40 pjanzen Exp $ */
/* $NetBSD: getcom.c,v 1.3 1995/03/21 15:07:30 cgd Exp $ */
/*
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)getcom.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: getcom.c,v 1.7 2000/09/17 21:28:33 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: getcom.c,v 1.8 2000/09/23 02:58:40 pjanzen Exp $";
#endif
#endif /* not lint */
@@ -53,10 +53,8 @@ getcom(buf, size, prompt, error)
for (;;) {
fputs(prompt, stdout);
if (fgets(buf, size, stdin) == 0) {
- if (feof(stdin)) {
- printf("user closed input stream, quitting...\n");
- exit(0);
- }
+ if (feof(stdin))
+ die(0);
clearerr(stdin);
continue;
}
@@ -67,6 +65,12 @@ getcom(buf, size, prompt, error)
if (error)
puts(error);
}
+ /* If we didn't get to the end of the line, don't read it in next time */
+ if (buf[strlen(buf) - 1] != '\n') {
+ int i;
+ while ((i = fgetc(stdin)) != '\n' && i != EOF)
+ ;
+ }
return (buf);
}