$OpenBSD: patch-source_io_c,v 1.3 2017/04/25 15:47:41 espie Exp $
--- source/io.c.orig	Fri Jul 22 03:47:26 1994
+++ source/io.c	Tue Apr 25 17:35:17 2017
@@ -60,6 +60,10 @@ long wgetch();
 char *getenv();
 #endif
 
+#ifdef __OpenBSD__
+#define USG
+#define USE_TERMIOS
+#endif
 
 #include <ctype.h>
 
@@ -109,6 +113,14 @@ typedef struct { int stuff; } fpvmach;
 /* Needs termio.h because curses.h doesn't include it */
 #include <termio.h>
 #endif
+#ifdef USE_TERMIOS
+# include <termios.h>
+#else
+# define termios termio
+# define tcgetattr(a, b) ioctl((a), TCGETA, (char *)(b))
+# define tcsetattr(a, b, c) ioctl((a), (b), (char *)(c))
+# define TCSANOW TCSETA
+#endif
 #else /* ! USG */
 #include <strings.h>
 #if defined(atarist) && defined(__GNUC__)
@@ -201,12 +213,8 @@ void sleep();
 #if !defined(MAC) && !defined(MSDOS) && !defined(ATARI_ST) && !defined(VMS)
 #ifndef AMIGA
 #ifdef USG
-#ifdef __linux__
 static struct termios save_termio;
 #else
-static struct termio save_termio;
-#endif
-#else
 static struct ltchars save_special_chars;
 static struct sgttyb save_ttyb;
 static struct tchars save_tchars;
@@ -235,38 +243,51 @@ static WINDOW *tempscr;		/* Spare window for VMS CTRL(
    Handle the stop and start signals. This ensures that the log
    is up to date, and that the terminal is fully reset and
    restored.  */
-int suspend()
+void suspend(int sig)
 {
-#ifdef USG
+#if defined(USG) && !defined(__OpenBSD__)
   /* for USG systems with BSDisms that have SIGTSTP defined, but don't
      actually implement it */
 #else
+#ifdef USE_TERMIOS
+  struct termios tbuf;
+#else
   struct sgttyb tbuf;
   struct ltchars lcbuf;
   struct tchars cbuf;
   int lbuf;
-  long time();
+#endif
 
   py.misc.male |= 2;
+#ifdef USE_TERMIOS
+  (void) tcgetattr(0, &tbuf);
+#else
   (void) ioctl(0, TIOCGETP, (char *)&tbuf);
   (void) ioctl(0, TIOCGETC, (char *)&cbuf);
   (void) ioctl(0, TIOCGLTC, (char *)&lcbuf);
 #if !defined(atarist) && !defined(__GNUC__)
   (void) ioctl(0, TIOCLGET, (char *)&lbuf);
 #endif
+#endif
+
   restore_term();
   (void) kill(0, SIGSTOP);
   curses_on = TRUE;
+
+#ifdef USE_TERMIOS
+  (void) tcsetattr(0, TCSANOW, &tbuf);
+#else
   (void) ioctl(0, TIOCSETP, (char *)&tbuf);
   (void) ioctl(0, TIOCSETC, (char *)&cbuf);
   (void) ioctl(0, TIOCSLTC, (char *)&lcbuf);
 #if !defined(atarist) && !defined(__GNUC__)
   (void) ioctl(0, TIOCLSET, (char *)&lbuf);
 #endif
+#endif
   (void) wrefresh(curscr);
   py.misc.male &= ~2;
 #endif
-  return 0;
+  return;
 }
 #endif
 #endif
@@ -307,7 +328,7 @@ void init_curses()
 #else
 #if !defined(VMS) && !defined(MSDOS) && !defined(ATARI_ST)
 #ifndef AMIGA
-  (void) ioctl(0, TCGETA, (char *)&save_termio);
+  (void) tcgetattr(0, &save_termio);
 #endif
 #endif
 #endif
@@ -385,12 +406,8 @@ void moriaterm()
 #if !defined(MSDOS) && !defined(ATARI_ST) && !defined(VMS)
 #ifndef AMIGA
 #ifdef USG
-#ifdef __linux__
   struct termios tbuf;
 #else
-  struct termio tbuf;
-#endif
-#else
   struct ltchars lbuf;
   struct tchars buf;
 #endif
@@ -420,7 +437,7 @@ void moriaterm()
 #else
 #if !defined(ATARI_ST) && !defined(VMS)
 #ifdef USG
-  (void) ioctl(0, TCGETA, (char *)&tbuf);
+  (void) tcgetattr(0, &tbuf);
   /* disable all of the normal special control characters */
   tbuf.c_cc[VINTR] = (char)3; /* control-C */
   tbuf.c_cc[VQUIT] = (char)-1;
@@ -438,7 +455,7 @@ void moriaterm()
   tbuf.c_cc[VMIN] = 1;  /* Input should wait for at least 1 char */
   tbuf.c_cc[VTIME] = 0; /* no matter how long that takes. */
 
-  (void) ioctl(0, TCSETA, (char *)&tbuf);
+  (void) tcgetattr(0, &tbuf);
 #else
   /* disable all of the special characters except the suspend char, interrupt
      char, and the control flow start/stop characters */
@@ -552,7 +569,7 @@ void restore_term()
 #ifdef USG
 #if !defined(MSDOS) && !defined(ATARI_ST) && !defined(VMS)
 #ifndef AMIGA
-  (void) ioctl(0, TCSETA, (char *)&save_termio);
+  (void) tcsetattr(0, TCSANOW, &save_termio);
 #endif
 #endif
 #else
@@ -646,12 +663,8 @@ void shell_out()
 {
 #ifdef USG
 #if !defined(MSDOS) && !defined(ATARI_ST) && !defined(AMIGA)
-#ifdef __linux__
   struct termios tbuf;
-#else
-  struct termio tbuf;
 #endif
-#endif
 #else
   struct sgttyb tbuf;
   struct ltchars lcbuf;
@@ -683,7 +696,7 @@ void shell_out()
 
 #ifdef USG
 #if !defined(MSDOS) && !defined(ATARI_ST) && !defined(AMIGA)
-  (void) ioctl(0, TCGETA, (char *)&tbuf);
+  (void) tcgetattr(0, &tbuf);
 #endif
 #else
   (void) ioctl(0, TIOCGETP, (char *)&tbuf);
@@ -725,7 +738,7 @@ void shell_out()
       default_signals();
 #ifdef USG
 #if !defined(MSDOS) && !defined(ATARI_ST) && !defined(AMIGA)
-      (void) ioctl(0, TCSETA, (char *)&save_termio);
+      (void) tcsetattr(0, TCSANOW, &save_termio);
 #endif
 #else
       (void) ioctl(0, TIOCSLTC, (char *)&save_special_chars);
@@ -785,7 +798,7 @@ void shell_out()
   /* have to disable ^Y for tunneling */
 #ifdef USG
 #if !defined(MSDOS) && !defined(ATARI_ST)
-  (void) ioctl(0, TCSETA, (char *)&tbuf);
+  (void) tcsetattr(0, TCSANOW, &tbuf);
 #endif
 #else
   (void) ioctl(0, TIOCSLTC, (char *)&lcbuf);
