Portable build framework for OpenNTPD
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.4 KiB

  1. /*
  2. * Copyright (c) 1999-2004 Damien Miller <djm@mindrot.org>
  3. * Copyright (c) 2004 Darren Tucker <dtucker at zip com au>
  4. *
  5. * Permission to use, copy, modify, and distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include <sys/time.h>
  18. #ifdef HAVE_ADJTIMEX
  19. #include <sys/timex.h>
  20. #endif
  21. int
  22. clock_getres(clockid_t clk_id, struct timespec *tp)
  23. {
  24. # ifdef HAVE_ADJTIMEX
  25. struct timex tmx;
  26. # endif
  27. if (clk_id != CLOCK_REALTIME)
  28. return -1; /* not implemented */
  29. tp->tv_sec = 0;
  30. # ifdef HAVE_ADJTIMEX
  31. tmx.modes = 0;
  32. if (adjtimex(&tmx) == -1)
  33. return -1;
  34. else
  35. tp->tv_nsec = tmx.precision * 1000; /* usec -> nsec */
  36. # else
  37. /* assume default 10ms tick */
  38. tp->tv_nsec = 10000000;
  39. # endif
  40. return 0;
  41. }