clock_getres.c 824 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. #include <unistd.h>
  12. #ifdef __NR_clock_getres
  13. _syscall2(int, clock_getres, clockid_t, clock_id, struct timespec*, res)
  14. #else
  15. int clock_getres(clockid_t clock_id, struct timespec* res)
  16. {
  17. int retval = -1;
  18. switch (clock_id) {
  19. case CLOCK_REALTIME:
  20. if (res) {
  21. long clk_tck;
  22. if ((clk_tck = sysconf(_SC_CLK_TCK)) < 0)
  23. clk_tck = 100;
  24. res->tv_sec = 0;
  25. res->tv_nsec = 1000000000 / clk_tck;
  26. }
  27. retval = 0;
  28. break;
  29. default:
  30. errno = EINVAL;
  31. break;
  32. }
  33. return retval;
  34. }
  35. #endif
  36. libc_hidden_def(clock_getres)