cpu/native: make use of stdio_read() / stdio_write()
On `native` the functions stdio_read() / stdio_write() were not used. Those functions are intended for alternative stdio implementations. As a result, no alternative stdio could be used on `native`. To fix this, call the functions in `_native_read()` / `_native_write()` when dealing with stdio fds.
This commit is contained in:
parent
f79207e217
commit
13e16fa34f
@ -40,6 +40,7 @@
|
|||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "irq.h"
|
#include "irq.h"
|
||||||
#include "xtimer.h"
|
#include "xtimer.h"
|
||||||
|
#include "stdio_base.h"
|
||||||
|
|
||||||
#include "native_internal.h"
|
#include "native_internal.h"
|
||||||
|
|
||||||
@ -217,6 +218,10 @@ ssize_t _native_read(int fd, void *buf, size_t count)
|
|||||||
{
|
{
|
||||||
ssize_t r;
|
ssize_t r;
|
||||||
|
|
||||||
|
if (fd == STDIN_FILENO) {
|
||||||
|
return stdio_read(buf, count);
|
||||||
|
}
|
||||||
|
|
||||||
_native_syscall_enter();
|
_native_syscall_enter();
|
||||||
r = real_read(fd, buf, count);
|
r = real_read(fd, buf, count);
|
||||||
_native_syscall_leave();
|
_native_syscall_leave();
|
||||||
@ -228,6 +233,10 @@ ssize_t _native_write(int fd, const void *buf, size_t count)
|
|||||||
{
|
{
|
||||||
ssize_t r;
|
ssize_t r;
|
||||||
|
|
||||||
|
if (fd == STDOUT_FILENO || fd == STDERR_FILENO) {
|
||||||
|
return stdio_write(buf, count);
|
||||||
|
}
|
||||||
|
|
||||||
_native_syscall_enter();
|
_native_syscall_enter();
|
||||||
r = real_write(fd, buf, count);
|
r = real_write(fd, buf, count);
|
||||||
_native_syscall_leave();
|
_native_syscall_leave();
|
||||||
@ -237,7 +246,27 @@ ssize_t _native_write(int fd, const void *buf, size_t count)
|
|||||||
|
|
||||||
ssize_t _native_writev(int fd, const struct iovec *iov, int iovcnt)
|
ssize_t _native_writev(int fd, const struct iovec *iov, int iovcnt)
|
||||||
{
|
{
|
||||||
ssize_t r;
|
ssize_t r = 0;
|
||||||
|
|
||||||
|
if (fd == STDOUT_FILENO || fd == STDERR_FILENO) {
|
||||||
|
while (iovcnt--) {
|
||||||
|
ssize_t res = stdio_write(iov->iov_base, iov->iov_len);
|
||||||
|
|
||||||
|
if (res >= 0) {
|
||||||
|
r += res;
|
||||||
|
} else {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res < (int)iov->iov_len) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
iov++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
_native_syscall_enter();
|
_native_syscall_enter();
|
||||||
r = real_writev(fd, iov, iovcnt);
|
r = real_writev(fd, iov, iovcnt);
|
||||||
@ -251,8 +280,14 @@ ssize_t _native_writev(int fd, const struct iovec *iov, int iovcnt)
|
|||||||
#endif
|
#endif
|
||||||
int putchar(int c)
|
int putchar(int c)
|
||||||
{
|
{
|
||||||
_native_write(STDOUT_FILENO, &c, 1);
|
char tmp = c;
|
||||||
return 0;
|
return _native_write(STDOUT_FILENO, &tmp, sizeof(tmp));
|
||||||
|
}
|
||||||
|
|
||||||
|
int putc(int c, FILE *fp)
|
||||||
|
{
|
||||||
|
char tmp = c;
|
||||||
|
return _native_write(fileno(fp), &tmp, sizeof(tmp));
|
||||||
}
|
}
|
||||||
|
|
||||||
int puts(const char *s)
|
int puts(const char *s)
|
||||||
@ -263,6 +298,22 @@ int puts(const char *s)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int fgetc(FILE *fp)
|
||||||
|
{
|
||||||
|
return getc(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
int getc(FILE *fp)
|
||||||
|
{
|
||||||
|
char c;
|
||||||
|
|
||||||
|
if (_native_read(fileno(fp), &c, sizeof(c)) <= 0) {
|
||||||
|
return EOF;
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
/* Solve 'format string is not a string literal' as it is validly used in this
|
/* Solve 'format string is not a string literal' as it is validly used in this
|
||||||
* function */
|
* function */
|
||||||
__attribute__((__format__ (__printf__, 1, 0)))
|
__attribute__((__format__ (__printf__, 1, 0)))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user