From: op Date: Mon, 8 Aug 2022 17:54:08 +0000 (+0000) Subject: fully switch quiz(6) to getline; diff from Ben Fuller (ben [at] bvnf X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=9e6678dc8fc3c990b80a99231a6cfa6e47eddd2f;p=openbsd fully switch quiz(6) to getline; diff from Ben Fuller (ben [at] bvnf space), ok millert@ --- diff --git a/games/quiz/quiz.c b/games/quiz/quiz.c index d4fd0604e0d..38e629b4cda 100644 --- a/games/quiz/quiz.c +++ b/games/quiz/quiz.c @@ -1,4 +1,4 @@ -/* $OpenBSD: quiz.c,v 1.31 2021/03/11 21:18:25 naddy Exp $ */ +/* $OpenBSD: quiz.c,v 1.32 2022/08/08 17:54:08 op Exp $ */ /* $NetBSD: quiz.c,v 1.9 1995/04/22 10:16:58 cgd Exp $ */ /*- @@ -224,12 +224,16 @@ quiz(void) { QE *qp; int i; - size_t len; + size_t size; + ssize_t len; u_int guesses, rights, wrongs; int next; char *answer, *t, question[LINE_SZ]; const char *s; + size = 0; + answer = NULL; + guesses = rights = wrongs = 0; for (;;) { if (qsize == 0) @@ -278,7 +282,7 @@ quiz(void) qp->q_asked = TRUE; (void)printf("%s?\n", question); for (;; ++guesses) { - if ((answer = fgetln(stdin, &len)) == NULL || + if ((len = getline(&answer, &size, stdin)) == -1 || answer[len - 1] != '\n') { score(rights, wrongs, guesses); exit(0); @@ -302,6 +306,7 @@ quiz(void) } } score(rights, wrongs, guesses); + free(answer); } const char *