github.com/haraldrudell/parl@v0.4.176/punix/os-version-darwin.go (about) 1 //go:build darwin 2 3 /* 4 © 2023–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/) 5 ISC License 6 */ 7 8 package punix 9 10 import ( 11 "runtime" 12 13 "github.com/haraldrudell/parl/perrors" 14 "golang.org/x/sys/unix" 15 ) 16 17 const ( 18 // sysctl kern.osproductversion 19 // - kern.osproductversion: 13.2.1 20 kernOsProductVersion = "kern.osproductversion" 21 macOS = "macOS" 22 ) 23 24 // OsVersion for darwin returns version: "macOS 13.2.1" 25 func OsVersion() (version string, hasVersion bool, err error) { 26 version = runtime.GOOS 27 var v string 28 if v, err = unix.Sysctl(kernOsProductVersion); perrors.Is(&err, "sysctl %s %w", kernOsProductVersion, err) { 29 return 30 } 31 if v != "" { 32 hasVersion = true 33 version = macOS + "\x20" + v 34 } 35 return 36 }