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