obsw/bsp_z7/newlib/read.c

34 lines
791 B
C

#include "xil_printf.h"
#include "xparameters.h"
#include "../hardware/interface_access.h"
#include "../hardware/interface_fds.h"
// newlib offers a (weak) write implementation which
// is reentrant by calling _read_r which in turn
// relies on _read which we implement here.
// This way, we get a global, reentrant read implementation
// NOTE: This might be architecture dependent, so check your
// newlib implementation!
int _read(int fd, char *ptr, int len) {
if (ptr == NULL) {
return 0;
}
// 0 is stdin, TODO: do we support it?
if (fd < 1) {
return -1;
}
// stdout and stderr
if (fd < 3) {
return -1;
}
if (fd < INTERFACE_FDS_NEXT) {
return hw_interface_read(fd, ptr, len);
}
// we do not have dynamic fds, so fd is invalid
return -1;
}