clock_gettime.c 882 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. #include <sys/time.h>
  13. #ifdef __NR_clock_gettime
  14. _syscall2(int, clock_gettime, clockid_t, clock_id, struct timespec*, tp)
  15. #else
  16. int clock_gettime(clockid_t clock_id, struct timespec* tp)
  17. {
  18. struct timeval tv;
  19. int retval = -1;
  20. switch (clock_id) {
  21. case CLOCK_REALTIME:
  22. /* In Linux, gettimeofday fails only on bad parameter.
  23. * We know that here parameter isn't bad.
  24. */
  25. gettimeofday(&tv, NULL);
  26. TIMEVAL_TO_TIMESPEC(&tv, tp);
  27. retval = 0;
  28. break;
  29. default:
  30. errno = EINVAL;
  31. break;
  32. }
  33. return retval;
  34. }
  35. #endif