diff --git a/components/libc/newlib/libc.c b/components/libc/newlib/libc.c new file mode 100644 index 0000000000000000000000000000000000000000..1f8d7221f02041d3e6fbca2b996bea1f576b15f9 --- /dev/null +++ b/components/libc/newlib/libc.c @@ -0,0 +1,20 @@ +#include +#include +#include +#include + +void libc_system_init(const char* tty_name) +{ + int fd; + + /* init console device */ + rt_console_init(tty_name); + + /* open console as stdin/stdout/stderr */ + fd = open("/dev/console", O_RDONLY, 0); /* for stdin */ + rt_kprintf("stdin: %d\n", fd); + fd = open("/dev/console", O_WRONLY, 0); /* for stdout */ + rt_kprintf("stdout: %d\n", fd); + fd = open("/dev/console", O_WRONLY, 0); /* for stderr */ + rt_kprintf("stderr: %d\n", fd); +} diff --git a/components/libc/newlib/libc.h b/components/libc/newlib/libc.h new file mode 100644 index 0000000000000000000000000000000000000000..b21a7264b385cc465b3dd8b192cd04fe05adbabb --- /dev/null +++ b/components/libc/newlib/libc.h @@ -0,0 +1,6 @@ +#ifndef __RTT_LIBC_H__ +#define __RTT_LIBC_H__ + +void libc_system_init(const char* tty_name); + +#endif diff --git a/components/libc/newlib/syscalls.c b/components/libc/newlib/syscalls.c index 3625f2d23426bd265ce20f37f5be35ea5200c038..93d96fe16586b4bde64c5b9e80806ae651b10a5f 100644 --- a/components/libc/newlib/syscalls.c +++ b/components/libc/newlib/syscalls.c @@ -51,6 +51,8 @@ _getpid_r(struct _reent *ptr) int _isatty_r(struct _reent *ptr, int fd) { + if (fd >=0 && fd < 3) return 1; + /* return "not supported" */ ptr->_errno = ENOTSUP; return -1; @@ -198,3 +200,18 @@ _free_r (struct _reent *ptr, void *addr) { rt_free (addr); } + +#ifdef RT_USING_FINSH +#include +#include +#include +#include +void nltest() +{ + printf("stdout test!!\n"); + fprintf(stdout, "fprintf test!!\n"); + fprintf(stderr, "fprintf test!!\n"); +} +FINSH_FUNCTION_EXPORT(nltest, newlib test); +#endif +