clock_gettime.c 794 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. retval = gettimeofday(&tv, NULL);
  23. if (retval == 0) {
  24. TIMEVAL_TO_TIMESPEC(&tv, tp);
  25. }
  26. break;
  27. default:
  28. errno = EINVAL;
  29. break;
  30. }
  31. return retval;
  32. }
  33. #endif