From 6d4893a1467452d3a0e94e712c2d07b0597b9f3c Mon Sep 17 00:00:00 2001 From: Anton Lundin Date: Thu, 27 Mar 2014 20:44:12 +0100 Subject: [PATCH] Fix building for Android This makes libdivecomputer build via Android NDK. Its currently unusable due to the fact that Android usually doesn't provide any kernel serial drivers. Signed-off-by: Anton Lundin --- src/serial_posix.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/serial_posix.c b/src/serial_posix.c index e365024..e56eb0d 100644 --- a/src/serial_posix.c +++ b/src/serial_posix.c @@ -433,7 +433,7 @@ serial_configure (serial_t *device, int baudrate, int databits, int parity, int // Configure a custom baudrate if necessary. if (custom) { -#if defined(TIOCGSERIAL) && defined(TIOCSSERIAL) +#if defined(TIOCGSERIAL) && defined(TIOCSSERIAL) && !defined(__ANDROID__) // Get the current settings. struct serial_struct ss; if (ioctl (device->fd, TIOCGSERIAL, &ss) != 0 && NOPTY) { @@ -518,7 +518,7 @@ serial_set_latency (serial_t *device, unsigned int milliseconds) if (device == NULL) return -1; // EINVAL (Invalid argument) -#if defined(TIOCGSERIAL) && defined(TIOCSSERIAL) +#if defined(TIOCGSERIAL) && defined(TIOCSSERIAL) && !defined(__ANDROID__) // Get the current settings. struct serial_struct ss; if (ioctl (device->fd, TIOCGSERIAL, &ss) != 0 && NOPTY) { @@ -671,7 +671,12 @@ serial_write (serial_t *device, const void *data, unsigned int size) } // Wait until all data has been transmitted. +#ifdef __ANDROID__ + /* Android is missing tcdrain, so use ioctl version instead */ + while (ioctl (device->fd, TCSBRK, 1) != 0) { +#else while (tcdrain (device->fd) != 0) { +#endif if (errno != EINTR ) { SYSERROR (device->context, errno); return -1;