os_js.odin 8.3 KB

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