os_js.odin 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. #+build js
  2. package os
  3. foreign import "odin_env"
  4. @(require_results)
  5. is_path_separator :: proc(c: byte) -> bool {
  6. return c == '/' || c == '\\'
  7. }
  8. Handle :: distinct u32
  9. stdout: Handle = 1
  10. stderr: Handle = 2
  11. @(require_results)
  12. open :: proc(path: string, mode: int = O_RDONLY, perm: int = 0) -> (Handle, Error) {
  13. unimplemented("core:os procedure not supported on JS target")
  14. }
  15. close :: proc(fd: Handle) -> Error {
  16. return nil
  17. }
  18. flush :: proc(fd: Handle) -> (err: Error) {
  19. return nil
  20. }
  21. write :: proc(fd: Handle, data: []byte) -> (int, Error) {
  22. foreign odin_env {
  23. @(link_name="write")
  24. _write :: proc "contextless" (fd: Handle, p: []byte) ---
  25. }
  26. _write(fd, data)
  27. return len(data), nil
  28. }
  29. read :: proc(fd: Handle, data: []byte) -> (int, Error) {
  30. unimplemented("core:os procedure not supported on JS target")
  31. }
  32. seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Error) {
  33. unimplemented("core:os procedure not supported on JS target")
  34. }
  35. @(require_results)
  36. file_size :: proc(fd: Handle) -> (i64, Error) {
  37. unimplemented("core:os procedure not supported on JS target")
  38. }
  39. read_at :: proc(fd: Handle, data: []byte, offset: i64) -> (n: int, err: Error) {
  40. unimplemented("core:os procedure not supported on JS target")
  41. }
  42. write_at :: proc(fd: Handle, data: []byte, offset: i64) -> (n: int, err: Error) {
  43. unimplemented("core:os procedure not supported on JS target")
  44. }
  45. @(require_results)
  46. exists :: proc(path: string) -> bool {
  47. unimplemented("core:os procedure not supported on JS target")
  48. }
  49. @(require_results)
  50. is_file :: proc(path: string) -> bool {
  51. unimplemented("core:os procedure not supported on JS target")
  52. }
  53. @(require_results)
  54. is_dir :: proc(path: string) -> bool {
  55. unimplemented("core:os procedure not supported on JS target")
  56. }
  57. @(require_results)
  58. get_current_directory :: proc(allocator := context.allocator) -> string {
  59. unimplemented("core:os procedure not supported on JS target")
  60. }
  61. set_current_directory :: proc(path: string) -> (err: Error) {
  62. unimplemented("core:os procedure not supported on JS target")
  63. }
  64. change_directory :: proc(path: string) -> (err: Error) {
  65. unimplemented("core:os procedure not supported on JS target")
  66. }
  67. make_directory :: proc(path: string, mode: u32 = 0) -> (err: Error) {
  68. unimplemented("core:os procedure not supported on JS target")
  69. }
  70. remove_directory :: proc(path: string) -> (err: Error) {
  71. unimplemented("core:os procedure not supported on JS target")
  72. }
  73. link :: proc(old_name, new_name: string) -> (err: Error) {
  74. unimplemented("core:os procedure not supported on JS target")
  75. }
  76. unlink :: proc(path: string) -> (err: Error) {
  77. unimplemented("core:os procedure not supported on JS target")
  78. }
  79. rename :: proc(old_path, new_path: string) -> (err: Error) {
  80. unimplemented("core:os procedure not supported on JS target")
  81. }
  82. ftruncate :: proc(fd: Handle, length: i64) -> (err: Error) {
  83. unimplemented("core:os procedure not supported on JS target")
  84. }
  85. truncate :: proc(path: string, length: i64) -> (err: Error) {
  86. unimplemented("core:os procedure not supported on JS target")
  87. }
  88. remove :: proc(name: string) -> Error {
  89. unimplemented("core:os procedure not supported on JS target")
  90. }
  91. @(require_results)
  92. pipe :: proc() -> (r, w: Handle, err: Error) {
  93. unimplemented("core:os procedure not supported on JS target")
  94. }
  95. @(require_results)
  96. read_dir :: proc(fd: Handle, n: int, allocator := context.allocator) -> (fi: []File_Info, err: Error) {
  97. unimplemented("core:os procedure not supported on JS target")
  98. }
  99. File_Time :: distinct u64
  100. _Platform_Error :: enum i32 {
  101. NONE = 0,
  102. FILE_NOT_FOUND = 2,
  103. PATH_NOT_FOUND = 3,
  104. ACCESS_DENIED = 5,
  105. INVALID_HANDLE = 6,
  106. NOT_ENOUGH_MEMORY = 8,
  107. NO_MORE_FILES = 18,
  108. HANDLE_EOF = 38,
  109. NETNAME_DELETED = 64,
  110. FILE_EXISTS = 80,
  111. INVALID_PARAMETER = 87,
  112. BROKEN_PIPE = 109,
  113. BUFFER_OVERFLOW = 111,
  114. INSUFFICIENT_BUFFER = 122,
  115. MOD_NOT_FOUND = 126,
  116. PROC_NOT_FOUND = 127,
  117. DIR_NOT_EMPTY = 145,
  118. ALREADY_EXISTS = 183,
  119. ENVVAR_NOT_FOUND = 203,
  120. MORE_DATA = 234,
  121. OPERATION_ABORTED = 995,
  122. IO_PENDING = 997,
  123. NOT_FOUND = 1168,
  124. PRIVILEGE_NOT_HELD = 1314,
  125. WSAEACCES = 10013,
  126. WSAECONNRESET = 10054,
  127. // Windows reserves errors >= 1<<29 for application use
  128. FILE_IS_PIPE = 1<<29 + 0,
  129. FILE_IS_NOT_DIR = 1<<29 + 1,
  130. NEGATIVE_OFFSET = 1<<29 + 2,
  131. }
  132. INVALID_HANDLE :: ~Handle(0)
  133. O_RDONLY :: 0x00000
  134. O_WRONLY :: 0x00001
  135. O_RDWR :: 0x00002
  136. O_CREATE :: 0x00040
  137. O_EXCL :: 0x00080
  138. O_NOCTTY :: 0x00100
  139. O_TRUNC :: 0x00200
  140. O_NONBLOCK :: 0x00800
  141. O_APPEND :: 0x00400
  142. O_SYNC :: 0x01000
  143. O_ASYNC :: 0x02000
  144. O_CLOEXEC :: 0x80000
  145. ERROR_FILE_NOT_FOUND :: Platform_Error.FILE_NOT_FOUND
  146. ERROR_PATH_NOT_FOUND :: Platform_Error.PATH_NOT_FOUND
  147. ERROR_ACCESS_DENIED :: Platform_Error.ACCESS_DENIED
  148. ERROR_INVALID_HANDLE :: Platform_Error.INVALID_HANDLE
  149. ERROR_NOT_ENOUGH_MEMORY :: Platform_Error.NOT_ENOUGH_MEMORY
  150. ERROR_NO_MORE_FILES :: Platform_Error.NO_MORE_FILES
  151. ERROR_HANDLE_EOF :: Platform_Error.HANDLE_EOF
  152. ERROR_NETNAME_DELETED :: Platform_Error.NETNAME_DELETED
  153. ERROR_FILE_EXISTS :: Platform_Error.FILE_EXISTS
  154. ERROR_INVALID_PARAMETER :: Platform_Error.INVALID_PARAMETER
  155. ERROR_BROKEN_PIPE :: Platform_Error.BROKEN_PIPE
  156. ERROR_BUFFER_OVERFLOW :: Platform_Error.BUFFER_OVERFLOW
  157. ERROR_INSUFFICIENT_BUFFER :: Platform_Error.INSUFFICIENT_BUFFER
  158. ERROR_MOD_NOT_FOUND :: Platform_Error.MOD_NOT_FOUND
  159. ERROR_PROC_NOT_FOUND :: Platform_Error.PROC_NOT_FOUND
  160. ERROR_DIR_NOT_EMPTY :: Platform_Error.DIR_NOT_EMPTY
  161. ERROR_ALREADY_EXISTS :: Platform_Error.ALREADY_EXISTS
  162. ERROR_ENVVAR_NOT_FOUND :: Platform_Error.ENVVAR_NOT_FOUND
  163. ERROR_MORE_DATA :: Platform_Error.MORE_DATA
  164. ERROR_OPERATION_ABORTED :: Platform_Error.OPERATION_ABORTED
  165. ERROR_IO_PENDING :: Platform_Error.IO_PENDING
  166. ERROR_NOT_FOUND :: Platform_Error.NOT_FOUND
  167. ERROR_PRIVILEGE_NOT_HELD :: Platform_Error.PRIVILEGE_NOT_HELD
  168. WSAEACCES :: Platform_Error.WSAEACCES
  169. WSAECONNRESET :: Platform_Error.WSAECONNRESET
  170. ERROR_FILE_IS_PIPE :: General_Error.File_Is_Pipe
  171. ERROR_FILE_IS_NOT_DIR :: General_Error.Not_Dir
  172. args: []string
  173. @(require_results)
  174. last_write_time :: proc(fd: Handle) -> (File_Time, Error) {
  175. unimplemented("core:os procedure not supported on JS target")
  176. }
  177. @(require_results)
  178. last_write_time_by_name :: proc(name: string) -> (File_Time, Error) {
  179. unimplemented("core:os procedure not supported on JS target")
  180. }
  181. @(require_results)
  182. get_page_size :: proc() -> int {
  183. unimplemented("core:os procedure not supported on JS target")
  184. }
  185. @(private, require_results)
  186. _processor_core_count :: proc() -> int {
  187. return 1
  188. }
  189. exit :: proc "contextless" (code: int) -> ! {
  190. unimplemented_contextless("core:os procedure not supported on JS target")
  191. }
  192. @(require_results)
  193. current_thread_id :: proc "contextless" () -> int {
  194. return 0
  195. }