mirror of
https://github.com/odin-lang/Odin.git
synced 2026-03-01 22:28:20 +00:00
Added getenv to the *nix stdlib.
This commit is contained in:
@@ -49,6 +49,7 @@ unix_gettid :: proc() -> u64
|
||||
unix_malloc :: proc(size: int) -> rawptr #foreign libc "malloc";
|
||||
unix_free :: proc(ptr: rawptr) #foreign libc "free";
|
||||
unix_realloc :: proc(ptr: rawptr, size: int) -> rawptr #foreign libc "realloc";
|
||||
unix_getenv :: proc(^u8) -> ^u8 #foreign libc "getenv";
|
||||
|
||||
unix_exit :: proc(status: int) #foreign libc "exit";
|
||||
|
||||
@@ -180,6 +181,14 @@ heap_free :: proc(ptr: rawptr) {
|
||||
unix_free(ptr);
|
||||
}
|
||||
|
||||
getenv :: proc(name: string) -> (string, bool) {
|
||||
cstr: ^u8 = unix_getenv(to_c_str(name));
|
||||
if(cstr == nil) {
|
||||
return "", false;
|
||||
}
|
||||
return from_c_str(cstr), true;
|
||||
}
|
||||
|
||||
exit :: proc(code: int) {
|
||||
unix_exit(code);
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ unix_gettid :: proc() -> u64
|
||||
unix_malloc :: proc(size: int) -> rawptr #foreign libc "malloc";
|
||||
unix_free :: proc(ptr: rawptr) #foreign libc "free";
|
||||
unix_realloc :: proc(ptr: rawptr, size: int) -> rawptr #foreign libc "realloc";
|
||||
unix_getenv :: proc(^u8) -> ^u8 #foreign libc "getenv";
|
||||
|
||||
unix_exit :: proc(status: int) #foreign libc "exit";
|
||||
|
||||
@@ -182,6 +183,13 @@ heap_free :: proc(ptr: rawptr) #inline {
|
||||
unix_free(ptr);
|
||||
}
|
||||
|
||||
getenv :: proc(name: string) -> (string, bool) {
|
||||
cstr: ^u8 = unix_getenv(to_c_str(name));
|
||||
if(cstr == nil) {
|
||||
return "", false;
|
||||
}
|
||||
return from_c_str(cstr), true;
|
||||
}
|
||||
|
||||
exit :: proc(code: int) #inline {
|
||||
unix_exit(code);
|
||||
|
||||
Reference in New Issue
Block a user