1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
Alexander Medvednikov
2019-07-17 10:54:24 +02:00
parent 55b8a9acb9
commit b9f3f2d622
2 changed files with 41 additions and 19 deletions

View File

@@ -483,16 +483,17 @@ pub fn user_os() string {
return 'unknown'
}
// hostname returns hostname
// hostname returns the host name reported by the kernel.
pub fn hostname() ?string {
mut hname := [256]byte
mut name := [256]byte
// https://www.ietf.org/rfc/rfc1035.txt
// The host name is returned as a null-terminated string.
res := C.gethostname(&hname, 256)
res := C.gethostname(&name, 256)
if res != 0 {
return error('os: hostname cannot get host name of PC.')
return error('os.hostname() cannot get the host name')
}
return tos_clone(hname)
return tos_clone(name)
}
// home_dir returns path to user's home directory.