mirror of
https://github.com/tio/tio.git
synced 2026-05-01 23:07:58 +02:00
hacky custom baud on macOS
This commit is contained in:
parent
3a1fd79fcb
commit
b84e7168b6
1 changed files with 25 additions and 4 deletions
29
src/tty.c
29
src/tty.c
|
|
@ -44,8 +44,10 @@
|
||||||
#include "tio/log.h"
|
#include "tio/log.h"
|
||||||
#include "tio/error.h"
|
#include "tio/error.h"
|
||||||
|
|
||||||
#ifdef HAVE_TERMIOS2
|
#if defined(HAVE_TERMIOS2)
|
||||||
extern int setspeed2(int fd, int baudrate);
|
extern int setspeed2(int fd, int baudrate);
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
#include <IOKit/serial/ioss.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static struct termios tio, tio_old, stdout_new, stdout_old, stdin_new, stdin_old;
|
static struct termios tio, tio_old, stdout_new, stdout_old, stdin_new, stdin_old;
|
||||||
|
|
@ -366,9 +368,16 @@ void tty_configure(void)
|
||||||
AUTOCONF_BAUDRATE_CASES
|
AUTOCONF_BAUDRATE_CASES
|
||||||
|
|
||||||
default:
|
default:
|
||||||
#ifdef HAVE_TERMIOS2
|
#if defined(HAVE_TERMIOS2)
|
||||||
standard_baudrate = false;
|
standard_baudrate = false;
|
||||||
break;
|
break;
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
standard_baudrate = false;
|
||||||
|
// We need to set *something* in tio here, otherwise the later
|
||||||
|
// tcsetattr will fail. We'll override this with ioctl.
|
||||||
|
cfsetispeed(&tio, B9600);
|
||||||
|
cfsetospeed(&tio, B9600);
|
||||||
|
break;
|
||||||
#else
|
#else
|
||||||
error_printf("Invalid baud rate");
|
error_printf("Invalid baud rate");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|
@ -679,7 +688,7 @@ int tty_connect(void)
|
||||||
goto error_tcsetattr;
|
goto error_tcsetattr;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_TERMIOS2
|
#if defined(HAVE_TERMIOS2)
|
||||||
if (!standard_baudrate)
|
if (!standard_baudrate)
|
||||||
{
|
{
|
||||||
if (setspeed2(fd, option.baudrate) != 0)
|
if (setspeed2(fd, option.baudrate) != 0)
|
||||||
|
|
@ -688,6 +697,16 @@ int tty_connect(void)
|
||||||
goto error_setspeed2;
|
goto error_setspeed2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
if (!standard_baudrate)
|
||||||
|
{
|
||||||
|
speed_t baud = option.baudrate;
|
||||||
|
if (ioctl(fd, IOSSIOSPEED, &baud) == -1)
|
||||||
|
{
|
||||||
|
error_printf_silent("Could not set baudrate speed (%s)", strerror(errno));
|
||||||
|
goto error_iokit;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
maxfd = MAX(fd, STDIN_FILENO) + 1; /* Maximum bit entry (fd) to test */
|
maxfd = MAX(fd, STDIN_FILENO) + 1; /* Maximum bit entry (fd) to test */
|
||||||
|
|
@ -827,8 +846,10 @@ int tty_connect(void)
|
||||||
|
|
||||||
return TIO_SUCCESS;
|
return TIO_SUCCESS;
|
||||||
|
|
||||||
#ifdef HAVE_TERMIOS2
|
#if defined(HAVE_TERMIOS2)
|
||||||
error_setspeed2:
|
error_setspeed2:
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
error_iokit:
|
||||||
#endif
|
#endif
|
||||||
error_tcsetattr:
|
error_tcsetattr:
|
||||||
error_tcgetattr:
|
error_tcgetattr:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue