diff options
| author | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2025-06-16 20:39:19 +0200 |
|---|---|---|
| committer | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2025-06-16 20:39:19 +0200 |
| commit | b9809e7aa48af6c3af1fe8b53dbdb6c4547aab30 (patch) | |
| tree | 4fd191a36c959a740dbc73a98dc35d74c2dc622d /core/os | |
| parent | 73dcc39d98396bee94b1daf586b593460fc08d3f (diff) | |
OpenBSD
Diffstat (limited to 'core/os')
| -rw-r--r-- | core/os/os_openbsd.odin | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/core/os/os_openbsd.odin b/core/os/os_openbsd.odin index d90e51e13..993bff252 100644 --- a/core/os/os_openbsd.odin +++ b/core/os/os_openbsd.odin @@ -787,9 +787,10 @@ access :: proc(path: string, mask: int) -> (bool, Error) { } @(require_results) -lookup_env :: proc(key: string, allocator := context.allocator) -> (value: string, found: bool) { +lookup_env_alloc :: proc(key: string, allocator := context.allocator) -> (value: string, found: bool) { runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD(ignore = context.temp_allocator == allocator) path_str := strings.clone_to_cstring(key, context.temp_allocator) + // NOTE(tetra): Lifetime of 'cstr' is unclear, but _unix_free(cstr) segfaults. cstr := _unix_getenv(path_str) if cstr == nil { return "", false @@ -798,12 +799,40 @@ lookup_env :: proc(key: string, allocator := context.allocator) -> (value: strin } @(require_results) -get_env :: proc(key: string, allocator := context.allocator) -> (value: string) { +lookup_env_buffer :: proc(buf: []u8, key: string) -> (value: string, err: Error) { + if len(key) + 1 > len(buf) { + return "", .Buffer_Full + } else { + copy(buf, key) + } + + if value = string(_unix_getenv(cstring(raw_data(buf)))); value == "" { + return "", .Env_Var_Not_Found + } else { + if len(value) > len(buf) { + return "", .Buffer_Full + } else { + copy(buf, value) + return string(buf[:len(value)]), nil + } + } +} +lookup_env :: proc{lookup_env_alloc, lookup_env_buffer} + +@(require_results) +get_env_alloc :: proc(key: string, allocator := context.allocator) -> (value: string) { value, _ = lookup_env(key, allocator) return } @(require_results) +get_env_buf :: proc(buf: []u8, key: string) -> (value: string) { + value, _ = lookup_env(buf, key) + return +} +get_env :: proc{get_env_alloc, get_env_buf} + +@(require_results) get_current_directory :: proc(allocator := context.allocator) -> string { context.allocator = allocator buf := make([dynamic]u8, MAX_PATH) |