Opening the tty may fail (for example if the wrong file is specified).
We now print an error and abort when this happens.
| ... | ... |
@@ -20,12 +20,26 @@ void tty_close(tty_t *tty) {
|
| 20 | 20 |
|
| 21 | 21 |
void tty_init(tty_t *tty, const char *tty_filename) {
|
| 22 | 22 |
tty->fdin = open(tty_filename, O_RDONLY); |
| 23 |
+ if (tty->fdin < 0) {
|
|
| 24 |
+ perror("Failed to open tty");
|
|
| 25 |
+ exit(EXIT_FAILURE); |
|
| 26 |
+ } |
|
| 27 |
+ |
|
| 23 | 28 |
tty->fout = fopen(tty_filename, "w"); |
| 24 |
- if (setvbuf(tty->fout, NULL, _IOFBF, 4096)) |
|
| 29 |
+ if (!tty->fout) {
|
|
| 30 |
+ perror("Failed to open tty");
|
|
| 31 |
+ exit(EXIT_FAILURE); |
|
| 32 |
+ } |
|
| 33 |
+ |
|
| 34 |
+ if (setvbuf(tty->fout, NULL, _IOFBF, 4096)) {
|
|
| 25 | 35 |
perror("setvbuf");
|
| 36 |
+ exit(EXIT_FAILURE); |
|
| 37 |
+ } |
|
| 26 | 38 |
|
| 27 |
- if (tcgetattr(tty->fdin, &tty->original_termios)) |
|
| 39 |
+ if (tcgetattr(tty->fdin, &tty->original_termios)) {
|
|
| 28 | 40 |
perror("tcgetattr");
|
| 41 |
+ exit(EXIT_FAILURE); |
|
| 42 |
+ } |
|
| 29 | 43 |
|
| 30 | 44 |
struct termios new_termios = tty->original_termios; |
| 31 | 45 |
|