sys_time.odin 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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/time.h - time types
  9. foreign lib {
  10. /*
  11. Store the current value of timer into value.
  12. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/getitimer.html ]]
  13. */
  14. @(link_name=LGETITIMER)
  15. getitimer :: proc(which: ITimer, value: ^itimerval) -> result ---
  16. /*
  17. Set the timer to the value given, and store the previous value in ovalue if it is not nil.
  18. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/getitimer.html ]]
  19. */
  20. @(link_name=LSETITIMER)
  21. setitimer :: proc(which: ITimer, value: ^itimerval, ovalue: ^itimerval) -> result ---
  22. /*
  23. Obtains the current time.
  24. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/gettimeofday.html ]]
  25. */
  26. @(link_name=LGETTIMEOFDAY)
  27. gettimeofday :: proc(tp: ^timeval, tzp: rawptr = nil) -> result ---
  28. /*
  29. Sets the access and modification times of the file at the given path.
  30. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/utimes.html ]]
  31. */
  32. @(link_name=LUTIMES)
  33. utimes :: proc(path: cstring, times: ^[2]timeval) -> result ---
  34. }
  35. ITimer :: enum c.int {
  36. // Decrements in real time.
  37. REAL = ITIMER_REAL,
  38. // Decrements in process virtual time, only when the process is executing.
  39. VIRTUAL = ITIMER_VIRTUAL,
  40. // Decrements both in process virtual time and when the system is running on
  41. // behalf of the process.
  42. PROF = ITIMER_PROF,
  43. }
  44. when ODIN_OS == .NetBSD {
  45. @(private) LGETITIMER :: "__getitimer50"
  46. @(private) LSETITIMER :: "__setitimer50"
  47. @(private) LGETTIMEOFDAY :: "__gettimeofday50"
  48. @(private) LUTIMES :: "__utimes50"
  49. } else {
  50. @(private) LGETITIMER :: "getitimer"
  51. @(private) LSETITIMER :: "setitimer"
  52. @(private) LGETTIMEOFDAY :: "gettimeofday"
  53. @(private) LUTIMES :: "utimes"
  54. }
  55. when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD {
  56. itimerval :: struct {
  57. it_interval: timeval, /* [PSX] timer interval */
  58. it_value: timeval, /* [PSX] current value */
  59. }
  60. ITIMER_REAL :: 0
  61. ITIMER_VIRTUAL :: 1
  62. ITIMER_PROF :: 2
  63. } else {
  64. #panic("posix is unimplemented for the current target")
  65. }