aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorHector Mejia <caquillo722@gmail.com>2024-07-05 16:26:03 -0400
committerHector Mejia <caquillo722@gmail.com>2024-07-05 16:26:03 -0400
commit2b854c94dafa9aa5fdd4c7ca46c778731fffcce2 (patch)
treef272f4ba45266db40f94aa58d39ef1b27e500e66 /core
parentecffe5a0826617d0a45843721707461034cb5cdc (diff)
added the setenv and unsetenv bindings for darwin, inspired but os_linux.odin
Diffstat (limited to 'core')
-rw-r--r--core/os/os_darwin.odin25
1 files changed, 25 insertions, 0 deletions
diff --git a/core/os/os_darwin.odin b/core/os/os_darwin.odin
index bbe335e6e..e3748cce4 100644
--- a/core/os/os_darwin.odin
+++ b/core/os/os_darwin.odin
@@ -477,7 +477,11 @@ foreign libc {
@(link_name="calloc") _unix_calloc :: proc(num, size: int) -> rawptr ---
@(link_name="free") _unix_free :: proc(ptr: rawptr) ---
@(link_name="realloc") _unix_realloc :: proc(ptr: rawptr, size: int) -> rawptr ---
+
@(link_name="getenv") _unix_getenv :: proc(cstring) -> cstring ---
+ @(link_name="unsetenv") _unix_unsetenv :: proc(cstring) -> c.int ---
+ @(link_name="setenv") _unix_setenv :: proc(key: cstring, value: cstring, overwrite: c.int) -> c.int ---
+
@(link_name="getcwd") _unix_getcwd :: proc(buf: cstring, len: c.size_t) -> cstring ---
@(link_name="chdir") _unix_chdir :: proc(buf: cstring) -> c.int ---
@(link_name="mkdir") _unix_mkdir :: proc(buf: cstring, mode: u16) -> c.int ---
@@ -914,6 +918,27 @@ get_env :: proc(key: string, allocator := context.allocator) -> (value: string)
return
}
+set_env :: proc(key, value: string) -> Errno {
+ runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
+ key_cstring := strings.clone_to_cstring(key, context.temp_allocator)
+ value_cstring := strings.clone_to_cstring(value, context.temp_allocator)
+ res := _unix_setenv(key_cstring, value_cstring, 1)
+ if res < 0 {
+ return Errno(get_last_error())
+ }
+ return ERROR_NONE
+}
+
+unset_env :: proc(key: string) -> Errno {
+ runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
+ s := strings.clone_to_cstring(key, context.temp_allocator)
+ res := _unix_unsetenv(s)
+ if res < 0 {
+ return Errno(get_last_error())
+ }
+ return ERROR_NONE
+}
+
get_current_directory :: proc() -> string {
page_size := get_page_size() // NOTE(tetra): See note in os_linux.odin/get_current_directory.
buf := make([dynamic]u8, page_size)