Minor changes to os2

This commit is contained in:
gingerBill
2024-02-17 13:41:54 +00:00
parent c5c2a4d09d
commit fa1875a8f1
5 changed files with 55 additions and 3 deletions
+41 -3
View File
@@ -1,10 +1,11 @@
//+private
package os2
import "base:runtime"
import "core:io"
import "core:mem"
import "core:sync"
import "base:runtime"
import "core:strings"
import "core:time"
import "core:unicode/utf16"
@@ -20,11 +21,45 @@ _file_allocator :: proc() -> runtime.Allocator {
return heap_allocator()
}
_temp_allocator_proc :: runtime.arena_allocator_proc
@(private="file", thread_local)
_global_default_temp_allocator_arena: runtime.Arena
_temp_allocator :: proc() -> runtime.Allocator {
// TODO(bill): make this not depend on the context allocator
return context.temp_allocator
return runtime.Allocator{
procedure = _temp_allocator_proc,
data = &_global_default_temp_allocator_arena,
}
}
@(require_results)
_temp_allocator_temp_begin :: proc(loc := #caller_location) -> (temp: runtime.Arena_Temp) {
temp = runtime.arena_temp_begin(&_global_default_temp_allocator_arena, loc)
return
}
_temp_allocator_temp_end :: proc(temp: runtime.Arena_Temp, loc := #caller_location) {
runtime.arena_temp_end(temp, loc)
}
@(fini, private)
_destroy_temp_allocator_fini :: proc() {
runtime.arena_destroy(&_global_default_temp_allocator_arena)
_global_default_temp_allocator_arena = {}
}
@(deferred_out=_temp_allocator_temp_end)
_TEMP_ALLOCATOR_GUARD :: #force_inline proc(ignore := false, loc := #caller_location) -> (runtime.Arena_Temp, runtime.Source_Code_Location) {
if ignore {
return {}, loc
} else {
return _temp_allocator_temp_begin(loc), loc
}
}
_File_Kind :: enum u8 {
File,
@@ -546,6 +581,9 @@ _normalize_link_path :: proc(p: []u16, allocator: runtime.Allocator) -> (str: st
if n == 0 {
return "", _get_platform_error()
}
_TEMP_ALLOCATOR_GUARD()
buf := make([]u16, n+1, _temp_allocator())
n = win32.GetFinalPathNameByHandleW(handle, raw_data(buf), u32(len(buf)), win32.VOLUME_NAME_DOS)
if n == 0 {