未验证 提交 6e1e70b7 编写于 作者: S shirou 提交者: GitHub

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

mem: use unix.SysctlUint64 for hw.memsize on darwin
......@@ -4,7 +4,6 @@ package mem
import (
"context"
"encoding/binary"
"fmt"
"unsafe"
......@@ -13,17 +12,10 @@ import (
)
func getHwMemsize() (uint64, error) {
totalString, err := unix.Sysctl("hw.memsize")
total, err := unix.SysctlUint64("hw.memsize")
if err != nil {
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
}
......
......@@ -4,7 +4,6 @@ package mem
import (
"context"
"encoding/binary"
"fmt"
"unsafe"
......@@ -13,17 +12,10 @@ import (
)
func getHwMemsize() (uint64, error) {
totalString, err := unix.Sysctl("hw.memsize")
total, err := unix.SysctlUint64("hw.memsize")
if err != nil {
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
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册