sys_utsname.odin 1.5 KB

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