public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Ken Brown <kbrown@cornell.edu>
To: cygwin <cygwin@cygwin.com>
Subject: cfsetspeed is not consistent with Linux
Date: Sun, 11 Jul 2021 12:33:42 -0400	[thread overview]
Message-ID: <466e52fb-bda0-b5c0-f201-033a85e8de29@cornell.edu> (raw)

While investigating an emacs bug 
(https://debbugs.gnu.org/cgi/bugreport.cgi?bug=49524), I noticed a difference in 
the behavior of cfsetspeed(3) on Cygwin and Linux.  I'm not sure we should "fix" 
this, because Cygwin's behavior is consistent with the Linux man page, and 
Linux's behavior is not.  But I thought I should point it out for the sake of 
discussion, because Cygwin generally tries to emulate Linux.  Here are the details:

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).  Test case:

$ cat cfsetspeed_test.c
#include <termios.h>
#include <stdio.h>

int
main ()
{
   struct termios tp;

   printf ("Calling cfsetspeed with speed B9600\n");
   if (cfsetspeed (&tp, B9600) < 0)
     perror ("cfsetspeed");
   else
     printf ("cfgetispeed reports speed %u\n", cfgetispeed (&tp));
   printf ("Calling cfsetspeed with speed 9600\n");
   if (cfsetspeed (&tp, 9600) < 0)
     perror ("cfsetspeed");
   else
     printf ("cfgetispeed reports speed %u\n", cfgetispeed (&tp));
}

$ gcc cfsetspeed_test.c

$ ./a.out
Calling cfsetspeed with speed B9600
cfgetispeed reports speed 13
Calling cfsetspeed with speed 9600
cfgetispeed reports speed 13

On Cygwin, however, the output of the same program is:

$ ./a
Calling cfsetspeed with speed B9600
cfgetispeed reports speed 13
Calling cfsetspeed with speed 9600
cfsetspeed: Invalid argument

If we decide that Cygwin should emulate Linux here, it would be a simple matter 
to copy the glibc code, which checks whether the speed is a numerical baud rate 
and, if so, converts it to a Bnnn constant.

Ken

             reply	other threads:[~2021-07-11 16:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-11 16:33 Ken Brown [this message]
2021-07-12  8:16 ` 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=466e52fb-bda0-b5c0-f201-033a85e8de29@cornell.edu \
    --to=kbrown@cornell.edu \
    --cc=cygwin@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).