os: use C.getlogin for os.loginname, instead of C.getlogin_r (C.getlogin_r absent on Android)

pull/9875/head
Delyan Angelov 2021-04-24 13:32:26 +03:00
parent 187895c93c
commit b506d8fcc0
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 5 additions and 8 deletions

View File

@ -53,7 +53,8 @@ fn C.symlink(&char, &char) int
fn C.gethostname(&char, int) int
fn C.getlogin_r(&char, int) int
// NB: not available on Android fn C.getlogin_r(&char, int) int
fn C.getlogin() &char
pub fn uname() Uname {
mut u := Uname{}
@ -86,13 +87,9 @@ pub fn hostname() string {
}
pub fn loginname() string {
mut lgnname := ''
size := 256
mut buf := unsafe { &char(malloc(size)) }
if C.getlogin_r(buf, size) == 0 {
lgnname = unsafe { cstring_to_vstring(buf) }
unsafe { free(buf) }
return lgnname
x := C.getlogin()
if !isnil(x) {
return unsafe { cstring_to_vstring(x) }
}
return ''
}