clock_getres.c 792 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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 "syscalls.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. long clk_tck;
  19. int retval = -1;
  20. switch (clock_id) {
  21. case CLOCK_REALTIME:
  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. retval = 0;
  27. break;
  28. default:
  29. errno = EINVAL;
  30. break;
  31. }
  32. return retval;
  33. }
  34. #endif