History

termios

Do not #include <termio.h> as it is deprecated in favor of termios.h and avoid non-portable ioctl calls in favour of tcgetattr and tcsetattr.

Barak A. Pearlmutter committed 4 years ago

Commit 85aa5da1 parent 8eea0da1 file · +4 −25Browse files

Showing the changes to src/core/util_console.cpp (1 of 1 file). Show all

Unified · Split

src/core/util_console.cpp+4−25
@@ -92,14 +92,8 @@ void io_addhistory( const char * addme ) · 91 unmodified lines
9292 // kb hit
9393 #ifndef __PLATFORM_WIN32__
9494 #include <string.h>
95−#ifdef __PLATFORM_MACOSX__
9695 #include <termios.h>
9796 static struct termios g_save;
98−#else
99− #include <termio.h>
100− static struct termio g_save;
101−#endif
102−
10397 #include <unistd.h>
10498 #include <sys/ioctl.h>
10599 #else
@@ -118,15 +112,9 @@ t_CKBOOL kb_initscr() · 12 unmodified lines
118112 if( g_init ) return FALSE;
119113
120114 #ifndef __PLATFORM_WIN32__
121−
122−#ifdef __PLATFORM_MACOSX__
123115 struct termios term;
124− if( ioctl( 0, TIOCGETA, &term ) == -1 )
125−#else
126− struct termio term;
127− if( ioctl( 0, TCGETA, &term ) == -1 )
128−#endif
129− {
116+ if( tcgetattr(0, &term) == -1 )
117+ {
130118 EM_log( CK_LOG_SEVERE, "(kbhit disabled): standard input not a tty!");
131119 return FALSE;
132120 }
@@ -142,12 +130,7 @@ t_CKBOOL kb_initscr() · 9 unmodified lines
142130 term.c_cc[VMIN] = 0;
143131 term.c_cc[VTIME]=0;
144132
145−#ifdef __PLATFORM_MACOSX__
146− ioctl( 0, TIOCSETA, &term );
147−#else
148− ioctl( 0, TCSETA, &term );
149−#endif
150−
133+ tcsetattr( 0, TCSADRAIN, &term );
151134 #endif
152135
153136 g_init = TRUE;
@@ -161,11 +144,7 @@ void kb_endwin() · 7 unmodified lines
161144 if( !g_init ) return;
162145
163146 #ifndef __PLATFORM_WIN32__
164−#ifdef __PLATFORM_MACOSX__
165− ioctl( 0, TIOCSETA, &g_save );
166−#else
167− ioctl( 0, TCSETA, &g_save );
168−#endif
147+ tcsetattr( 0, TCSADRAIN, &g_save );
169148 #endif
170149
171150 g_init = FALSE;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t