Created
February 23, 2026 00:49
-
-
Save mattj1/82339077f541aec1910655d6db6d91ad to your computer and use it in GitHub Desktop.
stdio_js.odin workaround
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #+private | |
| package odin_libc | |
| import "core:c" | |
| foreign import "odin_env" | |
| @(default_calling_convention = "c") | |
| foreign { | |
| @(link_name="fopen") _fopen :: proc (path, mode: cstring) -> FILE --- | |
| @(link_name="fseek") _fseek :: proc(file: FILE, offset: c.long, whence: i32) -> i32 --- | |
| @(link_name="ftell") _ftell :: proc (stream: FILE) -> c.long --- | |
| @(link_name="fclose") _fclose :: proc(file: FILE) -> i32 --- | |
| @(link_name="fread") _fread :: proc(buffer: [^]byte, size: uint, count: uint, file: FILE) -> uint --- | |
| @(link_name="fwrite") _fwrite :: proc(buffer: [^]byte, size: uint, count: uint, file: FILE) -> uint --- | |
| } | |
| _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 | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment