clock_getres.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * clock_getres() for uClibc
  3. *
  4. * Copyright (C) 2005 by Peter Kjellerstedt <pkj@axis.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU Library General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
  14. * for more details.
  15. *
  16. * You should have received a copy of the GNU Library General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. #define _GNU_SOURCE
  22. #include "syscalls.h"
  23. #include <time.h>
  24. #include <unistd.h>
  25. #ifdef __NR_clock_getres
  26. _syscall2(int, clock_getres, clockid_t, clock_id, struct timespec*, res);
  27. #else
  28. int clock_getres(clockid_t clock_id, struct timespec* res)
  29. {
  30. long clk_tck;
  31. int retval = -1;
  32. switch (clock_id) {
  33. case CLOCK_REALTIME:
  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. retval = 0;
  39. break;
  40. default:
  41. errno = EINVAL;
  42. break;
  43. }
  44. return retval;
  45. }
  46. #endif