From: Konrad Kuchciak Date: Fri, 24 Jul 2020 12:34:03 +0000 (+0200) Subject: uart: Fix read and write functions X-Git-Tag: submit/tizen/20201201.110307~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b9ac7d58a385494e59c7e618945c1d0447363470;p=platform%2Fcore%2Fapi%2Fperipheral-io.git uart: Fix read and write functions Return number of bytes read/written to fulfill declaration given in docs. Change-Id: I81e229a1b719c9370ed97d38316fbef8e712bba5 --- diff --git a/src/interface/peripheral_interface_uart.c b/src/interface/peripheral_interface_uart.c index 45e0690..09c4978 100644 --- a/src/interface/peripheral_interface_uart.c +++ b/src/interface/peripheral_interface_uart.c @@ -15,6 +15,7 @@ */ #include +#include #include "peripheral_interface_uart.h" @@ -178,16 +179,18 @@ int peripheral_interface_uart_set_flow_control(peripheral_uart_h uart, periphera 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; }