In platforms 21 and higher of the NDK, linux/serial.h is available,
which it was not before. This broke the build, because the configure
script would detect the availability of 'struct serial_struct' in that
header and set HAVE_STRUCT_SERIAL_STRUCT, but the #ifndef __ANDROID__
in libserialport_internal.h stopped us actually including the header.
This change fixes things to build with all versions of the NDK, and is
tested with builds for arm from versions 9 to 24.
Version 21 also added availability of tcdrain(), so we also use that
where available, and only use the direct ioctl() method on NDK < 21.
Fixes#1078.
serialport.c: In function 'get_time':
serialport.c:64:6: warning: implicit declaration of function 'clock_gettime' [-Wimplicit-function-declaration]
if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1)
^
serialport.c:64:20: error: 'CLOCK_MONOTONIC' undeclared (first use in this function)
if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1)
^
serialport.c:64:20: note: each undeclared identifier is reported only once for each function it appears in
serialport.c:65:17: error: 'CLOCK_REALTIME' undeclared (first use in this function)
clock_gettime(CLOCK_REALTIME, &ts);
^
serialport.c: At top level:
serialport.c:60:13: warning: 'get_time' defined but not used [-Wunused-function]
static void get_time(struct timeval *time)
^
This fixes the following scan-build warning:
serialport.c:1170:3: warning: Potential leak of memory pointed to by 'new_handles'
RETURN_ERROR(SP_ERR_MEM, "Mask array realloc() failed");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This also fixes the following scan-build warning:
serialport.c:335:15: warning: Result of 'malloc' is converted to a
pointer of type 'struct sp_port *', which is incompatible with sizeof
operand type 'struct sp_port **'
if (!(list = malloc(sizeof(struct sp_port **))))
^~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~
Since we're not handling and clearing receive errors (framing, parity and
overrun), we should turn them off to avoid crashing out with
ERROR_OPERATION_ABORTED in various calls if they occur. Invalid data
will then simply not end up in the buffer. This is consistent with our
current behaviour on posix/termios systems.
It might be nice to be able to inform calling code about receive errors, but I
can't see a good way to do this in a cross-platform way at the moment.
This fixes (parts of) bug #341.