1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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
}
}
|