Skip to content

Commit

Permalink
Simplify error handling of tty_putc()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Jenz Guenther authored and mptre committed Sep 18, 2017
1 parent 99d5a6f commit 1585928
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions pick.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1585928

Please sign in to comment.