sys_utsname.odin 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #+build linux, darwin, netbsd, openbsd, freebsd, haiku
  2. package posix
  3. import "core:c"
  4. when ODIN_OS == .Darwin {
  5. foreign import lib "system:System"
  6. } else {
  7. foreign import lib "system:c"
  8. }
  9. // sys/utsname.h = system name structure
  10. foreign lib {
  11. /*
  12. Stores information identifying the current system in the given structure.
  13. Returns: non-negative on success, -1 (setting errno) on failure
  14. NOTE: have a look at `core:sys/info` for similar/better system information.
  15. Example:
  16. uname: posix.utsname
  17. posix.uname(&uname)
  18. fmt.printfln("%#v", uname)
  19. Possible Output:
  20. utsname{
  21. sysname = Darwin,
  22. nodename = Laytans-MacBook-Pro.local,
  23. release = 23.5.0,
  24. version = Darwin Kernel Version 23.5.0: Wed May 1 20:16:51 PDT 2024; root:xnu-11331.111.3~1/RELEASE_ARM64_T8103,
  25. machine = arm64,
  26. }
  27. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/uname.html ]]
  28. */
  29. uname :: proc(uname: ^utsname) -> c.int ---
  30. }
  31. when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD || ODIN_OS == .Haiku {
  32. @(private)
  33. _SYS_NAMELEN :: 32 when ODIN_OS == .Haiku else 256
  34. utsname :: struct {
  35. sysname: [_SYS_NAMELEN]c.char `fmt:"s,0"`, /* [PSX] name of OS */
  36. nodename: [_SYS_NAMELEN]c.char `fmt:"s,0"`, /* [PSX] name of this network node */
  37. release: [_SYS_NAMELEN]c.char `fmt:"s,0"`, /* [PSX] release level */
  38. version: [_SYS_NAMELEN]c.char `fmt:"s,0"`, /* [PSX] version level */
  39. machine: [_SYS_NAMELEN]c.char `fmt:"s,0"`, /* [PSX] hardware type */
  40. }
  41. } else when ODIN_OS == .Linux {
  42. @(private)
  43. _SYS_NAMELEN :: 65
  44. utsname :: struct {
  45. sysname: [_SYS_NAMELEN]c.char `fmt:"s,0"`, /* [PSX] name of OS */
  46. nodename: [_SYS_NAMELEN]c.char `fmt:"s,0"`, /* [PSX] name of this network node */
  47. release: [_SYS_NAMELEN]c.char `fmt:"s,0"`, /* [PSX] release level */
  48. version: [_SYS_NAMELEN]c.char `fmt:"s,0"`, /* [PSX] version level */
  49. machine: [_SYS_NAMELEN]c.char `fmt:"s,0"`, /* [PSX] hardware type */
  50. __domainname: [_SYS_NAMELEN]c.char `fmt:"s,0"`,
  51. }
  52. }