ci: fix os.environ :-|

pull/9599/head
Delyan Angelov 2021-04-04 21:11:17 +03:00
parent accd4d83bf
commit 8a362588aa
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 17 additions and 7 deletions

View File

@ -66,6 +66,13 @@ pub fn unsetenv(name string) int {
// See: https://linux.die.net/man/5/environ for unix platforms. // See: https://linux.die.net/man/5/environ for unix platforms.
// See: https://docs.microsoft.com/bg-bg/windows/win32/api/processenv/nf-processenv-getenvironmentstrings // See: https://docs.microsoft.com/bg-bg/windows/win32/api/processenv/nf-processenv-getenvironmentstrings
// os.environ returns a map of all the current environment variables // os.environ returns a map of all the current environment variables
type PChar = &char
type PPChar = &&char
fn deref_ppchar(x &PChar) &char {
return &char(*x)
}
pub fn environ() map[string]string { pub fn environ() map[string]string {
mut res := map[string]string{} mut res := map[string]string{}
$if windows { $if windows {
@ -83,18 +90,21 @@ pub fn environ() map[string]string {
} }
C.FreeEnvironmentStringsW(estrings) C.FreeEnvironmentStringsW(estrings)
} $else { } $else {
/* e := unsafe { PPChar(voidptr(C.environ)) }
// e := unsafe { &&char(C.environ) } size_of_pchar := int(sizeof(PChar))
e := unsafe { &charptr(C.environ) } for i := 0; true; i++ {
for i := 0; !isnil(unsafe { e[i] }); i++ { z := voidptr(unsafe { &byte(voidptr(e)) + size_of_pchar * i })
x := &byte(e[i]) current_ptr := &PChar(z)
eline := unsafe { cstring_to_vstring(x) } derefed := deref_ppchar(current_ptr)
if isnil(derefed) {
break
}
eline := unsafe { cstring_to_vstring(derefed) }
eq_index := eline.index_byte(`=`) eq_index := eline.index_byte(`=`)
if eq_index > 0 { if eq_index > 0 {
res[eline[0..eq_index]] = eline[eq_index + 1..] res[eline[0..eq_index]] = eline[eq_index + 1..]
} }
} }
*/
} }
return res return res
} }