clock_getres.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * clock_getres() for uClibc
  3. *
  4. * Copyright (C) 2005 by Peter Kjellerstedt <pkj@axis.com>
  5. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  6. *
  7. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  8. */
  9. #include <sys/syscall.h>
  10. #include <time.h>
  11. #if defined(__UCLIBC_USE_TIME64__) && defined(__NR_clock_getres_time64)
  12. #include "internal/time64_helpers.h"
  13. int clock_getres(clockid_t clock_id, struct timespec *res)
  14. {
  15. struct __ts64_struct __ts64;
  16. int __ret = INLINE_SYSCALL(clock_getres_time64, 2, clock_id, &__ts64);
  17. if (__ret == 0 && res) {
  18. res->tv_sec = __ts64.tv_sec;
  19. res->tv_nsec = __ts64.tv_nsec;
  20. };
  21. return __ret;
  22. }
  23. #elif defined(__NR_clock_getres)
  24. _syscall2(int, clock_getres, clockid_t, clock_id, struct timespec*, res)
  25. #else
  26. # include <unistd.h>
  27. int clock_getres(clockid_t clock_id, struct timespec* res)
  28. {
  29. int retval = -1;
  30. switch (clock_id) {
  31. case CLOCK_REALTIME:
  32. if (res) {
  33. long clk_tck;
  34. if ((clk_tck = sysconf(_SC_CLK_TCK)) < 0)
  35. clk_tck = 100;
  36. res->tv_sec = 0;
  37. res->tv_nsec = 1000000000 / clk_tck;
  38. }
  39. retval = 0;
  40. break;
  41. default:
  42. errno = EINVAL;
  43. break;
  44. }
  45. return retval;
  46. }
  47. #endif
  48. libc_hidden_def(clock_getres)