Merge pull request #1180 from tklauser/mem-darwin-sysctluint64

mem: use unix.SysctlUint64 for hw.memsize on darwin
pull/1186/head
shirou 4 years ago committed by GitHub
commit 6e1e70b706
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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