Debian Codegraph @

sys/windows/version.go

raw symbols SCIP
1 // +build windows
2
3 package windows
4
5 import (
6 "fmt"
7 "syscall"
8 )
9
10 // Version identifies a Windows version by major, minor, and build number.
11 type Version struct {
12 Major int
13 Minor int
14 Build int
15 }
16
17 // GetWindowsVersion returns the Windows version information. Applications not
18 // manifested for Windows 8.1 or Windows 10 will return the Windows 8 OS version
19 // value (6.2).
20 //
21 // For a table of version numbers see:
22 // https://msdn.microsoft.com/en-us/library/windows/desktop/ms724833(v=vs.85).aspx
23 func GetWindowsVersion() Version {
24 // https://msdn.microsoft.com/en-us/library/windows/desktop/ms724439(v=vs.85).aspx
25 ver, err := syscall.GetVersion()
26 if err != nil {
27 // GetVersion should never return an error.
28 panic(fmt.Errorf("GetVersion failed: %v", err))
29 }
30
31 return Version{
32 Major: int(ver & 0xFF),
33 Minor: int(ver >> 8 & 0xFF),
34 Build: int(ver >> 16),
35 }
36 }
37
38 // IsWindowsVistaOrGreater returns true if the Windows version is Vista or
39 // greater.
40 func (v Version) IsWindowsVistaOrGreater() bool {
41 // Vista is 6.0.
42 return v.Major >= 6 && v.Minor >= 0
43 }