Update get_hostname

Previous solution made it impossible to free the returned string
containing hostname :/
master
Ronald 1 year ago
parent fc52839154
commit f97f1db020

@ -127,19 +127,20 @@ get_ram_usage_perc :: proc() -> (f64, bool) {
return 100 * (((total - free) - (buffers + cached)) / total), true return 100 * (((total - free) - (buffers + cached)) / total), true
} }
get_hostname :: proc() -> Maybe(string) { get_hostname :: proc() -> (hostname: string, ok: bool) #optional_ok {
data, ok := __read_entire_file_from_filename("/proc/sys/kernel/hostname") data: []u8
data, ok = __read_entire_file_from_filename("/proc/sys/kernel/hostname")
if !ok { if !ok {
return nil return
} }
defer delete(data) defer delete(data)
hostname, str_ok := strings.remove_all(string(data), "\n") hostname, ok = strings.remove_all(string(data), "\n")
if !ok { if !ok {
return nil return
} }
return hostname return
} }
@(private) @(private)

Loading…
Cancel
Save