xref: /nrf52832-nimble/rt-thread/components/libc/compilers/newlib/libc.c (revision 042d53a763ad75cb1465103098bb88c245d95138)
1 /*
2  * Copyright (c) 2006-2018, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2017/10/15     bernard      the first version
9  */
10 #include <rtthread.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <fcntl.h>
14 #include <sys/time.h>
15 
16 #include "libc.h"
17 
18 #ifdef RT_USING_PTHREADS
19 #include <pthread.h>
20 #endif
21 
22 int	_EXFUN(putenv,(char *__string));
23 
24 int libc_system_init(void)
25 {
26 #if defined(RT_USING_DFS) & defined(RT_USING_DFS_DEVFS) & defined(RT_USING_CONSOLE)
27     rt_device_t dev_console;
28 
29     dev_console = rt_console_get_device();
30     if (dev_console)
31     {
32     #if defined(RT_USING_POSIX)
33         libc_stdio_set_console(dev_console->parent.name, O_RDWR);
34     #else
35         libc_stdio_set_console(dev_console->parent.name, O_WRONLY);
36     #endif
37     }
38 
39     /* set PATH and HOME */
40     putenv("PATH=/bin");
41     putenv("HOME=/home");
42 #endif
43 
44 #if defined RT_USING_PTHREADS && !defined RT_USING_COMPONENTS_INIT
45     pthread_system_init();
46 #endif
47 
48     return 0;
49 }
50 INIT_COMPONENT_EXPORT(libc_system_init);
51