1
2
3
4
5
6
7 package cpu
8
9 import _ "unsafe"
10
11
12
13
14 func sysctlbynameInt32(name []byte) (int32, int32)
15
16
17
18
19 func sysctlbynameBytes(name, out []byte) int32
20
21
22
23
24
25
26
27
28
29
30
31 func sysctlEnabled(name []byte) bool {
32 ret, value := sysctlbynameInt32(name)
33 if ret < 0 {
34 return false
35 }
36 return value > 0
37 }
38
39
40
41
42
43 func darwinKernelVersionCheck(major, minor, patch int) bool {
44 var release [256]byte
45 ret := sysctlbynameBytes([]byte("kern.osrelease\x00"), release[:])
46 if ret < 0 {
47 return false
48 }
49
50 var mmp [3]int
51 c := 0
52 Loop:
53 for _, b := range release[:] {
54 switch {
55 case b >= '0' && b <= '9':
56 mmp[c] = 10*mmp[c] + int(b-'0')
57 case b == '.':
58 c++
59 if c > 2 {
60 return false
61 }
62 case b == 0:
63 break Loop
64 default:
65 return false
66 }
67 }
68 if c != 2 {
69 return false
70 }
71 return mmp[0] > major || mmp[0] == major && (mmp[1] > minor || mmp[1] == minor && mmp[2] >= patch)
72 }
73
View as plain text