aboutsummaryrefslogtreecommitdiff
path: root/vendor
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2026-02-11 17:53:16 +0000
committerGitHub <noreply@github.com>2026-02-11 17:53:16 +0000
commit355b8a8c83badc64d23dbb34ea00bb89ac9245db (patch)
tree1103d5bde2dd10c28a81f2104d9c17fa0f4c3166 /vendor
parentb5bf28dc47dd1c32a45ba0bbedcbcef80409b798 (diff)
parent1a37f4eb0cc792783784fca216c79e3f02a3234e (diff)
Merge pull request #6245 from odin-lang/new_os
`core:os/os2` -> `core:os` integration
Diffstat (limited to 'vendor')
-rw-r--r--vendor/OpenGL/helpers.odin38
-rw-r--r--vendor/fontstash/fontstash_os.odin7
-rw-r--r--vendor/libc-shim/stdio.odin66
-rw-r--r--vendor/libc-shim/stdio_js.odin60
-rw-r--r--vendor/libc-shim/stdio_os.odin104
-rw-r--r--vendor/libc-shim/stdlib.odin3
6 files changed, 209 insertions, 69 deletions
diff --git a/vendor/OpenGL/helpers.odin b/vendor/OpenGL/helpers.odin
index 84e3eae81..9c9c74d09 100644
--- a/vendor/OpenGL/helpers.odin
+++ b/vendor/OpenGL/helpers.odin
@@ -3,10 +3,11 @@ package vendor_gl
// Helper for loading shaders into a program
-import "core:os"
-import "core:fmt"
-import "core:strings"
-import "base:runtime"
+import "core:os"
+import "core:fmt"
+import "core:strings"
+@(require) import "core:time"
+import "base:runtime"
_ :: fmt
_ :: runtime
@@ -150,7 +151,10 @@ create_and_link_program :: proc(shader_ids: []u32, binary_retrievable := false)
}
load_compute_file :: proc(filename: string, binary_retrievable := false) -> (program_id: u32, ok: bool) {
- cs_data := os.read_entire_file(filename) or_return
+ cs_data, cs_data_err := os.read_entire_file(filename, context.allocator)
+ if cs_data_err != nil {
+ return 0, false
+ }
defer delete(cs_data)
// Create the shaders
@@ -165,10 +169,16 @@ load_compute_source :: proc(cs_data: string, binary_retrievable := false) -> (pr
}
load_shaders_file :: proc(vs_filename, fs_filename: string, binary_retrievable := false) -> (program_id: u32, ok: bool) {
- vs_data := os.read_entire_file(vs_filename) or_return
+ vs_data, vs_data_err := os.read_entire_file(vs_filename, context.allocator)
+ if vs_data_err != nil {
+ return 0, false
+ }
defer delete(vs_data)
- fs_data := os.read_entire_file(fs_filename) or_return
+ fs_data, fs_data_err := os.read_entire_file(fs_filename, context.allocator)
+ if fs_data_err != nil {
+ return 0, false
+ }
defer delete(fs_data)
return load_shaders_source(string(vs_data), string(fs_data), binary_retrievable)
@@ -192,14 +202,14 @@ when ODIN_OS == .Windows {
update_shader_if_changed :: proc(
vertex_name, fragment_name: string,
program: u32,
- last_vertex_time, last_fragment_time: os.File_Time,
+ last_vertex_time, last_fragment_time: time.Time,
) -> (
old_program: u32,
- current_vertex_time, current_fragment_time: os.File_Time,
+ current_vertex_time, current_fragment_time: time.Time,
updated: bool,
) {
- current_vertex_time, _ = os.last_write_time_by_name(vertex_name)
- current_fragment_time, _ = os.last_write_time_by_name(fragment_name)
+ current_vertex_time, _ = os.modification_time_by_path(vertex_name)
+ current_fragment_time, _ = os.modification_time_by_path(fragment_name)
old_program = program
if current_vertex_time != last_vertex_time || current_fragment_time != last_fragment_time {
@@ -220,13 +230,13 @@ when ODIN_OS == .Windows {
update_shader_if_changed_compute :: proc(
compute_name: string,
program: u32,
- last_compute_time: os.File_Time,
+ last_compute_time: time.Time,
) -> (
old_program: u32,
- current_compute_time: os.File_Time,
+ current_compute_time: time.Time,
updated: bool,
) {
- current_compute_time, _ = os.last_write_time_by_name(compute_name)
+ current_compute_time, _ = os.modification_time_by_path(compute_name)
old_program = program
if current_compute_time != last_compute_time {
diff --git a/vendor/fontstash/fontstash_os.odin b/vendor/fontstash/fontstash_os.odin
index e510a4834..d04df044c 100644
--- a/vendor/fontstash/fontstash_os.odin
+++ b/vendor/fontstash/fontstash_os.odin
@@ -12,12 +12,11 @@ AddFontPath :: proc(
path: string,
fontIndex: int = 0,
) -> int {
- data, ok := os.read_entire_file(path)
+ data, data_err := os.read_entire_file(path, context.allocator)
- if !ok {
+ if data_err != nil {
log.panicf("FONT: failed to read font at %s", path)
}
return AddFontMem(ctx, name, data, true, fontIndex)
-}
-
+} \ No newline at end of file
diff --git a/vendor/libc-shim/stdio.odin b/vendor/libc-shim/stdio.odin
index e269b8986..b47b3f166 100644
--- a/vendor/libc-shim/stdio.odin
+++ b/vendor/libc-shim/stdio.odin
@@ -4,93 +4,60 @@ package odin_libc
import "base:runtime"
import "core:c"
-import "core:io"
-import "core:os"
import "core:strconv"
import stb "vendor:stb/sprintf"
-FILE :: uintptr
+FILE :: rawptr
EOF :: -1
@(require, linkage="strong", link_name="fopen")
fopen :: proc "c" (path: cstring, mode: cstring) -> FILE {
context = g_ctx
- unimplemented("vendor/libc-shim: fopen")
+ return _fopen(path, mode)
}
@(require, linkage="strong", link_name="fseek")
fseek :: proc "c" (file: FILE, offset: c.long, whence: i32) -> i32 {
context = g_ctx
- handle := os.Handle(file-1)
- _, err := os.seek(handle, i64(offset), int(whence))
- if err != nil {
- return -1
- }
- return 0
+ return _fseek(file, offset, whence)
}
@(require, linkage="strong", link_name="ftell")
ftell :: proc "c" (file: FILE) -> c.long {
context = g_ctx
- handle := os.Handle(file-1)
- off, err := os.seek(handle, 0, os.SEEK_CUR)
- if err != nil {
- return -1
- }
- return c.long(off)
+ return _ftell(file)
}
@(require, linkage="strong", link_name="fclose")
fclose :: proc "c" (file: FILE) -> i32 {
context = g_ctx
- handle := os.Handle(file-1)
- if os.close(handle) != nil {
- return -1
- }
- return 0
+ return _fclose(file)
}
@(require, linkage="strong", link_name="fread")
fread :: proc "c" (buffer: [^]byte, size: uint, count: uint, file: FILE) -> uint {
context = g_ctx
- handle := os.Handle(file-1)
- n, _ := os.read(handle, buffer[:min(size, count)])
- return uint(max(0, n))
+ return _fread(buffer, size, count, file)
}
@(require, linkage="strong", link_name="fwrite")
fwrite :: proc "c" (buffer: [^]byte, size: uint, count: uint, file: FILE) -> uint {
context = g_ctx
- handle := os.Handle(file-1)
- n, _ := os.write(handle, buffer[:min(size, count)])
- return uint(max(0, n))
+ return _fwrite(buffer, size, count, file)
}
@(require, linkage="strong", link_name="putchar")
putchar :: proc "c" (char: c.int) -> c.int {
context = g_ctx
-
- n, err := os.write_byte(os.stdout, byte(char))
- if n == 0 || err != nil {
- return EOF
- }
- return char
+ return _putchar(char)
}
@(require, linkage="strong", link_name="getchar")
getchar :: proc "c" () -> c.int {
- when #defined(os.stdin) {
- ret: [1]byte
- n, err := os.read(os.stdin, ret[:])
- if n == 0 || err != nil {
- return EOF
- }
- return c.int(ret[0])
- } else {
- return EOF
- }
+ context = g_ctx
+ return _getchar()
}
@(require, linkage="strong", link_name="vsnprintf")
@@ -109,8 +76,6 @@ vsprintf :: proc "c" (buf: [^]byte, fmt: cstring, args: ^c.va_list) -> i32 {
vfprintf :: proc "c" (file: FILE, fmt: cstring, args: ^c.va_list) -> i32 {
context = g_ctx
- handle := os.Handle(file-1)
-
MAX_STACK :: 4096
buf: []byte
@@ -133,12 +98,15 @@ vfprintf :: proc "c" (file: FILE, fmt: cstring, args: ^c.va_list) -> i32 {
delete(buf)
}
- _, err := io.write_full(os.stream_from_handle(handle), buf)
- if err != nil {
- return -1
+ written: i32
+ for len(buf) > 0 {
+ n := _fwrite(raw_data(buf), size_of(byte), len(buf), file)
+ if n == 0 { break }
+ buf = buf[n:]
+ written += i32(n)
}
- return i32(len(buf))
+ return written
}
/*
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
+ }
+}
diff --git a/vendor/libc-shim/stdio_os.odin b/vendor/libc-shim/stdio_os.odin
new file mode 100644
index 000000000..f6d30a227
--- /dev/null
+++ b/vendor/libc-shim/stdio_os.odin
@@ -0,0 +1,104 @@
+#+build !freestanding
+#+build !js
+package odin_libc
+
+import "core:io"
+import "core:c"
+import "core:os"
+
+_fopen :: proc(path, _mode: cstring) -> FILE {
+ flags: os.File_Flags
+
+ mode := string(_mode)
+ if len(mode) > 1 {
+ switch mode[0] {
+ case 'r':
+ flags += {.Read}
+ case 'w':
+ flags += {.Write, .Create, .Trunc}
+ case 'a':
+ flags += {.Write, .Create, .Append}
+ case:
+ return nil
+ }
+
+ if len(mode) > 1 && mode[1] == '+' {
+ flags += {.Write, .Read}
+ } else if len(mode) > 2 && mode[1] == 'b' && mode[2] == '+' {
+ flags += {.Write, .Read}
+ }
+ }
+
+ file, err := os.open(string(path), flags, os.Permissions_Read_Write_All)
+ if err != nil {
+ return nil
+ }
+
+ return FILE(file)
+}
+
+_fseek :: proc(_file: FILE, offset: c.long, whence: i32) -> i32 {
+ file := __file(_file)
+ if _, err := os.seek(file, i64(offset), io.Seek_From(whence)); err != nil {
+ return -1
+ }
+
+ return 0
+}
+
+_ftell :: proc(_file: FILE) -> c.long {
+ file := __file(_file)
+ pos, err := os.seek(file, 0, .Current)
+ if err != nil {
+ return -1
+ }
+
+ return c.long(pos)
+}
+
+_fclose :: proc(_file: FILE) -> i32 {
+ file := __file(_file)
+ if err := os.close(file); err != nil {
+ return EOF
+ }
+
+ return 0
+}
+
+_fread :: proc(buffer: [^]byte, size: uint, count: uint, _file: FILE) -> uint {
+ file := __file(_file)
+ n, _ := os.read(file, buffer[:size*count])
+ return uint(max(0, n)) / size
+}
+
+_fwrite :: proc(buffer: [^]byte, size: uint, count: uint, _file: FILE) -> uint {
+ file := __file(_file)
+ n, _ := os.write(file, buffer[:size*count])
+ return uint(max(0, n)) / size
+}
+
+_putchar :: proc(char: c.int) -> c.int {
+ n, err := os.write_byte(os.stdout, byte(char))
+ if n == 0 || err != nil {
+ return EOF
+ }
+ return char
+}
+
+_getchar :: proc() -> c.int {
+ ret: [1]byte
+ n, err := os.read(os.stdin, ret[:])
+ if n == 0 || err != nil {
+ return EOF
+ }
+ return c.int(ret[0])
+}
+
+@(private="file")
+__file :: proc(file: FILE) -> ^os.File {
+ switch (uint(uintptr(file))) {
+ case 2: return os.stdout
+ case 3: return os.stderr
+ case: return (^os.File)(file)
+ }
+}
diff --git a/vendor/libc-shim/stdlib.odin b/vendor/libc-shim/stdlib.odin
index cffc66ed2..5dd4c53c1 100644
--- a/vendor/libc-shim/stdlib.odin
+++ b/vendor/libc-shim/stdlib.odin
@@ -5,7 +5,6 @@ import "base:intrinsics"
import "base:runtime"
import "core:c"
-import "core:os"
import "core:slice"
import "core:sort"
import "core:strconv"
@@ -166,7 +165,7 @@ atexit :: proc "c" (function: proc "c" ()) -> i32 {
@(require, linkage="strong", link_name="exit")
exit :: proc "c" (exit_code: c.int) -> ! {
finish_atexit()
- os.exit(int(exit_code))
+ runtime.exit(int(exit_code))
}
@(private, fini)