public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
From: Ken Brown <kbrown@cornell.edu>
To: cygwin-patches <cygwin-patches@cygwin.com>
Subject: [PATCH] Cygwin: cfsetspeed: allow speed to be a numerical baud rate
Date: Mon, 12 Jul 2021 08:57:51 -0400	[thread overview]
Message-ID: <d2c4a9cf-6ab0-26ca-596f-bdd7c0eec227@cornell.edu> (raw)

[-- Attachment #1: Type: text/plain, Size: 158 bytes --]

The attached patch addresses

   https://cygwin.com/pipermail/cygwin/2021-July/248887.html

I don't really understand the GPL issue, but I hope it's OK.

Ken

[-- Attachment #2: 0001-Cygwin-cfsetspeed-allow-speed-to-be-a-numerical-baud.patch --]
[-- Type: text/plain, Size: 4003 bytes --]

From 0321ecd99050ad702a528797af48ea4d01531508 Mon Sep 17 00:00:00 2001
From: Ken Brown <kbrown@cornell.edu>
Date: Sun, 11 Jul 2021 07:04:58 -0400
Subject: [PATCH] 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
---
 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.
 </para></listitem>
 
 <listitem><para>
-- 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.
+</para></listitem>
+
+<listitem><para>
+The speed argument to cfsetspeed(3) can now be a numerical baud rate
+rather than a Bnnn constant, as on Linux.
 </para></listitem>
 
 </itemizedlist>
-- 
2.32.0


             reply	other threads:[~2021-07-12 12:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-12 12:57 Ken Brown [this message]
2021-07-12 18:49 ` Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d2c4a9cf-6ab0-26ca-596f-bdd7c0eec227@cornell.edu \
    --to=kbrown@cornell.edu \
    --cc=cygwin-patches@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).