*/
#include <termios.h>
+#include <limits.h>
#include "peripheral_interface_uart.h"
int peripheral_interface_uart_read(peripheral_uart_h uart, uint8_t *buf, uint32_t length)
{
- int ret = read(uart->fd, (void *)buf, length);
- CHECK_ERROR(ret != length);
+ /* the return type has to allow negative values (for error codes), so we can't use the upper half of unsigned values */
+ int ret = read(uart->fd, (void *)buf, length > INT_MAX ? INT_MAX : length);
+ CHECK_ERROR(ret < 0);
- return PERIPHERAL_ERROR_NONE;
+ return ret;
}
int peripheral_interface_uart_write(peripheral_uart_h uart, uint8_t *buf, uint32_t length)
{
- int ret = write(uart->fd, buf, length);
- CHECK_ERROR(ret != length);
+ /* the return type has to allow negative values (for error codes), so we can't use the upper half of unsigned values */
+ int ret = write(uart->fd, buf, length > INT_MAX ? INT_MAX : length);
+ CHECK_ERROR(ret < 0);
- return PERIPHERAL_ERROR_NONE;
+ return ret;
}