aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/version/os_linux.go
blob: 7e5c4f1c8f830dbf33c83d00c8e91e1008b0f4de (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* SPDX-License-Identifier: MIT
 *
 * Copyright (C) 2019 WireGuard LLC. All Rights Reserved.
 */

package version

import (
	"bytes"
	"fmt"
	"golang.org/x/sys/unix"
)

// This isn't a Linux program, yes, but having the updater package work across platforms is quite helpful for testing.

func utsToStr(u [65]byte) string {
	i := bytes.IndexByte(u[:], 0)
	if i < 0 {
		return string(u[:])
	}
	return string(u[:i])
}

func OsName() string {
	var utsname unix.Utsname
	if unix.Uname(&utsname) != nil {
		return "Unix Unknown"
	}
	return fmt.Sprintf("%s %s %s", utsToStr(utsname.Sysname), utsToStr(utsname.Release), utsToStr(utsname.Version))
}