fixed MSYS2 compilation error and support for non-standard arbitrary baudrates

This commit is contained in:
swk 2026-02-18 14:08:49 +09:00
parent 6fb3a64ba2
commit 1d0276892f
2 changed files with 27 additions and 2 deletions

View file

@ -60,6 +60,31 @@ int setspeed(int fd, int baudrate)
return ioctl(fd, IOSSIOSPEED, (char *)&baudrate);
}
#elif defined (__CYGWIN__)
#include <windows.h>
#include <io.h>
int setspeed(int fd, int baudrate)
{
HANDLE hSerial = (HANDLE)_get_osfhandle(fd);
DCB dcbSerialParams = {0};
dcbSerialParams.DCBlength = sizeof(dcbSerialParams);
if (!GetCommState(hSerial, &dcbSerialParams))
{
int err = GetLastError();
errno = err == ERROR_INVALID_HANDLE ? ENODEV : EINVAL;
return -1;
}
dcbSerialParams.BaudRate = baudrate;
if (!SetCommState(hSerial, &dcbSerialParams))
{
int err = GetLastError();
errno = err == ERROR_INVALID_HANDLE ? ENODEV : EINVAL;
return -1;
}
return 0;
}
#else
int setspeed(int fd, int baudrate)
{

View file

@ -1266,7 +1266,7 @@ void tty_configure(void)
BAUDRATE_CASES
default:
#if defined (HAVE_TERMIOS2) || defined (HAVE_IOSSIOSPEED)
#if defined (HAVE_TERMIOS2) || defined (HAVE_IOSSIOSPEED) || defined (__CYGWIN__)
standard_baudrate = false;
break;
#else
@ -2361,7 +2361,7 @@ void tty_wait_for_device(void)
// Happens when port unpluged
if (errno == EACCES)
{
goto error;
break;
}
#elif defined(__APPLE__)
if (errno == EBADF)