libc.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include <rtthread.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <fcntl.h>
  5. #include <sys/time.h>
  6. #include "libc.h"
  7. #ifdef RT_USING_PTHREADS
  8. #include <pthread.h>
  9. #endif
  10. #ifdef RT_USING_DFS
  11. #include <dfs_posix.h>
  12. #ifdef RT_USING_DFS_DEVFS
  13. #include <devfs.h>
  14. #endif
  15. #endif
  16. int libc_system_init(void)
  17. {
  18. #ifdef RT_USING_DFS
  19. int fd;
  20. struct rt_device *console_dev;
  21. #ifndef RT_USING_DFS_DEVFS
  22. #error Please enable devfs by defining RT_USING_DFS_DEVFS in rtconfig.h
  23. #endif
  24. console_dev = rt_console_get_device();
  25. if (console_dev)
  26. {
  27. /* initialize console device */
  28. rt_console_init(console_dev->parent.name);
  29. /* open console as stdin/stdout/stderr */
  30. fd = open("/dev/console", O_RDONLY, 0); /* for stdin */
  31. fd = open("/dev/console", O_WRONLY, 0); /* for stdout */
  32. fd = open("/dev/console", O_WRONLY, 0); /* for stderr */
  33. /* skip warning */
  34. fd = fd;
  35. }
  36. #endif
  37. /* set PATH and HOME */
  38. putenv("PATH=/bin");
  39. putenv("HOME=/home");
  40. #if defined RT_USING_PTHREADS && !defined RT_USING_COMPONENTS_INIT
  41. pthread_system_init();
  42. #endif
  43. return 0;
  44. }
  45. INIT_COMPONENT_EXPORT(libc_system_init);