clock_gettime.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * clock_gettime() for uClibc
  3. *
  4. * Copyright (C) 2003 by Justus Pendleton <uc@ryoohki.net>
  5. * Copyright (C) 2005 by Peter Kjellerstedt <pkj@axis.com>
  6. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  7. *
  8. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  9. */
  10. #include <sys/syscall.h>
  11. #include <time.h>
  12. #if defined(__UCLIBC_USE_TIME64__) && defined(__NR_clock_gettime64)
  13. _syscall2_64(int, clock_gettime, clockid_t, clock_id, struct timespec*, tp)
  14. #elif defined(__NR_clock_gettime)
  15. _syscall2(int, clock_gettime, clockid_t, clock_id, struct timespec*, tp)
  16. #else
  17. # include <sys/time.h>
  18. int clock_gettime(clockid_t clock_id, struct timespec* tp)
  19. {
  20. struct timeval tv;
  21. int retval = -1;
  22. switch (clock_id) {
  23. case CLOCK_REALTIME:
  24. /* In Linux, gettimeofday fails only on bad parameter.
  25. * We know that here parameter isn't bad.
  26. */
  27. gettimeofday(&tv, NULL);
  28. TIMEVAL_TO_TIMESPEC(&tv, tp);
  29. retval = 0;
  30. break;
  31. default:
  32. errno = EINVAL;
  33. break;
  34. }
  35. return retval;
  36. }
  37. #endif