diff --git a/src/main/c/src/SerialImp.c b/src/main/c/src/SerialImp.c index 3b7c5e25..5c690411 100644 --- a/src/main/c/src/SerialImp.c +++ b/src/main/c/src/SerialImp.c @@ -4458,11 +4458,6 @@ JNIEXPORT jboolean JNICALL RXTXCommDriver(testRead)( int saved_flags; struct termios saved_termios; - if (tcgetattr(fd, &ttyset) < 0) { - ret = JNI_FALSE; - goto END; - } - /* save, restore later */ if ( ( saved_flags = fcntl(fd, F_GETFL ) ) < 0 ) { @@ -4471,6 +4466,12 @@ JNIEXPORT jboolean JNICALL RXTXCommDriver(testRead)( goto END; } + if (tcgetattr(fd, &ttyset) < 0) { + if (errno == EINVAL || errno == ENOTTY) goto NOT_TERMINAL; + ret = JNI_FALSE; + goto END; + } + memcpy( &saved_termios, &ttyset, sizeof( struct termios ) ); if ( fcntl( fd, F_SETFL, O_NONBLOCK ) < 0 ) @@ -4490,7 +4491,7 @@ JNIEXPORT jboolean JNICALL RXTXCommDriver(testRead)( tcsetattr( fd, TCSANOW, &saved_termios ); goto END; } - +NOT_TERMINAL: /* The following may mess up if both EAGAIN and EWOULDBLOCK