maptime.lisp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. (in-package :hurd-common)
  2. ;; This file maps the mapped_time_value_t type to Lisp.
  3. ;; Load libshouldbeinlibc
  4. (defun load-hurd-common-libraries ()
  5. (define-foreign-library libshouldbeinlibc
  6. (:unix (:or "libshouldbeinlibc.so.0.3" "libshouldbeinlibc.so"))
  7. (t (:default "libshouldbeinlibc")))
  8. (use-foreign-library libshouldbeinlibc))
  9. (load-hurd-common-libraries)
  10. (defcfun ("maptime_map" %maptime-map)
  11. err
  12. (use-mach-dev :boolean)
  13. (dev-name :string)
  14. (time-value :pointer))
  15. (defcstruct mapped-time-value
  16. "Mapped time value. Can be found at mach/time_value.h."
  17. (seconds :int)
  18. (microseconds :int)
  19. (check-seconds :int))
  20. (defun maptime-map (&optional (use-mach-dev nil) (dev-name nil))
  21. "Return a mapped time pointer or nil and error in case of errors.
  22. Returned value is a foreign pointer."
  23. (with-foreign-pointer (ret (foreign-type-size :pointer))
  24. (let ((error-code (%maptime-map use-mach-dev
  25. dev-name
  26. ret)))
  27. (select-error error-code
  28. (mem-ref ret :pointer)))))
  29. (defun maptime-seconds (ptr)
  30. "Return the seconds field from a mapped-time-value."
  31. (foreign-slot-value ptr 'mapped-time-value 'seconds))
  32. (defun maptime-microseconds (ptr)
  33. "Return the microseconds field from a mapped-time-value."
  34. (foreign-slot-value ptr 'mapped-time-value 'microseconds))
  35. (defun maptime-check-seconds (ptr)
  36. "Return the check seconds field from a mapped-time-value."
  37. (foreign-slot-value ptr 'mapped-time-value 'check-seconds))
  38. (define-symbol-macro *mapped-time* (maptime-map))