aboutsummaryrefslogtreecommitdiff
path: root/core/sys/posix/sys_utsname.odin
blob: 61f88b5842902dbf940085b0bdd3a4707f2266c0 (plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#+build linux, darwin, netbsd, openbsd, freebsd, haiku
package posix

import "core:c"

when ODIN_OS == .Darwin {
	foreign import lib "system:System"
} else {
	foreign import lib "system:c"
}

// sys/utsname.h = system name structure

foreign lib {
	/*
	Stores information identifying the current system in the given structure.

	Returns: non-negative on success, -1 (setting errno) on failure

	NOTE: have a look at `core:sys/info` for similar/better system information.
	
	Example:
		uname: posix.utsname
		posix.uname(&uname)
		fmt.printfln("%#v", uname)

	Possible Output:
		utsname{
			sysname = Darwin,
			nodename = Laytans-MacBook-Pro.local,
			release = 23.5.0,
			version = Darwin Kernel Version 23.5.0: Wed May  1 20:16:51 PDT 2024; root:xnu-11331.111.3~1/RELEASE_ARM64_T8103,
			machine = arm64,
		}

	[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/uname.html ]]
	*/
	uname :: proc(uname: ^utsname) -> c.int ---
}

when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD || ODIN_OS == .Haiku {

	@(private)
	_SYS_NAMELEN :: 32 when ODIN_OS == .Haiku else 256

	utsname :: struct {
		sysname:  [_SYS_NAMELEN]c.char `fmt:"s,0"`, /* [PSX] name of OS */
		nodename: [_SYS_NAMELEN]c.char `fmt:"s,0"`, /* [PSX] name of this network node */
		release:  [_SYS_NAMELEN]c.char `fmt:"s,0"`, /* [PSX] release level */
		version:  [_SYS_NAMELEN]c.char `fmt:"s,0"`, /* [PSX] version level */
		machine:  [_SYS_NAMELEN]c.char `fmt:"s,0"`, /* [PSX] hardware type */
	}

} else when ODIN_OS == .Linux {

	@(private)
	_SYS_NAMELEN :: 65

	utsname :: struct {
		sysname:      [_SYS_NAMELEN]c.char `fmt:"s,0"`, /* [PSX] name of OS */
		nodename:     [_SYS_NAMELEN]c.char `fmt:"s,0"`, /* [PSX] name of this network node */
		release:      [_SYS_NAMELEN]c.char `fmt:"s,0"`, /* [PSX] release level */
		version:      [_SYS_NAMELEN]c.char `fmt:"s,0"`, /* [PSX] version level */
		machine:      [_SYS_NAMELEN]c.char `fmt:"s,0"`, /* [PSX] hardware type */
		__domainname: [_SYS_NAMELEN]c.char `fmt:"s,0"`,
	}
}