From: Martin Ling Date: Fri, 3 Jan 2014 12:38:06 +0000 (+0100) Subject: linux: Speed fields may not be present in kernel termios structures. X-Git-Tag: libserialport-0.1.0~10 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=5cea279a85e16d20247d911b060b6aff8186003a;p=libserialport.git linux: Speed fields may not be present in kernel termios structures. --- diff --git a/configure.ac b/configure.ac index 961031d..6ceb02a 100644 --- a/configure.ac +++ b/configure.ac @@ -107,6 +107,10 @@ AC_TYPE_SIZE_T # Check for specific termios structures. AC_CHECK_TYPE([struct termios2], [AC_DEFINE(HAVE_TERMIOS2, 1)], [], [[#include ]]) AC_CHECK_TYPE([struct termiox], [AC_DEFINE(HAVE_TERMIOX, 1)], [], [[#include ]]) +AC_CHECK_MEMBERS([struct termios.c_ispeed, struct termios.c_ospeed], + [AC_DEFINE(HAVE_TERMIOS_SPEED, 1)], [], [[#include ]]) +AC_CHECK_MEMBERS([struct termios2.c_ispeed, struct termios2.c_ospeed], + [AC_DEFINE(HAVE_TERMIOS2_SPEED, 1)], [], [[#include ]]) AC_SUBST(MAKEFLAGS, '--no-print-directory') AC_SUBST(AM_LIBTOOLFLAGS, '--silent') diff --git a/linux_termios.c b/linux_termios.c index b236869..d45f801 100644 --- a/linux_termios.c +++ b/linux_termios.c @@ -33,8 +33,6 @@ * TCSETX/TCGETX ioctls used with struct termiox, others do not. */ -#if defined(__linux__) && !defined(__ANDROID__) - #include #include "linux_termios.h" @@ -65,6 +63,7 @@ int get_termios_size(void) #endif } +#ifdef USE_TERMIOS_SPEED int get_termios_speed(void *data) { #ifdef HAVE_TERMIOS2 @@ -89,6 +88,7 @@ void set_termios_speed(void *data, int speed) term->c_cflag |= BOTHER; term->c_ispeed = term->c_ospeed = speed; } +#endif #ifdef HAVE_TERMIOX int get_termiox_size(void) @@ -125,5 +125,3 @@ void set_termiox_flow(void *data, int rts, int cts, int dtr, int dsr) termx->x_cflag |= DSRXON; } #endif - -#endif diff --git a/serialport.c b/serialport.c index 0823180..12cb529 100644 --- a/serialport.c +++ b/serialport.c @@ -70,6 +70,11 @@ #define TIOCOUTQ FIONWRITE #endif +/* Non-standard baudrates are not available everywhere. */ +#if defined(HAVE_TERMIOS_SPEED) || defined(HAVE_TERMIOS2_SPEED) +#define USE_TERMIOS_SPEED +#endif + #include "libserialport.h" struct sp_port { @@ -1458,7 +1463,7 @@ enum sp_return sp_wait(struct sp_event_set *event_set, unsigned int timeout) #endif } -#ifdef __linux__ +#ifdef USE_TERMIOS_SPEED static enum sp_return get_baudrate(int fd, int *baudrate) { void *data; @@ -1511,6 +1516,7 @@ static enum sp_return set_baudrate(int fd, int baudrate) RETURN_OK(); } +#endif /* USE_TERMIOS_SPEED */ #ifdef USE_TERMIOX static enum sp_return get_flow(int fd, struct port_data *data) @@ -1568,7 +1574,6 @@ static enum sp_return set_flow(int fd, struct port_data *data) RETURN_OK(); } #endif /* USE_TERMIOX */ -#endif /* __linux__ */ static enum sp_return get_config(struct sp_port *port, struct port_data *data, struct sp_port_config *config) @@ -1705,7 +1710,7 @@ static enum sp_return get_config(struct sp_port *port, struct port_data *data, if (i == NUM_STD_BAUDRATES) { #ifdef __APPLE__ config->baudrate = (int)data->term.c_ispeed; -#elif defined(__linux__) +#elif defined(USE_TERMIOS_SPEED) TRY(get_baudrate(port->fd, &config->baudrate)); #else config->baudrate = -1; @@ -1788,7 +1793,7 @@ static enum sp_return set_config(struct sp_port *port, struct port_data *data, baud_nonstd = B0; #endif -#ifdef __linux__ +#ifdef USE_TERMIOS_SPEED int baud_nonstd = 0; #endif @@ -1955,7 +1960,7 @@ static enum sp_return set_config(struct sp_port *port, struct port_data *data, if (cfsetspeed(&data->term, B9600) < 0) RETURN_FAIL("cfsetspeed() failed"); baud_nonstd = config->baudrate; -#elif defined(__linux__) +#elif defined(USE_TERMIOS_SPEED) baud_nonstd = 1; #else RETURN_ERROR(SP_ERR_SUPP, "Non-standard baudrate not supported"); @@ -2151,8 +2156,10 @@ static enum sp_return set_config(struct sp_port *port, struct port_data *data, RETURN_FAIL("cfsetspeed() failed"); } #elif defined(__linux__) +#ifdef USE_TERMIOS_SPEED if (baud_nonstd) TRY(set_baudrate(port->fd, config->baudrate)); +#endif #ifdef USE_TERMIOX if (data->termiox_supported) TRY(set_flow(port->fd, data));