sys_time.odin 2.2 KB

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