Use multi-pointers when appropriate

This commit is contained in:
gingerBill
2021-08-22 12:54:04 +01:00
parent 8694a0f68a
commit 445ed9be2b
4 changed files with 12 additions and 16 deletions
+4 -7
View File
@@ -65,22 +65,19 @@ unset_env :: proc(key: string) -> Errno {
// environ returns a copy of strings representing the environment, in the form "key=value"
// NOTE: the slice of strings and the strings with be allocated using the supplied allocator
environ :: proc(allocator := context.allocator) -> []string {
envs := win32.GetEnvironmentStringsW();
envs := cast([^]win32.WCHAR)(win32.GetEnvironmentStringsW());
if envs == nil {
return nil;
}
defer win32.FreeEnvironmentStringsW(envs);
r := make([dynamic]string, 0, 50, allocator);
for from, i, p := 0, 0, envs; true; i += 1 {
c := (^u16)(uintptr(p) + uintptr(i*2))^;
if c == 0 {
for from, i := 0, 0; true; i += 1 {
if c := envs[i]; c == 0 {
if i <= from {
break;
}
w := mem.slice_ptr(mem.ptr_offset(p, from), i-from);
append(&r, win32.utf16_to_utf8(w, allocator));
append(&r, win32.utf16_to_utf8(envs[from:i], allocator));
from = i + 1;
}
}