syscalls.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #include <reent.h>
  2. #include <sys/errno.h>
  3. #include <rtthread.h>
  4. /* Reentrant versions of system calls. */
  5. int
  6. _close_r(struct _reent *ptr, int fd)
  7. {
  8. return close(fd);
  9. }
  10. int
  11. _execve_r(struct _reent *ptr, const char * name, char *const *argv, char *const *env)
  12. {
  13. /* return "not supported" */
  14. ptr->_errno = ENOTSUP;
  15. return -1;
  16. }
  17. int
  18. _fcntl_r(struct _reent *ptr, int fd, int cmd, int arg)
  19. {
  20. /* return "not supported" */
  21. ptr->_errno = ENOTSUP;
  22. return -1;
  23. }
  24. int
  25. _fork_r(struct _reent *ptr)
  26. {
  27. /* return "not supported" */
  28. ptr->_errno = ENOTSUP;
  29. return -1;
  30. }
  31. int
  32. _fstat_r(struct _reent *ptr, int fd, struct stat *pstat)
  33. {
  34. /* return "not supported" */
  35. ptr->_errno = ENOTSUP;
  36. return -1;
  37. }
  38. int
  39. _getpid_r(struct _reent *ptr)
  40. {
  41. return 0;
  42. }
  43. int
  44. _isatty_r(struct _reent *ptr, int fd)
  45. {
  46. /* return "not supported" */
  47. ptr->_errno = ENOTSUP;
  48. return -1;
  49. }
  50. int
  51. _kill_r(struct _reent *ptr, int pid, int sig)
  52. {
  53. /* return "not supported" */
  54. ptr->_errno = ENOTSUP;
  55. return -1;
  56. }
  57. int
  58. _link_r(struct _reent *ptr, const char *old, const char *new)
  59. {
  60. /* return "not supported" */
  61. ptr->_errno = ENOTSUP;
  62. return -1;
  63. }
  64. _off_t
  65. _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence)
  66. {
  67. _off_t rc;
  68. rc = lseek(fd, pos, whence);
  69. return rc;
  70. }
  71. int
  72. _mkdir_r(struct _reent *ptr, const char *name, int mode)
  73. {
  74. int rc;
  75. rc = mkdir(name, mode);
  76. return rc;
  77. }
  78. int
  79. _open_r(struct _reent *ptr, const char *file, int flags, int mode)
  80. {
  81. int rc;
  82. rc = open(file, flags, mode);
  83. return rc;
  84. }
  85. _ssize_t
  86. _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes)
  87. {
  88. _ssize_t rc;
  89. rc = read(fd, buf, nbytes);
  90. return rc;
  91. }
  92. int
  93. _rename_r(struct _reent *ptr, const char *old, const char *new)
  94. {
  95. int rc;
  96. rc = rename(old, new);
  97. return rc;
  98. }
  99. void *
  100. _sbrk_r(struct _reent *ptr, ptrdiff_t incr)
  101. {
  102. /* no use this routine to get memory */
  103. return RT_NULL;
  104. }
  105. int
  106. _stat_r(struct _reent *ptr, const char *file, struct stat *pstat)
  107. {
  108. int rc;
  109. rc = stat(file, pstat);
  110. return rc;
  111. }
  112. _CLOCK_T_
  113. _times_r(struct _reent *ptr, struct tms *ptms)
  114. {
  115. /* return "not supported" */
  116. ptr->_errno = ENOTSUP;
  117. return -1;
  118. }
  119. int
  120. _unlink_r(struct _reent *ptr, const char *file)
  121. {
  122. int rc;
  123. rc = unlink(file);
  124. return rc;
  125. }
  126. int
  127. _wait_r(struct _reent *ptr, int *status)
  128. {
  129. /* return "not supported" */
  130. ptr->_errno = ENOTSUP;
  131. return -1;
  132. }
  133. _ssize_t
  134. _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
  135. {
  136. _ssize_t rc;
  137. rc = write(fd, buf, nbytes);
  138. return rc;
  139. }
  140. int
  141. _gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp)
  142. {
  143. /* return "not supported" */
  144. ptr->_errno = ENOTSUP;
  145. return -1;
  146. }
  147. /* Memory routine */
  148. void *
  149. _malloc_r (struct _reent *ptr, size_t size)
  150. {
  151. return (void*)rt_malloc (size);
  152. }
  153. void *
  154. _realloc_r (struct _reent *ptr, void *old, size_t newlen)
  155. {
  156. return (void*)rt_realloc (old, newlen);
  157. }
  158. void *_calloc_r (struct _reent *ptr, size_t size, size_t len)
  159. {
  160. return (void*)rt_calloc (size, len);
  161. }
  162. void
  163. _free_r (struct _reent *ptr, void *addr)
  164. {
  165. rt_free (addr);
  166. }