From 4c7a1a5eac3c6afad6a333615e4033f999638a85 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sun, 11 Dec 2022 19:49:44 +0100 Subject: src: rearrange the standard baud rate setting block Let's rearrange the block so that the error is placed at the end. This will help support OS-specific alternatives. --- src/bt.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/bt.c b/src/bt.c index 5e759ff..7055818 100644 --- a/src/bt.c +++ b/src/bt.c @@ -544,14 +544,18 @@ int set_port(int fd, int baud) //tio.c_cflag &= ~(CBAUD | (CBAUD << IBSHIFT)); //tio.c_cflag |= BOTHER | (BOTHER << IBSHIFT); baud_flag = baud_encode(baud); + if (baud_flag != ~0) { + /* this standard baud rate is supported */ + if (cfsetospeed(&tio, baud_flag) == -1) + return -1; + if (cfsetispeed(&tio, baud_flag) == -1) + return -1; + } + if (baud_flag == ~0) { /* baud rate not found */ errno = EINVAL; return -1; } - if (cfsetospeed(&tio, baud_flag) == -1) - return -1; - if (cfsetispeed(&tio, baud_flag) == -1) - return -1; } tio.c_iflag = 0; -- 2.17.5