From 1585928500bd2da0d8597fe13d261a5830a84618 Mon Sep 17 00:00:00 2001 From: Jenz Guenther Date: Sun, 17 Sep 2017 12:46:54 +0200 Subject: [PATCH] Simplify error handling of tty_putc() The error handling can be done inside tty_putc() even tho it's used as the putfunc argument to tputs() since the latter does not rely on getting EOF back. Quoting POSIX[1]: The user-supplied function putfunc (specified as an argument to tputs()) is either putchar() or some other function with the same prototype. The tputs() function ignores the return value of putfunc. [1] http://pubs.opengroup.org/onlinepubs/7908799/xcurses/putp.html --- pick.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/pick.c b/pick.c index ec4e9426..764e428a 100644 --- a/pick.c +++ b/pick.c @@ -318,8 +318,7 @@ selected_choice(void) * column will be also be cleared. Therefore, move down * one line before clearing the screen. */ - if (tty_putc('\n') == EOF) - err(1, "tty_putc"); + tty_putc('\n'); tty_putp(clr_eos, 1); tty_putp(tty_parm1(parm_up_cursor, (choices_count - yscroll) + 1), 1); @@ -684,7 +683,10 @@ tty_init(void) int tty_putc(int c) { - return putc(c, tty_out); + if (putc(c, tty_out) == EOF) + err(1, "putc"); + + return c; } __dead void @@ -789,8 +791,7 @@ print_line(const char *str, size_t len, int standout, col += width; for (; width > 0; width--) - if (tty_putc(' ') == ERR) - err(1, "tty_putc"); + tty_putc(' '); i++; continue; @@ -801,8 +802,7 @@ print_line(const char *str, size_t len, int standout, * descriptions are enabled. */ if (str[i] == '\0') { - if (tty_putc(' ') == ERR) - err(1, "tty_putc"); + tty_putc(' '); i++, col++; continue; @@ -838,12 +838,10 @@ print_line(const char *str, size_t len, int standout, col += width; for (; nbytes > 0; nbytes--, i++) - if (tty_putc(str[i]) == EOF) - err(1, "tty_putc"); + tty_putc(str[i]); } for (; col < tty_columns; col++) - if (tty_putc(' ') == EOF) - err(1, "tty_putc"); + tty_putc(' '); /* * If exit_underline is greater than columns the underline attribute