clock_time.c 744 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <rtthread.h>
  2. #include <time.h>
  3. #include <errno.h>
  4. #include "libc.h"
  5. int clock_getres(clockid_t clock_id, struct timespec *res)
  6. {
  7. if ((clock_id != CLOCK_REALTIME) || (res == RT_NULL))
  8. {
  9. rt_set_errno(EINVAL);
  10. return -1;
  11. }
  12. res->tv_sec = 0;
  13. res->tv_nsec = NANOSECOND_PER_TICK;
  14. return 0;
  15. }
  16. int clock_gettime(clockid_t clock_id, struct timespec *tp)
  17. {
  18. if ((clock_id != CLOCK_REALTIME) || (tp == RT_NULL))
  19. {
  20. rt_set_errno(EINVAL);
  21. return -1;
  22. }
  23. libc_get_time(tp);
  24. return 0;
  25. }
  26. int clock_settime(clockid_t clock_id, const struct timespec *tp)
  27. {
  28. if ((clock_id != CLOCK_REALTIME) || (tp == RT_NULL))
  29. {
  30. rt_set_errno(EINVAL);
  31. return -1;
  32. }
  33. libc_set_time(tp);
  34. return 0;
  35. }