fzy

terminal fuzzy finder picker

git clone https://9o.is/git/fzy.git

commit a73ce3c7d945c166c606fd9f2b4ed1a59ba1c51d
parent b5e1915aaa0cb425c0737b1968ed9947a977167a
Author: John Hawthorn <john.hawthorn@gmail.com>
Date:   Mon, 16 May 2016 19:58:04 -0700

Check errors when opening tty

Opening the tty may fail (for example if the wrong file is specified).
We now print an error and abort when this happens.

Diffstat:
MCHANGELOG.md | 1+
Mtty.c | 18++++++++++++++++--
2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md @@ -7,6 +7,7 @@ Features: Bugfixes: - Fixed last line of results not being cleared on exit + - Check errors when opening the TTY device ## 0.3 (April 25, 2016) diff --git a/tty.c b/tty.c @@ -20,12 +20,26 @@ void tty_close(tty_t *tty) { void tty_init(tty_t *tty, const char *tty_filename) { tty->fdin = open(tty_filename, O_RDONLY); + if (tty->fdin < 0) { + perror("Failed to open tty"); + exit(EXIT_FAILURE); + } + tty->fout = fopen(tty_filename, "w"); - if (setvbuf(tty->fout, NULL, _IOFBF, 4096)) + if (!tty->fout) { + perror("Failed to open tty"); + exit(EXIT_FAILURE); + } + + if (setvbuf(tty->fout, NULL, _IOFBF, 4096)) { perror("setvbuf"); + exit(EXIT_FAILURE); + } - if (tcgetattr(tty->fdin, &tty->original_termios)) + if (tcgetattr(tty->fdin, &tty->original_termios)) { perror("tcgetattr"); + exit(EXIT_FAILURE); + } struct termios new_termios = tty->original_termios;