Skip to content

Commit

Permalink
Fix flag assignment in pal_termios (#108409)
Browse files Browse the repository at this point in the history
* Use bitwise OR when setting IGNBRK in pal_termios

* Address feedback
  • Loading branch information
am11 authored Oct 4, 2024
1 parent faaba7f commit a7f96cb
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/native/libs/System.IO.Ports.Native/pal_termios.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,22 +437,21 @@ int32_t SystemIoPortsNative_TermiosReset(intptr_t handle, int32_t speed, int32_t

if (tcgetattr(fd, &term) < 0)
{
return -1;
return -1;
}

#if HAVE_CFMAKERAW
cfmakeraw(&term);
#else
term.c_iflag &= ~(IMAXBEL|IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
term.c_iflag &= ~(IMAXBEL | IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
term.c_oflag &= ~OPOST;
term.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
term.c_cflag &= ~(CSIZE|PARENB);
term.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
term.c_cflag &= ~(CSIZE | PARENB);
term.c_cflag |= CS8;
#endif
term.c_cflag |= (CLOCAL | CREAD);
term.c_lflag &= ~((tcflag_t)(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ISIG | IEXTEN ));
term.c_cflag |= (CLOCAL | CREAD);
term.c_lflag &= ~((tcflag_t)(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ISIG | IEXTEN));
term.c_oflag &= ~((tcflag_t)(OPOST));
term.c_iflag = IGNBRK;

term.c_cflag &= ~((tcflag_t)(CSIZE));
switch (dataBits)
Expand All @@ -472,7 +471,7 @@ int32_t SystemIoPortsNative_TermiosReset(intptr_t handle, int32_t speed, int32_t
break;
}

// There really is only choice of 1 or 2.
// Configure stop bits
if (stopBits == 1)
{
term.c_cflag &= ~((tcflag_t)(CSTOPB));
Expand Down Expand Up @@ -503,7 +502,7 @@ int32_t SystemIoPortsNative_TermiosReset(intptr_t handle, int32_t speed, int32_t
switch (handshake)
{
case HandshakeNone: /* None */
/* do nothing. We did the reset above */
// Do nothing; already reset above
break;
case HandshakeHard: /* hardware flow control */
term.c_cflag |= CRTSCTS;
Expand Down Expand Up @@ -545,11 +544,11 @@ int32_t SystemIoPortsNative_TermiosReset(intptr_t handle, int32_t speed, int32_t
if (speed && brate == B0)
{
#if HAVE_IOSS_H
// we have deferred non-standard speed.
// We have deferred non-standard speed.
brate = speed;
if (ioctl(fd, IOSSIOSPEED, &brate) == -1)
{
return -1;
return -1;
}
#endif
#if HAVE_TERMIOS2
Expand Down

0 comments on commit a7f96cb

Please sign in to comment.