Merge branch 'osx-baudrate' of https://github.com/robey/tio into robey-osx-baudrate

This commit is contained in:
Martin Lund 2022-02-16 05:24:35 +01:00
commit 7ffeeccdf5
4 changed files with 70 additions and 6 deletions

28
src/iossiospeed.c Normal file
View file

@ -0,0 +1,28 @@
/*
* tio - a simple TTY terminal I/O application
*
* Copyright (c) 2017 Martin Lund
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#include <sys/ioctl.h>
#include <IOKit/serial/ioss.h>
int iossiospeed(int fd, int baudrate)
{
return ioctl(fd, IOSSIOSPEED, (char *)&baudrate);
}

View file

@ -20,6 +20,11 @@ if enable_setspeed2
tio_c_args += '-DHAVE_TERMIOS2'
endif
if enable_iossiospeed
tio_sources += 'iossiospeed.c'
tio_c_args += '-DHAVE_IOSSIOSPEED'
endif
executable('tio',
tio_sources,
c_args: tio_c_args,

View file

@ -49,6 +49,10 @@
extern int setspeed2(int fd, int baudrate);
#endif
#ifdef HAVE_IOSSIOSPEED
extern int iossiospeed(int fd, int baudrate);
#endif
#ifdef __APPLE__
#define PATH_SERIAL_DEVICES "/dev/"
#else
@ -347,7 +351,7 @@ void tty_configure(void)
BAUDRATE_CASES
default:
#ifdef HAVE_TERMIOS2
#if defined (HAVE_TERMIOS2) || defined (HAVE_IOSSIOSPEED)
standard_baudrate = false;
break;
#else
@ -647,6 +651,15 @@ int tty_connect(void)
if (tcgetattr(fd, &tio_old) < 0)
goto error_tcgetattr;
#ifdef HAVE_IOSSIOSPEED
if (!standard_baudrate)
{
/* OS X wants these fields left alone. We'll set baudrate with iossiospeed below. */
tio.c_ispeed = tio_old.c_ispeed;
tio.c_ospeed = tio_old.c_ospeed;
}
#endif
/* Make sure we restore tty settings on exit */
if (first)
{
@ -668,7 +681,18 @@ int tty_connect(void)
if (setspeed2(fd, option.baudrate) != 0)
{
error_printf_silent("Could not set baudrate speed (%s)", strerror(errno));
goto error_setspeed2;
goto error_setspeed;
}
}
#endif
#ifdef HAVE_IOSSIOSPEED
if (!standard_baudrate)
{
if (iossiospeed(fd, option.baudrate) != 0)
{
error_printf_silent("Could not set baudrate speed (%s)", strerror(errno));
goto error_setspeed;
}
}
#endif
@ -815,8 +839,8 @@ int tty_connect(void)
return TIO_SUCCESS;
#ifdef HAVE_TERMIOS2
error_setspeed2:
#if defined (HAVE_TERMIOS2) || defined (HAVE_IOSSIOSPEED)
error_setspeed:
#endif
error_tcsetattr:
error_tcgetattr: