MNRS-BM-BSP/newlib-nano/read.c

23 lines
512 B
C
Raw Permalink Normal View History

2024-01-16 12:26:47 +01:00
#include <stdint.h>
#include <errno.h>
#include <unistd.h>
#include "stub.h"
#include <platform.h>
ssize_t _read(int fd, void* ptr, size_t len);
ssize_t _read(int fd, void* ptr, size_t len) {
uint8_t * current = (uint8_t *)ptr;
ssize_t result = 0;
if (isatty(fd)) {
for (current = (uint8_t *)ptr;
(current < ((uint8_t *)ptr) + len) && (uart_get_rx_avail(uart) > 0);
current ++) {
*current = uart_read(uart);
result++;
}
return result;
}
return _stub(EBADF);
}