@@ -207,21 +207,54 @@ var SyscallsLibrary = {
207207#else
208208 var stream = SYSCALLS . getStreamFromFD ( fd ) ;
209209 switch ( op ) {
210- case { { { cDefs . TCGETA } } } :
210+ case { { { cDefs . TCGETA } } } : {
211+ if ( ! stream . tty ) return - { { { cDefs . ENOTTY } } } ;
212+ #if SYSCALL_DEBUG
213+ dbg ( 'warning: not filling tio struct' ) ;
214+ #endif
215+ return 0 ;
216+ }
211217 case { { { cDefs . TCGETS } } } : {
212218 if ( ! stream . tty ) return - { { { cDefs . ENOTTY } } } ;
219+ if ( stream . tty . ops . ioctl_tcgets ) {
220+ var termios = stream . tty . ops . ioctl_tcgets ( stream ) ;
221+ var argp = SYSCALLS . get ( ) ;
222+ { { { makeSetValue ( 'argp' , C_STRUCTS . termios . c_iflag , 'termios.c_iflag || 0' , 'i32' ) } } } ;
223+ { { { makeSetValue ( 'argp ', C_STRUCTS . termios . c_oflag , 'termios.c_oflag || 0' , 'i32' ) } } } ;
224+ { { { makeSetValue ( 'argp' , C_STRUCTS . termios . c_cflag , 'termios.c_cflag || 0' , 'i32' ) } } } ;
225+ { { { makeSetValue ( 'argp' , C_STRUCTS . termios . c_lflag , 'termios.c_lflag || 0' , 'i32' ) } } } ;
226+ for ( var i = 0 ; i < { { { cDefs. NCCS } } } ; i ++ ) {
227+ { { { makeSetValue ( 'argp + i' , C_STRUCTS . termios . c_cc , 'termios.c_cc[i] || 0' , 'i8' ) } } } ;
228+ }
229+ return 0 ;
230+ }
213231#if SYSCALL_DEBUG
214232 dbg ( 'warning: not filling tio struct' ) ;
215233#endif
216234 return 0 ;
217235 }
218236 case { { { cDefs . TCSETA } } } :
219237 case { { { cDefs . TCSETAW } } } :
220- case { { { cDefs . TCSETAF } } } :
238+ case { { { cDefs . TCSETAF } } } : {
239+ if ( ! stream . tty ) return - { { { cDefs . ENOTTY } } } ;
240+ return 0 ; // no-op, not actually adjusting terminal settings
241+ }
221242 case { { { cDefs . TCSETS } } } :
222243 case { { { cDefs . TCSETSW } } } :
223244 case { { { cDefs . TCSETSF } } } : {
224245 if ( ! stream . tty ) return - { { { cDefs . ENOTTY } } } ;
246+ if ( stream . tty . ops . ioctl_tcsets ) {
247+ var argp = SYSCALLS . get ( ) ;
248+ var c_iflag = { { { makeGetValue ( 'argp' , C_STRUCTS . termios . c_iflag , 'i32' ) } } } ;
249+ var c_oflag = { { { makeGetValue ( 'argp' , C_STRUCTS . termios . c_oflag , 'i32' ) } } } ;
250+ var c_cflag = { { { makeGetValue ( 'argp' , C_STRUCTS . termios . c_cflag , 'i32' ) } } } ;
251+ var c_lflag = { { { makeGetValue ( 'argp' , C_STRUCTS . termios . c_lflag , 'i32' ) } } } ;
252+ var c_cc = [ ]
253+ for ( var i = 0 ; i < { { { cDefs . NCCS } } } ; i ++ ) {
254+ c_cc . push ( { { { makeGetValue ( 'argp + i' , C_STRUCTS . termios . c_cc , 'i8' ) } } } ) ;
255+ }
256+ return stream . tty . ops . ioctl_tcsets ( stream . tty , op , { c_iflag , c_oflag , c_cflag , c_lflag , c_cc } ) ;
257+ }
225258 return 0 ; // no-op, not actually adjusting terminal settings
226259 }
227260 case { { { cDefs . TIOCGPGRP } } } : {
@@ -242,6 +275,12 @@ var SyscallsLibrary = {
242275 // TODO: in theory we should write to the winsize struct that gets
243276 // passed in, but for now musl doesn't read anything on it
244277 if ( ! stream . tty ) return - { { { cDefs . ENOTTY } } } ;
278+ if ( stream . tty . ops . ioctl_tiocgwinsz ) {
279+ var winsize = stream . tty . ops . ioctl_tiocgwinsz ( stream . tty ) ;
280+ var argp = SYSCALLS . get ( ) ;
281+ { { { makeSetValue ( 'argp' , 0 , 'winsize[0]' , 'i16' ) } } } ;
282+ { { { makeSetValue ( 'argp ', 2 , 'winsize [ 1 ] ', 'i16 ') } } } ;
283+ }
245284 return 0 ;
246285 }
247286 case { { { cDefs . TIOCSWINSZ } } } : {
@@ -251,6 +290,10 @@ var SyscallsLibrary = {
251290 if ( ! stream . tty ) return - { { { cDefs . ENOTTY } } } ;
252291 return 0 ;
253292 }
293+ case { { { cDefs . TCFLSH } } } : {
294+ if ( ! stream . tty ) return - { { { cDefs . ENOTTY } } } ;
295+ return 0 ;
296+ }
254297 default : return - { { { cDefs . EINVAL } } } ; // not supported
255298 }
256299#endif // SYSCALLS_REQUIRE_FILESYSTEM
@@ -542,7 +585,13 @@ var SyscallsLibrary = {
542585 var flags = SYSCALLS . DEFAULT_POLLMASK ;
543586
544587 if ( stream . stream_ops . poll ) {
545- flags = stream . stream_ops . poll ( stream ) ;
588+ var timeoutInMillis = - 1 ;
589+ if ( timeout ) {
590+ var tv_sec = ( readfds ? { { { makeGetValue ( 'timeout' , C_STRUCTS . timeval . tv_sec , 'i32' ) } } } : 0 ) ,
591+ tv_usec = ( readfds ? { { { makeGetValue ( 'timeout' , C_STRUCTS . timeval . tv_usec , 'i32' ) } } } : 0 ) ;
592+ timeoutInMillis = ( tv_sec + tv_usec / 1000000 ) * 1000 ;
593+ }
594+ flags = stream . stream_ops . poll ( stream , timeoutInMillis ) ;
546595 }
547596
548597 if ( ( flags & { { { cDefs . POLLIN } } } ) && check ( fd , srcReadLow , srcReadHigh , mask ) ) {
@@ -593,7 +642,7 @@ var SyscallsLibrary = {
593642 if ( stream ) {
594643 mask = SYSCALLS . DEFAULT_POLLMASK ;
595644 if ( stream . stream_ops . poll ) {
596- mask = stream . stream_ops . poll ( stream ) ;
645+ mask = stream . stream_ops . poll ( stream , - 1 ) ;
597646 }
598647 }
599648 mask &= events | { { { cDefs . POLLERR } } } | { { { cDefs . POLLHUP } } } ;
0 commit comments