From 2be41b1265e9c433a1a2af435e040388453fc603 Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Sat, 25 Jan 2020 14:51:56 +0000 Subject: [PATCH] Fix building on Cygwin. There were two issues: first, feature test macros were only defined for __linux__, so defintions we needed were not included. Enable the same feature test macros for __CYGWIN__. Second, the Cygwin headers do not define TIOCOUTQ, needed to use ioctl() to get the number of bytes in the output queue. Return SP_ERR_SUPP on Cygwin for this operation. This fixes bug #963. --- libserialport_internal.h | 4 ++-- serialport.c | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/libserialport_internal.h b/libserialport_internal.h index 20b3505..5b811cc 100644 --- a/libserialport_internal.h +++ b/libserialport_internal.h @@ -27,8 +27,8 @@ #define _CRT_SECURE_NO_WARNINGS #endif -/* These Linux/glibc specific defines must appear before other headers.*/ -#ifdef __linux__ +/* These feature test macros must appear before other headers.*/ +#if defined(__linux__) || defined(__CYGWIN__) /* For timeradd, timersub, timercmp, realpath. */ #define _BSD_SOURCE 1 /* for glibc < 2.19 */ #define _DEFAULT_SOURCE 1 /* for glibc >= 2.20 */ diff --git a/serialport.c b/serialport.c index 422b767..eda2d19 100644 --- a/serialport.c +++ b/serialport.c @@ -1307,6 +1307,11 @@ SP_API enum sp_return sp_output_waiting(struct sp_port *port) { TRACE("%p", port); +#ifdef __CYGWIN__ + /* TIOCOUTQ is not defined in Cygwin headers */ + RETURN_ERROR(SP_ERR_SUPP, + "Getting output bytes waiting is not supported on Cygwin"); +#else CHECK_OPEN_PORT(); DEBUG_FMT("Checking output bytes waiting on port %s", port->name); @@ -1324,6 +1329,7 @@ SP_API enum sp_return sp_output_waiting(struct sp_port *port) RETURN_FAIL("TIOCOUTQ ioctl failed"); RETURN_INT(bytes_waiting); #endif +#endif } SP_API enum sp_return sp_new_event_set(struct sp_event_set **result_ptr)