os: use C.getlogin for os.loginname, instead of C.getlogin_r (C.getlogin_r absent on Android)
parent
187895c93c
commit
b506d8fcc0
|
@ -53,7 +53,8 @@ fn C.symlink(&char, &char) int
|
||||||
|
|
||||||
fn C.gethostname(&char, int) 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 {
|
pub fn uname() Uname {
|
||||||
mut u := Uname{}
|
mut u := Uname{}
|
||||||
|
@ -86,13 +87,9 @@ pub fn hostname() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn loginname() string {
|
pub fn loginname() string {
|
||||||
mut lgnname := ''
|
x := C.getlogin()
|
||||||
size := 256
|
if !isnil(x) {
|
||||||
mut buf := unsafe { &char(malloc(size)) }
|
return unsafe { cstring_to_vstring(x) }
|
||||||
if C.getlogin_r(buf, size) == 0 {
|
|
||||||
lgnname = unsafe { cstring_to_vstring(buf) }
|
|
||||||
unsafe { free(buf) }
|
|
||||||
return lgnname
|
|
||||||
}
|
}
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue