Added getenv to the *nix stdlib.

This commit is contained in:
Zac Pierson
2017-02-23 15:28:25 -06:00
parent 561c583b3f
commit 20b9f1ff59
2 changed files with 17 additions and 0 deletions

View File

@@ -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);
}

View File

@@ -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);