From b4e59bac4e2d8b039a2365ddc219ac9a3caf0f77 Mon Sep 17 00:00:00 2001 From: yangfasheng Date: Tue, 20 Jun 2023 23:09:58 +0800 Subject: dfs v2 修改 fd_new 的 startfd 起始值为 0 ;修复 futex_wait 超时时间换算异常; (#7705) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangfasheng --- components/libc/posix/io/stdio/libc.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'components/libc') diff --git a/components/libc/posix/io/stdio/libc.c b/components/libc/posix/io/stdio/libc.c index a5bee3f448..9c7d28fefd 100644 --- a/components/libc/posix/io/stdio/libc.c +++ b/components/libc/posix/io/stdio/libc.c @@ -30,15 +30,34 @@ int libc_system_init(void) dev_console = rt_console_get_device(); if (dev_console) { - int fd = libc_stdio_set_console(dev_console->parent.name, O_RDWR); - if (fd < 0) + int fd, ret; + char name[STDIO_DEVICE_NAME_MAX]; + + rt_snprintf(name, sizeof(name) - 1, "/dev/%s", dev_console->parent.name); + name[STDIO_DEVICE_NAME_MAX - 1] = '\0'; + + fd = open(name, O_RDWR); + if (fd >= 0) + { + /* set fd (0, 1, 2) */ + ret = sys_dup2(fd, 0); + if (ret != fd) + { + close(fd); + } + sys_dup2(ret, 1); + sys_dup2(ret, 2); + + ret = libc_stdio_set_console(dev_console->parent.name, O_RDWR); + if (ret < 0) + { + return -1; + } + } + else { return -1; } - /* set fd (0, 1, 2) */ - sys_dup2(fd, 0); - sys_dup2(fd, 1); - sys_dup2(fd, 2); } #endif /* RT_USING_POSIX_STDIO */ return 0; -- cgit v1.3.1