libc.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * File : libc.c
  3. * Brief : gcc libc header file
  4. *
  5. * This file is part of RT-Thread RTOS
  6. * COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. * Change Logs:
  23. * Date Author Notes
  24. * 2017/10/15 bernard the first version
  25. */
  26. #include <rtthread.h>
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <fcntl.h>
  30. #include <sys/time.h>
  31. #include "libc.h"
  32. #ifdef RT_USING_PTHREADS
  33. #include <pthread.h>
  34. #endif
  35. int _EXFUN(putenv,(char *__string));
  36. int libc_system_init(void)
  37. {
  38. #if defined(RT_USING_DFS) & defined(RT_USING_DFS_DEVFS)
  39. rt_device_t dev_console;
  40. dev_console = rt_console_get_device();
  41. if (dev_console)
  42. {
  43. #if defined(RT_USING_POSIX)
  44. libc_stdio_set_console(dev_console->parent.name, O_RDWR);
  45. #else
  46. libc_stdio_set_console(dev_console->parent.name, O_WRONLY);
  47. #endif
  48. }
  49. #endif
  50. /* set PATH and HOME */
  51. putenv("PATH=/bin");
  52. putenv("HOME=/home");
  53. #if defined RT_USING_PTHREADS && !defined RT_USING_COMPONENTS_INIT
  54. pthread_system_init();
  55. #endif
  56. return 0;
  57. }
  58. INIT_COMPONENT_EXPORT(libc_system_init);