Make use of termios on OpenBSD

This commit is contained in:
Brad Smith 2022-09-02 23:52:34 -04:00
parent 4afc476d92
commit 662a041dba
3 changed files with 33 additions and 2 deletions

View File

@ -41,7 +41,7 @@ typedef struct {
#define TX_CMD_PROMPT ":" #define TX_CMD_PROMPT ":"
/* all of the state associated with a tty terminal */ /* all of the state associated with a tty terminal */
#if !defined(SYSV) && !defined(CYGWIN) #if !defined(SYSV) && !defined(CYGWIN) && !defined(__OpenBSD__)
typedef struct { typedef struct {
struct sgttyb tx_i_sgtty; struct sgttyb tx_i_sgtty;
struct tchars tx_i_tchars; struct tchars tx_i_tchars;

View File

@ -1215,6 +1215,15 @@ txGetTermState(buf)
ioctl( fileno( stdin ), TCGETA, buf); ioctl( fileno( stdin ), TCGETA, buf);
} }
#elif defined (__OpenBSD__)
void
txGetTermState(buf)
struct termios *buf;
{
(void) tcgetattr(fileno(stdin), buf);
}
#else #else
void void
@ -1247,12 +1256,16 @@ void
txSetTermState(buf) txSetTermState(buf)
#if defined(SYSV) || defined(CYGWIN) #if defined(SYSV) || defined(CYGWIN)
struct termio *buf; struct termio *buf;
#elif defined(__OpenBSD__)
struct termios *buf;
#else #else
txTermState *buf; txTermState *buf;
#endif /* SYSV */ #endif /* SYSV */
{ {
#if defined(SYSV) || defined(CYGWIN) #if defined(SYSV) || defined(CYGWIN)
ioctl( fileno(stdin), TCSETAF, buf ); ioctl( fileno(stdin), TCSETAF, buf );
#elif defined (__OpenBSD__)
(void) tcsetattr( fileno(stdin), TCSANOW, buf );
#else #else
/* set the current terminal characteristics */ /* set the current terminal characteristics */
(void) ioctl(fileno(stdin), TIOCSETN, (char *) &(buf->tx_i_sgtty) ); (void) ioctl(fileno(stdin), TIOCSETN, (char *) &(buf->tx_i_sgtty) );
@ -1282,11 +1295,13 @@ void
txInitTermRec(buf) txInitTermRec(buf)
#if defined(SYSV) || defined(CYGWIN) #if defined(SYSV) || defined(CYGWIN)
struct termio *buf; struct termio *buf;
#elif defined(__OpenBSD__)
struct termios *buf;
#else #else
txTermState *buf; txTermState *buf;
#endif /* SYSV */ #endif /* SYSV */
{ {
#if defined(SYSV) || defined(CYGWIN) #if defined(SYSV) || defined(CYGWIN) || defined(__OpenBSD__)
buf->c_lflag = ISIG; /* raw: no echo and no processing, allow signals */ buf->c_lflag = ISIG; /* raw: no echo and no processing, allow signals */
buf->c_cc[ VMIN ] = 1; buf->c_cc[ VMIN ] = 1;
buf->c_cc[ VTIME ] = 0; buf->c_cc[ VTIME ] = 0;
@ -1303,6 +1318,8 @@ txInitTermRec(buf)
#if defined(SYSV) || defined(CYGWIN) #if defined(SYSV) || defined(CYGWIN)
struct termio closeTermState; struct termio closeTermState;
#elif defined(__OpenBSD__)
struct termios closeTermState;
#else #else
static txTermState closeTermState; static txTermState closeTermState;
#endif /* SYSV */ #endif /* SYSV */
@ -1335,6 +1352,13 @@ txSaveTerm()
TxEOFChar = closeTermState.c_cc[VEOF]; TxEOFChar = closeTermState.c_cc[VEOF];
TxInterruptChar = closeTermState.c_cc[VINTR]; TxInterruptChar = closeTermState.c_cc[VINTR];
haveCloseState = TRUE; haveCloseState = TRUE;
#elif defined(__OpenBSD__)
(void) tcgetattr( fileno( stdin ), &closeTermState);
txEraseChar = closeTermState.c_cc[VERASE];
txKillChar = closeTermState.c_cc[VKILL];
TxEOFChar = closeTermState.c_cc[VEOF];
TxInterruptChar = closeTermState.c_cc[VINTR];
haveCloseState = TRUE;
#else #else
struct ltchars lt; struct ltchars lt;
txGetTermState(&closeTermState); txGetTermState(&closeTermState);
@ -1371,6 +1395,8 @@ TxSetTerminal()
{ {
#if defined(SYSV) || defined(CYGWIN) #if defined(SYSV) || defined(CYGWIN)
struct termio buf; struct termio buf;
#elif defined(__OpenBSD__)
struct termios buf;
#else #else
txTermState buf; txTermState buf;
#endif /* SYSV */ #endif /* SYSV */

View File

@ -33,7 +33,12 @@
# endif # endif
#include <sys/ioctl.h> #include <sys/ioctl.h>
#if defined(__OpenBSD__)
#include <termios.h>
#else
#include <sys/ioctl_compat.h> #include <sys/ioctl_compat.h>
#endif
#else #else
#include <termio.h> #include <termio.h>