...
1
2
3
4
5 package unix
6
7 import (
8 "syscall"
9 )
10
11
12
13
14
15
16 func KernelVersion() (major, minor int) {
17 var uname syscall.Utsname
18 if err := syscall.Uname(&uname); err != nil {
19 return
20 }
21
22 var (
23 values [2]int
24 value, vi int
25 )
26 for _, c := range uname.Release {
27 if '0' <= c && c <= '9' {
28 value = (value * 10) + int(c-'0')
29 } else {
30
31
32 values[vi] = value
33 vi++
34 if vi >= len(values) {
35 break
36 }
37 value = 0
38 }
39 }
40
41 return values[0], values[1]
42 }
43
View as plain text