From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2210) id C5AD13853811; Mon, 12 Jul 2021 20:26:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C5AD13853811 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Ken Brown To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: cfsetspeed: allow speed to be a numerical baud rate X-Act-Checkin: newlib-cygwin X-Git-Author: Ken Brown X-Git-Refname: refs/heads/master X-Git-Oldrev: 91f99d323b39dc0c06c40038791db9861d4b76b9 X-Git-Newrev: cee03513d80568a68cf1be2ca70385afdcaaaec3 Message-Id: <20210712202655.C5AD13853811@sourceware.org> Date: Mon, 12 Jul 2021 20:26:55 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Jul 2021 20:26:55 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=cee03513d80568a68cf1be2ca70385afdcaaaec3 commit cee03513d80568a68cf1be2ca70385afdcaaaec3 Author: Ken Brown Date: Sun Jul 11 07:04:58 2021 -0400 Cygwin: cfsetspeed: allow speed to be a numerical baud rate The Linux man page for cfsetspeed(3) specifies that the speed argument must be one of the constants Bnnn (e.g., B9600) defined in termios.h. But Linux in fact allows the speed to be the numerical baud rate (e.g., 9600). For consistency with Linux, we now do the same. Addresses: https://cygwin.com/pipermail/cygwin/2021-July/248887.html Diff: --- winsup/cygwin/release/3.2.1 | 4 +++ winsup/cygwin/termios.cc | 59 +++++++++++++++++++++++++++++++++++++++++++++ winsup/doc/new-features.xml | 11 ++++++--- 3 files changed, 71 insertions(+), 3 deletions(-) diff --git a/winsup/cygwin/release/3.2.1 b/winsup/cygwin/release/3.2.1 index 6ebe68fa6..99c65ce30 100644 --- a/winsup/cygwin/release/3.2.1 +++ b/winsup/cygwin/release/3.2.1 @@ -5,6 +5,10 @@ What's new: What changed: ------------- +- The speed argument to cfsetspeed(3) can now be a numerical baud rate + rather than a Bnnn constant, as on Linux. + Addresses: https://cygwin.com/pipermail/cygwin/2021-July/248887.html + Bug Fixes --------- diff --git a/winsup/cygwin/termios.cc b/winsup/cygwin/termios.cc index b29a64af2..ee9cd23b7 100644 --- a/winsup/cygwin/termios.cc +++ b/winsup/cygwin/termios.cc @@ -325,12 +325,71 @@ cfsetispeed (struct termios *in_tp, speed_t speed) return res; } +struct speed_struct +{ + speed_t value; + speed_t internal; +}; + +static const struct speed_struct speeds[] = + { + { 0, B0 }, + { 50, B50 }, + { 75, B75 }, + { 110, B110 }, + { 134, B134 }, + { 150, B150 }, + { 200, B200 }, + { 300, B300 }, + { 600, B600 }, + { 1200, B1200 }, + { 1800, B1800 }, + { 2400, B2400 }, + { 4800, B4800 }, + { 9600, B9600 }, + { 19200, B19200 }, + { 38400, B38400 }, + { 57600, B57600 }, + { 115200, B115200 }, + { 128000, B128000 }, + { 230400, B230400 }, + { 256000, B256000 }, + { 460800, B460800 }, + { 500000, B500000 }, + { 576000, B576000 }, + { 921600, B921600 }, + { 1000000, B1000000 }, + { 1152000, B1152000 }, + { 1500000, B1500000 }, + { 2000000, B2000000 }, + { 2500000, B2500000 }, + { 3000000, B3000000 }, + }; + +/* Given a numerical baud rate (e.g., 9600), convert it to a Bnnn + constant (e.g., B9600). */ +static speed_t +convert_speed (speed_t speed) +{ + for (size_t i = 0; i < sizeof speeds / sizeof speeds[0]; i++) + { + if (speed == speeds[i].internal) + return speed; + else if (speed == speeds[i].value) + return speeds[i].internal; + } + return speed; +} + /* cfsetspeed: 4.4BSD */ +/* Following Linux (undocumented), allow speed to be a numerical baud rate. */ extern "C" int cfsetspeed (struct termios *in_tp, speed_t speed) { struct termios *tp = __tonew_termios (in_tp); int res; + + speed = convert_speed (speed); /* errors come only from unsupported baud rates, so setspeed() would return identical results in both calls */ if ((res = setspeed (tp->c_ospeed, speed)) == 0) diff --git a/winsup/doc/new-features.xml b/winsup/doc/new-features.xml index 5ec36e409..b58872935 100644 --- a/winsup/doc/new-features.xml +++ b/winsup/doc/new-features.xml @@ -71,9 +71,14 @@ facl(2) now fails with EBADF on a file opened with O_PATH. -- Allow to start Windows Store executables via their "app execution - aliases". Handle these aliases (which are special reparse points) - as symlinks to the actual executables. +Allow to start Windows Store executables via their "app execution +aliases". Handle these aliases (which are special reparse points) +as symlinks to the actual executables. + + + +The speed argument to cfsetspeed(3) can now be a numerical baud rate +rather than a Bnnn constant, as on Linux.