- tty_settings->c_iflag &= ~((unsigned) (IGNBRK
- | PARMRK
- | INPCK
- | ISTRIP
- | INLCR
- | IGNCR
-#ifdef IUCLC
- | IUCLC
-#endif
-#ifdef IXANY
- | IXANY
-#endif
- | IXOFF));
-
- tty_settings->c_iflag |= (BRKINT
- | IGNPAR
- | ICRNL
- | IXON
-#ifdef IMAXBEL
- | IMAXBEL
-#endif
- );
-
- tty_settings->c_oflag &= ~((unsigned) (0
-#ifdef OLCUC
- | OLCUC
-#endif
-#ifdef OCRNL
- | OCRNL
-#endif
-#ifdef ONOCR
- | ONOCR
-#endif
-#ifdef ONLRET
- | ONLRET
-#endif
-#ifdef OFILL
- | OFILL
-#endif
-#ifdef OFDEL
- | OFDEL
-#endif
-#ifdef NLDLY
- | NLDLY
-#endif
-#ifdef CRDLY
- | CRDLY
-#endif
-#ifdef TABDLY
- | TABDLY
-#endif
-#ifdef BSDLY
- | BSDLY
-#endif
-#ifdef VTDLY
- | VTDLY
-#endif
-#ifdef FFDLY
- | FFDLY
-#endif
- ));
-
- tty_settings->c_oflag |= (OPOST
-#ifdef ONLCR
- | ONLCR
-#endif
- );
-
- tty_settings->c_cflag &= ~((unsigned) (CSIZE
- | CSTOPB
- | PARENB
- | PARODD
- | CLOCAL));
- tty_settings->c_cflag |= (CS8 | CREAD);
- tty_settings->c_lflag &= ~((unsigned) (ECHONL
- | NOFLSH
-#ifdef TOSTOP
- | TOSTOP
-#endif
-#ifdef ECHOPTR
- | ECHOPRT
-#endif
-#ifdef XCASE
- | XCASE
-#endif
- ));
-
- tty_settings->c_lflag |= (ISIG
- | ICANON
- | ECHO
- | ECHOE
- | ECHOK
-#ifdef ECHOCTL
- | ECHOCTL
-#endif
-#ifdef ECHOKE
- | ECHOKE
-#endif
- );
-#endif
+ clear_flags(tty_settings->c_iflag, (IGNBRK
+ | PARMRK
+ | INPCK
+ | ISTRIP
+ | INLCR
+ | IGNCR
+ | IUCLC
+ | IXANY
+ | IXOFF));
+
+ set_flags(tty_settings->c_iflag, (BRKINT
+ | IGNPAR
+ | ICRNL
+ | IXON
+ | IMAXBEL));
+
+ clear_flags(tty_settings->c_oflag, (0
+ | OLCUC
+ | OCRNL
+ | ONOCR
+ | ONLRET
+ | OFILL
+ | OFDEL
+ | NLDLY
+ | CRDLY
+ | TABDLY
+ | BSDLY
+ | VTDLY
+ | FFDLY));
+
+ set_flags(tty_settings->c_oflag, (OPOST
+ | ONLCR));
+
+ mask = (CSIZE | CSTOPB | PARENB | PARODD);
+#ifdef TIOCMGET
+ /* leave clocal alone if this appears to use a modem */
+ if (ioctl(fd, TIOCMGET, &modem_bits) == -1)
+ mask |= CLOCAL;
+#else
+ /* cannot check - use the behavior from tset */
+ mask |= CLOCAL;
+#endif
+ clear_flags(tty_settings->c_cflag, mask);
+
+ set_flags(tty_settings->c_cflag, (CS8 | CREAD));
+ clear_flags(tty_settings->c_lflag, (ECHONL
+ | NOFLSH
+ | TOSTOP
+ | ECHOPRT
+ | XCASE));
+
+ set_flags(tty_settings->c_lflag, (ISIG
+ | ICANON
+ | ECHO
+ | ECHOE
+ | ECHOK
+ | ECHOCTL
+ | ECHOKE));
+#endif /* TERMIOS */