+#define check(statement) \
+ do { \
+ int err = 0; \
+ if ((err = (statement))) { \
+ syslog(2, #statement " failed: %d", err); \
+ return err; \
+ } \
+ } while (0)
+
+int
+init_termios(int fd) {
+ struct termios term;
+
+ check(tcgetattr(fd, &term));
+
+ term.c_lflag = ICANON | IEXTEN | ISIG | ECHO | ECHOE | ECHONL;
+ term.c_iflag = ICRNL | IGNBRK;
+ term.c_oflag = ONLCR | OPOST;
+ term.c_cflag = CREAD | CLOCAL | CS8 | CPARENB;
+ term.c_cc[VERASE] = 0x08;
+
+ check(tcsetattr(fd, 0, &term));
+
+ return 0;
+}
+