From 780c09e3e452568e7befb26c0ffd4ae7f6d1a0cb Mon Sep 17 00:00:00 2001 From: BernardXiong Date: Sun, 11 Feb 2018 13:57:51 +0800 Subject: [libc] Fix the O_CREAT issue. libc_stdio_set_console/newlib uses fopen to open console device, which has O_CREAT flag and cause fault. --- components/libc/compilers/newlib/stdio.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'components/libc') diff --git a/components/libc/compilers/newlib/stdio.c b/components/libc/compilers/newlib/stdio.c index f28383818d..9a225622b5 100644 --- a/components/libc/compilers/newlib/stdio.c +++ b/components/libc/compilers/newlib/stdio.c @@ -81,7 +81,9 @@ int libc_stdio_set_console(const char* device_name, int mode) _GLOBAL_REENT->__sdidinit = 1; } - return fileno(std_console); + if (std_console) return fileno(std_console); + + return -1; } int libc_stdio_get_console(void) { -- cgit v1.3.1 From 43cc01742fc5cce22ccd2037ba80216c5207fc6a Mon Sep 17 00:00:00 2001 From: BernardXiong Date: Sun, 11 Feb 2018 13:58:20 +0800 Subject: [libc] cleanup code. --- components/libc/compilers/dlib/libc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'components/libc') diff --git a/components/libc/compilers/dlib/libc.c b/components/libc/compilers/dlib/libc.c index fe219537e3..fa977ab399 100644 --- a/components/libc/compilers/dlib/libc.c +++ b/components/libc/compilers/dlib/libc.c @@ -36,7 +36,7 @@ int libc_system_init(void) { -#if defined(RT_USING_DFS) & defined(RT_USING_DFS_DEVFS) +#if defined(RT_USING_DFS) && defined(RT_USING_DFS_DEVFS) rt_device_t dev_console; dev_console = rt_console_get_device(); @@ -50,10 +50,11 @@ int libc_system_init(void) } #endif -#if defined RT_USING_PTHREADS && !defined RT_USING_COMPONENTS_INIT +#if defined (RT_USING_PTHREADS) && !defined (RT_USING_COMPONENTS_INIT) pthread_system_init(); #endif return 0; } INIT_COMPONENT_EXPORT(libc_system_init); + -- cgit v1.3.1