public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH] Cygwin: cfsetspeed: allow speed to be a numerical baud rate
@ 2021-07-12 12:57 Ken Brown
  2021-07-12 18:49 ` Corinna Vinschen
  0 siblings, 1 reply; 2+ messages in thread
From: Ken Brown @ 2021-07-12 12:57 UTC (permalink / raw)
  To: cygwin-patches

[-- 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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Cygwin: cfsetspeed: allow speed to be a numerical baud rate
  2021-07-12 12:57 [PATCH] Cygwin: cfsetspeed: allow speed to be a numerical baud rate Ken Brown
@ 2021-07-12 18:49 ` Corinna Vinschen
  0 siblings, 0 replies; 2+ messages in thread
From: Corinna Vinschen @ 2021-07-12 18:49 UTC (permalink / raw)
  To: cygwin-patches

On Jul 12 08:57, Ken Brown wrote:
> 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

> >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(-)

LGTM, please push.


Thanks,
Corinna


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-07-12 18:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-12 12:57 [PATCH] Cygwin: cfsetspeed: allow speed to be a numerical baud rate Ken Brown
2021-07-12 18:49 ` Corinna Vinschen

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).