public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* character device canonical mode
@ 2022-01-13 17:37 Norton Allen
  2022-01-14  9:34 ` Corinna Vinschen
  0 siblings, 1 reply; 2+ messages in thread
From: Norton Allen @ 2022-01-13 17:37 UTC (permalink / raw)
  To: cygwin

Apparently Cygwin does not support canonical mode on serial devices. On 
input canonical mode will wait for a newline before returning from a 
read(). The bit is cleared/ignored by tcsetattr() as demonstrated by a 
subsequent tcgetattr() in the test program below.

I am wondering if this is because of a fundamental difference between 
the Windows serial device model and POSIX or just because the 
appropriate mappings haven't been implemented. (I have studiously 
avoided Windows programming for decades, and Cygwin has been my enabler!)

My test program:

#include <termios.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>

void check_rv(int rv, const char *where) {
   if (rv) {
     printf("Error %s: %d %s\n", where, errno, strerror(errno));
     exit(1);
   }
}

int main(int argc, char **argv) {
   termios termios_p;
   if (argc != 2) {
     printf("Must specify a serial device\n");
     exit(1);
   }
   int fd = open(argv[1], O_RDWR | O_NONBLOCK);
   check_rv(fd == -1, "opening serial device");
   check_rv(tcgetattr(fd, &termios_p), "from tcgetattr()");
   printf("c_lflag = 0x%X after open\n", termios_p.c_lflag);
   termios_p.c_lflag |= ICANON;
   printf("c_lflag = 0x%X to pass to tcsetattr()\n", termios_p.c_lflag);
   check_rv(tcsetattr(fd, TCSANOW, &termios_p), "from tcsetattr()");
   check_rv(tcgetattr(fd, &termios_p), "from 2nd tcgetattr()");
   printf("c_lflag = 0x%X after tcsetattr()\n", termios_p.c_lflag);
   return 0;
}


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

* Re: character device canonical mode
  2022-01-13 17:37 character device canonical mode Norton Allen
@ 2022-01-14  9:34 ` Corinna Vinschen
  0 siblings, 0 replies; 2+ messages in thread
From: Corinna Vinschen @ 2022-01-14  9:34 UTC (permalink / raw)
  To: cygwin

On Jan 13 12:37, Norton Allen wrote:
> Apparently Cygwin does not support canonical mode on serial devices.

I just checked, you're right, ICANON has never been implemented for
serial I/O.  The code hasn't seen a lot of love since its inception.
It has been added pre-2000 mainly to support GDB remote debugging
of embedded systems.


Corinna

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

end of thread, other threads:[~2022-01-14  9:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-13 17:37 character device canonical mode Norton Allen
2022-01-14  9:34 ` 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).