Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/games/caesar games/caesar: fix error handling for I/O



details:   https://anonhg.NetBSD.org/src/rev/deb2619ee908
branches:  trunk
changeset: 1026292:deb2619ee908
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Nov 16 20:42:47 2021 +0000

description:
games/caesar: fix error handling for I/O

The '!= 0' is needed for an upcoming fix to lint's strict bool mode.

The additional text in the error messages is necessary because errx only
outputs the given string, with no details from errno.  Since ferror does
not set errno, no such details are available, so just output a generic
message, which is still better than just "caesar: <stdout>".

diffstat:

 games/caesar/caesar.c |  12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diffs (37 lines):

diff -r adf8d0a8985f -r deb2619ee908 games/caesar/caesar.c
--- a/games/caesar/caesar.c     Tue Nov 16 18:37:24 2021 +0000
+++ b/games/caesar/caesar.c     Tue Nov 16 20:42:47 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: caesar.c,v 1.23 2021/05/01 20:21:25 rillig Exp $       */
+/*     $NetBSD: caesar.c,v 1.24 2021/11/16 20:42:47 rillig Exp $       */
 
 /*
  * Copyright (c) 1989, 1993
@@ -48,7 +48,7 @@
 #if 0
 static char sccsid[] = "@(#)caesar.c   8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: caesar.c,v 1.23 2021/05/01 20:21:25 rillig Exp $");
+__RCSID("$NetBSD: caesar.c,v 1.24 2021/11/16 20:42:47 rillig Exp $");
 #endif
 #endif /* not lint */
 
@@ -203,14 +203,14 @@
                /* NOTREACHED */
        }
 
-       if (ferror(stdin)) {
-               errx(EXIT_FAILURE, "<stdin>");
+       if (ferror(stdin) != 0) {
+               errx(EXIT_FAILURE, "<stdin>: read error");
                /* NOTREACHED */
        }
 
        (void)fflush(stdout);
-       if (ferror(stdout)) {
-               errx(EXIT_FAILURE, "<stdout>");
+       if (ferror(stdout) != 0) {
+               errx(EXIT_FAILURE, "<stdout>: write error");
                /* NOTREACHED */
        }
 



Home | Main Index | Thread Index | Old Index