1
0
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:
0x9ef 2019-07-16 21:29:17 +03:00 committed by Alexander Medvednikov
parent 91a712fdf0
commit 8ef3313d63

View File

@ -484,11 +484,15 @@ pub fn user_os() string {
}
// hostname returns hostname
pub fn hostname() string {
mut hname := [1024]byte
hname[1023] = `\0`
C.gethostname(&hname, 1023)
return tos_clone(hname)
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)
}
// home_dir returns path to user's home directory.