Skip to content

Commit 670fbcd

Browse files
SerialImp.c:RXTXCommDriver(testRead) - ignore tcgetattr() failures for hidraw device
If tcgetattr(fd, &ttyset) fails and errno is EINVAL 22 Invalid Argument, or ENOTTY - https://en.wikipedia.org/wiki/Not_a_typewriter, then this is not a serial device and do not try to adjust its settings. First obtain the flags, so that these can be restored later.
1 parent b1da316 commit 670fbcd

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/main/c/src/SerialImp.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4458,18 +4458,19 @@ JNIEXPORT jboolean JNICALL RXTXCommDriver(testRead)(
44584458
int saved_flags;
44594459
struct termios saved_termios;
44604460

4461-
if (tcgetattr(fd, &ttyset) < 0) {
4462-
ret = JNI_FALSE;
4463-
goto END;
4464-
}
4465-
44664461
/* save, restore later */
44674462
if ( ( saved_flags = fcntl(fd, F_GETFL ) ) < 0 )
44684463
{
44694464
report_warning( "testRead() fcntl(F_GETFL) failed\n" );
44704465
ret = JNI_FALSE;
44714466
goto END;
44724467
}
4468+
errno = 0;
4469+
if (tcgetattr(fd, &ttyset) < 0) {
4470+
if (errno == EINVAL || errno == ENOTTY) goto NOT_TERMINAL;
4471+
ret = JNI_FALSE;
4472+
goto END;
4473+
}
44734474

44744475
memcpy( &saved_termios, &ttyset, sizeof( struct termios ) );
44754476

@@ -4490,7 +4491,7 @@ JNIEXPORT jboolean JNICALL RXTXCommDriver(testRead)(
44904491
tcsetattr( fd, TCSANOW, &saved_termios );
44914492
goto END;
44924493
}
4493-
4494+
NOT_TERMINAL:
44944495
/*
44954496
44964497
The following may mess up if both EAGAIN and EWOULDBLOCK

0 commit comments

Comments
 (0)