stubs.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /**
  2. * reimplement arm c library's basic functions
  3. */
  4. #include <string.h>
  5. #include <rt_sys.h>
  6. #include "rtthread.h"
  7. #pragma import(__use_no_semihosting_swi)
  8. int remove(const char *filename)
  9. {
  10. RT_ASSERT(0);
  11. for(;;);
  12. }
  13. /* rename() */
  14. int system(const char *string)
  15. {
  16. RT_ASSERT(0);
  17. for(;;);
  18. }
  19. /* Standard IO device handles. */
  20. #define STDIN 1
  21. #define STDOUT 2
  22. #define STDERR 3
  23. /* Standard IO device name defines. */
  24. const char __stdin_name[] = "STDIN";
  25. const char __stdout_name[] = "STDOUT";
  26. const char __stderr_name[] = "STDERR";
  27. FILEHANDLE _sys_open(const char *name, int openmode)
  28. {
  29. /* Register standard Input Output devices. */
  30. if (strcmp(name, __stdin_name) == 0)
  31. return (STDIN);
  32. if (strcmp(name, __stdout_name) == 0)
  33. return (STDOUT);
  34. if (strcmp(name, __stderr_name) == 0)
  35. return (STDERR);
  36. #ifndef RT_USING_DFS
  37. return 0;
  38. #else
  39. /* TODO: adjust open file mode */
  40. return open(name, openmode, 0);
  41. #endif
  42. }
  43. int _sys_close(FILEHANDLE fh)
  44. {
  45. #ifndef RT_USING_DFS
  46. return 0;
  47. #else
  48. if (fh < 3)
  49. return 0;
  50. return close(fh);
  51. #endif
  52. }
  53. int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
  54. {
  55. if (fh == STDIN)
  56. {
  57. /* TODO */
  58. return 0;
  59. }
  60. #ifndef RT_USING_DFS
  61. return 0;
  62. #else
  63. return read(fh, buf, len);
  64. #endif
  65. }
  66. int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
  67. {
  68. if ((fh == STDOUT) || (fh == STDERR))
  69. {
  70. #ifndef RT_USING_CONSOLE
  71. return 0;
  72. #else
  73. rt_device_t console_device;
  74. extern rt_device_t rt_console_get_device(void);
  75. console_device = rt_console_get_device();
  76. if (console_device != 0) rt_device_write(console_device, 0, buf, len);
  77. return len;
  78. #endif
  79. }
  80. #ifndef RT_USING_DFS
  81. return 0;
  82. #else
  83. return write(fh, buf, len);
  84. #endif
  85. }
  86. int _sys_seek(FILEHANDLE fh, long pos)
  87. {
  88. #ifndef RT_USING_DFS
  89. return 0;
  90. #else
  91. /* TODO: adjust last parameter */
  92. return lseek(fh, pos, 0);
  93. #endif
  94. }
  95. int _sys_tmpnam(char *name, int fileno, unsigned maxlength)
  96. {
  97. return 0;
  98. }
  99. char *_sys_command_string(char *cmd, int len)
  100. {
  101. return cmd;
  102. }
  103. void _ttywrch(int ch)
  104. {
  105. }
  106. void _sys_exit(int return_code)
  107. {
  108. while (1);
  109. }
  110. long _sys_flen(FILEHANDLE fh)
  111. {
  112. return 0;
  113. }
  114. int _sys_istty(FILEHANDLE fh)
  115. {
  116. return 0;
  117. }