From 3b59037af30018c7a43c44dcd60c511380733a9c Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Thu, 23 Feb 2017 11:24:00 -0800 Subject: [PATCH] Backport the inlines for cfsetspeed and tcdrain. This fixes some issues with using boost's asio (which wrongly assumes _BSD_SOURCE implies that these things are available) following our change from -isystem to --sysroot. Test: Manual, check that we can build when using cfsetspeed on ICS. Bug: https://github.com/android-ndk/ndk/issues/302 Change-Id: Iab50221e4864f9a09a8fb00691252170eb6e8d09 --- ndk/platforms/android-9/include/sys/cdefs.h | 6 ++++++ ndk/platforms/android-9/include/termios.h | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/ndk/platforms/android-9/include/sys/cdefs.h b/ndk/platforms/android-9/include/sys/cdefs.h index 9a8dfdd20f5..eb9a654cd8d 100644 --- a/ndk/platforms/android-9/include/sys/cdefs.h +++ b/ndk/platforms/android-9/include/sys/cdefs.h @@ -86,6 +86,12 @@ #define __static_cast(x,y) (x)y #endif +#if defined(__cplusplus) +#define __BIONIC_CAST(_k,_t,_v) (_k<_t>(_v)) +#else +#define __BIONIC_CAST(_k,_t,_v) ((_t) (_v)) +#endif + /* * The __CONCAT macro is used to concatenate parts of symbol names, e.g. * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. diff --git a/ndk/platforms/android-9/include/termios.h b/ndk/platforms/android-9/include/termios.h index ad1908995e8..fc991aba854 100644 --- a/ndk/platforms/android-9/include/termios.h +++ b/ndk/platforms/android-9/include/termios.h @@ -108,6 +108,18 @@ static __inline__ void cfmakeraw(struct termios *s) s->c_cflag |= CS8; } +static __inline int cfsetspeed(struct termios* s, speed_t speed) { + // TODO: check 'speed' is valid. + s->c_cflag = (s->c_cflag & ~CBAUD) | (speed & CBAUD); + return 0; +} + +static __inline int tcdrain(int fd) { + // A non-zero argument to TCSBRK means "don't send a break". + // The drain is a side-effect of the ioctl! + return ioctl(fd, TCSBRK, __BIONIC_CAST(static_cast, unsigned long, 1)); +} + __END_DECLS #endif /* _TERMIOS_H_ */