diff options
| author | Sylvain Munaut <tnt@246tNt.com> | 2011-09-28 09:10:32 +0200 | 
|---|---|---|
| committer | Sylvain Munaut <tnt@246tNt.com> | 2011-09-28 09:11:09 +0200 | 
| commit | 9631184399a45ccae1592fa6940fe7f810eac64e (patch) | |
| tree | 657b24740aff824a6375ebee51774fd587d31148 | |
| parent | abf66e75cb7c7fd89bbadc3686cf60318953cc9d (diff) | |
core/serial: support custom baud rates on OS X
Thanks to Richard James <xyzzy@mm.st> for the patch
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
| -rw-r--r-- | src/serial.c | 24 | 
1 files changed, 22 insertions, 2 deletions
| diff --git a/src/serial.c b/src/serial.c index 26cf59d7..b68fd564 100644 --- a/src/serial.c +++ b/src/serial.c @@ -38,8 +38,9 @@  #include <sys/ioctl.h>  #include <sys/types.h>  #include <sys/stat.h> +#ifdef __linux__  #include <linux/serial.h> - +#endif  #include <osmocom/core/serial.h> @@ -155,6 +156,7 @@ osmo_serial_set_baudrate(int fd, speed_t baudrate)  int  osmo_serial_set_custom_baudrate(int fd, int baudrate)  { +#ifdef __linux__  	int rc;  	struct serial_struct ser_info; @@ -174,6 +176,23 @@ osmo_serial_set_custom_baudrate(int fd, int baudrate)  	}  	return _osmo_serial_set_baudrate(fd, B38400); /* 38400 is a kind of magic ... */ +#elif defined(__APPLE__) +#ifndef IOSSIOSPEED +#define IOSSIOSPEED    _IOW('T', 2, speed_t) +#endif +	int rc; + +	unsigned int speed = baudrate; +	rc = ioctl(fd, IOSSIOSPEED, &speed); +	if (rc < 0) { +		dbg.perror("ioctl(IOSSIOSPEED)"); +		return -errno; +	} +	return 0; +#else +#warning osmo_serial_set_custom_baudrate: unsupported platform +	return 0; +#endif  }  /*! \brief Clear any custom baudrate @@ -186,6 +205,7 @@ int  osmo_serial_clear_custom_baudrate(int fd)  {  	int rc; +#ifdef __linux__  	struct serial_struct ser_info;  	rc = ioctl(fd, TIOCGSERIAL, &ser_info); @@ -202,7 +222,7 @@ osmo_serial_clear_custom_baudrate(int fd)  		dbg_perror("ioctl(TIOCSSERIAL)");  		return -errno;  	} - +#endif  	return 0;  } | 
