gatchat/gattty.c | 26 +++++++++++++++++++++----- 1 files changed, 21 insertions(+), 5 deletions(-) diff --git a/gatchat/gattty.c b/gatchat/gattty.c index ed0fadf..aa9d3a4 100644 --- a/gatchat/gattty.c +++ b/gatchat/gattty.c @@ -97,6 +97,19 @@ static gboolean set_baud(const char *baud, struct termios *ti) return TRUE; } +static gboolean set_read(value, &ti) +{ + if (g_str_equal(bits, "off")) + ti->c_cflag &= ~(CREAD); + else if (g_str_equal(bits, "on")) + ti->c_cflag |= CREAD; + else + return FALSE; + + return TRUE; + +} + static gboolean set_stop_bits(const char *bits, struct termios *ti) { if (g_str_equal(bits, "1")) @@ -186,6 +199,12 @@ static int open_device(const char *tty, GHashTable *options) memset(&ti, 0, sizeof(ti)); cfmakeraw(&ti); + fd = open(tty, O_RDWR | O_NOCTTY | O_NONBLOCK); + if (fd < 0) + return -1; + + tcgetattr(fd,&ti); + if (options) { GHashTableIter iter; const char *key; @@ -210,17 +229,14 @@ static int open_device(const char *tty, GHashTable *options) ok = set_rtscts(value, &ti); else if (g_str_equal(key, "local")) ok = set_local(value, &ti); + else if (g_str_equal(key, "read")) + ok = set_read(value, &ti); if (ok == FALSE) return -1; } } - fd = open(tty, O_RDWR | O_NOCTTY | O_NONBLOCK); - if (fd < 0) - return -1; - - tcgetattr(fd,&ti); tcflush(fd, TCIOFLUSH); tcsetattr(fd, TCSANOW, &ti);