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

25 lines
584 B
C
Raw Normal View History

2024-01-16 12:26:47 +01:00
#include <stdint.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include "stub.h"
#include <platform.h>
ssize_t _write(int fd, const void* ptr, size_t len);
ssize_t _write(int fd, const void* ptr, size_t len) {
const char * current = (const char *)ptr;
if (isatty(fd)) {
for (size_t jj = 0; jj < len; jj++) {
while (uart_get_tx_free(uart)==0) ;
uart_write(uart, current[jj]);
if (current[jj] == '\n') {
while (uart_get_tx_free(uart)==0) ;
uart_write(uart, '\r');
}
}
return len;
}
return _stub(EBADF);
}