mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-01-31 14:20:26 +08:00
add stdin, stdout, stderr implementation in newlib.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1029 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
363ad228a4
commit
a6f06d24cf
20
components/libc/newlib/libc.c
Normal file
20
components/libc/newlib/libc.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include <rtthread.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
6
components/libc/newlib/libc.h
Normal file
6
components/libc/newlib/libc.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef __RTT_LIBC_H__
|
||||||
|
#define __RTT_LIBC_H__
|
||||||
|
|
||||||
|
void libc_system_init(const char* tty_name);
|
||||||
|
|
||||||
|
#endif
|
@ -51,6 +51,8 @@ _getpid_r(struct _reent *ptr)
|
|||||||
int
|
int
|
||||||
_isatty_r(struct _reent *ptr, int fd)
|
_isatty_r(struct _reent *ptr, int fd)
|
||||||
{
|
{
|
||||||
|
if (fd >=0 && fd < 3) return 1;
|
||||||
|
|
||||||
/* return "not supported" */
|
/* return "not supported" */
|
||||||
ptr->_errno = ENOTSUP;
|
ptr->_errno = ENOTSUP;
|
||||||
return -1;
|
return -1;
|
||||||
@ -198,3 +200,18 @@ _free_r (struct _reent *ptr, void *addr)
|
|||||||
{
|
{
|
||||||
rt_free (addr);
|
rt_free (addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef RT_USING_FINSH
|
||||||
|
#include <finsh.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
void nltest()
|
||||||
|
{
|
||||||
|
printf("stdout test!!\n");
|
||||||
|
fprintf(stdout, "fprintf test!!\n");
|
||||||
|
fprintf(stderr, "fprintf test!!\n");
|
||||||
|
}
|
||||||
|
FINSH_FUNCTION_EXPORT(nltest, newlib test);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user