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