Fixed buf on hostname and added optional type.
Before submitting this PR, submit https://github.com/vlang/v/pull/1188pull/1196/head
parent
91a712fdf0
commit
8ef3313d63
12
vlib/os/os.v
12
vlib/os/os.v
|
@ -484,10 +484,14 @@ pub fn user_os() string {
|
|||
}
|
||||
|
||||
// hostname returns hostname
|
||||
pub fn hostname() string {
|
||||
mut hname := [1024]byte
|
||||
hname[1023] = `\0`
|
||||
C.gethostname(&hname, 1023)
|
||||
pub fn hostname() ?string {
|
||||
mut hname := [256]byte
|
||||
// https://www.ietf.org/rfc/rfc1035.txt
|
||||
// The host name is returned as a null-terminated string.
|
||||
res := C.gethostname(&hname, 256)
|
||||
if res != 0 {
|
||||
return error('os: hostname cannot get host name of PC.')
|
||||
}
|
||||
return tos_clone(hname)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue