clock_gettime.c 832 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. /* libc_hidden_proto(gettimeofday) */
  17. int clock_gettime(clockid_t clock_id, struct timespec* tp)
  18. {
  19. struct timeval tv;
  20. int retval = -1;
  21. switch (clock_id) {
  22. case CLOCK_REALTIME:
  23. retval = gettimeofday(&tv, NULL);
  24. if (retval == 0) {
  25. TIMEVAL_TO_TIMESPEC(&tv, tp);
  26. }
  27. break;
  28. default:
  29. errno = EINVAL;
  30. break;
  31. }
  32. return retval;
  33. }
  34. #endif