Files
obsw/bsp_z7/newlib/write.c
T
mohr c111ec176c
ROMEO CI Builder / Build Code (push) Failing after 1m43s
debian seems to have a newlib without reent :(
2025-11-14 17:27:56 +01:00

51 lines
1.1 KiB
C

#include "xil_printf.h"
#include "xparameters.h"
#include "../hardware/interface_access.h"
#include "../hardware/interface_fds.h"
#include <errno.h>
#include <reent.h>
#include <unistd.h>
int write(int fd, const void *ptr, size_t len) {
if (ptr == NULL) {
// _REENT_ERRNO(_REENT) = EINVAL;
return -1;
}
//TODO check len
// 0 is stdin, do not write to it
if (fd < 1) {
// _REENT_ERRNO(_REENT) = EBADF;
return -1;
}
// we only support a single debug UART, so
// stdout and stderr are the same and go to the xilinx stdout UART
// We output directely to avoid loops and allow debugging (not via a write)
if (fd < 3) {
size_t todo;
const char *data = ptr;
for (todo = 0; todo < len; todo++) {
outbyte(*data++);
}
return len;
}
if (fd < INTERFACE_FDS_NEXT) {
int result = hw_interface_write(fd, ptr, len);
if (result >= 0) {
return result;
// } else if (_REENT_ERRNO(_REENT) != EBADF) {
// return result;
}
// continue if fd did not match to try other fd providers
}
// we do not have dynamic fds, so fd is invalid
// _REENT_ERRNO(_REENT) = EBADF;
return -1;
}