=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/msgs/Attic/msgs.c,v retrieving revision 1.31 retrieving revision 1.32 diff -u -r1.31 -r1.32 --- src/usr.bin/msgs/Attic/msgs.c 2007/05/17 10:59:26 1.31 +++ src/usr.bin/msgs/Attic/msgs.c 2007/09/09 12:36:38 1.32 @@ -1,4 +1,4 @@ -/* $OpenBSD: msgs.c,v 1.31 2007/05/17 10:59:26 moritz Exp $ */ +/* $OpenBSD: msgs.c,v 1.32 2007/09/09 12:36:38 chl Exp $ */ /* $NetBSD: msgs.c,v 1.7 1995/09/28 06:57:40 tls Exp $ */ /*- @@ -40,7 +40,7 @@ #if 0 static char sccsid[] = "@(#)msgs.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: msgs.c,v 1.31 2007/05/17 10:59:26 moritz Exp $"; +static char rcsid[] = "$OpenBSD: msgs.c,v 1.32 2007/09/09 12:36:38 chl Exp $"; #endif #endif /* not lint */ @@ -75,6 +75,7 @@ #include #include #include +#include #include #include #include @@ -371,7 +372,8 @@ printf("Message %d:\nFrom %s %sSubject: ", nextmsg, pw->pw_name, ctime(&t)); fflush(stdout); - fgets(inbuf, sizeof inbuf, stdin); + if (fgets(inbuf, sizeof inbuf, stdin) == NULL) + errx(1, "could not read input"); putchar('\n'); fflush(stdout); fprintf(newmsg, "From %s %sSubject: %s\n", @@ -380,8 +382,7 @@ } else blankline = seensubj = NO; for (;;) { - fgets(inbuf, sizeof inbuf, stdin); - if (feof(stdin) || ferror(stdin)) + if (fgets(inbuf, sizeof inbuf, stdin) == NULL) break; blankline = (blankline || (inbuf[0] == '\n')); seensubj = (seensubj || @@ -752,9 +753,9 @@ printf("%s ", prompt); fflush(stdout); intrpflg = NO; - (void) fgets(inbuf, sizeof inbuf, stdin); - if ((n = strlen(inbuf)) > 0 && inbuf[n - 1] == '\n') - inbuf[n - 1] = '\0'; + if (fgets(inbuf, sizeof inbuf, stdin) == NULL) + errx(1, "could not read input"); + inbuf[strcspn(inbuf, "\n")] = '\0'; if (intrpflg) inbuf[0] = 'x';