1
0
mirror of git://sigrok.org/libserialport synced 2023-08-10 21:13:24 +03:00

android: Fix build compatibility with NDK platform 21 and up.

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.
This commit is contained in:
Martin Ling 2020-01-04 23:00:17 +00:00
parent 277f832a6a
commit abd31fd9f9
2 changed files with 6 additions and 3 deletions

View File

@ -68,8 +68,9 @@
#endif #endif
#ifdef __linux__ #ifdef __linux__
#include <dirent.h> #include <dirent.h>
#ifndef __ANDROID__ /* Android only has linux/serial.h from platform 21 onwards. */
#include "linux/serial.h" #if !(defined(__ANDROID__) && (__ANDROID_API__ < 21))
#include <linux/serial.h>
#endif #endif
#include "linux_termios.h" #include "linux_termios.h"

View File

@ -742,7 +742,9 @@ SP_API enum sp_return sp_drain(struct sp_port *port)
#else #else
int result; int result;
while (1) { while (1) {
#ifdef __ANDROID__ #if defined(__ANDROID__) && (__ANDROID_API__ < 21)
/* Android only has tcdrain from platform 21 onwards.
* On previous API versions, use the ioctl directly. */
int arg = 1; int arg = 1;
result = ioctl(port->fd, TCSBRK, &arg); result = ioctl(port->fd, TCSBRK, &arg);
#else #else