rtt_file.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * Copyright 2024 Sony Semiconductor Solutions Corporation.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  5. */
  6. #include "platform_api_vmcore.h"
  7. #include "platform_api_extension.h"
  8. #include <errno.h>
  9. #include <stdio.h>
  10. #include <stddef.h>
  11. #include <fcntl.h>
  12. #include <stdint.h>
  13. struct iovec {
  14. void *iov_base;
  15. size_t iov_len;
  16. };
  17. ssize_t
  18. readv(int fd, const struct iovec *iov, int iovcnt)
  19. {
  20. ssize_t ntotal;
  21. ssize_t nread;
  22. size_t remaining;
  23. uint8_t *buffer;
  24. int i;
  25. /* Process each entry in the struct iovec array */
  26. for (i = 0, ntotal = 0; i < iovcnt; i++) {
  27. /* Ignore zero-length reads */
  28. if (iov[i].iov_len > 0) {
  29. buffer = iov[i].iov_base;
  30. remaining = iov[i].iov_len;
  31. /* Read repeatedly as necessary to fill buffer */
  32. do {
  33. /* NOTE: read() is a cancellation point */
  34. nread = read(fd, buffer, remaining);
  35. /* Check for a read error */
  36. if (nread < 0) {
  37. return nread;
  38. }
  39. /* Check for an end-of-file condition */
  40. else if (nread == 0) {
  41. return ntotal;
  42. }
  43. /* Update pointers and counts in order to handle partial
  44. * buffer reads.
  45. */
  46. buffer += nread;
  47. remaining -= nread;
  48. ntotal += nread;
  49. } while (remaining > 0);
  50. }
  51. }
  52. return ntotal;
  53. }
  54. ssize_t
  55. writev(int fd, const struct iovec *iov, int iovcnt)
  56. {
  57. uint16_t i, num;
  58. int length;
  59. num = 0;
  60. for (i = 0; i < iovcnt; i++) {
  61. if (iov[i].iov_len > 0) {
  62. length = write(fd, iov[i].iov_base, iov[i].iov_len);
  63. if (length != iov[i].iov_len)
  64. return errno;
  65. num += iov[i].iov_len;
  66. }
  67. }
  68. return num;
  69. }
  70. int
  71. fstatat(int fd, const char *path, struct stat *buf, int flag)
  72. {
  73. errno = ENOSYS;
  74. return -1;
  75. }
  76. int
  77. mkdirat(int fd, const char *path, mode_t mode)
  78. {
  79. errno = ENOSYS;
  80. return -1;
  81. }
  82. ssize_t
  83. readlinkat(int fd, const char *path, char *buf, size_t bufsize)
  84. {
  85. errno = EINVAL;
  86. return -1;
  87. }
  88. int
  89. linkat(int fd1, const char *path1, int fd2, const char *path2, int flag)
  90. {
  91. errno = ENOSYS;
  92. return -1;
  93. }
  94. int
  95. renameat(int fromfd, const char *from, int tofd, const char *to)
  96. {
  97. errno = ENOSYS;
  98. return -1;
  99. }
  100. int
  101. symlinkat(const char *target, int fd, const char *path)
  102. {
  103. errno = ENOSYS;
  104. return -1;
  105. }
  106. int
  107. unlinkat(int fd, const char *path, int flag)
  108. {
  109. errno = ENOSYS;
  110. return -1;
  111. }
  112. int
  113. utimensat(int fd, const char *path, const struct timespec *ts, int flag)
  114. {
  115. errno = ENOSYS;
  116. return -1;
  117. }
  118. DIR *
  119. fdopendir(int fd)
  120. {
  121. errno = ENOSYS;
  122. return NULL;
  123. }
  124. int
  125. fdatasync(int fd)
  126. {
  127. errno = ENOSYS;
  128. return -1;
  129. }
  130. ssize_t
  131. preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset)
  132. {
  133. errno = ENOSYS;
  134. return 0;
  135. }
  136. ssize_t
  137. pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset)
  138. {
  139. errno = ENOSYS;
  140. return 0;
  141. }
  142. char *
  143. realpath(char *path, char *resolved_path)
  144. {
  145. errno = ENOSYS;
  146. return NULL;
  147. }
  148. int
  149. futimens(int fd, const struct timespec *times)
  150. {
  151. errno = ENOSYS;
  152. return -1;
  153. }
  154. int
  155. posix_fallocate(int __fd, off_t __offset, off_t __length)
  156. {
  157. errno = ENOSYS;
  158. return -1;
  159. }
  160. os_raw_file_handle
  161. os_invalid_raw_handle(void)
  162. {
  163. return -1;
  164. }