mem: use unix.SysctlUint64 for hw.memsize on darwin

Use unix.SysctlUint64 which directly returns an uint64 rather than
converting it from a string.
pull/1180/head
Tobias Klauser 3 years ago
parent 78065a7ce2
commit d935ecccea

@ -4,7 +4,6 @@ package mem
import ( import (
"context" "context"
"encoding/binary"
"fmt" "fmt"
"unsafe" "unsafe"
@ -13,17 +12,10 @@ import (
) )
func getHwMemsize() (uint64, error) { func getHwMemsize() (uint64, error) {
totalString, err := unix.Sysctl("hw.memsize") total, err := unix.SysctlUint64("hw.memsize")
if err != nil { if err != nil {
return 0, err return 0, err
} }
// unix.sysctl() helpfully assumes the result is a null-terminated string and
// removes the last byte of the result if it's 0 :/
totalString += "\x00"
total := uint64(binary.LittleEndian.Uint64([]byte(totalString)))
return total, nil return total, nil
} }

@ -4,7 +4,6 @@ package mem
import ( import (
"context" "context"
"encoding/binary"
"fmt" "fmt"
"unsafe" "unsafe"
@ -13,17 +12,10 @@ import (
) )
func getHwMemsize() (uint64, error) { func getHwMemsize() (uint64, error) {
totalString, err := unix.Sysctl("hw.memsize") total, err := unix.SysctlUint64("hw.memsize")
if err != nil { if err != nil {
return 0, err return 0, err
} }
// unix.sysctl() helpfully assumes the result is a null-terminated string and
// removes the last byte of the result if it's 0 :/
totalString += "\x00"
total := uint64(binary.LittleEndian.Uint64([]byte(totalString)))
return total, nil return total, nil
} }

Loading…
Cancel
Save