Fix macOS compilation

This commit is contained in:
Andy CA6JAU 2018-07-21 20:41:55 -04:00
parent 9c17f83f9e
commit e5c2ede05c

View file

@ -35,8 +35,10 @@
#include <fcntl.h>
#include <unistd.h>
#include <termios.h>
#if !defined(__APPLE__)
#include <linux/i2c-dev.h>
#endif
#endif
#if defined(_WIN32) || defined(_WIN64)
@ -244,6 +246,7 @@ bool CSerialController::open()
assert(m_fd == -1);
if (m_protocol == "i2c"){
#if !defined(__APPLE__)
m_fd = ::open(m_device.c_str(), O_RDWR);
if (m_fd < 0) {
LogError("Cannot open device - %s", m_device.c_str());
@ -261,6 +264,7 @@ bool CSerialController::open()
::close(m_fd);
return false;
}
#endif
} else {
#if defined(__APPLE__)
m_fd = ::open(m_device.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK); /*open in block mode under OSX*/
@ -407,6 +411,7 @@ int CSerialController::read(unsigned char* buffer, unsigned int length)
while (offset < length) {
if (m_protocol == "i2c"){
#if !defined(__APPLE__)
ssize_t n = ::read(m_fd, buffer + offset, 1U);
if (n < 0) {
if (errno != EAGAIN) {
@ -417,6 +422,7 @@ int CSerialController::read(unsigned char* buffer, unsigned int length)
if (n > 0)
offset += n;
#endif
} else {
fd_set fds;
@ -489,7 +495,9 @@ int CSerialController::write(const unsigned char* buffer, unsigned int length)
while (ptr < length) {
ssize_t n = 0U;
if (m_protocol == "i2c"){
#if !defined(__APPLE__)
n = ::write(m_fd, buffer + ptr, 1U);
#endif
} else {
if (canWrite())
n = ::write(m_fd, buffer + ptr, length - ptr);