aboutsummaryrefslogtreecommitdiff
path: root/vendor/libc-shim/stdio_js.odin
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/libc-shim/stdio_js.odin')
-rw-r--r--vendor/libc-shim/stdio_js.odin60
1 files changed, 60 insertions, 0 deletions
diff --git a/vendor/libc-shim/stdio_js.odin b/vendor/libc-shim/stdio_js.odin
new file mode 100644
index 000000000..2382ed449
--- /dev/null
+++ b/vendor/libc-shim/stdio_js.odin
@@ -0,0 +1,60 @@
+#+private
+package odin_libc
+
+import "core:c"
+
+foreign import "odin_env"
+
+_fopen :: proc(path, mode: cstring) -> FILE {
+ unimplemented("vendor/libc: fopen in JS")
+}
+
+_fseek :: proc(file: FILE, offset: c.long, whence: i32) -> i32 {
+ unimplemented("vendor/libc: fseek in JS")
+}
+
+_ftell :: proc(file: FILE) -> c.long {
+ unimplemented("vendor/libc: ftell in JS")
+}
+
+_fclose :: proc(file: FILE) -> i32 {
+ unimplemented("vendor/libc: fclose in JS")
+}
+
+_fread :: proc(buffer: [^]byte, size: uint, count: uint, file: FILE) -> uint {
+ unimplemented("vendor/libc: fread in JS")
+}
+
+_fwrite :: proc(buffer: [^]byte, size: uint, count: uint, file: FILE) -> uint {
+ fd, ok := __fd(file)
+ if !ok {
+ return 0
+ }
+
+ __write(fd, buffer[:size*count])
+ return count
+}
+
+_putchar :: proc(char: c.int) -> c.int {
+ __write(1, {byte(char)})
+ return char
+}
+
+_getchar :: proc() -> c.int {
+ return EOF
+}
+
+@(private="file")
+foreign odin_env {
+ @(link_name="write")
+ __write :: proc "contextless" (fd: u32, p: []byte) ---
+}
+
+@(private="file")
+__fd :: proc(file: FILE) -> (u32, bool) {
+ switch (uint(uintptr(file))) {
+ case 2: return 1, true // stdout
+ case 3: return 2, true // stderr
+ case: return 0, false
+ }
+}