Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/main/c/src/SerialImp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand All @@ -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 )
Expand All @@ -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
Expand Down