summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--tty.c18
2 files changed, 17 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8255b7a..4b9fc9b 100644
--- 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
index 11c6de4..bf2bc83 100644
--- 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;